-
Notifications
You must be signed in to change notification settings - Fork 5
349 lines (291 loc) · 13.5 KB
/
probe.yml
File metadata and controls
349 lines (291 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
name: Probe
on:
workflow_dispatch:
pull_request:
branches: [ main ]
jobs:
probe:
name: Compliance Probe
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Discover servers
id: discover
run: |
SERVERS='[]'
for f in src/Servers/*/probe.json; do
dir=$(basename "$(dirname "$f")")
name=$(jq -r .name "$f")
lang=$(jq -r '.language // ""' "$f")
SERVERS=$(echo "$SERVERS" | jq -c --arg d "$dir" --arg n "$name" --arg l "$lang" '. + [{"dir": $d, "name": $n, "language": $l}]')
done
echo "servers=$SERVERS" >> "$GITHUB_OUTPUT"
echo "Discovered: $(echo "$SERVERS" | jq -r '.[].name' | tr '\n' ', ')"
- name: Detect changes
id: changes
run: |
SERVERS='${{ steps.discover.outputs.servers }}'
set_all() {
echo "servers=$SERVERS" >> "$GITHUB_OUTPUT"
}
# workflow_dispatch always runs everything
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
set_all
exit 0
fi
CHANGED=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
# Global triggers → run all
if echo "$CHANGED" | grep -qE '^(src/Http11Probe/|src/Http11Probe\.Cli/|Directory\.Build\.props|\.dockerignore|\.github/workflows/probe\.yml)'; then
set_all
exit 0
fi
AFFECTED='[]'
for row in $(echo "$SERVERS" | jq -r '.[] | @base64'); do
dir=$(echo "$row" | base64 -d | jq -r '.dir')
name=$(echo "$row" | base64 -d | jq -r '.name')
lang=$(echo "$row" | base64 -d | jq -r '.language')
if echo "$CHANGED" | grep -q "^src/Servers/${dir}/"; then
AFFECTED=$(echo "$AFFECTED" | jq -c --arg d "$dir" --arg n "$name" --arg l "$lang" '. + [{"dir": $d, "name": $n, "language": $l}]')
fi
done
echo "servers=$AFFECTED" >> "$GITHUB_OUTPUT"
- name: Setup .NET
if: steps.changes.outputs.servers != '[]'
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0'
- name: Build probe CLI
if: steps.changes.outputs.servers != '[]'
run: dotnet build Http11Probe.slnx -c Release
# ── Build / Run / Probe / Kill — one server at a time ──────────
- name: Probe servers
if: steps.changes.outputs.servers != '[]'
run: |
SERVERS='${{ steps.changes.outputs.servers }}'
PROBE_PORT=8080
for row in $(echo "$SERVERS" | jq -r '.[] | @base64'); do
dir=$(echo "$row" | base64 -d | jq -r '.dir')
name=$(echo "$row" | base64 -d | jq -r '.name')
tag=$(echo "probe-$dir" | tr '[:upper:]' '[:lower:]')
echo "::group::$name"
# Build
docker build -t "$tag" -f "src/Servers/$dir/Dockerfile" .
# Run
docker run -d --name probe-target --network host "$tag"
# Wait
for i in $(seq 1 30); do
curl -sf "http://localhost:${PROBE_PORT}/" > /dev/null 2>&1 && break
sleep 1
done
# Probe
dotnet run --no-build -c Release --project src/Http11Probe.Cli -- \
--host localhost --port "$PROBE_PORT" --output "probe-${dir}.json" || true
# Kill
docker stop probe-target && docker rm probe-target
echo "::endgroup::"
done
- name: Cleanup
if: always()
run: docker rm -f probe-target 2>/dev/null || true
# ── Process results ────────────────────────────────────────────
- name: Process results
if: steps.changes.outputs.servers != '[]'
env:
PROBE_SERVERS: ${{ steps.changes.outputs.servers }}
run: |
python3 << 'PYEOF'
import json, sys, os, subprocess, pathlib
# ── Pass through CLI verdicts (evaluation now lives in C#) ──
def evaluate(raw):
results = []
for r in raw['results']:
status = r.get('statusCode')
conn = r.get('connectionState', '')
got = str(status) if status is not None else conn
expected = r.get('expected', '?')
verdict = r['verdict']
scored = r.get('scored', True)
reason = r['description']
if verdict == 'Fail':
reason = f"Expected {expected}, got {got} — {reason}"
results.append({
'id': r['id'], 'description': r['description'],
'category': r['category'], 'rfc': r.get('rfcReference'),
'verdict': verdict, 'statusCode': status,
'expected': expected, 'got': got,
'connectionState': conn, 'reason': reason,
'scored': scored,
'rfcLevel': r.get('rfcLevel', 'Must'),
'durationMs': r.get('durationMs', 0),
'rawRequest': r.get('rawRequest'),
'rawResponse': r.get('rawResponse'),
'behavioralNote': r.get('behavioralNote'),
'doubleFlush': r.get('doubleFlush'),
})
scored_results = [r for r in results if r['scored']]
scored_pass = sum(1 for r in scored_results if r['verdict'] == 'Pass')
scored_fail = sum(1 for r in scored_results if r['verdict'] == 'Fail')
scored_warn = sum(1 for r in scored_results if r['verdict'] == 'Warn')
unscored = sum(1 for r in results if not r['scored'])
return {
'summary': {'total': len(results), 'scored': len(scored_results), 'passed': scored_pass, 'failed': scored_fail, 'warnings': scored_warn, 'unscored': unscored},
'results': results,
}
# ── Process each server ──────────────────────────────────────
servers_config = json.loads(os.environ['PROBE_SERVERS'])
SERVERS = [(s['name'], f"probe-{s['dir']}.json", s.get('language', '')) for s in servers_config]
commit_id = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode().strip()
commit_msg = subprocess.check_output(['git', 'log', '-1', '--format=%s']).decode().strip()
commit_time = subprocess.check_output(['git', 'log', '-1', '--format=%cI']).decode().strip()
server_data = []
for name, path, language in SERVERS:
p = pathlib.Path(path)
if not p.exists():
print(f'::warning::{name}: result file {path} not found, skipping')
continue
with open(path) as f:
raw = json.load(f)
ev = evaluate(raw)
ev['name'] = name
ev['language'] = language
server_data.append(ev)
s = ev['summary']
print(f"{name}: {s['passed']}/{s['scored']} passed, {s['failed']} failed, {s['warnings']} warnings")
if not server_data:
print('::warning::No probe results found — nothing to report')
sys.exit(0)
# ── Baseline gate ─────────────────────────────────────────────
BASELINE_TESTS = {'COMP-BASELINE', 'COMP-POST-CL-BODY'}
baseline_failures = []
for sv in server_data:
for r in sv['results']:
if r['id'] in BASELINE_TESTS and r['verdict'] == 'Fail':
baseline_failures.append(f"{sv['name']}: {r['id']} — got {r['got']}")
if baseline_failures:
for f in baseline_failures:
print(f'::error::{f}')
# ── Write data.js ────────────────────────────────────────────
output = {
'commit': {'id': commit_id, 'message': commit_msg, 'timestamp': commit_time},
'servers': server_data,
}
with open('probe-data.js', 'w') as f:
f.write('window.PROBE_DATA = ' + json.dumps(output) + ';')
# ── Write PR comment ─────────────────────────────────────────
lines = ['<!-- http11probe-results -->', '## Http11Probe — Compliance Comparison', '']
# Summary table with bars
max_scored = max(s['summary']['scored'] for s in server_data)
BAR_WIDTH = 20
lines.append('| Server | Score | |')
lines.append('|--------|------:|---|')
for sv in sorted(server_data, key=lambda s: s['summary']['passed'] + s['summary']['warnings'], reverse=True):
s = sv['summary']
score = s['passed'] + s['warnings']
pct = score / s['scored'] if s['scored'] else 0
filled = round(pct * BAR_WIDTH)
bar = '\u2588' * filled + '\u2591' * (BAR_WIDTH - filled)
lines.append(f"| **{sv['name']}** | {score}/{s['scored']} | `{bar}` {pct:.0%} |")
lines.append('')
# Collect all test IDs in order from first server
test_ids = [r['id'] for r in server_data[0]['results']] if server_data else []
# Build lookup: server_name -> {test_id -> result}
lookup = {}
for sv in server_data:
lookup[sv['name']] = {r['id']: r for r in sv['results']}
names = [sv['name'] for sv in server_data]
import re
def short(tid):
return re.sub(r'^(RFC\d+-[\d.]+-|COMP-|SMUG-|MAL-|NORM-)', '', tid)
# Baseline status
if baseline_failures:
lines.append('### ❌ Baseline Failed')
lines.append('')
for bf in baseline_failures:
lines.append(f'- `{bf}`')
lines.append('')
else:
lines.append('### ✅ Baseline Passed')
lines.append('')
for cat_name, title in [('Compliance', 'Compliance'), ('Smuggling', 'Smuggling'), ('MalformedInput', 'Malformed Input'), ('Normalization', 'Header Normalization')]:
cat_tests = [tid for tid in test_ids if lookup[names[0]][tid]['category'] == cat_name]
if not cat_tests:
continue
lines.append(f'### {title}')
lines.append('')
# Header row: Test | Expected | Server1 | Server2 | ...
hdr = '| Test | Expected | ' + ' | '.join(f'**{n}**' for n in names) + ' |'
sep = '|---|---' + ''.join('|:---:' for _ in names) + '|'
lines.append(hdr)
lines.append(sep)
# One row per test
for tid in cat_tests:
first = lookup[names[0]][tid]
expected = first['expected']
cells = []
for n in names:
r = lookup[n].get(tid)
if not r:
cells.append('—')
else:
icon = '✅' if r['verdict'] == 'Pass' else ('⚠️' if r['verdict'] == 'Warn' else '❌')
cells.append(f"{icon}`{r['got']}`")
lines.append(f"| `{short(tid)}` | {expected} | " + ' | '.join(cells) + ' |')
lines.append('')
lines.append(f"<sub>Commit: {commit_id[:7]}</sub>")
with open('probe-comment.md', 'w') as f:
f.write('\n'.join(lines))
if baseline_failures:
sys.exit(1)
PYEOF
# ── Upload / publish ───────────────────────────────────────────
- name: Upload results
uses: actions/upload-artifact@v4
if: always()
with:
name: probe-results
path: probe-*.json
- name: Save PR metadata
if: github.event_name == 'pull_request' && steps.changes.outputs.servers != '[]'
run: echo '${{ github.event.number }}' > pr-number.txt
- name: Upload PR comment
if: always() && github.event_name == 'pull_request' && steps.changes.outputs.servers != '[]'
uses: actions/upload-artifact@v4
with:
name: probe-pr-comment
path: |
probe-comment.md
pr-number.txt
- name: Push to latest-results
if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if git fetch origin latest-results 2>/dev/null; then
git worktree add /tmp/latest-results origin/latest-results
else
git worktree add --detach /tmp/latest-results HEAD
git -C /tmp/latest-results switch --orphan latest-results
fi
mkdir -p /tmp/latest-results/probe
cp probe-data.js /tmp/latest-results/probe/data.js
cd /tmp/latest-results
git add probe/data.js
if git diff --cached --quiet; then
echo "No changes to commit."
else
git commit -m "Update probe results"
git push origin HEAD:latest-results
fi
cd -
git worktree remove /tmp/latest-results || true
- name: Rebuild docs
if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main'
run: gh workflow run "Deploy Docs to GitHub Pages"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}