Skip to content

Commit e3de60a

Browse files
test(skills): move shared spec fixtures into a named harness module (#2417)
* test(skills): move shared spec declarations into skillsTestHarness.ts The platform path constants, the p() helper and the enoent() not-found factory that SkillsManager.spec.ts declared at module scope now live in src/services/skills/__tests__/skillsTestHarness.ts and are imported back. The 12 moved lines are byte-identical to the lines they were cut from, and the vi.hoisted mock functions plus every vi.mock call stay in the spec: vitest hoists them per file, so moving them would change when the mocks are created rather than only where the declarations live. mockSymlinks stays too, because it closes over the spec-local mockLstat. No test and no assertion changed. The spec's assertion-line multiset is identical before and after the move, eslint reports 0 problems for both files with --prune-suppressions and the suppression count for the spec stays at 2, prettier --check passes for both files, and the focused suite passes 94 of 94 tests on node v22.23.4 in a linked worktree on Windows. * test(skills): cover both platform branches of the harness path constants The harness computes HOME_DIR, PROJECT_DIR and SHARED_DIR once at import time, so the branch the importing runner never takes stayed a partial on the patch. Re-import the module under each platform value and assert both sides, at the layer that already owns the harness. --------- Co-authored-by: edelauna <54631123+edelauna@users.noreply.github.com>
1 parent 44cf712 commit e3de60a

2 files changed

Lines changed: 65 additions & 16 deletions

File tree

‎src/services/skills/__tests__/SkillsManager.spec.ts‎

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,11 @@ const {
3939
mockUnlink: vi.fn(),
4040
}))
4141

42-
// Platform-agnostic test paths
43-
// Use forward slashes for consistency, then normalize with path.normalize
44-
const HOME_DIR = process.platform === "win32" ? "C:\\Users\\testuser" : "/home/user"
45-
const PROJECT_DIR = process.platform === "win32" ? "C:\\test\\project" : "/test/project"
46-
const SHARED_DIR = process.platform === "win32" ? "C:\\shared\\skills" : "/shared/skills"
47-
48-
// Helper to create platform-appropriate paths
49-
const p = (...segments: string[]) => path.join(...segments)
50-
42+
import { enoent, GLOBAL_AGENTS_DIR, GLOBAL_ROO_DIR, HOME_DIR, p, PROJECT_DIR, SHARED_DIR } from "./skillsTestHarness"
5143
// Make fs.lstat report the given paths as symlinks
5244
const mockSymlinks = (...paths: string[]) =>
5345
mockLstat.mockImplementation(async (pathArg: string) => ({ isSymbolicLink: () => paths.includes(pathArg) }))
5446

