F3 SLICE-4: persistence/re-anchor/orphan decision-logic tests (INV-1/INV-6) (#6)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ben Stull
2026-06-10 10:01:49 -07:00
parent d05cb0f9d4
commit 4b27acfcae
2 changed files with 80 additions and 0 deletions
+26
View File
@@ -125,3 +125,29 @@ describe("coalesce", () => {
expect(coalesce([span("a", 5, 5, HUMAN)])).toEqual([]);
});
});
describe("edge probes (post-review)", () => {
it("applyChange does not mutate its input array or spans", () => {
const input = [span("a", 0, 10, AGENT)];
const snapshot = JSON.parse(JSON.stringify(input));
applyChange(input, { start: 2, end: 4, newLength: 1 }, HUMAN, ctx());
expect(input).toEqual(snapshot);
});
it("an edit swallowing a whole middle span across three spans removes only it", () => {
// Deletion [3,9): a → [0,3); b swallowed; c's remainder [9,12) shifts -6 to
// [3,6). The two surviving HUMAN spans are adjacent at 3 with the same
// (undefined) turnId, so coalesce merges them into ONE span — only the
// agent-authored middle span's characters are gone (INV-6/INV-7).
const r = applyChange(
[span("a", 0, 4, HUMAN), span("b", 4, 8, AGENT), span("c", 8, 12, HUMAN)],
{ start: 3, end: 9, newLength: 0 }, HUMAN, ctx(),
);
expect(ranges(r)).toEqual([[0, 6]]);
expect(authors(r)).toEqual(["human"]);
});
it("a replacement exactly covering a span replaces it with the editor's span", () => {
const r = applyChange([span("a", 4, 8, AGENT)], { start: 4, end: 8, newLength: 4 }, HUMAN, ctx());
expect(ranges(r)).toEqual([[4, 8]]);
expect(authors(r)).toEqual(["human"]);
});
});