@@ -126,6 +126,59 @@ describe("WorkspaceFsCommands – target folder resolution", () => {
126126 } ) ;
127127 } ) ;
128128
129+ // createFile mirrors createFolder's target resolution but, like upload,
130+ // checks workspaceClient before reaching getValidRoot.
131+ describe ( "createFile (context menu)" , ( ) => {
132+ beforeEach ( ( ) => {
133+ when ( mockConnectionManager . workspaceClient ) . thenReturn ( { } as any ) ;
134+ } ) ;
135+
136+ it ( "no element → targets root" , async ( ) => {
137+ await commands . createFile ( undefined ) ;
138+ assert . strictEqual ( capturedRootPath , ROOT_PATH ) ;
139+ } ) ;
140+
141+ it ( "element=A → targets A" , async ( ) => {
142+ await commands . createFile ( entityA ) ;
143+ assert . strictEqual ( capturedRootPath , entityA . path ) ;
144+ } ) ;
145+
146+ it ( "element=B while A is selected → targets B" , async ( ) => {
147+ fakeTreeView . simulateSelect ( entityA ) ;
148+ await commands . createFile ( entityB ) ;
149+ assert . strictEqual ( capturedRootPath , entityB . path ) ;
150+ } ) ;
151+ } ) ;
152+
153+ describe ( "createFileFromToolbar (toolbar)" , ( ) => {
154+ beforeEach ( ( ) => {
155+ when ( mockConnectionManager . workspaceClient ) . thenReturn ( { } as any ) ;
156+ } ) ;
157+
158+ it ( "nothing selected → targets root" , async ( ) => {
159+ await commands . createFileFromToolbar ( undefined ) ;
160+ assert . strictEqual ( capturedRootPath , ROOT_PATH ) ;
161+ } ) ;
162+
163+ it ( "A selected, toolbar clicked → targets A" , async ( ) => {
164+ fakeTreeView . simulateSelect ( entityA ) ;
165+ await commands . createFileFromToolbar ( entityA ) ;
166+ assert . strictEqual ( capturedRootPath , entityA . path ) ;
167+ } ) ;
168+
169+ it ( "selection cleared before toolbar click → targets root" , async ( ) => {
170+ fakeTreeView . simulateSelect ( entityA ) ;
171+ fakeTreeView . simulateSelect ( undefined ) ;
172+ await commands . createFileFromToolbar ( undefined ) ;
173+ assert . strictEqual ( capturedRootPath , ROOT_PATH ) ;
174+ } ) ;
175+
176+ it ( "element passed but nothing selected (edge case) → targets root" , async ( ) => {
177+ await commands . createFileFromToolbar ( entityA ) ;
178+ assert . strictEqual ( capturedRootPath , ROOT_PATH ) ;
179+ } ) ;
180+ } ) ;
181+
129182 describe ( "uploadFile (context menu)" , ( ) => {
130183 // doUploadFile checks workspaceClient before reaching getValidRoot;
131184 // provide a non-null client so root-path resolution is exercised.
0 commit comments