From 42879ca145d33ebd0acca7da369b4dee0850d053 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 11 May 2026 07:38:45 +0100 Subject: [PATCH] test: tighten command analysis summary assertions --- src/infra/command-analysis/explain.test.ts | 62 +++++++++------------- 1 file changed, 25 insertions(+), 37 deletions(-) diff --git a/src/infra/command-analysis/explain.test.ts b/src/infra/command-analysis/explain.test.ts index b43658240a1..2e57edea266 100644 --- a/src/infra/command-analysis/explain.test.ts +++ b/src/infra/command-analysis/explain.test.ts @@ -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",