55-
// A real not-found error, as fs throws for a missing path or broken symlink
56-
const enoent = () => Object.assign(new Error("ENOENT: no such file or directory"), { code: "ENOENT" })
57-
5847
// Mock fs/promises module
5948
vi.mock("fs/promises", () => ({
6049
default: {
@@ -107,10 +96,6 @@ vi.mock("vscode", () => ({
10796
RelativePattern: vi.fn(),
10897
}))
10998

110-
// Global roo directory - computed once
111-
const GLOBAL_ROO_DIR = p(HOME_DIR, ".roo")
112-
const GLOBAL_AGENTS_DIR = p(HOME_DIR, ".agents")
113-
11499
// Mock roo-config
115100
vi.mock("../../roo-config", () => ({
116101
getGlobalRooDirectory: () => GLOBAL_ROO_DIR,
@@ -3340,3 +3325,46 @@ Instructions`)
33403325
})
33413326
})
33423327
})
3328+
3329+
describe("skillsTestHarness platform branches", () => {
3330+
// The harness computes its constants once, at import time, from process.platform, so the branch
3331+
// the importing runner never takes is only exercisable by re-importing the module with that
3332+
// platform value installed. Both sides are asserted so the patch coverage lands whichever runner
3333+
// computes the report, and the module registry is reset back afterwards for the tests above.
3334+
const harnessUnderPlatform = async (platform: NodeJS.Platform) => {
3335+
const original = Object.getOwnPropertyDescriptor(process, "platform")
3336+
Object.defineProperty(process, "platform", { value: platform, configurable: true, writable: true })
3337+
vi.resetModules()
3338+
try {
3339+
return await import("./skillsTestHarness")
3340+
} finally {
3341+
if (original) {
3342+
Object.defineProperty(process, "platform", original)
3343+
}
3344+
vi.resetModules()
3345+
}
3346+
}
3347+
3348+
it("takes the win32 branch of each path constant", async () => {
3349+
const harness = await harnessUnderPlatform("win32")
3350+
expect(harness.HOME_DIR).toBe("C:\\Users\\testuser")
3351+
expect(harness.PROJECT_DIR).toBe("C:\\test\\project")
3352+
expect(harness.SHARED_DIR).toBe("C:\\shared\\skills")
3353+
expect(harness.GLOBAL_ROO_DIR).toBe(path.join("C:\\Users\\testuser", ".roo"))
3354+
expect(harness.GLOBAL_AGENTS_DIR).toBe(path.join("C:\\Users\\testuser", ".agents"))
3355+
expect(harness.p("skills", "code")).toBe(path.join("skills", "code"))
3356+
expect(harness.enoent().code).toBe("ENOENT")
3357+
})
3358+
3359+
it("takes the posix branch of each path constant", async () => {
3360+
const harness = await harnessUnderPlatform("linux")
3361+
expect(harness.HOME_DIR).toBe("/home/user")
3362+
expect(harness.PROJECT_DIR).toBe("/test/project")
3363+
expect(harness.SHARED_DIR).toBe("/shared/skills")
3364+
expect(harness.GLOBAL_ROO_DIR).toBe(path.join("/home/user", ".roo"))
3365+
expect(harness.GLOBAL_AGENTS_DIR).toBe(path.join("/home/user", ".agents"))
3366+
expect(harness.p("skills", "code")).toBe(path.join("skills", "code"))
3367+
expect(harness.enoent().code).toBe("ENOENT")
3368+
expect(harness.enoent().message).toBe("ENOENT: no such file or directory")
3369+
})
3370+
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Shared, declaration-only harness for the skills tests: the platform-agnostic path constants,
2+
// the path helper and the real not-found error factory. The vi.hoisted mock functions and every
3+
// vi.mock call stay in SkillsManager.spec.ts, because moving those would change when the mocks are
4+
// created relative to vitest's hoisting rather than only where the declarations live.
5+
6+
import * as path from "path"
7+
8+
// Platform-agnostic test paths
9+
// Use forward slashes for consistency, then normalize with path.normalize
10+
const HOME_DIR = process.platform === "win32" ? "C:\\Users\\testuser" : "/home/user"
11+
const PROJECT_DIR = process.platform === "win32" ? "C:\\test\\project" : "/test/project"
12+
const SHARED_DIR = process.platform === "win32" ? "C:\\shared\\skills" : "/shared/skills"
13+
// Helper to create platform-appropriate paths
14+
const p = (...segments: string[]) => path.join(...segments)
15+
// A real not-found error, as fs throws for a missing path or broken symlink
16+
const enoent = () => Object.assign(new Error("ENOENT: no such file or directory"), { code: "ENOENT" })
17+
// Global roo directory - computed once
18+
const GLOBAL_ROO_DIR = p(HOME_DIR, ".roo")
19+
const GLOBAL_AGENTS_DIR = p(HOME_DIR, ".agents")
20+
21+
export { enoent, GLOBAL_AGENTS_DIR, GLOBAL_ROO_DIR, HOME_DIR, p, PROJECT_DIR, SHARED_DIR }

0 commit comments

Comments
 (0)