test: isolate browser server auth env

This commit is contained in:
Peter Steinberger
2026-02-14 19:40:58 +00:00
parent ad5e7b9688
commit 31295c8341
@@ -13,6 +13,8 @@ type HarnessState = {
cfgEvaluateEnabled: boolean; cfgEvaluateEnabled: boolean;
createTargetId: string | null; createTargetId: string | null;
prevGatewayPort: string | undefined; prevGatewayPort: string | undefined;
prevGatewayToken: string | undefined;
prevGatewayPassword: string | undefined;
}; };
const state: HarnessState = { const state: HarnessState = {
@@ -23,6 +25,8 @@ const state: HarnessState = {
cfgEvaluateEnabled: true, cfgEvaluateEnabled: true,
createTargetId: null, createTargetId: null,
prevGatewayPort: undefined, prevGatewayPort: undefined,
prevGatewayToken: undefined,
prevGatewayPassword: undefined,
}; };
export function getBrowserControlServerTestState(): HarnessState { export function getBrowserControlServerTestState(): HarnessState {
@@ -279,6 +283,12 @@ export function installBrowserControlServerHooks() {
state.cdpBaseUrl = `http://127.0.0.1:${state.testPort + 1}`; state.cdpBaseUrl = `http://127.0.0.1:${state.testPort + 1}`;
state.prevGatewayPort = process.env.OPENCLAW_GATEWAY_PORT; state.prevGatewayPort = process.env.OPENCLAW_GATEWAY_PORT;
process.env.OPENCLAW_GATEWAY_PORT = String(state.testPort - 2); process.env.OPENCLAW_GATEWAY_PORT = String(state.testPort - 2);
// Avoid flaky auth coupling: some suites temporarily set gateway env auth
// which would make the browser control server require auth.
state.prevGatewayToken = process.env.OPENCLAW_GATEWAY_TOKEN;
state.prevGatewayPassword = process.env.OPENCLAW_GATEWAY_PASSWORD;
delete process.env.OPENCLAW_GATEWAY_TOKEN;
delete process.env.OPENCLAW_GATEWAY_PASSWORD;
// Minimal CDP JSON endpoints used by the server. // Minimal CDP JSON endpoints used by the server.
let putNewCalls = 0; let putNewCalls = 0;
@@ -341,6 +351,16 @@ export function installBrowserControlServerHooks() {
} else { } else {
process.env.OPENCLAW_GATEWAY_PORT = state.prevGatewayPort; process.env.OPENCLAW_GATEWAY_PORT = state.prevGatewayPort;
} }
if (state.prevGatewayToken === undefined) {
delete process.env.OPENCLAW_GATEWAY_TOKEN;
} else {
process.env.OPENCLAW_GATEWAY_TOKEN = state.prevGatewayToken;
}
if (state.prevGatewayPassword === undefined) {
delete process.env.OPENCLAW_GATEWAY_PASSWORD;
} else {
process.env.OPENCLAW_GATEWAY_PASSWORD = state.prevGatewayPassword;
}
await stopBrowserControlServer(); await stopBrowserControlServer();
}); });
} }