F7.1: intra-diagram mermaid diffing (#22) #28

Merged
benstull merged 10 commits from f7.1-intra-diagram-mermaid-diff into main 2026-06-11 23:36:58 +00:00
2 changed files with 35 additions and 0 deletions
Showing only changes of commit 3b45e784c1 - Show all commits
+8
View File
@@ -214,6 +214,14 @@ export class TrackChangesPreviewController implements vscode.Disposable {
getLastModel(uriString: string): BlockOp[] | undefined {
return this.lastModel.get(uriString);
}
/** F7.1 (#22) test seam: the track-changes HTML the panel would post for a doc. */
renderHtmlFor(uriString: string): string {
const doc = vscode.workspace.textDocuments.find((d) => d.uri.toString() === uriString);
if (!doc) return "";
const current = doc.getText();
const baseline = this.diffView.getBaseline(uriString);
return renderTrackChanges(baseline?.text ?? current, current);
}
/** F9: current view mode for a panel (default track-changes). */
getMode(uriString: string): "changes" | "authorship" {
return this.mode.get(uriString) ?? "changes";
@@ -105,4 +105,31 @@ suite("F7 track-changes preview (host E2E — markdown only, programmatic seam,
await settle();
assert.strictEqual(api.trackChangesPreviewController.isOpen(key), false, "no panel for non-markdown");
});
test("a changed flowchart augments the emitted mermaid source (#22, INV-29)", async () => {
const doc = await openDoc();
const api = await getApi();
// Show the preview and pin the baseline so the fixture's `a --> b` flowchart
// is the "before"; then add an edge `a --> c` and confirm the intra-diagram diff.
await vscode.commands.executeCommand("cowriting.showTrackChangesPreview");
await vscode.commands.executeCommand("cowriting.pinDiffBaseline");
await settle();
const anchor = doc.getText().indexOf("a --> b");
assert.ok(anchor >= 0, "fixture contains the flowchart edge");
const insertAt = doc.positionAt(anchor + "a --> b".length);
const edit = new vscode.WorkspaceEdit();
edit.insert(doc.uri, insertAt, "\n a --> c");
assert.ok(await vscode.workspace.applyEdit(edit), "flowchart edit applied");
await settle();
const model = api.trackChangesPreviewController.getLastModel(docUri()) ?? [];
const mermaidOp = model.find((o) => o.kind === "changed" && o.block.type === "mermaid");
assert.ok(mermaidOp, "the flowchart block is a changed mermaid op");
const html = api.trackChangesPreviewController.renderHtmlFor(docUri());
assert.match(html, /classDef cwAdded/, "augmented with cwAdded classDef");
assert.match(html, /class\s+c\s+cwAdded/, "node c colored added");
assert.match(html, /cw-mermaid-legend/, "legend emitted");
});
});