Skip to content

refactor: production code no longer sniffs for a test mock - #214

Merged
fstubner merged 1 commit into
mainfrom
refactor/remove-test-shim
Sep 3, 2026
Merged

refactor: production code no longer sniffs for a test mock#214
fstubner merged 1 commit into
mainfrom
refactor/remove-test-shim

Conversation

@fstubner

@fstubner fstubner commented Sep 3, 2026

Copy link
Copy Markdown
Owner

streamSubprocess inspected runSubprocess for vitest's .mock property and, when it found one, ran a different implementation that synthesised stream events from a buffered result.

Its comment claimed this "still exercised the streaming code path in production". It exercised it nowhere: every dispatcher suite mocked runSubprocess, so every dispatcher suite ran the adapter, and the real streaming implementation had no coverage from any test that drove a dispatcher.

What changed

  • The adapter moves to tests/support/buffered-stream.ts.
  • The six suites that relied on it now mock streamSubprocess — the function the dispatchers actually call — and point it at their existing buffered mock.
  • Every assertion still reads argv, env and stdin off that same mock, so the suite bodies are unchanged. The diff is 19 added lines per suite and nothing removed.
  • src/ no longer contains any reference to a mock shape.

Sabotage check

Dropping the stdout emit from the real streamer fails 12 tests across stream-subprocess.test.ts and generic-cli-real-subprocess.test.ts — the two suites that spawn real processes. That is what confirms the real path is covered now that nothing reroutes around it.

What this does not do

The six rewired suites still drive a stub, so they still do not exercise real piping — a stub yielding one stdout chunk cannot show a partial line surviving across two reads. That is deliberate and now stated in each file: the real-subprocess suites cover it, and these cover the ordering contract per harness protocol.

npm run check: 1219 passed, 8 skipped, exit 0.

`streamSubprocess` inspected `runSubprocess` for vitest's `.mock` property
and, when it found one, ran a completely different implementation that
synthesised stream events from a buffered result. Its comment claimed this
"still exercised the streaming code path in production". It exercised it
nowhere: every dispatcher suite mocked `runSubprocess`, so every dispatcher
suite ran the adapter, and the real streaming implementation had no coverage
from any test that drove a dispatcher.

The adapter moves to tests/support/buffered-stream.ts, where the six suites
that want it opt in by mocking `streamSubprocess` — the function the
dispatchers actually call — and pointing it at their existing buffered mock.
Every assertion still reads argv, env and stdin off that same mock, so the
suites' bodies are unchanged.

Sabotage: dropping the stdout emit from the real streamer fails 12 tests
across stream-subprocess.test.ts and generic-cli-real-subprocess.test.ts,
confirming the real path is covered by the two suites that spawn processes.
@fstubner
fstubner merged commit f690a07 into main Sep 3, 2026
4 checks passed
@fstubner
fstubner deleted the refactor/remove-test-shim branch September 3, 2026 21:03
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