Repository navigation
test(skills): move shared spec fixtures into a named harness module #2417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b66149f
74c08f1
a237ff0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
|
@@ -3274,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")) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| expect(harness.enoent().code).toBe("ENOENT") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The harness comment says |
||
| }) | ||
|
|
||
| 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") | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This describe exists to satisfy
codecov/patchfor a declaration-only helper, and it resets the module registry and overridesprocess.platforminside the production spec. Would making the harness constants platform-neutral, adding the file to theignore:list incodecov.yml, or moving the block to its ownskillsTestHarness.spec.tswork instead?