repositories / pi-ext
pi-ext
bugabingas pi extensions
owned by admin
extensions/devdocs/__tests__/settings.test.ts
Rawimport { expect, it } from "vitest";
import { installedVersion } from "../src/adapters/local.ts";
import { defaultDatabasePath, parsePath } from "../src/settings.ts";
import { matchesVersion } from "../src/types.ts";
it("uses platform-specific cache roots independent of this host", () => {
expect(
defaultDatabasePath("linux", "/users/example", {
XDG_CACHE_HOME: "/cache",
}),
).toBe("/cache/pi/devdocs/cache.db");
expect(
defaultDatabasePath("linux", "/users/example", {
XDG_CACHE_HOME: "relative",
}),
).toBe("/users/example/.cache/pi/devdocs/cache.db");
expect(defaultDatabasePath("darwin", "/Users/example", {})).toBe(
"/Users/example/Library/Caches/pi/devdocs/cache.db",
);
expect(
defaultDatabasePath("win32", "C:\\Users\\Example", {
LOCALAPPDATA: "D:\\Cache",
}),
).toBe("D:\\Cache\\pi\\devdocs\\cache.db");
expect(() => parsePath("~/docs.db")).toThrow();
});
it("extracts full installed versions including prefixed Node releases", () => {
expect(installedVersion("v26.13.0\n")).toBe("26.13.0");
expect(installedVersion("git version 2.56.0\n")).toBe("2.56.0");
expect(installedVersion("0.116.1\n")).toBe("0.116.1");
});
it("rejects substituted exact releases and unknown version evidence", () => {
expect(matchesVersion("1.2.3", "1.2.4")).toBe(false);
expect(matchesVersion("1.2", "1.2.4")).toBe(true);
expect(matchesVersion("1", null)).toBe(false);
});