@@ -11685,28 +11685,46 @@ describe("CodexAdapterV2 post-settle continuation", () => {
1168511685 const startApprovalTurn = (
1168611686 scenario : string ,
1168711687 entries : ReadonlyArray < CodexReplay . CodexAppServerReplayEntry > ,
11688+ runtimeMode : "approval-required" | "full-access" = "approval-required" ,
1168811689 ) =>
1168911690 Effect . gen ( function * ( ) {
1169011691 const pending = yield * Queue . unbounded < OrchestrationV2RuntimeRequest > ( ) ;
1169111692 const harness = yield * makeCodexReplayHarness (
1169211693 makeCodexReplayTranscript ( {
1169311694 scenario,
11694- entries : [ ...codexReplayPreamble ( { nativeThreadId, nativeTurnId, prompt } ) , ...entries ] ,
11695+ entries : [
11696+ ...codexReplayPreamble ( {
11697+ nativeThreadId,
11698+ nativeTurnId,
11699+ prompt,
11700+ ...( runtimeMode === "full-access"
11701+ ? { }
11702+ : {
11703+ turnPolicy : {
11704+ approvalPolicy : "untrusted" as const ,
11705+ sandboxPolicy : { type : "readOnly" as const } ,
11706+ } ,
11707+ } ) ,
11708+ } ) ,
11709+ ...entries ,
11710+ ] ,
1169511711 } ) ,
1169611712 ( event ) =>
1169711713 event . type === "runtime_request.updated" && event . runtimeRequest . status === "pending"
1169811714 ? Queue . offer ( pending , event . runtimeRequest )
1169911715 : Effect . void ,
1170011716 ) ;
11701- yield * harness . runtime . startTurn (
11702- makeCodexTestTurnInput ( {
11703- threadId : harness . threadId ,
11704- providerThread : harness . providerThread ,
11705- now : yield * DateTime . now ,
11706- attemptId : RunAttemptId . make ( `${ scenario } -attempt` ) ,
11707- text : prompt ,
11708- } ) ,
11709- ) ;
11717+ const turnInput = makeCodexTestTurnInput ( {
11718+ threadId : harness . threadId ,
11719+ providerThread : harness . providerThread ,
11720+ now : yield * DateTime . now ,
11721+ attemptId : RunAttemptId . make ( `${ scenario } -attempt` ) ,
11722+ text : prompt ,
11723+ } ) ;
11724+ yield * harness . runtime . startTurn ( {
11725+ ...turnInput ,
11726+ runtimePolicy : { ...turnInput . runtimePolicy , runtimeMode } ,
11727+ } ) ;
1171011728 return {
1171111729 harness,
1171211730 answerNext : Queue . take ( pending ) . pipe (
@@ -11917,6 +11935,140 @@ describe("CodexAdapterV2 post-settle continuation", () => {
1191711935 ) ,
1191811936 ) ,
1191911937 ) ;
11938+
11939+ const approvalMethods = [
11940+ "item/commandExecution/requestApproval" ,
11941+ "item/fileChange/requestApproval" ,
11942+ "item/permissions/requestApproval" ,
11943+ ] as const ;
11944+ const permissionEntries = [
11945+ { access : "write" as const , path : { type : "path" as const , path : "/w/a.ts" } } ,
11946+ ] ;
11947+
11948+ it . effect . each ( approvalMethods ) (
11949+ "accepts %s in full access and leaves no pending approval" ,
11950+ ( method ) =>
11951+ Effect . gen ( function * ( ) {
11952+ const result =
11953+ method === "item/permissions/requestApproval"
11954+ ? { permissions : { fileSystem : { entries : permissionEntries } } , scope : "turn" }
11955+ : { decision : "accept" } ;
11956+ const { harness } = yield * startApprovalTurn (
11957+ `full-access-${ method . replaceAll ( "/" , "-" ) } ` ,
11958+ [
11959+ {
11960+ type : "emit_inbound" ,
11961+ label : method ,
11962+ frame : {
11963+ id : 0 ,
11964+ method,
11965+ params : {
11966+ threadId : nativeThreadId ,
11967+ turnId : nativeTurnId ,
11968+ itemId : "full-access-item" ,
11969+ startedAtMs : 2 ,
11970+ ...( method === "item/commandExecution/requestApproval"
11971+ ? { command : "rm -rf /tmp/closura-scratch" , reason : "dangerous" }
11972+ : { } ) ,
11973+ ...( method === "item/fileChange/requestApproval"
11974+ ? { reason : null , grantRoot : null }
11975+ : { } ) ,
11976+ ...( method === "item/permissions/requestApproval"
11977+ ? { cwd : "/w" , permissions : { fileSystem : { entries : permissionEntries } } }
11978+ : { } ) ,
11979+ } ,
11980+ } ,
11981+ } ,
11982+ {
11983+ type : "expect_outbound" ,
11984+ label : method ,
11985+ frame : { id : 0 , result } ,
11986+ } ,
11987+ turnCompleted ( nativeTurnId ) ,
11988+ ] ,
11989+ "full-access" ,
11990+ ) ;
11991+ yield * harness . firstTerminal ;
11992+ assert . isFalse ( harness . events . some ( ( event ) => event . type === "runtime_request.updated" ) ) ;
11993+ assert . deepEqual (
11994+ harness . terminalEvents ( ) . map ( ( event ) => event . status ) ,
11995+ [ "completed" ] ,
11996+ ) ;
11997+ } ) . pipe (
11998+ Effect . scoped ,
11999+ Effect . provide (
12000+ Layer . mergeAll (
12001+ IdAllocator . layer ,
12002+ McpProviderSessions . layer ,
12003+ NodeServices . layer ,
12004+ NodeCrypto . layer ,
12005+ ) ,
12006+ ) ,
12007+ ) ,
12008+ ) ;
12009+
12010+ it . effect . each ( approvalMethods ) (
12011+ "still parks %s when the thread is approval-required" ,
12012+ ( method ) =>
12013+ Effect . gen ( function * ( ) {
12014+ const result =
12015+ method === "item/permissions/requestApproval"
12016+ ? { permissions : { fileSystem : { entries : permissionEntries } } , scope : "turn" }
12017+ : { decision : "accept" } ;
12018+ const { harness, answerNext } = yield * startApprovalTurn (
12019+ `approval-required-${ method . replaceAll ( "/" , "-" ) } ` ,
12020+ [
12021+ {
12022+ type : "emit_inbound" ,
12023+ label : method ,
12024+ frame : {
12025+ id : 0 ,
12026+ method,
12027+ params : {
12028+ threadId : nativeThreadId ,
12029+ turnId : nativeTurnId ,
12030+ itemId : "narrow-item" ,
12031+ startedAtMs : 2 ,
12032+ ...( method === "item/commandExecution/requestApproval"
12033+ ? { command : "rm -rf /tmp/closura-scratch" , reason : "dangerous" }
12034+ : { } ) ,
12035+ ...( method === "item/fileChange/requestApproval"
12036+ ? { reason : null , grantRoot : null }
12037+ : { } ) ,
12038+ ...( method === "item/permissions/requestApproval"
12039+ ? { cwd : "/w" , permissions : { fileSystem : { entries : permissionEntries } } }
12040+ : { } ) ,
12041+ } ,
12042+ } ,
12043+ } ,
12044+ {
12045+ type : "expect_outbound" ,
12046+ label : method ,
12047+ frame : { id : 0 , result } ,
12048+ } ,
12049+ turnCompleted ( nativeTurnId ) ,
12050+ ] ,
12051+ ) ;
12052+ const request = yield * answerNext ;
12053+ assert . equal ( request . status , "pending" ) ;
12054+ yield * harness . firstTerminal ;
12055+ const requests = harness . events . flatMap ( ( event ) =>
12056+ event . type === "runtime_request.updated" ? [ event . runtimeRequest ] : [ ] ,
12057+ ) ;
12058+ assert . isNotEmpty ( requests ) ;
12059+ assert . equal ( requests [ 0 ] ?. status , "pending" ) ;
12060+ } ) . pipe (
12061+ Effect . scoped ,
12062+ Effect . provide (
12063+ Layer . mergeAll (
12064+ IdAllocator . layer ,
12065+ McpProviderSessions . layer ,
12066+ NodeServices . layer ,
12067+ NodeCrypto . layer ,
12068+ ) ,
12069+ ) ,
12070+ ) ,
12071+ ) ;
1192012072 } ) ;
1192112073} ) ;
1192212074
0 commit comments