|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { formatRCAData } from "../../src/tools/rca-agent-utils/format-rca"; |
| 3 | + |
| 4 | +describe("formatRCAData", () => { |
| 5 | + it("returns a no-data message when there are no test cases", () => { |
| 6 | + expect(formatRCAData(null)).toBe("No RCA data available."); |
| 7 | + expect(formatRCAData({ testCases: [] })).toBe("No RCA data available."); |
| 8 | + }); |
| 9 | + |
| 10 | + it("labels a suggested fix as a proposal and appends the approval-gate directive", () => { |
| 11 | + const output = formatRCAData({ |
| 12 | + testCases: [ |
| 13 | + { |
| 14 | + id: 101, |
| 15 | + state: "failed", |
| 16 | + rcaData: { |
| 17 | + rcaData: { |
| 18 | + root_cause: "Selector changed", |
| 19 | + possible_fix: "Update the locator to the new data-testid", |
| 20 | + }, |
| 21 | + }, |
| 22 | + }, |
| 23 | + ], |
| 24 | + }); |
| 25 | + |
| 26 | + // The fix is framed as a proposal, not an instruction to apply. |
| 27 | + expect(output).toContain("Suggested Fix (proposal only"); |
| 28 | + expect(output).toContain("do not apply without explicit user approval"); |
| 29 | + |
| 30 | + // The approval-gate directive must be present so consuming agents do not |
| 31 | + // auto-apply code changes. |
| 32 | + expect(output).toContain("Action required"); |
| 33 | + expect(output).toContain( |
| 34 | + "apply code changes ONLY after the user explicitly approves", |
| 35 | + ); |
| 36 | + expect(output).toContain("Do not modify any files automatically"); |
| 37 | + }); |
| 38 | + |
| 39 | + it("omits the approval-gate directive when no fix is suggested", () => { |
| 40 | + const output = formatRCAData({ |
| 41 | + testCases: [ |
| 42 | + { |
| 43 | + id: 102, |
| 44 | + state: "failed", |
| 45 | + rcaData: { |
| 46 | + rcaData: { |
| 47 | + root_cause: "Network timeout", |
| 48 | + }, |
| 49 | + }, |
| 50 | + }, |
| 51 | + ], |
| 52 | + }); |
| 53 | + |
| 54 | + expect(output).toContain("Network timeout"); |
| 55 | + expect(output).not.toContain("Action required"); |
| 56 | + expect(output).not.toContain("Suggested Fix"); |
| 57 | + }); |
| 58 | +}); |
0 commit comments