Files
OmniRoute/scripts/build/mitm-stub-flag.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

24 lines
1.1 KiB
JavaScript

/**
* Decide whether the Turbopack build should alias @/mitm/manager to the
* feature-degraded stub (src/mitm/manager.stub.ts).
*
* History (#6344): the alias used to be UNCONDITIONAL in next.config.mjs
* because Docker images were the only Turbopack consumers (webpack was the
* production default and never aliased the manager). When v3.8.45 flipped the
* production bundler default to Turbopack, the stub silently shipped to every
* npm / Electron / VPS artifact — Agent Bridge start then threw
* "MITM manager stub reached at runtime" for all non-Docker users.
*
* The stub is only correct where the runtime genuinely cannot run the MITM
* stack (containers without host access — #3390 graceful degradation), so it
* is now opt-in via OMNIROUTE_MITM_STUB=1, set by the Dockerfile.
*/
export function shouldStubMitmManager(env = process.env) {
return env.OMNIROUTE_MITM_STUB === "1";
}
/** Turbopack resolveAlias fragment for @/mitm/manager, derived from the env. */
export function mitmManagerAliasFor(env = process.env) {
return shouldStubMitmManager(env) ? { "@/mitm/manager": "./src/mitm/manager.stub.ts" } : {};
}