-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy path0000-rules-finder-cross-drive-project-scope.test.ts
More file actions
47 lines (41 loc) · 1.54 KB
/
Copy path0000-rules-finder-cross-drive-project-scope.test.ts
File metadata and controls
47 lines (41 loc) · 1.54 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
import { win32 } from "node:path";
import { describe, expect, it, vi } from "vitest";
import { findRuleCandidates } from "../../../src/core/extensions/builtin/rules/rules/finder.ts";
const { projectRoot, crossDriveTarget, crossDriveAgentsMd, homeDir } = vi.hoisted(() => ({
projectRoot: "C:\\workspace\\proj",
crossDriveTarget: "D:\\other\\file.ts",
crossDriveAgentsMd: "D:\\other\\AGENTS.md",
homeDir: "C:\\Users\\test",
}));
vi.mock("node:fs", () => ({
existsSync: (path: string) => path === crossDriveAgentsMd,
statSync: () => ({ isFile: () => true, isDirectory: () => false }),
lstatSync: () => ({ isSymbolicLink: () => false }),
readdirSync: () => [],
realpathSync: Object.assign((path: string) => path, { native: (path: string) => path }),
}));
vi.mock("node:path", async (importOriginal) => {
const path = await importOriginal<typeof import("node:path")>();
return {
...path,
dirname: path.win32.dirname,
join: path.win32.join,
relative: path.win32.relative,
resolve: path.win32.resolve,
};
});
describe("rules finder cross-drive project scope", () => {
it("#given a target file on a different drive than the project root #when collecting project rule candidates #then rules outside the project root are not collected", () => {
// given
expect(win32.relative(projectRoot, "D:\\other")).toBe("D:\\other");
// when
const candidates = findRuleCandidates({
projectRoot,
targetFile: crossDriveTarget,
homeDir,
skipUserHome: true,
});
// then
expect(candidates.map((candidate) => candidate.path)).toEqual([]);
});
});