Skip to content

Commit 5b1d2f2

Browse files
committed
test: parameterize more loop-generated cases
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
1 parent 3707b8e commit 5b1d2f2

7 files changed

Lines changed: 65 additions & 52 deletions

test/channels-remove-full-teardown.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,9 @@ module.exports = {
201201
}
202202

203203
describe("channels remove full teardown (#3998)", () => {
204-
for (const sandboxAgent of ["openclaw", "hermes"] as const) {
205-
it(`strips '${sandboxAgent}' session.policyPresets and clears the in-sandbox whatsapp state dir`, () => {
204+
it.each(["openclaw", "hermes"] as const)(
205+
"strips '%s' session.policyPresets and clears the in-sandbox whatsapp state dir",
206+
(sandboxAgent) => {
206207
const script = `${buildPreamble({ sandboxAgent })}
207208
const ctx = module.exports;
208209
(async () => {
@@ -285,8 +286,8 @@ const ctx = module.exports;
285286
clearIdx < rebuildIdx,
286287
`sandbox state must be cleared before rebuild so the backup excludes the auth files: ${JSON.stringify(payload.callOrder)}`,
287288
);
288-
});
289-
}
289+
},
290+
);
290291

291292
it("falls back to SSH when sandbox-exec wrapper does not return the sentinel", () => {
292293
const script = `${buildPreamble({

test/cli/logs-documented-invocations.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,14 @@ describe("documented sandbox logs invocations", () => {
6868
expect(invocations.length).toBeGreaterThanOrEqual(5);
6969
});
7070

71-
for (const { args, reference } of invocations) {
72-
it(`runs the invocation documented at ${reference}`, ({ resources }) => {
71+
it.for(invocations.map(({ args, reference }) => [reference, args] as const))(
72+
"runs the invocation documented at %s",
73+
([, args], { resources }) => {
7374
const setup = createLogsTestSetup(resources, "nemoclaw-cli-logs-documented-");
7475
const result = setup.runLogs(`${args} 2>&1`);
7576

7677
expect(result.out).not.toContain("Nonexistent flag");
7778
expect(result.code).toBe(0);
78-
});
79-
}
79+
},
80+
);
8081
});

test/hermes-restart-config-seal-hostile-input.test.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import {
1515
} from "./helpers/hermes-restart-config-seal-fixture";
1616

1717
describe.skipIf(process.platform === "win32")("Hermes mutable restart input seal", () => {
18-
for (const oversizedName of ["config.yaml", ".env"] as const) {
19-
it(`contains an oversized sparse ${oversizedName} without reading its logical payload`, () => {
18+
it.each(["config.yaml", ".env"] as const)(
19+
"contains an oversized sparse %s without reading its logical payload",
20+
(oversizedName) => {
2021
const fixture = createRestartFixture();
2122
const oversizedPath = oversizedName === "config.yaml" ? fixture.configPath : fixture.envPath;
2223
fs.truncateSync(
@@ -41,8 +42,8 @@ describe.skipIf(process.platform === "win32")("Hermes mutable restart input seal
4142
fs.chmodSync(fixture.hermesDir, 0o700);
4243
fs.rmSync(fixture.root, { recursive: true, force: true });
4344
}
44-
});
45-
}
45+
},
46+
);
4647

4748
it("fresh-seals a hardlinked input and revokes the external writable inode", () => {
4849
const fixture = createRestartFixture();
@@ -82,8 +83,9 @@ describe.skipIf(process.platform === "win32")("Hermes mutable restart input seal
8283
}
8384
});
8485

85-
for (const hostileKind of ["symlink", "fifo"] as const) {
86-
it(`seals a hostile ${hostileKind} config entry into a root-only unavailable posture`, () => {
86+
it.each(["symlink", "fifo"] as const)(
87+
"seals a hostile %s config entry into a root-only unavailable posture",
88+
(hostileKind) => {
8789
const fixture = createRestartFixture();
8890
fs.unlinkSync(fixture.configPath);
8991
const arrangeHostileConfig = {
@@ -119,11 +121,12 @@ describe.skipIf(process.platform === "win32")("Hermes mutable restart input seal
119121
fs.chmodSync(fixture.hermesDir, 0o700);
120122
fs.rmSync(fixture.root, { recursive: true, force: true });
121123
}
122-
});
123-
}
124+
},
125+
);
124126

125-
for (const hostileKind of ["symlink", "fifo"] as const) {
126-
it(`quarantines an outer .hermes ${hostileKind} only after freezing /sandbox`, () => {
127+
it.each(["symlink", "fifo"] as const)(
128+
"quarantines an outer .hermes %s only after freezing /sandbox",
129+
(hostileKind) => {
127130
const fixture = createRestartFixture();
128131
fs.rmSync(fixture.hermesDir, { recursive: true, force: true });
129132
const victim = path.join(fixture.root, "outer-victim");
@@ -154,8 +157,8 @@ describe.skipIf(process.platform === "win32")("Hermes mutable restart input seal
154157
fs.chmodSync(fixture.hermesDir, 0o700);
155158
fs.rmSync(fixture.root, { recursive: true, force: true });
156159
}
157-
});
158-
}
160+
},
161+
);
159162

160163
it("re-seals an applied mutable transition before recursive rollback", () => {
161164
const fixture = createRestartFixture();

test/mcp-provider-ownership.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ bridge.removeMcpBridge("alpha", "fake").then(
214214
}
215215

216216
describe("MCP provider ownership", () => {
217-
for (const boundary of ["detach", "delete"] as const) {
218-
it(`rechecks stable identity immediately before provider ${boundary}`, () => {
217+
it.each(["detach", "delete"] as const)(
218+
"rechecks stable identity immediately before provider %s",
219+
(boundary) => {
219220
const result = runRemoveIdentityRace(boundary);
220221

221222
expect(result.status, `${result.stdout}\\n${result.stderr}`).toBe(0);
@@ -234,8 +235,8 @@ describe("MCP provider ownership", () => {
234235
),
235236
).toBe(boundary === "delete");
236237
expect(payload.bridgePresent).toBe(true);
237-
});
238-
}
238+
},
239+
);
239240

240241
it("removes an exact legacy provider whose credential name is now reserved", () => {
241242
const result = runLegacyReservedCredentialCleanup();

test/onboard-preset-diff.test.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,11 @@ describe("setupPoliciesWithSelection preset diff (#2177)", () => {
365365
// channel→preset registry iteration as Discord/Telegram, so each apply/remove
366366
// case guards the egress-policy application for every shipped channel — not
367367
// only the two already covered above (#5967).
368-
for (const channel of ["teams", "whatsapp", "wechat"]) {
369-
it(`resume selection applies the ${channel} policy required by a configured ${channel} channel (#5967)`, async () => {
368+
const optionalChannelPresets = ["teams", "whatsapp", "wechat"].map((channel) => ({ channel }));
369+
370+
it.each(optionalChannelPresets)(
371+
"resume selection applies the $channel policy required by a configured $channel channel (#5967)",
372+
async ({ channel }) => {
370373
const payload = await runPolicyScenario({
371374
policyMode: "suggested",
372375
policyPresets: "",
@@ -380,9 +383,12 @@ describe("setupPoliciesWithSelection preset diff (#2177)", () => {
380383
`${channel} must be applied to the gateway when the channel is enabled; got applied ${JSON.stringify(payload.appliedCalls)}`,
381384
);
382385
assert.deepEqual(payload.finalApplied.slice().sort(), ["npm", "pypi", channel].sort());
383-
});
386+
},
387+
);
384388

385-
it(`custom non-interactive selection removes disabled ${channel} while honoring the explicit preset list (#5967)`, async () => {
389+
it.each(optionalChannelPresets)(
390+
"custom non-interactive selection removes disabled $channel while honoring the explicit preset list (#5967)",
391+
async ({ channel }) => {
386392
const payload = await runPolicyScenario({
387393
policyMode: "custom",
388394
policyPresets: "npm",
@@ -393,8 +399,8 @@ describe("setupPoliciesWithSelection preset diff (#2177)", () => {
393399
assert.deepEqual(payload.chosen, ["npm"]);
394400
assert.deepEqual(payload.removedCalls.slice().sort(), ["pypi", channel].sort());
395401
assert.deepEqual(payload.finalApplied, ["npm"]);
396-
});
397-
}
402+
},
403+
);
398404

399405
it("custom non-interactive selection removes disabled Slack while honoring the explicit preset list", async () => {
400406
const payload = await runPolicyScenario({

test/onboard-selection.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,12 +2851,12 @@ reportChildScenario(async () => {
28512851

28522852
const secretCredentialBackScenarios = PROCESS_CREDENTIAL_BACK_SCENARIOS.slice(1, -1);
28532853

2854-
for (const scenario of secretCredentialBackScenarios) {
2855-
const action = scenario.expectedOutcome === "exit" ? "exit" : "back";
2856-
it(`lets users type ${action} at the ${scenario.name} secret credential prompt`, () => {
2857-
runCredentialBackScenarioProcess(scenario);
2858-
});
2859-
}
2854+
it.each(secretCredentialBackScenarios.map((scenario) => ({
2855+
...scenario,
2856+
action: scenario.expectedOutcome === "exit" ? "exit" : "back",
2857+
})))("lets users type $action at the $name secret credential prompt", (scenario) => {
2858+
runCredentialBackScenarioProcess(scenario);
2859+
});
28602860

28612861
it("lets users type back at the Local NIM NGC API key secret credential prompt", () => {
28622862
runCredentialBackScenarioProcess(PROCESS_CREDENTIAL_BACK_SCENARIOS.at(-1)!);

test/sandbox-init.test.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -760,35 +760,36 @@ EOF
760760
});
761761

762762
describe("entrypoints call harden_resource_limits", () => {
763+
const entrypoints = ["../scripts/nemoclaw-start.sh", "../agents/hermes/start.sh"];
764+
763765
// Both entrypoints must delegate RLIMIT hardening to the shared helper and
764766
// must no longer carry the pre-#4527 raw inline `ulimit -Su 512` block.
765-
for (const rel of ["../scripts/nemoclaw-start.sh", "../agents/hermes/start.sh"]) {
766-
it(`${rel} calls harden_resource_limits and has no raw inline nproc block`, () => {
767+
it.each(entrypoints)(
768+
"%s calls harden_resource_limits and has no raw inline nproc block",
769+
(rel) => {
767770
const src = readFileSync(join(import.meta.dirname, rel), "utf-8");
768771
expect(src).toContain("harden_resource_limits");
769772
expect(src).not.toContain("ulimit -Su 512");
770773
expect(src).not.toContain("ulimit -Hu 512");
771-
});
772-
}
774+
},
775+
);
773776

774777
// SECURITY (#4527): the RLIMIT caps are only unraisable if they are set
775778
// while still root PID 1, BEFORE drop_capabilities (capsh) and the
776779
// setpriv step-down. A refactor that moved the harden call after the
777780
// privilege drop would turn it into dead code (cap set as the unprivileged
778781
// agent, hard limit no longer lowered) while every other test stayed green.
779782
// Pin the ordering so that regression is caught.
780-
for (const rel of ["../scripts/nemoclaw-start.sh", "../agents/hermes/start.sh"]) {
781-
it(`${rel} calls harden_resource_limits before drop_capabilities`, () => {
782-
const src = readFileSync(join(import.meta.dirname, rel), "utf-8");
783-
// Anchor to executable command lines, not free-text, so a comment
784-
// mentioning either name cannot satisfy (or break) the ordering check.
785-
const hardenIdx = src.match(/^\s*harden_resource_limits\s*$/m)?.index ?? -1;
786-
const dropIdx = src.match(/^\s*drop_capabilities\b.*$/m)?.index ?? -1;
787-
expect(hardenIdx).toBeGreaterThanOrEqual(0);
788-
expect(dropIdx).toBeGreaterThanOrEqual(0);
789-
expect(hardenIdx).toBeLessThan(dropIdx);
790-
});
791-
}
783+
it.each(entrypoints)("%s calls harden_resource_limits before drop_capabilities", (rel) => {
784+
const src = readFileSync(join(import.meta.dirname, rel), "utf-8");
785+
// Anchor to executable command lines, not free-text, so a comment
786+
// mentioning either name cannot satisfy (or break) the ordering check.
787+
const hardenIdx = src.match(/^\s*harden_resource_limits\s*$/m)?.index ?? -1;
788+
const dropIdx = src.match(/^\s*drop_capabilities\b.*$/m)?.index ?? -1;
789+
expect(hardenIdx).toBeGreaterThanOrEqual(0);
790+
expect(dropIdx).toBeGreaterThanOrEqual(0);
791+
expect(hardenIdx).toBeLessThan(dropIdx);
792+
});
792793
});
793794

794795
describe("init_step_down_prefixes", () => {

0 commit comments

Comments
 (0)