Skip to content

Commit 031f80c

Browse files
committed
test(pdf-server): document computeDiff same-id modification behavior
Two new tests: - User-added annotation modification: captured in diff.added (id not in baseline, so latest content persists correctly). - Baseline annotation in-place modification: KNOWN LIMITATION. Same-id edit produces empty diff (id-set based), so the change vanishes on reload. Viewer's addAnnotation() works around via remove+add, but updateAnnotation() (interact tool's update_annotations) does not.
1 parent 5fbed04 commit 031f80c

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

examples/pdf-server/src/pdf-annotations.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,45 @@ describe("computeDiff", () => {
269269
expect(diff.added).toEqual([]);
270270
});
271271

272+
it("captures modification of a USER-ADDED annotation (id not in baseline)", () => {
273+
// User adds a stamp, then edits its label. The stamp's id was never
274+
// in the baseline → it stays in `added` with its latest content.
275+
const editedStamp: PdfAnnotationDef = {
276+
type: "stamp",
277+
id: "user-s1",
278+
page: 1,
279+
x: 300,
280+
y: 400,
281+
label: "FINAL", // was "DRAFT" originally, now edited
282+
};
283+
const diff = computeDiff([pdfNote], [pdfNote, editedStamp], new Map());
284+
expect(diff.added).toEqual([editedStamp]);
285+
expect(diff.added[0]).toMatchObject({ label: "FINAL" });
286+
});
287+
288+
it("KNOWN LIMITATION: in-place edit of a baseline annotation is lost", () => {
289+
// Editing a PDF-native note's content: same id as baseline, different
290+
// content. computeDiff is id-set based — same-id → neither added nor
291+
// removed. The edit vanishes on reload.
292+
//
293+
// Viewer mitigation: addAnnotation() always removeAnnotation(id) first,
294+
// so the common UI path is remove+add. But updateAnnotation() mutates
295+
// in place — if the interact tool's update_annotations edits a baseline
296+
// annotation, that edit won't survive a page reload.
297+
const editedNote: PdfAnnotationDef = {
298+
...pdfNote,
299+
content: "Edited by user",
300+
};
301+
const diff = computeDiff(
302+
[pdfNote, pdfHighlight],
303+
[editedNote, pdfHighlight],
304+
new Map(),
305+
);
306+
expect(diff.added).toEqual([]);
307+
expect(diff.removed).toEqual([]);
308+
// If this starts FAILING, the limitation was fixed — update expectations.
309+
});
310+
272311
it("captures form field values", () => {
273312
const fields = new Map<string, string | boolean>([
274313
["name", "Alice"],

0 commit comments

Comments
 (0)