test(metaharness): bench JSON has results[] with numeric meanUs (iter 114)

iter-88 verified bench output JSON.parses. iter-114 goes deeper into
the schema: the bench JSON must have a non-empty `results[]` array
with `meanUs: number` and `label: string` per entry.

The bug-class iter-114 catches:
   - Empty results array (e.g., wrong loop bounds): JSON.parse passes,
     iter-82 GITHUB_STEP_SUMMARY table renders empty, iter-99 wall-budget
     reads undefined meanUs
   - Non-numeric meanUs (e.g., a bug stringifies it): downstream
     consumers compute Number(meanUs) → NaN → broken comparisons
   - Missing label: artifact analysis can't distinguish per-category
     measurements

These are real failure modes that iter-88's parse-only gate misses.

WHAT SHIPPED — smoke step 17z77

For each of bench-similarity + bench-parse-mcp-scan:
   - Run with --iters 500 --format json
   - Parse + assert:
       results is an array
       results.length > 0
       every entry has meanUs as number (int or float)
       every entry has label as string

Specific failure form: ${bench}-empty / ${bench}-non-numeric-meanUs
/ ${bench}-not-array / ${bench}-non-string-label

GATES THIS ITER
   smoke:    116 → 117 (step 17z77 green)
   contract: 2 bench scripts × results[].meanUs + label shape verified

BENCH SCRIPT CONTRACT (post-iter-114)

| Gate                    | What it catches              | Iter |
|-------------------------|------------------------------|------|
| `--format json` parses  | output contamination         | 88   |
| has generatedAt         | timestamp emission           | 112  |
| has results[]           | array shape + numeric meanUs | 114  |
| --max-mean-us threshold | perf regression              | 41+86|
| CI artifact upload      | historical baseline tracking | 82+87|

Five gates per bench script. Future bench-scripts should adopt the
same shape contract.

Co-Authored-By: RuFlo <ruv@ruv.net>
This commit is contained in:
ruv committed 2026-06-17 01:46:12 -04:00
1 parent 05b8e2f548
commit c712f4973a
1 file changed
+23
@@ -191,6 +191,29 @@ grep -q "execCli(\[\s*'-y'\s*,\s*'metaharness@latest'" "$F" 2>/dev/null || \
grep -q "cwd: opts" "$F" || miss="$miss no-cwd-passthrough"
[[ -z "$miss" ]] && ok || bad "$miss"
step "17z77. bench scripts emit results[] with numeric meanUs (iter 114)"
miss=""
# iter 88 verified bench output JSON.parses. iter 114 goes further:
# bench JSON must have a non-empty results[] array with numeric meanUs
# per entry. An empty array would pass JSON.parse but break iter-82/iter-87
# artifact analysis + the inline `node -e` GITHUB_STEP_SUMMARY tables.
for bench in bench-similarity bench-parse-mcp-scan; do
OUT=$(node "$ROOT/scripts/${bench}.mjs" --iters 500 --format json 2>/dev/null)
SHAPE=$(echo "$OUT" | python3 -c "
import json, sys, re
m = re.search(r'\{[\s\S]*\}', sys.stdin.read())
d = json.loads(m.group()) if m else {}
r = d.get('results', None)
if not isinstance(r, list): print('not-array')
elif len(r) == 0: print('empty')
elif not all(isinstance(x.get('meanUs'), (int, float)) for x in r): print('non-numeric-meanUs')
elif not all(isinstance(x.get('label'), str) for x in r): print('non-string-label')
else: print('OK')
" 2>/dev/null)
[[ "$SHAPE" == "OK" ]] || miss="$miss ${bench}-${SHAPE}"
done
[[ -z "$miss" ]] && ok || bad "$miss"
step "17z76. oia-audit emits startedAt + finishedAt timestamp pair (iter 113)"
miss=""
# Companion to iter-112. oia-audit is the documented multi-step