fix(demo): keep a demo baseline per engine and check it before every reset

The baseline was travel-baseline.db on both engines and went straight into
the swap, so a SQLite baseline left in the data directory made every hourly
reset of a Postgres demo fail inside pg_restore, and never got replaced. It
is now named after the engine's archive entry (travel-baseline.db on
SQLite, travel-baseline.pgdump on Postgres), and the backup port's new
checkCopy refuses one the engine cannot restore before the swap; the reset
then saves a fresh baseline and logs the reason instead of failing hourly.
This commit is contained in:
Maurice
2026-11-17 12:19:13 +01:00
parent 7a99190550
commit 99c3c670a5
11 changed files with 144 additions and 4 deletions
@@ -169,4 +169,18 @@ describe('PostgresDatabaseBackup', () => {
expect(backup.location()).toBe('Postgres postgresql://trek:***@db/trek');
await expect(postgresBackup({}).snapshot(path.join(root, 'c.pgdump'))).rejects.toThrow(/without TREK_DB_URL/);
});
it('PGBACKUP-007: a kept copy (the demo baseline) passes only as a dump with TREK history this build knows', async () => {
const copy = path.join(root, 'travel-baseline.pgdump');
writeFileSync(copy, 'dump');
installFakeTool(bin, 'pg_restore', { snippets: [listsMigrations(KNOWN.slice(0, 2))] });
await expect(backup.checkCopy(copy)).resolves.toBeNull();
const notADump = failsWith('pg_restore: error: input file does not appear to be a valid archive');
installFakeTool(bin, 'pg_restore', { snippets: [notADump] });
await expect(backup.checkCopy(copy)).resolves.toBe('Uploaded file is not a valid Postgres dump');
installFakeTool(bin, 'pg_restore', { snippets: [listsMigrations(['Migration20990101000000_from_the_future'])] });
await expect(backup.checkCopy(copy)).resolves.toMatch(/made by a newer TREK version/);
});
});