@@ -67,6 +67,22 @@ async function healthy(port: number): Promise<boolean> {
6767 }
6868}
6969
70+ /**
71+ * Startup budget for the proxy, generous on CI and tight locally.
72+ *
73+ * The subject of this test is signal forwarding, not startup latency, so the
74+ * budget only has to be long enough that a slow machine does not read as an
75+ * orphaned proxy. Locally the spawn is healthy in ~800ms; a shared CI runner
76+ * building four shards plus a macOS suite in parallel is a different machine
77+ * entirely, and 20s was not enough for it twice on 2026-09-03.
78+ *
79+ * Raising this cannot hide the regression the test guards: an orphaned proxy
80+ * fails at step 4 (the port never frees), which has its own deadline. What a
81+ * too-short startup budget DOES hide is that distinction — it fails before the
82+ * shutdown path runs at all.
83+ */
84+ const STARTUP_BUDGET_MS = process . env . CI ? 60_000 : 20_000 ;
85+
7086async function waitUntil ( fn : ( ) => Promise < boolean > , deadlineMs : number ) : Promise < boolean > {
7187 const end = Date . now ( ) + deadlineMs ;
7288 while ( Date . now ( ) < end ) {
@@ -91,8 +107,17 @@ describe.skipIf(!runnable)("ocx launcher graceful shutdown", () => {
91107 const codexConfig = join ( home , "config.toml" ) ;
92108 writeFileSync ( codexConfig , 'model = "gpt-5.1"\n' ) ;
93109
110+ // stdout/stderr are CAPTURED, not discarded.
111+ //
112+ // This test failed twice on the v2.41.0 promotion at exactly 20s -- the
113+ // startup deadline below, not the shutdown path this test is named for.
114+ // With `stdio: "ignore"` the failure said only `expect(up).toBe(true)`:
115+ // no proxy log, no exit code, no way to tell a slow runner from a real
116+ // startup regression. Locally the same spawn is healthy in ~800ms, so a
117+ // 25x margin is already generous and the missing evidence was the actual
118+ // problem.
94119 const child = spawn ( "node" , [ BIN_OCX , "start" , "--port" , String ( port ) ] , {
95- stdio : "ignore" ,
120+ stdio : [ "ignore" , "pipe" , "pipe" ] ,
96121 env : {
97122 ...process . env ,
98123 HOME : identity . homeDir ,
@@ -105,11 +130,25 @@ describe.skipIf(!runnable)("ocx launcher graceful shutdown", () => {
105130 spawned . push ( child ) ;
106131
107132 let exited = false ;
133+ let exitCode : number | null = null ;
134+ let exitSignal : NodeJS . Signals | null = null ;
108135 child . on ( "exit" , ( ) => { exited = true ; } ) ;
136+ child . on ( "exit" , ( code , sig ) => { exitCode = code ; exitSignal = sig ; } ) ;
137+
138+ let output = "" ;
139+ child . stdout ?. on ( "data" , chunk => { output += String ( chunk ) ; } ) ;
140+ child . stderr ?. on ( "data" , chunk => { output += String ( chunk ) ; } ) ;
109141
110142 // 1. Proxy comes up + injected the Codex config (Design B root override on loopback).
111- const up = await waitUntil ( ( ) => healthy ( port ) , 20_000 ) ;
112- expect ( up ) . toBe ( true ) ;
143+ const up = await waitUntil ( ( ) => healthy ( port ) , STARTUP_BUDGET_MS ) ;
144+ if ( ! up ) {
145+ // Name what actually went wrong instead of asserting a bare boolean.
146+ const died = exited ? ` The launcher EXITED (code ${ exitCode } , signal ${ exitSignal } ).` : " The launcher was still running." ;
147+ throw new Error (
148+ `The proxy never answered /healthz on port ${ port } within ${ STARTUP_BUDGET_MS } ms.${ died } `
149+ + ` Launcher output:\n${ output . trim ( ) || "(none)" } ` ,
150+ ) ;
151+ }
113152 expect ( existsSync ( join ( home , "ocx.pid" ) ) ) . toBe ( true ) ;
114153 const injected = readFileSync ( codexConfig , "utf8" ) ;
115154 expect ( injected ) . toContain ( "# Auto-injected by opencodex" ) ;
@@ -132,7 +171,7 @@ describe.skipIf(!runnable)("ocx launcher graceful shutdown", () => {
132171 expect ( existsSync ( join ( home , "runtime-port.json" ) ) ) . toBe ( false ) ;
133172 expect ( readFileSync ( codexConfig , "utf8" ) ) . not . toContain ( "opencodex" ) ;
134173 } ,
135- 45_000 ,
174+ STARTUP_BUDGET_MS + 40_000 ,
136175 ) ;
137176 }
138177} ) ;
0 commit comments