name: Tests

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

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Go
        uses: actions/setup-go@v5
        with:
          go-version-file: go.mod
          cache: true

      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: "20"
          cache: "npm"
          cache-dependency-path: frontend/package-lock.json

      - name: Install test dependencies
        run: sudo apt-get install -y --no-install-recommends jq sqlite3

      - name: Build
        run: ./scripts/build.sh

      - name: Make test scripts executable
        run: chmod +x tests/*.sh

      - name: Critical path test
        run: ./tests/critical-path.sh

      - name: Config validation test
        run: ./tests/config-validation.sh

      - name: Idempotency test
        run: ./tests/idempotency.sh

      - name: State reconciliation test
        run: ./tests/state-reconciliation.sh

      - name: Go vet
        run: go vet ./...
