name: TLA+ Specs

on:
  workflow_dispatch:
  push:
    paths:
      - 'specs/**'
      - 'src/checkpoint.rs'
      - 'src/bytecode_tape/optimize.rs'
      - 'src/bytecode_tape/mod.rs'
  pull_request:
    paths:
      - 'specs/**'
      - 'src/checkpoint.rs'
      - 'src/bytecode_tape/optimize.rs'
      - 'src/bytecode_tape/mod.rs'

jobs:
  verify-anchors:
    runs-on: ubuntu-latest
    timeout-minutes: 2
    steps:
      - uses: actions/checkout@v7

      - name: Verify SPEC anchors
        run: ./specs/verify_anchors.sh

  model-check:
    runs-on: ubuntu-latest
    needs: verify-anchors
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v7

      - uses: actions/setup-java@v5
        with:
          java-version: '21'
          distribution: 'temurin'

      - name: Download TLA+ tools
        run: |
          curl -sL -o specs/tla2tools.jar \
            https://github.com/tlaplus/tlaplus/releases/download/v1.8.0/tla2tools.jar
          echo "TLC version:"
          java -cp specs/tla2tools.jar tlc2.TLC -h 2>&1 | head -3

      - name: Check Revolve (base)
        run: |
          java -XX:+UseParallelGC -cp specs/tla2tools.jar tlc2.TLC \
            -config specs/revolve/Revolve.cfg \
            specs/revolve/Revolve.tla \
            -workers auto

      - name: Check RevolveOnline
        run: |
          java -XX:+UseParallelGC -cp specs/tla2tools.jar tlc2.TLC \
            -config specs/revolve/RevolveOnline.cfg \
            specs/revolve/RevolveOnline.tla \
            -workers auto

      - name: Check HintAllocation
        run: |
          java -XX:+UseParallelGC -cp specs/tla2tools.jar tlc2.TLC \
            -config specs/revolve/HintAllocation.cfg \
            specs/revolve/HintAllocation.tla \
            -workers auto

      - name: Check TapeOptimizer
        run: |
          java -XX:+UseParallelGC -cp specs/tla2tools.jar tlc2.TLC \
            -config specs/tape_optimizer/TapeOptimizer.cfg \
            specs/tape_optimizer/TapeOptimizer.tla \
            -workers auto

      - name: Check TapeOptimizer Idempotency
        run: |
          java -XX:+UseParallelGC -cp specs/tla2tools.jar tlc2.TLC \
            -config specs/tape_optimizer/Idempotency.cfg \
            specs/tape_optimizer/Idempotency.tla \
            -workers auto
