|
| 1 | +name: LS-N verification gate |
| 2 | + |
| 3 | +# Verifies that every approved loss-scenario in |
| 4 | +# `safety/stpa/loss-scenarios.yaml` has a passing regression test by |
| 5 | +# naming convention (`LS-A-11` -> `ls_a_11_*`). Posts a single sticky PR |
| 6 | +# comment summarising passed / failed / missing counts. Fails the job |
| 7 | +# only when an existing test fails; missing tests are reported as a |
| 8 | +# warning (advisory) so older approved scenarios with ad-hoc test names |
| 9 | +# can be migrated incrementally rather than blocking every PR. |
| 10 | +# |
| 11 | +# Adapted from spar's rivet-driven verification gate |
| 12 | +# (pulseengine/spar@ba329f3d). meld has no rivet-style executable |
| 13 | +# artifact, but `status: approved` LS entries pair with regression tests |
| 14 | +# by the established `ls_<letter>_<num>_*` naming convention; this gate |
| 15 | +# makes that pairing a verifiable contract. |
| 16 | +# |
| 17 | +# Inputs are all integer/metadata fields (PR number, head_ref); no |
| 18 | +# untrusted free-form text from PR titles/bodies/comments is read in |
| 19 | +# `run:` blocks, so the standard injection vectors do not apply. |
| 20 | + |
| 21 | +on: |
| 22 | + pull_request: |
| 23 | + branches: [main] |
| 24 | + workflow_dispatch: |
| 25 | + |
| 26 | +concurrency: |
| 27 | + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} |
| 28 | + cancel-in-progress: true |
| 29 | + |
| 30 | +permissions: |
| 31 | + contents: read |
| 32 | + pull-requests: write |
| 33 | + |
| 34 | +jobs: |
| 35 | + verify: |
| 36 | + name: LS-N verification gate |
| 37 | + runs-on: [self-hosted, linux, x64, rust-cpu] |
| 38 | + timeout-minutes: 30 |
| 39 | + env: |
| 40 | + CARGO_TERM_COLOR: always |
| 41 | + CARGO_INCREMENTAL: 0 |
| 42 | + steps: |
| 43 | + - uses: actions/checkout@v4 |
| 44 | + |
| 45 | + - uses: dtolnay/rust-toolchain@stable |
| 46 | + |
| 47 | + - uses: Swatinem/rust-cache@v2 |
| 48 | + |
| 49 | + - name: Install PyYAML |
| 50 | + # Self-hosted runners ship Debian/Ubuntu Python with PEP 668 |
| 51 | + # protection; `--break-system-packages` is the documented opt-out |
| 52 | + # for CI environments where the runner's Python install is |
| 53 | + # disposable per workflow run. |
| 54 | + run: pip install --user --break-system-packages pyyaml |
| 55 | + |
| 56 | + - name: Run LS-N verification |
| 57 | + id: verify |
| 58 | + continue-on-error: true |
| 59 | + run: | |
| 60 | + python3 tools/run_ls_verification.py \ |
| 61 | + --results-json verification-results.json |
| 62 | +
|
| 63 | + - name: Upload results artifact |
| 64 | + if: always() |
| 65 | + uses: actions/upload-artifact@v4 |
| 66 | + with: |
| 67 | + name: verification-results |
| 68 | + path: verification-results.json |
| 69 | + if-no-files-found: warn |
| 70 | + |
| 71 | + - name: Post sticky PR comment |
| 72 | + if: github.event_name == 'pull_request' && always() |
| 73 | + env: |
| 74 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 76 | + run: | |
| 77 | + python3 tools/post_verification_comment.py "$PR_NUMBER" |
| 78 | +
|
| 79 | + - name: Fail job if any approved LS-N test failed |
| 80 | + # Exit code 1 from run_ls_verification.py = a regression test |
| 81 | + # for an approved LS entry failed. Exit 2 = missing tests only; |
| 82 | + # treated as advisory. Exit 0 = all approved entries verified. |
| 83 | + if: steps.verify.outcome == 'failure' |
| 84 | + run: | |
| 85 | + # Re-check: outcome == failure can mean exit 1 (real fail) or |
| 86 | + # exit 2 (missing only). Inspect the JSON to decide. |
| 87 | + failed=$(python3 -c "import json; print(json.load(open('verification-results.json'))['failed_count'])") |
| 88 | + if [ "$failed" -gt 0 ]; then |
| 89 | + echo "::error::$failed approved LS-N entries have failing regression tests; see PR comment" |
| 90 | + exit 1 |
| 91 | + fi |
| 92 | + echo "::warning::Some approved LS-N entries are missing regression tests (advisory only)" |
0 commit comments