name: PR7 API compatibility

on:
  pull_request:
    paths:
      - "baseline/extracted/v2_api_routes.txt"
      - "baseline/V2_HEAD_COMMIT.txt"
      - "baseline/raw_api_contracts.txt"
      - "baseline/raw__well-known_agent-card_json.txt"
      - "baseline/raw__well-known_x402_json.txt"
      - "baseline/schemas/v2/**"
      - "baseline/x402-route-registry.json"
      - "pr7/**"
      - ".github/workflows/pr7-api-compat.yml"
  push:
    branches:
      - fix/v3-api-compat

jobs:
  api-compatibility:
    name: V2 baseline and V3 envelope gate
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: pr7
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm
          cache-dependency-path: pr7/package-lock.json
      - name: Install PR7 dependencies
        run: npm ci
      - name: Verify evidence-bound V2 fixture diff
        run: npm run check:api-compat
      - name: Verify generated registry alignment
        run: npm run check:registry
      - name: Run PR7 API compatibility tests
        run: npm run test:api-compat
      - name: Typecheck PR7 API compatibility code
        run: npm run typecheck
      - name: Verify repository diff whitespace
        working-directory: .
        run: git diff --check
