name: ci

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: cargo build --all-targets
      - run: cargo test --all-targets

  fmt:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - run: cargo fmt --all -- --check

  clippy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - uses: Swatinem/rust-cache@v2
      - run: cargo clippy --all-targets -- -D warnings

  demo-detached:
    # Runs demo-detached.sh end-to-end: local relay + two daemons + full
    # detached pair handshake + signed send/recv. Catches regressions that
    # only surface under the real CLI surface (process spawning, FIFO/IO
    # buffering, daemon lifecycle).
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: sudo apt-get update && sudo apt-get install -y jq
      - run: cargo build --release --bin wire
      - run: WIRE=./target/release/wire bash demo-detached.sh

  demo-invite:
    # Runs demo-invite.sh end-to-end: local relay + paul + willard + one-paste
    # invite-URL pair + bidirectional signed send/recv. Catches regressions in
    # the v0.4.0 pair_drop hook, daemon-pull cursor persist, and CLI wiring.
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: sudo apt-get update && sudo apt-get install -y jq
      - run: cargo build --release --bin wire
      - run: WIRE=./target/release/wire bash demo-invite.sh

  demo-hotline:
    # Runs demo-hotline.sh end-to-end: local relay + 5 agents with vibes +
    # full mesh via `wire add` + signed ring-send. Validates the v0.5
    # handle directory, .well-known/wire/agent resolver, pair_drop +
    # pair_drop_ack flow, profile fields, and 5-way mesh under one daemon.
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: sudo apt-get update && sudo apt-get install -y jq
      - run: cargo build --release --bin wire
      - run: WIRE=./target/release/wire bash demo-hotline.sh
