





















@@ -272,6 +272,42 @@ async function activateImportedStartupConfig(config: OpenClawConfig) {
272272);
273273}
274274275+async function prepareGatewaySecretRefStartupConfig(params: {
276+prepareRuntimeSecretsSnapshot: PrepareRuntimeSecretsSnapshotForTest;
277+activateRuntimeSecretsSnapshot: ActivateRuntimeSecretsSnapshotForTest;
278+}) {
279+return await prepareGatewayStartupConfig({
280+configSnapshot: gatewaySecretRefSnapshot(),
281+activateRuntimeSecrets: runtimeSecretsActivatorForTest(params),
282+});
283+}
284+285+function expectBootstrapAuthResolvedGatewayToken(
286+result: Awaited<ReturnType<typeof prepareGatewayStartupConfig>>,
287+): void {
288+expect(result.auth).toMatchObject({
289+mode: "token",
290+token: RESOLVED_GATEWAY_TOKEN,
291+});
292+}
293+294+async function expectImportedStartupConfigUsesFullSecretsRuntime(
295+harness: ReturnType<typeof createGatewayStartupSecretsRuntimeHarness>,
296+config: OpenClawConfig,
297+): Promise<void> {
298+harness.install();
299+300+try {
301+await activateImportedStartupConfig(config);
302+303+expect(harness.runtimeImport).toHaveBeenCalledTimes(1);
304+expect(harness.prepareRuntimeSecretsSnapshot).toHaveBeenCalledTimes(1);
305+expect(harness.activateRuntimeSecretsSnapshot).toHaveBeenCalledTimes(1);
306+} finally {
307+harness.cleanup();
308+}
309+}
310+275311describe("gateway startup config secret preflight", () => {
276312const previousSkipChannels = process.env.OPENCLAW_SKIP_CHANNELS;
277313const previousSkipProviders = process.env.OPENCLAW_SKIP_PROVIDERS;
@@ -545,19 +581,7 @@ describe("gateway startup config secret preflight", () => {
545581it.each(KNOWN_WEAK_GATEWAY_TOKEN_PLACEHOLDERS)(
546582"rejects known weak gateway tokens resolved during secret activation: %s",
547583async (token) => {
548-const sourceConfig = gatewayTokenConfig({
549-secrets: {
550-providers: {
551-default: { source: "env" },
552-},
553-},
554-gateway: {
555-auth: {
556-mode: "token",
557-token: { source: "env", provider: "default", id: "GATEWAY_TOKEN_REF" },
558-},
559-},
560-});
584+const sourceConfig = gatewayTokenConfig(gatewaySecretRefSnapshot().config);
561585const prepareRuntimeSecretsSnapshot = vi.fn(async () =>
562586preparedSnapshot({
563587 ...sourceConfig,
@@ -680,16 +704,12 @@ describe("gateway startup config secret preflight", () => {
680704);
681705const activateRuntimeSecretsSnapshot = vi.fn();
682706683-const result = await prepareGatewayStartupConfig({
684-configSnapshot: gatewaySecretRefSnapshot(),
685-activateRuntimeSecrets: runtimeSecretsActivatorForTest({
686- prepareRuntimeSecretsSnapshot,
687- activateRuntimeSecretsSnapshot,
688-}),
707+const result = await prepareGatewaySecretRefStartupConfig({
708+ prepareRuntimeSecretsSnapshot,
709+ activateRuntimeSecretsSnapshot,
689710});
690711691-expect(result.auth.mode).toBe("token");
692-expect(result.auth.token).toBe(RESOLVED_GATEWAY_TOKEN);
712+expectBootstrapAuthResolvedGatewayToken(result);
693713expect(result.cfg.gateway?.auth?.token).toBe(RESOLVED_GATEWAY_TOKEN);
694714expect(prepareRuntimeSecretsSnapshot).toHaveBeenCalledTimes(1);
695715expect(activateRuntimeSecretsSnapshot).toHaveBeenCalledTimes(1);
@@ -722,16 +742,12 @@ describe("gateway startup config secret preflight", () => {
722742}));
723743const activateRuntimeSecretsSnapshot = vi.fn();
724744725-const result = await prepareGatewayStartupConfig({
726-configSnapshot: gatewaySecretRefSnapshot(),
727-activateRuntimeSecrets: runtimeSecretsActivatorForTest({
728- prepareRuntimeSecretsSnapshot,
729- activateRuntimeSecretsSnapshot,
730-}),
745+const result = await prepareGatewaySecretRefStartupConfig({
746+ prepareRuntimeSecretsSnapshot,
747+ activateRuntimeSecretsSnapshot,
731748});
732749733-expect(result.auth.mode).toBe("token");
734-expect(result.auth.token).toBe(RESOLVED_GATEWAY_TOKEN);
750+expectBootstrapAuthResolvedGatewayToken(result);
735751expect(prepareRuntimeSecretsSnapshot).toHaveBeenCalledTimes(2);
736752expect(activateRuntimeSecretsSnapshot).toHaveBeenCalledTimes(1);
737753});
@@ -836,31 +852,22 @@ describe("gateway startup config secret preflight", () => {
836852837853it("keeps the full secrets runtime path when startup config has a SecretRef", async () => {
838854const harness = createGatewayStartupSecretsRuntimeHarness("openclaw-startup-secret-ref-");
839-harness.install();
840-841-try {
842-await activateImportedStartupConfig(
843-asConfig({
844-agents: {
845-list: [{ id: "default", agentDir: harness.agentDir }],
846-},
847-models: {
848-providers: {
849-openai: {
850-models: [],
851-apiKey: { source: "env", provider: "default", id: "OPENAI_API_KEY" },
852-},
855+await expectImportedStartupConfigUsesFullSecretsRuntime(
856+harness,
857+asConfig({
858+agents: {
859+list: [{ id: "default", agentDir: harness.agentDir }],
860+},
861+models: {
862+providers: {
863+openai: {
864+models: [],
865+apiKey: { source: "env", provider: "default", id: "OPENAI_API_KEY" },
853866},
854867},
855-}),
856-);
857-858-expect(harness.runtimeImport).toHaveBeenCalledTimes(1);
859-expect(harness.prepareRuntimeSecretsSnapshot).toHaveBeenCalledTimes(1);
860-expect(harness.activateRuntimeSecretsSnapshot).toHaveBeenCalledTimes(1);
861-} finally {
862-harness.cleanup();
863-}
868+},
869+}),
870+);
864871});
865872866873it("keeps the full secrets runtime path when auth profile files are present", async () => {
@@ -878,22 +885,13 @@ describe("gateway startup config secret preflight", () => {
878885 },
879886 })}\n`,
880887);
881-harness.install();
882-883-try {
884-await activateImportedStartupConfig(
885-asConfig({
886-agents: {
887-list: [{ id: "default", agentDir: harness.agentDir }],
888-},
889-}),
890-);
891-892-expect(harness.runtimeImport).toHaveBeenCalledTimes(1);
893-expect(harness.prepareRuntimeSecretsSnapshot).toHaveBeenCalledTimes(1);
894-expect(harness.activateRuntimeSecretsSnapshot).toHaveBeenCalledTimes(1);
895-} finally {
896-harness.cleanup();
897-}
888+await expectImportedStartupConfigUsesFullSecretsRuntime(
889+harness,
890+asConfig({
891+agents: {
892+list: [{ id: "default", agentDir: harness.agentDir }],
893+},
894+}),
895+);
898896});
899897});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。