
























@@ -17,6 +17,15 @@ const DEFAULT_EXPECTED_POLICY: CliCommandPathPolicy = {
1717networkProxy: "default",
1818};
191920+type NetworkProxyResolver = Extract<
21+CliCommandPathPolicy["networkProxy"],
22+(ctx: { argv: string[]; commandPath: string[] }) => unknown
23+>;
24+type LoadPluginsResolver = Extract<
25+CliCommandPathPolicy["loadPlugins"],
26+(ctx: { argv: string[]; commandPath: string[]; jsonOutputMode: boolean }) => unknown
27+>;
28+2029function expectResolvedPolicy(
2130commandPath: string[],
2231expected: Partial<CliCommandPathPolicy>,
@@ -27,6 +36,18 @@ function expectResolvedPolicy(
2736});
2837}
293839+function expectNetworkProxyResolver(
40+policy: CliCommandPathPolicy,
41+): asserts policy is CliCommandPathPolicy & { networkProxy: NetworkProxyResolver } {
42+expect(typeof policy.networkProxy).toBe("function");
43+}
44+45+function expectLoadPluginsResolver(
46+policy: CliCommandPathPolicy,
47+): asserts policy is CliCommandPathPolicy & { loadPlugins: LoadPluginsResolver } {
48+expect(typeof policy.loadPlugins).toBe("function");
49+}
50+3051describe("command-path-policy", () => {
3152afterEach(() => {
3253vi.doUnmock("./command-catalog.js");
@@ -61,11 +82,26 @@ describe("command-path-policy", () => {
6182pluginRegistry: { scope: "configured-channels" },
6283networkProxy: "bypass",
6384});
64-expectResolvedPolicy(["channels", "status"], {
85+const channelsStatusPolicy = resolveCliCommandPathPolicy(["channels", "status"]);
86+expect(channelsStatusPolicy).toEqual({
87+ ...DEFAULT_EXPECTED_POLICY,
6588loadPlugins: "never",
6689pluginRegistry: { scope: "configured-channels" },
67-networkProxy: expect.any(Function),
90+networkProxy: channelsStatusPolicy.networkProxy,
6891});
92+expectNetworkProxyResolver(channelsStatusPolicy);
93+expect(
94+channelsStatusPolicy.networkProxy({
95+argv: ["node", "openclaw", "channels", "status"],
96+commandPath: ["channels", "status"],
97+}),
98+).toBe("bypass");
99+expect(
100+channelsStatusPolicy.networkProxy({
101+argv: ["node", "openclaw", "channels", "status", "--probe"],
102+commandPath: ["channels", "status"],
103+}),
104+).toBe("default");
69105expectResolvedPolicy(["channels", "list"], {
70106loadPlugins: "never",
71107pluginRegistry: { scope: "configured-channels" },
@@ -89,11 +125,48 @@ describe("command-path-policy", () => {
89125});
9012691127it("keeps config-only agent commands on config-only startup", () => {
92-expectResolvedPolicy(["agent"], {
93-loadPlugins: expect.any(Function),
128+const agentPolicy = resolveCliCommandPathPolicy(["agent"]);
129+expect(agentPolicy).toEqual({
130+ ...DEFAULT_EXPECTED_POLICY,
131+loadPlugins: agentPolicy.loadPlugins,
94132pluginRegistry: { scope: "all" },
95-networkProxy: expect.any(Function),
133+networkProxy: agentPolicy.networkProxy,
96134});
135+expectLoadPluginsResolver(agentPolicy);
136+expectNetworkProxyResolver(agentPolicy);
137+expect(
138+agentPolicy.loadPlugins({
139+argv: ["node", "openclaw", "agent"],
140+commandPath: ["agent"],
141+jsonOutputMode: false,
142+}),
143+).toBe(true);
144+expect(
145+agentPolicy.loadPlugins({
146+argv: ["node", "openclaw", "agent", "--json"],
147+commandPath: ["agent"],
148+jsonOutputMode: true,
149+}),
150+).toBe(false);
151+expect(
152+agentPolicy.loadPlugins({
153+argv: ["node", "openclaw", "agent", "--local"],
154+commandPath: ["agent"],
155+jsonOutputMode: true,
156+}),
157+).toBe(true);
158+expect(
159+agentPolicy.networkProxy({
160+argv: ["node", "openclaw", "agent"],
161+commandPath: ["agent"],
162+}),
163+).toBe("bypass");
164+expect(
165+agentPolicy.networkProxy({
166+argv: ["node", "openclaw", "agent", "--local"],
167+commandPath: ["agent"],
168+}),
169+).toBe("default");
9717098171for (const commandPath of [
99172["agents"],
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。