a323b827a8
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
59 lines
3.2 KiB
TypeScript
59 lines
3.2 KiB
TypeScript
import * as assert from "node:assert";
|
|
import * as vscode from "vscode";
|
|
import { activateApi, settle } from "./helpers";
|
|
|
|
async function api() {
|
|
const ext = vscode.extensions.getExtension("benstull.vscode-cowriting-plugin")!;
|
|
return (await ext.activate()) as import("../../../src/extension").CowritingApi;
|
|
}
|
|
|
|
suite("coediting registry (PUC-7)", () => {
|
|
test("enter → isCoediting true; exit → false; persists in list()", async () => {
|
|
const { coeditingRegistry } = await api();
|
|
const doc = await vscode.workspace.openTextDocument({ language: "markdown", content: "# t\n\nbody\n" });
|
|
await vscode.window.showTextDocument(doc);
|
|
await vscode.commands.executeCommand("cowriting.coeditDocument");
|
|
assert.strictEqual(coeditingRegistry.isCoediting(doc.uri), true);
|
|
assert.ok(coeditingRegistry.list().includes(doc.uri.toString()));
|
|
await vscode.commands.executeCommand("cowriting.stopCoediting");
|
|
assert.strictEqual(coeditingRegistry.isCoediting(doc.uri), false);
|
|
});
|
|
|
|
// Task 3 (INV-10): a document that was never entered into coediting gets no
|
|
// native-diff surface at all. QuickDiff's `provideOriginalResource` isn't
|
|
// directly queryable from a host-E2E test, so this asserts the gate INPUTS
|
|
// structurally: `isCoediting` stays false and the SCM change count — which
|
|
// `ScmSurfaceController` only ever populates for a coediting doc — stays 0.
|
|
test("non-entered doc: no coediting, no change count (structural, INV-10)", async () => {
|
|
const api = await activateApi();
|
|
const doc = await vscode.workspace.openTextDocument({ language: "markdown", content: "untouched\n" });
|
|
await vscode.window.showTextDocument(doc);
|
|
await settle();
|
|
assert.strictEqual(api.coeditingRegistry.isCoediting(doc.uri), false);
|
|
assert.strictEqual(api.scmSurfaceController.changeCount(doc.uri.toString()), 0);
|
|
});
|
|
|
|
// Task 4 (INV-10, PUC-7): the no-hijack scenario — a non-entered doc gets no
|
|
// thread-creation surface at all; entering unlocks it; exiting hides the
|
|
// rendered thread (not the sidecar-backed data); re-entering restores it.
|
|
test("non-entered doc gets no surfaces; exit detaches; re-enter restores threads", async () => {
|
|
const api = await activateApi();
|
|
const doc = await vscode.workspace.openTextDocument({ language: "markdown", content: "# a\n\npara\n" });
|
|
const ed = await vscode.window.showTextDocument(doc);
|
|
// not entered → no thread creation
|
|
ed.selection = new vscode.Selection(2, 0, 2, 4);
|
|
const before = await api.threadController.createThreadOnSelection("hi");
|
|
assert.strictEqual(before, undefined);
|
|
// entered → works
|
|
await vscode.commands.executeCommand("cowriting.coeditDocument");
|
|
const id = await api.threadController.createThreadOnSelection("hi");
|
|
assert.ok(id);
|
|
// exit → rendered thread set empty; re-enter → restored from sidecar
|
|
await vscode.commands.executeCommand("cowriting.stopCoediting");
|
|
assert.strictEqual(api.threadController.getRendered(api.proposalController.keyFor(doc)).length, 0);
|
|
await vscode.commands.executeCommand("cowriting.coeditDocument");
|
|
await settle();
|
|
assert.strictEqual(api.threadController.getRendered(api.proposalController.keyFor(doc)).length, 1);
|
|
});
|
|
});
|