@@ -72,6 +72,7 @@ class MockAgentService implements IAgentService {
7272 readonly browsedUris : URI [ ] = [ ] ;
7373 readonly browseErrors = new Map < string , Error > ( ) ;
7474 readonly listedSessions : IAgentSessionMetadata [ ] = [ ] ;
75+ readonly createSessionConfigs : ( IAgentCreateSessionConfig | undefined ) [ ] = [ ] ;
7576
7677 private readonly _onDidAction = new Emitter < import ( '../../common/state/sessionActions.js' ) . IActionEnvelope > ( ) ;
7778 readonly onDidAction = this . _onDidAction . event ;
@@ -91,6 +92,7 @@ class MockAgentService implements IAgentService {
9192 this . _stateManager . dispatchClientAction ( action , origin ) ;
9293 }
9394 async createSession ( config ?: IAgentCreateSessionConfig ) : Promise < URI > {
95+ this . createSessionConfigs . push ( config ) ;
9496 const session = config ?. session ?? URI . parse ( 'copilot:///new-session' ) ;
9597 this . _stateManager . createSession ( {
9698 resource : session . toString ( ) ,
@@ -582,14 +584,10 @@ suite('ProtocolServerHandler', () => {
582584
583585 suite ( 'createSession activeClient' , ( ) => {
584586
585- test ( 'forwards activeClient as SessionActiveClientChanged ' , async ( ) => {
587+ test ( 'forwards activeClient to the agent service ' , async ( ) => {
586588 const newSession = URI . parse ( 'copilot:///eager-session' ) . toString ( ) ;
587- // Pre-create the session so the client can subscribe at handshake
588- // time. MockAgentService.createSession below is idempotent against
589- // state-manager duplicates.
590- stateManager . createSession ( makeSessionSummary ( newSession ) ) ;
591589
592- const transport = connectClient ( 'client-1' , [ newSession ] ) ;
590+ const transport = connectClient ( 'client-1' ) ;
593591 transport . sent . length = 0 ;
594592
595593 const responsePromise = waitForResponse ( transport , 2 ) ;
@@ -602,21 +600,15 @@ suite('ProtocolServerHandler', () => {
602600 customizations : [ { uri : 'file:///plugin-a' , displayName : 'A' } ] ,
603601 } ,
604602 } ) ) ;
605- await responsePromise ;
603+ const resp = await responsePromise as { result ?: unknown ; error ?: unknown } ;
606604
607- const activeClientMsgs = findNotifications ( transport . sent , 'action' ) . filter ( m => {
608- const envelope = m . params as unknown as { action : { type : string } } ;
609- return envelope . action . type === ActionType . SessionActiveClientChanged ;
610- } ) ;
611- assert . strictEqual ( activeClientMsgs . length , 1 , 'should emit exactly one SessionActiveClientChanged' ) ;
612- const envelope = activeClientMsgs [ 0 ] . params as unknown as { action : { session : string ; activeClient : { clientId : string ; tools : { name : string } [ ] ; customizations ?: { uri : string } [ ] } } } ;
605+ assert . strictEqual ( resp . error , undefined , 'createSession should succeed' ) ;
606+ const config = agentService . createSessionConfigs . at ( - 1 ) ;
613607 assert . deepStrictEqual ( {
614- session : envelope . action . session ,
615- clientId : envelope . action . activeClient . clientId ,
616- toolName : envelope . action . activeClient . tools [ 0 ] . name ,
617- customizationUri : envelope . action . activeClient . customizations ?. [ 0 ] . uri ,
608+ clientId : config ?. activeClient ?. clientId ,
609+ toolName : config ?. activeClient ?. tools [ 0 ] ?. name ,
610+ customizationUri : config ?. activeClient ?. customizations ?. [ 0 ] . uri ,
618611 } , {
619- session : newSession ,
620612 clientId : 'client-1' ,
621613 toolName : 't1' ,
622614 customizationUri : 'file:///plugin-a' ,
@@ -625,9 +617,8 @@ suite('ProtocolServerHandler', () => {
625617
626618 test ( 'rejects createSession when activeClient.clientId mismatches' , async ( ) => {
627619 const newSession = URI . parse ( 'copilot:///mismatch-session' ) . toString ( ) ;
628- stateManager . createSession ( makeSessionSummary ( newSession ) ) ;
629620
630- const transport = connectClient ( 'client-1' , [ newSession ] ) ;
621+ const transport = connectClient ( 'client-1' ) ;
631622 transport . sent . length = 0 ;
632623
633624 const responsePromise = waitForResponse ( transport , 2 ) ;
@@ -643,11 +634,7 @@ suite('ProtocolServerHandler', () => {
643634
644635 assert . ok ( resp . error , 'response should be an error' ) ;
645636 assert . strictEqual ( resp . result , undefined ) ;
646- const activeClientMsgs = findNotifications ( transport . sent , 'action' ) . filter ( m => {
647- const envelope = m . params as unknown as { action : { type : string } } ;
648- return envelope . action . type === ActionType . SessionActiveClientChanged ;
649- } ) ;
650- assert . strictEqual ( activeClientMsgs . length , 0 , 'no activeClient notification should have been emitted' ) ;
637+ assert . strictEqual ( agentService . createSessionConfigs . length , 0 , 'agent service should not have been called' ) ;
651638 } ) ;
652639 } ) ;
653640} ) ;
0 commit comments