name: Tests
on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]

jobs:
  crypto-tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"
      - name: Install dependencies
        run: pip install mnemonic cryptography
      - name: Run keygen tests
        run: python tests/test_keygen.py
      - name: Run Shamir tests
        run: python tests/test_shamir.py

  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'

      - name: Install tools
        run: |
          pip install ruff mypy
          sudo apt-get install -y shellcheck

      - name: Ruff check
        run: ruff check src/

      - name: Ruff format check
        run: ruff format --check src/

      - name: MyPy (crypto + auth-proxy)
        run: mypy src/crypto/ src/auth-proxy/ --ignore-missing-imports

      - name: ShellCheck
        run: shellcheck scripts/*.sh src/sandbox-manager/manager.sh container/entrypoint.sh

  security:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Semgrep
        uses: semgrep/semgrep-action@v1
        with:
          config: >-
            p/python
            p/secrets
            p/owasp-top-ten
            p/docker

      - name: Trivy filesystem scan
        uses: aquasecurity/trivy-action@master
        with:
          scan-type: 'fs'
          scan-ref: '.'
          severity: 'HIGH,CRITICAL'
