test: tighten command analysis summary assertions

This commit is contained in:
Peter Steinberger
2026-05-11 07:38:45 +01:00
parent 5dfcc9dd5e
commit 42879ca145

View File

@@ -13,22 +13,18 @@ describe("command-analysis explanation summary", () => {
const summary = summarizeCommandExplanation(explanation);
expect(summary.commandCount).toBe(1);
expect(summary.riskKinds).toContain("shell-wrapper");
expect(summary.riskKinds).toContain("inline-eval");
expect(summary.warningLines).toEqual(
expect.arrayContaining([expect.stringContaining("inline-eval")]),
);
expect(summary.riskKinds).toEqual(["shell-wrapper", "inline-eval"]);
expect(summary.warningLines).toEqual([
"Contains shell-wrapper: bash -lc",
"Contains inline-eval: python3 -c",
]);
});
it("loads the rich command explainer for rich display summaries", async () => {
const result = await explainCommandForDisplay(`bash -lc 'python3 -c "print(1)"'`);
expect(result?.summary).toEqual(
expect.objectContaining({
commandCount: 1,
riskKinds: expect.arrayContaining(["shell-wrapper", "inline-eval"]),
}),
);
expect(result?.summary.commandCount).toBe(1);
expect(result?.summary.riskKinds).toEqual(["shell-wrapper", "inline-eval"]);
});
it("summarizes policy command segments without async parsing", () => {
@@ -46,19 +42,15 @@ describe("command-analysis explanation summary", () => {
});
it("resolves node display summaries from argv", () => {
expect(
resolveCommandAnalysisSummaryForDisplay({
host: "node",
commandText: "python3 script.py",
commandArgv: ["python3", "-c", "print(1)"],
}),
).toEqual(
expect.objectContaining({
commandCount: 1,
riskKinds: ["inline-eval"],
warningLines: ["Contains inline-eval: python3 -c"],
}),
);
const summary = resolveCommandAnalysisSummaryForDisplay({
host: "node",
commandText: "python3 script.py",
commandArgv: ["python3", "-c", "print(1)"],
});
expect(summary?.commandCount).toBe(1);
expect(summary?.riskKinds).toEqual(["inline-eval"]);
expect(summary?.warningLines).toEqual(["Contains inline-eval: python3 -c"]);
expect(
resolveCommandAnalysisSummaryForDisplay({
host: "node",
@@ -68,19 +60,15 @@ describe("command-analysis explanation summary", () => {
});
it("resolves gateway display summaries from shell text even when argv is stale", () => {
expect(
resolveCommandAnalysisSummaryForDisplay({
host: "gateway",
commandText: "python3 -c 'print(1)'",
commandArgv: ["python3", "script.py"],
}),
).toEqual(
expect.objectContaining({
commandCount: 1,
riskKinds: ["inline-eval"],
warningLines: ["Contains inline-eval: python3 -c"],
}),
);
const summary = resolveCommandAnalysisSummaryForDisplay({
host: "gateway",
commandText: "python3 -c 'print(1)'",
commandArgv: ["python3", "script.py"],
});
expect(summary?.commandCount).toBe(1);
expect(summary?.riskKinds).toEqual(["inline-eval"]);
expect(summary?.warningLines).toEqual(["Contains inline-eval: python3 -c"]);
expect(
resolveCommandAnalysisSummaryForDisplay({
host: "gateway",