@@ -5,6 +5,7 @@ import { provideInstance, tmpdir } from "../fixture/fixture"
55import { Instance } from "../../src/project/instance"
66import { Agent } from "../../src/agent/agent"
77import { Permission } from "../../src/permission"
8+ import { Global } from "@opencode-ai/core/global"
89
910// Helper to evaluate permission for a tool with wildcard pattern
1011function evalPerm ( agent : Agent . Info | undefined , permission : string ) : Permission . Action | undefined {
@@ -83,7 +84,7 @@ test("explore agent denies edit and write", async () => {
8384 } )
8485} )
8586
86- test ( "explore agent asks for external directories and allows Truncate.GLOB " , async ( ) => {
87+ test ( "explore agent asks for external directories and allows whitelisted external paths " , async ( ) => {
8788 const { Truncate } = await import ( "../../src/tool/truncate" )
8889 await using tmp = await tmpdir ( )
8990 await Instance . provide ( {
@@ -93,6 +94,9 @@ test("explore agent asks for external directories and allows Truncate.GLOB", asy
9394 expect ( explore ) . toBeDefined ( )
9495 expect ( Permission . evaluate ( "external_directory" , "/some/other/path" , explore ! . permission ) . action ) . toBe ( "ask" )
9596 expect ( Permission . evaluate ( "external_directory" , Truncate . GLOB , explore ! . permission ) . action ) . toBe ( "allow" )
97+ expect ( Permission . evaluate ( "external_directory" , path . join ( Global . Path . tmp , "agent-work" ) , explore ! . permission ) . action ) . toBe (
98+ "allow" ,
99+ )
96100 } ,
97101 } )
98102} )
@@ -515,6 +519,20 @@ test("Truncate.GLOB is allowed even when user denies external_directory globally
515519 } )
516520} )
517521
522+ test ( "global tmp directory children are allowed for external_directory" , async ( ) => {
523+ await using tmp = await tmpdir ( )
524+ await Instance . provide ( {
525+ directory : tmp . path ,
526+ fn : async ( ) => {
527+ const build = await load ( tmp . path , ( svc ) => svc . get ( "build" ) )
528+ expect ( Permission . evaluate ( "external_directory" , path . join ( Global . Path . tmp , "scratch" ) , build ! . permission ) . action ) . toBe (
529+ "allow" ,
530+ )
531+ expect ( Permission . evaluate ( "external_directory" , "/some/other/path" , build ! . permission ) . action ) . toBe ( "ask" )
532+ } ,
533+ } )
534+ } )
535+
518536test ( "Truncate.GLOB is allowed even when user denies external_directory per-agent" , async ( ) => {
519537 const { Truncate } = await import ( "../../src/tool/truncate" )
520538 await using tmp = await tmpdir ( {
0 commit comments