Files
openclaw/src/commands/daemon-install-plan.shared.test.ts
Jayesh Betala 66d1d13889 fix(gateway): include openclaw bin in service PATH (#84475)
* fix(gateway): include openclaw bin in service PATH

* fix(doctor): accept expected service PATH

* docs(changelog): mention managed service PATH bin fix

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
2026-05-22 21:28:50 +08:00

110 lines
3.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
resolveDaemonInstallRuntimeInputs,
resolveDaemonNodeBinDir,
resolveDaemonOpenClawBinDir,
resolveDaemonServicePathDirs,
resolveGatewayDevMode,
} from "./daemon-install-plan.shared.js";
describe("resolveGatewayDevMode", () => {
it("detects src ts entrypoints", () => {
expect(resolveGatewayDevMode(["node", "/Users/me/openclaw/src/cli/index.ts"])).toBe(true);
expect(resolveGatewayDevMode(["node", "C:\\Users\\me\\openclaw\\src\\cli\\index.ts"])).toBe(
true,
);
expect(resolveGatewayDevMode(["node", "/Users/me/openclaw/dist/cli/index.js"])).toBe(false);
});
});
describe("resolveDaemonInstallRuntimeInputs", () => {
it("keeps explicit devMode and nodePath overrides", async () => {
await expect(
resolveDaemonInstallRuntimeInputs({
env: {},
runtime: "node",
devMode: false,
nodePath: "/custom/node",
}),
).resolves.toEqual({
devMode: false,
nodePath: "/custom/node",
});
});
});
describe("resolveDaemonNodeBinDir", () => {
it("returns the absolute node bin directory", () => {
expect(resolveDaemonNodeBinDir("/custom/node/bin/node")).toEqual(["/custom/node/bin"]);
});
it("ignores bare executable names", () => {
expect(resolveDaemonNodeBinDir("node")).toBeUndefined();
});
});
describe("resolveDaemonOpenClawBinDir", () => {
it("uses the active openclaw command directory", () => {
expect(
resolveDaemonOpenClawBinDir({
argv: ["node", "/Users/testuser/.npm-global/bin/openclaw", "gateway", "install"],
env: { PATH: "" },
platform: "darwin",
}),
).toEqual(["/Users/testuser/.npm-global/bin"]);
});
it("finds the PATH shim that resolves to the active package entrypoint", () => {
const realpaths = new Map([
["/Users/testuser/.npm-global/bin/openclaw", "/pkg/openclaw/openclaw.mjs"],
[
"/Users/testuser/.npm-global/lib/node_modules/openclaw/openclaw.mjs",
"/pkg/openclaw/openclaw.mjs",
],
]);
expect(
resolveDaemonOpenClawBinDir({
argv: [
"node",
"/Users/testuser/.npm-global/lib/node_modules/openclaw/openclaw.mjs",
"gateway",
"install",
],
env: { PATH: "/Users/testuser/.npm-global/bin:/usr/bin" },
platform: "darwin",
existsSync: (candidate) => candidate === "/Users/testuser/.npm-global/bin/openclaw",
realpathSync: (candidate) => realpaths.get(candidate) ?? candidate,
}),
).toEqual(["/Users/testuser/.npm-global/bin"]);
});
it("ignores unrelated openclaw commands elsewhere on PATH", () => {
expect(
resolveDaemonOpenClawBinDir({
argv: ["node", "/opt/openclaw/openclaw.mjs", "gateway", "install"],
env: { PATH: "/Users/testuser/.npm-global/bin" },
platform: "darwin",
existsSync: () => true,
realpathSync: (candidate) =>
candidate === "/Users/testuser/.npm-global/bin/openclaw"
? "/other/openclaw.mjs"
: candidate,
}),
).toBeUndefined();
});
});
describe("resolveDaemonServicePathDirs", () => {
it("combines node and active openclaw command directories", () => {
expect(
resolveDaemonServicePathDirs({
nodePath: "/opt/homebrew/opt/node/bin/node",
argv: ["node", "/Users/testuser/.npm-global/bin/openclaw", "gateway", "install"],
env: { PATH: "" },
platform: "darwin",
}),
).toEqual(["/opt/homebrew/opt/node/bin", "/Users/testuser/.npm-global/bin"]);
});
});