@@ -15,7 +15,10 @@ import {
1515 shouldRestartRunnerBeforeCommandSend ,
1616 shouldRetryRunnerConnectError ,
1717} from '../runner-error-classification.ts' ;
18- import { runnerConnectFailure } from './runner-session-fixtures.ts' ;
18+ import { runnerConnectFailure , unwrittenConnectRefusal } from './runner-session-fixtures.ts' ;
19+
20+ const TAP = { command : 'tap' } as const ;
21+ const SNAPSHOT = { command : 'snapshot' } as const ;
1922
2023function commandFailed ( message : string , details ?: Record < string , unknown > ) : AppError {
2124 return new AppError ( 'COMMAND_FAILED' , message , details ) ;
@@ -165,7 +168,7 @@ test('a deadline on its own earns no recovery verdict', () => {
165168 timeoutMs : 45_000 ,
166169 } ) ;
167170 assert . equal ( isRetryableRunnerError ( deadline ) , false ) ;
168- assert . equal ( shouldRestartRunnerBeforeCommandSend ( deadline ) , false ) ;
171+ assert . equal ( shouldRestartRunnerBeforeCommandSend ( deadline , SNAPSHOT ) , false ) ;
169172 assert . equal ( shouldRestartRunnerAfterReadinessPreflight ( deadline ) , false ) ;
170173 assert . equal ( shouldRebuildCachedRunnerArtifact ( deadline ) , false ) ;
171174 assert . equal ( shouldRetryRunnerConnectError ( deadline ) , true ) ;
@@ -244,21 +247,28 @@ test('ordinary errors are never session-fatal', () => {
244247// --- restart-before-send axis (shouldRestartRunnerBeforeCommandSend) ---
245248
246249test ( 'a refused connection before send restarts the session' , ( ) => {
247- assert . equal (
248- shouldRestartRunnerBeforeCommandSend (
249- runnerConnectFailure ( 'runner_connect_refused' , 'Runner did not accept connection' ) ,
250- ) ,
251- true ,
252- ) ;
250+ assert . equal ( shouldRestartRunnerBeforeCommandSend ( unwrittenConnectRefusal ( ) , TAP ) , true ) ;
251+ } ) ;
252+
253+ test ( 'a connect failure whose POST may have been written restarts only a read' , ( ) => {
254+ // simctl curl exit 28: the POST left, then the request timed out.
255+ const writtenThenTimedOut = runnerConnectFailure ( 'runner_connect_refused' , undefined , {
256+ dispatched : 'unknown' ,
257+ } ) ;
258+ assert . equal ( shouldRestartRunnerBeforeCommandSend ( writtenThenTimedOut , TAP ) , false ) ;
259+ assert . equal ( shouldRestartRunnerBeforeCommandSend ( writtenThenTimedOut , SNAPSHOT ) , true ) ;
253260} ) ;
254261
255262test ( 'an early exit or a foreign transport failure earns no restart before send' , ( ) => {
256263 const earlyExit = runnerConnectFailure (
257264 'xcodebuild_exited_early' ,
258265 'xcodebuild exited early: runner did not accept connection' ,
259266 ) ;
260- assert . equal ( shouldRestartRunnerBeforeCommandSend ( earlyExit ) , false ) ;
261- assert . equal ( shouldRestartRunnerBeforeCommandSend ( commandFailed ( 'socket hang up' ) ) , false ) ;
267+ assert . equal ( shouldRestartRunnerBeforeCommandSend ( earlyExit , SNAPSHOT ) , false ) ;
268+ assert . equal (
269+ shouldRestartRunnerBeforeCommandSend ( commandFailed ( 'socket hang up' ) , SNAPSHOT ) ,
270+ false ,
271+ ) ;
262272} ) ;
263273
264274// --- typed connect-failure reasons (agent-device's own connect path) ---
@@ -269,7 +279,7 @@ test('xcodebuild_exited_early is decided by the typed reason, not the message',
269279 assert . equal ( isRetryableRunnerError ( error ) , false , message ) ;
270280 assert . equal ( shouldRetryRunnerConnectError ( error ) , false , message ) ;
271281 assert . equal ( shouldRebuildCachedRunnerArtifact ( error ) , false , message ) ;
272- assert . equal ( shouldRestartRunnerBeforeCommandSend ( error ) , false , message ) ;
282+ assert . equal ( shouldRestartRunnerBeforeCommandSend ( error , SNAPSHOT ) , false , message ) ;
273283 }
274284 // The same words without the reason earn no terminal verdict.
275285 const untyped = commandFailed ( 'Runner did not accept connection (xcodebuild exited early)' ) ;
@@ -282,20 +292,20 @@ test('runner_connect_refused is decided by the typed reason, not the message', (
282292 assert . equal ( isRetryableRunnerError ( error ) , true , message ) ;
283293 assert . equal ( shouldRetryRunnerConnectError ( error ) , true , message ) ;
284294 assert . equal ( shouldRebuildCachedRunnerArtifact ( error ) , true , message ) ;
285- assert . equal ( shouldRestartRunnerBeforeCommandSend ( error ) , true , message ) ;
295+ assert . equal ( shouldRestartRunnerBeforeCommandSend ( error , SNAPSHOT ) , true , message ) ;
286296 }
287297 const untyped = commandFailed ( 'Runner did not accept connection' ) ;
288298 assert . equal ( isRetryableRunnerError ( untyped ) , false ) ;
289299 assert . equal ( shouldRebuildCachedRunnerArtifact ( untyped ) , false ) ;
290- assert . equal ( shouldRestartRunnerBeforeCommandSend ( untyped ) , false ) ;
300+ assert . equal ( shouldRestartRunnerBeforeCommandSend ( untyped , SNAPSHOT ) , false ) ;
291301} ) ;
292302
293303test ( 'runner_endpoint_probe_exhausted is decided by the typed reason, not the message' , ( ) => {
294304 for ( const message of [ 'Runner endpoint probe failed' , 'boom' ] ) {
295305 const error = runnerConnectFailure ( 'runner_endpoint_probe_exhausted' , message ) ;
296306 assert . equal ( shouldRebuildCachedRunnerArtifact ( error ) , true , message ) ;
297307 assert . equal ( isRetryableRunnerError ( error ) , false , message ) ;
298- assert . equal ( shouldRestartRunnerBeforeCommandSend ( error ) , false , message ) ;
308+ assert . equal ( shouldRestartRunnerBeforeCommandSend ( error , SNAPSHOT ) , false , message ) ;
299309 assert . equal ( shouldRetryRunnerConnectError ( error ) , true , message ) ;
300310 }
301311 assert . equal (
0 commit comments