Skip to content

Commit 8289534

Browse files
test(mcp): pin the fallback workspace root for both the settings path and confineTo
PR 1913's head review 5843751481 lists a failed pre-merge check whose Regression Evidence item reads: "Add an MCP call-site test with provider `cwd` unavailable. Mock `getWorkspacePath()` to return a distinct path and assert that the project write uses it for both the settings path and `confineTo`. Retain the explicit-`cwd` and global-write tests." The four rows already in src/services/mcp/__tests__/McpHub.spec.ts under "project-scoped write confinement at every call site" all install mockProvider.cwd, so the fallback branch at McpHub.ts:2080 was never taken at a call site and getWorkspacePath was never mocked in this file. This adds the missing row and keeps the four existing rows untouched. The new row installs an absent cwd, lets the mocked getWorkspacePath return /fallback/workspace, and asserts both halves: the project settings path is /fallback/workspace/.roo/mcp.json and the confinement root handed to safeWriteJson is /fallback/workspace. The point is that one root serves both purposes, so a project write taken without a provider cwd is confined to the directory it actually writes into. Kill evidence, all in wt-r160-1913 at node v22.23.4 over this spec file (94 tests with the new row): - replacing the fallback at McpHub.ts:2080 with a different directory gave 1 failed, 93 passed: only the new row failed, so it is what pins the settings-path half. - giving project writes a different defined confinement root at McpHub.ts:2142 gave 2 failed, 92 passed: the new row and the existing explicit-cwd row, so the confinement half is held from two sides. - dropping the fallback in favour of the provider cwd alone at line 2142 gave 2 failed, 92 passed, the new row and the global-write row that expects an unconstrained confineTo. - a mutant that changes only getProjectMcpPath's default parameter at line 634 survived this row (94 passed), because these call sites pass the root explicitly, so the row does not claim the default parameter is exercised; the row covers the shared write root at 2080 and its use at 2142. - unmutated: exit 0, 94 passed of 94 in this file. eslint --prune-suppressions --max-warnings=0 on services/mcp/__tests__/McpHub.spec.ts exits 0 with no output, and the file has no entry in src/eslint-suppressions.json, so its count is 0 before and 0 after. This commit stages only that one path; a pre-existing modification of src/eslint-suppressions.json left behind in this worktree by an earlier prune run (33,294 B against 30,910 B committed) is neither staged nor reverted here. No --no-verify, no HUSKY=0, no git add -A, no changeset, no CHANGELOG, no label change.
1 parent 2960636 commit 8289534

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎src/services/mcp/__tests__/McpHub.spec.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ vi.mock("chokidar", () => ({
156156
},
157157
}))
158158

159+
// Only getWorkspacePath is replaced; the original module is loaded and spread so its side effect
160+
// (installing String.prototype.toPosix) and its other exports keep working for this file. The fallback
161+
// is what the fallback test inside the confinement describe below exercises, so it must be distinguishable
162+
// from any workspace path a test could otherwise compute.
163+
vi.mock("../../../utils/path", async (importOriginal) => {
164+
const actual = await importOriginal<typeof import("../../../utils/path")>()
165+
return { ...actual, getWorkspacePath: vi.fn(() => "/fallback/workspace") }
166+
})
167+
159168
describe("McpHub", () => {
160169
let mcpHub: McpHubType
161170
let mockProvider: Partial<ClineProvider>
@@ -1292,6 +1301,24 @@ describe("McpHub", () => {
12921301
expect(write[2]?.confineTo).toBeUndefined()
12931302
}
12941303
})
1304+
it("uses the fallback workspace path for both the settings path and the confinement root when the provider carries no cwd", async () => {
1305+
// The provider is reachable but has no cwd, which is the state the `?? getWorkspacePath()` fallback at
1306+
// src/services/mcp/McpHub.ts:2080 exists for. The row pins that ONE root serves both purposes: the
1307+
// project settings path is built from the fallback and the confinement root handed to safeWriteJson is
1308+
// that same fallback, so a project write taken without a provider cwd is confined to the very directory
1309+
// it writes into rather than going unconstrained or being confined to a different directory. cwd is a
1310+
// getter on ClineProvider, so the test installs the absent value.
1311+
Object.defineProperty(mockProvider, "cwd", { value: undefined, configurable: true })
1312+
vi.mocked(fs.readFile).mockResolvedValueOnce(projectConfigJson)
1313+
mcpHub.connections = [connectionFor("project")]
1314+
1315+
await mcpHub.updateServerTimeout("test-server", 120)
1316+
1317+
const write = vi.mocked(safeWriteJson).mock.calls.find((call) => String(call[0]).includes(".roo"))
1318+
expect(write).toBeDefined()
1319+
expect(String(write![0]).split("\\").join("/")).toContain("/fallback/workspace/.roo/mcp.json")
1320+
expect(write![2]).toEqual(expect.objectContaining({ confineTo: "/fallback/workspace" }))
1321+
})
12951322
})
12961323

12971324
describe("toggleToolAlwaysAllow", () => {

0 commit comments

Comments
 (0)