Testing¶
What Hearth's test suites cover, so you know what a green run proves. How to run them is in Development.
The layers¶
| Suite | Where | Runs in CI | Needs |
|---|---|---|---|
| Rust unit and integration tests | cargo test --workspace |
Yes | A Redis for the store tests (HEARTH_TEST_REDIS) |
| Agent flow tests | crates/hearth-agent/tests |
Yes, with the workspace | Nothing: a fake device and a fake gateway |
| UI unit and browser tests | ui/: npm test, npm run e2e |
Unit tests yes | The mock gateway in ui/mock |
| Chart checks | helm lint, helm template, CRDs match the code |
Yes | Helm |
| Farm end to end | e2e/run.sh |
Yes, on kind with images built from the change | A farm and kubectl |
| Devices end to end | e2e/run-devices.sh |
No | A Mac with Xcode, an Android SDK and Appium |
Farm end to end (e2e/run.sh)¶
Real Playwright, Selenium and WebSocket clients against a running farm. Device tests skip
themselves when the farm has no device pools; chaos tests skip without kubectl access.
| File | Scenario | Checks |
|---|---|---|
playwright.test.mjs |
Chromium, Firefox and WebKit: a whole browser per session | newContext works more than once; the session ends done with video.mp4 |
| Headless launch | x-playwright-launch-options {headless: true} is honoured; no video |
|
| A burst larger than the warm pool | Every session queues and finishes (HEARTH_BURST, default 5) |
|
| Wrong client version | Refused before connecting: runs Playwright 1.65 for chromium, not 1.10 |
|
| Unknown key or engine | 401 for a bad key, 404 for /playwright/edge |
|
| Video download | GET /api/sessions/{id}/artifacts/video.mp4 is a real MP4; a missing artifact is 404 |
|
cdp.test.mjs |
connectOverCDP on Chromium |
A page loads, a CDP session answers Browser.getVersion, video recorded |
| CDP on Firefox | Refused (404) |
|
selenium.test.mjs |
Selenium Chrome and Firefox through /wd/hub with basic auth |
Find, type, screenshot, quit; session done with video |
| Errors | W3C session not created for browserName: safari; invalid session id for an unknown session |
|
| Status | /wd/hub/status answers ready: true without a key |
|
ui-api.test.mjs |
Web UI sign-in | POST /api/auth/login sets an HttpOnly SameSite=Strict cookie that works for the API; a bad key is 401 |
| Pools | /api/pools lists Playwright and WebDriver pools |
|
| Live view, take control, stop | The MJPEG stream has JPEG frames; text typed over the control WebSocket reaches the page; DELETE ends the session as stopped by a user |
|
| Team isolation | Another team's session id answers 404 |
|
limits.test.mjs |
A team limited to one session | The second session gets 429 with Retry-After and limit of 1; the slot comes back after the first ends |
apps.test.mjs |
App upload | Upload by content gives hearth:app:<sha256> and lists it; .ipa and empty uploads are 400 |
| App by URL | A device session with appium:app set to a URL is refused: upload the app first |
|
chaos.test.mjs |
A browser pod killed mid-session | The session fails with went away, the team slot comes back, new sessions work |
| Redis restarted (state lost) | Sessions work again within 3 minutes | |
| Operator and gateway restarted | Sessions work again within 3 minutes |
Devices end to end (e2e/run-devices.sh)¶
Real devices on the machine running the tests: one Android emulator (pixel-api35) and two iOS
simulators (iphone17-ios27, ipadair11-ios27), served by a hearth-agent the script starts.
The test apps come from e2e/fixtures/build-apps.sh: a one-screen iOS app (HearthDemo.app.zip,
built with Xcode) and Appium's settings app as a small APK.
| Scenario | Checks |
|---|---|
| iOS iPhone and iPad: install, tap, live view, take control, video | The uploaded app installs and launches; two taps change its label; a live frame is a JPEG; the control WebSocket says kind: device (and landscape for the iPad); a tap sent through take control reaches the app; the session ends done and video.mp4 arrives |
| Android: install, run, live view, video | The APK installs and is the current package; screenshots work; a live frame is a JPEG; the home button from take control leaves the app; done with video.mp4 |
| Host-reaching capabilities and commands | appium:app pointing at a metadata URL is refused; a session with appium:chromedriverExecutable still starts (the key is dropped); mobile: shell and mobile: installApp are refused as not allowed |
| Idle device session | A session with no commands ends as failed with no command for too long, and the emulator is ready again (skipped with HEARTH_SKIP_SLOW) |
Agent flow tests¶
crates/hearth-agent/tests/agent_flow.rs drives the agent against a fake gateway and fake
devices:
- heartbeats report devices with ids under the host's prefix;
- calls without the agent token are refused;
- a prepare and release cycle downloads the app, uploads the artifacts and resets the device;
- an app whose checksum does not match fails
prepareand frees the device; - unknown device ids and bad session ids are refused;
- two failed resets mark a device
failed, and it recovers; - the live view serves multipart JPEG.
Unit tests next to the code cover the config file (defaults, device ids and ports, iPads in
landscape, invalid hosts and keys) and the zip checks (.. entries, escaping symlinks, writing
through a symlink, exactly one .app).
What is not covered by automated tests¶
- Your own S3, GCS, R2 or MinIO bucket: only the bundled SeaweedFS is exercised.
- In-cluster emulator pods: they need nodes with
/dev/kvm, which CI runners do not have. - Node autoscalers and large bursts: the burst test is small.
- The Grafana dashboard and the ServiceMonitor are rendered by
helm templatebut not loaded into Prometheus or Grafana.