From 76d2d7a9757ebe2126b06cdee3a3e12407e4ec68 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 12 Apr 2026 09:40:35 +0100 Subject: [PATCH] test(commands): share gateway status secretref config --- src/commands/gateway-status.test.ts | 20 ++----------------- src/commands/gateway-status/helpers.test.ts | 21 ++------------------ src/commands/gateway-status/test-support.ts | 22 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 37 deletions(-) create mode 100644 src/commands/gateway-status/test-support.ts diff --git a/src/commands/gateway-status.test.ts b/src/commands/gateway-status.test.ts index 7316d6e87ca..6015e5c48b1 100644 --- a/src/commands/gateway-status.test.ts +++ b/src/commands/gateway-status.test.ts @@ -5,6 +5,7 @@ import type { GatewayTlsRuntime } from "../infra/tls/gateway.js"; import type { RuntimeEnv } from "../runtime.js"; import { withEnvAsync } from "../test-utils/env.js"; import { gatewayStatusCommand } from "./gateway-status.js"; +import { createSecretRefGatewayConfig } from "./gateway-status/test-support.js"; const mocks = vi.hoisted(() => { const sshStop = vi.fn(async () => {}); @@ -548,24 +549,7 @@ describe("gateway-status command", () => { exists: true, valid: true, config: { - secrets: { - defaults: { - env: "default", - }, - }, - gateway: { - mode: "remote", - auth: { - mode: "token", - token: { source: "env", provider: "default", id: "OPENCLAW_GATEWAY_TOKEN" }, - password: { source: "env", provider: "default", id: "OPENCLAW_GATEWAY_PASSWORD" }, - }, - remote: { - url: "wss://remote.example:18789", - token: { source: "env", provider: "default", id: "REMOTE_GATEWAY_TOKEN" }, - password: { source: "env", provider: "default", id: "REMOTE_GATEWAY_PASSWORD" }, - }, - }, + ...createSecretRefGatewayConfig({ gatewayMode: "remote" }), discovery: { wideArea: { enabled: true }, }, diff --git a/src/commands/gateway-status/helpers.test.ts b/src/commands/gateway-status/helpers.test.ts index 2cd603853cc..84eab331a96 100644 --- a/src/commands/gateway-status/helpers.test.ts +++ b/src/commands/gateway-status/helpers.test.ts @@ -10,6 +10,7 @@ import { resolveProbeBudgetMs, resolveTargets, } from "./helpers.js"; +import { createSecretRefGatewayConfig } from "./test-support.js"; describe("extractConfigSummary", () => { it("marks SecretRef-backed gateway auth credentials as configured", () => { @@ -19,25 +20,7 @@ describe("extractConfigSummary", () => { valid: true, issues: [], legacyIssues: [], - config: { - secrets: { - defaults: { - env: "default", - }, - }, - gateway: { - auth: { - mode: "token", - token: { source: "env", provider: "default", id: "OPENCLAW_GATEWAY_TOKEN" }, - password: { source: "env", provider: "default", id: "OPENCLAW_GATEWAY_PASSWORD" }, - }, - remote: { - url: "wss://remote.example:18789", - token: { source: "env", provider: "default", id: "REMOTE_GATEWAY_TOKEN" }, - password: { source: "env", provider: "default", id: "REMOTE_GATEWAY_PASSWORD" }, - }, - }, - }, + config: createSecretRefGatewayConfig(), }); expect(summary.gateway.authTokenConfigured).toBe(true); diff --git a/src/commands/gateway-status/test-support.ts b/src/commands/gateway-status/test-support.ts new file mode 100644 index 00000000000..7627ab90374 --- /dev/null +++ b/src/commands/gateway-status/test-support.ts @@ -0,0 +1,22 @@ +export function createSecretRefGatewayConfig(params?: { gatewayMode?: "local" | "remote" }) { + return { + secrets: { + defaults: { + env: "default", + }, + }, + gateway: { + ...(params?.gatewayMode ? { mode: params.gatewayMode } : {}), + auth: { + mode: "token" as const, + token: { source: "env", provider: "default", id: "OPENCLAW_GATEWAY_TOKEN" }, + password: { source: "env", provider: "default", id: "OPENCLAW_GATEWAY_PASSWORD" }, + }, + remote: { + url: "wss://remote.example:18789", + token: { source: "env", provider: "default", id: "REMOTE_GATEWAY_TOKEN" }, + password: { source: "env", provider: "default", id: "REMOTE_GATEWAY_PASSWORD" }, + }, + }, + }; +}