@@ -2791,8 +2791,52 @@ describe("CodexAdapterV2 post-settle continuation", () => {
27912791 Effect . scoped (
27922792 Effect . gen ( function * ( ) {
27932793 const nativeThreadId = "session-approval-thread" ;
2794- const firstTurnId = "session-approval-turn-1" ;
2795- const secondTurnId = "session-approval-turn-2" ;
2794+ const turnIds = [
2795+ "session-approval-turn-1" ,
2796+ "session-approval-turn-2" ,
2797+ "session-approval-turn-3" ,
2798+ ] ;
2799+ const turnPolicies = {
2800+ "approval-required" : {
2801+ approvalPolicy : "untrusted" ,
2802+ approvalsReviewer : "user" ,
2803+ sandboxPolicy : { type : "readOnly" } ,
2804+ } ,
2805+ "full-access" : {
2806+ approvalPolicy : "never" ,
2807+ approvalsReviewer : "user" ,
2808+ sandboxPolicy : { type : "dangerFullAccess" } ,
2809+ } ,
2810+ } as const ;
2811+ const turnModes = [ "approval-required" , "full-access" , "approval-required" ] as const ;
2812+ const turnText = ( index : number ) => `Review round ${ index + 1 } .` ;
2813+ const startTurn = ( index : number ) : ReadonlyArray < CodexReplay . CodexAppServerReplayEntry > => [
2814+ {
2815+ type : "expect_outbound" ,
2816+ label : `turn ${ index + 1 } turn/start` ,
2817+ frame : {
2818+ id : 3 + index ,
2819+ method : "turn/start" ,
2820+ params : {
2821+ threadId : nativeThreadId ,
2822+ input : [ { type : "text" , text : turnText ( index ) } ] ,
2823+ cwd : "/workspace" ,
2824+ model : "gpt-5.4" ,
2825+ ...turnPolicies [ turnModes [ index ] ! ] ,
2826+ summary : "detailed" ,
2827+ } ,
2828+ } ,
2829+ } ,
2830+ {
2831+ type : "emit_inbound" ,
2832+ label : `turn ${ index + 1 } turn/start` ,
2833+ frame : {
2834+ id : 3 + index ,
2835+ result : { turn : makeCodexReplayTurn ( { id : turnIds [ index ] ! , status : "inProgress" } ) } ,
2836+ } ,
2837+ } ,
2838+ turnEvent ( "turn/started" , turnIds [ index ] ! ) ,
2839+ ] ;
27962840 const approval = ( input : {
27972841 readonly id : number ;
27982842 readonly turnId : string ;
@@ -2843,69 +2887,46 @@ describe("CodexAdapterV2 post-settle continuation", () => {
28432887 entries : [
28442888 ...codexReplayPreamble ( {
28452889 nativeThreadId,
2846- nativeTurnId : firstTurnId ,
2847- prompt : "Review it." ,
2848- } ) ,
2890+ nativeTurnId : turnIds [ 0 ] ! ,
2891+ prompt : turnText ( 0 ) ,
2892+ } ) . slice ( 0 , - 3 ) ,
2893+ ...startTurn ( 0 ) ,
28492894 ...approval ( {
28502895 id : 100 ,
2851- turnId : firstTurnId ,
2896+ turnId : turnIds [ 0 ] ! ,
28522897 kind : "commandExecution" ,
28532898 itemId : "first-command" ,
28542899 decision : "acceptForSession" ,
28552900 } ) ,
28562901 // Answered without asking: Codex alone would ask for every new command.
28572902 ...approval ( {
28582903 id : 101 ,
2859- turnId : firstTurnId ,
2904+ turnId : turnIds [ 0 ] ! ,
28602905 kind : "commandExecution" ,
28612906 itemId : "second-command" ,
28622907 decision : "acceptForSession" ,
28632908 } ) ,
28642909 // Only commands were allowed, so a file change still asks.
28652910 ...approval ( {
28662911 id : 102 ,
2867- turnId : firstTurnId ,
2912+ turnId : turnIds [ 0 ] ! ,
28682913 kind : "fileChange" ,
28692914 itemId : "first-patch" ,
28702915 decision : "accept" ,
28712916 } ) ,
2872- turnEvent ( "turn/completed" , firstTurnId ) ,
2873- {
2874- type : "expect_outbound" ,
2875- label : "supervised turn/start" ,
2876- frame : {
2877- id : 4 ,
2878- method : "turn/start" ,
2879- params : {
2880- threadId : nativeThreadId ,
2881- input : [ { type : "text" , text : "Again, supervised." } ] ,
2882- cwd : "/workspace" ,
2883- model : "gpt-5.4" ,
2884- approvalPolicy : "untrusted" ,
2885- approvalsReviewer : "user" ,
2886- sandboxPolicy : { type : "readOnly" } ,
2887- summary : "detailed" ,
2888- } ,
2889- } ,
2890- } ,
2891- {
2892- type : "emit_inbound" ,
2893- label : "supervised turn/start" ,
2894- frame : {
2895- id : 4 ,
2896- result : { turn : makeCodexReplayTurn ( { id : secondTurnId , status : "inProgress" } ) } ,
2897- } ,
2898- } ,
2899- turnEvent ( "turn/started" , secondTurnId ) ,
2900- // A runtime mode change takes the allowance back.
2917+ turnEvent ( "turn/completed" , turnIds [ 0 ] ! ) ,
2918+ ...startTurn ( 1 ) ,
2919+ turnEvent ( "turn/completed" , turnIds [ 1 ] ! ) ,
2920+ ...startTurn ( 2 ) ,
2921+ // Back in the first mode, the allowance does not come back.
29012922 ...approval ( {
29022923 id : 103 ,
2903- turnId : secondTurnId ,
2924+ turnId : turnIds [ 2 ] ! ,
29042925 kind : "commandExecution" ,
29052926 itemId : "third-command" ,
29062927 decision : "accept" ,
29072928 } ) ,
2908- turnEvent ( "turn/completed" , secondTurnId ) ,
2929+ turnEvent ( "turn/completed" , turnIds [ 2 ] ! ) ,
29092930 ] ,
29102931 } ) ;
29112932 const harness = yield * makeCodexReplayHarness ( transcript ) ;
@@ -2930,32 +2951,31 @@ describe("CodexAdapterV2 post-settle continuation", () => {
29302951 yield * harness . runtime . respondToRuntimeRequest ( { requestId : request . id , decision } ) ;
29312952 } ) ;
29322953
2933- yield * harness . runtime . startTurn (
2934- makeCodexTestTurnInput ( {
2935- threadId : harness . threadId ,
2936- providerThread : harness . providerThread ,
2937- now : yield * DateTime . now ,
2938- attemptId : RunAttemptId . make ( "session-approvals-1" ) ,
2939- text : "Review it." ,
2940- } ) ,
2941- ) ;
2954+ const runTurn = ( index : number ) =>
2955+ Effect . gen ( function * ( ) {
2956+ yield * harness . runtime . startTurn ( {
2957+ ...makeCodexTestTurnInput ( {
2958+ threadId : harness . threadId ,
2959+ providerThread : harness . providerThread ,
2960+ now : yield * DateTime . now ,
2961+ attemptId : RunAttemptId . make ( `session-approvals-${ index + 1 } ` ) ,
2962+ text : turnText ( index ) ,
2963+ } ) ,
2964+ runOrdinal : index + 1 ,
2965+ providerTurnOrdinal : index + 1 ,
2966+ runtimePolicy : { ...CODEX_TEST_RUNTIME_POLICY , runtimeMode : turnModes [ index ] ! } ,
2967+ } ) ;
2968+ } ) ;
2969+
2970+ yield * runTurn ( 0 ) ;
29422971 yield * answer ( 1 , "command" , "acceptForSession" ) ;
29432972 yield * answer ( 2 , "file-change" , "accept" ) ;
2944- yield * harness . firstTerminal ;
2945- yield * harness . runtime . startTurn ( {
2946- ...makeCodexTestTurnInput ( {
2947- threadId : harness . threadId ,
2948- providerThread : harness . providerThread ,
2949- now : yield * DateTime . now ,
2950- attemptId : RunAttemptId . make ( "session-approvals-2" ) ,
2951- text : "Again, supervised." ,
2952- } ) ,
2953- runOrdinal : 2 ,
2954- providerTurnOrdinal : 2 ,
2955- runtimePolicy : { ...CODEX_TEST_RUNTIME_POLICY , runtimeMode : "approval-required" } ,
2956- } ) ;
2973+ yield * awaitUntil ( ( ) => harness . terminalEvents ( ) . length === 1 , "turn 1" ) ;
2974+ yield * runTurn ( 1 ) ;
2975+ yield * awaitUntil ( ( ) => harness . terminalEvents ( ) . length === 2 , "turn 2" ) ;
2976+ yield * runTurn ( 2 ) ;
29572977 yield * answer ( 3 , "command" , "accept" ) ;
2958- yield * awaitUntil ( ( ) => harness . terminalEvents ( ) . length === 2 , "supervised turn" ) ;
2978+ yield * awaitUntil ( ( ) => harness . terminalEvents ( ) . length === 3 , "turn 3 " ) ;
29592979 assert . lengthOf ( requests ( ) , 3 ) ;
29602980 } ) . pipe (
29612981 Effect . provide (
0 commit comments