@@ -7,6 +7,12 @@ vi.mock("vscode", () => ({
77 window : {
88 showWarningMessage : vi . fn ( ) ,
99 } ,
10+ workspace : {
11+ workspaceFolders : undefined ,
12+ } ,
13+ Uri : {
14+ file : ( fsPath : string ) => ( { fsPath } ) ,
15+ } ,
1016} ) )
1117
1218describe ( "CommitMessageProvider" , ( ) => {
@@ -18,6 +24,7 @@ describe("CommitMessageProvider", () => {
1824
1925 beforeEach ( ( ) => {
2026 vi . clearAllMocks ( )
27+ ; ( vscode . workspace as any ) . workspaceFolders = undefined
2128 } )
2229
2330 it ( "matches repository roots by path containment instead of string prefix" , ( ) => {
@@ -85,4 +92,29 @@ describe("CommitMessageProvider", () => {
8592 expect ( gitCollector . gatherChanges ) . toHaveBeenCalledTimes ( 1 )
8693 expect ( resolution ) . toEqual ( { changes : [ ] , files : [ ] , usedStaged : true } )
8794 } )
95+
96+ it ( "uses the SCM resource URI as the workspace path when provided" , ( ) => {
97+ const provider = createProvider ( )
98+
99+ expect ( ( provider as any ) . determineWorkspacePath ( vscode . Uri . file ( "/repo" ) ) ) . toBe ( "/repo" )
100+ } )
101+
102+ it ( "falls back to the workspace folder only when exactly one folder is open" , ( ) => {
103+ ; ( vscode . workspace as any ) . workspaceFolders = [ { uri : vscode . Uri . file ( "/single-root" ) } ]
104+ const provider = createProvider ( )
105+
106+ expect ( ( provider as any ) . determineWorkspacePath ( ) ) . toBe ( "/single-root" )
107+ } )
108+
109+ it ( "fails clearly instead of guessing in multi-root workspaces" , ( ) => {
110+ ; ( vscode . workspace as any ) . workspaceFolders = [
111+ { uri : vscode . Uri . file ( "/first-root" ) } ,
112+ { uri : vscode . Uri . file ( "/second-root" ) } ,
113+ ]
114+ const provider = createProvider ( )
115+
116+ expect ( ( ) => ( provider as any ) . determineWorkspacePath ( ) ) . toThrow (
117+ "Run this command from a specific Git source control input in a multi-root workspace" ,
118+ )
119+ } )
88120} )
0 commit comments