@@ -23,6 +23,7 @@ import { Provider } from "@opencode/core/provider"
2323import { AbsolutePath } from "@opencode/core/schema"
2424import { WellKnown } from "@opencode/core/wellknown"
2525import { KV } from "@opencode/core/kv"
26+ import { ManagedPolicy } from "@opencode/core/managed-policy"
2627import { Integration } from "@opencode/schema/integration"
2728import { emptyCredentialNode , emptyWellknownNode } from "../fixture/config-nodes"
2829import { location } from "../fixture/location"
@@ -77,6 +78,8 @@ function testLayer(
7778 return Layer . mergeAll ( built , watcher )
7879}
7980
81+ const tool = ( effect : "allow" | "deny" ) => ( { action : "tool.use" , resource : "shell:*" , effect } )
82+
8083const provider = {
8184 package : "native" ,
8285 settings : { } ,
@@ -202,7 +205,7 @@ describe("Config", () => {
202205 ) ,
203206 )
204207
205- it . live ( "loads system configuration at lowest priority" , ( ) =>
208+ it . live ( "loads system configuration at highest priority" , ( ) =>
206209 Effect . acquireDisposable ( Effect . promise ( ( ) => tmpdir ( ) ) ) . pipe (
207210 Effect . flatMap ( ( tmp ) => {
208211 const system = path . join ( tmp . path , "system" )
@@ -214,24 +217,30 @@ describe("Config", () => {
214217 await fs . mkdir ( project , { recursive : true } )
215218 await fs . writeFile (
216219 path . join ( system , "opencode.json" ) ,
217- JSON . stringify ( { shell : "system" , username : "system-user" } ) ,
220+ JSON . stringify ( { shell : "system" , username : "system-user" , experimental : { policies : [ tool ( "deny" ) ] } } ) ,
218221 )
219222 await fs . writeFile ( path . join ( global , "opencode.json" ) , JSON . stringify ( { shell : "global" } ) )
220- await fs . writeFile ( path . join ( project , "opencode.json" ) , JSON . stringify ( { shell : "project" } ) )
223+ await fs . writeFile (
224+ path . join ( project , "opencode.json" ) ,
225+ JSON . stringify ( { shell : "project" , experimental : { policies : [ tool ( "allow" ) ] } } ) ,
226+ )
221227 } ) . pipe (
222228 Effect . andThen (
223229 Effect . gen ( function * ( ) {
224230 const config = yield * Config . Service
225231 const entries = yield * config . entries ( )
226232 expect (
227233 entries . flatMap ( ( entry ) => ( entry . type === "document" && entry . info . shell ? [ entry . info . shell ] : [ ] ) ) ,
228- ) . toEqual ( [ "system " , "global " , "project " ] )
234+ ) . toEqual ( [ "global " , "project " , "system " ] )
229235 expect ( entries . flatMap ( ( entry ) => ( entry . type === "directory" ? [ entry . path ] : [ ] ) ) ) . toEqual ( [
230- AbsolutePath . make ( system ) ,
231236 AbsolutePath . make ( global ) ,
237+ AbsolutePath . make ( system ) ,
232238 ] )
233- expect ( Config . latest ( entries , "shell" ) ) . toBe ( "project " )
239+ expect ( Config . latest ( entries , "shell" ) ) . toBe ( "system " )
234240 expect ( Config . latest ( entries , "username" ) ) . toBe ( "system-user" )
241+ expect (
242+ ManagedPolicy . decision ( ManagedPolicy . statements ( entries , { statements : [ ] } ) , "tool.use" , "shell:ls" ) ,
243+ ) . toBe ( "deny" )
235244 } ) . pipe (
236245 Effect . provide (
237246 testLayer ( project , global , project , undefined , undefined , emptyCredentialNode , emptyWellknownNode , {
0 commit comments