Skip to content

test(e2e): Server lifecycle, startup, tray/settings, and deep linking - #3860

Merged
yasserfaraazkhan merged 24 commits into
masterfrom
e2e/06-server-management
Jul 2, 2026
Merged

test(e2e): Server lifecycle, startup, tray/settings, and deep linking#3860
yasserfaraazkhan merged 24 commits into
masterfrom
e2e/06-server-management

Conversation

@yasserfaraazkhan

@yasserfaraazkhan yasserfaraazkhan commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary:

  • errorView.ts — timing around ErrorView and certificate dialogs: reload server views after the renderer is up so load failures aren’t missed. Used heavily by bad_servers and certificate_trust; if those look brittle, start here.
  • deeplink.ts — builds mattermost-dev:// URLs (not tied to Playwright worker NODE_ENV). Deep link, OAuth callback, and “app already running” specs all go through this.
  • Server management block — add/edit/remove/configure modals, bad server URLs, cert trust, tab management, long server names, header. Exercises modals, serverMap, and cert auto-trust hooks from test(e2e): Playwright harness and main-process hooks for migration stack #3855.
  • Startup / first-run — welcome screen, config integrity, session persistence, window reposition (Linux CI guard), cmd-tab restore. Often sensitive to onboarding flags and clean data dirs.
  • Tray + settings — tray menu (macOS), hide tray icon, window-close-to-tray, settings page, autostart (finally restores prior state). Platform guards matter — skim for process.platform / test.skip before assuming every file runs everywhere.
  • Popout + Linux — popout windows, drag-and-drop reorder, Wayland launch, dark mode policy spec.

Release Note

NONE

Change Impact: 🟠 Medium

Regression Risk: Shared E2E test harness utilities were added/expanded (renderer reload + error-view detection, deep-link navigation, and a faster app teardown helper) and are used across many specs; if any synchronization/teardown logic is off, it can cause widespread CI flakiness/hangs. While this targets test code (not production business logic), it touches certificate-trust/reload flows and multiple lifecycle paths with potentially timing-sensitive selectors and polling.
QA Recommendation: Re-run the full affected E2E suites end-to-end. If they’re green, a small manual smoke pass is recommended on (1) server error view reload/recovery (error appears then disappears) and (2) “trust invalid/expired certificate” resulting in server view loading.
Generated by CodeRabbitAI

Part 1 of splitting #3847 — core Playwright config, fixtures, electronApp
teardown, and GitHub Actions E2E workflow updates. No new specs yet.
Exposes __e2eTestRefs, message-box stub, tray/deep-link hooks (NODE_ENV=test
only) plus directLaunch, testRefs, and shared helper updates.
@mm-cloud-bot

Copy link
Copy Markdown

@yasserfaraazkhan: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

I understand the commands that are listed here

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR adds new E2E helpers for error views, settings windows, deep links, and shell interactions, while updating server-management, startup, tray, popout, settings, and Linux specs to use shared launch, reload, and shutdown flows.

Changes

Server management error handling

Layer / File(s) Summary
Error view helpers
e2e/helpers/errorView.ts
Adds WaitForErrorViewOptions, waitForRendererThenReload, and waitForErrorView for waiting on renderer error UI after reloading server views.
Bad server flows
e2e/specs/server_management/bad_servers.test.ts
Refactors bad_servers.test.ts to use shared launch and close helpers, stabilizes the add-server modal open path, and switches error assertions to waitForErrorView plus shared TLS error matching.
Certificate trust test
e2e/specs/server_management/certificate_trust.test.ts
Adds the SEC-03 test that writes an expired-certificate config, trusts the certificate through stubbed dialogs, reloads the server, and verifies certificate.json persistence and ErrorView removal.
Server test teardown
e2e/specs/server_management/add_server_modal.test.ts, configure_server_modal.test.ts, edit_server_modal.test.ts, header.test.ts, long_server_name.test.ts, remove_server_modal.test.ts, tab_management.test.ts
Replaces per-test Electron shutdown and lock-file waiting with closeElectronAppFast across server-management modal and tab-management specs.

