Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(e2e): refuse a web bundle built for different ports

M3gA-Mindb5f647c239f6
diff --git a/app/scripts/e2e-web-build.sh b/app/scripts/e2e-web-build.sh
index 2bd14d7535..4851b52067 100755
--- a/app/scripts/e2e-web-build.sh
+++ b/app/scripts/e2e-web-build.sh
@@ -28,7 +28,38 @@ if [ -f "$REPO_ROOT/.env" ]; then
fi
echo "Building web E2E bundle with backend ${VITE_BACKEND_URL}"
+# Drop the previous marker first. `build:web` runs `tsc`, so a failed build
+# leaves the OLD `dist-web` in place; without this the old marker would survive
+# beside it and the session would happily serve a stale bundle that merely
+# happens to agree about ports. No marker means the session refuses.
+rm -f "$APP_DIR/dist-web/.e2e-build-ports.json"
pnpm run build:web
+
+# Record what got baked, so the session can refuse a bundle built for other
+# ports (#6478).
+#
+# `VITE_BACKEND_URL` above is substituted into the bundle by Vite at BUILD time
+# and has no runtime override in web mode: `utils/config.ts` reads
+# `import.meta.env.VITE_BACKEND_URL || DEFAULT_BACKEND_URL`, and
+# `services/backendUrl.ts`'s web path falls back to `window.location.origin` —
+# which is the web HOST port, not the mock's, so it cannot reconcile a
+# mismatch. Set the ports for the session but not the build (the natural thing
+# to do, since ports are a session concern) and the frontend's own API calls go
+# to a mock that is not listening, while the core — which reads `api_url` from
+# the `config.toml` the session generates at runtime — talks to the right one.
+# Some specs then fail and others pass, for a reason nothing reports.
+#
+# `VITE_OPENHUMAN_CORE_RPC_URL` is baked too but is NOT part of this problem: a
+# stored URL wins over it (`coreRpcClient.ts`, `storedUrl ?? CORE_RPC_URL`) and
+# the Playwright helper seeds that from the runtime port on every boot. It is
+# recorded here anyway so a future divergence is visible rather than inferred.
+cat > "$APP_DIR/dist-web/.e2e-build-ports.json" <<JSON
+{
+ "e2e_mock_port": "${E2E_MOCK_PORT:-18473}",
+ "openhuman_core_port": "${OPENHUMAN_CORE_PORT:-17788}",
+ "vite_backend_url": "${VITE_BACKEND_URL}"
+}
+JSON
echo "Building standalone openhuman-core for web E2E into ${E2E_WEB_CORE_TARGET_DIR}..."
# A bare core build uses the contributor feature set, which intentionally
# omits product domains such as voice, web3, documents and crash reporting.
diff --git a/app/scripts/e2e-web-session.sh b/app/scripts/e2e-web-session.sh
index 7a07c2d6f4..62279ee5de 100755
--- a/app/scripts/e2e-web-session.sh
+++ b/app/scripts/e2e-web-session.sh
@@ -158,6 +158,34 @@ node "$REPO_ROOT/scripts/mock-api-server.mjs" --port "$E2E_MOCK_PORT" >"$OPENHUM
MOCK_PID=$!
wait_for_http "http://127.0.0.1:${E2E_MOCK_PORT}/__admin/health" "mock backend"
+# Refuse a bundle built for different ports (#6478).
+#
+# `VITE_BACKEND_URL` is substituted into the bundle at BUILD time and has no
+# runtime override in web mode, so a bundle built on one `E2E_MOCK_PORT` and
+# served against another sends the frontend's own API calls to a mock that is
+# not listening — while the core, reading `api_url` from the `config.toml`
+# generated below, reaches the right one. Some specs fail and others pass, with
+# nothing reporting why. Checked before anything is started so the failure is a
+# one-line message rather than a debugging session.
+BUILD_PORTS_FILE="$APP_DIR/dist-web/.e2e-build-ports.json"
+if [ ! -f "$BUILD_PORTS_FILE" ]; then
+ echo "ERROR: $APP_DIR/dist-web has no .e2e-build-ports.json, so the ports it was built for are unknown." >&2
+ echo " It predates this check. Rebuild with: pnpm test:e2e:web:build" >&2
+ exit 1
+fi
+BUILT_MOCK_PORT="$(sed -n 's/.*"e2e_mock_port"[[:space:]]*:[[:space:]]*"\([0-9]*\)".*/\1/p' "$BUILD_PORTS_FILE")"
+if [ -z "$BUILT_MOCK_PORT" ]; then
+ echo "ERROR: could not read e2e_mock_port from $BUILD_PORTS_FILE. Rebuild with: pnpm test:e2e:web:build" >&2
+ exit 1
+fi
+if [ "$BUILT_MOCK_PORT" != "$E2E_MOCK_PORT" ]; then
+ echo "ERROR: dist-web was built for E2E_MOCK_PORT=$BUILT_MOCK_PORT but this session uses $E2E_MOCK_PORT." >&2
+ echo " The backend URL is baked into the bundle and cannot be changed at run time," >&2
+ echo " so the app would call a mock that is not listening while the core called the right one." >&2
+ echo " Rebuild with the ports this session uses: E2E_MOCK_PORT=$E2E_MOCK_PORT pnpm test:e2e:web:build" >&2
+ exit 1
+fi
+
export OPENHUMAN_CORE_BIN="$E2E_WEB_CORE_TARGET_DIR/debug/openhuman-core"
if [ ! -x "$OPENHUMAN_CORE_BIN" ]; then
echo "ERROR: standalone core binary is missing at $OPENHUMAN_CORE_BIN. Run pnpm test:e2e:web:build first." >&2