Skip to content

test(behavior): parity axis helpers for SDT contracts (SD-3237/SD-3218)#3558

Merged
caio-pizzol merged 3 commits into
mainfrom
caio/sdt-parity-helpers
May 29, 2026
Merged

test(behavior): parity axis helpers for SDT contracts (SD-3237/SD-3218)#3558
caio-pizzol merged 3 commits into
mainfrom
caio/sdt-parity-helpers

Conversation

@caio-pizzol
Copy link
Copy Markdown
Contributor

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-cc
  • contentControlLifecycle(before, after) -> preserved / emptied / deleted / created / none
  • caretLocation(snap, range) -> inside-cc / before-cc / after-cc / outside-cc (null for a range)
  • bodyMutation(before, after) -> none / text-changed / structure-changed

Extends getInlineSdtSnapshot with docSize + paragraphCount so 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 refactoring sdt-select-all-inside to assert selectionScope(...) === 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.

…-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.
@caio-pizzol caio-pizzol requested a review from a team as a code owner May 28, 2026 23:57
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 28, 2026

SD-3237

SD-3218

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: 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".

Comment thread tests/behavior/tests/helpers/sdt-parity.spec.ts Outdated
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

Re-trigger cubic

@codecov-commenter
Copy link
Copy Markdown

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.
@caio-pizzol caio-pizzol merged commit 052410b into main May 29, 2026
24 checks passed
@caio-pizzol caio-pizzol deleted the caio/sdt-parity-helpers branch May 29, 2026 09:33
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.
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