@@ -36,7 +36,9 @@ function maybeCompactCodexAppServerSession(
3636 ) ;
3737}
3838
39- async function writeTestBinding ( options : { authProfileId ?: string } = { } ) : Promise < string > {
39+ async function writeTestBinding (
40+ options : Partial < Parameters < typeof writeCodexAppServerBinding > [ 1 ] > = { } ,
41+ ) : Promise < string > {
4042 const sessionFile = path . join ( tempDir , "session.jsonl" ) ;
4143 await writeCodexAppServerBinding ( sessionFile , {
4244 threadId : "thread-1" ,
@@ -336,18 +338,30 @@ describe("maybeCompactCodexAppServerSession", () => {
336338 expect ( result . result ) . toBeUndefined ( ) ;
337339 } ) ;
338340
339- it ( "clears stale thread bindings and reports failed native compaction" , async ( ) => {
341+ it ( "preserves stale thread binding metadata for recovery and reports failed native compaction" , async ( ) => {
340342 const fake = createFakeCodexClient ( ) ;
341343 fake . request . mockRejectedValueOnce ( new Error ( "thread not found: thread-1" ) ) ;
342344 setCodexAppServerClientFactoryForTest ( async ( ) => fake . client ) ;
343- const sessionFile = await writeTestBinding ( ) ;
345+ const sessionFile = await writeTestBinding ( {
346+ authProfileId : "openai-codex:work" ,
347+ model : "gpt-5.4-mini" ,
348+ approvalPolicy : "on-request" ,
349+ sandbox : "workspace-write" ,
350+ serviceTier : "priority" ,
351+ } ) ;
344352
345353 const result = requireCompactResult (
346354 await startCompaction ( sessionFile , { currentTokenCount : 456 } ) ,
347355 ) ;
348356
349357 expect ( fake . request ) . toHaveBeenCalledWith ( "thread/compact/start" , { threadId : "thread-1" } ) ;
350- expect ( await readCodexAppServerBinding ( sessionFile ) ) . toBeUndefined ( ) ;
358+ const preservedBinding = await readCodexAppServerBinding ( sessionFile ) ;
359+ expect ( preservedBinding ?. threadId ) . toBe ( "thread-1" ) ;
360+ expect ( preservedBinding ?. authProfileId ) . toBe ( "openai-codex:work" ) ;
361+ expect ( preservedBinding ?. model ) . toBe ( "gpt-5.4-mini" ) ;
362+ expect ( preservedBinding ?. approvalPolicy ) . toBe ( "on-request" ) ;
363+ expect ( preservedBinding ?. sandbox ) . toBe ( "workspace-write" ) ;
364+ expect ( preservedBinding ?. serviceTier ) . toBe ( "priority" ) ;
351365 expect ( result . ok ) . toBe ( false ) ;
352366 expect ( result . compacted ) . toBe ( false ) ;
353367 expect ( result . reason ) . toBe ( "thread not found: thread-1" ) ;
0 commit comments