Files
Moltbot/src/daemon/runtime-paths.test.ts
Glucksberg 2ca78a8aed fix(runtime): bump minimum Node.js version to 22.12.0 (#5370)
* fix(runtime): bump minimum Node.js version to 22.12.0

Aligns the runtime guard with the declared package.json engines requirement.

The Matrix plugin (and potentially others) requires Node >= 22.12.0,
but the runtime guard previously allowed 22.0.0+. This caused confusing
errors like 'Cannot find module @vector-im/matrix-bot-sdk' when the real
issue was an unsupported Node version.

- Update MIN_NODE from 22.0.0 to 22.12.0
- Update error message to reflect the correct version
- Update tests to use 22.12.0 as the minimum valid version

Fixes #5292

* fix: update test versions to match MIN_NODE=22.12.0

---------

Co-authored-by: Markus Glucksberg <markus@glucksberg.com>
2026-02-05 13:42:52 -08:00

127 lines
3.1 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "vitest";
const fsMocks = vi.hoisted(() => ({
access: vi.fn(),
}));
vi.mock("node:fs/promises", () => ({
default: { access: fsMocks.access },
access: fsMocks.access,
}));
import {
renderSystemNodeWarning,
resolvePreferredNodePath,
resolveSystemNodeInfo,
} from "./runtime-paths.js";
afterEach(() => {
vi.resetAllMocks();
});
describe("resolvePreferredNodePath", () => {
const darwinNode = "/opt/homebrew/bin/node";
it("uses system node when it meets the minimum version", async () => {
fsMocks.access.mockImplementation(async (target: string) => {
if (target === darwinNode) {
return;
}
throw new Error("missing");
});
// Node 22.12.0+ is the minimum required version
const execFile = vi.fn().mockResolvedValue({ stdout: "22.12.0\n", stderr: "" });
const result = await resolvePreferredNodePath({
env: {},
runtime: "node",
platform: "darwin",
execFile,
});
expect(result).toBe(darwinNode);
expect(execFile).toHaveBeenCalledTimes(1);
});
it("skips system node when it is too old", async () => {
fsMocks.access.mockImplementation(async (target: string) => {
if (target === darwinNode) {
return;
}
throw new Error("missing");
});
// Node 22.11.x is below minimum 22.12.0
const execFile = vi.fn().mockResolvedValue({ stdout: "22.11.0\n", stderr: "" });
const result = await resolvePreferredNodePath({
env: {},
runtime: "node",
platform: "darwin",
execFile,
});
expect(result).toBeUndefined();
expect(execFile).toHaveBeenCalledTimes(1);
});
it("returns undefined when no system node is found", async () => {
fsMocks.access.mockRejectedValue(new Error("missing"));
const execFile = vi.fn();
const result = await resolvePreferredNodePath({
env: {},
runtime: "node",
platform: "darwin",
execFile,
});
expect(result).toBeUndefined();
expect(execFile).not.toHaveBeenCalled();
});
});
describe("resolveSystemNodeInfo", () => {
const darwinNode = "/opt/homebrew/bin/node";
it("returns supported info when version is new enough", async () => {
fsMocks.access.mockImplementation(async (target: string) => {
if (target === darwinNode) {
return;
}
throw new Error("missing");
});
// Node 22.12.0+ is the minimum required version
const execFile = vi.fn().mockResolvedValue({ stdout: "22.12.0\n", stderr: "" });
const result = await resolveSystemNodeInfo({
env: {},
platform: "darwin",
execFile,
});
expect(result).toEqual({
path: darwinNode,
version: "22.12.0",
supported: true,
});
});
it("renders a warning when system node is too old", () => {
const warning = renderSystemNodeWarning(
{
path: darwinNode,
version: "18.19.0",
supported: false,
},
"/Users/me/.fnm/node-22/bin/node",
);
expect(warning).toContain("below the required Node 22+");
expect(warning).toContain(darwinNode);
});
});