@@ -123,6 +123,8 @@ const makeFakeCopilot = Effect.fnUntraced(function* () {
123123 const switchResults : Array < Awaited < ReturnType < CopilotSdkSession [ "rpc" ] [ "model" ] [ "switchTo" ] > > > =
124124 [ ] ;
125125 const switchFailures : Array < Error > = [ ] ;
126+ // Each entry refuses one permission-mode switch, reporting the mode Copilot kept.
127+ const permissionRefusals : Array < "allow-all" | "manual" > = [ ] ;
126128 const gate = ( ) => {
127129 let release ! : ( ) => void ;
128130 const promise = new Promise < void > ( ( resolve ) => {
@@ -175,7 +177,10 @@ const makeFakeCopilot = Effect.fnUntraced(function* () {
175177 permissions : {
176178 setMode : async ( params ) => {
177179 record ( "permissions.setMode" , params ) ;
178- return { success : true , mode : params . mode } ;
180+ const kept = permissionRefusals . shift ( ) ;
181+ return kept === undefined
182+ ? { success : true , mode : params . mode }
183+ : { success : false , mode : kept } ;
179184 } ,
180185 handlePendingPermissionRequest : async ( params ) => {
181186 record ( "permissions.handlePendingPermissionRequest" , params ) ;
@@ -323,6 +328,9 @@ const makeFakeCopilot = Effect.fnUntraced(function* () {
323328 queueSwitchResult : ( result : ( typeof switchResults ) [ number ] ) => {
324329 switchResults . push ( result ) ;
325330 } ,
331+ refuseNextPermissionMode : ( kept : ( typeof permissionRefusals ) [ number ] ) => {
332+ permissionRefusals . push ( kept ) ;
333+ } ,
326334 config : ( ) => config ,
327335 hangAbort : ( ) => {
328336 hangAbort = true ;
@@ -1604,10 +1612,11 @@ describe("CopilotSdkAdapterV2", () => {
16041612 { id : "reasoning_effort" , value : "high" } ,
16051613 ] ) ,
16061614 ) ;
1615+ // The mode goes first: Copilot can switch to a configured plan model with it.
1616+ assert . deepStrictEqual ( ( yield * fake . takeCall ( "mode.set" ) ) . args , [ { mode : "autopilot" } ] ) ;
16071617 assert . deepStrictEqual ( ( yield * fake . takeCall ( "model.switchTo" ) ) . args , [
16081618 { modelId : "claude-sonnet-4.5" , reasoningEffort : "high" , contextTier : "long_context" } ,
16091619 ] ) ;
1610- assert . deepStrictEqual ( ( yield * fake . takeCall ( "mode.set" ) ) . args , [ { mode : "autopilot" } ] ) ;
16111620 assert . deepStrictEqual ( ( yield * fake . takeCall ( "permissions.setMode" ) ) . args , [
16121621 { mode : "allow-all" } ,
16131622 ] ) ;
@@ -1682,6 +1691,42 @@ describe("CopilotSdkAdapterV2", () => {
16821691 yield * harness . runtime . startTurn ( { ...gpt , providerTurnOrdinal : 5 } ) ;
16831692 assert . deepStrictEqual ( ( yield * fake . takeCall ( "model.switchTo" ) ) . args , switchToGpt ) ;
16841693 yield * fake . takeCall ( "sendAndWait" ) ;
1694+ yield * fake . finishRun ( ) ;
1695+ yield * harness . untilTerminal ( ) ;
1696+ const planInput = yield * turnInput (
1697+ harness . providerThread ,
1698+ [
1699+ { id : "mode" , value : "https://agentclientprotocol.com/protocol/session-modes#plan" } ,
1700+ { id : "allow_all" , value : true } ,
1701+ ] ,
1702+ 6 ,
1703+ ) ;
1704+ const plan = {
1705+ ...planInput ,
1706+ modelSelection : { ...planInput . modelSelection , model : "gpt-5.5" } ,
1707+ } ;
1708+ yield * harness . runtime . startTurn ( plan ) ;
1709+ yield * fake . takeCall ( "sendAndWait" ) ;
1710+ yield * fake . finishRun ( ) ;
1711+ yield * harness . untilTerminal ( ) ;
1712+ // Copilot kept allow-all: a prompt now would auto-approve what T3 should ask about.
1713+ fake . refuseNextPermissionMode ( "allow-all" ) ;
1714+ const kept = yield * harness . runtime
1715+ . startTurn ( { ...gpt , providerTurnOrdinal : 7 } )
1716+ . pipe ( Effect . flip ) ;
1717+ assert . isTrue ( Predicate . isTagged ( kept . cause , "CopilotPromptNotSentError" ) ) ;
1718+ assert . deepStrictEqual ( ( yield * fake . takeCall ( "mode.set" ) ) . args , [ { mode : "interactive" } ] ) ;
1719+ assert . deepStrictEqual ( ( yield * fake . takeCall ( "permissions.setMode" ) ) . args , [
1720+ { mode : "manual" } ,
1721+ ] ) ;
1722+ // Copilot did leave plan mode, so going back to the earlier settings switches again.
1723+ yield * harness . runtime . startTurn ( { ...plan , providerTurnOrdinal : 7 } ) ;
1724+ assert . deepInclude ( yield * fake . nextCall , { method : "mode.set" , args : [ { mode : "plan" } ] } ) ;
1725+ assert . deepInclude ( yield * fake . nextCall , {
1726+ method : "permissions.setMode" ,
1727+ args : [ { mode : "allow-all" } ] ,
1728+ } ) ;
1729+ assert . deepInclude ( yield * fake . nextCall , { method : "sendAndWait" } ) ;
16851730 } ) . pipe ( Effect . scoped , Effect . provide ( testLayer ) ) ,
16861731 ) ;
16871732
0 commit comments