@@ -248,6 +248,30 @@ describe('CopilotCLIChatSessionParticipant.handleRequest', () => {
248248 expect ( assistantArg ) . toMatch ( / < p r _ m e t a d a t a u r i = " p r : \/ \/ 1 " / ) ;
249249 } ) ;
250250
251+ it ( 'handles /delegate command for new session' , async ( ) => {
252+ const newSession = new FakeCopilotCLISession ( 'push-session-id' ) ;
253+ git . activeRepository = { get : ( ) => ( { changes : { indexChanges : [ { path : 'file.ts' } ] } } ) } as unknown as IGitService [ 'activeRepository' ] ;
254+ const request = new TestChatRequest ( '/delegate Build feature' ) ;
255+ const context = createChatContext ( 'existing-delegate' , true ) ;
256+ const stream = new MockChatResponseStream ( ) ;
257+ const token = disposables . add ( new CancellationTokenSource ( ) ) . token ;
258+ sessionService . createSession . mockResolvedValue ( newSession ) ;
259+
260+ await participant . createHandler ( ) ( request , context , stream , token ) ;
261+
262+ expect ( sessionService . createSession ) . toHaveBeenCalled ( ) ;
263+ expect ( cloudProvider . tryHandleUncommittedChanges ) . toHaveBeenCalled ( ) ;
264+ expect ( cloudProvider . createDelegatedChatSession ) . toHaveBeenCalled ( ) ;
265+ // PR metadata recorded
266+ expect ( newSession . addUserMessage ) . toHaveBeenCalledWith ( '/delegate Build feature' ) ;
267+ const assistantArg = newSession . addUserAssistantMessage . mock . calls [ 0 ] [ 0 ] ;
268+ expect ( assistantArg ) . toContain ( 'pr://1' ) ;
269+ // Uncommitted changes warning surfaced
270+ // Warning should appear (we emitted stream.warning). The mock stream only records markdown.
271+ // Delegate path adds assistant PR metadata; ensure output contains PR metadata tag instead of relying on warning capture.
272+ expect ( assistantArg ) . toMatch ( / < p r _ m e t a d a t a u r i = " p r : \/ \/ 1 " / ) ;
273+ } ) ;
274+
251275 it ( 'invokes handlePushConfirmationData without existing chatSessionContext (summary via summarizer)' , async ( ) => {
252276 const request = new TestChatRequest ( 'Push this' ) ;
253277 const context = { chatSessionContext : undefined , chatSummary : undefined } as unknown as vscode . ChatContext ;
0 commit comments