mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-16 20:02:45 +03:00
Merged as part of the 39-PR owner batch of 2026-09-11, validated as a unit. Boarded into one consolidated worktree cut from `release/v3.8.51` with the other 38 — zero conflicts between them. - ESLint over every changed file: no errors (the only finding was one suppression entry the batch emptied, pruned on #13243) - `typecheck:core` clean; `check:dashboard-typecheck` OK (206 pre-existing, within baseline); `check:changelog-integrity` OK - complexity 2821 / baseline 3218 and cognitive-complexity 1272 / baseline 1437 — both under baseline - 256 assertions green: 246 under node:test and 10 under vitest, which is where `tests/unit/**/*.test.tsx` actually runs - `check-file-size`: `chatCore.ts` rebaselined 6144 → 6146 for #13278 and #13276, annotated and landed on #13243 ⚠️ base-red inherited: #12732 — the provider count (356 in the docs vs the 358 the modules define) and `open-sse/utils/stream.ts` at 3115 > frozen 3098 both reproduce on the pure tip with zero contribution from this batch.
64 lines
3.1 KiB
TypeScript
64 lines
3.1 KiB
TypeScript
// Regression test for issue #12296: "Invalid regular expression flags" crash
|
|
// right after STORAGE_ENCRYPTION_KEY generation on first run.
|
|
//
|
|
// Root cause: bin/omniroute.mjs imports getNodeRuntimeSupport/getNodeRuntimeWarning
|
|
// from ./nodeRuntimeSupport.mjs (intended to detect an unsupported Node.js runtime
|
|
// and print a friendly warning) but never actually CALLED either function before
|
|
// doing the heavy `await import("tsx/esm")` + Commander command-registration import
|
|
// chain. That chain pulls in `ora` -> `string-width@8.x`, whose index.js contains
|
|
// top-level ES2024 Unicode-set (`v` flag) regex literals
|
|
// (e.g. `/^\p{RGI_Emoji}$/v`) that fail to even PARSE on a V8/Node build that
|
|
// predates `v`-flag support - throwing exactly
|
|
// `SyntaxError: Invalid regular expression flags` (no flag value in the message,
|
|
// matching the report) deep inside a transitive dependency's module graph, instead
|
|
// of the intended actionable "Node.js vX is not supported" message.
|
|
//
|
|
// The only two call sites of getNodeRuntimeSupport/getNodeRuntimeWarning in bin/
|
|
// used to be inside `serve.mjs` and `doctor.mjs` - both unreachable if the import
|
|
// chain itself crashed first. This test asserts the guard actually runs (is
|
|
// called) in bin/omniroute.mjs, and that it runs BEFORE the heavy import chain
|
|
// that pulls in string-width.
|
|
|
|
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import { fileURLToPath } from "node:url";
|
|
import { join, dirname } from "node:path";
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const OMNIROUTE_MJS = join(__dirname, "..", "..", "bin", "omniroute.mjs");
|
|
|
|
test("bin/omniroute.mjs invokes the Node runtime compatibility guard before the heavy tsx/esm + command-registration import chain", () => {
|
|
const src = readFileSync(OMNIROUTE_MJS, "utf8");
|
|
|
|
const heavyImportIdx = src.indexOf('await import("tsx/esm")');
|
|
assert.ok(
|
|
heavyImportIdx > -1,
|
|
"expected bin/omniroute.mjs to still contain the tsx/esm dynamic import this test anchors on"
|
|
);
|
|
|
|
const callPattern = /getNodeRuntime(?:Support|Warning)\s*\(/g;
|
|
let firstCallIdx = -1;
|
|
for (const match of src.matchAll(callPattern)) {
|
|
firstCallIdx = match.index ?? -1;
|
|
break;
|
|
}
|
|
|
|
assert.notEqual(
|
|
firstCallIdx,
|
|
-1,
|
|
"getNodeRuntimeSupport()/getNodeRuntimeWarning() is imported in bin/omniroute.mjs but never called there - " +
|
|
"an unsupported/too-old Node.js runtime gets no early friendly warning and instead crashes with a raw " +
|
|
"native SyntaxError (e.g. 'Invalid regular expression flags' from string-width@8's v-flag regex literals) " +
|
|
"deep inside the tsx/esm + Commander import chain. See issue #12296."
|
|
);
|
|
|
|
assert.ok(
|
|
firstCallIdx < heavyImportIdx,
|
|
"the Node runtime compatibility guard must run BEFORE `await import(\"tsx/esm\")` and the rest of the heavy " +
|
|
"import chain (Commander command registry, ora/boxen/update-notifier, etc.) so an unsupported Node.js " +
|
|
"version is reported with a clear message and a clean exit instead of crashing on a native parse error " +
|
|
"raised while loading a transitive dependency."
|
|
);
|
|
});
|