@@ -7,6 +7,7 @@ import { describe, expect, it, vi } from "vitest";
77import {
88 canUseCodexModelBackedApprovalsReviewerForModel ,
99 codexAppServerStartOptionsKey ,
10+ codexSandboxPolicyForTurn ,
1011 readCodexPluginConfig ,
1112 resolveCodexAppServerRuntimeOptions ,
1213 resolveCodexAppServerStartOptionsForAgent ,
@@ -549,6 +550,91 @@ describe("Codex app-server config", () => {
549550 } ) ;
550551 } ) ;
551552
553+ it ( "confines only explicitly forced private-QA Codex runtime to workspace writes" , ( ) => {
554+ const privateQaCodexEnv = {
555+ OPENCLAW_BUILD_PRIVATE_QA : "1" ,
556+ OPENCLAW_QA_FORCE_RUNTIME : "codex" ,
557+ } ;
558+ const runtime = resolveRuntimeForTest ( {
559+ pluginConfig : {
560+ appServer : {
561+ mode : "yolo" ,
562+ approvalPolicy : "never" ,
563+ sandbox : "danger-full-access" ,
564+ } ,
565+ } ,
566+ env : privateQaCodexEnv ,
567+ } ) ;
568+
569+ expectRuntimePolicy ( runtime , {
570+ approvalPolicy : "never" ,
571+ sandbox : "workspace-write" ,
572+ approvalsReviewer : "user" ,
573+ } ) ;
574+ expect ( codexSandboxPolicyForTurn ( runtime . sandbox , "/qa/workspace" , privateQaCodexEnv ) ) . toEqual ( {
575+ type : "workspaceWrite" ,
576+ writableRoots : [ "/qa/workspace" ] ,
577+ networkAccess : false ,
578+ excludeTmpdirEnvVar : true ,
579+ excludeSlashTmp : true ,
580+ } ) ;
581+ } ) ;
582+
583+ it ( "preserves an explicitly read-only sandbox for forced private-QA Codex runtime" , ( ) => {
584+ const privateQaCodexEnv = {
585+ OPENCLAW_BUILD_PRIVATE_QA : "1" ,
586+ OPENCLAW_QA_FORCE_RUNTIME : "codex" ,
587+ } ;
588+ const runtime = resolveRuntimeForTest ( {
589+ pluginConfig : {
590+ appServer : {
591+ mode : "yolo" ,
592+ approvalPolicy : "never" ,
593+ sandbox : "read-only" ,
594+ } ,
595+ } ,
596+ env : privateQaCodexEnv ,
597+ } ) ;
598+
599+ expectRuntimePolicy ( runtime , {
600+ approvalPolicy : "never" ,
601+ sandbox : "read-only" ,
602+ approvalsReviewer : "user" ,
603+ } ) ;
604+ expect ( codexSandboxPolicyForTurn ( runtime . sandbox , "/qa/workspace" , privateQaCodexEnv ) ) . toEqual ( {
605+ type : "readOnly" ,
606+ networkAccess : false ,
607+ } ) ;
608+ } ) ;
609+
610+ it . each ( [
611+ { label : "ordinary production" , env : { } } ,
612+ { label : "private build without a forced runtime" , env : { OPENCLAW_BUILD_PRIVATE_QA : "1" } } ,
613+ {
614+ label : "forced runtime without a private build" ,
615+ env : { OPENCLAW_QA_FORCE_RUNTIME : "codex" } ,
616+ } ,
617+ {
618+ label : "forced private-QA OpenClaw runtime" ,
619+ env : { OPENCLAW_BUILD_PRIVATE_QA : "1" , OPENCLAW_QA_FORCE_RUNTIME : "openclaw" } ,
620+ } ,
621+ ] ) ( "preserves production yolo filesystem policy for $label" , ( { env } ) => {
622+ const runtime = resolveRuntimeForTest ( { pluginConfig : { } , env } ) ;
623+
624+ expectRuntimePolicy ( runtime , {
625+ approvalPolicy : "never" ,
626+ sandbox : "danger-full-access" ,
627+ approvalsReviewer : "user" ,
628+ } ) ;
629+ expect ( codexSandboxPolicyForTurn ( "workspace-write" , "/qa/workspace" , env ) ) . toEqual ( {
630+ type : "workspaceWrite" ,
631+ writableRoots : [ "/qa/workspace" ] ,
632+ networkAccess : false ,
633+ excludeTmpdirEnvVar : false ,
634+ excludeSlashTmp : false ,
635+ } ) ;
636+ } ) ;
637+
552638 it ( "does not change ordinary harness connection defaults when supervision is enabled" , ( ) => {
553639 const runtime = resolveRuntimeForTest ( {
554640 pluginConfig : { supervision : { enabled : true } } ,
0 commit comments