Skip to content

Commit 56ec602

Browse files
committed
test: simplify table test conversions
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
1 parent 8c624c0 commit 56ec602

159 files changed

Lines changed: 552 additions & 1150 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ci/test-file-size-budget.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"src/lib/onboard/preflight.test.ts": 1875,
88
"test/generate-openclaw-config.test.ts": 1907,
99
"test/install-preflight.test.ts": 3025,
10-
"test/nemoclaw-start.test.ts": 4785,
10+
"test/nemoclaw-start.test.ts": 4761,
1111
"test/onboard-messaging.test.ts": 2033,
1212
"test/onboard-selection.test.ts": 4177
1313
}

nemoclaw/src/blueprint/runner.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,7 @@ describe("runner", () => {
410410
});
411411

412412
it.each(
413-
Array.from(
414-
[
413+
[
415414
"credential_env",
416415
"credential_default",
417416
"SECRET_KEY",
@@ -420,8 +419,6 @@ describe("runner", () => {
420419
"future-token-value",
421420
"future-authorization",
422421
],
423-
(tableRow) => [tableRow] as const,
424-
),
425422
)(
426423
"does not expose credential field names or secret values in public plan output [%s]",
427424
async (leaked) => {

nemoclaw/src/register.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ describe("plugin registration", () => {
177177

178178
const bannerLines = output.split("\n").filter((line) => line.length > 0);
179179
expect(bannerLines.length).toBeGreaterThan(0);
180-
expect(
181-
Array.from(bannerLines, (line) => Object.is(line.startsWith("[gateway] "), true)),
182-
).not.toContain(false);
180+
expect(bannerLines.every((line) => line.startsWith("[gateway] "))).toBe(true);
183181
});
184182

185183
it("falls back to onboard config when openclaw.json has no primary model", () => {

src/lib/actions/sandbox/auto-pair-approval-receipt.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ describe("auto-pair approval receipts (#4616)", () => {
2020
spawnSync("sh", ["-c", "command -v python3"], { stdio: "ignore" }).status !== 0;
2121

2222
it.skipIf(pythonUnavailable).each(
23-
Array.from(
24-
[
23+
[
2524
[{ NEMOCLAW_LIST_SLEEP_MS: "800" }, "list-timeout"],
2625
[
2726
{ NEMOCLAW_LIST_EXIT_CODE: "1", NEMOCLAW_LIST_STDERR: "raw failure" },
@@ -52,12 +51,10 @@ describe("auto-pair approval receipts (#4616)", () => {
5251
[{ NEMOCLAW_LIST_STDOUT: "raw invalid json" }, "list-invalid-json"],
5352
[{ NEMOCLAW_LIST_STDOUT: "[]\n" }, "list-invalid-output"],
5453
[{ NEMOCLAW_LIST_STDOUT: "{}\n" }, "list-missing-pending"],
55-
] as const,
56-
(tableRow) => [tableRow] as const,
57-
),
54+
] as const,
5855
)(
5956
"omits raw output from devices-list failure classifications [case %#]",
60-
([environment, receipt]) => {
57+
(environment, receipt) => {
6158
const policy = readAutoPairApprovalPolicyModule();
6259
expect(policy).toBeTruthy();
6360
const script = buildAutoPairApprovalScript(

src/lib/actions/sandbox/auto-pair-approval-script.test.ts

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -109,48 +109,38 @@ describe("buildAutoPairApprovalScript (#4263/#4616)", () => {
109109
expect(module).not.toContain("recover_failed_scope_approval");
110110
});
111111

112-
it.each(
113-
Array.from(
114-
[
115-
`${RECEIPT_MARKER}=approved-one\nlater output\n`,
116-
`${RECEIPT_MARKER}=approve-failed\n${RECEIPT_MARKER}=approved-one\n`,
117-
`${RECEIPT_MARKER}=raw-request-id\n`,
118-
],
119-
(value) => [value],
120-
),
121-
)("accepts exactly one terminal fixed receipt [case %#]", (output) => {
112+
it.each([
113+
"approved-one",
114+
"list-failed",
115+
"list-state-path-invalid",
116+
"list-platform-unsupported",
117+
"list-state-root-failed",
118+
"list-devices-directory-failed",
119+
"list-pending-unsafe",
120+
"list-pending-unstable",
121+
"list-pending-invalid-shape",
122+
"list-pending-unavailable",
123+
"list-timeout",
124+
"list-exec-failed",
125+
"list-scope-upgrade-pending",
126+
"list-device-pairing-required",
127+
"list-gateway-connect-failed",
128+
"list-command-failed",
129+
"list-empty-output",
130+
"list-invalid-json",
131+
"list-invalid-output",
132+
"list-missing-pending",
133+
] as const)("accepts the terminal fixed receipt %s", (receipt) => {
122134
expect(
123-
Array.from(
124-
[
125-
"approved-one",
126-
"list-failed",
127-
"list-state-path-invalid",
128-
"list-platform-unsupported",
129-
"list-state-root-failed",
130-
"list-devices-directory-failed",
131-
"list-pending-unsafe",
132-
"list-pending-unstable",
133-
"list-pending-invalid-shape",
134-
"list-pending-unavailable",
135-
"list-timeout",
136-
"list-exec-failed",
137-
"list-scope-upgrade-pending",
138-
"list-device-pairing-required",
139-
"list-gateway-connect-failed",
140-
"list-command-failed",
141-
"list-empty-output",
142-
"list-invalid-json",
143-
"list-invalid-output",
144-
"list-missing-pending",
145-
] as const,
146-
(receipt) =>
147-
Object.is(
148-
parseAutoPairApprovalReceipt(`ignored setup output\n${RECEIPT_MARKER}=${receipt}\n`),
149-
receipt,
150-
),
151-
),
152-
).not.toContain(false);
135+
parseAutoPairApprovalReceipt(`ignored setup output\n${RECEIPT_MARKER}=${receipt}\n`),
136+
).toBe(receipt);
137+
});
153138

139+
it.each([
140+
`${RECEIPT_MARKER}=approved-one\nlater output\n`,
141+
`${RECEIPT_MARKER}=approve-failed\n${RECEIPT_MARKER}=approved-one\n`,
142+
`${RECEIPT_MARKER}=raw-request-id\n`,
143+
])("rejects a non-terminal, duplicate, or unknown receipt [case %#]", (output) => {
154144
expect(parseAutoPairApprovalReceipt(output)).toBeNull();
155145
});
156146
});

src/lib/actions/sandbox/connect-hermes-light-theme.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,9 @@ describe("Hermes sandbox connect light terminal skin", () => {
378378

379379
const skinWriteCall = skinWriteCalls(harness)[0];
380380
expect(skinWriteCall?.[0]).toEqual(["sandbox", "exec", "--name", "alpha", "--", "sh", "-s"]);
381-
expect(
382-
Array.from((skinWriteCall?.[0] ?? []) as string[], (part) => !/[\n\r]/.test(part)),
383-
).not.toContain(false);
381+
expect(((skinWriteCall?.[0] ?? []) as string[]).every((part) => !/[\n\r]/.test(part))).toBe(
382+
true,
383+
);
384384
const opts = skinWriteCall?.[1] as { input?: string; stdio?: unknown } | undefined;
385385
expect(opts?.input ?? "").toContain('mv -f "$tmp" "$skin_dir/nemoclaw-light.yaml"');
386386
expect(opts?.input ?? "").toContain("\n");

src/lib/actions/sandbox/launch-readiness.test.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,16 +1041,11 @@ describe("launch readiness validation", () => {
10411041
],
10421042
},
10431043
];
1044-
expect(
1045-
Array.from(
1046-
mutations,
1047-
(mutation) =>
1044+
expect(mutations.every((mutation) =>
10481045
!Object.is(
10491046
launchReadinessDigest(buildLaunchReadinessRegistryProjection(mutation, agent)),
10501047
original,
1051-
),
1052-
),
1053-
).not.toContain(false);
1048+
))).toBe(true);
10541049
});
10551050

10561051
it("binds every host mount field without projecting the host source path (#8942)", () => {
@@ -1109,16 +1104,11 @@ describe("launch readiness validation", () => {
11091104
],
11101105
},
11111106
];
1112-
expect(
1113-
Array.from(
1114-
mutations,
1115-
(mutation) =>
1107+
expect(mutations.every((mutation) =>
11161108
!Object.is(
11171109
launchReadinessDigest(buildLaunchReadinessRegistryProjection(mutation, agent)),
11181110
original,
1119-
),
1120-
),
1121-
).not.toContain(false);
1111+
))).toBe(true);
11221112
expect(() =>
11231113
buildLaunchReadinessRegistryProjection(
11241114
{
@@ -1163,10 +1153,7 @@ describe("launch readiness validation", () => {
11631153
{ ...originalProfile, estimatedImageDownloadBytes: 1_001 },
11641154
{ ...originalProfile, estimatedModelDownloadBytes: 2_001 },
11651155
];
1166-
expect(
1167-
Array.from(
1168-
mutations,
1169-
(mutation) =>
1156+
expect(mutations.every((mutation) =>
11701157
!Object.is(
11711158
launchReadinessDigest(
11721159
buildLaunchReadinessRegistryProjection(
@@ -1175,9 +1162,7 @@ describe("launch readiness validation", () => {
11751162
),
11761163
),
11771164
original,
1178-
),
1179-
),
1180-
).not.toContain(false);
1165+
))).toBe(true);
11811166
});
11821167

11831168
it("excludes diagnostic timestamps, source paths, and GPU detail from the projection", () => {

src/lib/actions/sandbox/pi-candidate-lifecycle.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ describe("Pi candidate operational surfaces", () => {
147147
// source alone and never probe the OpenClaw gateway.
148148
expect(runOpenshell).toHaveBeenCalled();
149149
expect(exitCodes).toEqual([0]);
150-
expect(
151-
Array.from(runOpenshell.mock.calls, ([args]) => !args.join(" ").includes("openclaw")),
152-
).not.toContain(false);
150+
expect(runOpenshell.mock.calls.every(([args]) => !args.join(" ").includes("openclaw"))).toBe(true);
153151
expect(agent.forwardPort).toBe(0);
154152
expect(agent.healthProbe).toBeNull();
155153
});

src/lib/actions/sandbox/policy-channel-remove-flow.test.ts

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ describe("policy channel remove/enable flows", () => {
8484
return { rebuildSandbox, removePreset, updateSandbox };
8585
}
8686

87+
function expectHermesSessionCleanup(command: unknown) {
88+
expect(String(command)).toContain("/sandbox/.hermes/platforms/whatsapp");
89+
expect(String(command)).toContain(
90+
"/sandbox/.hermes/profiles/dashboard-home/platforms/whatsapp/session",
91+
);
92+
expect(String(command)).toContain(
93+
"/sandbox/.hermes/dashboard-home/platforms/whatsapp/session",
94+
);
95+
}
96+
8797
async function removeWhatsappNonInteractive() {
8898
const previousNonInteractive = process.env.NEMOCLAW_NON_INTERACTIVE;
8999
process.env.NEMOCLAW_NON_INTERACTIVE = "1";
@@ -137,14 +147,15 @@ describe("policy channel remove/enable flows", () => {
137147
).toBeLessThan(updateSandbox.mock.invocationCallOrder[0]);
138148
});
139149

140-
it.each([{ scenario: "exec transport" }, { scenario: "SSH transport" }])(
141-
"clears every Hermes WhatsApp session path through the SSH fallback [$scenario]",
142-
async ({ scenario }) => {
150+
it.each([
151+
{ scenario: "exec transport", execStatus: 0, usesSsh: false },
152+
{ scenario: "SSH fallback", execStatus: 1, usesSsh: true },
153+
])("clears every Hermes WhatsApp session path through $scenario", async ({ execStatus, usesSsh }) => {
143154
const { updateSandbox } = await arrangeHermesWhatsappRemoval();
144155
vi.mocked(processRecovery.executeSandboxExecCommand).mockReturnValue({
145-
status: 1,
146-
stdout: "",
147-
stderr: "exec unavailable",
156+
status: execStatus,
157+
stdout: execStatus === 0 ? "NEMOCLAW_CHANNEL_CLEAR_OK\n" : "",
158+
stderr: execStatus === 0 ? "" : "exec unavailable",
148159
});
149160
vi.mocked(processRecovery.executeSandboxCommand).mockReturnValue({
150161
status: 0,
@@ -154,30 +165,24 @@ describe("policy channel remove/enable flows", () => {
154165

155166
await expect(removeWhatsappNonInteractive()).resolves.toBeUndefined();
156167

157-
const command = (
158-
{
159-
"exec transport": vi.mocked(processRecovery.executeSandboxExecCommand).mock.calls[0]?.[1],
160-
"SSH transport": vi.mocked(processRecovery.executeSandboxCommand).mock.calls[0]?.[1],
161-
} as const
162-
)[scenario]!;
163-
expect(String(command)).toContain("/sandbox/.hermes/platforms/whatsapp");
164-
expect(String(command)).toContain(
165-
"/sandbox/.hermes/profiles/dashboard-home/platforms/whatsapp/session",
166-
);
167-
expect(String(command)).toContain(
168-
"/sandbox/.hermes/dashboard-home/platforms/whatsapp/session",
169-
);
168+
const transport = usesSsh
169+
? vi.mocked(processRecovery.executeSandboxCommand)
170+
: vi.mocked(processRecovery.executeSandboxExecCommand);
171+
expectHermesSessionCleanup(transport.mock.calls[0]?.[1]);
172+
const sshCleanupCommands = vi
173+
.mocked(processRecovery.executeSandboxCommand)
174+
.mock.calls.filter(([, command]) =>
175+
String(command).includes("/sandbox/.hermes/platforms/whatsapp"),
176+
);
177+
expect(sshCleanupCommands).toHaveLength(usesSsh ? 1 : 0);
170178

171179
expect(updateSandbox).toHaveBeenCalled();
172-
expect(
173-
vi.mocked(processRecovery.executeSandboxCommand).mock.invocationCallOrder[0],
174-
).toBeLessThan(updateSandbox.mock.invocationCallOrder[0]);
175-
},
176-
);
180+
expect(transport.mock.invocationCallOrder[0]).toBeLessThan(
181+
updateSandbox.mock.invocationCallOrder[0],
182+
);
183+
});
177184

178-
it.each([{ scenario: "exec transport" }, { scenario: "SSH transport" }])(
179-
"keeps channel state unchanged when both Hermes cleanup transports fail [$scenario]",
180-
async ({ scenario }) => {
185+
it("keeps channel state unchanged when both Hermes cleanup transports fail", async () => {
181186
const { rebuildSandbox, removePreset, updateSandbox } = await arrangeHermesWhatsappRemoval();
182187
const runOpenshell = vi.spyOn(openshellRuntime, "runOpenshell");
183188
vi.mocked(processRecovery.executeSandboxExecCommand).mockReturnValue({
@@ -193,26 +198,18 @@ describe("policy channel remove/enable flows", () => {
193198

194199
await expect(removeWhatsappNonInteractive()).rejects.toThrow("process.exit(1)");
195200

196-
const command = (
197-
{
198-
"exec transport": vi.mocked(processRecovery.executeSandboxExecCommand).mock.calls[0]?.[1],
199-
"SSH transport": vi.mocked(processRecovery.executeSandboxCommand).mock.calls[0]?.[1],
200-
} as const
201-
)[scenario]!;
202-
expect(String(command)).toContain("/sandbox/.hermes/platforms/whatsapp");
203-
expect(String(command)).toContain(
204-
"/sandbox/.hermes/profiles/dashboard-home/platforms/whatsapp/session",
201+
expectHermesSessionCleanup(
202+
vi.mocked(processRecovery.executeSandboxExecCommand).mock.calls[0]?.[1],
205203
);
206-
expect(String(command)).toContain(
207-
"/sandbox/.hermes/dashboard-home/platforms/whatsapp/session",
204+
expectHermesSessionCleanup(
205+
vi.mocked(processRecovery.executeSandboxCommand).mock.calls[0]?.[1],
208206
);
209207

210208
expect(runOpenshell).not.toHaveBeenCalled();
211209
expect(updateSandbox).not.toHaveBeenCalled();
212210
expect(removePreset).not.toHaveBeenCalled();
213211
expect(rebuildSandbox).not.toHaveBeenCalled();
214-
},
215-
);
212+
});
216213

217214
it("supports stop dry runs for configured Hermes channels", async () => {
218215
vi.spyOn(registry, "getSandbox").mockReturnValue({ name: "alpha", agent: "hermes" });

src/lib/actions/sandbox/policy-explain.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ describe("writePolicyContextToSandbox", () => {
205205
});
206206

207207
it.each(
208-
Array.from(
209-
[
208+
[
210209
"rm -rf",
211210
"curl http://attacker",
212211
"whoami",
@@ -216,8 +215,6 @@ describe("writePolicyContextToSandbox", () => {
216215
"/etc/shadow",
217216
"evil",
218217
],
219-
(tableRow) => [tableRow] as const,
220-
),
221218
)(
222219
"encodes hostile markdown payloads as base64 so they cannot break out of the write command [%s]",
223220
(token) => {

0 commit comments

Comments
 (0)