BakeNative is under active development. APIs may change.
Skip to Content
BakeNative

UI parity testing

Deterministic proof that one Octane app renders the same on the web and on every native target, with Chromium as the reference.

The same .tsrx app must look identical on every target where no platform code is involved. Three test layers check this automatically, with no model calls:

LayerWhat it comparesWhereCommand
1. Headless parityChromium (dist/web, the reference) vs the Rust core (dist/mac through bake snap: the layout every host applies, painted offscreen): element rects and pixels at 3xtests/parity, native/rust/crates/bake-snappnpm test:parity
2. e2e flowsReal targets: web (Playwright WebKit) and the iOS brownfield app on a simulator, driven by locators; per-target screenshot baselines, then web vs iOStests/e2epnpm test:e2e
3. parity5The real hosts on five targets: Chromium (the reference) vs the iOS simulator, macOS, Android and Windows, node by node and pixel by pixel, snapshot frame and hydrated screentests/e2e/parity5pnpm --filter @bake-native/e2e-tests parity5

Layer 1 is the precise, CI-able check. Layer 2 proves the shipped apps behave the same (tap → state → pixels) and catches host-level regressions.

Layer 1: headless parity

examples/app ── bake build ─┬─ dist/web ── Playwright Chromium ── web.json + web.png
                           └─ dist/mac ── bake snap ──────────── native.json + native.png
                                              │
                         Hermes first commit → bake-core HostTree → Document (CSS + layout +
                         CoreText text) → tiny-skia painter per node (sRGB, y-down, scale)
  • bake snap (the Rust bake-snap, native/rust/crates/bake-snap) runs app.hbc once in a throwaway Hermes, lays the first commit out with the Rust core's Document (CoreText text) at a viewport and color scheme, and paints every node with tiny-skia (glyphs through CoreText) into an offscreen bitmap. It doesn't use a window or views. Buttons and inputs are painted as their CSS boxes, which is what the renderers draw. It writes every rendered node (element path such as 0/2/1, tag, role, document-space rect) and a PNG of the whole document. Two runs must produce identical bytes, and the runner checks this on every case.
  • Web (tests/parity/lib/web-snap.mjs) serves dist/web, opens it in Playwright Chromium (sRGB, grayscale glyph AA, no scrollbars; Chrome is the reference) at the same viewport, device scale and prefers-color-scheme, disables transitions, waits for document.fonts.ready plus two frames with identical geometry, then writes the same JSON (same element-path walker as the dev tool's WebPreview) and a full-page PNG.
  • Compare (tests/parity/lib/compare.mjs) checks the following:
    • Rects. Every native node must exist on the web at the same element path with the same tag and an x/y/width/height within 0.5 px. A web element with a box that native doesn't draw fails unless it is inline content of a native text, SVG or button node. The document size must match within 1 px.
    • Pixels. A device pixel differs when an RGB channel differs by more than 12/255, unless it is a tolerated edge. A pixel is a tolerated edge when a pixel within 1 device px in the other image matches it (glyph antialiasing, sub-pixel edges), or when the 3×3 box-averaged colors match (the same ink distributed differently, such as fractional vs pixel-snapped borders). Flat areas are never tolerated, so a wrong color always counts. The case fails if more than 0.1 % of pixels differ, or more than 4 % of any 32×32 CSS px tile.
    • A diff PNG paints tolerated edges yellow, differing pixels red and known issues blue.

The matrix is phone 390×844, tablet 820×1180 and desktop 1280×800, all at 3x, each in light and dark. 3x is used everywhere because a 2 px shift is then 6 device px, far outside the edge tolerance.

Measured (examples/app, default Starter screen)

With the Rust core (2026-11-25, Chromium 159): rects 33/33 in every case (max Δ 0.30 px), but pixels 0.5–1.1 % of the document differ (worst tile 10.9–13.6 %), along every text edge: the painter's glyph rasterization differs from Chromium's. pnpm test:parity fails on pixels until it matches; pnpm check gates rects and holds pixels at that baseline. The numbers below are the frozen Swift painter against WebKit.

Self-test

pnpm test:parity:selftest injects small regressions into the web page only, at phone (3x) and desktop. The unmodified baseline must pass, and each mutation must fail on the check it targets:

MutationFails onWorst tile (phone / desktop)
.title 2 px lowerrects20.6 % / 17.8 %
counter button label 2 px lower inside an unchanged boxpixels10.5 % / 11.9 %
card title indented 2 pxpixels26.4 % / 35.1 %
lede color token swappixels18.7 % / 17.6 %
counter button background Δ≈18/255pixels69 % / 70 %
card border colorpixels6.3 % / 6.3 %
card radius 14.4 → 4 pxpixels5.4 % / 5.6 %

The 4 % tile limit sits between today's noise (at most 2.3 %) and the weakest mutation signal (5.4 %).

Known issues

parity.config.json → knownIssues lists real divergences that can't be fixed in the test. Each entry is matched by tag + text prefix, not path, so it survives app restructuring. Its element (the union of its native and web rects) is masked out of the pixel comparison but still rect-checked. The report states whether the issue still reproduces, and an entry that matches nothing, or no longer differs, is flagged for removal.

None are open right now. (The last one, from when WebKit was the reference, was a line break: CoreText followed UAX #14 where the browser breaks after every space; the Rust core's bake_text::TextBlock takes the browser's break opportunities. Chromium is the reference now.)

Run

pnpm hermes                         # once: Hermes VM + hermesc
pnpm --filter @bake-native/parity-tests exec playwright install chromium   # once
pnpm test:parity                    # build web + mac, 6 cases (bake snap builds on first use)
pnpm test:parity -- --no-build --only phone,dark
pnpm test:parity -- --set maxTileDiffRatio=0.03     # override a tolerance
pnpm test:parity:selftest

Output: tests/parity/.out/report/<viewport>-<scheme>/ (native.png, web.png, diff.png, both JSONs), summary.md and report.json. The command exits non-zero on failure. There are no baselines: each run compares web with native directly, so nothing needs updating after an intended UI change. Tolerances live in tests/parity/parity.config.json.

Layer 2: e2e.com flows

tests/e2e uses e2e with two targets and locator-only tests. It uses no agent.* steps, so it needs no model, sign-in or API key. It requires Node ≥ 24.8 (or ≥ 22.22.3).

  • web serves .out/web (built by build.mjs from examples/app at git HEAD, so uncommitted work doesn't leak in; APP_ROOT=<dir> overrides) in Playwright WebKit at 440×956, the iPhone 17 Pro Max point size.
  • ios runs dev.bakenative.examples.brownfield on an existing simulator. E2E_IOS_DEVICE (a name or UDID) is required: no config picks a simulator on its own, and none is ever created. The agent-device session defaults to e2e-ios-<udid>, so runs on different simulators never share one and opens Octane screen (UIKit) from the native catalog. The installed app must be built from the same examples/app as the web target (pnpm ios, then xcodegen + xcodebuild + simctl install). The simulator must not be held by another agent-device session. It must be set up as the baselines expect: language and region en-US and the US keyboard first (a run on a simulator with another language or keyboard fails up front; node tests/e2e/agent-device-runner.mjs sim-defaults --udid <udid> --fix sets them and reboots it). Each run puts the appearance and text size back to light and large. On the bake simulators a run also fails while a News or Reminders widget is on the home screen: the system reloads a widget whenever the appearance or text size changes, and News's widget extension then takes most of a core for minutes, which skews flicker and parity timing (node tests/e2e/agent-device-runner.mjs sim-widgets --udid <udid> --fix takes those widgets off, nothing else, and boots the simulator again).

The native-view suite uses @e2e-dev/desktop to drive the AppKit app through macOS Accessibility. Its iOS target uses @e2e-dev/mobile with agent-device. Build the Mac app and check permissions before running its target.

node tests/e2e/native-view/build.mjs
pnpm --filter @bake-native/e2e-tests exec e2e doctor --config e2e.native-view.config.ts --target macos
pnpm --filter @bake-native/e2e-tests exec e2e run --config e2e.native-view.config.ts --target macos

Grant Accessibility to the app that launches e2e. Grant Screen Recording for screenshots. The desktop engine uses a single worker and launches a fresh app for each test. The first-frame suite uses ScreenCaptureKit video. The clock, inspect, locales, and first-screen suites use Bake's inspect transport for clock control and adoption diagnostics. Desktop engine reference

Use the project's e2e skill in .agents/skills/e2e when adding or updating a test. Arrange each test's starting state independently. Use locators and retrying assertions to wait for UI state. Keep frame sampling intervals explicit in tests that measure time or capture a video.

The flow is: open → Count: 0 visible → screenshot → tap the button → Count: 1 visible → screenshot. Baselines are stored per target as tests/counter.e2e.ts-snapshots/counter-{0,1}-{web,ios}-darwin.png. The native HUD (launch timings) is masked.

e2e compares each target only with its own baseline. cross-compare.mjs then compares web with iOS for the same step:

  1. It finds the iOS content top by aligning the two images vertically (117 pt under the brownfield navigation bar).
  2. It masks iOS rows above 116 pt (status and navigation bar), in case the content ever slides under the translucent bar. With today's layout the content starts at 117 pt, so this mask is empty. It also excludes e2e's mask color (the HUD).
  3. It runs the same classifier as layer 1 with a channel threshold of 16, at most 0.6 % differing pixels and at most 18 % per tile.

Screenshots are at 1x (e2e stores device screenshots at point size), so noise is relatively higher: 0.44 % of pixels and 13.3 % in the worst tile, from the 48 pt title. pnpm --filter @bake-native/e2e-tests cross:selftest checks that a 2 pt shift of the densest text band, erased text and a wrong color region are all caught. At 1x a 2 pt shift of small body text stays close to the noise floor, so layer 1 is the precise geometry check.

pnpm ios && (cd examples/ios-brownfield && xcodegen generate && xcodebuild … && xcrun simctl install <UDID> …)
pnpm test:e2e                      # build web, e2e run (web + ios), cross-compare
cd tests/e2e && npx e2e run --target web
npx e2e run --update-snapshots     # after an intended UI change: review, commit the PNGs

Run the iOS target with a warm frame cache. The first open after installing (or after Clear cached frames) mounts from scratch, and its HUD is one line shorter, which moves the masked area. Record and compare baselines after one prior open. Baselines are per OS (-darwin), so record CI's own baselines from a CI job with -u.

Android and Windows

The Android and Windows regression tests run on the same e2e runner, each with its own config in tests/e2e:

ConfigDeviceTests
e2e.android.config.ts (pnpm e2e:android)An emulator this machine's adb server sees (E2E_ANDROID_SERIAL)flicker (first screen == settled screen: mount, baked, held and resized, frame cache, prewarm, font scale), parity5 against Chromium, a11y (uiautomator dump against the core's semantic tree), the red error overlay
e2e.android-app.config.ts (pnpm e2e:android-app)The sameexamples/android: E2EProbe flicker, tabs, Gboard input (Korean, ASCII, hardware Enter), the dark mode toggle, prewarm; the network transport (examples/fetch, examples/images); the Video native view
e2e.pc-android.config.ts (pnpm e2e:pc-android)The Windows PC's emulator, from another machine through its agent-device proxythe counter flow, and flicker, parity5 and a11y with the PC's adb server (E2E_ADB_SERVER_SOCKET)
e2e.windows.config.ts (pnpm e2e:pc)The Windows desktop session, through our engine server (@bake-native/testing/windows-engine.mjs)counter, UI Automation tree and events, the error overlay, parity5, flicker (snapshot frame == adopted frame, live and held)

The Android tests drive the device through an adb fixture (tests/e2e/android/fixtures.mjs): display and font scale overrides, bundle pushes into the debug app, the test activity's intents, and captures at device pixels (screencap, the in-app PixelCopy dumps), because e2e stores device screenshots at 1x. Taps and text go through e2e's locators. Overrides are undone when the worker ends.

Restarting the Windows emulator (when its GPU pipe stalls and every cell times out): stop only its own emulator.exe and qemu-system-x86_64.exe, then start it again with the same command line plus -no-snapshot-load (a cold boot). If the AVD lives outside %USERPROFILE%\.android\avd, set ANDROID_AVD_HOME to its folder, or the emulator exits with "Unknown AVD name". Start it through Win32_Process.Create (WMI) rather than from a tool's shell: a shell that ends takes its child processes with it.

What tests/e2e holds

Each directory is one regression area; its config (e2e.<name>.config.ts) or script says which targets it runs on and how to build what it drives.

TestsConfig or commandWhat they check
tests/counter.e2e.tse2e.config.ts (web, iOS), e2e.windows.config.tsOpen the Octane screen, tap the counter, check the label, a screenshot baseline per target (then cross-compare.mjs)
tests/radio-group.e2e.tsweb, iOS, e2e.android.config.ts, e2e.windows.config.tsRadios of one group tapped in turn: only the last stays checked
tests/back-swipe.e2e.tsiOSThe system back swipe over a pushed Octane screen with a horizontal card strip: only the edge swipe pops
tests/fixed-drag.e2e.tsiOSA drag on a position: fixed view after the page scrolled; a left-edge drag on touch-action: none content is not a back swipe; a child painted outside a non-clipping box takes taps
tests/keyboard-dialog.e2e.tsiOSA text field in a fixed Dialog (examples/shadcn) and the soft keyboard
tests/scroll-tap.e2e.tse2e.windows.config.tsA tap after the page scrolled lands where the node is on screen
flicker/e2e.flicker.config.ts (iOS), e2e.android.config.ts, e2e.windows.config.tsThe snapshot's first frame equals the frame after JS adopted it, pixel for pixel (mount, baked, held, resized, frame cache, prewarm, font scale)
parity5/e2e.parity5.config.ts (iOS), e2e.android.config.ts, e2e.windows.config.ts, e2e.rejudge.config.tsLayer 3; rejudge judges saved cells again with no device
a11y/e2e.android.config.ts, e2e.windows.config.tsThe Android AccessibilityNodeInfo tree and the Windows UI Automation tree hold the core's roles, names and reading order
a11y-overlays/e2e.a11y-overlays.config.ts (web, iOS)Overlay roles and states and a modal dialog's focus; Chromium's accessibility tree is the reference
error-overlay/e2e.android.config.ts, e2e.windows.config.tsThe red error overlay on a debug core
android-app/e2e.android-app.config.tsexamples/android: flicker, tabs, Gboard input, dark mode, prewarm, the network transport (net), <video>
pc-android/e2e.pc-android.config.tsThe counter on the Windows PC's emulator through its agent-device proxy, timed per step
inspect/e2e.inspect.config.ts (web, Windows)examples/inspect with the same clock and network fixtures on both targets, through bake inspect on Windows
ui-sdk-showcase/e2e.ui-sdk-showcase.config.ts (web, iOS)The service filter's first keystroke stays typed while a sibling is inserted
showcase/e2e.showcase.config.ts (web, iOS)The docs demo flows, recorded to docs/public/videos
first-frame/e2e.first-frame.config.ts (iOS, Android, macOS)Tap a catalog row to the screen's first frame, read from the device's screen recording (macOS: the window through ScreenCaptureKit, screen recording permission): no blank frame, within 500 ms; a stale app.baked is never shown (first-frame/README.md)
system-modules/, module-events/, video/, element-api/node --test (pnpm --filter @bake-native/e2e-tests <name>)The registry modules' web implementations, module events, <video> and the element APIs in Playwright Chromium (video/ios.mjs and element-api/ios.mjs run the same checks on the simulator)
android-coldstart/, android-fps/, android-prewarm/node tests/e2e/<name>/run.mjsAndroid measurements: cold start from logcat, frame pacing of the showcase, open to first frame with and without a prewarm

The shared agent-device daemon

Every iOS and Android run on a machine talks to one agent-device daemon per state directory (~/.agent-device unless AGENT_DEVICE_STATE_DIR says otherwise), whichever worktree started it. Which copy of agent-device started it does not matter as long as the version is the same: published copies are all installed and are never replaced for their path. The daemon exits by itself 5 minutes after its last request, and the next run starts a new one from its own worktree.

Stock agent-device lets one SDK client (createAgentDeviceClient with the default managed lifecycle, which is what mobile() uses) end the daemon for everyone:

  • A timed-out request. Most commands give a request 90 s. When one runs longer, the client asks the daemon for its session list. If no answer comes within 1 s (a busy daemon, a stuck device), the client force-kills the daemon. Every session on it dies, including other runs on other simulators.
  • An "unreachable" daemon. Before each request the client connects to the daemon's port: a 500 ms connect, three retries 200 ms apart. If that fails while the process is alive, the client retires the daemon (SIGTERM) and starts its own. The CLI prints Replaced unreachable daemon (pid N, v…) in <dir>.; an SDK client (mobile()) prints nothing. A client that asks for the HTTP transport (AGENT_DEVICE_DAEMON_TRANSPORT=http) from a socket-only daemon fails this check against a healthy daemon.
  • Another version or code. A daemon of another agent-device version (or a source checkout against a published copy) is asked to quiesce. A daemon with open sessions refuses and the client's request fails; an idle one is replaced (Replaced idle daemon … it did not match this client). The install path does not count: every published copy of the same version is installed, and their code signatures are never compared, so worktrees with different node_modules (or another patch hash) share one daemon.

The CLI and SDK use the same patched local daemon decision in dist/src/daemon-client-lifecycle.js. The workspace pins both the direct CLI and mobile() to the copy with patches/agent-device@0.21.46.patch. The Windows PC's Android proxy must run the same agent-device version as mobile().

  • A timed-out request is canceled and the daemon stays up. Set AGENT_DEVICE_DAEMON_TIMEOUT_RETIRE=1 to get the stock behavior back. Nothing resets a hung daemon by itself any more: when no other run is using it, stop it with agent-device daemon stop --state-dir ~/.agent-device.
  • A daemon whose process is alive gets 15 s of retries before it counts as unreachable (AGENT_DEVICE_DAEMON_UNREACHABLE_GRACE_MS), on both paths. A dead daemon is still replaced right away.
  • Both paths keep a live daemon that answers when the client would otherwise replace it for a version or code mismatch. The client prints a warning. Set AGENT_DEVICE_DAEMON_REPLACE_MISMATCHED=1 to restore stock replacement behavior.

pnpm --filter @bake-native/e2e-tests runner:selftest checks that the installed agent-device carries the patch.

What a run does around the daemon

  • The daemon starts outside the run's process tree. agent-device starts its daemon detached (its own session and process group), so a SIGTERM to the run's process group (timeout, Ctrl-C) does not reach it. But the daemon stays the child of the process that started it until that process exits. When the first request comes from an e2e worker, the daemon is the worker's child for the whole run, and anything that kills the run's process tree (a tool or agent timeout walks children by ppid) kills the daemon too, with every other run's sessions. So every e2e run with an ios target starts the daemon before any worker, from a short-lived agent-device session list, after which it belongs to launchd (ensureDaemon in tests/e2e/agent-device-runner.mjs; node agent-device-runner.mjs ensure-daemon by hand). A daemon that already runs is used as it is. If it is still someone's child, the run says so.
  • One run per session name. A run takes <state dir>/bake-e2e-locks/<session>.lock (lockSession) for its E2E_IOS_SESSION and holds it until its exit hooks are done. A second run with the same session name is refused with the holder's pid and directory, or waits with E2E_SESSION_LOCK_WAIT_MS=<ms>. The lock records the holder's pid and start time, so a lock left by a killed run is taken over.
  • Cleanup touches only this session's processes. After the run, agent-device-runner.mjs cleanup stops the XCUITest runner that this session's runner.log names, by pid, after checking its exact command line. It never stops processes by name or pattern, never the daemon, and never another session's runner.
  • The daemon never ends a run. Nothing in the harness stops the daemon, and the patched client does not retire a daemon that is alive and answering.

Rules for shared machines:

  • Run agent-device from the workspace: mobile() uses the patched copy, and scripts in tests/e2e call agentDevice() / agentDeviceCommand() from agent-device-runner.mjs. The global agent-device on PATH and worktrees without the patch still have the stock behavior.
  • Never stop, restart or replace the daemon while another run uses it. To experiment, use your own state directory: AGENT_DEVICE_STATE_DIR=$(mktemp -d) or --state-dir.
  • Stop processes only by the pids your own run started. No pkill, killall or pattern matches: on a shared machine they hit other runs' runners and the daemon.
  • Give every concurrent run its own E2E_IOS_SESSION (the default, e2e-ios-<udid>, already differs per simulator). Do not start the same command twice; the second one is refused while the first holds the session.
  • If you start a long run under a time limit that kills the whole process tree (an agent tool's timeout), run node tests/e2e/agent-device-runner.mjs ensure-daemon first when no run is active, or let the run start the daemon itself, so the daemon is not part of that tree.
  • Leave AGENT_DEVICE_DAEMON_TRANSPORT and AGENT_DEVICE_DAEMON_SERVER_MODE unset on shared machines.
  • After a version bump of agent-device, port the patch and check the daemon client code again (dist/src/daemon-client-lifecycle.js).

Layer 3: parity5 on every host

tests/e2e/parity5 runs the example screens on the real hosts and compares each with Chromium at the same viewport and device scale. Every target gets the same deterministic variant of the app: one test font loaded with @font-face, no animations, a frozen clock and a seeded Math.random. Each native dump is taken twice and must be identical. The Chromium reference must be deterministic too: each web cell runs in two separate launches whose dumps and screenshots must match exactly, and the page is rasterized once more right before the capture so late-decoded images do not change edge pixels.

Besides the example screens, three full apps run in more than their first state (light and dark, phone, tablet and desktop sizes, some scrolled): the Norrow shop demo, the showcase market list and an inbox app made for this gate.

  • Structure. Debug hosts dump the laid-out tree (element paths, on-screen rects, paint values). Rects must be within 0.5 CSS px of where Chromium paints the element; colors within 2/255 per channel.
  • Pixels. A pixel differs above 12/255 per channel. A cell fails above 0.1 % of the viewport or 4 % of any 32 CSS px tile. Platform UI (native controls, the system navigation bar, SwiftUI) is masked and checked against per-device baselines instead.
  • Snapshot vs hydrated. On iOS the baked first frame and the hydrated screen must match exactly.
pnpm --filter @bake-native/e2e-tests parity5            # iOS and macOS cells, summary
E2E_ANDROID_SERIAL=<emulator> pnpm --filter @bake-native/e2e-tests parity5:android   # build, then the e2e cells
pnpm --filter @bake-native/e2e-tests parity5:windows    # on Windows: the e2e target windows-parity5
pnpm --filter @bake-native/e2e-tests parity5:web        # the Chromium reference alone, at 1x, 2x and 3x
pnpm --filter @bake-native/e2e-tests parity5:selftest   # the comparator on synthetic dumps

Results go to tests/e2e/.e2e/parity5/summary.md, with one directory per cell holding report.json, the native and Chromium PNGs and the diff images. The full method is in tests/e2e/parity5/README.md.

CI

.github/workflows/parity.yml (workflow CI) runs on a macOS runner for every pull request and every push to main:

  • pnpm check (macOS): the whole pnpm check (tools/check.mjs), which includes layer 1, then the layer 1 self-test (reported, not gating). The reports are uploaded as an artifact.
  • Apple e2e (macOS): native/rust/apple/e2e.sh, the Rust core with CoreText and real Hermes over the baked example bundles.

Both restore the Hermes build (native/hermes/artifacts, macOS slice with the static VM) from the Hermes (macOS) job, which builds it only when the pinned SHA in tools/build-hermes/Plugins/BuildHermes/plugin.swift or the plugin changes. The cargo target directory and SwiftPM's .build directories are cached from main; pull requests restore them without saving. Layer 2 needs a booted simulator with the app installed, so it runs locally.

On this page