Files
openclaw/src/infra/command-analysis/explain.test.ts
Peter Steinberger d1684f48a3 refactor: delete dead infra and config exports (#106019)
* refactor: delete dead infra and config exports

* refactor: preserve live infra and config contracts

* refactor(config): remove obsolete file-store lifecycle APIs

* refactor(infra): finish current-main dead export cleanup
2026-07-13 12:00:47 -07:00

55 lines
1.9 KiB
TypeScript

// Covers command-analysis summary formatting for parsed shell explanations and
// policy-only argv/shell segment analysis.
import { describe, expect, it } from "vitest";
import { resolveCommandAnalysisSummaryForDisplay } from "./explain.js";
describe("command-analysis explanation summary", () => {
it("resolves node display summaries from argv", async () => {
const summary = await 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(
await resolveCommandAnalysisSummaryForDisplay({
host: "node",
commandText: "python3 -c 'print(1)'",
}),
).toBeNull();
});
it("resolves gateway display summaries from shell text even when argv is stale", async () => {
const summary = await 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(
(
await resolveCommandAnalysisSummaryForDisplay({
host: "gateway",
commandText: "echo ok",
commandArgv: ["python3", "-c", "print(1)"],
})
)?.riskKinds,
).toStrictEqual([]);
expect(
(
await resolveCommandAnalysisSummaryForDisplay({
host: "gateway",
commandText: "python3 -c 'print(1)'",
sanitizeText: (value) => value.replaceAll("python3", "python"),
})
)?.warningLines,
).toEqual(["Contains inline-eval: python -c"]);
});
});