App lifecycle and window behavior

Layer / File(s) Summary
Drag-and-drop and popout flows
e2e/specs/server_management/drag_and_drop.test.ts, popout_windows.test.ts
Switches drag-and-drop and popout tests to shared direct-launch helpers, updates per-view navigation recovery, rewrites popout creation and teardown through main-process refs, and adjusts popout move and close assertions.
Startup shutdown helpers
e2e/specs/startup/app.test.ts, config.test.ts, config_integrity.test.ts, session_persistence.test.ts, welcome_screen_modal.test.ts, window.test.ts, cmd_tab_restore.test.ts, window_reposition.test.ts
Updates startup specs to use closeElectronApp and closeElectronAppFast for app shutdown and lock-file cleanup, including session persistence, welcome screen, config, integrity, and window bounds tests.
Tray, popup, and policy flows
e2e/specs/system/tray_menu.test.ts, tray_restore.test.ts, window_close_tray.test.ts, e2e/specs/popup.test.ts, policy.test.ts
Adds tray menu and restore tests, a window-close tray test, popup teardown changes, and policy app close cleanup through main-process and dialog-driven interactions.

Deep linking and settings behavior

Layer / File(s) Summary
Deep link helpers
e2e/helpers/deeplink.ts
Adds Mattermost deep-link URL builders, an app-level opener, and polling navigation helpers for channel deep-link flows.
Settings window helper
e2e/helpers/settingsWindow.ts
Adds openSettingsWindow with retrying window discovery and IPC-driven opening.
Deep link specs
e2e/specs/deep_linking/deeplink.test.ts, deeplink_running.test.ts, oauth_callback.test.ts
Updates deep-link tests to use shared helpers, registers the main process, adds macOS open-url coverage, and adds an OAuth callback deep-link test.
Settings behavior tests
e2e/specs/settings/autostart.test.ts, tray_icon_hide.test.ts, settings.test.ts
Adds an autostart config test, a tray-icon hide test, and platform tag updates for settings coverage.

Linux-specific UI behavior

Layer / File(s) Summary
Linux launch and dark mode
e2e/specs/linux/wayland_launch.test.ts, linux_dark_mode.test.ts, e2e/helpers/tray.ts
Adds a Wayland launch test, switches the Linux dark-mode toggle to the Electron menu, adds a macOS config-driven dark-mode test, and adds a helper to hide the main window from the main process.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • mattermost/desktop#3855: Shares the E2E certificate-error and main-process test hooks used by the new error-view and trust flows.
  • mattermost/desktop#3864: Updates several of the same E2E teardown paths to use closeElectronAppFast.

Suggested reviewers: devinbinnie, NARSimoes, saturninoabril, lieut-data

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.47% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: broad E2E test coverage across server lifecycle, startup, tray/settings, and deep linking.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch e2e/06-server-management

Comment @coderabbitai help to get the list of available commands.

@yasserfaraazkhan yasserfaraazkhan changed the title E2E: Server management and certificate trust (6/10) E2E: Server management and certificate trust Jun 19, 2026
Base automatically changed from e2e/02-main-hooks to e2e/01-harness-ci June 19, 2026 11:21
Base automatically changed from e2e/01-harness-ci to master June 30, 2026 23:13
Resolve harness/hook conflicts by keeping merged #3855 changes.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions github-actions Bot added the E2E/Run Run Desktop E2E Tests label Jun 30, 2026
@mm-cloud-bot

Copy link
Copy Markdown

❌ E2E Test Setup Failed

