mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-18 05:02:15 +03:00
* fix(build): resolve npm-cli.js on POSIX layouts in the shim-free prepublish resolver The #8858 resolver only tried <dir(node)>/node_modules/npm/bin — the Windows layout. On POSIX (GitHub hosted runners, nvm, system installs) npm lives at <prefix>/lib/node_modules/npm while node is <prefix>/bin/ node, so resolveBundledNpmEntry returned null and npm run build:cli died installing @omniroute/opencode-plugin deps on every fresh checkout ('npm-cli.js not found next to the running Node binary') — redding Fast Production Build and dast-smoke for the whole PR queue. Extract the resolver to scripts/build/resolveNpmEntry.ts with injectable seams and try, in order: npm_execpath (exported by npm run itself), the Windows beside-the-binary layout, the POSIX <prefix>/lib layout. TDD: tests/unit/build/resolve-npm-entry.test.ts — the POSIX-layout and npm_execpath cases plus a live regression guard fail against the old single-candidate logic (2/5) and pass with the fix (5/5). * docs(env): register the 7 env vars orphaned by the 08-05 merge batch The Docs Gates env/docs contract went red on the release tip: #9260 added OMNIROUTE_INTERNAL_SERVICE_TOKEN(_FILE) and #9324 added OPENROUTER_PROVIDER_STATS_ENABLED/_TTL_MS without .env.example entries, and the #9286 Redis sidecar vars (REDIS_BIND_HOST, REDIS_PORT, OMNIROUTE_REDIS_BIND_HOST) never reached ENVIRONMENT.md. Inherited base-red on every open PR. Defaults and descriptions taken from the consuming source files. --------- Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com>
72 lines
2.7 KiB
TypeScript
72 lines
2.7 KiB
TypeScript
/**
|
|
* #8858 follow-up — `resolveBundledNpmEntry` only knew the WINDOWS npm layout
|
|
* (`<dir(node.exe)>\node_modules\npm\bin\...`). On POSIX installs (GitHub
|
|
* hosted runners, nvm, system node) npm lives at
|
|
* `<prefix>/lib/node_modules/npm/bin/...` while node is `<prefix>/bin/node`,
|
|
* so the resolver returned null and `npm run build:cli` (Fast Production
|
|
* Build, dast-smoke) failed on every fresh CI checkout with
|
|
* "npm-cli.js not found next to the running Node binary".
|
|
*/
|
|
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { resolveBundledNpmEntry } from "../../../scripts/build/resolveNpmEntry.ts";
|
|
|
|
const POSIX_PREFIX = "/opt/hostedtoolcache/node/24.18.0/x64";
|
|
const POSIX_NODE = `${POSIX_PREFIX}/bin/node`;
|
|
const POSIX_NPM_CLI = `${POSIX_PREFIX}/lib/node_modules/npm/bin/npm-cli.js`;
|
|
|
|
const WIN_STYLE_DIR = "/fake/nodejs"; // Windows layout shape (npm beside the binary)
|
|
const WIN_STYLE_NODE = `${WIN_STYLE_DIR}/node.exe`;
|
|
const WIN_STYLE_NPM_CLI = `${WIN_STYLE_DIR}/node_modules/npm/bin/npm-cli.js`;
|
|
|
|
test("POSIX layout: finds npm-cli.js under <prefix>/lib/node_modules (hosted runner shape)", () => {
|
|
const resolved = resolveBundledNpmEntry("npm-cli.js", {
|
|
execPath: POSIX_NODE,
|
|
npmExecPath: undefined,
|
|
exists: (p) => p === POSIX_NPM_CLI,
|
|
});
|
|
assert.equal(resolved, POSIX_NPM_CLI);
|
|
});
|
|
|
|
test("Windows layout: still finds npm-cli.js beside the node binary", () => {
|
|
const resolved = resolveBundledNpmEntry("npm-cli.js", {
|
|
execPath: WIN_STYLE_NODE,
|
|
npmExecPath: undefined,
|
|
exists: (p) => p === WIN_STYLE_NPM_CLI,
|
|
});
|
|
assert.equal(resolved, WIN_STYLE_NPM_CLI);
|
|
});
|
|
|
|
test("npm_execpath (set by `npm run`) wins and resolves npx-cli.js as its sibling", () => {
|
|
const npmExecPath = `${POSIX_PREFIX}/lib/node_modules/npm/bin/npm-cli.js`;
|
|
const npxSibling = `${POSIX_PREFIX}/lib/node_modules/npm/bin/npx-cli.js`;
|
|
const resolved = resolveBundledNpmEntry("npx-cli.js", {
|
|
execPath: POSIX_NODE,
|
|
npmExecPath,
|
|
exists: (p) => p === npxSibling,
|
|
});
|
|
assert.equal(resolved, npxSibling);
|
|
});
|
|
|
|
test("returns null when no layout matches", () => {
|
|
const resolved = resolveBundledNpmEntry("npm-cli.js", {
|
|
execPath: POSIX_NODE,
|
|
npmExecPath: undefined,
|
|
exists: () => false,
|
|
});
|
|
assert.equal(resolved, null);
|
|
});
|
|
|
|
test("live environment: the real node install can resolve npm-cli.js (POSIX regression guard)", (t) => {
|
|
if (process.platform === "win32") {
|
|
t.skip("POSIX-only live check");
|
|
return;
|
|
}
|
|
const resolved = resolveBundledNpmEntry("npm-cli.js");
|
|
assert.ok(
|
|
resolved,
|
|
`real install must resolve npm-cli.js (execPath=${process.execPath}) — the #8858 resolver returned null on POSIX`
|
|
);
|
|
});
|