Repository navigation
test(desktop): introduce Playwright Electron E2E + CI (first version) - #581
Merged
Merged
Conversation
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.
4 tasks
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
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:
userData, env injection, hidden window +dock.hideso runs don't steal focus)BackendRegistryroutesai-sdkthroughFakeBackendunderMAKA_E2E— the single E2E backend seam; every session-creation path deterministically uses fake, with no real provider keys or network.github/workflows/ci.yml—typecheck+unit+e2ejobs onubuntu-latest(e2e underxvfb), on PR + push to mainReview follow-ups (done in this PR)
!app.isPackaged && MAKA_E2E==='1' && MAKA_E2E_USER_DATA_DIR— a packaged build, or a strayMAKA_E2Ewithout the throwaway dir, can't enable the fake backend against real user data.retries:1; each fixture waits for its readiness selector (cold-start convergence), so flakes surface instead of being absorbed.ensureBootstrapConnectioninto the e2e fixture (pre-seeds throwawayuserDatavia@maka/storage); production main keeps only the fake-backend seam.emptyWindow(no seed —first-runexercises the true no-connection boot) andwindow(seeded — chat/session/settings/attachment).CI note (test job has visible pre-existing failures)
The
testjob 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 behindcontinue-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.tsstale sourceRef pointing at a desktop file hoisted to runtime ineb52bc91→ repointed (fixed here)history-compact-artifactsoversized-block assertion drifts on Linux (estimatedTokenssize difference) → tracked for a separate follow-uptypecheck+e2eare the real gates and pass. A follow-up PR will fix the remaining Linux test failures and maketestgating.Known follow-ups (not in this PR)
testgating.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_DIRall hold; never in production builds, never against real user data.Checklist