Skip to content

test(document-api): word-in-the-loop validation for anchored metadata (SD-3201)#3373

Merged
caio-pizzol merged 3 commits into
mainfrom
caio-pizzol/SD-3201-word-roundtrip-validation
May 18, 2026
Merged

test(document-api): word-in-the-loop validation for anchored metadata (SD-3201)#3373
caio-pizzol merged 3 commits into
mainfrom
caio-pizzol/SD-3201-word-roundtrip-validation

Conversation

@caio-pizzol
Copy link
Copy Markdown
Contributor

@caio-pizzol caio-pizzol commented May 18, 2026

Closes the round-trip gap from SD-3104 (#3351). The SuperDoc → DOCX → SuperDoc cycle was already proven by tests/doc-api-stories/tests/metadata/all-commands.ts; this PR adds Microsoft Word in the middle as deterministic fixtures replayed in CI.

Coverage

Two fixtures under tests/doc-api-stories/tests/word-roundtrip/fixtures/, both produced by opening a SuperDoc-exported baseline in Microsoft Word and saving:

  • baseline-word-resaved.docx — Word Save As, no edits. Proves Word does not strip the customXml part or the hidden SDT wrapper on a no-op save.
  • baseline-word-edited.docx — text inserted inside the cited span ("duty of care" → "duty reasonable of care"). Proves the SDT survives content edits without detaching.

Replay test asserts

For each fixture, the SuperDoc client reopens the file and verifies:

  • metadata.list({ namespace }) returns the citation
  • metadata.get({ id }) returns the expected payload (Word does not alter the customXml data during save or inline edits)
  • metadata.resolve({ id }) returns a selection target with text endpoints — the anchor did not orphan
  • For the edited fixture, metadata.list({ within: target }) confirms the citation is still listable in its own resolved range after Word's run-splitting

Text-content equality of the resolved range against the edited string is not asserted (see the inline comment at all-commands.ts:109).

Why deterministic fixtures, not live Word API

Fixtures run in CI without Word access. Catching new-Word-version regressions (Document Inspector strips customXml, Word changes SDT semantics, etc.) is a separate live pre-rollout check — not gated by CI.

What this does not cover

  • Word Document Inspector with "Remove customXml" enabled (intentionally destructive; out of scope)
  • Track Changes interacting with the anchor (separate workstream)
  • New Word version regressions (covered by the pre-rollout live script, not in this PR)

… (SD-3201)

Closes the round-trip gap from SD-3104: SuperDoc -> DOCX -> Word save /
edit -> SuperDoc. The SuperDoc -> DOCX -> SuperDoc round-trip was already
proven by tests/doc-api-stories/tests/metadata/all-commands.ts; this adds
Word in the middle as deterministic fixtures replayed in CI.

Two fixtures, both generated from one SuperDoc-side source (one paragraph,
one anchored citation 'fixture-cite-001' over 'duty of care'):

- baseline-word-resaved.docx: opened in Word, re-saved without edits.
  Proves Word does not strip the customXml part or the hidden SDT
  wrapper on save.
- baseline-word-edited.docx: opened in Word with text inserted inside
  the cited span. Proves the SDT survives content edits and the anchor
  expands to cover the edited content (no orphan, no detach).

Replay test under tests/doc-api-stories/tests/word-roundtrip/:
- list({ namespace }) returns the citation
- get({ id }) returns the payload byte-for-byte (Word does not
  renormalize the customXml part)
- resolve({ id }) returns a SelectionTarget
- list({ within: resolvedTarget }) confirms the anchor still covers
  the post-edit range

What this does not cover
- New Word version regressions. A separate live script gated on Word
  API access is the pre-customer-rollout pre-flight; not in this PR.
- Word's 'Inspect Document' / Document Inspector cleanup, which can
  strip Custom XML Data as 'personal information.' Documented as a
  known limitation in the namespace adoption guide (SD-3209).
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 18, 2026

SD-3201

@caio-pizzol caio-pizzol marked this pull request as ready for review May 18, 2026 21:52
@caio-pizzol caio-pizzol requested a review from a team as a code owner May 18, 2026 21:52
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b2ff89d7d3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread tests/doc-api-stories/tests/word-roundtrip/all-commands.ts Outdated
…3201)

Soften the inline comment to match what the test actually asserts: the
anchor did not detach (resolve returns a selection target with text
endpoints), and the citation is still listable via within-scoped list.
Text-content equality of the resolved range against the edited string
is explicitly not asserted here.

Also drop the 'byte-for-byte' wording on the no-edit fixture — the
assertion is parsed-payload equality, not raw XML byte equality.
…D-3201)

Replaces the self-referential metadata.list({ within: resolved.target })
block with a slice of the resolved block's text via editor.doc.extract.
The slice now asserts the SDT range covers 'duty' + 'reasonable' +
'care' — proving the Word-inserted word is inside the anchor using a
read surface (extract) that's independent of the metadata store.
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@caio-pizzol caio-pizzol merged commit 450f1f7 into main May 18, 2026
15 checks passed
@caio-pizzol caio-pizzol deleted the caio-pizzol/SD-3201-word-roundtrip-validation branch May 18, 2026 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants