Repository navigation
test(e2e): regression guards for previously-reported "Unexpected error" crashes - #4268
Merged
Merged
Conversation
…r" crashes Adds three Playwright specs that exercise the user-described recipes from ~50 "Unexpected error" issues filed against shipped versions (v0.16.x through v0.18.4). All recipes pass on current develop — the cumulative guards added during the electron-vite refactor and subsequent fixes closed the original crash surfaces. These specs become regression guards: if any of the historical paths reopens, CI fails before another user files the same issue. Covered categories (with issue numbers): - "Failed to execute 'setStart' on 'Range': There is no child at offset N" via setCursorRange / inputHandler / enterHandler / paste (#4159 #4111 #4101 #4091 #4052 #4035 #4006 #4005 #4004 #3996 #3954 #3936 #3929 #3886 #3829 #3793 #3790 #3771 #3737 #3727 #3636 #3542 #3378 #2627 #2526) - "Cannot destructure property 'text' of {block} as it is null" via updateParagraph (#2099 #3571 #3663 #3667 #3879) - "selectionChange: expected cursor but cursor is null" via paragraphCtrl (#4160 #3942) Infra additions in test/e2e/helpers.ts: - `MARKTEXT_ERROR_INTERACTION=1` in the launch env so the main process exception handler does not pop the modal "Unexpected error" dialog under Playwright (which would deadlock the test worker). - A parallel `mt::handle-renderer-error` IPC listener stored in a shared global, with `getRendererErrors` / `clearRendererErrors` / `expectNoRendererErrors` helpers. - A "crash counter sanity" test that forces a renderer-side throw and asserts it is captured, so the assertion above never passes vacuously. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds Playwright E2E regression tests to guard against several historically frequent “Unexpected error” crash signatures by asserting that specific user-action recipes no longer trigger renderer error handling, and it extends the E2E helper infrastructure to suppress the blocking modal error dialog while capturing renderer errors via IPC.
Changes:
- Add a renderer-error capture mechanism in
test/e2e/helpers.ts(IPC listener + helpers) and disable the modal error dialog viaMARKTEXT_ERROR_INTERACTION=1. - Add 3 new E2E spec files covering historical crash recipes around range offsets, paragraph updates, and selection-change edge cases.
- Add a sanity test intended to verify that the new crash counter is actually wired up.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| test/e2e/helpers.ts | Sets an env var to suppress modal error dialogs during tests and installs IPC-based renderer error capture helpers. |
| test/e2e/crash-range-offset.spec.ts | Adds regression recipes for historical Range.setStart offset crashes + a crash-counter sanity check. |
| test/e2e/crash-update-paragraph.spec.ts | Adds regression recipes for updateParagraph-related null block crashes (quick insert + menu paths). |
| test/e2e/crash-selection-change.spec.ts | Adds regression recipes for selectionChange null-cursor crashes + a white-box behavior probe. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced May 23, 2026
Closed
Closed
Closed
Closed
Closed
Quick-insert + menu paths:
- Fix the quick-insert selector to use data-label="heading 1" (lowercase, per
src/muya/lib/ui/quickInsert/config.js) instead of the made-up "header 1" /
localized text fallback. The previous selector silently no-op'd in any
non-English locale and let the spec pass without exercising the recipe.
- Stop swallowing clickMenuById failures in three places. If the menu id is
wrong or the menu is not ready, the test must fail loudly rather than
vacuously asserting "no crash" without invoking the crash surface.
- Add a waitForMenuReady() call to every beforeEach so menu invocation is
deterministic.
- The "rapid alternation" test now asserts that some heading/paragraph
structure exists, proving the menu clicks actually mutated state.
Selection-change paths:
- The "Blur the editor..." test now actually blurs document.activeElement
in addition to clearing the DOM selection (the original recipe).
- The "Repeated focus/blur" test no longer references "menu invocation" in
its name — renamed to "Repeated DOM selection clear + refocus" so the
name matches the surface it exercises.
- The white-box selectionChange probe now uses test.skip() when muya is not
reachable on `window`, and a hard `expect('threw')` when it is. Replaces
the previous toContain([allValues]) which was a no-op.
Sanity helper:
- Replace fixed waitForTimeout(300) in the sanity test with a new
waitForRendererError() helper that polls getRendererErrors with a 5s
deadline. Slower CI runners no longer race the timeout.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced May 23, 2026
Closed
Closed
Closed
Closed
Closed
Closed
Closed
Closed
Closed
Closed
Closed
Closed
Closed
Closed
Closed
This was referenced May 23, 2026
Comment on lines
66
to
70
| // MARKTEXT_ERROR_INTERACTION suppresses the modal "Unexpected error" dialog | ||
| // (see src/main/exceptionHandler.ts) — we instead capture errors via the | ||
| // mt::handle-renderer-error IPC below so specs can assert on them. | ||
| env: { ...process.env, PERF_TESTING: 'true', MARKTEXT_ERROR_INTERACTION: '1' }, | ||
| timeout: 30000 |
| // The user then clicks on / highlights the text. We simulate by selecting | ||
| // all and then collapsing to caret to provoke setCursorRange across the | ||
| // mixed inline DOM the paragraph now contains. | ||
| await page.keyboard.press('Control+A') |
| await placeCaretInEditor(page) | ||
| await clearRendererErrors(app) | ||
|
|
||
| await page.keyboard.press('Control+A') |
Comment on lines
+32
to
+38
| test.beforeEach(async() => { | ||
| const launched = await launchWithMarkdown('# Doc\n\nFirst para.\n\nSecond para.\n') | ||
| app = launched.app | ||
| page = launched.page | ||
| await waitForMenuReady(app) | ||
| await placeCaretInEditor(page) | ||
| await clearRendererErrors(app) |
Comment on lines
+75
to
+113
|
|
||
| // White-box probe: directly invoke the contentState API to confirm the throw | ||
| // is still present in the source. The renderer does not expose `muya` on | ||
| // `window`, so we walk the editor component to find the instance via a known | ||
| // property if available. If the probe cannot reach muya in this environment | ||
| // it is skipped rather than passing vacuously. | ||
| test.describe('selectionChange API behaviour', () => { | ||
| test('Calling selectionChange with null cursor throws (white-box)', async() => { | ||
| const { app, page } = await launchWithMarkdown('# Doc\n') | ||
| try { | ||
| await page.waitForTimeout(300) | ||
| const outcome = await page.evaluate(() => { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const anyWin = window as any | ||
| const muya = anyWin.__MUYA__ || anyWin.muya | ||
| if (!muya || !muya.contentState) return 'no-muya' | ||
| try { | ||
| muya.contentState.cursor = null | ||
| muya.contentState.selectionChange(null) | ||
| return 'did-not-throw' | ||
| } catch { | ||
| return 'threw' | ||
| } | ||
| }) | ||
| // Muya is not currently exposed on `window` — this probe is | ||
| // informational and is skipped when it cannot reach the instance. | ||
| // If a future change starts exposing muya, this guard switches from | ||
| // skip to a hard assertion that null-cursor selectionChange still | ||
| // throws (which is the current documented behaviour). | ||
| if (outcome === 'no-muya') { | ||
| test.skip(true, 'muya instance is not exposed on window in this build') | ||
| } else { | ||
| expect(outcome).toBe('threw') | ||
| } | ||
| } finally { | ||
| await app.close() | ||
| } | ||
| }) | ||
| }) |
helpers.ts:
- Make MARKTEXT_ERROR_INTERACTION opt-in via a new LaunchOptions
{ suppressErrorDialog?: boolean } parameter on launchElectron,
launchWithDoc, launchWithMarkdown. Default behaviour is unchanged for
existing specs — they keep getting the dialog if a renderer error
leaks. Only the 3 crash-guard specs opt in (they install the IPC
counter and assert on it explicitly). Removes the silent-regression
risk Copilot flagged: existing specs would otherwise silently ignore
renderer exceptions that previously surfaced as a dialog.
crash-range-offset.spec.ts:
- Replace `Control+A` with `ControlOrMeta+A` in both Select-All recipes
so the spec is portable to macOS (where Select All is Cmd+A).
- Opt into suppressErrorDialog for the two describe blocks and the
sanity test.
crash-update-paragraph.spec.ts:
- The #2099 recipe is "type @ in a *fresh* file" but beforeEach was
seeding with `# Doc\n\nFirst para.\n\nSecond para.\n`. Refactor each
test to own its own launch via a small launchAndReady() helper so
the #2099 test can use the empty seed the report actually describes.
crash-selection-change.spec.ts:
- Remove the always-skipped white-box probe — it always hit the
`no-muya` branch (Muya is not exposed on `window` anywhere in src/)
and was effectively dead code that added noise without guarding
any behaviour.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
thimbleberrysystems
pushed a commit
to thimbleberrysystems/WordBird
that referenced
this pull request
Jun 21, 2026
…r" crashes (marktext#4268) * test(e2e): regression guards for previously-reported "Unexpected error" crashes Adds three Playwright specs that exercise the user-described recipes from ~50 "Unexpected error" issues filed against shipped versions (v0.16.x through v0.18.4). All recipes pass on current develop — the cumulative guards added during the electron-vite refactor and subsequent fixes closed the original crash surfaces. These specs become regression guards: if any of the historical paths reopens, CI fails before another user files the same issue. Covered categories (with issue numbers): - "Failed to execute 'setStart' on 'Range': There is no child at offset N" via setCursorRange / inputHandler / enterHandler / paste (marktext#4159 marktext#4111 marktext#4101 marktext#4091 marktext#4052 marktext#4035 marktext#4006 marktext#4005 marktext#4004 marktext#3996 marktext#3954 marktext#3936 marktext#3929 marktext#3886 marktext#3829 marktext#3793 marktext#3790 marktext#3771 marktext#3737 marktext#3727 marktext#3636 marktext#3542 marktext#3378 marktext#2627 marktext#2526) - "Cannot destructure property 'text' of {block} as it is null" via updateParagraph (marktext#2099 marktext#3571 marktext#3663 marktext#3667 marktext#3879) - "selectionChange: expected cursor but cursor is null" via paragraphCtrl (marktext#4160 marktext#3942) Infra additions in test/e2e/helpers.ts: - `MARKTEXT_ERROR_INTERACTION=1` in the launch env so the main process exception handler does not pop the modal "Unexpected error" dialog under Playwright (which would deadlock the test worker). - A parallel `mt::handle-renderer-error` IPC listener stored in a shared global, with `getRendererErrors` / `clearRendererErrors` / `expectNoRendererErrors` helpers. - A "crash counter sanity" test that forces a renderer-side throw and asserts it is captured, so the assertion above never passes vacuously. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(e2e): address Copilot review on PR marktext#4268 Quick-insert + menu paths: - Fix the quick-insert selector to use data-label="heading 1" (lowercase, per src/muya/lib/ui/quickInsert/config.js) instead of the made-up "header 1" / localized text fallback. The previous selector silently no-op'd in any non-English locale and let the spec pass without exercising the recipe. - Stop swallowing clickMenuById failures in three places. If the menu id is wrong or the menu is not ready, the test must fail loudly rather than vacuously asserting "no crash" without invoking the crash surface. - Add a waitForMenuReady() call to every beforeEach so menu invocation is deterministic. - The "rapid alternation" test now asserts that some heading/paragraph structure exists, proving the menu clicks actually mutated state. Selection-change paths: - The "Blur the editor..." test now actually blurs document.activeElement in addition to clearing the DOM selection (the original recipe). - The "Repeated focus/blur" test no longer references "menu invocation" in its name — renamed to "Repeated DOM selection clear + refocus" so the name matches the surface it exercises. - The white-box selectionChange probe now uses test.skip() when muya is not reachable on `window`, and a hard `expect('threw')` when it is. Replaces the previous toContain([allValues]) which was a no-op. Sanity helper: - Replace fixed waitForTimeout(300) in the sanity test with a new waitForRendererError() helper that polls getRendererErrors with a 5s deadline. Slower CI runners no longer race the timeout. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(e2e): address second-round Copilot review on PR marktext#4268 helpers.ts: - Make MARKTEXT_ERROR_INTERACTION opt-in via a new LaunchOptions { suppressErrorDialog?: boolean } parameter on launchElectron, launchWithDoc, launchWithMarkdown. Default behaviour is unchanged for existing specs — they keep getting the dialog if a renderer error leaks. Only the 3 crash-guard specs opt in (they install the IPC counter and assert on it explicitly). Removes the silent-regression risk Copilot flagged: existing specs would otherwise silently ignore renderer exceptions that previously surfaced as a dialog. crash-range-offset.spec.ts: - Replace `Control+A` with `ControlOrMeta+A` in both Select-All recipes so the spec is portable to macOS (where Select All is Cmd+A). - Opt into suppressErrorDialog for the two describe blocks and the sanity test. crash-update-paragraph.spec.ts: - The marktext#2099 recipe is "type @ in a *fresh* file" but beforeEach was seeding with `# Doc\n\nFirst para.\n\nSecond para.\n`. Refactor each test to own its own launch via a small launchAndReady() helper so the marktext#2099 test can use the empty seed the report actually describes. crash-selection-change.spec.ts: - Remove the always-skipped white-box probe — it always hit the `no-muya` branch (Muya is not exposed on `window` anywhere in src/) and was effectively dead code that added noise without guarding any behaviour. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.
Summary
Triaged the 88 OPEN issues with the title prefix
Unexpected error(gh issue list --search "Unexpected error in:title" --state open), grouped them by error signature, located each crash site in current code, and attempted to reproduce every reproducible category with Playwright user-action recipes only (no programmatic state hacks).Empirical finding: on current
develop(0.18.9), none of the historical user recipes still crashes. Cumulative changes from the electron-vite refactor (#4001) and subsequent fixes already closed the main crash surfaces:getMuyaIndexCursornull anchorBlock destructure (#4117/#4090/#4079/#4078)src/muya/lib/utils/importMarkdown.js:464-467— `if (!anchorBlockquickInsert.selectItemnull block destructure (#2099/#3571/#3663/#3667/#3879)src/muya/lib/ui/quickInsert/index.js:160-164CLOSE_TABSundefined-tab pathname destructure (#3100/#3551)src/renderer/src/store/editor.ts:1044—?? { pathname: '' }bringToFrontnull window deref (#2065/#3321/#4137)src/main/windows/base.ts:85early returnsrc/muya/lib/selection/index.js:524-530selectionChangenull cursor (#4160/#3942)src/muya/lib/contentState/paragraphCtrl.js:18-22model-cursor fallbackRather than add speculative defensive fixes that cannot be validated by a failing test, this PR encodes the historical crash recipes as regression-guard e2e specs. If any of these crash paths reopens, CI fails before another user files the same issue.
What's in the PR
3 new e2e specs under
test/e2e/, totalling 14 tests:crash-range-offset.spec.ts(9 tests) — recipes from the 25setStartissues (escaped HTML typing from Unexpected error: Failed to execute 'setStart' on 'Range': There is no child at offset 73. #2526, code-block backspace from Unexpected error: Failed to execute 'setStart' on 'Range': There is no child at offset 1766. #3737, Enter mid-formatted-paragraph, paste of rich HTML, select-all-delete in math-rich paragraphs).crash-update-paragraph.spec.ts(3 tests) — type@then pick Header 1 (Unexpected error: Cannot destructure property 'text' of 'n' as it is null. #2099 recipe), delete paragraph then heading-menu, rapid heading↔paragraph menu alternation.crash-selection-change.spec.ts(2 tests) — clear DOM selection + blur then invoke format menu, repeated DOM selection clear + refocus.Helper infra in
test/e2e/helpers.ts:LaunchOptions { suppressErrorDialog?: boolean }parameter onlaunchElectron/launchWithDoc/launchWithMarkdown. When opted in, setsMARKTEXT_ERROR_INTERACTION=1so the main-process exception handler does not pop the modal "Unexpected error" dialog under Playwright (would deadlock the worker). Only the crash-guard specs opt in — existing specs keep getting the dialog if a renderer error leaks (no silent-regression risk).mt::handle-renderer-errorIPC listener onipcMainthat accumulates errors into a shared global, plusgetRendererErrors/clearRendererErrors/expectNoRendererErrorshelpers.throwand asserts it is captured — guards against the new assertion passing vacuously.Test plan
pnpm run typecheck— passespnpm run lint— no new errors/warnings introduced by these filespnpm run test:unit— 550 tests passpnpm exec playwright test test/e2e/crash-*.spec.ts— 14 / 14 passpnpm exec playwright test test/e2e/editor-input.spec.ts test/e2e/launch.spec.ts test/e2e/tabs.spec.ts— existing specs unaffected by the new env var / IPC listenerOut of scope
Issues that are not user-reproducible at all stay open for now:
Cannot find window menu for id NUnexpected error: Cannot find window menu for id 1. #3313/Unexpected error: Cannot find window menu for id 1. #2262/Unexpected error: Cannot find window menu for id 2. #2295,getPrimaryDisplay: callback can only be called for onceUnexpected error: callback can only be called for once #2203/Unexpected error: callback can only be called for once #2519net::ERR_*auto-updater Unexpected error: net::ERR_HTTP2_PROTOCOL_ERROR #3184/Unexpected error: net::ERR_CONNECTION_RESET #2531/Unexpected error: net::ERR_CONNECTION_CLOSED #3237,EMFILEUnexpected error: EMFILE: too many open files, open 'C:\Users\Administrator\AppData\Roaming\marktext\preferences.json' #2906,EISDIRUnexpected error: EISDIR: illegal operation on a directory, watch '\\wsl.localhost\Ubuntu\home\eric\Projects-client\subatomic\client-import\md-images' #3779registerKeyHandlersUnexpected error: Invalid state: all arguments must be non-null. #3365,resolvePathUnexpected error: Cannot set properties of undefined (setting 'resolvePath') #3797SyntaxError: 9during HTML/PDF export ("Unexpected renderer process error" exporting HTML or PDF #4046) — worth a separate investigation.🤖 Generated with Claude Code