@@ -232,6 +232,51 @@ describe("Codex app-server approval bridge", () => {
232232 } ,
233233 ) ;
234234
235+ it . each ( [
236+ [ "promoted tool policy" , { autoApproveOpenClawToolPolicy : true } ] ,
237+ [ "full-auto runtime policy" , { autoApprove : true } ] ,
238+ ] as const ) ( "keeps permission grants on the human path under %s" , async ( _label , policy ) => {
239+ const params = createParams ( ) ;
240+ mockCallGatewayTool
241+ . mockResolvedValueOnce ( { id : "plugin:permission-policy-allow" , status : "accepted" } )
242+ . mockResolvedValueOnce ( {
243+ id : "plugin:permission-policy-allow" ,
244+ decision : "allow-once" ,
245+ } ) ;
246+
247+ const result = await handleCodexAppServerApprovalRequest ( {
248+ method : "item/permissions/requestApproval" ,
249+ requestParams : {
250+ threadId : "thread-1" ,
251+ turnId : "turn-1" ,
252+ itemId : "permission-policy-allow" ,
253+ permissions : {
254+ network : { enabled : true } ,
255+ fileSystem : { write : [ "/workspace" ] } ,
256+ } ,
257+ } ,
258+ paramsForRun : params ,
259+ threadId : "thread-1" ,
260+ turnId : "turn-1" ,
261+ ...policy ,
262+ } ) ;
263+
264+ expect ( result ) . toEqual ( {
265+ permissions : {
266+ network : { enabled : true } ,
267+ fileSystem : { write : [ "/workspace" ] } ,
268+ } ,
269+ scope : "turn" ,
270+ } ) ;
271+ expect ( mockRunBeforeToolCallHook ) . toHaveBeenCalledWith (
272+ expect . objectContaining ( { toolName : "codex_permission_approval" } ) ,
273+ ) ;
274+ expect ( mockCallGatewayTool . mock . calls . map ( ( [ method ] ) => method ) ) . toEqual ( [
275+ "plugin.approval.request" ,
276+ "plugin.approval.waitDecision" ,
277+ ] ) ;
278+ } ) ;
279+
235280 it ( "routes command approvals through plugin approvals and accepts allowed commands" , async ( ) => {
236281 const params = createParams ( ) ;
237282 mockCallGatewayTool
@@ -2465,8 +2510,11 @@ describe("Codex app-server approval bridge", () => {
24652510 } ) ;
24662511 } ) ;
24672512
2468- it ( "fails closed for unsupported native approval methods without requesting plugin approval " , async ( ) => {
2513+ it ( "routes unknown approval methods to the human path and still fails closed " , async ( ) => {
24692514 const params = createParams ( ) ;
2515+ mockCallGatewayTool
2516+ . mockResolvedValueOnce ( { id : "plugin:future-approval" , status : "accepted" } )
2517+ . mockResolvedValueOnce ( { id : "plugin:future-approval" , decision : "deny" } ) ;
24702518
24712519 const result = await handleCodexAppServerApprovalRequest ( {
24722520 method : "future/requestApproval" ,
@@ -2484,8 +2532,15 @@ describe("Codex app-server approval bridge", () => {
24842532 decision : "decline" ,
24852533 reason : "OpenClaw codex app-server bridge does not grant native approvals yet." ,
24862534 } ) ;
2487- expect ( mockCallGatewayTool ) . not . toHaveBeenCalled ( ) ;
2488- expect ( params . onAgentEvent ) . not . toHaveBeenCalled ( ) ;
2535+ expect ( mockRunBeforeToolCallHook ) . not . toHaveBeenCalled ( ) ;
2536+ expect ( mockCallGatewayTool . mock . calls . map ( ( [ method ] ) => method ) ) . toEqual ( [
2537+ "plugin.approval.request" ,
2538+ "plugin.approval.waitDecision" ,
2539+ ] ) ;
2540+ findApprovalEvent ( params , {
2541+ status : "denied" ,
2542+ approvalId : "plugin:future-approval" ,
2543+ } ) ;
24892544 } ) ;
24902545 it ( "labels permission approvals explicitly with permission detail" , async ( ) => {
24912546 const params = createParams ( ) ;
0 commit comments