Automation

The automation server exposes runtime state and accepts commands via a file-based protocol. Use it for integration testing, CI smoke tests, and inspecting running apps.

Enabling automation

Build with the automation flag:

zig build run-webview -Dautomation=true

In your runner, pass an automation.Server to RuntimeOptions:

const server = zero_native.automation.Server.init(io, ".zig-cache/zero-native-automation", "My App");
var runtime = zero_native.Runtime.init(.{
    .platform = my_platform,
    .automation = server,
});

The default directory is .zig-cache/zero-native-automation.

File protocol

When the runtime publishes a snapshot, it writes these files to the automation directory:

FileDescription
snapshot.txtRuntime state: app name, source kind, window metadata, ready=true/false
accessibility.txtAccessibility tree summary
windows.txtWindow list: window @w{id} "{title}" focused={bool} per line
screenshot.ppmScreenshot in PPM format (currently a 2x2 placeholder)
command.txtCommand input: written by the CLI, consumed by the runtime
bridge-response.txtJSON response from the last bridge command

Commands

The runtime polls command.txt and processes these actions:

ActionDescription
reloadReload the WebView source
waitBlock until the snapshot shows ready=true
bridge <json>Send a bridge command with origin zero://inline

After processing a command, the runtime writes done to command.txt.

CLI usage

The zero-native automate subcommand interacts with the automation directory:

# Wait for the app to be ready (polls snapshot.txt for ready=true)
zero-native automate wait

# List running automation-enabled apps
zero-native automate list

# Dump the current snapshot
zero-native automate snapshot

# Capture a screenshot
zero-native automate screenshot

# Reload the WebView
zero-native automate reload

# Send a bridge command and get the response
zero-native automate bridge '{"id":"1","command":"native.ping","payload":{"source":"automation"}}'

Testing with automation

The test-webview-smoke build step demonstrates a full automation test flow:

  1. Build and start the app with -Dautomation=true
  2. Run zero-native automate wait to block until the app is ready
  3. Run zero-native automate snapshot to verify window metadata and source kind
  4. Run zero-native automate bridge '...' to test the native bridge round-trip
  5. Verify the response in bridge-response.txt
zig build test-webview-smoke -Dplatform=macos

Custom directory

Pass a custom path to automation.Server.init():

const server = zero_native.automation.Server.init(io, "/tmp/my-app-automation", "My App");

The CLI reads from the default .zig-cache/zero-native-automation unless you specify a directory via the automation subcommand.