feat(f7.1): mermaid diff dispatcher + type detection (#22)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Ben Stull
2026-06-11 16:29:36 -07:00
parent c117552ea1
commit d8ce4f12e1
4 changed files with 86 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import { describe, it, expect } from "vitest";
import { detectDiagramType, diffMermaid } from "../src/mermaidDiff";
describe("detectDiagramType", () => {
it("detects flowchart from `flowchart` / `graph` headers", () => {
expect(detectDiagramType("flowchart LR\n a-->b")).toBe("flowchart");
expect(detectDiagramType("graph TD\n a-->b")).toBe("flowchart");
expect(detectDiagramType(" \n%% c\ngraph TD")).toBe("flowchart");
});
it("detects sequence from `sequenceDiagram`", () => {
expect(detectDiagramType("sequenceDiagram\n A->>B: hi")).toBe("sequence");
});
it("returns `other` for unsupported types", () => {
expect(detectDiagramType("classDiagram\n class A")).toBe("other");
expect(detectDiagramType("stateDiagram-v2\n s1 --> s2")).toBe("other");
expect(detectDiagramType("")).toBe("other");
});
});
describe("diffMermaid", () => {
it("falls back for an unsupported diagram type", () => {
expect(diffMermaid("classDiagram\n class A", "classDiagram\n class B")).toEqual({ kind: "fallback" });
});
it("falls back (never throws) when the differ throws", () => {
// A deliberately malformed flowchart still degrades gracefully.
const r = diffMermaid("flowchart LR", "flowchart LR\n a -->");
expect(["augmented", "fallback"]).toContain(r.kind);
});
});