Skip to content

Commit 39878b2

Browse files
committed
fix(cli): keep channels status route cold
1 parent 90a3774 commit 39878b2

4 files changed

Lines changed: 76 additions & 49 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// The real route-first channel status path must stay out of local config/plugin runtimes.
2+
import { beforeEach, describe, expect, it, vi } from "vitest";
3+
4+
const loaded = vi.hoisted(() => {
5+
const modules = new Set<string>();
6+
return {
7+
modules,
8+
mark(name: string) {
9+
modules.add(name);
10+
},
11+
};
12+
});
13+
const callGatewayMock = vi.hoisted(() => vi.fn(async () => ({ channelAccounts: {} })));
14+
const runtime = vi.hoisted(() => ({
15+
error: vi.fn(),
16+
exit: vi.fn(),
17+
log: vi.fn(),
18+
writeJson: vi.fn(),
19+
writeStdout: vi.fn(),
20+
}));
21+
22+
vi.mock("./program/config-guard.js", () => {
23+
loaded.mark("config-guard");
24+
return { ensureConfigReady: vi.fn(async () => {}) };
25+
});
26+
27+
vi.mock("../commands/channels/status.runtime.js", () => {
28+
loaded.mark("channels-status-runtime");
29+
return {
30+
formatGatewayChannelsStatusLines: vi.fn(() => []),
31+
renderChannelsStatusFallback: vi.fn(async () => {}),
32+
};
33+
});
34+
35+
vi.mock("../gateway/call.js", () => ({
36+
callGateway: callGatewayMock,
37+
}));
38+
39+
vi.mock("./progress.js", () => ({
40+
withProgress: vi.fn(async (_opts, run: () => Promise<unknown>) => await run()),
41+
}));
42+
43+
vi.mock("../runtime.js", () => ({
44+
defaultRuntime: runtime,
45+
writeRuntimeJson: vi.fn((target, value) => target.writeJson(value, 2)),
46+
}));
47+
48+
import { tryRouteCli } from "./route.js";
49+
50+
describe("routed channels status cold imports", () => {
51+
beforeEach(() => {
52+
// Never clear `loaded.modules`: mock factories mark at module-load time, so an
53+
// eager import during route.js's own static import graph is exactly the
54+
// regression evidence this test exists to keep.
55+
vi.clearAllMocks();
56+
});
57+
58+
it("keeps successful JSON routes cold with and without probing", async () => {
59+
for (const probe of [false, true]) {
60+
vi.clearAllMocks();
61+
const argv = ["node", "openclaw", "channels", "status", "--json"];
62+
if (probe) {
63+
argv.push("--probe");
64+
}
65+
66+
await expect(tryRouteCli(argv)).resolves.toBe(true);
67+
68+
expect(callGatewayMock).toHaveBeenCalledOnce();
69+
expect(runtime.writeJson).toHaveBeenCalledWith({ channelAccounts: {} }, 2);
70+
expect(loaded.modules).not.toContain("config-guard");
71+
expect(loaded.modules).not.toContain("channels-status-runtime");
72+
}
73+
});
74+
});

‎src/cli/command-catalog.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ export const cliCommandCatalog: readonly CliCommandCatalogEntry[] = [
486486
exact: true,
487487
policy: {
488488
bypassConfigGuard: true,
489+
routeConfigGuard: "always",
489490
loadPlugins: "never",
490491
networkProxy: ({ argv }) => (hasFlag(argv, "--probe") ? "default" : "bypass"),
491492
},

‎src/cli/command-path-policy.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ describe("command-path-policy", () => {
9797
expect(channelsStatusPolicy).toEqual({
9898
...DEFAULT_EXPECTED_POLICY,
9999
bypassConfigGuard: true,
100+
routeConfigGuard: "always",
100101
loadPlugins: "never",
101102
pluginRegistry: { scope: "configured-channels" },
102103
networkProxy: channelsStatusPolicy.networkProxy,

‎src/commands/channels.status-cold-imports.test.ts‎

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)