Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 44 additions & 16 deletions src/services/skills/__tests__/SkillsManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"))
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")
})
})
21 changes: 21 additions & 0 deletions src/services/skills/__tests__/skillsTestHarness.ts
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 }
Loading