Skip to content

feat(docx-core): sweep side-part revisions on accept/reject#218

Open
stevenobiajulu wants to merge 2 commits into
mainfrom
165-sidepart-accept-reject
Open

feat(docx-core): sweep side-part revisions on accept/reject#218
stevenobiajulu wants to merge 2 commits into
mainfrom
165-sidepart-accept-reject

Conversation

@stevenobiajulu
Copy link
Copy Markdown
Member

Summary

Closes #165.

accept_changes now resolves tracked-change markup in document.xml plus supported side-story parts: word/footnotes.xml, word/endnotes.xml, and word/comments.xml. The low-level accept/reject DOM primitives also work against story-root XML, and DocxDocument exposes symmetric package-level accept and reject sweeps.

Implementation

  • Extends low-level acceptChanges(doc) / rejectChanges(doc) to use w:body when present, otherwise the document element as a story root.
  • Makes DocxDocument.acceptChanges() async so it can read and rewrite optional side parts from the DOCX ZIP.
  • Adds DocxDocument.rejectChanges() with the same package sweep behavior.
  • Updates the MCP accept_changes tool to await the async document facade.
  • Writes side parts back only when revision markup was actually resolved.
  • Keeps footnotesXml cache in sync after footnote-story accept/reject.
  • Updates SUPPORT.md to classify comment replies as Table B package-level metadata and to document side-part accept/reject behavior.

Verification

  • npm -w @usejunior/docx-core run test:run -- test-primitives/document.test.ts test-primitives/accept_changes.test.ts test-primitives/reject_changes.test.ts — 23 passed
  • npm -w @usejunior/docx-mcp run test:run -- src/tools/add_accept_tracked_changes.test.ts — 12 passed
  • npm -w @usejunior/docx-core run lint
  • npm -w @usejunior/docx-mcp run lint
  • npm -w @usejunior/docx-core run build
  • npm -w @usejunior/docx-mcp run build
  • git diff --check
  • npm run lint:allure-imports — passed with one pre-existing warning in packages/docx-mcp/src/cli/commands/edit.test.ts:133

Notes

This PR keeps revision-ID uniqueness separate from the side-part accept/reject sweep. That prerequisite is covered in draft PR #216 for #171.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
site Ready Ready Preview, Comment May 22, 2026 6:51am

Request Review

@github-actions github-actions Bot added the feat label May 22, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

❌ Patch coverage is 90.90909% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/docx-core/src/primitives/document.ts 90.00% 8 Missing ⚠️
...ackages/docx-core/src/primitives/accept_changes.ts 92.85% 1 Missing ⚠️
...ackages/docx-core/src/primitives/reject_changes.ts 93.33% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Peer review of PR #218 flagged that rejecting an addFootnote(..., ctx)
removed the body w:footnoteReference but left the <w:footnote w:id=N>
shell in word/footnotes.xml — and the symmetric case (acceptChanges over
a tracked-deleted footnote) leaked the same shell. The reject path was
therefore not really restoring pre-edit state.

Add a post-sweep orphan prune in DocxDocument.acceptChanges /
rejectChanges that drops non-reserved <w:footnote> entries whose ID is
no longer referenced from the body. Reserved separator /
continuationSeparator entries are preserved. Only runs when the body
sweep actually removed a deletion (accept) or insertion (reject), so
documents with pre-existing orphans and no revisions are untouched.

Adds four BDD tests: addFootnote+reject, deleteFootnote+accept,
deleteFootnote+reject (round-trip restoration), and updateFootnoteText
+accept (replacement-wins case).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@stevenobiajulu stevenobiajulu marked this pull request as ready for review May 22, 2026 06:51
@stevenobiajulu stevenobiajulu enabled auto-merge (squash) May 22, 2026 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend accept_changes / reject_changes to handle revisions in footnotes.xml and comments.xml

1 participant