

























@@ -61,6 +61,12 @@ function preparedSnapshot(config: OpenClawConfig): PreparedSecretsRuntimeSnapsho
6161};
6262}
636364+function callArg<T>(mock: { mock: { calls: unknown[][] } }, index = 0): T {
65+const call = mock.mock.calls[index];
66+expect(call).toBeDefined();
67+return call?.[0] as T;
68+}
69+6470describe("gateway startup config secret preflight", () => {
6571const previousSkipChannels = process.env.OPENCLAW_SKIP_CHANNELS;
6672const previousSkipProviders = process.env.OPENCLAW_SKIP_PROVIDERS;
@@ -124,10 +130,12 @@ describe("gateway startup config secret preflight", () => {
124130activate: false,
125131});
126132127-expect(prepareRuntimeSecretsSnapshot).toHaveBeenCalledWith({
128-config: expect.any(Object),
129-loadAuthStore: loadAuthProfileStoreWithoutExternalProfiles,
130-});
133+const preflightInput = callArg<{
134+config?: unknown;
135+loadAuthStore?: unknown;
136+}>(prepareRuntimeSecretsSnapshot);
137+expect(typeof preflightInput.config).toBe("object");
138+expect(preflightInput.loadAuthStore).toBe(loadAuthProfileStoreWithoutExternalProfiles);
131139});
132140133141it("does not emit degraded or recovered events for warning-only secret reloads", async () => {
@@ -153,37 +161,33 @@ describe("gateway startup config secret preflight", () => {
153161activateRuntimeSecretsSnapshot: vi.fn(),
154162});
155163156-await expect(
157-activateRuntimeSecrets(
158-{
159-plugins: {
160-entries: {
161-google: {
162-enabled: true,
163-config: {
164-webSearch: {
165-apiKey: { source: "env", provider: "default", id: "MISSING_GEMINI_KEY" },
166-},
167-},
164+const config = {
165+plugins: {
166+entries: {
167+google: {
168+enabled: true,
169+config: {
170+webSearch: {
171+apiKey: { source: "env", provider: "default", id: "MISSING_GEMINI_KEY" },
168172},
169173},
170174},
171175},
172-{
173-reason: "reload",
174-activate: true,
175-},
176-),
177-).resolves.toMatchObject({
178-warnings: [warning],
176+},
177+};
178+const result = await activateRuntimeSecrets(config, {
179+reason: "reload",
180+activate: true,
179181});
182+expect(result.sourceConfig).toBe(config);
183+expect(result.config).toBe(config);
184+expect(result.warnings).toEqual([warning]);
180185expect(logSecrets.warn).toHaveBeenCalledWith(
181186"[WEB_SEARCH_KEY_UNRESOLVED_FALLBACK_USED] web search provider fell back to environment credentials",
182187);
183188expect(emitStateEvent).not.toHaveBeenCalled();
184-expect(prepareRuntimeSecretsSnapshot).toHaveBeenCalledWith({
185-config: expect.any(Object),
186-});
189+const preflightInput = callArg<{ config?: unknown }>(prepareRuntimeSecretsSnapshot);
190+expect(typeof preflightInput.config).toBe("object");
187191});
188192189193it.each(KNOWN_WEAK_GATEWAY_TOKEN_PLACEHOLDERS)(
@@ -259,22 +263,17 @@ describe("gateway startup config secret preflight", () => {
259263}),
260264);
261265262-await expect(
263-activateRuntimeSecrets(config, {
264-reason: "startup",
265-activate: false,
266-}),
267-).resolves.toMatchObject({
268-config: expect.objectContaining({
269-gateway: expect.any(Object),
270-}),
271-});
272-expect(prepareRuntimeSecretsSnapshot).toHaveBeenCalledWith({
273-config: expect.not.objectContaining({
274-channels: expect.anything(),
275-}),
276-loadAuthStore: loadAuthProfileStoreWithoutExternalProfiles,
266+const result = await activateRuntimeSecrets(config, {
267+reason: "startup",
268+activate: false,
277269});
270+expect(typeof result.config.gateway).toBe("object");
271+const preflightInput = callArg<{
272+config?: OpenClawConfig;
273+loadAuthStore?: unknown;
274+}>(prepareRuntimeSecretsSnapshot);
275+expect(preflightInput.config?.channels).toBeUndefined();
276+expect(preflightInput.loadAuthStore).toBe(loadAuthProfileStoreWithoutExternalProfiles);
278277});
279278280279it("honors startup auth overrides before secret preflight gating", async () => {
@@ -310,21 +309,15 @@ describe("gateway startup config secret preflight", () => {
310309}),
311310});
312311313-expect(result.auth).toMatchObject({
314-mode: "password",
315-password: "override-password",
316-});
317-expect(prepareRuntimeSecretsSnapshot).toHaveBeenNthCalledWith(1, {
318-config: expect.objectContaining({
319-gateway: expect.objectContaining({
320-auth: expect.objectContaining({
321-mode: "password",
322-password: "override-password",
323-}),
324-}),
325-}),
326-loadAuthStore: loadAuthProfileStoreWithoutExternalProfiles,
327-});
312+expect(result.auth.mode).toBe("password");
313+expect(result.auth.password).toBe("override-password");
314+const preflightInput = callArg<{
315+config?: OpenClawConfig;
316+loadAuthStore?: unknown;
317+}>(prepareRuntimeSecretsSnapshot);
318+expect(preflightInput.config?.gateway?.auth?.mode).toBe("password");
319+expect(preflightInput.config?.gateway?.auth?.password).toBe("override-password");
320+expect(preflightInput.loadAuthStore).toBe(loadAuthProfileStoreWithoutExternalProfiles);
328321expect(activateRuntimeSecretsSnapshot).toHaveBeenCalledTimes(1);
329322});
330323@@ -344,21 +337,15 @@ describe("gateway startup config secret preflight", () => {
344337}),
345338});
346339347-expect(result.auth).toMatchObject({
348-mode: "token",
349-token: "startup-test-token",
350-});
340+expect(result.auth.mode).toBe("token");
341+expect(result.auth.token).toBe("startup-test-token");
351342expect(prepareRuntimeSecretsSnapshot).toHaveBeenCalledTimes(1);
352-expect(prepareRuntimeSecretsSnapshot).toHaveBeenCalledWith({
353-config: expect.objectContaining({
354-gateway: expect.objectContaining({
355-auth: expect.objectContaining({
356-token: "startup-test-token",
357-}),
358-}),
359-}),
360-loadAuthStore: loadAuthProfileStoreWithoutExternalProfiles,
361-});
343+const preflightInput = callArg<{
344+config?: OpenClawConfig;
345+loadAuthStore?: unknown;
346+}>(prepareRuntimeSecretsSnapshot);
347+expect(preflightInput.config?.gateway?.auth?.token).toBe("startup-test-token");
348+expect(preflightInput.loadAuthStore).toBe(loadAuthProfileStoreWithoutExternalProfiles);
362349});
363350364351it("uses gateway auth strings resolved during startup preflight for bootstrap auth", async () => {
@@ -401,10 +388,8 @@ describe("gateway startup config secret preflight", () => {
401388}),
402389});
403390404-expect(result.auth).toMatchObject({
405-mode: "token",
406-token: "resolved-gateway-token",
407-});
391+expect(result.auth.mode).toBe("token");
392+expect(result.auth.token).toBe("resolved-gateway-token");
408393expect(prepareRuntimeSecretsSnapshot).toHaveBeenCalledTimes(2);
409394});
410395});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。