@@ -1316,6 +1316,12 @@ describe("spawnSubagentDirect seam flow", () => {
13161316 } ) ;
13171317
13181318 it ( "registers the target agent id for cross-agent task attribution" , async ( ) => {
1319+ let persistedStore : Record < string , Record < string , unknown > > | undefined ;
1320+ installSessionStoreCaptureMock ( hoisted . updateSessionStoreMock , {
1321+ onStore : ( store ) => {
1322+ persistedStore = store ;
1323+ } ,
1324+ } ) ;
13191325 hoisted . configOverride = createConfigOverride ( {
13201326 session : {
13211327 scope : "global" ,
@@ -1348,11 +1354,16 @@ describe("spawnSubagentDirect seam flow", () => {
13481354 {
13491355 agentSessionKey : "global" ,
13501356 requesterAgentIdOverride : "main" ,
1357+ sessionPermissionPolicy : { mode : "guarded" , root : "/tmp/workspace-main" } ,
13511358 } ,
13521359 ) ;
13531360
13541361 expect ( result . status ) . toBe ( "accepted" ) ;
13551362 expect ( result . childSessionKey ) . toMatch ( / ^ a g e n t : w o r k e r : s u b a g e n t : / ) ;
1363+ expect ( persistedStore ?. [ result . childSessionKey as string ] ) . toMatchObject ( {
1364+ permissionMode : "guarded" ,
1365+ sessionRoot : resolveUserPath ( "/tmp/workspace-worker" ) ,
1366+ } ) ;
13561367 const registerInput = firstRegisteredSubagentRun ( ) ;
13571368 expect ( registerInput . childSessionKey ) . toBe ( result . childSessionKey ) ;
13581369 expect ( registerInput . agentId ) . toBe ( "worker" ) ;
@@ -1564,6 +1575,43 @@ describe("spawnSubagentDirect seam flow", () => {
15641575 ) ;
15651576 } ) ;
15661577
1578+ it . each ( [
1579+ { label : "default" , mode : undefined } ,
1580+ { label : "read-only" , mode : "read-only" } ,
1581+ { label : "guarded" , mode : "guarded" } ,
1582+ { label : "workspace" , mode : "workspace" } ,
1583+ { label : "full" , mode : "full" } ,
1584+ ] as const ) (
1585+ "inherits the parent's $label permission mode in a hidden child" ,
1586+ async ( { mode } ) => {
1587+ const sessionRoot = resolveUserPath ( "/tmp/workspace-main" ) ;
1588+ let persistedStore : Record < string , Record < string , unknown > > | undefined ;
1589+ installSessionStoreCaptureMock ( hoisted . updateSessionStoreMock , {
1590+ onStore : ( store ) => {
1591+ persistedStore = store ;
1592+ } ,
1593+ } ) ;
1594+
1595+ const result = await spawnSubagentDirect (
1596+ { task : "inherit the parent permission policy" } ,
1597+ {
1598+ agentSessionKey : "agent:main:main" ,
1599+ workspaceDir : sessionRoot ,
1600+ ...( mode ? { sessionPermissionPolicy : { mode, root : sessionRoot } } : { } ) ,
1601+ } ,
1602+ ) ;
1603+
1604+ expect ( result . status ) . toBe ( "accepted" ) ;
1605+ const childEntry = persistedStore ?. [ result . childSessionKey as string ] ;
1606+ if ( mode ) {
1607+ expect ( childEntry ) . toMatchObject ( { permissionMode : mode , sessionRoot } ) ;
1608+ } else {
1609+ expect ( childEntry ) . not . toHaveProperty ( "permissionMode" ) ;
1610+ expect ( childEntry ) . not . toHaveProperty ( "sessionRoot" ) ;
1611+ }
1612+ } ,
1613+ ) ;
1614+
15671615 it . each ( inheritedSpawnPreferenceCases ) (
15681616 "$name" ,
15691617 async ( {
0 commit comments