-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroots.test.ts
More file actions
106 lines (95 loc) · 4.39 KB
/
Copy pathroots.test.ts
File metadata and controls
106 lines (95 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* Tests for workspace root resolution paths in src/server/roots.ts.
*
* Uses a simple tool (git_status) as the vehicle since the interesting
* resolution logic lives in requireGitAndRoots / resolveWorkspaceRoots,
* which are exercised whenever a tool is invoked.
*/
import { afterEach, describe, expect, test } from "bun:test";
import { mkdirSync } from "node:fs";
import { join } from "node:path";
import { registerGitInventoryTool } from "./git-inventory-tool.js";
import { registerGitStatusTool } from "./git-status-tool.js";
import { captureTool, cleanupTmpPaths, gitInitMain, mkTmpDir } from "./test-harness.js";
afterEach(cleanupTmpPaths);
describe("workspace root resolution", () => {
test("omitting workspaceRoot falls back to process.cwd() (which is a git repo in CI)", async () => {
// process.cwd() during tests is the project root — a valid git repo.
const run = captureTool(registerGitStatusTool);
const text = await run({ format: "json" });
const parsed = JSON.parse(text) as { groups?: unknown; error?: string };
// Either succeeds (returns groups) or returns an error — should not throw.
expect(parsed.groups !== undefined || parsed.error !== undefined).toBe(true);
});
test("allWorkspaceRoots=true with empty sessions falls back to process.cwd()", async () => {
const run = captureTool(registerGitStatusTool);
const text = await run({ allWorkspaceRoots: true, format: "json" });
const parsed = JSON.parse(text) as { groups?: unknown; error?: string };
expect(parsed.groups !== undefined || parsed.error !== undefined).toBe(true);
});
test("rootIndex out of range returns root_index_out_of_range (empty sessions)", async () => {
const run = captureTool(registerGitStatusTool);
// With sessions=[], any numeric rootIndex will be out of range.
const text = await run({ rootIndex: 99, format: "json" });
const parsed = JSON.parse(text) as { error: string };
expect(parsed.error).toBe("root_index_out_of_range");
});
test("absoluteGitRoots: two sibling repos → two status groups", async () => {
const a = mkTmpDir("abs-root-a-");
const b = mkTmpDir("abs-root-b-");
gitInitMain(a);
gitInitMain(b);
const run = captureTool(registerGitStatusTool);
const text = await run({ format: "json", absoluteGitRoots: [a, b] });
const parsed = JSON.parse(text) as { groups?: { mcpRoot: string; repos: unknown[] }[] };
expect(parsed.groups?.length).toBe(2);
expect(parsed.groups?.[0]?.mcpRoot).toBe(a);
expect(parsed.groups?.[1]?.mcpRoot).toBe(b);
});
test("uses MCP client roots when workspaceRoot is omitted", async () => {
const a = mkTmpDir("mcp-root-a-");
const b = mkTmpDir("mcp-root-b-");
gitInitMain(a);
gitInitMain(b);
const run = captureTool(registerGitStatusTool, undefined, [
`file://${a}`,
"vscode-remote://ssh-remote/ignored",
`file://${b}`,
]);
const text = await run({ allWorkspaceRoots: true, format: "json" });
const parsed = JSON.parse(text) as { groups?: { mcpRoot: string }[] };
expect(parsed.groups?.map((g) => g.mcpRoot)).toEqual([a, b]);
});
test("absoluteGitRoots dedupes same repo (nested path + root)", async () => {
const a = mkTmpDir("abs-root-dedupe-");
gitInitMain(a);
const nested = join(a, "subdir");
mkdirSync(nested, { recursive: true });
const run = captureTool(registerGitStatusTool);
const text = await run({ format: "json", absoluteGitRoots: [nested, a] });
const parsed = JSON.parse(text) as { groups?: unknown[] };
expect(parsed.groups?.length).toBe(1);
});
test("absoluteGitRoots + workspaceRoot → absolute_git_roots_exclusive", async () => {
const run = captureTool(registerGitStatusTool);
const text = await run({
format: "json",
absoluteGitRoots: [process.cwd()],
workspaceRoot: process.cwd(),
});
const parsed = JSON.parse(text) as { error?: string };
expect(parsed.error).toBe("absolute_git_roots_exclusive");
});
test("git_inventory absoluteGitRoots + nestedRoots → conflict", async () => {
const a = mkTmpDir("abs-inv-");
gitInitMain(a);
const run = captureTool(registerGitInventoryTool);
const text = await run({
format: "json",
absoluteGitRoots: [a],
nestedRoots: ["."],
});
const parsed = JSON.parse(text) as { error?: string };
expect(parsed.error).toBe("absolute_git_roots_nested_or_preset_conflict");
});
});