|
| 1 | +name: Pilot Site Validation |
| 2 | + |
| 3 | +# BEP-0200 Phase 3 + NTSyCS Compliance CI |
| 4 | +# Triggers on every push/PR that touches compliance or core modules. |
| 5 | +# Also runs weekly to detect regressions in regulatory requirements. |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: [main] |
| 10 | + paths: |
| 11 | + - "src/core/**" |
| 12 | + - "src/interfaces/**" |
| 13 | + - "tests/test_compliance*" |
| 14 | + - "tests/test_cen_*" |
| 15 | + - "tests/test_ppo_*" |
| 16 | + - "scripts/pilot_setup.py" |
| 17 | + pull_request: |
| 18 | + branches: [main] |
| 19 | + schedule: |
| 20 | + - cron: "0 6 * * 1" # Weekly Monday 06:00 UTC — regulatory regression check |
| 21 | + |
| 22 | +permissions: |
| 23 | + contents: read |
| 24 | + checks: write |
| 25 | + |
| 26 | +jobs: |
| 27 | + # ───────────────────────────────────────────────────────────────────── |
| 28 | + # JOB 1: NTSyCS Compliance Tests (11 GAPs) |
| 29 | + # ───────────────────────────────────────────────────────────────────── |
| 30 | + compliance: |
| 31 | + name: "NTSyCS Compliance — 11 GAPs" |
| 32 | + runs-on: ubuntu-latest |
| 33 | + timeout-minutes: 15 |
| 34 | + |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v4 |
| 37 | + |
| 38 | + - name: Set up Python 3.12 |
| 39 | + uses: actions/setup-python@v5 |
| 40 | + with: |
| 41 | + python-version: "3.12" |
| 42 | + cache: pip |
| 43 | + |
| 44 | + - name: Install dependencies |
| 45 | + run: | |
| 46 | + python -m pip install --upgrade pip |
| 47 | + pip install -e ".[dev]" |
| 48 | +
|
| 49 | + - name: Run compliance test suite |
| 50 | + id: compliance_tests |
| 51 | + run: | |
| 52 | + pytest \ |
| 53 | + tests/test_compliance_api.py \ |
| 54 | + tests/test_cen_sc_bidder.py \ |
| 55 | + tests/test_cen_publisher.py \ |
| 56 | + tests/test_iec104_driver.py \ |
| 57 | + -v --tb=short --junitxml=reports/compliance.xml \ |
| 58 | + --ignore=tests/agents/ |
| 59 | + env: |
| 60 | + BESSAI_SITE_ID: SITE-CI-VALIDATION |
| 61 | + BESSAI_P_NOM_KW: "1000" |
| 62 | + BESSAI_COMPLIANCE_ENABLED: "true" |
| 63 | + |
| 64 | + - name: Upload compliance report |
| 65 | + uses: actions/upload-artifact@v4 |
| 66 | + if: always() |
| 67 | + with: |
| 68 | + name: compliance-junit-${{ github.run_id }} |
| 69 | + path: reports/compliance.xml |
| 70 | + |
| 71 | + # ───────────────────────────────────────────────────────────────────── |
| 72 | + # JOB 2: BEP-0200 Phase 3 — PPO Environment Validation |
| 73 | + # ───────────────────────────────────────────────────────────────────── |
| 74 | + ppo-validation: |
| 75 | + name: "BEP-0200 Phase 3 — PPO Environment" |
| 76 | + runs-on: ubuntu-latest |
| 77 | + timeout-minutes: 10 |
| 78 | + |
| 79 | + steps: |
| 80 | + - uses: actions/checkout@v4 |
| 81 | + |
| 82 | + - name: Set up Python 3.12 |
| 83 | + uses: actions/setup-python@v5 |
| 84 | + with: |
| 85 | + python-version: "3.12" |
| 86 | + cache: pip |
| 87 | + |
| 88 | + - name: Install dependencies (no SB3 in CI — validation mode) |
| 89 | + run: | |
| 90 | + python -m pip install --upgrade pip |
| 91 | + pip install -e ".[dev]" |
| 92 | +
|
| 93 | + - name: Validate BESSDispatchEnv |
| 94 | + run: | |
| 95 | + pytest tests/test_ppo_trainer.py -v --tb=short |
| 96 | + env: |
| 97 | + BESSAI_P_NOM_KW: "1000" |
| 98 | + |
| 99 | + - name: Validate PPOTrainer (synthetic data / no SB3) |
| 100 | + run: | |
| 101 | + python -c " |
| 102 | + from src.core.ppo_trainer import PPOTrainer, TrainingConfig |
| 103 | + cfg = TrainingConfig(total_timesteps=2_000, max_episode_steps=96) |
| 104 | + t = PPOTrainer(site_id='CI-TEST', config=cfg) |
| 105 | + r = t.train() |
| 106 | + assert r.training_duration_s > 0, 'Training did not run' |
| 107 | + assert r.bep_ref.startswith('BEP-0200'), f'Wrong BEP ref: {r.bep_ref}' |
| 108 | + print(f'✅ BEP-0200 Phase 3 validated: {r.total_timesteps} steps, reward={r.final_mean_reward:.4f}') |
| 109 | + " |
| 110 | +
|
| 111 | + # ───────────────────────────────────────────────────────────────────── |
| 112 | + # JOB 3: Unified Server Smoke Test |
| 113 | + # ───────────────────────────────────────────────────────────────────── |
| 114 | + server-smoke: |
| 115 | + name: "BESSAIServer Endpoints Smoke Test" |
| 116 | + runs-on: ubuntu-latest |
| 117 | + timeout-minutes: 5 |
| 118 | + |
| 119 | + steps: |
| 120 | + - uses: actions/checkout@v4 |
| 121 | + |
| 122 | + - name: Set up Python 3.12 |
| 123 | + uses: actions/setup-python@v5 |
| 124 | + with: |
| 125 | + python-version: "3.12" |
| 126 | + cache: pip |
| 127 | + |
| 128 | + - name: Install dependencies |
| 129 | + run: pip install -e ".[dev]" |
| 130 | + |
| 131 | + - name: Smoke test BESSAIServer |
| 132 | + run: | |
| 133 | + python -c " |
| 134 | + import asyncio, json |
| 135 | + from src.interfaces.server import BESSAIServer |
| 136 | +
|
| 137 | + server = BESSAIServer(site_id='CI-TEST', version='2.14.0') |
| 138 | + server.set_cycle(1, True, 'ok') |
| 139 | + server.set_compliance_state(True, 100.0, [], 1) |
| 140 | +
|
| 141 | + # Verify state is set correctly |
| 142 | + assert server._compliance.all_ok == True |
| 143 | + assert server._compliance.score == 100.0 |
| 144 | + assert server._last_cycle == 1 |
| 145 | + assert server._version == '2.14.0' |
| 146 | + print('✅ BESSAIServer state management validated') |
| 147 | + " |
| 148 | +
|
| 149 | + # ───────────────────────────────────────────────────────────────────── |
| 150 | + # JOB 4: Pilot Readiness Check |
| 151 | + # ───────────────────────────────────────────────────────────────────── |
| 152 | + pilot-readiness: |
| 153 | + name: "Pilot Site Readiness (CI Mode)" |
| 154 | + runs-on: ubuntu-latest |
| 155 | + timeout-minutes: 5 |
| 156 | + |
| 157 | + steps: |
| 158 | + - uses: actions/checkout@v4 |
| 159 | + |
| 160 | + - name: Set up Python 3.12 |
| 161 | + uses: actions/setup-python@v5 |
| 162 | + with: |
| 163 | + python-version: "3.12" |
| 164 | + cache: pip |
| 165 | + |
| 166 | + - name: Install dependencies |
| 167 | + run: pip install -e ".[dev]" |
| 168 | + |
| 169 | + - name: Validate pilot_setup.py script exists and parses |
| 170 | + run: | |
| 171 | + python -c " |
| 172 | + import ast, sys |
| 173 | + with open('scripts/pilot_setup.py') as f: |
| 174 | + ast.parse(f.read()) |
| 175 | + print('✅ pilot_setup.py syntax valid') |
| 176 | + " |
| 177 | +
|
| 178 | + - name: Validate .env.example completeness |
| 179 | + run: | |
| 180 | + python -c " |
| 181 | + required = [ |
| 182 | + 'BESSAI_SITE_ID', 'BESSAI_CAPACITY_KWH', 'BESSAI_P_NOM_KW', |
| 183 | + 'CEN_ENDPOINT', 'CEN_TLS_CERT', 'CEN_TLS_KEY', |
| 184 | + 'CSIRT_API_KEY', 'SC_PFR_PRICE_USD_MWH', |
| 185 | + ] |
| 186 | + with open('.env.example') as f: |
| 187 | + content = f.read() |
| 188 | + missing = [k for k in required if k not in content] |
| 189 | + if missing: |
| 190 | + print(f'❌ Missing from .env.example: {missing}') |
| 191 | + sys.exit(1) |
| 192 | + print(f'✅ .env.example has all {len(required)} required variables') |
| 193 | + import sys; sys.exit(0) |
| 194 | + " |
| 195 | +
|
| 196 | + # ───────────────────────────────────────────────────────────────────── |
| 197 | + # Summary badge |
| 198 | + # ───────────────────────────────────────────────────────────────────── |
| 199 | + summary: |
| 200 | + name: "v2.14.0 Pilot Validation Summary" |
| 201 | + needs: [compliance, ppo-validation, server-smoke, pilot-readiness] |
| 202 | + runs-on: ubuntu-latest |
| 203 | + if: always() |
| 204 | + |
| 205 | + steps: |
| 206 | + - name: Report validation status |
| 207 | + run: | |
| 208 | + echo "## BESSAI v2.14.0 — Pilot Validation Results" >> $GITHUB_STEP_SUMMARY |
| 209 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 210 | + echo "| Job | Status |" >> $GITHUB_STEP_SUMMARY |
| 211 | + echo "|-----|--------|" >> $GITHUB_STEP_SUMMARY |
| 212 | + echo "| NTSyCS Compliance (11 GAPs) | ${{ needs.compliance.result }} |" >> $GITHUB_STEP_SUMMARY |
| 213 | + echo "| BEP-0200 Phase 3 PPO | ${{ needs.ppo-validation.result }} |" >> $GITHUB_STEP_SUMMARY |
| 214 | + echo "| BESSAIServer Smoke | ${{ needs.server-smoke.result }} |" >> $GITHUB_STEP_SUMMARY |
| 215 | + echo "| Pilot Readiness | ${{ needs.pilot-readiness.result }} |" >> $GITHUB_STEP_SUMMARY |
| 216 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 217 | + echo "Commit: \`${{ github.sha }}\` — Ref: \`${{ github.ref }}\`" >> $GITHUB_STEP_SUMMARY |
0 commit comments