name: Installer tests

on:
  pull_request:
    paths:
      - 'install.sh'
      - 'upgrade.sh'
      - 'docker-compose.yml.tpl'
      - 'Caddyfile.tpl'
      - 'config/defaults.conf'
      - 'scripts/oxpulse-xray-update.sh'
      - 'lib/reconcile.sh'
      - 'tests/test_install_die_on_empty_sfu_secret.sh'
      - 'tests/test_upgrade_die_on_empty_sfu_secret.sh'
      - 'tests/test_sfu_compose.sh'
      - 'tests/test_upgrade_render_completeness.sh'
      - 'tests/test_render_completeness.sh'
      - 'tests/test_state_migration_matrix.sh'
      - 'tests/test_health_gate_baseline.sh'
      - 'tests/test_manifest_coverage.sh'
      - 'tests/test_converge_idempotent.sh'
      - 'tests/test_apply_restarts_wired.sh'
      - 'tests/test_health_gate_cold_start_settle.sh'
      - 'tests/test_upgrade_self_reexec.sh'
      - 'tests/test_reconcile_caddy_reload_observability.sh'
      - 'oxpulse-channels-health-report.sh'
      - 'tests/test_channels_health_report.sh'
      - 'lib/healthcheck-lib.sh'
      - 'tests/test_settle_serveability.sh'
      - 'tests/test_settle_dual_pin_consistency.sh'
      - 'manifest.yaml'
      - 'healthcheck.sh'
      - '.github/workflows/installer-tests.yml'
  push:
    branches: [main]
    paths:
      - 'install.sh'
      - 'upgrade.sh'
      - 'docker-compose.yml.tpl'
      - 'Caddyfile.tpl'
      - 'config/defaults.conf'
      - 'scripts/oxpulse-xray-update.sh'
      - 'lib/reconcile.sh'
      - 'tests/test_install_die_on_empty_sfu_secret.sh'
      - 'tests/test_upgrade_die_on_empty_sfu_secret.sh'
      - 'tests/test_sfu_compose.sh'
      - 'tests/test_upgrade_render_completeness.sh'
      - 'tests/test_render_completeness.sh'
      - 'tests/test_state_migration_matrix.sh'
      - 'tests/test_health_gate_baseline.sh'
      - 'tests/test_manifest_coverage.sh'
      - 'tests/test_converge_idempotent.sh'
      - 'tests/test_apply_restarts_wired.sh'
      - 'tests/test_health_gate_cold_start_settle.sh'
      - 'tests/test_upgrade_self_reexec.sh'
      - 'tests/test_reconcile_caddy_reload_observability.sh'
      - 'oxpulse-channels-health-report.sh'
      - 'tests/test_channels_health_report.sh'
      - 'lib/healthcheck-lib.sh'
      - 'tests/test_settle_serveability.sh'
      - 'tests/test_settle_dual_pin_consistency.sh'
      - 'manifest.yaml'
      - 'healthcheck.sh'
      - '.github/workflows/installer-tests.yml'

jobs:
  installer-tests:
    name: Installer regression tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install shellcheck
        run: sudo apt-get install -y shellcheck

      - name: shellcheck -x -S warning *.sh (matches release gate)
        run: |
          shopt -s nullglob
          for f in *.sh; do
            echo ">> $f"
            shellcheck -x -S warning "$f"
          done

      - name: install.sh dies on empty signaling_sfu_secret
        run: bash tests/test_install_die_on_empty_sfu_secret.sh

      - name: upgrade.sh dies on empty signaling_sfu_secret
        run: bash tests/test_upgrade_die_on_empty_sfu_secret.sh

      - name: SFU compose template wiring (SFU_EDGE_ID regression)
        run: bash tests/test_sfu_compose.sh

      - name: Caddy render completeness + with_templates conflict-check path
        run: bash tests/test_upgrade_render_completeness.sh

      - name: Caddyfile.tpl placeholder coverage + reconcile lib primitives (Phase 1, S1)
        run: bash tests/test_render_completeness.sh

      - name: State schema v1 migration matrix (Phase 2, ADR-002)
        run: bash tests/test_state_migration_matrix.sh

      - name: Baseline-aware health gate — regression diff (Phase 3, Decision 4)
        run: bash tests/test_health_gate_baseline.sh

      - name: Manifest coverage — all surfaces declared + caddyfile wired (Phase 4a)
        run: bash tests/test_manifest_coverage.sh

      - name: reconcile_all idempotency — run2 produces zero swaps (Phase 4a, S2)
        run: bash tests/test_converge_idempotent.sh

      - name: apply_restarts wired inside reconcile_all — dead-code fix verified (Phase 4a)
        run: bash tests/test_apply_restarts_wired.sh

      - name: Settle gate tolerates a transient cold-start regression (v0.14.3 FIX 1)
        run: bash tests/test_health_gate_cold_start_settle.sh

      - name: Stale upgrade.sh re-execs into the released one once (v0.14.3 FIX 2)
        run: bash tests/test_upgrade_self_reexec.sh

      - name: Caddy reload stderr surfaced + un-loadable Caddyfile persisted (v0.14.3 FIX 3)
        run: bash tests/test_reconcile_caddy_reload_observability.sh

      - name: Channel-canary honest end-to-end probes (multi-channel failover hardening, P1)
        run: bash tests/test_channels_health_report.sh

      - name: Serve-ability-aware settle gate — suppress multi-homed false rollback (P3)
        run: bash tests/test_settle_serveability.sh

      - name: Settle dual-pin fitness — inline vs lib health primitives stay identical
        run: bash tests/test_settle_dual_pin_consistency.sh
