Skip to content

Commit d5fe89a

Browse files
committed
test: tighten status and onboarding assertions
1 parent 0aa0083 commit d5fe89a

4 files changed

Lines changed: 64 additions & 80 deletions

File tree

src/commands/onboard-remote.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ describe("promptRemoteGatewayConfig", () => {
264264
const next = await promptRemoteGatewayConfig({} as OpenClawConfig, prompter);
265265

266266
expect(next.gateway?.remote?.url).toBe("ws://127.0.0.1:18789");
267-
expect(select).not.toHaveBeenCalledWith(
268-
expect.objectContaining({ message: "Connection method" }),
267+
expect(vi.mocked(select).mock.calls.map(([params]) => params.message)).not.toContain(
268+
"Connection method",
269269
);
270270
});
271271

@@ -391,7 +391,9 @@ describe("promptRemoteGatewayConfig", () => {
391391
const next = await promptRemoteGatewayConfig(cfg, prompter);
392392

393393
expect(next.gateway?.remote?.token).toBe("preexisting-remote-token");
394-
expect(text).not.toHaveBeenCalledWith(expect.objectContaining({ message: "Gateway token" }));
394+
expect(vi.mocked(text).mock.calls.map(([params]) => params.message)).not.toContain(
395+
"Gateway token",
396+
);
395397
});
396398

397399
it("keeps an existing remote gateway password when user confirms via masked-preview prompt", async () => {
@@ -427,6 +429,8 @@ describe("promptRemoteGatewayConfig", () => {
427429
const next = await promptRemoteGatewayConfig(cfg, prompter);
428430

429431
expect(next.gateway?.remote?.password).toBe("preexisting-remote-password");
430-
expect(text).not.toHaveBeenCalledWith(expect.objectContaining({ message: "Gateway password" }));
432+
expect(vi.mocked(text).mock.calls.map(([params]) => params.message)).not.toContain(
433+
"Gateway password",
434+
);
431435
});
432436
});

src/commands/status-all/channels.test.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,31 +77,20 @@ describe("buildChannelsTable", () => {
7777
},
7878
);
7979

80-
expect(table.rows).toContainEqual(
81-
expect.objectContaining({
82-
id: "discord",
83-
state: "ok",
84-
detail: expect.not.stringContaining("unavailable"),
85-
}),
86-
);
87-
expect(table.details[0]?.rows[0]).toEqual(
88-
expect.objectContaining({
89-
Status: "OK",
90-
Notes: expect.stringContaining("credential available in gateway runtime"),
91-
}),
92-
);
80+
const row = table.rows.find((entry) => entry.id === "discord");
81+
expect(row?.state).toBe("ok");
82+
expect(row?.detail).not.toContain("unavailable");
83+
const detailRow = table.details[0]?.rows[0];
84+
expect(detailRow?.Status).toBe("OK");
85+
expect(detailRow?.Notes).toContain("credential available in gateway runtime");
9386
});
9487

9588
it("warns when a configured token is unavailable and there is no live account proof", async () => {
9689
const table = await buildChannelsTable({ channels: { discord: { enabled: true } } });
9790

98-
expect(table.rows).toContainEqual(
99-
expect.objectContaining({
100-
id: "discord",
101-
state: "warn",
102-
detail: expect.stringContaining("unavailable"),
103-
}),
104-
);
91+
const row = table.rows.find((entry) => entry.id === "discord");
92+
expect(row?.state).toBe("warn");
93+
expect(row?.detail).toContain("unavailable");
10594
});
10695

