fix(test): stabilize OutroScreen preserveFiles K-test process.exit spy#776
Merged
Conversation
Move the `vi.spyOn(process, 'exit')` from each K-path test into a file-level `beforeAll` / `afterAll` so the spy stays patched across the file's lifetime. Previously, each test restored the spy when it finished, but the K keystroke fires a `wizardSuccessExit` async chain fire-and-forget — under CI load, that chain landed after `exitSpy.mockRestore()` and tripped the real `process.exit`, which vitest surfaced as an unhandled rejection 24s+ after the file's tests reported green. This recurred across multiple salvage PRs. The file-level stub means there is no window where the real `process.exit` is reachable while OutroScreen tests are still running.
kelsonpw
added a commit
that referenced
this pull request
May 14, 2026
Same fix as PR #776 (main-track). Including here so this branch's own CI passes; the main-track PR will eventually de-dupe via merge. Move the `vi.spyOn(process, 'exit')` from each K-path test into a file-level `beforeAll` / `afterAll` so the spy stays patched across the file's lifetime. Previously, each test restored the spy when it finished, but the K keystroke fires a `wizardSuccessExit` async chain fire-and-forget — under CI load, that chain landed after `exitSpy.mockRestore()` and tripped the real `process.exit`, which vitest surfaced as an unhandled rejection.
kelsonpw
added a commit
that referenced
this pull request
May 14, 2026
Same fix as PR #776 (main-track). Including here so this branch's own CI stays deterministically green; the main-track PR will eventually de-dupe via merge. Without this, the K-keystroke fires a fire-and-forget `wizardSuccessExit` chain that races `exitSpy.mockRestore()` and surfaces an unhandled rejection on CI Node 22 / 24 under load.
kelsonpw
added a commit
that referenced
this pull request
May 14, 2026
Same fix as PR #776 (main-track). Including here so this branch's own CI stays deterministically green; the main-track PR will eventually de-dupe via merge. Without this, the K-keystroke fires a fire-and-forget `wizardSuccessExit` chain that races `exitSpy.mockRestore()` and surfaces an unhandled rejection on CI Node 22 / 24 under load.
kelsonpw
added a commit
that referenced
this pull request
May 14, 2026
Same fix as PR #776 (main-track). Including here so this branch's own CI stays deterministically green; the main-track PR will eventually de-dupe via merge. Without this, the K-keystroke fires a fire-and-forget `wizardSuccessExit` chain that races `exitSpy.mockRestore()` and surfaces an unhandled rejection on CI Node 22 / 24 under load.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The K-keystroke tests in
OutroScreen.preserveFiles.test.tsxwereusing a per-test
vi.spyOn(process, 'exit').mockImplementation(...)pattern paired with
exitSpy.mockRestore()in cleanup. The Kkeystroke triggers a fire-and-forget
wizardSuccessExit(10)chainwhich is fully asynchronous — under CI load the chain landed AFTER
the spy was restored, hit the real
process.exit, and vitest'sinterceptor surfaced it as an unhandled rejection 24s+ after the
file's tests reported green.
This same flake recurred across six salvage PRs (#765–771).
Fix
Move the
vi.spyOn(process, 'exit')to a file-levelbeforeAll/afterAll, so there is no window between testcompletion and spy restore where the real
process.exitisreachable.
Test plan
OutroScreen.preserveFiles.test.tsx— all 6 tests pass locally🤖 Generated with Claude Code
Note
Low Risk
Low risk: test-harness-only change that adjusts
process.exitstubbing scope to eliminate CI flakiness, with no production behavior impact.Overview
Prevents CI flakes in
OutroScreen.preserveFiles.test.tsxby moving theprocess.exitspy from per-test setup/teardown to a file-levelbeforeAll/afterAll, avoiding a race where an asyncwizardSuccessExitcall could hit the real exit aftermockRestore().Removes redundant per-test
process.exitspies/restore calls and updates the Vitest imports accordingly.Reviewed by Cursor Bugbot for commit b25f7a6. Bugbot is set up for automated code reviews on this repo. Configure here.