Repository navigation
feat(tui-test): test terminal queries before startup completes - #36
Closed
factory-ain3sh wants to merge 1 commit into
Closed
factory-ain3sh wants to merge 1 commit into
factory-ain3sh wants to merge 1 commit into
Conversation
Install synchronous onSpawn hooks before PTY output subscription so tests can respond to terminal queries before the runner's readiness wait ends. Expose raw output with disposable onData subscriptions and preserve the existing trace and rendering path. Cover immediate, delayed, silent, and failed-setup cases with real PTYs. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
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.
Description
What
Tests can observe and answer terminal queries from the first PTY output, before startup readiness completes. Five real-PTY cases pass; disabling raw-output delivery makes all four dependent cases fail.
Why
The runner can wait five seconds before
beforeEachand test callbacks. Terminal probes with shorter deadlines have already timed out by then, so those callbacks cannot test startup interactions.How
test.onSpawninstalls synchronous observers before the terminal subscribes to PTY output.terminal.onDataexposes raw chunks with an unsubscribe function. Trace recording and xterm rendering keep their existing path.Change Shape
Related Issue
Part of CLI-2240.
This is the prerequisite harness change for the Factory CLI startup-overlap regression tests. The CLI pins
26d49bdb26d81102220738dc291f552046e6e207; merge this PR before its CLI consumer.Reviewer Guide
Review depth: Standard. Additive public API at a timing-sensitive boundary.
src/terminal/term.ts: observers register before output delivery; exit, kill, and setup failure clean up listeners.src/runner/worker.tsandsrc/test/: suite inheritance and hook execution order.test/terminal-startup.e2e.test.ts: immediate/delayed replies, silence, unsubscribe, fresh per-test observers, and setup failure.The README documents the new contract. Its other whitespace changes come from the configured formatter.
Risk & Impact
Hooks must remain synchronous; asynchronous setup belongs in
beforeSpawn. Chunks can split escape sequences, and late subscriptions do not replay previous output. Observers run on the output-delivery path, so expensive callbacks can delay a test.Existing users need not register a hook or subscriber. No readiness timeout changes.
Contract Delta
test.onSpawn((terminal) => void): synchronous, outermost-first, once per terminal.terminal.onData((chunk) => void): () => void: future raw output only; subscriptions end on exit/kill.Verification
Behavior verified @
26d49bdb: five targeted PTY tests pass on Linux. Removing the generated raw-output emit line fails four dependent tests while the setup-error control passes; rebuilding restores five passes.Sentinel test:
test/terminal-startup.e2e.test.ts, “answers a startup query before test callbacks and preserves rendering.”Rerun:
npm run build, thennode index.js terminal-startup.e2e.test.ts.Not tested locally: macOS, Windows, Bun, and the full Node version matrix. Existing CI owns those lanes.
Standard validators: TypeScript build, scoped ESLint and Prettier pass. Slop-scan exits 1 on three pre-existing catches shifted by seven lines; all three were verified inside an unchanged 371-line block, with unchanged score and no new findings.