import { describe, expect, it } from "vitest"; import { buildAgentFormat } from "./agent-format.js"; import { agentFormatSchema, type Finding } from "./schemas/index.js"; const DEAD_TOOL_NAMES = ["apply_fix", "swap_to_canonical", "tokens.suggest"]; function finding(overrides: Partial = {}): Finding { return { ruleId: "styles/no-raw-color", ruleVersion: "1.0.0", severity: "serious", level: "error", code: "FUI2001", message: "Use a token.", fingerprint: "fp_1", location: { file: "src/Button.tsx", line: 1, column: 1 }, evidence: [ { factId: "fact_1", fact: { kind: "style", location: { file: "src/Button.tsx", line: 1, column: 1 }, }, }, ], ...overrides, }; } describe("buildAgentFormat", () => { it("names only hosted MCP tools in fix plans", () => { const agentFormat = buildAgentFormat({ filesScanned: 1, findings: [ finding({ fix: { kind: "replaceStyleValue", title: "Use token", property: "color", value: "var(--color-brand)", deterministic: true, }, }), finding({ ruleId: "components/prefer-library", code: "FUI1001", fingerprint: "fp_2", }), finding({ code: "FUI2002", fingerprint: "fp_3", attributes: { property: "color", rawValue: "#2563eb" }, }), ], }); agentFormatSchema.parse(agentFormat); const toolNames = [...agentFormat.fix_first, ...agentFormat.remaining].map( (entry) => entry.plan.tool ); expect(new Set(toolNames)).toEqual(new Set(["design_system/conform"])); for (const deadName of DEAD_TOOL_NAMES) { expect(toolNames).not.toContain(deadName); } }); it("keeps warn-only scans passed when the report summary passed", () => { const agentFormat = buildAgentFormat({ filesScanned: 1, passed: true, findings: [ finding({ severity: "moderate", level: "warn", }), ], }); expect(agentFormat.passed).toBe(true); }); it("omits full findings and evidence by default", () => { const agentFormat = buildAgentFormat({ filesScanned: 1, findings: [finding()], }); expect(agentFormat.findings).toBeUndefined(); expect([...agentFormat.fix_first, ...agentFormat.remaining][0]?.evidence).toEqual([]); }); it("keeps a gradient score for noisy scans", () => { const findings = Array.from({ length: 80 }, (_, index) => finding({ fingerprint: `fp_${index}`, severity: "moderate", level: "warn", }) ); expect(buildAgentFormat({ filesScanned: 3, findings }).score).toBeGreaterThan(0); }); });