forked from openclaw/openclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus.test.ts
More file actions
110 lines (95 loc) · 2.69 KB
/
Copy pathstatus.test.ts
File metadata and controls
110 lines (95 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { beforeEach, describe, expect, it, vi } from "vitest";
import { createCliRuntimeCapture } from "../test-runtime-capture.js";
import type { DaemonStatus } from "./status.gather.js";
const gatherDaemonStatus = vi.fn(
async (_opts?: unknown): Promise<DaemonStatus> => ({
service: {
label: "LaunchAgent",
loaded: true,
loadedText: "loaded",
notLoadedText: "not loaded",
},
rpc: {
ok: true,
url: "ws://127.0.0.1:18789",
},
extraServices: [],
}),
);
const printDaemonStatus = vi.fn();
const { runtimeErrors, defaultRuntime, resetRuntimeCapture } = createCliRuntimeCapture();
vi.mock("../../runtime.js", () => ({
defaultRuntime,
}));
vi.mock("../../terminal/theme.js", () => ({
colorize: (_rich: boolean, _color: unknown, text: string) => text,
isRich: () => false,
theme: { error: "error" },
}));
vi.mock("./status.gather.js", () => ({
gatherDaemonStatus: (opts: unknown) => gatherDaemonStatus(opts),
}));
vi.mock("./status.print.js", () => ({
printDaemonStatus: (...args: unknown[]) => printDaemonStatus(...args),
}));
const { runDaemonStatus } = await import("./status.js");
describe("runDaemonStatus", () => {
beforeEach(() => {
gatherDaemonStatus.mockClear();
printDaemonStatus.mockClear();
resetRuntimeCapture();
});
it("exits when require-rpc is set and the probe fails", async () => {
gatherDaemonStatus.mockResolvedValueOnce({
service: {
label: "LaunchAgent",
loaded: true,
loadedText: "loaded",
notLoadedText: "not loaded",
},
rpc: {
ok: false,
url: "ws://127.0.0.1:18789",
error: "gateway closed",
},
extraServices: [],
});
await expect(
runDaemonStatus({
rpc: {},
probe: true,
requireRpc: true,
json: false,
}),
).rejects.toThrow("__exit__:1");
expect(printDaemonStatus).toHaveBeenCalledTimes(1);
});
it("forwards require-rpc to daemon status gathering", async () => {
await runDaemonStatus({
rpc: {},
probe: true,
requireRpc: true,
json: false,
});
expect(gatherDaemonStatus).toHaveBeenCalledWith({
rpc: {},
probe: true,
requireRpc: true,
deep: false,
});
});
it("rejects require-rpc when probing is disabled", async () => {
await expect(
runDaemonStatus({
rpc: {},
probe: false,
requireRpc: true,
json: false,
}),
).rejects.toThrow("__exit__:1");
expect(gatherDaemonStatus).not.toHaveBeenCalled();
expect(runtimeErrors[0]).toBe(
"Gateway status failed: --require-rpc needs probing enabled. Remove --no-probe or drop --require-rpc.",
);
});
});