fix: resolve npx gateway daemon install
This commit is contained in:
71
src/daemon/program-args.test.ts
Normal file
71
src/daemon/program-args.test.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const access = vi.fn();
|
||||
const realpath = vi.fn();
|
||||
|
||||
vi.mock("node:fs/promises", () => ({
|
||||
default: { access, realpath },
|
||||
access,
|
||||
realpath,
|
||||
}));
|
||||
|
||||
import { resolveGatewayProgramArguments } from "./program-args.js";
|
||||
|
||||
const originalArgv = [...process.argv];
|
||||
|
||||
afterEach(() => {
|
||||
process.argv = [...originalArgv];
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
describe("resolveGatewayProgramArguments", () => {
|
||||
it("uses realpath-resolved dist entry when running via npx shim", async () => {
|
||||
process.argv = [
|
||||
"node",
|
||||
"/tmp/.npm/_npx/63c3/node_modules/.bin/clawdbot",
|
||||
];
|
||||
realpath.mockResolvedValue(
|
||||
"/tmp/.npm/_npx/63c3/node_modules/clawdbot/dist/entry.js",
|
||||
);
|
||||
access.mockImplementation(async (target: string) => {
|
||||
if (target === "/tmp/.npm/_npx/63c3/node_modules/clawdbot/dist/entry.js") {
|
||||
return;
|
||||
}
|
||||
throw new Error("missing");
|
||||
});
|
||||
|
||||
const result = await resolveGatewayProgramArguments({ port: 18789 });
|
||||
|
||||
expect(result.programArguments).toEqual([
|
||||
process.execPath,
|
||||
"/tmp/.npm/_npx/63c3/node_modules/clawdbot/dist/entry.js",
|
||||
"gateway-daemon",
|
||||
"--port",
|
||||
"18789",
|
||||
]);
|
||||
});
|
||||
|
||||
it("falls back to node_modules package dist when .bin path is not resolved", async () => {
|
||||
process.argv = [
|
||||
"node",
|
||||
"/tmp/.npm/_npx/63c3/node_modules/.bin/clawdbot",
|
||||
];
|
||||
realpath.mockRejectedValue(new Error("no realpath"));
|
||||
access.mockImplementation(async (target: string) => {
|
||||
if (target === "/tmp/.npm/_npx/63c3/node_modules/clawdbot/dist/index.js") {
|
||||
return;
|
||||
}
|
||||
throw new Error("missing");
|
||||
});
|
||||
|
||||
const result = await resolveGatewayProgramArguments({ port: 18789 });
|
||||
|
||||
expect(result.programArguments).toEqual([
|
||||
process.execPath,
|
||||
"/tmp/.npm/_npx/63c3/node_modules/clawdbot/dist/index.js",
|
||||
"gateway-daemon",
|
||||
"--port",
|
||||
"18789",
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user