Skip to content

test(desktop): introduce Playwright Electron E2E + CI (first version) - #581

Merged
Astro-Han merged 19 commits into
mainfrom
feat/desktop-e2e
Jul 6, 2026
Merged

Astro-Han merged 19 commits into
mainfrom
feat/desktop-e2e

Conversation

@Astro-Han

@Astro-Han Astro-Han commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

First version of desktop E2E tests (Playwright + Electron) plus a CI workflow — a baseline regression net for core user flows, which until now had zero automated coverage.

Why

The repo had no E2E and no CI; regressions on core flows could only be caught manually. This adds the first automated safety net.

Scope

Changed:

  • E2E foundation: Playwright config + launch fixtures (per-test isolated userData, env injection, hidden window + dock.hide so runs don't steal focus)
  • BackendRegistry routes ai-sdk through FakeBackend under MAKA_E2E — the single E2E backend seam; every session-creation path deterministically uses fake, with no real provider keys or network
  • 5 specs: first-run / chat loop / session create+coexistence / settings theme / attachment drop→ingest
  • CI: .github/workflows/ci.yml — typecheck + unit + e2e jobs on ubuntu-latest (e2e under xvfb), on PR + push to main

Review follow-ups (done in this PR)

  • All E2E switches gated behind !app.isPackaged && MAKA_E2E==='1' && MAKA_E2E_USER_DATA_DIR — a packaged build, or a stray MAKA_E2E without the throwaway dir, can't enable the fake backend against real user data.
  • Dropped global retries:1; each fixture waits for its readiness selector (cold-start convergence), so flakes surface instead of being absorbed.
  • E2E connection seed moved from production ensureBootstrapConnection into the e2e fixture (pre-seeds throwaway userData via @maka/storage); production main keeps only the fake-backend seam.
  • Attachment spec drops a file, sends, and asserts the fake backend received it by name — proving the ingest-on-send path.
  • Split into emptyWindow (no seed — first-run exercises the true no-connection boot) and window (seeded — chat/session/settings/attachment).

CI note (test job has visible pre-existing failures)

The test job currently fails on main's pre-existing Linux issues that no CI had ever caught — not introduced by this PR. The failure is left visible (not hidden behind continue-on-error) so reviewers can see exactly what's pre-existing vs. what this PR changed:

  • rg (ripgrep) missing on ubuntu → installed in the test job (fixed here)
  • ahe-target-protocol.ts stale sourceRef pointing at a desktop file hoisted to runtime in eb52bc91 → repointed (fixed here)
  • history-compact-artifacts oversized-block assertion drifts on Linux (estimatedTokens size difference) → tracked for a separate follow-up

typecheck + e2e are the real gates and pass. A follow-up PR will fix the remaining Linux test failures and make test gating.

Known follow-ups (not in this PR)

  • Fix main's pre-existing Linux test failures (history-compact-artifacts etc.) and restore test gating.
  • Session switch-back assertion — sidebar groups rows by status and rows land in collapsed groups; a flaky click would contradict retries:0.

Verification

cd apps/desktop && npm run e2e — 5 specs pass (~9s), stable without retries.
Existing desktop unit tests unaffected (changes are E2E-only seams; production paths never activate them).
CI gates typecheck + e2e on every PR.

User-facing impact

None. All E2E switches activate only when !app.isPackaged && MAKA_E2E && MAKA_E2E_USER_DATA_DIR all hold; never in production builds, never against real user data.

Checklist

  • Scope matches the title
  • Verification lists commands/results
  • User-facing impact: none
  • Risk called out (pre-existing Linux test failures visible, tracked separately)
  • UI changes: N/A (test/CI infrastructure)

Astro-Han added 19 commits July 6, 2026 22:41
Foundation for desktop end-to-end tests:
- resolveSessionBackend pure helper forces the deterministic fake backend
  under MAKA_E2E=1, so tests run without provider keys or network
- main.ts routes sessions:create through it, admits the fake path via the
  dev guard, and redirects userData under MAKA_E2E_USER_DATA_DIR for hermetic
  per-test isolation
- e2e/ holds the Playwright config, launch fixture (isolated userData + env),
  and a first-run spec covering the launch -> main -> renderer chain
- adds @playwright/test and `npm run e2e`

First-run spec passes (~1s); resolveSessionBackend unit tests 3/3;
existing suites unaffected.
- ensureBootstrapConnection seeds a real-looking 'e2e' connection under
  MAKA_E2E so onboarding clears and the quick-chat input is usable;
  sessions still run on the fake backend, so no real API is called
- BackendRegistry overrides 'ai-sdk' to the fake under MAKA_E2E, so every
  session-creation path (sessions:create, quickChat:start, future ones)
  routes to the deterministic fake instead of leaking to a real provider
- send-message spec: type into the quick-chat input, send, assert the
  fake backend streams its reply into the transcript

Both specs pass (~1s each).
session-management spec: start chat A, create chat B and send in it, assert both appear in the sidebar. Empty sessions are filtered by lastMessageAt so B only lists once it has a message. Switching back via the sidebar row is deferred (rows can sit in a collapsed status group); a flaky click is worse than no assertion.
settings spec: expand the collapsed sidebar, open settings, navigate to Appearance, pick the dark theme radio, assert <html> picks up the dark class.
attachment spec: drop a file onto the composer, assert a pending attachment card. config retries: 1 — electron cold-start (launch + connection seed + onboarding convergence) can occasionally exceed the 10s expect timeout on a full-suite run; one retry absorbs it without masking persistent failures. 5 specs pass (~9s).
main-window.ts show:false and main.ts dock.hide() now also trigger under MAKA_E2E, reusing the visual-smoke 'accessory app' path: no dock bounce, never becomes frontmost. paintWhenInitiallyHidden defaults to true so the hidden window still renders and Playwright drives the DOM unchanged. 5 specs still pass (~8s).
- remove resolveSessionBackend + its test + the MAKA_E2E guard branch: it conflicted with the BackendRegistry override (wrote header.backend=fake which chat-readiness rejects on send). The registry override is the single seam: header stays ai-sdk, runtime factory swaps to FakeBackend.
- e2e script builds @maka/* deps first (was desktop-only; broke on clean checkout).
- move MAKA_E2E_USER_DATA_DIR setPath before requestSingleInstanceLock so the lock judges the throwaway dir (developer with Maka open no longer kills E2E as a second instance).
5 specs pass (~8s).
Triggers on PR (main) + push (main); concurrency cancels stale PR runs. Three parallel jobs on ubuntu-latest: typecheck, unit test, e2e. E2E runs under xvfb since Electron needs a display on a headless Linux runner. Node 22 + npm cache.
The runtime Grep tool shells out to rg, which ubuntu runners don't ship. Without it 2 suites fail with `rg: not found` (builtin read tools path containment, LocalWorkspaceExecutor file operations).
…oist

The context-budget-policy source was hoisted from apps/desktop/src/main/ to packages/runtime/src/ in eb52bc9 (hoist context budget policy builder), but the AHE target snapshot's sourceRef still pointed at the old (now-deleted) desktop path. The ahe-export validation test failed: source ref 'apps/desktop/src/main/context-budget-policy.ts' does not exist under repo root. Pre-existing on main, surfaced by this PR's new CI test job.
The test job surfaces main's pre-existing Linux failures (estimatedTokens drift in history-compact-artifacts, etc.), tracked for a separate follow-up. The job still runs and reports; typecheck + e2e stay gating.
P2-1: gate every E2E switch behind !app.isPackaged (setPath, BackendRegistry override, dock.hide, window show:false) so a packaged build ignores stray MAKA_E2E env. P3-1: move the connection seed out of production ensureBootstrapConnection into the e2e fixture (pre-seeds throwaway userData via @maka/storage). P2-2: drop retries:1; fixture waits for the onboarding quickchat input (cold-start convergence) so flakes surface instead of being absorbed.
Fake backend echoes input.attachments names; the spec drops note.txt, sends, and asserts the reply contains the attachment name — proving the ingest-on-send path delivered the file, not just that the UI rendered a card.
…error

ChatGPT review pointed out continue-on-error made the workflow green while the test job was red — a safety-net PR shouldn't hide a red light. Drop it; the test job now fails visibly on main's pre-existing Linux issues (history-compact-artifacts etc.), which the PR body documents as pre-existing and tracked for a follow-up. typecheck + e2e remain the real gates and pass.
…empty boot

ChatGPT review: the single fixture pre-seeded a connection for every test, so first-run didn't exercise the no-connection boot path (name vs. coverage mismatch). Split into emptyWindow (no seed, wait for #root — first-run only) and window (seed + wait for quickchat — chat/session/settings/attachment).
ChatGPT review: isE2e only checked MAKA_E2E, so a developer setting only that one (no throwaway dir) would enable the fake backend against their real userData. Now isE2e requires both env, so the fake backend can't run without the isolated dir.
…sed skip

The oversized block hardcoded estimatedTokens: 9999 with a short summary, but loadHistoryCompactBlocksFromArtifacts recomputes tokens from renderHistoryCompactBlock(block).length (it deliberately ignores the persisted estimate). So 9999 was ignored, the short render stayed under maxEstimatedTokens, and the block wasn't skipped — the test asserted behavior impl doesn't do. Mirror the runtime test: force a long summary so the render exceeds maxEstimatedTokens while content stays under maxBytes. Pre-existing test-design bug surfaced by the new CI.
…ure cleanup

ChatGPT re-review P2/P3 follow-ups on the E2E harness.

P2: fixtures launched Electron with ...process.env, so host provider keys auto-bootstrapped a connection (breaking the true first-run assertion) and VITE_DEV_SERVER_URL loaded the dev server instead of the built bundle. buildE2eEnv deny-lists those (provider *_API_KEY/*_API_TOKEN/*_API_SECRET, VITE_DEV_SERVER_URL, stale MAKA_*); deny-list over allow-list because Electron relies on undocumented platform env an allow-list would silently drop.

P3: main-window.ts read MAKA_E2E directly for show:false while main.ts gated isE2e on three conditions, so a stray MAKA_E2E=1 without USER_DATA_DIR still hid the window. main.ts now computes startHidden = Boolean(visualSmokeFixture) || isE2e and passes it to the controller; main-window.ts owns no env policy.

P3: fixtures ran mkdtemp + launchE2eApp outside the try, so a readiness timeout left a zombie Electron and a leaked maka-e2e-* dir. withE2eWindow wraps launch + use in one try/finally that always closes the app and rms userData.
outputDir 'test-results' resolves against the apps/desktop cwd, so the e2e/test-results/ entry never matched apps/desktop/test-results/. Use a bare test-results/ entry to cover both layouts.
@Astro-Han
Astro-Han merged commit d9e04c0 into main Jul 6, 2026
3 checks passed
@Astro-Han
Astro-Han deleted the feat/desktop-e2e branch July 6, 2026 18:59
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.

1 participant