@@ -8,6 +8,7 @@ import { Codicon } from '../../../../../base/common/codicons.js';
88import { ThemeIcon } from '../../../../../base/common/themables.js' ;
99import { mock } from '../../../../../base/test/common/mock.js' ;
1010import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js' ;
11+ import { NullActionViewItemService } from '../../../../../platform/actions/browser/actionViewItemService.js' ;
1112import { isIMenuItem , MenuId , MenuRegistry } from '../../../../../platform/actions/common/actions.js' ;
1213import { CommandsRegistry , ICommandService } from '../../../../../platform/commands/common/commands.js' ;
1314import type { ContextKeyExpression , ContextKeyValue } from '../../../../../platform/contextkey/common/contextkey.js' ;
@@ -18,7 +19,7 @@ import { IsAuxiliaryWindowContext, IsSessionsWindowContext, RemoteNameContext }
1819import { Menus } from '../../../../browser/menus.js' ;
1920import { RemoteTunnelCommandIds } from '../../../../../workbench/contrib/remoteTunnel/electron-browser/remoteTunnel.contribution.js' ;
2021import { TOGGLE_SHARING_ID } from '../../../../../workbench/contrib/chat/electron-browser/tunnelHost.contribution.js' ;
21- import { TOGGLE_SHARING_FROM_AGENTS_ID } from '../../electron-browser/tunnelHost.contribution.js' ;
22+ import { SessionsTunnelHostTitlebarContribution , TOGGLE_SHARING_FROM_AGENTS_ID } from '../../electron-browser/tunnelHost.contribution.js' ;
2223
2324class TestRemoteTunnelService extends mock < IRemoteTunnelService > ( ) {
2425 override getMode ( ) : Promise < TunnelMode > {
@@ -43,11 +44,16 @@ suite('Sessions - Tunnel Host Contribution', () => {
4344
4445 ensureNoDisposablesAreLeakedInTestSuite ( ) ;
4546
46- test ( 'remote connections toggle is in Agents titlebar and non-Agents chat input ' , ( ) => {
47+ test ( 'registers the remote connections toggle with the titlebar contribution ' , ( ) => {
4748 const findToggle = ( menu : MenuId , id : string ) => MenuRegistry . getMenuItems ( menu )
4849 . filter ( isIMenuItem )
4950 . find ( item => item . command . id === id ) ;
5051
52+ assert . strictEqual ( findToggle ( Menus . TitleBarRightLayout , TOGGLE_SHARING_FROM_AGENTS_ID ) , undefined ) ;
53+ assert . strictEqual ( CommandsRegistry . getCommand ( TOGGLE_SHARING_FROM_AGENTS_ID ) , undefined ) ;
54+
55+ const contribution = new SessionsTunnelHostTitlebarContribution ( new TestRemoteTunnelService ( ) , new NullActionViewItemService ( ) ) ;
56+
5157 const summarize = ( menu : MenuId , id : string ) => {
5258 const item = findToggle ( menu , id ) ;
5359 return item && {
@@ -57,58 +63,71 @@ suite('Sessions - Tunnel Host Contribution', () => {
5763 } ;
5864 } ;
5965
60- assert . deepStrictEqual ( {
61- titlebar : summarize ( Menus . TitleBarRightLayout , TOGGLE_SHARING_FROM_AGENTS_ID ) ,
62- chatInput : summarize ( MenuId . ChatInputSecondary , TOGGLE_SHARING_ID ) ,
63- } , {
64- titlebar : { group : 'navigation' , order : 90 , icon : Codicon . radioTower . id } ,
65- chatInput : { group : 'navigation' , order : 10 , icon : Codicon . radioTower . id } ,
66- } ) ;
67-
68- const titlebarToggle = findToggle ( Menus . TitleBarRightLayout , TOGGLE_SHARING_FROM_AGENTS_ID ) ;
69- const chatInputToggle = findToggle ( MenuId . ChatInputSecondary , TOGGLE_SHARING_ID ) ;
70- if ( ! titlebarToggle ?. when || ! chatInputToggle ?. when ) {
71- assert . fail ( 'remote connections menu items should have when clauses' ) ;
72- }
66+ try {
67+ assert . deepStrictEqual ( {
68+ titlebar : summarize ( Menus . TitleBarRightLayout , TOGGLE_SHARING_FROM_AGENTS_ID ) ,
69+ chatInput : summarize ( MenuId . ChatInputSecondary , TOGGLE_SHARING_ID ) ,
70+ } , {
71+ titlebar : { group : 'navigation' , order : 90 , icon : Codicon . radioTower . id } ,
72+ chatInput : { group : 'navigation' , order : 10 , icon : Codicon . radioTower . id } ,
73+ } ) ;
74+
75+ const titlebarToggle = findToggle ( Menus . TitleBarRightLayout , TOGGLE_SHARING_FROM_AGENTS_ID ) ;
76+ const chatInputToggle = findToggle ( MenuId . ChatInputSecondary , TOGGLE_SHARING_ID ) ;
77+ if ( ! titlebarToggle ?. when || ! chatInputToggle ?. when ) {
78+ assert . fail ( 'remote connections menu items should have when clauses' ) ;
79+ }
80+
81+ const evalWhen = ( when : ContextKeyExpression , values : Record < string , ContextKeyValue > ) => {
82+ return when . evaluate ( { getValue : < T extends ContextKeyValue = ContextKeyValue > ( key : string ) => values [ key ] as T } ) ;
83+ } ;
84+ const agentHostChat = {
85+ [ ChatContextKeys . enabled . key ] : true ,
86+ [ ChatContextKeys . chatIsAgentHostSession . key ] : true ,
87+ [ IsAuxiliaryWindowContext . key ] : false ,
88+ [ RemoteNameContext . key ] : '' ,
89+ } ;
7390
74- const evalWhen = ( when : ContextKeyExpression , values : Record < string , ContextKeyValue > ) => {
75- return when . evaluate ( { getValue : < T extends ContextKeyValue = ContextKeyValue > ( key : string ) => values [ key ] as T } ) ;
76- } ;
77- const agentHostChat = {
78- [ ChatContextKeys . enabled . key ] : true ,
79- [ ChatContextKeys . chatIsAgentHostSession . key ] : true ,
80- [ IsAuxiliaryWindowContext . key ] : false ,
81- [ RemoteNameContext . key ] : '' ,
82- } ;
91+ assert . deepStrictEqual ( {
92+ agentsTitlebar : evalWhen ( titlebarToggle . when , { ...agentHostChat , [ IsSessionsWindowContext . key ] : true } ) ,
93+ editorTitlebar : evalWhen ( titlebarToggle . when , { ...agentHostChat , [ IsSessionsWindowContext . key ] : false } ) ,
94+ agentsChatInput : evalWhen ( chatInputToggle . when , { ...agentHostChat , [ IsSessionsWindowContext . key ] : true } ) ,
95+ editorChatInput : evalWhen ( chatInputToggle . when , { ...agentHostChat , [ IsSessionsWindowContext . key ] : false } ) ,
96+ remoteEditorChatInput : evalWhen ( chatInputToggle . when , { ...agentHostChat , [ IsSessionsWindowContext . key ] : false , [ RemoteNameContext . key ] : 'ssh-remote' } ) ,
97+ } , {
98+ agentsTitlebar : true ,
99+ editorTitlebar : false ,
100+ agentsChatInput : false ,
101+ editorChatInput : true ,
102+ remoteEditorChatInput : false ,
103+ } ) ;
104+ } finally {
105+ contribution . dispose ( ) ;
106+ }
83107
84- assert . deepStrictEqual ( {
85- agentsTitlebar : evalWhen ( titlebarToggle . when , { ...agentHostChat , [ IsSessionsWindowContext . key ] : true } ) ,
86- editorTitlebar : evalWhen ( titlebarToggle . when , { ...agentHostChat , [ IsSessionsWindowContext . key ] : false } ) ,
87- agentsChatInput : evalWhen ( chatInputToggle . when , { ...agentHostChat , [ IsSessionsWindowContext . key ] : true } ) ,
88- editorChatInput : evalWhen ( chatInputToggle . when , { ...agentHostChat , [ IsSessionsWindowContext . key ] : false } ) ,
89- remoteEditorChatInput : evalWhen ( chatInputToggle . when , { ...agentHostChat , [ IsSessionsWindowContext . key ] : false , [ RemoteNameContext . key ] : 'ssh-remote' } ) ,
90- } , {
91- agentsTitlebar : true ,
92- editorTitlebar : false ,
93- agentsChatInput : false ,
94- editorChatInput : true ,
95- remoteEditorChatInput : false ,
96- } ) ;
108+ assert . strictEqual ( findToggle ( Menus . TitleBarRightLayout , TOGGLE_SHARING_FROM_AGENTS_ID ) , undefined ) ;
109+ assert . strictEqual ( CommandsRegistry . getCommand ( TOGGLE_SHARING_FROM_AGENTS_ID ) , undefined ) ;
97110 } ) ;
98111
99112 test ( 'Agents turn-on forces GitHub without offering service installation' , async ( ) => {
100113 const instantiationService = new TestInstantiationService ( ) ;
101114 const commandService = new TestCommandService ( ) ;
102115 instantiationService . stub ( IRemoteTunnelService , new TestRemoteTunnelService ( ) ) ;
103116 instantiationService . stub ( ICommandService , commandService ) ;
104- const command = CommandsRegistry . getCommand ( TOGGLE_SHARING_FROM_AGENTS_ID ) ;
105- assert . ok ( command ) ;
117+ const contribution = new SessionsTunnelHostTitlebarContribution ( new TestRemoteTunnelService ( ) , new NullActionViewItemService ( ) ) ;
106118
107- await instantiationService . invokeFunction ( command . handler ) ;
119+ try {
120+ const command = CommandsRegistry . getCommand ( TOGGLE_SHARING_FROM_AGENTS_ID ) ;
121+ assert . ok ( command ) ;
108122
109- assert . deepStrictEqual ( commandService . calls , [ {
110- id : RemoteTunnelCommandIds . turnOn ,
111- args : [ { authenticationProviderId : 'github' , showServiceOption : false , showSuccessNotification : false } ] ,
112- } ] ) ;
123+ await instantiationService . invokeFunction ( command . handler ) ;
124+
125+ assert . deepStrictEqual ( commandService . calls , [ {
126+ id : RemoteTunnelCommandIds . turnOn ,
127+ args : [ { authenticationProviderId : 'github' , showServiceOption : false , showSuccessNotification : false } ] ,
128+ } ] ) ;
129+ } finally {
130+ contribution . dispose ( ) ;
131+ }
113132 } ) ;
114133} ) ;
0 commit comments