# One-command local runner for the AVP reference examples and conformance suite.
#
# Uses go-task (https://taskfile.dev): `task --list`. Each target mirrors the matching
# .github/workflows/examples-*.yml job, so "green locally" means "green in CI". Each language
# is independent; run only the toolchains you have installed.
#
# Requirements per target: conformance/typescript -> Bun; go -> Go; python -> Python 3;
# rust -> Cargo; java -> a JDK. `task test` runs every target and needs them all.
version: "3"

tasks:
  default:
    desc: List available tasks.
    cmds:
      - task --list
    silent: true

  test:
    desc: Run the conformance suite and every language's example tests.
    cmds:
      - task: conformance
      - task: vectors-check
      - task: go
      - task: typescript
      - task: python
      - task: rust
      - task: java

  conformance:
    desc: Reproduce every vector in vectors/ and check schema/example/index/openapi consistency.
    dir: examples/conformance
    cmds:
      - bun install --frozen-lockfile
      - bun run typecheck
      - bun run test

  vectors-check:
    desc: Re-derive every vector from its documented seeds (provenance and drift gate).
    cmds:
      - bun vectors/generate.ts --check

  openapi-lint:
    desc: Lint openapi.yaml with Spectral.
    cmds:
      - bunx @stoplight/spectral-cli@6 lint openapi.yaml --ruleset .spectral.yaml --fail-severity error

  harness:
    desc: Run the black-box conformance harness against a server (AVP_SERVER_URL=http://host:port task harness).
    dir: harness
    cmds:
      - bun conformance.ts --server "{{.AVP_SERVER_URL}}"
    env:
      AVP_SERVER_URL: '{{.AVP_SERVER_URL | default "http://localhost:8787"}}'

  go:
    desc: Vet, test, and build the Go client and server.
    dir: examples/go
    cmds:
      - go vet ./...
      - go test ./...
      - go build ./...

  typescript:
    desc: Typecheck and test the TypeScript client and server.
    cmds:
      - for: { var: PROJECTS }
        cmd: cd examples/typescript/{{.ITEM}} && bun install --frozen-lockfile && bun run typecheck && (grep -q '"test"' package.json && bun run test || echo "no test script in {{.ITEM}}")
    vars:
      PROJECTS: client server

  python:
    desc: Byte-compile and unit-test the Python client and server.
    cmds:
      - cd examples/python/server && pip install -r requirements.txt && python -m py_compile server.py test_server.py && python -m unittest test_server.py
      - cd examples/python/client && pip install -r requirements.txt && python -m py_compile client.py crypto.py && python -m unittest test_crypto.py

  rust:
    desc: Build and test the Rust client and server.
    cmds:
      - cd examples/rust/server && cargo test
      - cd examples/rust/client && cargo test

  java:
    desc: Compile and run the Java server smoke test and client crypto vectors.
    cmds:
      - cd examples/java/server && javac Server.java SmokeTest.java && java SmokeTest
      - cd examples/java/client && javac Crypto.java CryptoVectors.java Client.java && java CryptoVectors

  interop:
    desc: Cross-language wire interop (informational; runs in CI).
    cmds:
      - |
        echo "The cross-language interop matrix (each lang's client -> Go server, Go client ->"
        echo "each lang's server) runs in .github/workflows/examples-interop.yml. Reproducing the"
        echo "full matrix locally needs all five toolchains plus port-readiness polling; the"
        echo "workflow is the reference. Per-language correctness is covered by 'task test'."
    silent: true
