From 3b45e784c1db2b79c19be35e9687c8ab4b5254e5 Mon Sep 17 00:00:00 2001 From: Ben Stull Date: Thu, 11 Jun 2026 16:34:42 -0700 Subject: [PATCH] =?UTF-8?q?test(f7.1):=20host=20E2E=20=E2=80=94=20changed?= =?UTF-8?q?=20flowchart=20augments=20emitted=20source=20(#22)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a renderHtmlFor test seam to TrackChangesPreviewController. Co-Authored-By: Claude Opus 4.8 --- src/trackChangesPreview.ts | 8 +++++++ test/e2e/suite/trackChangesPreview.test.ts | 27 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/trackChangesPreview.ts b/src/trackChangesPreview.ts index e4fd7ba..c8b2763 100644 --- a/src/trackChangesPreview.ts +++ b/src/trackChangesPreview.ts @@ -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"; diff --git a/test/e2e/suite/trackChangesPreview.test.ts b/test/e2e/suite/trackChangesPreview.test.ts index 6b1c1c2..3d6cf95 100644 --- a/test/e2e/suite/trackChangesPreview.test.ts +++ b/test/e2e/suite/trackChangesPreview.test.ts @@ -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"); + }); });