2170a0d282
Deletes the last bespoke UI surface (TrackChangesPreviewController + its sealed webview client assets); every entry point re-points at native VS Code chrome per spec §5: the #41 right-click entries become cowriting.openReviewPreview (enter coediting if needed -> "Open Preview to the Side"), Ctrl+Alt+R/Cmd+Alt+R moves to cowriting.reviewChanges (native diff), and the F12 CodeLens per-proposal titles read "Keep"/"Reject" with a top-of-file "Keep all (N)"/"Reject all" pair once >=2 proposals are pending. EditFlow drops its own askClaude/askEditInstruction (the webview's only caller) and its now-unused constructor params. Coverage that lived only in the webview's test seams (renderHtmlFor, receiveMessage, isOpen, ...) moves to direct calls against the surviving controllers/pure renderReview (test/e2e/suite/helpers.ts gains a shared renderHtmlFor probe); a genuine gap (pending-proposal + unchanged-block rendering) is backfilled in test/previewAnnotations.test.ts. README's "how it works" is rewritten as the native-surface map; the superseded F6/F7/F9/ F10/F11 sections are kept as a marked historical record rather than deleted outright. 292 unit + 91 E2E green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
92 lines
4.3 KiB
TypeScript
92 lines
4.3 KiB
TypeScript
import * as assert from "assert";
|
|
import * as fs from "fs";
|
|
import * as path from "path";
|
|
import * as vscode from "vscode";
|
|
import type { CowritingApi } from "../../../src/extension";
|
|
import { undoWorks, UNDO_SKIP_REASON } from "./undoCapable";
|
|
import { renderHtmlFor } from "./helpers";
|
|
|
|
const WS = process.env.E2E_WORKSPACE!;
|
|
const settle = () => new Promise((r) => setTimeout(r, 400));
|
|
|
|
async function getApi(): Promise<CowritingApi> {
|
|
const ext = vscode.extensions.getExtension("benstull.vscode-cowriting-plugin")!;
|
|
const api = (await ext.activate()) as CowritingApi;
|
|
assert.ok(api?.attributionController && api?.proposalController, "exports attribution + proposal");
|
|
return api;
|
|
}
|
|
|
|
/** Also enters coediting (INV-10/Task 2): the baseline is established only on
|
|
* entry, not merely on open — needed for the preview's added/changed marks to
|
|
* reflect a real diff rather than a vacuous baseline==current fallback. */
|
|
async function freshDoc(rel: string, body: string): Promise<{ doc: vscode.TextDocument; key: string }> {
|
|
const abs = path.join(WS, rel);
|
|
fs.mkdirSync(path.dirname(abs), { recursive: true });
|
|
fs.writeFileSync(abs, body, "utf8");
|
|
const uri = vscode.Uri.file(abs);
|
|
const doc = await vscode.workspace.openTextDocument(uri);
|
|
await vscode.window.showTextDocument(doc);
|
|
await vscode.commands.executeCommand("cowriting.coeditDocument");
|
|
await settle();
|
|
return { doc, key: uri.toString() };
|
|
}
|
|
|
|
// #38 (P1): undo in the editor renders WRONG marks in the F10 review preview.
|
|
// Root cause: attribution attributes every non-seam change to the human and
|
|
// ignores e.reason, so an undo that re-inserts text falsely colors it human.
|
|
// We drive a MID-EDIT undo (buffer stays dirty, so the disk-sync guard doesn't
|
|
// mask it) and assert the restored baseline text is NOT re-attributed.
|
|
suite("F10 #38 — undo does not mis-attribute restored text (host E2E, no LLM)", () => {
|
|
const DOC_REL = "docs/undo38.md";
|
|
const BASE = "Alpha bravo charlie.\n";
|
|
|
|
// #54: skip (loudly) where executeCommand("undo") is non-functional; run where it works.
|
|
suiteSetup(async function () {
|
|
if (!(await undoWorks())) {
|
|
console.warn(UNDO_SKIP_REASON);
|
|
this.skip();
|
|
}
|
|
});
|
|
|
|
test("undo of a deletion of baseline text leaves it unattributed (not human)", async () => {
|
|
const { doc, key } = await freshDoc(DOC_REL, BASE);
|
|
const api = await getApi();
|
|
|
|
// Forward edit 1 (human): append a tail so a LATER undo of edit 2 keeps the
|
|
// buffer dirty (≠ disk) → the attribution branch runs, not the disk-sync one.
|
|
const e1 = new vscode.WorkspaceEdit();
|
|
e1.insert(doc.uri, doc.positionAt(doc.getText().length), "\nHuman tail.\n");
|
|
assert.ok(await vscode.workspace.applyEdit(e1), "edit 1 applied");
|
|
await settle();
|
|
|
|
// Forward edit 2 (human): delete the baseline word "bravo " (offsets 6..12).
|
|
const e2 = new vscode.WorkspaceEdit();
|
|
e2.delete(doc.uri, new vscode.Range(doc.positionAt(6), doc.positionAt(12)));
|
|
assert.ok(await vscode.workspace.applyEdit(e2), "edit 2 applied");
|
|
await settle();
|
|
assert.ok(!doc.getText().includes("bravo"), "bravo deleted");
|
|
|
|
// Undo edit 2 → "bravo " is re-inserted. It is RESTORED baseline text, not
|
|
// freshly authored — it must NOT become a human-attributed span.
|
|
await vscode.commands.executeCommand("undo");
|
|
await settle();
|
|
assert.ok(doc.getText().includes("Alpha bravo charlie."), "undo restored 'bravo '");
|
|
assert.ok(doc.isDirty, "buffer still dirty (mid-edit undo → attribution branch, not disk-sync)");
|
|
|
|
const bravoStart = doc.getText().indexOf("bravo");
|
|
const spans = api.attributionController.spansFor(doc);
|
|
const overBravo = spans.filter((s) => s.start < bravoStart + 5 && s.end > bravoStart);
|
|
assert.deepStrictEqual(
|
|
overBravo,
|
|
[],
|
|
`restored baseline text 'bravo' must be unattributed, got spans: ${JSON.stringify(overBravo)}`,
|
|
);
|
|
|
|
// And the on-state render must not color 'bravo' as human-authored.
|
|
// Added blocks use cw-ins-human (not cw-by-human) since Task 3/44ef0a2.
|
|
const html = renderHtmlFor(api, doc, key);
|
|
const bravoColoredHuman = /cw-ins-human[^<]*bravo|<[^>]+class="[^"]*cw-ins-human[^"]*"[^>]*>[^<]*bravo/.test(html);
|
|
assert.ok(!bravoColoredHuman, "restored 'bravo' is not colored cw-ins-human in the preview");
|
|
});
|
|
});
|