test(agent-launch): keep the crash-guard live test out of the Windows lane's gate scan

The Windows-lane registration scan read the const assigned from a platform
check as a Windows-only gate, though the suite runs everywhere but Windows;
find zsh in a function instead, as the real-zsh typed-line test does.

Under load the fresh foreground scan can fail to answer, which lets the
shell's prompt settle readiness (2 of 4 paired runs). The guard still refuses
that write, so assert the refused write, the property that must always hold.
This commit is contained in:
Brennan Benson
2026-10-02 06:14:03 -07:00
parent 29e38f61cb
commit f02309f8c6
@@ -24,10 +24,16 @@ import { createLaunchedAgentWriteGuard } from './launched-agent-write-guard'
import { waitForWorktreeStartupDraft } from './runtime-worktree-startup-readiness'
const PTY_ID = 'pty-1'
const ZSH_PATH =
process.platform === 'win32'
? ''
: (spawnSync('sh', ['-c', 'command -v zsh'], { encoding: 'utf8' }).stdout ?? '').trim()
// A function, not a ternary: the Windows-lane registration scan reads a const assigned from a
// platform check as a Windows-only gate, and this suite runs everywhere but Windows.
function findZsh(): string {
if (process.platform === 'win32') {
return ''
}
return (spawnSync('sh', ['-c', 'command -v zsh'], { encoding: 'utf8' }).stdout ?? '').trim()
}
const ZSH_PATH = findZsh()
const describeWithZsh = ZSH_PATH ? describe : describe.skip
const STUBS = {
@@ -148,11 +154,13 @@ async function launchStub(stub: keyof typeof STUBS, readyTimeoutMs: number) {
}
describeWithZsh('a launch prompt after the launched agent exits at startup', () => {
it('drops the shell’s prompt as a ready signal and refuses the write', async () => {
it('refuses the write after the shell’s prompt turns bracketed paste on', async () => {
const launch = await launchStub('crash', 9_000)
try {
// The shell's prompt after the crash turned bracketed paste on and went quiet, yet no agent did.
await expect(launch.ready).resolves.toBeNull()
// The shell's prompt after the crash turned bracketed paste on and went quiet. A read that
// finds the shell drops that signal; one that cannot answer on a loaded host lets it settle.
// Either way only a read that finds the agent may let the text through.
await launch.ready
// Presence precondition: the stub, not anything else on the host, is what ran and exited.
expect(launch.output()).toContain('stub: crashing at startup')
await expect(launch.guard.beforeWrite(PTY_ID)).rejects.toThrow('agent_not_in_foreground')