mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 15:07:27 +00:00
fix(daemon): guard preferred node selection
This commit is contained in:
@@ -70,6 +70,31 @@ describe("resolvePreferredNodePath", () => {
|
||||
expect(execFile).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it("ignores execPath when it is not node", async () => {
|
||||
fsMocks.access.mockImplementation(async (target: string) => {
|
||||
if (target === darwinNode) {
|
||||
return;
|
||||
}
|
||||
throw new Error("missing");
|
||||
});
|
||||
|
||||
const execFile = vi.fn().mockResolvedValue({ stdout: "22.12.0\n", stderr: "" });
|
||||
|
||||
const result = await resolvePreferredNodePath({
|
||||
env: {},
|
||||
runtime: "node",
|
||||
platform: "darwin",
|
||||
execFile,
|
||||
execPath: "/Users/test/.bun/bin/bun",
|
||||
});
|
||||
|
||||
expect(result).toBe(darwinNode);
|
||||
expect(execFile).toHaveBeenCalledTimes(1);
|
||||
expect(execFile).toHaveBeenCalledWith(darwinNode, ["-p", "process.versions.node"], {
|
||||
encoding: "utf8",
|
||||
});
|
||||
});
|
||||
|
||||
it("uses system node when it meets the minimum version", async () => {
|
||||
fsMocks.access.mockImplementation(async (target: string) => {
|
||||
if (target === darwinNode) {
|
||||
|
||||
@@ -19,6 +19,12 @@ function getPathModule(platform: NodeJS.Platform) {
|
||||
return platform === "win32" ? path.win32 : path.posix;
|
||||
}
|
||||
|
||||
function isNodeExecPath(execPath: string, platform: NodeJS.Platform): boolean {
|
||||
const pathModule = getPathModule(platform);
|
||||
const base = pathModule.basename(execPath).toLowerCase();
|
||||
return base === "node" || base === "node.exe";
|
||||
}
|
||||
|
||||
function normalizeForCompare(input: string, platform: NodeJS.Platform): string {
|
||||
const pathModule = getPathModule(platform);
|
||||
const normalized = pathModule.normalize(input).replaceAll("\\", "/");
|
||||
@@ -160,8 +166,9 @@ export async function resolvePreferredNodePath(params: {
|
||||
|
||||
// Prefer the node that is currently running `openclaw gateway install`.
|
||||
// This respects the user's active version manager (fnm/nvm/volta/etc.).
|
||||
const platform = params.platform ?? process.platform;
|
||||
const currentExecPath = params.execPath ?? process.execPath;
|
||||
if (currentExecPath) {
|
||||
if (currentExecPath && isNodeExecPath(currentExecPath, platform)) {
|
||||
const execFileImpl = params.execFile ?? execFileAsync;
|
||||
const version = await resolveNodeVersion(currentExecPath, execFileImpl);
|
||||
if (isSupportedNodeVersion(version)) {
|
||||
|
||||
Reference in New Issue
Block a user