@@ -10,7 +10,13 @@ import { describe, expect, test, afterEach } from "bun:test";
1010import { mkdtempSync , mkdirSync , writeFileSync , rmSync } from "node:fs" ;
1111import { tmpdir } from "node:os" ;
1212import { join } from "node:path" ;
13- import { findCodexRolloutByThreadId , getLastCodexMessage , getLatestCodexPlan } from "./codex-session" ;
13+ import {
14+ findCodexRolloutByThreadId ,
15+ getCodexStopSkipReason ,
16+ getLastCodexMessage ,
17+ getLatestCodexPlan ,
18+ logCodexStopSkip ,
19+ } from "./codex-session" ;
1420
1521// --- Fixture Helpers ---
1622
@@ -389,6 +395,7 @@ describe("getLatestCodexPlan", () => {
389395 text : "Authoritative plan item" ,
390396 source : "plan-item" ,
391397 } ) ;
398+
392399 } ) ;
393400
394401 test ( "falls back to raw proposed_plan blocks for plan-only assistant replies" , ( ) => {
@@ -408,6 +415,40 @@ describe("getLatestCodexPlan", () => {
408415 } ) ;
409416 } ) ;
410417
418+ describe ( "Codex Stop skip diagnostics" , ( ) => {
419+ test ( "classifies a missing Stop turn id without reading stale plan content" , ( ) => {
420+ expect ( getCodexStopSkipReason ( "not-read.jsonl" ) ) . toBe ( "missing-turn-id" ) ;
421+ } ) ;
422+
423+ test ( "requires an id-carrying rollout turn marker" , ( ) => {
424+ const turnId = "turn-without-marker" ;
425+ const path = writeTempRollout (
426+ buildRollout (
427+ sessionMeta ( ) ,
428+ turnStarted ( "other-turn" ) ,
429+ completedPlanItem ( "Plan item without matching start marker" , turnId ) ,
430+ ) ,
431+ ) ;
432+
433+ expect ( getCodexStopSkipReason ( path , turnId ) ) . toBe ( "missing-turn-marker" ) ;
434+ } ) ;
435+
436+ test ( "writes the exact skip breadcrumb only when debug is enabled" , ( ) => {
437+ const messages : string [ ] = [ ] ;
438+ const write = ( message : string ) => messages . push ( message ) ;
439+
440+ logCodexStopSkip ( "missing-turn-id" , { debug : "" , write } ) ;
441+ expect ( messages ) . toEqual ( [ ] ) ;
442+
443+ logCodexStopSkip ( "missing-turn-id" , { debug : "1" , write } ) ;
444+ logCodexStopSkip ( "missing-turn-marker" , { debug : "1" , write } ) ;
445+ expect ( messages ) . toEqual ( [
446+ "[DEBUG] Codex Stop plan review skipped: missing Stop payload turn_id." ,
447+ "[DEBUG] Codex Stop plan review skipped: missing id-carrying rollout turn marker." ,
448+ ] ) ;
449+ } ) ;
450+ } ) ;
451+
411452 test ( "extracts plan blocks surrounded by assistant prose" , ( ) => {
412453 const turnId = "turn-prose" ;
413454 const path = writeTempRollout (
0 commit comments