





















@@ -10,6 +10,8 @@ import { agentCliCommand, agentViaGatewayTesting } from "./agent-via-gateway.js"
1010import type { agentCommand as AgentCommand } from "./agent.js";
11111212const loadConfig = vi.hoisted(() => vi.fn());
13+const loadConfigWithShellEnvFallback = vi.hoisted(() => vi.fn());
14+const loadRuntimeConfig = vi.hoisted(() => vi.fn());
1315const callGateway = vi.hoisted(() => vi.fn());
1416const isGatewayCredentialsRequiredError = vi.hoisted(() =>
1517vi.fn(
@@ -49,7 +51,7 @@ const jsonRuntime = {
4951};
50525153function mockConfig(storePath: string, overrides?: Partial<OpenClawConfig>) {
52-loadConfig.mockReturnValue({
54+const config = {
5355agents: {
5456defaults: {
5557timeoutSeconds: 600,
@@ -63,7 +65,10 @@ function mockConfig(storePath: string, overrides?: Partial<OpenClawConfig>) {
6365 ...overrides?.session,
6466},
6567gateway: overrides?.gateway,
66-});
68+};
69+loadConfig.mockReturnValue(config);
70+loadConfigWithShellEnvFallback.mockResolvedValue(config);
71+loadRuntimeConfig.mockReturnValue(config);
6772}
68736974async function withTempStore(
@@ -217,7 +222,14 @@ function createGatewayNormalCloseError() {
217222});
218223}
219224220-vi.mock("../config/io.js", () => ({ getRuntimeConfig: loadConfig, loadConfig }));
225+vi.mock("../config/gateway-dispatch-config.js", () => ({
226+readGatewayDispatchConfig: loadConfig,
227+readGatewayDispatchConfigWithShellEnvFallback: loadConfigWithShellEnvFallback,
228+}));
229+vi.mock("../config/io.js", () => ({
230+getRuntimeConfig: loadRuntimeConfig,
231+loadConfig: loadRuntimeConfig,
232+}));
221233vi.mock("../gateway/call.js", () => ({
222234 callGateway,
223235 isGatewayCredentialsRequiredError,
@@ -344,11 +356,7 @@ describe("agentCliCommand", () => {
344356expect(params.sessionId).toBeUndefined();
345357expect(params.to).toBeUndefined();
346358expect(request.config).toBe(loadConfig.mock.results[0]?.value);
347-expect(loadConfig).toHaveBeenCalledWith({
348-skipPluginValidation: true,
349-pin: false,
350-skipShellEnvFallback: true,
351-});
359+expect(loadConfig).toHaveBeenCalledWith();
352360expect(agentCommand).not.toHaveBeenCalled();
353361expect(loadAgentSessionModuleMock).not.toHaveBeenCalled();
354362});
@@ -366,18 +374,19 @@ describe("agentCliCommand", () => {
366374};
367375loadConfig.mockReset();
368376loadConfig.mockReturnValueOnce(fastConfig);
369-loadConfig.mockReturnValueOnce(shellEnvConfig);
377+loadConfigWithShellEnvFallback.mockReset();
378+loadConfigWithShellEnvFallback.mockResolvedValueOnce(shellEnvConfig);
370379const authError = new Error("gateway agent requires credentials");
371380authError.name = "GatewayCredentialsRequiredError";
372381callGateway.mockRejectedValueOnce(authError);
373382mockGatewaySuccessReply();
374383375384await agentCliCommand({ message: "hi", sessionKey: "agent:main:incident-42" }, runtime);
376385377-expect(loadConfig.mock.calls).toEqual([
378- [{ skipPluginValidation: true, pin: false, skipShellEnvFallback: true }],
379- [{ skipPluginValidation: true, pin: false, skipShellEnvFallback: false }],
380-]);
386+expect(loadConfig).toHaveBeenCalledTimes(1);
387+expect(loadConfig).toHaveBeenCalledWith();
388+expect(loadConfigWithShellEnvFallback).toHaveBeenCalledTimes(1);
389+expect(loadConfigWithShellEnvFallback).toHaveBeenCalledWith();
381390expect(callGateway).toHaveBeenCalledTimes(2);
382391expect(requireRecord(callGateway.mock.calls[0]?.[0], "first gateway request").config).toBe(
383392fastConfig,
@@ -396,18 +405,19 @@ describe("agentCliCommand", () => {
396405};
397406loadConfig.mockReset();
398407loadConfig.mockReturnValueOnce(fastConfig);
399-loadConfig.mockReturnValueOnce(fastConfig);
408+loadConfigWithShellEnvFallback.mockReset();
409+loadConfigWithShellEnvFallback.mockResolvedValueOnce(fastConfig);
400410const authError = new Error("gateway url override requires explicit credentials");
401411authError.name = "GatewayExplicitAuthRequiredError";
402412callGateway.mockRejectedValueOnce(authError);
403413mockGatewaySuccessReply();
404414405415await agentCliCommand({ message: "hi", sessionKey: "agent:main:incident-42" }, runtime);
406416407-expect(loadConfig.mock.calls).toEqual([
408- [{ skipPluginValidation: true, pin: false, skipShellEnvFallback: true }],
409- [{ skipPluginValidation: true, pin: false, skipShellEnvFallback: false }],
410-]);
417+expect(loadConfig).toHaveBeenCalledTimes(1);
418+expect(loadConfig).toHaveBeenCalledWith();
419+expect(loadConfigWithShellEnvFallback).toHaveBeenCalledTimes(1);
420+expect(loadConfigWithShellEnvFallback).toHaveBeenCalledWith();
411421expect(callGateway).toHaveBeenCalledTimes(2);
412422});
413423});
@@ -1559,10 +1569,7 @@ describe("agentCliCommand", () => {
15591569};
15601570expect(fallbackOpts.sessionId).toMatch(/^gateway-fallback-/);
15611571expect(fallbackOpts.sessionKey).toBe(`agent:ops:explicit:${fallbackOpts.sessionId}`);
1562-expect(loadConfig.mock.calls).toEqual([
1563-[{ skipPluginValidation: true, pin: false, skipShellEnvFallback: true }],
1564-[{ skipPluginValidation: true, pin: false, skipShellEnvFallback: true }],
1565-]);
1572+expect(loadConfig.mock.calls).toEqual([[], []]);
15661573},
15671574{ agents: { list: [{ id: "ops", default: true }, { id: "main" }] } },
15681575);
@@ -1750,7 +1757,7 @@ describe("agentCliCommand", () => {
17501757);
17511758expect(localOpts.agentId).toBe("ops");
17521759expect(localOpts.sessionKey).toBe("agent:ops:incident-42");
1753-expect(loadConfig).toHaveBeenCalledWith();
1760+expect(loadRuntimeConfig).toHaveBeenCalledWith();
17541761});
17551762});
17561763此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。