@@ -144,17 +144,15 @@ it.effect("groups available models by provider with paging", () =>
144144 } ) ,
145145)
146146
147- const approvals = { assertions : [ ] as Permission . AssertInput [ ] , denyEdit : false }
147+ const approvals = { assertions : [ ] as Permission . AssertInput [ ] , rejectEdit : false }
148148const worktreeIt = testEffect (
149149 makePluginTestLayer (
150150 permissionLayer ( {
151151 assert : ( input ) =>
152152 Effect . sync ( ( ) => approvals . assertions . push ( input ) ) . pipe (
153153 Effect . andThen (
154- approvals . denyEdit && input . action === "edit"
155- ? Effect . fail (
156- new Permission . BlockedError ( { rules : [ ] , permission : input . action , resources : input . resources } ) ,
157- )
154+ approvals . rejectEdit && input . action === "edit"
155+ ? Effect . fail ( new Permission . CorrectedError ( { feedback : "Keep this worktree" } ) )
158156 : Effect . void ,
159157 ) ,
160158 ) ,
@@ -193,17 +191,14 @@ worktreeIt.live("creates, lists, and removes worktrees for the plugin's project"
193191 yield * OpenCodeTools . Plugin . effect ( yield * PluginHost . make ( plugins ) )
194192 const session = yield * sessions . create ( { location : Location . Ref . make ( { directory : location . directory } ) } )
195193 const registry = yield * Tool . Service
196- const call = ( name : string , input : Record < string , unknown > ) =>
194+ const program = ( code : string ) =>
197195 executeTool ( registry , {
198196 sessionID : session . id ,
199197 ...toolIdentity ,
200- call : {
201- type : "tool-call" ,
202- id : `call-${ name } -${ JSON . stringify ( input ) } ` ,
203- name : "execute" ,
204- input : { code : `return await tools.opencode.${ name } (${ JSON . stringify ( input ) } )` } ,
205- } ,
198+ call : { type : "tool-call" , id : `call-${ code } ` , name : "execute" , input : { code } } ,
206199 } )
200+ const call = ( name : string , input : Record < string , unknown > ) =>
201+ program ( `return await tools.opencode.${ name } (${ JSON . stringify ( input ) } )` )
207202 const run = ( name : string , input : Record < string , unknown > ) =>
208203 call ( name , input ) . pipe (
209204 Effect . map ( ( result ) => JSON . parse ( result . content ?. [ 0 ] ?. type === "text" ? result . content [ 0 ] . text : "" ) ) ,
@@ -234,12 +229,21 @@ worktreeIt.live("creates, lists, and removes worktrees for the plugin's project"
234229 expect ( yield * Effect . promise ( ( ) => Bun . file ( path . join ( directory , "draft.txt" ) ) . exists ( ) ) ) . toBe ( true )
235230 yield * Effect . promise ( ( ) => fs . rm ( path . join ( directory , "draft.txt" ) ) )
236231
237- // Removal requires the same approval as editing files in the worktree.
232+ // Removal requires the same approval as editing files in the worktree. Rejection feedback reaches the
233+ // program and the execute result, as it would reach the model from a direct call.
238234 approvals . assertions . length = 0
239- approvals . denyEdit = true
240- expect ( yield * call ( "worktree_remove" , { directory } ) ) . toMatchObject ( { metadata : { error : true } } )
235+ approvals . rejectEdit = true
236+ expect ( yield * call ( "worktree_remove" , { directory } ) ) . toMatchObject ( {
237+ content : [ { type : "text" , text : "Keep this worktree" } ] ,
238+ metadata : { error : true } ,
239+ } )
240+ expect (
241+ yield * program (
242+ `try { await tools.opencode.worktree_remove(${ JSON . stringify ( { directory } ) } ) } catch (error) { return error.message }` ,
243+ ) ,
244+ ) . toMatchObject ( { content : [ { type : "text" , text : "Keep this worktree" } ] } )
241245 expect ( yield * Effect . promise ( ( ) => Bun . file ( path . join ( directory , ".git" ) ) . exists ( ) ) ) . toBe ( true )
242- approvals . denyEdit = false
246+ approvals . rejectEdit = false
243247
244248 // Relative paths resolve from the session's directory for both approval and removal.
245249 expect ( yield * run ( "worktree_remove" , { directory : path . relative ( location . directory , directory ) } ) ) . toEqual ( {
@@ -252,6 +256,7 @@ worktreeIt.live("creates, lists, and removes worktrees for the plugin's project"
252256 expect ( approvals . assertions ) . toMatchObject ( [
253257 { action : "edit" , resources : [ resource ] , save : [ "*" ] , sessionID : session . id } ,
254258 { action : "edit" , resources : [ resource ] , save : [ "*" ] , sessionID : session . id } ,
259+ { action : "edit" , resources : [ resource ] , save : [ "*" ] , sessionID : session . id } ,
255260 ] )
256261 expect ( ( yield * run ( "worktree_list" , { } ) ) . worktrees ) . not . toContainEqual ( { directory, strategy : "git" } )
257262 } ) ,
0 commit comments