F2: region-anchored threads on @cline/sdk (Feature #4) #5

Merged
benstull merged 7 commits from feat/f2-region-anchored-threads into main 2026-06-10 14:01:18 +00:00
Showing only changes of commit 2a9c198859 - Show all commits
+28
View File
@@ -0,0 +1,28 @@
import { describe, it, expect } from "vitest";
import { buildFingerprint, resolve } from "../src/anchorer";
const ORIGINAL = "intro\nThe quick brown fox\noutro\n";
describe("re-anchor scenarios (SLICE-4 decision logic)", () => {
it("reload, document unchanged: resolves to the same range", () => {
const start = ORIGINAL.indexOf("quick brown");
const fp = buildFingerprint(ORIGINAL, { start, end: start + "quick brown".length });
expect(resolve(ORIGINAL, fp)).toEqual({ start, end: start + "quick brown".length });
});
it("external edit that moves the anchored text down: re-resolves to the new range", () => {
const start = ORIGINAL.indexOf("quick brown");
const fp = buildFingerprint(ORIGINAL, { start, end: start + "quick brown".length });
const edited = "a new first line\nanother line\n" + ORIGINAL;
const newStart = edited.indexOf("quick brown");
expect(newStart).not.toBe(start);
expect(resolve(edited, fp)).toEqual({ start: newStart, end: newStart + "quick brown".length });
});
it("external edit that deletes the anchored text: orphaned, never moved (INV-1)", () => {
const start = ORIGINAL.indexOf("quick brown");
const fp = buildFingerprint(ORIGINAL, { start, end: start + "quick brown".length });
const edited = "intro\nThe lazy dog\noutro\n";
expect(resolve(edited, fp)).toBe("orphaned");
});
});