|
| 1 | +name: behavioral |
| 2 | + |
| 3 | +# Behavioral tests run a real agent against a skill and grade what it did (see |
| 4 | +# eval/behavioral/). They cost real API tokens and, for some skills, install |
| 5 | +# and exercise local models, so they are NOT part of the always-on PR gate. |
| 6 | +# Instead they are: |
| 7 | +# |
| 8 | +# * label-gated on PRs -- a maintainer adds the `run-behavioral` label to opt |
| 9 | +# a PR in. This keeps the ANTHROPIC_API_KEY secret away from untrusted / |
| 10 | +# fork code, which runs with tool permissions bypassed. |
| 11 | +# * selective -- only the skills whose folder or test changed are run (the |
| 12 | +# whole suite runs when the shared harness changes). See |
| 13 | +# .github/scripts/select_behavioral.py. |
| 14 | +# * dispatchable -- run any subset by hand from the Actions tab. |
| 15 | +# |
| 16 | +# Shape mirrors validate.yml: discover -> matrix -> single aggregate gate, so |
| 17 | +# branch protection can require just the `behavioral` check. That gate passes |
| 18 | +# (neutral) when the label is absent, so it never blocks an unlabeled PR. |
| 19 | + |
| 20 | +on: |
| 21 | + pull_request: |
| 22 | + types: [opened, synchronize, reopened, labeled] |
| 23 | + paths: |
| 24 | + - "skills/**" |
| 25 | + - "eval/behavioral/**" |
| 26 | + - "eval/claude_eval.py" |
| 27 | + - ".github/workflows/behavioral.yml" |
| 28 | + - ".github/scripts/select_behavioral.py" |
| 29 | + workflow_dispatch: |
| 30 | + inputs: |
| 31 | + skills: |
| 32 | + description: "Comma-separated skill names to test (blank = every skill that has a behavioral test)." |
| 33 | + required: false |
| 34 | + default: "" |
| 35 | + |
| 36 | +concurrency: |
| 37 | + group: behavioral-${{ github.event.pull_request.number || github.ref }} |
| 38 | + cancel-in-progress: true |
| 39 | + |
| 40 | +permissions: |
| 41 | + contents: read |
| 42 | + |
| 43 | +env: |
| 44 | + BEHAVIORAL_LABEL: run-behavioral |
| 45 | + |
| 46 | +jobs: |
| 47 | + # Decide which skills to run. On PRs this is gated on the `run-behavioral` |
| 48 | + # label so the secret is never exposed to code that a maintainer hasn't |
| 49 | + # vouched for. |
| 50 | + discover: |
| 51 | + name: Select behavioral tests |
| 52 | + if: >- |
| 53 | + github.event_name == 'workflow_dispatch' || |
| 54 | + (github.event_name == 'pull_request' && |
| 55 | + contains(github.event.pull_request.labels.*.name, 'run-behavioral')) |
| 56 | + runs-on: ubuntu-latest |
| 57 | + outputs: |
| 58 | + skills: ${{ steps.select.outputs.skills }} |
| 59 | + any: ${{ steps.select.outputs.any }} |
| 60 | + steps: |
| 61 | + - name: Check out repository |
| 62 | + uses: actions/checkout@v4 |
| 63 | + with: |
| 64 | + # Need the merge base so `git diff` can see what the PR changed. |
| 65 | + fetch-depth: 0 |
| 66 | + |
| 67 | + - name: Set up uv |
| 68 | + uses: astral-sh/setup-uv@v7 |
| 69 | + |
| 70 | + - name: Select skills |
| 71 | + id: select |
| 72 | + run: | |
| 73 | + set -euo pipefail |
| 74 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 75 | + if [ -n "${{ github.event.inputs.skills }}" ]; then |
| 76 | + skills=$(uv run .github/scripts/select_behavioral.py --names "${{ github.event.inputs.skills }}") |
| 77 | + else |
| 78 | + skills=$(uv run .github/scripts/select_behavioral.py --all) |
| 79 | + fi |
| 80 | + else |
| 81 | + base="${{ github.event.pull_request.base.sha }}" |
| 82 | + head="${{ github.event.pull_request.head.sha }}" |
| 83 | + skills=$(git diff --name-only "$base" "$head" \ |
| 84 | + | uv run .github/scripts/select_behavioral.py --changed) |
| 85 | + fi |
| 86 | + echo "Selected skills: $skills" |
| 87 | + echo "skills=$skills" >> "$GITHUB_OUTPUT" |
| 88 | + if [ "$skills" = "[]" ]; then |
| 89 | + echo "any=false" >> "$GITHUB_OUTPUT" |
| 90 | + else |
| 91 | + echo "any=true" >> "$GITHUB_OUTPUT" |
| 92 | + fi |
| 93 | +
|
| 94 | + behavioral: |
| 95 | + name: Behavioral (${{ matrix.skill }}) |
| 96 | + needs: discover |
| 97 | + if: needs.discover.outputs.any == 'true' |
| 98 | + runs-on: ubuntu-latest |
| 99 | + # Behavioral runs install local models and can take a while; cap it so a |
| 100 | + # hung agent or stalled model pull fails the job instead of burning minutes. |
| 101 | + timeout-minutes: 45 |
| 102 | + strategy: |
| 103 | + # One skill failing should not hide the others' results. |
| 104 | + fail-fast: false |
| 105 | + matrix: |
| 106 | + skill: ${{ fromJson(needs.discover.outputs.skills) }} |
| 107 | + steps: |
| 108 | + - name: Check out repository |
| 109 | + uses: actions/checkout@v4 |
| 110 | + |
| 111 | + - name: Set up Python |
| 112 | + uses: actions/setup-python@v5 |
| 113 | + with: |
| 114 | + python-version: "3.12" |
| 115 | + |
| 116 | + - name: Set up Node |
| 117 | + uses: actions/setup-node@v4 |
| 118 | + with: |
| 119 | + node-version: "20" |
| 120 | + |
| 121 | + - name: Install the claude CLI |
| 122 | + run: npm install -g @anthropic-ai/claude-code |
| 123 | + |
| 124 | + - name: Install behavioral test dependencies |
| 125 | + run: pip install -r eval/behavioral/requirements.txt |
| 126 | + |
| 127 | + - name: Run behavioral test for ${{ matrix.skill }} |
| 128 | + working-directory: eval/behavioral |
| 129 | + env: |
| 130 | + # The CLI authenticates from this key; it is only present on labeled |
| 131 | + # PRs and manual dispatch (see the `discover` gate above). |
| 132 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 133 | + # Lets the harness default to this skill if a test relies on the env. |
| 134 | + BEHAVIORAL_SKILL: ${{ matrix.skill }} |
| 135 | + run: | |
| 136 | + set -euo pipefail |
| 137 | + test_file="tests/test_$(echo '${{ matrix.skill }}' | tr '-' '_').py" |
| 138 | + echo "Running $test_file" |
| 139 | + pytest "$test_file" |
| 140 | +
|
| 141 | + # Single aggregate gate. Mark THIS check required in branch protection. |
| 142 | + # It passes when behavioral tests were not requested (no label) and when |
| 143 | + # every selected behavioral job succeeded, so it never blocks an unlabeled PR. |
| 144 | + behavioral-gate: |
| 145 | + name: behavioral |
| 146 | + needs: [discover, behavioral] |
| 147 | + if: always() |
| 148 | + runs-on: ubuntu-latest |
| 149 | + steps: |
| 150 | + - name: Verify behavioral results |
| 151 | + run: | |
| 152 | + discover_result="${{ needs.discover.result }}" |
| 153 | + behavioral_result="${{ needs.behavioral.result }}" |
| 154 | + echo "discover: $discover_result" |
| 155 | + echo "behavioral: $behavioral_result" |
| 156 | +
|
| 157 | + # Label absent (or dispatch skipped): behavioral tests were not |
| 158 | + # requested for this run, so the gate is a no-op pass. |
| 159 | + if [ "$discover_result" = "skipped" ]; then |
| 160 | + echo "Behavioral tests not requested (no '${BEHAVIORAL_LABEL}' label)." |
| 161 | + exit 0 |
| 162 | + fi |
| 163 | +
|
| 164 | + # Nothing matched the change set, or everything that ran passed. |
| 165 | + if [ "$behavioral_result" = "success" ] || [ "$behavioral_result" = "skipped" ]; then |
| 166 | + echo "All requested behavioral tests passed." |
| 167 | + exit 0 |
| 168 | + fi |
| 169 | +
|
| 170 | + echo "One or more behavioral tests failed." >&2 |
| 171 | + exit 1 |
0 commit comments