Skip to content

test(territories): fix card-overlays FK flake by draining audit writes#205

Merged
mindsers merged 1 commit into
mainfrom
fix/card-overlays-test-flake
Jun 6, 2026
Merged

test(territories): fix card-overlays FK flake by draining audit writes#205
mindsers merged 1 commit into
mainfrom
fix/card-overlays-test-flake

Conversation

@mindsers

@mindsers mindsers commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • The card-overlays.integration.test.ts cleanup can intermittently fail with an FK violation on CongregationAuditLog because audit() is fire-and-forget via unscopedDb — a stray write can land after the test's auditLog.deleteMany and before the congregation.deleteMany, leaving a referenced row.
  • Adds flushPendingAuditWrites() to audit.server.ts which tracks in-flight audit() promises and lets callers await them. The test awaits it just before the cleanup deletes.
  • Production behavior is unchanged: audit() still doesn't block its callers; the helper is for tests that need to assert a clean slate.

Test plan

  • pnpm test:unit (1146 tests passing, including 3 new tests covering flushPendingAuditWrites)
  • pnpm test:typecheck
  • pnpm test:lint
  • pnpm test:integration -- card-overlays.integration.test.ts — 5 consecutive clean runs locally

The card-overlays RLS integration test's afterAll deleted audit logs and
then dropped the test congregations, but `audit()` is fire-and-forget via
`unscopedDb`. An in-flight write could land after the deleteMany and
break the congregation FK, causing intermittent FK failures in CI.

Expose `flushPendingAuditWrites()` from the audit module and await it in
the test's cleanup so all pending writes settle before the audit-log
deleteMany runs.
@mindsers mindsers merged commit 17efc2e into main Jun 6, 2026
6 checks passed
@mindsers mindsers deleted the fix/card-overlays-test-flake branch June 6, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant