Skip to content

test: close seeded journal databases before fixture cleanup - #37176

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/lt1031-journal-fixture-close
Nov 1, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/lt1031-journal-fixture-close

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2
Prod 0 0 0 0

The journal refusal test can pass its inventory assertions and then fail CI while removing its temporary directory. Seeding session records leaves a test-owned SQLite connection and checkpoint worker open; stopping the runtime closes a different connection.

Await the existing close-all test database API in the suite’s shared teardown before removing the fixture directory. This closes every seeded connection and waits for checkpoint-worker termination, including when a test fails. Shipped app behavior is unchanged.

Plan: reuse the common pattern of closing owned database resources before deleting their files. Audit record-store harness consumers and their shared teardown, then add the missing close at the fixture cleanup boundary. Budget: 0 production lines and about 2 test lines, one PR, no saved fields or wire changes. No added capability or changed outcome; no older-client or saved-user-data impact; no UI choice; no conflicting ruling. Test-only maintenance uses the short plan; plan review and plan check do not apply.

Path: light; qa=none.

  • Small: 0 production lines and 0 production files.
  • Outside risky areas: only a test suite’s temporary fixture cleanup changes; no shipped journal, lifecycle, process, file deletion, or protocol behavior changes.
  • Not a repeat: file history shows moves, import updates, and journal/inventory behavior changes, with no earlier repair of the missing fixture close or revert.
  • Local effect: test-only teardown, using the existing test-database close API.

Common-pattern differences: none in the changed teardown; owned database resources close before fixture deletion.

Validation: temporary instrumentation of the reported test on main confirmed that the captured seed database remained open after runtime shutdown (expected isClosed=true, received false). This reproduces the ownership defect, not the intermittent ENOTEMPTY itself. Instrumentation is kept outside the PR; no extra regression test is added for this cleanup-only change. The same temporary assertion passes with the fix. The final named refusal suite passes all 13 tests through tc-gate. Formatting and the pre-commit checks passed.

Tracked in STA-13026.

@brennanb2025
brennanb2025 marked this pull request as ready for review November 1, 2026 21:50
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 6 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8bfa8572-11d1-4864-8a64-7f98d0c1ac95
Commits

Reviewing files that changed from the base of the PR and between d337a1e and aaf613f.

Files selected for processing: 1
  • src/main/runtime/agent-session/structured-agent-session-host-refusal.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@brennanb2025

brennanb2025 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Review loop status: review done, CI green

The problem. The journal refusal test suite (structured-agent-session-host-refusal.test.ts) can pass all its assertions and still fail CI when it removes its temporary directory (intermittent ENOTEMPTY). One test seeds session records through the record-store test harness. That opens a test-owned SQLite connection and its checkpoint worker. Stopping the runtime closes the runtime's own connection, not this one, so the seeded connection is still open when the directory is deleted.

The change. The suite's shared afterEach now awaits the existing closeTestJournalHostDatabases() before deleting the fixture directory. This closes every seeded connection and waits for its checkpoint worker to exit, including after a failed test. Users see no change: no shipped code is touched.

What was verified

  • The light-path classification (small, outside the risky areas, not a repeat, local effect) was checked against the code by a fresh adversarial reviewer. It returned CLEAN with no findings.
  • The only connection the suite leaves open is the one opened by the seeding test, and that connection goes into the map the new call closes. The runtime closes its own separate connection first, so nothing is closed twice, and JournalHostDatabase.close() is idempotent anyway. vi.restoreAllMocks() runs before the close, so the one test that mocks close doesn't affect teardown.
  • Class check: the reviewer spot-checked six other suites from the author's audit of 113 record-store harness consumers. All of them already close their seeded databases (host harness closeAll, the scale fixture, rest rig, history fixture, request-failure rig, streaming replay). No other suite was missing the close.
  • Before the fix, an instrumented copy of the test on main showed the seeded database still open after runtime shutdown. With the fix, the same instrumentation passes. The suite passed 13/13 three times locally and 13/13 in CI (shard 9). The flake is intermittent, so these runs show nothing regressed; they don't prove the flake is gone.

Deferred (P3, already on main, outside this fix): the teardown swallows a failed runtime stop (.catch(() => undefined)), which could leave the runtime's own connection open. closeTestJournalHostDatabases closes databases one at a time and stops at the first failure. This suite has only one seeded database, so neither has any effect here.

CI. Green on aaf613fa6f7. The earlier red run came only from two breakages on main (the automation-operations.ts line cap and the Source Control test store fixtures), both since fixed on main. This branch merged main once (aaf613fa6f7, merging d337a1efed3) with no conflicts; the merge brings in no change to this PR's diff, which is still the two test lines below. The review evidence is for d5362b8fe39.

QA: none needed (test-only change).

For Brennan's review

  • src/main/runtime/agent-session/structured-agent-session-host-refusal.test.ts:82: the close sits between mock restore and directory removal.

@brennanb2025
brennanb2025 merged commit db44f96 into main Nov 1, 2026
42 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/lt1031-journal-fixture-close branch November 1, 2026 23:58
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