Skip to content

Commit 8c624c0

Browse files
committed
test: convert next 300 test loops to tables
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
1 parent 183a9c8 commit 8c624c0

202 files changed

Lines changed: 10321 additions & 9272 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.

nemoclaw/src/blueprint/runner.test.ts

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -409,58 +409,65 @@ describe("runner", () => {
409409
expect(plan.dry_run).toBe(false);
410410
});
411411

412-
it("does not expose credential field names or secret values in public plan output", async () => {
413-
captureStdout();
414-
mockExeca.mockResolvedValue({ exitCode: 0 });
415-
const bp = {
416-
components: {
417-
inference: {
418-
profiles: {
419-
secrets: {
420-
provider_type: "openai",
421-
provider_name: "secret-provider",
422-
endpoint: "https://api.example.com/v1",
423-
model: "gpt-4",
424-
credential_env: "SECRET_KEY",
425-
credential_default: "default-secret-value",
426-
token: "future-token-value",
427-
authorization: "Bearer future-authorization",
428-
},
429-
},
430-
},
431-
sandbox: { image: "openclaw", name: "sb", forward_ports: [18789] },
432-
},
433-
};
434-
process.env.SECRET_KEY = "real-secret-value";
435-
try {
436-
const plan = await actionPlan("secrets", bp);
437-
const rendered = capturedJsonOutput<{
438-
inference: Record<string, unknown>;
439-
}>();
440-
const out = stdoutText();
441-
442-
expect(plan.inference).not.toHaveProperty("credential_env");
443-
expect(rendered.inference).toEqual({
444-
provider_type: "openai",
445-
provider_name: "secret-provider",
446-
endpoint: "https://api.example.com/v1",
447-
model: "gpt-4",
448-
});
449-
for (const leaked of [
412+
it.each(
413+
Array.from(
414+
[
450415
"credential_env",
451416
"credential_default",
452417
"SECRET_KEY",
453418
"default-secret-value",
454419
"real-secret-value",
455420
"future-token-value",
456421
"future-authorization",
457-
]) {
422+
],
423+
(tableRow) => [tableRow] as const,
424+
),
425+
)(
426+
"does not expose credential field names or secret values in public plan output [%s]",
427+
async (leaked) => {
428+
captureStdout();
429+
mockExeca.mockResolvedValue({ exitCode: 0 });
430+
const bp = {
431+
components: {
432+
inference: {
433+
profiles: {
434+
secrets: {
435+
provider_type: "openai",
436+
provider_name: "secret-provider",
437+
endpoint: "https://api.example.com/v1",
438+
model: "gpt-4",
439+
credential_env: "SECRET_KEY",
440+
credential_default: "default-secret-value",
441+
token: "future-token-value",
442+
authorization: "Bearer future-authorization",
443+
},
444+
},
445+
},
446+
sandbox: { image: "openclaw", name: "sb", forward_ports: [18789] },
447+
},
448+
};
449+
process.env.SECRET_KEY = "real-secret-value";
450+
try {
451+
const plan = await actionPlan("secrets", bp);
452+
const rendered = capturedJsonOutput<{
453+
inference: Record<string, unknown>;
454+
}>();
455+
const out = stdoutText();
456+
457+
expect(plan.inference).not.toHaveProperty("credential_env");
458+
expect(rendered.inference).toEqual({
459+
provider_type: "openai",
460+
provider_name: "secret-provider",
461+
endpoint: "https://api.example.com/v1",
462+
model: "gpt-4",
463+
});
464+
458465
expect(out).not.toContain(leaked);
466+
} finally {
467+
delete process.env.SECRET_KEY;
459468
}
460-
} finally {
461-
delete process.env.SECRET_KEY;
462-
}
463-
});
469+
},
470+
);
464471

465472
it("passes dryRun through to the plan", async () => {
466473
captureStdout();

nemoclaw/src/register.test.ts

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

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

185185
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: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,9 @@ describe("auto-pair approval receipts (#4616)", () => {
1919
const pythonUnavailable =
2020
spawnSync("sh", ["-c", "command -v python3"], { stdio: "ignore" }).status !== 0;
2121

22-
it.skipIf(pythonUnavailable)("omits raw output from devices-list failure classifications", () => {
23-
const policy = readAutoPairApprovalPolicyModule();
24-
expect(policy).toBeTruthy();
25-
const script = buildAutoPairApprovalScript(
26-
Buffer.from(policy as string, "utf-8").toString("base64"),
27-
{
28-
emitReceipt: true,
29-
budget: { listTimeoutS: 0.5 },
30-
},
31-
);
32-
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-auto-pair-list-receipt-"));
33-
try {
34-
fs.writeFileSync(
35-
path.join(tmpDir, "openclaw"),
36-
`#!${process.execPath}
37-
const args = process.argv.slice(2);
38-
if (args[0] !== "devices" || args[1] !== "list") process.exit(2);
39-
const sleepMs = Number(process.env.NEMOCLAW_LIST_SLEEP_MS || "0");
40-
if (sleepMs > 0) {
41-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, sleepMs);
42-
}
43-
process.stdout.write(process.env.NEMOCLAW_LIST_STDOUT || "");
44-
process.stderr.write(process.env.NEMOCLAW_LIST_STDERR || "");
45-
process.exit(Number(process.env.NEMOCLAW_LIST_EXIT_CODE || "0"));
46-
`,
47-
{ mode: 0o755 },
48-
);
49-
for (const [environment, receipt] of [
22+
it.skipIf(pythonUnavailable).each(
23+
Array.from(
24+
[
5025
[{ NEMOCLAW_LIST_SLEEP_MS: "800" }, "list-timeout"],
5126
[
5227
{ NEMOCLAW_LIST_EXIT_CODE: "1", NEMOCLAW_LIST_STDERR: "raw failure" },
@@ -77,7 +52,39 @@ process.exit(Number(process.env.NEMOCLAW_LIST_EXIT_CODE || "0"));
7752
[{ NEMOCLAW_LIST_STDOUT: "raw invalid json" }, "list-invalid-json"],
7853
[{ NEMOCLAW_LIST_STDOUT: "[]\n" }, "list-invalid-output"],
7954
[{ NEMOCLAW_LIST_STDOUT: "{}\n" }, "list-missing-pending"],
80-
] as const) {
55+
] as const,
56+
(tableRow) => [tableRow] as const,
57+
),
58+
)(
59+
"omits raw output from devices-list failure classifications [case %#]",
60+
([environment, receipt]) => {
61+
const policy = readAutoPairApprovalPolicyModule();
62+
expect(policy).toBeTruthy();
63+
const script = buildAutoPairApprovalScript(
64+
Buffer.from(policy as string, "utf-8").toString("base64"),
65+
{
66+
emitReceipt: true,
67+
budget: { listTimeoutS: 0.5 },
68+
},
69+
);
70+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-auto-pair-list-receipt-"));
71+
try {
72+
fs.writeFileSync(
73+
path.join(tmpDir, "openclaw"),
74+
`#!${process.execPath}
75+
const args = process.argv.slice(2);
76+
if (args[0] !== "devices" || args[1] !== "list") process.exit(2);
77+
const sleepMs = Number(process.env.NEMOCLAW_LIST_SLEEP_MS || "0");
78+
if (sleepMs > 0) {
79+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, sleepMs);
80+
}
81+
process.stdout.write(process.env.NEMOCLAW_LIST_STDOUT || "");
82+
process.stderr.write(process.env.NEMOCLAW_LIST_STDERR || "");
83+
process.exit(Number(process.env.NEMOCLAW_LIST_EXIT_CODE || "0"));
84+
`,
85+
{ mode: 0o755 },
86+
);
87+
8188
const result = spawnSync("sh", ["-c", script], {
8289
encoding: "utf-8",
8390
env: {
@@ -89,11 +96,11 @@ process.exit(Number(process.env.NEMOCLAW_LIST_EXIT_CODE || "0"));
8996
});
9097
expect(parseAutoPairApprovalReceipt(result.stdout)).toBe(receipt);
9198
expect(`${result.stdout}${result.stderr}`).not.toContain("raw ");
99+
} finally {
100+
fs.rmSync(tmpDir, { recursive: true, force: true });
92101
}
93-
} finally {
94-
fs.rmSync(tmpDir, { recursive: true, force: true });
95-
}
96-
});
102+
},
103+
);
97104

98105
it("distinguishes host execution failures without returning their details", () => {
99106
const timeoutError = Object.assign(new Error("private timeout detail"), {

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

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -119,32 +119,37 @@ describe("buildAutoPairApprovalScript (#4263/#4616)", () => {
119119
(value) => [value],
120120
),
121121
)("accepts exactly one terminal fixed receipt [case %#]", (output) => {
122-
for (const receipt of [
123-
"approved-one",
124-
"list-failed",
125-
"list-state-path-invalid",
126-
"list-platform-unsupported",
127-
"list-state-root-failed",
128-
"list-devices-directory-failed",
129-
"list-pending-unsafe",
130-
"list-pending-unstable",
131-
"list-pending-invalid-shape",
132-
"list-pending-unavailable",
133-
"list-timeout",
134-
"list-exec-failed",
135-
"list-scope-upgrade-pending",
136-
"list-device-pairing-required",
137-
"list-gateway-connect-failed",
138-
"list-command-failed",
139-
"list-empty-output",
140-
"list-invalid-json",
141-
"list-invalid-output",
142-
"list-missing-pending",
143-
] as const) {
144-
expect(
145-
parseAutoPairApprovalReceipt(`ignored setup output\n${RECEIPT_MARKER}=${receipt}\n`),
146-
).toBe(receipt);
147-
}
122+
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);
148153

149154
expect(parseAutoPairApprovalReceipt(output)).toBeNull();
150155
});

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-
for (const part of (skinWriteCall?.[0] ?? []) as string[]) {
382-
expect(part).not.toMatch(/[\n\r]/);
383-
}
381+
expect(
382+
Array.from((skinWriteCall?.[0] ?? []) as string[], (part) => !/[\n\r]/.test(part)),
383+
).not.toContain(false);
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");

0 commit comments

Comments
 (0)