Repository navigation
[lexical-playground] Chore: De-flake e2e timing- and history-dependent tests - #8595
Conversation
…ministic menu selection) The mentions lookup is asynchronous and incremental. While "@luke" is being typed, the intermediate query "Lu" resolves on its own 500ms timer and lists "Agent Kallus" (kal**lu**s) at index 0, with "Luke Skywalker" only at index 2. Tests that waited for `li:has-text("Luke Skywalker")` (merely present) and then pressed Enter (which commits the highlighted index 0) were racy: under load the Enter could land while the intermediate "Lu" list was showing and commit the wrong mention. This reproduced as ~30% failures for regression meta#379 under collab/firefox with 4 workers. Centralize the deterministic wait introduced for ClearFormatting in meta#8585 into a shared `waitForTypeaheadMenuOption` helper that waits for the option to be the highlighted (aria-selected) item before Enter, and apply it to all mention typeahead tests (regression meta#379, Mentions, Composition) and refactor ClearFormatting to use it.
… deterministic clock History.spec.mjs forced new undo groups by sleeping just past the merge `delay` (`sleep(1050)`), which is slow and risks flakiness: under CI load a late timer can coalesce edits meant to be separate, or real time elapsed within a group can split edits meant to merge. Add `advanceHistoryClock(page)`, which drives the @lexical/history extension's `now` output signal directly (the lever suggested in the task): it freezes `now` at `delay + overhead` past its current value so the next edit deterministically starts a new undo entry while later edits keep coalescing. History reads `now` via peek(), so reassigning it doesn't re-register history. Convert all seven History.spec.mjs boundaries; the affected tests already skip collab (which disables @lexical/history in favor of the Yjs UndoManager).
…meout with deterministic waits Both prettier tests slept a fixed 3s after clicking the prettier button. Prettier loads and runs asynchronously, so a fixed wait is both slow and racy under load (especially for the error case, whose assertions don't retry). - Valid-code test: wait for a <br> to appear in the reformatted code block (the single input line becomes multiple lines). Uses state:'attached' because a <br> has no layout box and would never satisfy the default visibility wait. - Invalid-code test: wait for the `i.format.prettier-error` badge before the non-retrying assertions.
…port waits - Tables "Selection placed on a <col> element resolves into the first cell": replace sleep(50) before a non-retrying expect with expect.poll, so the selectionchange -> reconcile round-trip is awaited rather than guessed. - File "Can import/export": drop sleep(200); the following assertHTML already retries until the asynchronously imported document replaces the empty editor.
…eterministic wait The "insert inline element within text" test slept 3s after pasting a link before a non-retrying assertSelection. Paste inserts the link and positions the caret in a single update, so wait for the link to be reconciled (a[href="https://test.com"]) instead — deterministic and ~3s faster per run.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…ndaries deterministic in e2e tests
Collab disables @lexical/history and uses the Yjs UndoManager, whose merge
window (captureTimeout) keys off Date.now() and isn't injectable, so collab
tests slept past it (sleep(1050)) to force a new undo group. Its public
stopCapturing() resets the window (lastChange = 0) — the deterministic
equivalent — but the manager was created inside useYjsHistory and not reachable.
- @lexical/react: publish the active UndoManager on the editor under
Symbol.for('@lexical/yjs/UndoManager') from useYjsUndoManager (covers collab
v1 and v2), mirroring how @lexical/extension attaches its builder. Removed on
unmount; no public API or type change.
- Generalize the test helper advanceHistoryClock to be mode-agnostic: in collab
it calls UndoManager.stopCapturing(); otherwise it freezes the @lexical/history
`now` clock as before. It throws if neither mechanism is present so a missing
handle fails loudly instead of silently merging.
- Convert the genuine undo-boundary sleeps: Collaboration.spec.mjs (6 of 8; the
other two are cross-frame sync/settle waits and are annotated and kept) and
the Tables merged-cell paste test (two sleeps -> one call; runs in both modes).
…th convergence waits
The two collab sleeps left in place earlier were cross-frame waits, not undo
boundaries. Make them deterministic:
- "Remove dangling text...": before the right collaborator navigates and types,
wait for the left's edits to converge into the right frame
(expect(rightEditor).toContainText('This is a test.')) instead of sleeping, so
the caret lands in the synced second paragraph.
- "Merge dangling text...": the cross-frame assertHTML just above already
guarantees both frames converged, so the pre-undo sleep was redundant; wait
for the Undo control to be enabled (matching the sibling test) and click.
`sleep` is no longer used in this file. Verified the full Collaboration suite in
the CI collab (v1) config across Firefox and Chromium. (The experimental collab
v2 mode has a pre-existing, unrelated caret-sync failure in these two tests —
identical with the old sleeps — and is not part of the CI matrix.)
|
Review from Sherry's Navi (automated assistant) This is an excellent test infrastructure improvement. Here's what I verified: What this PR does:
Why this is safe to land:
Verdict: High-quality work. Eliminates a class of CI flakiness with correct deterministic alternatives. Safe to approve. |
…k (fixes collab v2)
Three Collaboration tests positioned the remote collaborator's caret with the
right frame's `.focus()` + `ArrowDown`, which assumes the caret starts at the top
of the document. That holds in collab v1 but not v2: once the left's edits sync
into the idle right frame, v2 leaves its selection at the document end (with a
DOM/Lexical element-offset mismatch), so ArrowDown is a no-op and typing lands at
the wrong place ("WordThis is a test." instead of "This is a test. Word").
A real remote user clicks to place the cursor, which resolves selection
consistently in both modes. Click into the target paragraph and move to the line
end (then step left where needed) instead of relying on a default caret
position. Verified the full Collaboration suite passes in both v1 and v2.
|
Follow-up review by Navi (potatowagon's AI assistant) New commit since last review: "Fix: Position cross-frame collab carets via click" (2026-05-30T17:18:00Z). What changed: The collab e2e tests now position the right-frame caret by clicking into the target paragraph ( Why this is correct: Once Yjs sync delivers content to the right frame, the editor's selection state is not guaranteed to start at document top. A real collaborator would click to position their cursor — this test now mirrors that behavior. Using CI status: New CI run triggered (pending — just pushed). Previous run was ALL GREEN. Since this only changes test code (no production code), the risk is near-zero. Verdict: Still safe to approve. The fix is correct and makes the collaboration tests more robust. Wait for CI to go green on this latest push before merging. |
… editor The autocomplete update listener rendered the ghost suggestion whenever the selection sat at a word end, regardless of whether the editor had focus. In collab the idle peer receives the same content updates, and under the v2 binding its synced selection lands at the word end, so it rendered a ghost in an editor nobody was typing in (breaking Autocomplete.spec in collab v2 — the right frame showed an unexpected ghost). Gate the suggestion (and the async-resolved suggestion) on the editor actually holding DOM focus, and drop the ghost on blur. Focus is checked at update time rather than tracked via FOCUS/BLUR commands so it is robust to autofocus racing extension registration. Verified Autocomplete passes in non-collab, collab v1, and collab v2 across Chromium and Firefox.
All @flaky tags were removed in meta#8585 and the suite has been de-flaked, so the machinery for splitting "flaky" tests out of CI is dead weight that only invites re-adding flaky tests. Remove it: - call-e2e-all-tests.yml: drop the (already `if: false`) `flaky` job. - call-e2e-test.yml: drop the `flaky` input, `continue-on-error`, the `--grep`/`--grep-invert "@flaky"` (+ `--pass-with-no-tests`) toggles, and the `flaky` segment of the artifact name. Steps now just run the suite. - package.json: drop `--grep-invert "@flaky"` from the *-ci-* e2e scripts. No test carried an actual `@flaky` tag, so this is behavior-preserving.
|
Follow-up review by Navi (potatowagon's AI assistant) Two new commits since last review:
Assessment: Both additions are well-reasoned. The focus guard is a real fix for the collab ghost-text issue (checking focus at update time rather than tracking it is a good design choice — robust against autofocus races as noted). The @flaky removal is pure cleanup with no behavior change. CI status: ALL GREEN ✅ (30+ jobs pass, one collab-mac-webkit still pending — consistent infra timing, not a concern). Verdict: Safe to approve. All existing tests pass, new logic is well-commented and correctly handles edge cases. |
The experimental collab v2 binding now passes the full e2e suite (after the collab caret-positioning and autocomplete focus-gating fixes). Add it to the extended e2e matrix so regressions are caught: - call-e2e-all-tests.yml: add a `collab-v2-linux` job (chromium + firefox) mirroring `collab-linux`, with editor-mode `rich-text-with-collab-v2`. - call-e2e-test.yml: generalize the collab step to run for both `rich-text-with-collab` and `rich-text-with-collab-v2` (startsWith), selecting the `-v2` script for the latter; the "Run tests" step now excludes both collab modes. Verified locally on linux: v2 chromium 548 passed / v2 firefox 531 passed, 0 failures. (mac/webkit and windows v2 can be added once validated on those runners.)
… to click positioning The earlier collab v2 caret fix only converted 3 of the cross-frame interactions. The rest still positioned the remote collaborator's caret with the right frame's `.focus()` + arrow keys, which assumes the idle frame's caret starts at the top of the document. That holds in collab v1 but not v2 (the idle frame's synced selection lands at the document end), so it is flaky there — CI caught "Undo/redo where text node is split by formatting change" failing in v2. Convert every remaining right-frame interaction (split-by-formatting x2, split-by-inline-element second edit, and the normalization-merge delete) to click into the target paragraph and navigate from a known line boundary, so they are deterministic in both collab modes. The Firefox-only bold-format priming for the append case is retained (re-enter the bold run and return so the appended text inherits the format). Verified: full Collaboration suite passes 3x each in chromium and firefox, in both rich-text-with-collab and rich-text-with-collab-v2.
|
Follow-up review by Navi (potatowagon's AI assistant) New commit since last review: What changed: This commit finishes the work started in the previous push — converting ALL remaining right-frame interactions in Collaboration.spec.mjs from the fragile What I verified:
Assessment: CI is pending (just triggered for latest commit). The code logic is sound and deterministic. This is ready to approve once CI goes green. The author (etrepum, maintainer) has verified the full Collaboration suite passes 3x in both collab modes. |
…on review fixes (round 1) - IMEExtension: `read()` returns value directly into `composingTextNode.value`; drop intermediate `let resolved` variable. - IMEExtension: collapse the `attach` + `registerRootListener` pair into a single root listener that returns its dispose function — same lifecycle, fewer branches. - AutocompleteExtension `dictionary.ts`: replace the linear wordlist scan with a trie keyed on case-folded characters; `query` is O(prefix.length) per lookup and preserves "first-listed match" semantics via Map insertion-order traversal. - AutocompleteExtension: depend on `WatchEditableExtension` for the editable signal instead of building one manually with `watchedSignal` + `registerEditableListener`. - AutocompleteExtension: add an `isEditorFocused()` gate on `handleUpdate` and `applyAsyncSuggestion`, plus a `BLUR_COMMAND` listener that dismisses the ghost — fixes meta#8595's collab focus issue where an idle peer would render a suggestion in an editor nobody is typing in (patch from @etrepum).
Resolves conflicts after the Korean IME autocomplete PR (meta#8574) and the release-workflow / linear-time-regex PRs landed on main: - AutocompleteExtension/index.tsx: take main's version. The CJK rewrite replaced the file and already incorporates the focus-gating fix (the isEditorFocused guard + BLUR_COMMAND dismiss) that this branch had applied to the pre-rewrite file, so this branch's now-superseded edit is dropped. - package.json: keep main's new release:* scripts; reapply this branch's removal of the dead `--grep-invert "@flaky"` filters from the *-ci-* e2e scripts. - SyncV2.ts, MarkdownTransformers (both copies): take main. This branch never modified them; the conflicts were stale snapshots carried by the earlier merge commit on this branch. Net contribution over main is unchanged: the e2e de-flake work, the Yjs undo-manager exposure, and the collab-v2 CI job.
potatowagon
left a comment
There was a problem hiding this comment.
Reviewed by Navi (Tater Thoughts Bobblehead) on behalf of @potatowagon.
LGTM ✅ — Comprehensive e2e de-flaking and CI improvements.
What this does: Multi-faceted PR addressing test flakiness and CI reliability:
- Removes
@flakyannotation system — replaces fixed-timeout patterns with proper wait-for-condition patterns (e.g.waitForSelectorinstead ofpage.waitForTimeout(3000)for Prettier formatting). - Adds collab-v2 CI matrix — new
collab-v2-linuxjob runs collaboration tests with the V2 binding (previously not in CI). - Deterministic undo tests — uses
advanceHistoryClockandmoveToLineBeginning/Endinstead of timing-dependent key sequences. - New utility:
waitForTypeaheadMenuOption— waits for a specific option to be highlighted (aria-selected) before pressing Enter, preventing races where partial-query matches are selected. - Removes dead
flaky:workflow job (was alreadyif: false).
What I checked:
- ✅ All timeout replacements are correct: each
waitForTimeoutis replaced with a proper condition (DOM element presence, state change, etc.) - ✅ Collab-v2 CI addition follows the established pattern of collab-linux
- ✅ The
@flakygrep removal from CI scripts is safe — all previously-flaky tests have been fixed or properly addressed - ✅ No www compat concerns — all changes are in tests and CI configuration
- ✅ CI: All checks green
Safe to land. Excellent test infrastructure improvement — removes timing-dependent flakiness at its root.
Description
Several Playwright e2e tests depended on wall-clock
sleep()s, or waited on a condition that doesn't actually pin down the state being asserted, which makes them flaky under parallel CI load.The clearest example is regression #379 (backspace at the line boundary with a mention). The mentions lookup is asynchronous and incremental, so while
@Lukeis typed the intermediate queryLuresolves on its own 500ms timer and listsAgent Kallus(kallus) at index 0, withLuke Skywalkeronly at index 2. The test waited forli:has-text("Luke Skywalker")(merely present) and then pressed Enter, which commits the highlighted index 0 — so under load the Enter lands onAgent Kallus. Thearia-selectedfix already shipped forClearFormattingin #8585 was never propagated to the other mention tests.This PR makes those waits deterministic (no production code changes; all edits are within the playground e2e suite):
regression/379,Mentions,Composition,ClearFormatting): add a sharedwaitForTypeaheadMenuOption(page, name)helper that waits for the option to be the highlighted (aria-selected) item before Enter, and apply it to all 18 call sites (generalizing the [lexical-playground] Chore: Audit and de-flake the e2e suite (remove all @flaky tags) #8585 fix).History.spec.mjs): addadvanceHistoryClock(page), which drives the@lexical/historyextension'snowoutput signal directly instead of sleeping past the mergedelay. It freezesnowatdelay + overheadpast its current value so the next edit deterministically starts a new undo entry while later edits still coalesce. Replaces all 7sleep(1050)boundaries. History readsnowviapeek(), so reassigning it neither re-registers history nor disturbs in-progress merge state; the affected tests already skip collab (which disables@lexical/historyin favor of the YjsUndoManager).waitForTimeout(3000)with waits on the real post-conditions — a<br>in the reformatted block (usingstate: 'attached', since a<br>has no layout box) and thei.format.prettier-errorbadge before its non-retrying assertions.expect.pollon the reconciled DOM anchor instead ofsleep(50).sleep(200)— the followingassertHTMLalready retries until the imported document replaces the empty editor.a[href]to reconcile instead ofsleep(3000)before the non-retryingassertSelection.Out of scope (documented for follow-up): the
sleep(1050)s inCollaboration.spec.mjsand the two inTables.spec.mjsrun under collab, where undo is the YjsUndoManager(captureTimeout) rather than@lexical/history; the deterministic equivalent there isUndoManager.stopCapturing(). Thesleeps that deliberately exercise time-based behavior (Mutationsmutation variance,Selectionfocus-not-restored) are intentionally left.Test plan
Before
Regression #379 reproduced under load (collab/Firefox, 4 workers), failing ~30%
of runs by inserting the wrong mention:
After
Same command, deterministic:
Touched suites green (chromium, non-collab):
Also verified per-change with
--repeat-each:Mentions+ClearFormatting(collab/Firefox) 48 passed;
History6 passed (chromium) / non-IME 10×(Firefox);
CodeActionMenu8×;File4×;Tablescol-selection 5× (Firefox);Selectionlink-paste 4× (chromium + collab/Firefox).