Failed to create E2E test instances: failed to create installation: failed with status code 409

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@e2e/specs/server_management/bad_servers.test.ts`:
- Around line 381-390: The test currently checks for .ErrorView too early,
before the trusted-server navigation path in launchDirectTestApp() and the main
window has finished loading. Update the bad_servers.test.ts flow around
launchDirectTestApp, mainWindow, and ErrorView so the test first waits for the
server view to fully load expired.badssl.com, then assert that .ErrorView
remains absent after that navigation has completed.
- Around line 304-307: The server lookup in the Mattermost test is indexing
buildServerMap() too early and can still hit the unreachable view, so wait until
the Mattermost entry is actually present before reading
serverMap[demoMattermostConfig.servers[0].name][0]. Update the bad_servers test
around buildServerMap and mmEntry retrieval to poll for the Mattermost server
entry (using the existing demoMattermostConfig.servers[0].name key) before
accessing .win, so the URL check only runs after the correct view is available.

In `@e2e/specs/server_management/certificate_trust.test.ts`:
- Around line 37-52: The certificate trust spec is duplicating Electron startup
logic instead of using the shared direct-launch helper. Update the test to use
launchDirectTestApp from e2e/helpers/directLaunch.ts, passing the needed env
overrides and writeConfig: false so it matches the existing harness behavior.
Remove the open-coded electron.launch, waitForAppReady, and
registerElectronMainProcess setup from certificate_trust.test.ts and rely on the
helper’s launch flow instead.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b12f0295-564c-4498-9bbd-ee194e76f208

📥 Commits

Reviewing files that changed from the base of the PR and between 08129c4 and b41357d.

📒 Files selected for processing (10)
  • e2e/helpers/errorView.ts
  • e2e/specs/server_management/add_server_modal.test.ts
  • e2e/specs/server_management/bad_servers.test.ts
  • e2e/specs/server_management/certificate_trust.test.ts
  • e2e/specs/server_management/configure_server_modal.test.ts
  • e2e/specs/server_management/edit_server_modal.test.ts
  • e2e/specs/server_management/header.test.ts
  • e2e/specs/server_management/long_server_name.test.ts
  • e2e/specs/server_management/remove_server_modal.test.ts
  • e2e/specs/server_management/tab_management.test.ts

Comment thread e2e/specs/server_management/bad_servers.test.ts Outdated
Comment thread e2e/specs/server_management/bad_servers.test.ts
Comment thread e2e/specs/server_management/certificate_trust.test.ts Outdated
Poll for Mattermost server view registration, wait for trusted cert
navigation before asserting ErrorView absence, and reuse launchDirectTestApp
in certificate_trust.test.ts.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions github-actions Bot added E2E/Run Run Desktop E2E Tests and removed E2E/Run Run Desktop E2E Tests labels Jun 30, 2026
@mm-cloud-bot

Copy link
Copy Markdown

❌ E2E Test Setup Failed

Failed to create E2E test instances: installation wait cancelled: context canceled

@yasserfaraazkhan

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@yasserfaraazkhan yasserfaraazkhan added E2E/Reset-Servers Destroy E2E server for a fresh Run. Add E2E/Run label to kick off an e2e run. and removed E2E/Run Run Desktop E2E Tests E2E/Reset-Servers Destroy E2E server for a fresh Run. Add E2E/Run label to kick off an e2e run. labels Jul 1, 2026
@github-actions github-actions Bot added the E2E/Run Run Desktop E2E Tests label Jul 1, 2026
@mm-cloud-bot

Copy link
Copy Markdown

❌ E2E Test Setup Failed

Failed to create E2E test instances: installation wait cancelled: context canceled

* E2E: Tray, settings, deep linking, and misc specs (10/10).

* Address CodeRabbit review on tray/deeplink/settings E2E specs

Always use mattermost-dev deep links in E2E helpers, use shared fixtures
for the macOS open-url test, and restore autostart after SET-01.
@github-actions github-actions Bot added E2E/Run Run Desktop E2E Tests and removed E2E/Run Run Desktop E2E Tests labels Jul 1, 2026
The diagnostic build from the previous commit found the actual cause:
ServerDropdownButton is fully visible/enabled/unobstructed at click time
(ruling out every DOM/focus theory from the prior 3 fix attempts), and the
dropdown.html window never appears at all.

Root cause is in production code: ServerDropdownView.handleOpen()
(src/app/mainWindow/serverDropdownView.ts) silently no-ops if its
WebContentsView doesn't exist yet. That view is created lazily by init(),
which runs on the MAIN_WINDOW_CREATED event — a boot-time race that can
still be pending when a freshly-launched shared app's first test clicks the
button under CI load. A single click landing in that window is lost
forever, since nothing else triggers dropdown creation afterward — this is
why the single-click+20s-poll version (previous commit) could never
succeed no matter how long the timeout, and why the earlier 3x
click-and-poll retry (5s per attempt, 15s total) sometimes wasn't long
enough.

The earlier "it's a toggle, re-clicking closes it" concern only applies
*after* a successful open sets state on both the main and renderer side —
a click that lands before the view exists changes no state anywhere, so
re-clicking is safe and just retries the open. Replaced with a retry loop
(click, poll 3s, repeat) over a 40s budget, long enough to survive the
boot-time race while still safely retrying instead of guessing a longer
single timeout.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions github-actions Bot added the E2E/Run Run Desktop E2E Tests label Jul 1, 2026
yasserfaraazkhan added a commit that referenced this pull request Jul 1, 2026
…e catch

settingsWindow.ts / autostart.test.ts: same bugs already found and fixed in
the sibling PR #3860 (both branches independently introduced this file
from the same base) — waitForLoadState() failures were being swallowed and
returned as a possibly-broken Page outside the retry loop, and the
autostart restore step could fail silently, leaving the real OS autostart
entry toggled for subsequent CI runs with no warning.

src/main/notifications/index.ts: the new __e2eDisplayAndClickMention test
hook reached into NotificationManager's private allActiveNotifications
field via `as unknown as {...}`, defeating type-checking — a future rename
of that field would silently break the hook instead of failing to compile.
Added a small, type-safe findActiveMentionByChannelId() method on the class
instead, used by the test hook. Verified: `tsc` (full check-types) clean,
all 66 existing notification unit tests still pass.

desktop_notification_delivery.test.ts: readBadgeCount's bare
`catch { return 0 }` masked any real failure as "no badge" — but the
non-darwin call sites are already gated behind the unityRunning check at
the call site, so app.getBadgeCount() isn't expected to throw there;
removed the redundant catch so a real failure surfaces instead of being
silently scored as a passing badge-count of 0.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the E2E/Run Run Desktop E2E Tests label Jul 1, 2026
…wn view

Diagnosed from CI trace (28540903308 artifact 8020461659) after 6 failed
guesses on the "dropdown click never opens the dropdown" symptom. The trace
showed:
- 13 clicks on .ServerDropdownButton over 40s, all producing no dropdown
- A "Close page" API call from bad_servers.test.ts:127 (my beforeEach) at
  200813ms — before any test-body code ran
- Failure screenshot showed the .ServerDropdownButton visibly present,
  unobstructed, and clickable

The root cause is the defensive beforeEach I added in commit 84e0523:
`win.close()` on any window whose URL `.includes('dropdown')` matches:
  • dropdown.html         ← the SERVER DROPDOWN's WebContentsView
                            (loaded at MAIN_WINDOW_CREATED, needed for
                            OPEN_SERVERS_DROPDOWN to render anything)
  • downloadsDropdown.html
  • downloadsDropdownMenu.html

Playwright's Page.close() destroys the underlying WebContents. After that,
every subsequent click on .ServerDropdownButton reaches
ServerDropdownView.handleOpen() in the main process, which no-ops because
this.view.webContents is destroyed — the setBounds/addChildView calls
either throw and get swallowed or silently do nothing visible. That
explains why 6 prior fix attempts (retry-click, bringToFront, longer
timeouts, retry-loop, etc.) all failed identically: the target was
correct, the button was clickable, the click was landing, but the
dropdown's own infrastructure had already been destroyed at test setup.

Removed the beforeEach entirely. The failure-recovery it defended against
(stray modal windows persisting from a prior test's failure) is a
theoretical edge case; the correctness cost of destroying the dropdown
view at every test's start is real and confirmed. If serial-mode state
leaks ever become a real problem, prefer sending CLOSE_SERVERS_DROPDOWN
IPC (which properly closes without destroying the view) or a keyboard
Escape at test end.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions github-actions Bot added E2E/Run Run Desktop E2E Tests and removed E2E/Run Run Desktop E2E Tests labels Jul 1, 2026
Diagnosed from CI screenshot/trace (run 28548703597, macOS, RC4 cipher
test): SyntaxError: Unexpected end of JSON input at bad_servers.test.ts:207,
JSON.parse(fs.readFileSync(configPath, 'utf8')).

This is not hypothetical — traced to the actual write path: Config.
saveLocalConfigData() persists via JsonFileManager.write()
(src/common/JsonFileManager.ts:24-37), which calls Node's fs.writeFile().
That truncates the file before writing the new content; it is not an
atomic write-to-temp-then-rename. The E2E test reads the same file from a
separate process (the Playwright runner) while the Electron app may still
be mid-write, so an empty or partial read is a real, reproducible race,
not a one-off.

All 4 tests in the "Adding servers via Add Server Modal" block had the
identical unguarded pattern; RC4 happened to hit it on this run, but any of
the four could. Replaced with findServerInConfig(), which treats a read or
parse failure as "not ready yet" (returns undefined) so expect.poll keeps
retrying instead of the exception failing the test outright.

Separately: this run also showed "(@ci-macos) Worker teardown timeout of
90000ms exceeded" affecting unrelated files (window_menu, notification_click,
permissions_ipc, policy, popup) — left out of scope as a pre-existing CI
infrastructure flake, not something introduced by this file's changes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions github-actions Bot added E2E/Run Run Desktop E2E Tests and removed E2E/Run Run Desktop E2E Tests labels Jul 1, 2026

@saturninoabril saturninoabril 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.

Thanks @yasserfaraazkhan, LGTM!

…ement

# Conflicts:
#	e2e/helpers/mattermostShell.ts
#	e2e/specs/deep_linking/deeplink.test.ts
#	e2e/specs/mattermost/copy_link.test.ts
#	e2e/specs/server_management/bad_servers.test.ts
#	e2e/specs/server_management/drag_and_drop.test.ts
@github-actions github-actions Bot added the E2E/Run Run Desktop E2E Tests label Jul 2, 2026
@mm-cloud-bot

Copy link
Copy Markdown

❌ E2E Test Setup Failed

Failed to create E2E test instances: failed to create installation: failed with status code 409

@yasserfaraazkhan yasserfaraazkhan added E2E/Reset-Servers Destroy E2E server for a fresh Run. Add E2E/Run label to kick off an e2e run. E2E/Run Run Desktop E2E Tests and removed E2E/Run Run Desktop E2E Tests E2E/Reset-Servers Destroy E2E server for a fresh Run. Add E2E/Run label to kick off an e2e run. labels Jul 2, 2026
@github-actions github-actions Bot removed the E2E/Run Run Desktop E2E Tests label Jul 2, 2026
@github-actions github-actions Bot added E2E/Run Run Desktop E2E Tests and removed E2E/Run Run Desktop E2E Tests labels Jul 2, 2026
@github-actions github-actions Bot added E2E/Run Run Desktop E2E Tests and removed E2E/Run Run Desktop E2E Tests labels Jul 2, 2026
@yasserfaraazkhan
yasserfaraazkhan merged commit 34bab8a into master Jul 2, 2026
41 checks passed
@yasserfaraazkhan
yasserfaraazkhan deleted the e2e/06-server-management branch July 2, 2026 12:32
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.

3 participants