80 lines
3.8 KiB
TypeScript
80 lines
3.8 KiB
TypeScript
import * as assert from "node:assert";
|
|
import MarkdownIt from "markdown-it";
|
|
import * as vscode from "vscode";
|
|
import { cowritingMarkdownItPlugin } from "../../../src/previewAnnotations";
|
|
import { activateApi, settle } from "./helpers";
|
|
|
|
// Task 7 (D3/D21, PUC-3): the built-in preview's DOM isn't queryable from a
|
|
// host E2E test (§6.8), so this asserts the pure transform's INPUTS/OUTPUTS
|
|
// through the real `CowritingApi` seams instead — the production
|
|
// `previewAnnotationHost.inputsFor` (not a hand-rolled reimplementation) fed
|
|
// through the real `cowritingMarkdownItPlugin` + a fresh markdown-it instance
|
|
// (mirroring the unit suite's own `render()` helper), so this exercises the
|
|
// ACTUAL registry/diffView/attribution/proposals/config wiring end to end.
|
|
suite("PUC-3 annotate-toggle (built-in Markdown preview annotations)", () => {
|
|
test("a machine-attributed change renders cw-ins-claude; disabling the setting passes the source through unchanged", async () => {
|
|
const api = await activateApi();
|
|
const doc = await vscode.workspace.openTextDocument({
|
|
language: "markdown",
|
|
content: "hello world\n",
|
|
});
|
|
await vscode.window.showTextDocument(doc);
|
|
await vscode.commands.executeCommand("cowriting.coeditDocument");
|
|
await settle();
|
|
|
|
const start = doc.getText().indexOf("world");
|
|
const ok = await vscode.commands.executeCommand<boolean>("cowriting.applyAgentEdit", {
|
|
uri: doc.uri.toString(),
|
|
start,
|
|
end: start + "world".length,
|
|
newText: "brave new world",
|
|
model: "sonnet",
|
|
sessionId: "e2e-preview-annotations",
|
|
turnId: "turn-e2e-preview-annotations",
|
|
});
|
|
assert.strictEqual(ok, true, "seam edit applies");
|
|
await settle();
|
|
|
|
// Annotations ON (default): render the CURRENT buffer through the real
|
|
// markdown-it plugin + the production host — proves the full pipeline
|
|
// (core-rule swap → full-render sentinel walk) reaches a live doc.
|
|
const md = new MarkdownIt();
|
|
cowritingMarkdownItPlugin(md, api.previewAnnotationHost);
|
|
const html = md.render(doc.getText());
|
|
assert.ok(html.includes("cw-ins-claude"), `expected cw-ins-claude in:\n${html}`);
|
|
|
|
// Toggle OFF: the config-gated `enabled` flag reaches `annotateSource` and
|
|
// the transform becomes the identity (no core-rule swap, no marks).
|
|
const config = vscode.workspace.getConfiguration("cowriting");
|
|
await config.update("annotations", false, vscode.ConfigurationTarget.Global);
|
|
try {
|
|
const inputs = api.previewAnnotationHost.inputsFor(undefined);
|
|
assert.ok(inputs, "inputsFor still resolves a coedited doc while disabled");
|
|
assert.strictEqual(inputs!.enabled, false);
|
|
const md2 = new MarkdownIt();
|
|
cowritingMarkdownItPlugin(md2, api.previewAnnotationHost);
|
|
const plainMd = new MarkdownIt();
|
|
assert.strictEqual(md2.render(doc.getText()), plainMd.render(doc.getText()));
|
|
} finally {
|
|
await config.update("annotations", true, vscode.ConfigurationTarget.Global);
|
|
}
|
|
});
|
|
|
|
test("cowriting.toggleAnnotations flips the setting", async () => {
|
|
const api = await activateApi();
|
|
const doc = await vscode.workspace.openTextDocument({ language: "markdown", content: "toggle me\n" });
|
|
await vscode.window.showTextDocument(doc);
|
|
await vscode.commands.executeCommand("cowriting.coeditDocument");
|
|
await settle();
|
|
|
|
const config = () => vscode.workspace.getConfiguration("cowriting");
|
|
const before = config().get<boolean>("annotations", true);
|
|
await vscode.commands.executeCommand("cowriting.toggleAnnotations");
|
|
assert.strictEqual(config().get<boolean>("annotations", true), !before);
|
|
// restore
|
|
await vscode.commands.executeCommand("cowriting.toggleAnnotations");
|
|
assert.strictEqual(config().get<boolean>("annotations", true), before);
|
|
void api; // keep the activated extension alive for the duration of the test
|
|
});
|
|
});
|