Skip to content

test(muya): de-flake heading-locale + backspace regression specs (#4434 review) - #4436

Merged
Jocs merged 1 commit into
developfrom
test/harden-4434-regression-specs
Jun 10, 2026
Merged

Jocs merged 1 commit into
developfrom
test/harden-4434-regression-specs

Conversation

@Jocs

@Jocs Jocs commented Jun 10, 2026

Copy link
Copy Markdown
Member

Summary

Fix-forward for #4434. After that PR merged, Copilot posted 6 review comments flagging genuine timing-flakiness in the two regression specs it added (now on develop). This PR hardens both so they deterministically exercise their bug guards rather than racing the engine's next-animation-frame flush.

What changed

packages/muya/src/__tests__/headingLocaleCrash.spec.ts

  • afterEach now clears the document-global Selection (window.getSelection()?.removeAllRanges()) — matching several other Muya specs — so a stale Range can't point into a removed host node and break a later test's setCursor.
  • Every affordance assertion now await flush() after typeHeading(). The paragraph→atx-heading conversion and the HeadingCopyLink attachment render flush on the next animation frame, so querying the affordance / reading its aria-label / dispatching its click immediately after typeHeading() could see null. Affected: the zh-CN render test, the per-locale (en vs zh-CN) test, the click test, and the all-locale test.
  • The "every shipped locale" test now actually covers all shipped locales — it loops de, en, es, fr, ja, ko, pt, zh-CN, zh-TW (9) instead of just [en, zhCN]. Typing # must not crash under any locale, which is the whole point of the guard.

packages/muya/src/block/content/paragraphContent/__tests__/backspaceUnwrap.spec.ts

  • The caret/join-point assertion now await flush() before reading the merged tree. The merge op flushes on the next frame; without awaiting it, contentByText('alphabeta') / getCursor() could observe the pre-merge state.

Test intent is preserved — each spec still genuinely exercises its original bug guard (the #-crash-under-non-en-locale guard especially, now broadened to all 9 shipped locales).

Verification

  • Target specs: 13 passed; stable across 5 consecutive runs (no longer timing-dependent).
  • pnpm -C packages/muya lint — 0 errors (only pre-existing warnings in untouched files); the two changed files lint clean.
  • pnpm -C packages/muya lint:types — clean.
  • pnpm -C packages/muya test — 671 passed.
  • pnpm -C packages/muya test:spec — 1347 passed.
  • madge circular check — no circular deps.

Related: #4434

🤖 Generated with Claude Code

… review)

Post-merge Copilot review on #4434 flagged real timing-dependence in two
regression specs now on develop. Harden both so they deterministically
exercise their bug guards:

headingLocaleCrash.spec.ts
- afterEach now clears the document-global Selection
  (window.getSelection()?.removeAllRanges()) so a stale Range can't point
  into a removed host node and break a later test's setCursor.
- Every test that queries the HeadingCopyLink affordance / its aria-label /
  dispatches its click now `await flush()` after typeHeading(), since the
  paragraph->atx-heading conversion and the attachment render land on the
  next animation frame.
- The "every shipped locale" test now actually loops all nine shipped
  locales (de, en, es, fr, ja, ko, pt, zh-CN, zh-TW) instead of just
  [en, zhCN], so typing `#` is proven crash-safe under every locale — the
  whole point of the guard.

backspaceUnwrap.spec.ts
- The caret/join-point assertion now `await flush()` before reading the
  merged tree, since the merge op flushes on the next frame; without it
  contentByText('alphabeta')/getCursor() could observe the pre-merge state.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings June 10, 2026 05:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens Muya regression specs introduced in #4434 by removing timing-related flakiness (next-animation-frame flush races) and by ensuring test isolation across runs. It keeps the original regression intent while making assertions deterministic.

Changes:

  • Await a next-frame flush() after heading conversion / backspace merge operations before asserting on DOM/state/cursor.
  • Clear the document-global Selection in afterEach to prevent stale Range references from affecting later tests.
  • Expand the “shipped locales” heading guard to exercise the conversion path across all bundled locales (9 total).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/muya/src/tests/headingLocaleCrash.spec.ts De-flakes heading-locale regression tests via flush(), clears global selection in afterEach, and broadens locale coverage.
packages/muya/src/block/content/paragraphContent/tests/backspaceUnwrap.spec.ts De-flakes caret/join-point assertion by awaiting the merge flush before reading merged content/cursor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Jocs
Jocs merged commit 62e20f4 into develop Jun 10, 2026
8 checks passed
@Jocs
Jocs deleted the test/harden-4434-regression-specs branch June 10, 2026 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants