Skip to content

Latest commit

 

History

History
195 lines (170 loc) · 14.1 KB

e2e.md

File metadata and controls

195 lines (170 loc) · 14.1 KB
covers
.c8rc.json
.github/workflows/test.yml
e2e/*.js

End-to-end journeys

e2e/ holds a few Playwright journeys that launch the real Electron app and check what only a running app shows: layout, the IPC round trips, the main-process data behind the sidebar. The node:test suite under test/ runs over jsdom, which has no layout, and over injected fakes. It cannot see these. Issue #304.

Running them

task e2e          # Linux: builds the CodeMirror and Mermaid bundles, wraps the run in xvfb-run when there is no display
npm run e2e       # any platform, with a display, once the bundles are built

They need an installed node_modules whose native modules are built for Electron. npm install does that already: postinstall runs electron-builder install-app-deps. No browser download is needed, because Playwright drives the Electron binary from node_modules/electron.

npm test and npm run coverage never run these files. scripts/run-tests.js reads only test/, and .c8rc.json and the patch-coverage gate exclude e2e/**.

In CI

The e2e job of .github/workflows/test.yml runs on ubuntu-latest under xvfb-run (1920x1080 screen) on every pull request and every push to main or release/*. Before the run, it checks that better-sqlite3 and node-pty load under Electron's ABI. postinstall swallows a failed rebuild, and without that check a failed rebuild would show up as an app that does not start. When a journey fails, the job uploads switchboard-e2e-results/ under the runner's temporary directory (a trace.zip and a failure.png for each failed journey) and the HTML report as the e2e-results artifact, retained for 3 days on PRs and 14 days on pushes. The job has a 10-minute timeout. Open a trace with npx playwright show-trace trace.zip. It has the DOM and a screenshot for each step.

The job is a required check of the main-protection and release-protection rulesets, repository settings outside this file (read from the GitHub API on 2026-11-25).

The journeys

Journey File What it pins
A changed tracked file is listed with its counts, and the header total matches changes.spec.js status → rows → summary, through the real git and IPC
Clicking an untracked file opens it and its line count appears changes.spec.js the row click, the editable content pair, the count on open
An edit saved in the panel editor reaches disk, and the file stays changed changes.spec.js the editor gets the panel's width (not two 225 px columns), save writes the bytes
A clicked markdown file opens formatted in Touched as an opened row, and its preview scrolls inside the panel changes.spec.js the click route into Touched, the opened row, the preview's min-height: 0 (its box stays within #file-panel-content), the toggle back to the source editor
The shell opened with no tab fills the panel and is not a sidebar row panel.spec.js the .shell-only layout, and buildProjectsFromCache skipping the panel shell
Changes on a project with no git work tree says so, with no git output panel.spec.js the not-a-repository note instead of git's raw output
Refresh beside Stop redraws a plain terminal and restores its fitted size terminal-refresh.spec.js visible header geometry, one refresh IPC, actual PTY size events, and final fitted size
A window close asks first: Cancel keeps the window and its terminal, Close exits close-window.spec.js the guard holding the real close event, the in-page question, a terminal that still runs commands after Cancel, the exit (code 0) after Close
Quit from the menu asks first: Cancel keeps the app and its terminal, Stop exits close-window.spec.js the question naming the plain terminal it would stop (#562), a terminal that still runs commands after Cancel, the exit (code 0) after Stop
Closing a window whose page hangs, then closing it again, still ends the app hung-window.spec.js the close question never shown, the second close after the 2.5 s bound destroying the window, and exit code 0
A Touched modified file shows the shared diff below its list, and Close restores the full list changes.spec.js the Touched diff parking
Background Delete is a designed confirmation: Escape cancels, Delete proceeds app-dialogs.spec.js the modal stack's keys on the Delete dialog
New agent rows contain their controls and align their columns, at several window sizes dispatch-dialog.spec.js the dispatch dialog's layout
Keyboard focus: Configure, the New session menu, F6 / Shift+F6, Tab order, row Archive reveal keyboard-focus.spec.js focus moves and native tab order
Electron confines relative native writes to the disposable home launch-isolation.spec.js the launch fixture's working directory (see below)
Markdown Mermaid loads once under the CSP, isolates details and fits a narrow Gantt preview mermaid-preview.spec.js the lazy Mermaid bundle in the real renderer
A transcript-driven row state survives a sidebar re-render state-survives-rerender.spec.js the row state kept across a re-render
The themed file panel shows a long Touched list and scrollable file contents theme-controls.spec.js the file panel's scroll regions under a theme
E1–E8: the session tool bar tool-bar.spec.js see Session tool bar
Schedule rows keep every action inside the tab at 200, 340 and 600 px, light and dark, 100% and 150% zoom schedules.spec.js no button or history toggle leaves its row or the tab, none clips its text, and the tab never scrolls sideways (#1238)
Keyboard focus survives Schedules refreshes, and the create form stays reachable in a small zoomed window schedules.spec.js Create, a row action, the history toggle and a project Retry keep focus across a re-render; Tab reveals row actions with a visible outline; the open form keeps its value and focus; Tab reaches the form's Create at 800x500, 150% zoom; Escape returns to Create (#1238)

The issue's fifth journey expected the Changes control to disappear. #310 made it unconditional, so the journey checks what the panel says instead (see .ai/contexts/changes-view.md, "Not a repository").

Writing one

The shared launch fixture sets ELECTRON_IS_DEV=0 to disable the development reloader for every journey. Unpackaged Electron launches otherwise enable it, and writing screenshots inside the watched app directory can reload the renderer mid-test and discard the DOM a journey is interacting with. Playwright also writes test outputs to switchboard-e2e-results/ under RUNNER_TEMP in CI or the OS temporary directory locally, outside the app directory.

Electron receives the absolute app directory as its entry point and the disposable HOME as its working directory. On Windows, native spelling initialization under the Codex sandbox can create malformed relative directories containing Microsoft/Spelling/neutral, even with an absolute userData path. Keeping the working directory in the fixture home contains those writes and removes them during teardown (#591). The native defect is tracked in openai/codex#41889. launch-isolation.spec.js checks the actual Electron cwd, a relative write, and the absence of new Unicode directories in the checkout after teardown.

  • Few and coarse. Each journey costs an Electron launch. Add one only for something jsdom cannot see.

  • Isolated. The launch fixture in e2e/fixtures.js gives each test its own temporary HOME (and USERPROFILE), its own SWITCHBOARD_DATA_DIR and SWITCHBOARD_TRIGGERS_DIR, and a git identity. It drops every inherited variable whose name starts with CLAUDE or GIT_, plus the exact names HISTFILE, ELECTRON_RUN_AS_NODE, ZDOTDIR, BASH_ENV, ENV, PROMPT_COMMAND and INPUTRC, all matched case-insensitively (including lowercase and mixed-case spellings). XDG_CONFIG_HOME, XDG_DATA_HOME, XDG_CACHE_HOME and XDG_STATE_HOME point inside the temporary HOME, so a plain terminal's shell finds its startup files (~/.bashrc, ~/.zshrc, …) in the temporary HOME rather than the user's. This is not a sandbox: system-wide startup files such as /etc/profile still run, and other inherited shell variables (SHELLOPTS, PS4, PS1, …) pass through unchanged. Inherited GIT_DIR, GIT_WORK_TREE or GIT_INDEX_FILE would point git at another repository. Build the fixture projects with makeRepo / makePlainDir before calling launch(), because the app reads them at startup. See Live testing for why each of these is needed. It also replaces CODEX_HOME with <temporary HOME>/.codex, removing inherited values regardless of name casing. Codex sessions and projects therefore come from the disposable home, even when CODEX_HOME is set in the parent environment.

  • Plain terminals only. Open a session with openPlainTerminal, the project's + → Terminal. Never click the fixture's session row: that would start claude --resume.

  • Structure and geometry, never pixels or wording. Assert element boxes, classes, counts, and what reaches disk. Match a number in a label, never the sentence around it. There are no screenshot baselines.

  • No waitForTimeout. Wait on a locator assertion (toBeVisible, toHaveCount) or on expect.poll. A journey that needs a sleep is written wrong.

  • Bounded teardown. The fixture asks the app to close and waits up to 10 s for it to exit. If it has not exited, the fixture kills it:

    • On Linux and macOS, Playwright starts Electron as the leader of a new process group (detached on every platform but Windows). The fixture sends SIGKILL to that group. This reaches every process still in the group. It does not reach a process that has moved to another group or session. If the group signal fails, the fixture sends SIGKILL to the main process only.
    • On Windows, Playwright starts Electron through cmd.exe. The fixture runs taskkill /T /F on that pid, which kills the process and its descendants.

    Then it deletes the temporary HOME. If the app exits within the 10 s, no kill is sent. A journey may end the app itself (hung-window.spec.js and close-window.spec.js do); the fixture then skips the trace, the screenshot and the close, and only deletes the temporary HOME.

schedules.spec.js replaces the main-process list-schedules handler with a fixture (long Windows paths, a long name and refusal, disabled, malformed, linked, unreadable, archived-project and unknown-project rows, a project whose folder cannot be read, 20 history entries), so no schedule file or CLI run is involved. It relies on the tab being on by default in a fresh profile, so it also checks the startup path that reveals the tab. Its screenshots (one per size, zoom, theme and sidebar width, plus the create form) and the sidebar width each combination actually got (a 600 px sidebar can shrink in a small zoomed window) go to the test output directory and the report annotations; CI uploads them only when the job fails.

Proving a journey can fail

Each journey was turned red by reverting the behaviour it pins:

Mutation Red journey
Drop the .shell-only region rule in public/style.css the shell fills the panel (height ratio 0.26)
Drop both .shell-only rules the shell fills the panel (the handle is visible)
Remove the isPanelShellSession skip in session-cache.js the shell is not a sidebar row
Default the Changes editor to side-by-side the saved edit (each editor 224.5 px wide in a 449 px host)
Skip the not-a-repository branch in refreshChanges no git work tree
Show the deleted count as the added count in a row the tracked file's counts
Turn off up-front untracked counting and the count on open the untracked file

With up-front untracked counting on, removing only the count on open leaves the untracked journey green, because status has already counted the file.

Session tool bar (#506)

e2e/tool-bar.spec.js covers E1-E8: single/grid bar geometry, shell height across tool switches and shell-only fill, tool-only layout, Refresh beside the id, the 32-case narrow-window/zoom matrix, ordered shrinking and restored widths, vertical zoom, focused-grid ownership, and native Tab traversal. Run each mutation independently on the corrected implementation in the CI e2e job, preserving the journey's assertions. Each run below failed its journey on that mutation, applied alone on top of 69610d2 (draft PR #514).

Journey Mutation Red run
E1: single/grid bar geometry Position #tool-bar absolutely at top: 0 run
E2a-E2c: shell height and tool switches Initialize the shell before Touched, reverting their DOM order run
E3: tool without a shell Show the shell region even when no shell is open run
E4: Refresh beside id Restore justify-content: space-between on #terminal-header run
E5: 32-case overflow matrix Disable #sidebar shrinking run
E5b: ordered shrinking and restoration Force the expanded sidebar to 200px run, from the E5 sidebar-shrink mutation; the 200px mutation itself was not run
E6: vertical zoom Give #tool-bar a negative strip-height top margin run
E7: focused grid card Hide #tool-bar in grid mode run
E8: native Tab traversal Set every visible enabled tool button's tabindex to 0 run