63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
import path from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
buildMinimalServicePath,
|
|
buildServiceEnvironment,
|
|
} from "./service-env.js";
|
|
|
|
describe("buildMinimalServicePath", () => {
|
|
it("includes Homebrew + system dirs on macOS", () => {
|
|
const result = buildMinimalServicePath({
|
|
platform: "darwin",
|
|
});
|
|
const parts = result.split(path.delimiter);
|
|
expect(parts).toContain("/opt/homebrew/bin");
|
|
expect(parts).toContain("/usr/local/bin");
|
|
expect(parts).toContain("/usr/bin");
|
|
expect(parts).toContain("/bin");
|
|
});
|
|
|
|
it("returns PATH as-is on Windows", () => {
|
|
const result = buildMinimalServicePath({
|
|
env: { PATH: "C:\\\\Windows\\\\System32" },
|
|
platform: "win32",
|
|
});
|
|
expect(result).toBe("C:\\\\Windows\\\\System32");
|
|
});
|
|
|
|
it("includes extra directories when provided", () => {
|
|
const result = buildMinimalServicePath({
|
|
platform: "linux",
|
|
extraDirs: ["/custom/tools"],
|
|
});
|
|
expect(result.split(path.delimiter)).toContain("/custom/tools");
|
|
});
|
|
|
|
it("deduplicates directories", () => {
|
|
const result = buildMinimalServicePath({
|
|
platform: "linux",
|
|
extraDirs: ["/usr/bin"],
|
|
});
|
|
const parts = result.split(path.delimiter);
|
|
const unique = [...new Set(parts)];
|
|
expect(parts.length).toBe(unique.length);
|
|
});
|
|
});
|
|
|
|
describe("buildServiceEnvironment", () => {
|
|
it("sets minimal PATH and gateway vars", () => {
|
|
const env = buildServiceEnvironment({
|
|
env: { HOME: "/home/user" },
|
|
port: 18789,
|
|
token: "secret",
|
|
});
|
|
if (process.platform === "win32") {
|
|
expect(env.PATH).toBe("");
|
|
} else {
|
|
expect(env.PATH).toContain("/usr/bin");
|
|
}
|
|
expect(env.CLAWDBOT_GATEWAY_PORT).toBe("18789");
|
|
expect(env.CLAWDBOT_GATEWAY_TOKEN).toBe("secret");
|
|
});
|
|
});
|