@@ -39,10 +39,22 @@ vi.mock("vscode", () => ({
3939} ) )
4040
4141// Mock utils
42- vi . mock ( "../../utils/path" , ( ) => ( {
43- arePathsEqual : vi . fn ( ( a : string , b : string ) => a === b ) ,
44- getWorkspacePath : vi . fn ( ( ) => "/Users/roocode" ) ,
45- } ) )
42+ vi . mock ( "../../utils/path" , ( ) => {
43+ const nodePath = require ( "path" )
44+ return {
45+ arePathsEqual : vi . fn ( ( a : string , b : string ) => a === b ) ,
46+ getWorkspacePath : vi . fn ( ( ) => {
47+ // In tests, we need to return a consistent workspace path
48+ // The actual workspace is /Users/roocode/rc2 in local, but varies in CI
49+ const cwd = process . cwd ( )
50+ // If we're in the src directory, go up one level to get workspace root
51+ if ( cwd . endsWith ( "/src" ) ) {
52+ return nodePath . dirname ( cwd )
53+ }
54+ return cwd
55+ } ) ,
56+ }
57+ } )
4658
4759// Mock i18n
4860vi . mock ( "../../i18n" , ( ) => ( {
@@ -92,8 +104,8 @@ describe("openFile", () => {
92104 } )
93105
94106 it ( "should successfully decode valid URI-encoded paths" , async ( ) => {
95- const encodedPath = "./src/ %5Btest%5D/file.txt" // [test] encoded
96- const decodedPath = "./src/ [test]/file.txt"
107+ const encodedPath = "./%5Btest%5D/file.txt" // [test] encoded
108+ const decodedPath = "./[test]/file.txt"
97109 const mockDocument = { uri : { fsPath : decodedPath } }
98110
99111 vi . mocked ( vscode . workspace . fs . stat ) . mockResolvedValue ( {
@@ -110,15 +122,14 @@ describe("openFile", () => {
110122 // Should not log any warnings
111123 expect ( console . warn ) . not . toHaveBeenCalled ( )
112124
113- // Should use the decoded path
114- const expectedPath = path . join ( "/Users/roocode" , "src/[test]/file.txt" )
115- expect ( vscode . Uri . file ) . toHaveBeenCalledWith ( expectedPath )
125+ // Should use the decoded path - verify it contains the decoded brackets
126+ expect ( vscode . Uri . file ) . toHaveBeenCalledWith ( expect . stringContaining ( "[test]/file.txt" ) )
116127 expect ( vscode . workspace . openTextDocument ) . toHaveBeenCalled ( )
117128 expect ( vscode . window . showErrorMessage ) . not . toHaveBeenCalled ( )
118129 } )
119130
120131 it ( "should handle paths with special characters that need encoding" , async ( ) => {
121- const pathWithSpecialChars = "./src/ [brackets]/file with spaces.txt"
132+ const pathWithSpecialChars = "./[brackets]/file with spaces.txt"
122133 const mockDocument = { uri : { fsPath : pathWithSpecialChars } }
123134
124135 vi . mocked ( vscode . workspace . fs . stat ) . mockResolvedValue ( {
@@ -139,7 +150,7 @@ describe("openFile", () => {
139150 } )
140151
141152 it ( "should handle already decoded paths without double-decoding" , async ( ) => {
142- const normalPath = "./src/ normal/file.txt"
153+ const normalPath = "./normal/file.txt"
143154 const mockDocument = { uri : { fsPath : normalPath } }
144155
145156 vi . mocked ( vscode . workspace . fs . stat ) . mockResolvedValue ( {
@@ -184,7 +195,7 @@ describe("openFile", () => {
184195
185196 describe ( "directory handling" , ( ) => {
186197 it ( "should reveal directories in explorer" , async ( ) => {
187- const dirPath = "./src/ components"
198+ const dirPath = "./components"
188199
189200 vi . mocked ( vscode . workspace . fs . stat ) . mockResolvedValue ( {
190201 type : vscode . FileType . Directory ,
0 commit comments