10796
it("shows configured official external channels when the plugin is missing", async () => {

src/commands/status-overview-rows.test.ts

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,67 +9,60 @@ import {
99
createStatusCommandOverviewRowsParams,
1010
} from "./status.test-support.ts";
1111

12+
function findRowValue(rows: Array<{ Item: string; Value: string }>, item: string) {
13+
return rows.find((row) => row.Item === item)?.Value;
14+
}
15+
1216
describe("status-overview-rows", () => {
1317
it("builds command overview rows from the shared surface", () => {
14-
expect(buildStatusCommandOverviewRows(createStatusCommandOverviewRowsParams())).toEqual(
15-
expect.arrayContaining([
16-
{ Item: "OS", Value: `macOS · node ${process.versions.node}` },
17-
{
18-
Item: "Memory",
19-
Value:
20-
"1 files · 2 chunks · plugin memory · ok(vector ready) · warn(fts ready) · muted(cache warm)",
21-
},
22-
{ Item: "Plugin compatibility", Value: "warn(1 notice · 1 plugin)" },
23-
{ Item: "Sessions", Value: "2 active · default gpt-5.5 (12k ctx) · store.json" },
24-
]),
18+
const rows = buildStatusCommandOverviewRows(createStatusCommandOverviewRowsParams());
19+
20+
expect(findRowValue(rows, "OS")).toBe(`macOS · node ${process.versions.node}`);
21+
expect(findRowValue(rows, "Memory")).toBe(
22+
"1 files · 2 chunks · plugin memory · ok(vector ready) · warn(fts ready) · muted(cache warm)",
23+
);
24+
expect(findRowValue(rows, "Plugin compatibility")).toBe("warn(1 notice · 1 plugin)");
25+
expect(findRowValue(rows, "Sessions")).toBe(
26+
"2 active · default gpt-5.5 (12k ctx) · store.json",
2527
);
2628
});
2729

2830
it("marks skipped memory inspection as not checked in fast status output", () => {
29-
expect(
30-
buildStatusCommandOverviewRows(
31-
createStatusCommandOverviewRowsParams({
32-
memory: null,
33-
memoryPlugin: { enabled: true, slot: "memory-lancedb-pro" },
34-
}),
35-
),
36-
).toEqual(
37-
expect.arrayContaining([
38-
{
39-
Item: "Memory",
40-
Value: "muted(enabled (plugin memory-lancedb-pro) · not checked)",
41-
},
42-
]),
31+
const rows = buildStatusCommandOverviewRows(
32+
createStatusCommandOverviewRowsParams({
33+
memory: null,
34+
memoryPlugin: { enabled: true, slot: "memory-lancedb-pro" },
35+
}),
36+
);
37+
38+
expect(findRowValue(rows, "Memory")).toBe(
39+
"muted(enabled (plugin memory-lancedb-pro) · not checked)",
4340
);
4441
});
4542

4643
it("builds status-all overview rows from the shared surface", () => {
47-
expect(
48-
buildStatusAllOverviewRows({
49-
surface: {
50-
...baseStatusOverviewSurface,
51-
tailscaleMode: "off",
52-
tailscaleHttpsUrl: null,
53-
gatewayConnection: { url: "wss://gateway.example.com", urlSource: "config" },
54-
},
55-
osLabel: "macOS",
56-
configPath: "/tmp/openclaw.json",
57-
secretDiagnosticsCount: 2,
58-
agentStatus: {
59-
bootstrapPendingCount: 1,
60-
totalSessions: 2,
61-
agents: [{ id: "main", lastActiveAgeMs: 60_000 }],
62-
},
63-
tailscaleBackendState: "Running",
64-
}),
65-
).toEqual(
66-
expect.arrayContaining([
67-
{ Item: "Version", Value: VERSION },
68-
{ Item: "OS", Value: "macOS" },
69-
{ Item: "Config", Value: "/tmp/openclaw.json" },
70-
{ Item: "Security", Value: "Run: openclaw security audit --deep" },
71-
{ Item: "Secrets", Value: "2 diagnostics" },
72-
]),
73-
);
44+
const rows = buildStatusAllOverviewRows({
45+
surface: {
46+
...baseStatusOverviewSurface,
47+
tailscaleMode: "off",
48+
tailscaleHttpsUrl: null,
49+
gatewayConnection: { url: "wss://gateway.example.com", urlSource: "config" },
50+
},
51+
osLabel: "macOS",
52+
configPath: "/tmp/openclaw.json",
53+
secretDiagnosticsCount: 2,
54+
agentStatus: {
55+
bootstrapPendingCount: 1,
56+
totalSessions: 2,
57+
agents: [{ id: "main", lastActiveAgeMs: 60_000 }],
58+
},
59+
tailscaleBackendState: "Running",
60+
});
61+
62+
expect(findRowValue(rows, "Version")).toBe(VERSION);
63+
expect(findRowValue(rows, "OS")).toBe("macOS");
64+
expect(findRowValue(rows, "Config")).toBe("/tmp/openclaw.json");
65+
expect(findRowValue(rows, "Security")).toBe("Run: openclaw security audit --deep");
66+
expect(findRowValue(rows, "Secrets")).toBe("2 diagnostics");
7467
});
7568
});

src/commands/tasks.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,8 @@ describe("tasks commands", () => {
265265
};
266266
expect(payload.maintenance.sessions.pruned).toBe(1);
267267
expect(payload.maintenance.sessions.runningCronJobs).toBe(1);
268-
expect(payload.maintenance.sessions.stores[0]).toMatchObject({
269-
pruned: 1,
270-
preservedRunning: 1,
271-
});
268+
expect(payload.maintenance.sessions.stores[0]?.pruned).toBe(1);
269+
expect(payload.maintenance.sessions.stores[0]?.preservedRunning).toBe(1);
272270

273271
const updated = JSON.parse(await fs.readFile(storePath, "utf-8")) as Record<string, unknown>;
274272
expect(updated["agent:main:cron:done-job:run:old-run"]).toBeUndefined();

0 commit comments

Comments
 (0)