Skip to content

Commit 801b5d4

Browse files
committed
fix: stabilize isolated gateway test runtime
1 parent 329fbc3 commit 801b5d4

7 files changed

Lines changed: 360 additions & 101 deletions

File tree

src/cron/service/ops.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import type { CronJob, CronJobCreate, CronJobPatch } from "../types.js";
99
import {
1010
applyJobPatch,
11+
assertSupportedJobSpec,
1112
computeJobNextRunAtMs,
1213
createJob,
1314
findJobOrThrow,
@@ -488,6 +489,7 @@ async function inspectManualRunPreflight(
488489
// persist does not block manual triggers for up to STUCK_RUN_MS (#17554).
489490
recomputeNextRunsForMaintenance(state);
490491
const job = findJobOrThrow(state, id);
492+
assertSupportedJobSpec(job);
491493
if (typeof job.state.runningAtMs === "number") {
492494
return { ok: true, ran: false, reason: "already-running" as const };
493495
}

src/gateway/server.e2e-ws-harness.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ export async function startGatewayServerHarness(): Promise<GatewayServerHarness>
2323
const envSnapshot = captureEnv(["OPENCLAW_GATEWAY_TOKEN"]);
2424
delete process.env.OPENCLAW_GATEWAY_TOKEN;
2525
const port = await getFreePort();
26-
const server = await startGatewayServer(port);
26+
const server = await startGatewayServer(port, {
27+
auth: { mode: "none" },
28+
controlUiEnabled: false,
29+
});
2730

2831
const openClient = async (opts?: Parameters<typeof connectOk>[1]): Promise<GatewayWsClient> => {
2932
const ws = new WebSocket(`ws://127.0.0.1:${port}`);

src/gateway/server.impl.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,30 @@ async function prepareGatewayStartupConfig(params: {
288288
tailscale: params.tailscaleOverride,
289289
},
290290
);
291-
await params.activateRuntimeSecrets(startupPreflightConfig, {
292-
reason: "startup",
293-
activate: false,
294-
});
291+
const preflightConfig = (
292+
await params.activateRuntimeSecrets(startupPreflightConfig, {
293+
reason: "startup",
294+
activate: false,
295+
})
296+
).config;
297+
const preflightAuthOverride =
298+
typeof preflightConfig.gateway?.auth?.token === "string" ||
299+
typeof preflightConfig.gateway?.auth?.password === "string"
300+
? {
301+
...params.authOverride,
302+
...(typeof preflightConfig.gateway?.auth?.token === "string"
303+
? { token: preflightConfig.gateway.auth.token }
304+
: {}),
305+
...(typeof preflightConfig.gateway?.auth?.password === "string"
306+
? { password: preflightConfig.gateway.auth.password }
307+
: {}),
308+
}
309+
: params.authOverride;
295310

296311
const authBootstrap = await ensureGatewayStartupAuth({
297312
cfg: params.runtimeConfig,
298313
env: process.env,
299-
authOverride: params.authOverride,
314+
authOverride: preflightAuthOverride,
300315
tailscaleOverride: params.tailscaleOverride,
301316
persist: true,
302317
baseHash: params.configSnapshot.hash,
@@ -637,7 +652,8 @@ export async function startGatewayServer(
637652
} = runtimeConfig;
638653
const getResolvedAuth = () =>
639654
resolveGatewayAuth({
640-
authConfig: getRuntimeConfig().gateway?.auth,
655+
authConfig:
656+
getActiveSecretsRuntimeSnapshot()?.config.gateway?.auth ?? getRuntimeConfig().gateway?.auth,
641657
authOverride: opts.auth,
642658
env: process.env,
643659
tailscaleMode,

src/gateway/server.preauth-hardening.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ import { attachGatewayUpgradeHandler, createGatewayHttpServer } from "./server-h
77
import { createPreauthConnectionBudget } from "./server/preauth-connection-budget.js";
88
import type { GatewayWsClient } from "./server/ws-types.js";
99
import { testState } from "./test-helpers.mocks.js";
10-
import { createGatewaySuiteHarness, readConnectChallengeNonce } from "./test-helpers.server.js";
10+
import {
11+
createGatewaySuiteHarness,
12+
installGatewayTestHooks,
13+
readConnectChallengeNonce,
14+
} from "./test-helpers.server.js";
1115
import { withTempConfig } from "./test-temp-config.js";
1216

17+
installGatewayTestHooks({ scope: "suite" });
18+
1319
let cleanupEnv: Array<() => void> = [];
1420

1521
afterEach(async () => {

0 commit comments

Comments
 (0)