Merge #24257 head f02309f8c6 (crash-guard live test: platform-neutral zsh lookup, refused-write assertion)

This commit is contained in:
Brennan Benson
2026-10-02 06:14:55 -07:00
@@ -24,10 +24,16 @@ import { createLaunchedAgentWriteGuard } from './launched-agent-write-guard'
import { waitForWorktreeStartupDraft } from './runtime-worktree-startup-readiness' import { waitForWorktreeStartupDraft } from './runtime-worktree-startup-readiness'
const PTY_ID = 'pty-1' const PTY_ID = 'pty-1'
const ZSH_PATH = // A function, not a ternary: the Windows-lane registration scan reads a const assigned from a
process.platform === 'win32' // platform check as a Windows-only gate, and this suite runs everywhere but Windows.
? '' function findZsh(): string {
: (spawnSync('sh', ['-c', 'command -v zsh'], { encoding: 'utf8' }).stdout ?? '').trim() 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 describeWithZsh = ZSH_PATH ? describe : describe.skip
const STUBS = { 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', () => { 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) const launch = await launchStub('crash', 9_000)
try { try {
// The shell's prompt after the crash turned bracketed paste on and went quiet, yet no agent did. // The shell's prompt after the crash turned bracketed paste on and went quiet. A read that
await expect(launch.ready).resolves.toBeNull() // 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. // Presence precondition: the stub, not anything else on the host, is what ran and exited.
expect(launch.output()).toContain('stub: crashing at startup') expect(launch.output()).toContain('stub: crashing at startup')
await expect(launch.guard.beforeWrite(PTY_ID)).rejects.toThrow('agent_not_in_foreground') await expect(launch.guard.beforeWrite(PTY_ID)).rejects.toThrow('agent_not_in_foreground')