From b66149f6c09e2e4649a677049c9b47a336c6a3de Mon Sep 17 00:00:00 2001 From: Eason Liang <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Wed, 11 Nov 2026 03:42:34 +0800 Subject: [PATCH 1/2] 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. --- .../skills/__tests__/SkillsManager.spec.ts | 17 +-------------- .../skills/__tests__/skillsTestHarness.ts | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 src/services/skills/__tests__/skillsTestHarness.ts diff --git a/src/services/skills/__tests__/SkillsManager.spec.ts b/src/services/skills/__tests__/SkillsManager.spec.ts index 1d6727605e..c7c2944728 100644 --- a/src/services/skills/__tests__/SkillsManager.spec.ts +++ b/src/services/skills/__tests__/SkillsManager.spec.ts @@ -39,22 +39,11 @@ const { mockUnlink: vi.fn(), })) -// Platform-agnostic test paths -// Use forward slashes for consistency, then normalize with path.normalize -const HOME_DIR = process.platform === "win32" ? "C:\\Users\\testuser" : "/home/user" -const PROJECT_DIR = process.platform === "win32" ? "C:\\test\\project" : "/test/project" -const SHARED_DIR = process.platform === "win32" ? "C:\\shared\\skills" : "/shared/skills" - -// Helper to create platform-appropriate paths -const p = (...segments: string[]) => path.join(...segments) - +import { enoent, GLOBAL_AGENTS_DIR, GLOBAL_ROO_DIR, HOME_DIR, p, PROJECT_DIR, SHARED_DIR } from "./skillsTestHarness" // Make fs.lstat report the given paths as symlinks const mockSymlinks = (...paths: string[]) => mockLstat.mockImplementation(async (pathArg: string) => ({ isSymbolicLink: () => paths.includes(pathArg) })) -// A real not-found error, as fs throws for a missing path or broken symlink -const enoent = () => Object.assign(new Error("ENOENT: no such file or directory"), { code: "ENOENT" }) - // Mock fs/promises module vi.mock("fs/promises", () => ({ default: { @@ -107,10 +96,6 @@ vi.mock("vscode", () => ({ RelativePattern: vi.fn(), })) -// Global roo directory - computed once -const GLOBAL_ROO_DIR = p(HOME_DIR, ".roo") -const GLOBAL_AGENTS_DIR = p(HOME_DIR, ".agents") - // Mock roo-config vi.mock("../../roo-config", () => ({ getGlobalRooDirectory: () => GLOBAL_ROO_DIR, diff --git a/src/services/skills/__tests__/skillsTestHarness.ts b/src/services/skills/__tests__/skillsTestHarness.ts new file mode 100644 index 0000000000..eee3ecd471 --- /dev/null +++ b/src/services/skills/__tests__/skillsTestHarness.ts @@ -0,0 +1,21 @@ +// Shared, declaration-only harness for the skills tests: the platform-agnostic path constants, +// the path helper and the real not-found error factory. The vi.hoisted mock functions and every +// vi.mock call stay in SkillsManager.spec.ts, because moving those would change when the mocks are +// created relative to vitest's hoisting rather than only where the declarations live. + +import * as path from "path" + +// Platform-agnostic test paths +// Use forward slashes for consistency, then normalize with path.normalize +const HOME_DIR = process.platform === "win32" ? "C:\\Users\\testuser" : "/home/user" +const PROJECT_DIR = process.platform === "win32" ? "C:\\test\\project" : "/test/project" +const SHARED_DIR = process.platform === "win32" ? "C:\\shared\\skills" : "/shared/skills" +// Helper to create platform-appropriate paths +const p = (...segments: string[]) => path.join(...segments) +// A real not-found error, as fs throws for a missing path or broken symlink +const enoent = () => Object.assign(new Error("ENOENT: no such file or directory"), { code: "ENOENT" }) +// Global roo directory - computed once +const GLOBAL_ROO_DIR = p(HOME_DIR, ".roo") +const GLOBAL_AGENTS_DIR = p(HOME_DIR, ".agents") + +export { enoent, GLOBAL_AGENTS_DIR, GLOBAL_ROO_DIR, HOME_DIR, p, PROJECT_DIR, SHARED_DIR } From a237ff06221bf7f4ce8d89824f5e47688f4e323d Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Sun, 15 Nov 2026 00:33:34 +0800 Subject: [PATCH 2/2] 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. --- .../skills/__tests__/SkillsManager.spec.ts | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/services/skills/__tests__/SkillsManager.spec.ts b/src/services/skills/__tests__/SkillsManager.spec.ts index c7c2944728..e78462f23d 100644 --- a/src/services/skills/__tests__/SkillsManager.spec.ts +++ b/src/services/skills/__tests__/SkillsManager.spec.ts @@ -3259,3 +3259,46 @@ Instructions`) }) }) }) + +describe("skillsTestHarness platform branches", () => { + // The harness computes its constants once, at import time, from process.platform, so the branch + // the importing runner never takes is only exercisable by re-importing the module with that + // platform value installed. Both sides are asserted so the patch coverage lands whichever runner + // computes the report, and the module registry is reset back afterwards for the tests above. + const harnessUnderPlatform = async (platform: NodeJS.Platform) => { + const original = Object.getOwnPropertyDescriptor(process, "platform") + Object.defineProperty(process, "platform", { value: platform, configurable: true, writable: true }) + vi.resetModules() + try { + return await import("./skillsTestHarness") + } finally { + if (original) { + Object.defineProperty(process, "platform", original) + } + vi.resetModules() + } + } + + it("takes the win32 branch of each path constant", async () => { + const harness = await harnessUnderPlatform("win32") + expect(harness.HOME_DIR).toBe("C:\\Users\\testuser") + expect(harness.PROJECT_DIR).toBe("C:\\test\\project") + expect(harness.SHARED_DIR).toBe("C:\\shared\\skills") + expect(harness.GLOBAL_ROO_DIR).toBe(path.join("C:\\Users\\testuser", ".roo")) + expect(harness.GLOBAL_AGENTS_DIR).toBe(path.join("C:\\Users\\testuser", ".agents")) + expect(harness.p("skills", "code")).toBe(path.join("skills", "code")) + expect(harness.enoent().code).toBe("ENOENT") + }) + + it("takes the posix branch of each path constant", async () => { + const harness = await harnessUnderPlatform("linux") + expect(harness.HOME_DIR).toBe("/home/user") + expect(harness.PROJECT_DIR).toBe("/test/project") + expect(harness.SHARED_DIR).toBe("/shared/skills") + expect(harness.GLOBAL_ROO_DIR).toBe(path.join("/home/user", ".roo")) + expect(harness.GLOBAL_AGENTS_DIR).toBe(path.join("/home/user", ".agents")) + expect(harness.p("skills", "code")).toBe(path.join("skills", "code")) + expect(harness.enoent().code).toBe("ENOENT") + expect(harness.enoent().message).toBe("ENOENT: no such file or directory") + }) +})