Skip to content
This repository was archived by the owner on Jun 7, 2026. It is now read-only.

refactor(test): replace setTimeout with deterministic spawn polling - #63

Merged
matthew-petty merged 5 commits into
mainfrom
refactor/29-deterministic-spawn-polling
Dec 26, 2025
Merged

refactor(test): replace setTimeout with deterministic spawn polling#63
matthew-petty merged 5 commits into
mainfrom
refactor/29-deterministic-spawn-polling

Conversation

@matthew-petty

Copy link
Copy Markdown
Member

Summary

  • Extracted afterSpawnCalled helper from health.test.ts to shared helpers.ts
  • Replaced all setTimeout patterns with deterministic spawn polling across test files
  • Eliminates flaky test timing issues in CI environments

Changes

File Replacements
helpers.ts Added afterSpawnCalled helper function
health.test.ts Imported helper from shared module
stream.test.ts 16 replacements
generate.test.ts 11 replacements
app.test.ts 8 replacements
sdk.integration.test.ts 6 replacements

How it works

The afterSpawnCalled helper polls every 1ms until mockSpawn has been called, then executes the callback. This eliminates race conditions where setTimeout(50) might fire before or after the actual spawn call depending on CI load.

// Before - timing-dependent and flaky
setTimeout(() => {
  mockProc.emit("close", 0, null);
}, 50);

// After - deterministic
afterSpawnCalled(mockSpawn, () => {
  mockProc.emit("close", 0, null);
});

Closes #29

Test plan

  • All 83 tests pass locally
  • Pre-commit hooks pass (Biome, TypeScript, secret scanning)

Move the deterministic spawn polling helper from health.test.ts to the
shared helpers.ts file so it can be reused across all test files.

Part of #29
Replace setTimeout patterns with deterministic spawn polling to
eliminate flaky test timing issues.

Part of #29
Replace setTimeout patterns with deterministic spawn polling to
eliminate flaky test timing issues.

Part of #29
Replace setTimeout patterns with deterministic spawn polling to
eliminate flaky test timing issues.

Part of #29
Replace setTimeout patterns with deterministic spawn polling to
eliminate flaky test timing issues. Combined staggered streaming
timeouts into a single afterSpawnCalled callback.

Part of #29
@codecov

codecov Bot commented Dec 26, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@matthew-petty
matthew-petty merged commit bd2a7c6 into main Dec 26, 2025
3 checks passed
@matthew-petty
matthew-petty deleted the refactor/29-deterministic-spawn-polling branch December 26, 2025 15:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(test): replace setTimeout with deterministic spawn polling pattern

1 participant