test(behavior): parity axis helpers for SDT contracts (SD-3237/SD-3218)#3558
Merged
Conversation
…-3218) Adds pure compute helpers that derive a Word-parity-contract axis value from a snapshot, using the same vocabulary as the word-api contracts: - selectionScope(snap, range) - contentControlLifecycle(before, after) - caretLocation(snap, range) - bodyMutation(before, after) Each parity spec becomes a one-liner (expect(selectionScope(snap, sdt)).toBe(...)) instead of re-deriving from/to math - which is where the earlier edge-direction bug crept in. Extends getInlineSdtSnapshot with docSize + paragraphCount so whole-document scope and structure-changed mutation are computable. Pure unit-tested (tests/helpers/sdt-parity.spec.ts, no browser) and demonstrated against real behavior by refactoring sdt-select-all-inside to use selectionScope.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f786f5c526
ℹ️ 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".
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…content text It compares whole-doc textContent, so SDT content changes (e.g. emptying) do count as text-changed; only wrapper lifecycle is excluded.
…aywright/test Per tests/behavior/AGENTS.md. The helper tests stay pure because the superdoc fixture is lazy and never requested here.
gpardhivvarma
pushed a commit
to gpardhivvarma/superdoc
that referenced
this pull request
May 29, 2026
…SD-3237/SD-3218) First consumer of the parity axis helpers (superdoc-dev#3558). Two lock-invariant navigation contracts: - inline-right-arrow-trailing: one Right-arrow exits the SDT (caretLocation inside-cc -> after-cc), asserted via caretLocation(). - inline-shift-right-boundary: Shift+Right crosses the boundary character-by-character (selectionScope reaches cc-and-beyond, never whole-content-control), asserted via selectionScope(). No divergence - SuperDoc matches Word. No new contracts, no raw Word data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The next scaling piece after the contract schema landed: axis-shaped assertion helpers so consuming a Word parity contract is a one-liner instead of re-deriving from/to math (which is exactly where the edge-direction bug crept in earlier).
Adds pure compute helpers to
helpers/sdt.ts, using the same vocabulary as the word-api contracts:selectionScope(snap, range)-> collapsed / cc-content / whole-content-control / within-cc / cc-and-beyond / whole-document / outside-cccontentControlLifecycle(before, after)-> preserved / emptied / deleted / created / nonecaretLocation(snap, range)-> inside-cc / before-cc / after-cc / outside-cc (null for a range)bodyMutation(before, after)-> none / text-changed / structure-changedExtends
getInlineSdtSnapshotwithdocSize+paragraphCountso whole-document scope and structure-changed mutation are computable.They are pure functions (no browser), so they are unit-tested directly with synthetic snapshots in
tests/helpers/sdt-parity.spec.ts(every axis value), and demonstrated against real behavior by refactoringsdt-select-all-insideto assertselectionScope(...) === whole-document.This makes the upcoming navigation PR and remaining keyboard-breadth contracts cheap to consume and resistant to translation bugs.
Verified: helper unit test 20 passed (no browser); refactored select-all 6 passed across chromium/firefox/webkit.