moadim 0.20.0

Loop engine for AI agents — routines over REST, MCP, and a built-in web UI
name: Test

# Mirror the local pre-push hook's test gate in CI, so the test suite is
# 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`
# lived solely in the pre-push hook, so a PR that skipped hook setup could break
# tests and still go green.
#
# This relies on the committed `prebuilt.html` (build.rs falls back to it when
# trunk is absent), so no trunk or wasm target is needed to build and test the
# server crate. The command mirrors CONTRIBUTING.md's documented pre-push gate
# (`cargo test`) — keep the two in lockstep.
#
# NOTE: the pre-push hook also enforces a 100% line-coverage floor
# (`cargo llvm-cov --fail-under-lines 100 --ignore-filename-regex 'src/main\.rs'`).
# That gate is intentionally NOT added here yet: the tree is currently below
# 100% line coverage on current stable Rust, so a `--fail-under-lines 100` CI
# job would be red on arrival and block every PR. Enforcing it in CI is tracked
# as follow-up work once the coverage gap is closed (see issue #150).
#
# The `coverage` job below DOES run the same `cargo llvm-cov` command (same
# --ignore-filename-regex exclusion, so the number is comparable to the local
# hook) and publishes it as a step summary table. It deliberately omits
# --fail-under-lines, so it only reports the metric and can never fail the
# build on coverage percentage (see issue #526).

# 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@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          ref: ${{ inputs.ref }}

      - name: Install Rust
        uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1
        with:
          toolchain: stable

      - name: Cache cargo registry and target/
        uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
        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 (report only)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

      - name: Install Rust (with llvm-tools-preview)
        uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1
        with:
          toolchain: stable
          components: llvm-tools-preview

      - name: Cache cargo registry and target/
        uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
        with:
          # Scoped so this job's target/ artifacts (built with llvm-cov's
          # instrumentation flags) don't clobber the `test`/`clippy` jobs'
          # cache entries.
          shared-key: coverage

      - name: Install cargo-llvm-cov
        run: cargo install --locked cargo-llvm-cov

      - name: Generate coverage summary
        # Mirror the pre-push hook's `cargo llvm-cov` invocation, including
        # the same --ignore-filename-regex exclusion, so this number stays
        # comparable to the local hook's. This is deliberately non-gating:
        # --fail-under-lines is NOT passed, so this step (and the job) can
        # never fail the build on coverage percentage — it only surfaces the
        # metric on the PR. See the NOTE above and issue #526.
        run: |
          {
            echo '## Code coverage (report only, not gating)'
            echo ''
            echo '```'
            cargo llvm-cov --ignore-filename-regex 'src/main\.rs' --summary-only
            echo '```'
          } >> "$GITHUB_STEP_SUMMARY"