mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-26 17:12:27 +03:00
Validated on the resolved merge against the current tip (527da656 + the post-#11281 rebaseline): the single conflict was a comment-only collision in providers/[id]/models/route.ts (kept the tip's #10828-ordering note). Focused suites 125/125 across all 13 touched test files (build-sqlite-stub, cc-compatible, copilot-claude-messages, copilot-gemini-route, executor-github, ghe-copilot, github-copilot-discovery-token, github-copilot-model-discovery, noauth-sibling-7620, provider-header-profiles, provider-models-config, request-log-payloads, upstream-error-passthrough), typecheck:core clean, file-size/changelog-integrity OK. Merged --admin over the inherited 2026-08-23 base-red cluster (#9985) — the reds are proven tip failures (CLI catalog cluster + @testing-library allowlist, being drained by #11280), not from this diff. Note: the rebase means several items the body listed (relay x-relay-path SSRF, /v1/search blocked-providers, #10736 rotation fence, #10903, #10865, #10899, #10916) already landed upstream and are NOT in this delta — the delta is: better-sqlite3 build guard + build heap/worker caps + telemetry-off (#10060 re-derived), credential-echo passthrough refusal + OCR/moderation redaction + call-log key redaction, Copilot CLI 1.0.81-6 wire identity + Claude→/v1/messages name-matched routing + discovery token fix, CC model_not_found 400, compat overrides for no-auth aliases (#7620-pinned). The Copilot wire-identity change is the one to watch in production. Thank you @arminanton — and the ported-author credits in the commit history (@rqzbeh, yidecode, the #10899/#10916 authors) are preserved. Your config-posture finding (REQUIRE_API_KEY default vs 0.0.0.0) is noted for a maintainer decision, as you scoped it.
70 lines
2.9 KiB
TypeScript
70 lines
2.9 KiB
TypeScript
/**
|
|
* #10060 — during the Next.js production build the native better-sqlite3 addon
|
|
* must never load. Its Statement destructor aborts with SIGABRT when a build
|
|
* worker thread exits (assertion in node::RemoveEnvironmentCleanupHook), which
|
|
* can leave the build with no standalone output.
|
|
*
|
|
* The reliable build signal is OMNIROUTE_BUILDING=1 (set by
|
|
* build-next-isolated.mjs and inherited by every spawned build worker), because
|
|
* Next.js workers sometimes drop NEXT_PHASE. These tests pin the two contracts
|
|
* that keep the addon out of the build:
|
|
*
|
|
* 1. build-next-isolated.mjs exports OMNIROUTE_BUILDING=1 into the build env.
|
|
* 2. getDbInstance() returns a no-op stub (never the native driver) whenever
|
|
* the build signal is set, and that stub satisfies the SqliteAdapter shape.
|
|
*/
|
|
|
|
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { resolveNextBuildEnv } from "../../../scripts/build/build-next-isolated.mjs";
|
|
|
|
describe("#10060 build env carries OMNIROUTE_BUILDING", () => {
|
|
it("resolveNextBuildEnv sets OMNIROUTE_BUILDING=1", () => {
|
|
const env = resolveNextBuildEnv({}, "linux");
|
|
assert.equal(env.OMNIROUTE_BUILDING, "1");
|
|
});
|
|
|
|
it("preserves provided env keys and does not clobber the build-worker flag", () => {
|
|
const env = resolveNextBuildEnv({ NEXT_PRIVATE_BUILD_WORKER: "1" }, "linux");
|
|
assert.equal(env.NEXT_PRIVATE_BUILD_WORKER, "1");
|
|
assert.equal(env.OMNIROUTE_BUILDING, "1");
|
|
});
|
|
});
|
|
|
|
describe("#10060 getDbInstance stubs SQLite during build", () => {
|
|
const savedBuilding = process.env.OMNIROUTE_BUILDING;
|
|
const savedPhase = process.env.NEXT_PHASE;
|
|
|
|
beforeEach(() => {
|
|
delete process.env.NEXT_PHASE;
|
|
process.env.OMNIROUTE_BUILDING = "1";
|
|
});
|
|
|
|
afterEach(() => {
|
|
if (savedBuilding === undefined) delete process.env.OMNIROUTE_BUILDING;
|
|
else process.env.OMNIROUTE_BUILDING = savedBuilding;
|
|
if (savedPhase === undefined) delete process.env.NEXT_PHASE;
|
|
else process.env.NEXT_PHASE = savedPhase;
|
|
});
|
|
|
|
it("returns a no-op stub (never the native better-sqlite3 driver) under the build signal", async () => {
|
|
// Import fresh so isBuildPhase is evaluated with OMNIROUTE_BUILDING set.
|
|
const mod = await import(`../../../src/lib/db/core.ts?build-stub=${Date.now()}`);
|
|
const db = mod.getDbInstance();
|
|
|
|
// Must NOT be the native addon — that is the whole point of the fix.
|
|
assert.notEqual(db.driver, "better-sqlite3");
|
|
assert.equal(db.open, true);
|
|
|
|
// The stub satisfies the SqliteAdapter surface the build's module-eval touches.
|
|
const stmt = db.prepare("SELECT 1 AS x");
|
|
assert.equal(stmt.get(), undefined);
|
|
assert.deepEqual(stmt.all(), []);
|
|
assert.deepEqual(stmt.run(), { changes: 0, lastInsertRowid: 0 });
|
|
assert.doesNotThrow(() => db.exec("CREATE TABLE t (a)"));
|
|
assert.doesNotThrow(() => db.pragma("journal_mode = WAL"));
|
|
assert.doesNotThrow(() => db.close());
|
|
});
|
|
});
|