fix(FN-XXX): harden windows path handling

This commit is contained in:
gsxdsm
2026-04-29 07:35:23 -07:00
parent dba6059080
commit bd14cf84e3
17 changed files with 189 additions and 32 deletions

View File

@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { createSkillsAdapter } from "../skills-adapter.js";
import { createSkillsAdapter, extractSkillName } from "../skills-adapter.js";
import { writeFile, mkdir, access } from "node:fs/promises";
import { join, dirname } from "node:path";
import { tmpdir } from "node:os";
@@ -531,3 +531,10 @@ describe("createSkillsAdapter - readSkillContent", () => {
await cleanup(skillDir);
});
});
describe("extractSkillName", () => {
it("normalizes Windows separators before deriving the display name", () => {
expect(extractSkillName("skills\\tooling\\windows-fix", "npm")).toBe("tooling/windows-fix");
expect(extractSkillName("windows-fix", "npm")).toBe("windows-fix");
});
});

View File

@@ -106,6 +106,24 @@ describe("usage", () => {
expect(second).not.toBe(first);
expect(second).toHaveLength(0);
});
it("falls back to USERPROFILE when HOME is unset", async () => {
vi.stubEnv("HOME", "");
vi.stubEnv("USERPROFILE", "/profiles/test-user");
mockReadFile.mockImplementation(async () => {
return Promise.reject(new Error("File not found"));
});
await fetchAllProviderUsage();
const readPaths = mockReadFile.mock.calls.map(([filePath]) => String(filePath));
expect(readPaths).toContain("/profiles/test-user/.claude/.credentials.json");
expect(readPaths).toContain("/profiles/test-user/.config/claude/.credentials.json");
expect(readPaths).toContain("/profiles/test-user/.codex/auth.json");
expect(readPaths).toContain("/profiles/test-user/.gemini/oauth_creds.json");
expect(readPaths.some((filePath) => filePath.startsWith("/home/testuser/"))).toBe(false);
});
});
describe("fetchGitHubCopilotUsage (via fetchAllProviderUsage)", () => {