Skip to content

Commit 147ca50

Browse files
daniel-lxshannesrudolph
authored andcommitted
Fix Windows path handling in CustomModesManager test and remove unused import
- Fix path traversal test to use platform-aware paths with path.resolve() - Remove unused loadRuleFiles import from CustomModesManager.ts - Addresses review feedback for cross-platform compatibility
1 parent daae3d7 commit 147ca50

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/core/config/CustomModesManager.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { logger } from "../../utils/logging"
1313
import { GlobalFileNames } from "../../shared/globalFileNames"
1414
import { ensureSettingsDirectoryExists } from "../../utils/globalContext"
1515
import { t } from "../../i18n"
16-
import { loadRuleFiles } from "../prompts/sections/custom-instructions"
1716

1817
const ROOMODES_FILENAME = ".roomodes"
1918

src/core/config/__tests__/CustomModesManager.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ describe("CustomModesManager", () => {
6464
},
6565
} as unknown as vscode.ExtensionContext
6666

67-
mockWorkspaceFolders = [{ uri: { fsPath: "/mock/workspace" } }]
67+
const mockWorkspacePath = path.resolve("/mock/workspace")
68+
mockWorkspaceFolders = [{ uri: { fsPath: mockWorkspacePath } }]
6869
;(vscode.workspace as any).workspaceFolders = mockWorkspaceFolders
6970
;(vscode.workspace.onDidSaveTextDocument as Mock).mockReturnValue({ dispose: vi.fn() })
70-
;(getWorkspacePath as Mock).mockReturnValue("/mock/workspace")
71+
;(getWorkspacePath as Mock).mockReturnValue(mockWorkspacePath)
7172
;(fileExistsAtPath as Mock).mockImplementation(async (path: string) => {
7273
return path === mockSettingsPath || path === mockRoomodes
7374
})
@@ -1079,17 +1080,18 @@ describe("CustomModesManager", () => {
10791080
expect(result.success).toBe(true)
10801081

10811082
// Verify that no files were written outside the .roo directory
1083+
const mockWorkspacePath = path.resolve("/mock/workspace")
10821084
const writtenRuleFiles = writtenFiles.filter((p) => !p.includes(".roomodes"))
10831085
writtenRuleFiles.forEach((filePath) => {
10841086
const normalizedPath = path.normalize(filePath)
1085-
const expectedBasePath = path.normalize(path.join("/mock/workspace", ".roo"))
1087+
const expectedBasePath = path.normalize(path.join(mockWorkspacePath, ".roo"))
10861088
expect(normalizedPath.startsWith(expectedBasePath)).toBe(true)
10871089
})
10881090

10891091
// Verify that malicious paths were not written
10901092
expect(writtenFiles.some((p) => p.includes("etc/passwd"))).toBe(false)
10911093
expect(writtenFiles.some((p) => p.includes("sensitive.txt"))).toBe(false)
1092-
expect(writtenFiles.some((p) => path.isAbsolute(p) && !p.startsWith("/mock/workspace"))).toBe(false)
1094+
expect(writtenFiles.some((p) => path.isAbsolute(p) && !p.startsWith(mockWorkspacePath))).toBe(false)
10931095
})
10941096

10951097
it("should handle malformed YAML gracefully", async () => {

0 commit comments

Comments
 (0)