name: Test
# Mirror the local pre-push hook's test and coverage gates in CI, so they are
# enforced on every PR even when a contributor (or a fork) hasn't installed the
# git hooks. Previously CI ran only fmt + clippy (see lint.yml); `cargo test`
# and the 100% line-coverage floor lived solely in the pre-push hook, so a PR
# that skipped hook setup could break tests or drop coverage and still go
# green.
#
# This relies on the committed `prebuilt.html` (build.rs falls back to it when
# pnpm is absent), so no pnpm step is needed to build and test the server
# crate. Both commands mirror CONTRIBUTING.md's documented pre-push gate —
# keep the hook, CONTRIBUTING.md, and this workflow in lockstep.
#
# `client/` isn't a Cargo workspace member, so `cargo test` never runs its
# Vitest suite. The `client-test` job below mirrors the pre-push hook's
# `pnpm --filter client test` step in CI. The `client-screenshots` job also
# runs the mocked Playwright UI screenshot capture so PRs exercise the visual
# baseline flow in CI. Exact binary PNG freshness stays in
# `pnpm --dir client run test:e2e:screenshots:check` for developer machines,
# because Linux runner fonts and antialiasing can legitimately differ from the
# committed review baselines.
# Restrict the default GITHUB_TOKEN to read-only; this workflow only needs to
# read repository contents to check out and run the test suite.
permissions:
contents: read
on:
pull_request:
push:
branches: [main]
workflow_call:
inputs:
ref:
description: >
Git ref to check out. Empty (the default) means "use the ref that
triggered this run" — set only by changeset-release.yml, which
calls this workflow directly to test a branch (changeset-release/main)
other than the one that triggered it.
required: false
type: string
# Cancel a stale run when a PR gets a new push, matching lint.yml's behavior
# so superseded test runs don't pile up and burn CI minutes. Literal "test"
# prefix, not ${{ github.workflow }} — see lint.yml's comment: workflow_call
# callers (cut-release.yml) would otherwise collide lint and test onto the
# same concurrency group and race-cancel each other.
concurrency:
group: test-${{ inputs.ref || github.ref }}
cancel-in-progress: true
jobs:
test:
name: cargo test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.ref }}
- name: Install Rust
uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # v1
with:
toolchain: stable
- name: Cache cargo registry and target/
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
with:
# Scoped so the `test` and `clippy` jobs' target/ artifacts (built
# with different flags: plain build vs --all-targets clippy) don't
# clobber each other's cache entry.
shared-key: test
- name: Run tests
run: cargo test
coverage:
name: cargo llvm-cov (100% line floor)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install Rust (with llvm-tools-preview)
uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # v1
with:
toolchain: stable
components: llvm-tools-preview
- name: Cache cargo registry (registry only, not target)
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Install cargo-llvm-cov
run: cargo install cargo-llvm-cov --locked
- name: Enforce 100% line coverage (excluding main.rs and test modules)
run: cargo llvm-cov --fail-under-lines 100 --ignore-filename-regex 'src/main\.rs|.*_tests.*\.rs|src/routines/command_builder\.rs|src/cli/restart\.rs|src/cli/start\.rs|src/cli/system\.rs|src/cli/wait_until\.rs|src/machine/write_machine_toml\.rs|src/middlewares/logger\.rs|src/read_runtime_state\.rs|src/routes/http_listener\.rs|src/routes/http_settings_routes\.rs|src/routes/move_routine/cli\.rs|src/routes/move_routine/http\.rs|src/routines/cleanup/log_cap\.rs|src/routines/cleanup/ttl\.rs|src/routines/defaults/write_removed_defaults\.rs|src/routines/next_run_at\.rs|src/routines/service\.rs|src/routines/service_log_tail\.rs|src/routines/service_move\.rs|src/routines/service_update\.rs|src/routines/svc_create\.rs|src/routines/validate_machines\.rs|src/service/macos\.rs|src/service/request_automation_permission\.rs|src/sync/wait_for_crontab_write\.rs|src/utils/atomic\.rs|src/utils/claude_json\.rs|src/run_server\.rs|src/service/linux\.rs'
client-test:
name: client (vitest)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.ref }}
- name: Install pnpm
uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10
- name: Install Node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 22
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run tests
run: pnpm --filter client test
client-screenshots:
name: client (screenshot e2e)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.ref }}
- name: Install pnpm
uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10
- name: Install Node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 22
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Install Chromium
run: pnpm --dir client exec playwright install --with-deps chromium
- name: Run UI screenshot capture
run: pnpm --dir client run test:e2e:screenshots