Files
OmniRoute/tests/unit/mitm-stub-alias-6344.test.mjs
Diego Rodrigues de Sa e Souza a0ab693c4b fix(docker): make MITM manager Turbopack stub opt-in so npm/Electron/VPS bundle the real manager (#6344) (#6374)
* fix(docker): make @/mitm/manager Turbopack stub opt-in (OMNIROUTE_MITM_STUB=1) so npm/Electron/VPS builds bundle the real manager (#6344)

v3.8.45 flipped the production bundler default to Turbopack. next.config.mjs
aliased @/mitm/manager to the Docker-only degraded stub unconditionally, which
was harmless while Docker was the only Turbopack consumer but shipped the stub
to every npm/Electron/VPS artifact once Turbopack became the default — breaking
Agent Bridge start with 'MITM manager stub reached at runtime'. The alias is now
gated on OMNIROUTE_MITM_STUB=1 (set only by the Dockerfile) via the shared
scripts/build/mitm-stub-flag.mjs helper.

Regression guard: tests/unit/mitm-stub-alias-6344.test.mjs (4).

* test(next-config): align mitm-manager alias assertion with opt-in stub (#6344)

The existing test asserted the alias was always present; #6344 makes it opt-in
(OMNIROUTE_MITM_STUB=1). Default build now asserts no alias, plus a new env-matrix
test covering both the default (no stub) and Docker (stub) cases.

* docs(changelog): restore #6359 bullet eaten by merge auto-resolve
2026-07-06 15:20:40 -03:00

42 lines
1.9 KiB
JavaScript

// Regression test for #6344 — the 3.8.45 Turbopack-default flip shipped the
// @/mitm/manager build stub to every npm/Electron/VPS artifact, breaking Agent
// Bridge start ("MITM manager stub reached at runtime"). The stub alias must be
// opt-in (Docker sets OMNIROUTE_MITM_STUB=1); a default production build must
// bundle the REAL manager.
import { describe, it } from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
const { shouldStubMitmManager, mitmManagerAliasFor } = await import(
"../../scripts/build/mitm-stub-flag.mjs"
);
describe("mitm manager stub alias (#6344)", () => {
it("default env does NOT stub the manager (npm/Electron/VPS builds get the real module)", () => {
assert.equal(shouldStubMitmManager({}), false);
assert.deepEqual(mitmManagerAliasFor({}), {});
});
it("OMNIROUTE_MITM_STUB=1 opts into the stub (Docker graceful degradation, #3390)", () => {
assert.equal(shouldStubMitmManager({ OMNIROUTE_MITM_STUB: "1" }), true);
assert.deepEqual(mitmManagerAliasFor({ OMNIROUTE_MITM_STUB: "1" }), {
"@/mitm/manager": "./src/mitm/manager.stub.ts",
});
});
it("next.config.mjs derives the turbopack alias from the flag (no unconditional stub)", () => {
const config = readFileSync(new URL("../../next.config.mjs", import.meta.url), "utf8");
assert.match(config, /mitmManagerAliasFor/, "next.config.mjs must use mitmManagerAliasFor()");
assert.doesNotMatch(
config,
/^\s*"@\/mitm\/manager":\s*"\.\/src\/mitm\/manager\.stub\.ts",?\s*$/m,
"next.config.mjs must not hardcode the @/mitm/manager stub alias"
);
});
it("the Dockerfile keeps Docker on the stub via OMNIROUTE_MITM_STUB=1", () => {
const dockerfile = readFileSync(new URL("../../Dockerfile", import.meta.url), "utf8");
assert.match(dockerfile, /^ENV OMNIROUTE_MITM_STUB=1$/m);
});
});