test(web): the purge failure test no longer boots a second database (#203)

The test started a second PGlite inside its body to get a real database
error. Under load (every test file boots its own PGlite), that boot
exceeded the 5 s test timeout: one run out of several failed on it.

The real failure now comes from the database of the file, whose journal
table is renamed for the time of one purge, with a control that the error
does carry the text of the query that safePurge must not log.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
le king fu 2026-11-15 12:47:02 -05:00
commit 93c36c412f

View file

@ -358,9 +358,18 @@ describe('safePurge', () => {
await expect(safePurge(() => Promise.reject('a string'), log)).resolves.toBeUndefined();
expect(lines).toEqual(['> Journal purge failed: QueryError', '> Journal purge failed: TypeError', '> Journal purge failed: Error']);
// A real failure: the table is not there.
const empty = drizzle(new PGlite());
await expect(safePurge(() => purgeOldActions(empty, NOW), log)).resolves.toBeUndefined();
// A real failure: the table is not there for the time of one purge. No
// second database is started for it: a PGlite that boots inside a test
// has exceeded the test timeout when the other files boot theirs.
await pg.exec('alter table sl_agent_actions rename to sl_agent_actions_away');
try {
// Control: what safePurge has to hide. The query fails with its text.
const failure = await purgeOldActions(db, NOW).then(() => null, (error: Error) => error);
expect(failure?.message).toContain('sl_agent_actions');
await expect(safePurge(() => purgeOldActions(db, NOW), log)).resolves.toBeUndefined();
} finally {
await pg.exec('alter table sl_agent_actions_away rename to sl_agent_actions');
}
expect(lines).toHaveLength(4);
expect(lines[3]).toMatch(/^> Journal purge failed: [A-Za-z]+$/);
expect(lines.join('\n')).not.toMatch(/sl_agent_actions|delete|user-1|db-host/);