test(docx-core): characterize collision/salt-loop in insertParagraphBookmarks (closes #282)#284
test(docx-core): characterize collision/salt-loop in insertParagraphBookmarks (closes #282)#284stevenobiajulu wants to merge 2 commits into
Conversation
…ookmarks `buildParagraphSeed` combines paragraph text with the immediate prev/next neighbor text and ancestor signature. When two paragraphs sit at positions where both the text and the prev/next neighbors are identical, the seed collides; `deriveDeterministicJrParaName` resolves this with a 10,000-step salt-loop (first hit unsalted, subsequent hits get `|salt:N`). This load-bearing behavior had no characterization test. The two added scenarios: 1. Build a fixture with two paragraphs at positions 1 and 4 that share text and identical prev/next neighbors (`Anchor context.`/`Tail context.`), call `insertParagraphBookmarks`, assert both _bk_* IDs match the canonical regex and are distinct from each other. 2. Open the same XML body twice independently, apply `insertParagraphBookmarks` to each, assert the two collision-resolved ID lists are byte-identical across opens. Both scenarios use `test.openspec(...)` to land on the existing `document-paragraph-id-stability-and-fingerprint` traceability lane. No source files changed; this characterizes existing behavior only. Peer review (Gemini + Codex) pending. Ref: #282
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
LLM-Based Quality GateOverall: ✅ PASS (14 pass · 0 warn · 14 total)
Full checklist questions
Estimated cost (this run): $0.0152 — 43,919 input + 793 output tokens (≈4 chars/token) on |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Peer review (Codex dynamic) noted the prior "two distinct IDs" assertion would still pass if `buildParagraphSeed` later added sibling position or wider context — the salt-loop would never run and the test would lose its characterization value. Pin the exact unsalted hash (_bk_04c5b72c79f7) and the |salt:1 hash (_bk_a2abd088979b) so the test fails loudly if the derivation changes shape. Comment notes the rationale. Ref: #282
Peer review (Gemini + Codex) — 2026-05-29Codex findings: Verified the fixture truly collides (instrumented runtime seed dump confirmed both target paragraphs produce Gemini findings: Approve via static analysis + Allure-result inspection. Confirmed fixture coordinates, identified seed equivalence, validated spec-coverage expectation ( Resolution: Applied Codex's recommendation in |
Summary
buildParagraphSeedcombines paragraph text with the immediate prev/next neighbor text and ancestor signature. When two paragraphs sit at positions where both the text and the prev/next neighbors are identical, the seed collides;deriveDeterministicJrParaNameresolves this with a 10,000-step salt-loop (first hit unsalted, subsequent hits get|salt:N). This load-bearing behavior had no characterization test.Implementation
Two new scenarios added to
paragraph_id_stability.traceability.test.ts, alongside the existing stability scenario, both registered viatest.openspec(...)on thedocument-paragraph-id-stability-and-fingerprintlane:insertParagraphBookmarks resolves seed collisions with a deterministic salt— Six-paragraph fixture with twoDuplicate clause.paragraphs at indices 1 and 4, both sandwiched between identicalAnchor context./Tail context.neighbors so the seedtext|prev|next|ancestorsis identical. AfterinsertParagraphBookmarks, both paragraphs have_bk_[0-9a-f]{12}IDs and the two IDs are distinct.Collision resolution is stable across independent reopens— Same XML body, opened twice independently,insertParagraphBookmarksapplied to each. The two collision-resolved ID lists are byte-identical paragraph-by-paragraph across opens.A literal two-paragraph fixture would NOT collide because the seed includes neighbor text. The six-paragraph layout is the minimum to force a collision while keeping neighbor context identical.
No source files changed; this characterizes existing behavior only.
Verification
test:run -w @usejunior/docx-core -- test-primitives/paragraph_id_stability.traceability.test.ts→ 5 passed (3 existing + 2 new)npm run build)npm run lint:workspaces) — pre-existing unused-eslint-disable warning inpackages/docx-mcp/src/cli/commands/edit.test.ts:133; unrelated.npm run test:run) — all workspaces green.check:spec-coverage,check:conformance-citations,check:conformance-docall OK.Closes