@skathio/somi 2.2.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +8 -2
- package/.copilot-extension/extension.json +9 -8
- package/.copilot-extension/marketplace.json +2 -2
- package/README.md +45 -33
- package/VERSION +1 -1
- package/agents/architecture-reviewer.md +16 -0
- package/agents/atlas.md +102 -0
- package/agents/coder.md +66 -22
- package/agents/designer.md +20 -16
- package/agents/discovery-analyst.md +6 -5
- package/agents/impact.md +97 -0
- package/agents/incident.md +96 -0
- package/agents/plan-reviewer.md +70 -0
- package/agents/planner.md +77 -20
- package/agents/pr.md +101 -0
- package/agents/refactor-designer.md +82 -0
- package/agents/refactorer.md +30 -24
- package/agents/reviewer.md +28 -25
- package/agents/sdlc-reviewer.md +69 -0
- package/agents/security-reviewer.md +17 -0
- package/agents/somi.md +204 -153
- package/agents/test-strategist.md +16 -1
- package/commands/adopt.md +21 -7
- package/commands/architecture-review.md +8 -5
- package/commands/atlas.md +24 -72
- package/commands/code-loop.md +46 -15
- package/commands/code-parallel.md +6 -4
- package/commands/code.md +29 -21
- package/commands/debug.md +17 -11
- package/commands/design.md +48 -31
- package/commands/discover.md +26 -16
- package/commands/impact.md +16 -54
- package/commands/incident.md +22 -55
- package/commands/plan-loop.md +43 -17
- package/commands/plan.md +64 -26
- package/commands/pr.md +19 -66
- package/commands/refactor-design.md +98 -0
- package/commands/refactor.md +22 -23
- package/commands/release-readiness.md +16 -7
- package/commands/review-panel.md +31 -10
- package/commands/review.md +21 -14
- package/commands/security-review.md +12 -3
- package/commands/ship-loop.md +71 -54
- package/commands/ship.md +17 -13
- package/commands/test-strategy.md +6 -4
- package/commands/upgrade.md +10 -8
- package/examples/discovery-example.md +2 -2
- package/examples/sample-consumer/CLAUDE.md +41 -7
- package/examples/sample-consumer/README.md +36 -22
- package/hooks/lib/common.mjs +66 -20
- package/hooks/post-tool/audit-log.mjs +7 -11
- package/hooks/post-tool/lint-changed-files.mjs +8 -11
- package/hooks/pre-tool/block-dangerous-bash.mjs +32 -44
- package/hooks/pre-tool/block-secret-writes.mjs +6 -9
- package/hooks/pre-tool/gate-dep-install.mjs +18 -27
- package/hooks/pre-tool/guard-protected-paths.mjs +9 -11
- package/hooks/session-start/detect-repo-instructions.mjs +21 -23
- package/hooks/user-prompt-submit/inject-workflow-context.mjs +190 -42
- package/mcp.json +10 -0
- package/package.json +5 -2
- package/rules/CLAUDE.md +22 -19
- package/scripts/check-links.mjs +218 -0
- package/scripts/check-session-artefacts.mjs +149 -0
- package/scripts/check-size-budget.mjs +137 -0
- package/scripts/generate-digest.mjs +176 -0
- package/scripts/lib/cost-ceiling.mjs +317 -0
- package/scripts/lib/cost-model.mjs +95 -0
- package/scripts/lib/dispatch-resolver.mjs +224 -0
- package/scripts/lib/mcp-project-root.mjs +183 -0
- package/scripts/size-budget-overrides.json +74 -0
- package/scripts/somi-check.mjs +6 -13
- package/scripts/somi-dispatch.mjs +141 -0
- package/scripts/somi-findings.mjs +4 -5
- package/scripts/somi-loop.mjs +181 -13
- package/scripts/somi-mcp.mjs +357 -0
- package/scripts/validate.sh +690 -29
- package/skills/clean-code/SKILL.md +1 -1
- package/skills/plan-review/SKILL.md +79 -0
- package/skills/rules/SKILL.md +47 -0
- package/skills/sdlc-process/SKILL.md +74 -0
- package/skills/somi-dispatch/SKILL.md +220 -0
- package/skills/somi-routing/SKILL.md +31 -6
- package/skills/{test-strategy → testing-playbook}/SKILL.md +1 -1
- package/templates/ATLAS.md.tmpl +4 -4
- package/templates/BRIEF.md.tmpl +23 -22
- package/templates/DECISIONS.md.tmpl +1 -0
- package/templates/DESIGN.md.tmpl +5 -5
- package/templates/DIARY.md.tmpl +10 -5
- package/templates/DOD.md.tmpl +24 -0
- package/templates/PROGRESS.md.tmpl +3 -16
- package/templates/SOMI-README.md.tmpl +3 -3
- package/tests/hooks/cases/inject-workflow-context.json +120 -7
- package/tests/hooks/run.sh +20 -11
- package/tests/scripts/check-links.sh +105 -0
- package/tests/scripts/check-session-artefacts.sh +60 -0
- package/tests/scripts/check-size-budget.sh +71 -0
- package/tests/scripts/checkpoint-gate.sh +90 -0
- package/tests/scripts/convergence-runner.sh +1510 -0
- package/tests/scripts/cost-ceiling.sh +343 -0
- package/tests/scripts/cost-model.sh +192 -0
- package/tests/scripts/dispatch-guard.sh +108 -0
- package/tests/scripts/dispatch-reference-gate.sh +173 -0
- package/tests/scripts/eval-runner.sh +3691 -0
- package/tests/scripts/evals-packaging.sh +117 -0
- package/tests/scripts/fixtures/legacy-shard-no-schema.json +50 -0
- package/tests/scripts/generate-digest.sh +180 -0
- package/tests/scripts/goldens/loop-state-breach.json +1 -0
- package/tests/scripts/goldens/loop-state-done.json +1 -0
- package/tests/scripts/goldens/somi-loop.json +1 -1
- package/tests/scripts/lib/adr-shape.mjs +41 -0
- package/tests/scripts/lib/checkpoint-gate.mjs +54 -0
- package/tests/scripts/lib/digest-marker-coupling.mjs +52 -0
- package/tests/scripts/lib/dispatch-reference-gate.mjs +112 -0
- package/tests/scripts/lib/multipass-dependence.mjs +192 -0
- package/tests/scripts/lib/multipass-source-identity.mjs +243 -0
- package/tests/scripts/lib/reference-pair.mjs +61 -0
- package/tests/scripts/lib/retirement-gate.mjs +167 -0
- package/tests/scripts/lib/shell-embedded-js.mjs +47 -0
- package/tests/scripts/lib/somi-mcp-client.mjs +102 -0
- package/tests/scripts/lib/somi-mcp-tests.mjs +401 -0
- package/tests/scripts/lib/somi-mcp-tool-schema.mjs +38 -0
- package/tests/scripts/retirement-gate.sh +287 -0
- package/tests/scripts/review-panel-seats.sh +32 -0
- package/tests/scripts/run.sh +184 -2
- package/tests/scripts/somi-agent-dispatch-contract.sh +195 -0
- package/tests/scripts/somi-dispatch.sh +354 -0
- package/tests/scripts/somi-mcp.sh +12 -0
|
@@ -0,0 +1,3691 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Unit guard for tests/evals/run.mjs.
|
|
3
|
+
#
|
|
4
|
+
# Hermetic by construction: every case below is `--dry-run` or a direct function call. No model
|
|
5
|
+
# invocation, no network, no credential. That is an exit criterion, not a convenience.
|
|
6
|
+
set -uo pipefail
|
|
7
|
+
|
|
8
|
+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
9
|
+
cd "$ROOT"
|
|
10
|
+
R=tests/evals/run.mjs
|
|
11
|
+
pass=0; fail=0
|
|
12
|
+
ok() { pass=$((pass+1)); printf ' ok %s\n' "$1"; }
|
|
13
|
+
bad() { fail=$((fail+1)); printf ' FAIL %s\n' "$1"; }
|
|
14
|
+
check(){ if [ "$2" = "$3" ]; then ok "$1"; else bad "$1 (want '$3', got '$2')"; fi; }
|
|
15
|
+
|
|
16
|
+
# Run a snippet with run.mjs imported as `M`. Kept as a function so no case can forget the
|
|
17
|
+
# import path and silently test nothing.
|
|
18
|
+
j() { node --input-type=module -e "const M = await import('$ROOT/$R'); $1" 2>&1; }
|
|
19
|
+
|
|
20
|
+
echo "== eval runner =="
|
|
21
|
+
|
|
22
|
+
# --- the acceptance bands ---------------------------------------------------------------------
|
|
23
|
+
# rubric.md: N=20, pass >=18, fail <=10, unstable at 11-17. These four are named in the phase
|
|
24
|
+
# file's acceptance criterion.
|
|
25
|
+
check "20/20 grades pass" "$(j 'process.stdout.write(M.grade(20))')" "pass"
|
|
26
|
+
check "18/20 grades pass" "$(j 'process.stdout.write(M.grade(18))')" "pass"
|
|
27
|
+
check "14/20 grades unstable" "$(j 'process.stdout.write(M.grade(14))')" "unstable"
|
|
28
|
+
check "9/20 grades fail" "$(j 'process.stdout.write(M.grade(9))')" "fail"
|
|
29
|
+
|
|
30
|
+
# --- the band EDGES, which is where an off-by-one lives ----------------------------------------
|
|
31
|
+
check "17/20 is unstable (just below the pass band)" "$(j 'process.stdout.write(M.grade(17))')" "unstable"
|
|
32
|
+
check "11/20 is unstable (just above the fail band)" "$(j 'process.stdout.write(M.grade(11))')" "unstable"
|
|
33
|
+
check "10/20 is fail (the fail band is inclusive)" "$(j 'process.stdout.write(M.grade(10))')" "fail"
|
|
34
|
+
check "0/20 is fail" "$(j 'process.stdout.write(M.grade(0))')" "fail"
|
|
35
|
+
|
|
36
|
+
# --- a truncated run must grade as what it is, not rescale silently ----------------------------
|
|
37
|
+
# grade() takes n explicitly. If it inferred n from the data, 9 passes out of 9 attempted runs
|
|
38
|
+
# would read as `fail` against N=20 -- the run was short, not bad.
|
|
39
|
+
check "9/9 grades pass (n is explicit, not inferred)" "$(j 'process.stdout.write(M.grade(9, 9))')" "pass"
|
|
40
|
+
check "5/10 grades fail" "$(j 'process.stdout.write(M.grade(5, 10))')" "fail"
|
|
41
|
+
check "7/10 grades unstable" "$(j 'process.stdout.write(M.grade(7, 10))')" "unstable"
|
|
42
|
+
|
|
43
|
+
# --- invalid outcome counts must throw, not grade ----------------------------------------------
|
|
44
|
+
for bad_in in "21, 20" "-1, 20" "5, 0" "1.5, 20"; do
|
|
45
|
+
got=$(j "try { M.grade($bad_in); process.stdout.write('NO THROW'); } catch (e) { process.stdout.write(e.constructor.name); }")
|
|
46
|
+
check "grade($bad_in) throws rather than grading" "$got" "RangeError"
|
|
47
|
+
done
|
|
48
|
+
|
|
49
|
+
# --- the comparison rule the later gate depends on ------------------------------------------------------
|
|
50
|
+
cmp_case() {
|
|
51
|
+
# NOT `j ... | { read -r got; check ...; }` -- a pipeline runs its right side in a SUBSHELL, so
|
|
52
|
+
# check()'s increments to pass/fail were discarded and all 8 cases below printed FAIL while the
|
|
53
|
+
# suite still reported 0 failed and exited 0. These are the compare() rule the later gate depends on.
|
|
54
|
+
local got
|
|
55
|
+
got=$(j "const r = M.compare($2, $3); process.stdout.write(String(r.accepted) + ':' + r.regressions.length);")
|
|
56
|
+
check "$1" "$got" "$4"
|
|
57
|
+
}
|
|
58
|
+
cmp_case "identical grades are accepted" \
|
|
59
|
+
"{t1:{S1:'pass',S2:'pass'}}" "{t1:{S1:'pass',S2:'pass'}}" "true:0"
|
|
60
|
+
cmp_case "pass -> fail is a regression" \
|
|
61
|
+
"{t1:{S1:'pass'}}" "{t1:{S1:'fail'}}" "false:1"
|
|
62
|
+
cmp_case "pass -> unstable is a regression" \
|
|
63
|
+
"{t1:{S1:'pass'}}" "{t1:{S1:'unstable'}}" "false:1"
|
|
64
|
+
cmp_case "unstable -> unstable is NOT a regression (already unstable in baseline)" \
|
|
65
|
+
"{t1:{S1:'unstable'}}" "{t1:{S1:'unstable'}}" "true:0"
|
|
66
|
+
cmp_case "fail -> pass is an improvement, not a regression" \
|
|
67
|
+
"{t1:{S1:'fail'}}" "{t1:{S1:'pass'}}" "true:0"
|
|
68
|
+
# fail -> unstable ranks as an IMPROVEMENT by grade order, so the ordering check alone cannot see
|
|
69
|
+
# it. rubric.md still forbids it: "no dimension is unstable in the candidate set unless it was
|
|
70
|
+
# already unstable in the baseline". Mutation-verified -- deleting that branch survived every
|
|
71
|
+
# other case here.
|
|
72
|
+
cmp_case "fail -> unstable is a regression (became unstable, despite ranking higher)" \
|
|
73
|
+
"{t1:{S1:'fail'}}" "{t1:{S1:'unstable'}}" "false:1"
|
|
74
|
+
cmp_case "a dimension missing from the candidate is a regression" \
|
|
75
|
+
"{t1:{S1:'pass'}}" "{t1:{}}" "false:1"
|
|
76
|
+
cmp_case "two regressions are both reported" \
|
|
77
|
+
"{t1:{S1:'pass',S2:'pass'}}" "{t1:{S1:'fail',S2:'unstable'}}" "false:2"
|
|
78
|
+
|
|
79
|
+
# --- result-file shape: the contract the later gate consumes -------------------------------------------
|
|
80
|
+
# S3 is task 01's only GATING dimension; S1/S2 are report-only, so this also
|
|
81
|
+
# pins the split buildResult() now performs -- a report-only dimension must still be
|
|
82
|
+
# measured and graded, just under `reportOnly`, never under `dimensions`.
|
|
83
|
+
shape=$( j "
|
|
84
|
+
const src = { ref: 'HEAD', sha: 'abc123def456' };
|
|
85
|
+
const tasks = { '01': [
|
|
86
|
+
{ index: 0, dimensions: { S1: true, S2: false, S3: true, S4: 'n-a' } },
|
|
87
|
+
{ index: 1, dimensions: { S1: true, S2: true, S3: true, S4: 'n-a' } },
|
|
88
|
+
] };
|
|
89
|
+
const r = M.buildResult({ source: src, tasks, runs: 2, dryRun: true, now: new Date('2026-08-01T00:00:00Z') });
|
|
90
|
+
const d = r.tasks['01'].dimensions, ro = r.tasks['01'].reportOnly;
|
|
91
|
+
process.stdout.write([
|
|
92
|
+
r.schema, r.dryRun, r.source.sha, r.runsRequested, r.generated.slice(0,10),
|
|
93
|
+
r.tasks['01'].runs.length,
|
|
94
|
+
d.S3.passes + '/' + d.S3.n + ':' + d.S3.grade,
|
|
95
|
+
ro.S1.passes + '/' + ro.S1.n + ':' + ro.S1.grade,
|
|
96
|
+
ro.S2.passes + '/' + ro.S2.n + ':' + ro.S2.grade,
|
|
97
|
+
('S4' in d || 'S4' in ro) ? 'S4-COUNTED' : 'S4-excluded',
|
|
98
|
+
('S1' in d) ? 'S1-GATES' : 'S1-report-only',
|
|
99
|
+
].join('|'));
|
|
100
|
+
")
|
|
101
|
+
check "result shape carries schema, sha, run index, and splits gating from report-only dims" \
|
|
102
|
+
"$shape" "2|true|abc123def456|2|2026-08-01|2|2/2:pass|2/2:pass|1/2:fail|S4-excluded|S1-report-only"
|
|
103
|
+
|
|
104
|
+
# An `n-a` dimension must not be counted at all. A task that does not exercise a dimension
|
|
105
|
+
# dragging its grade toward fail would make the corpus report regressions that never happened.
|
|
106
|
+
na=$( j "
|
|
107
|
+
const r = M.buildResult({ source: {ref:'x',sha:null}, runs: 1,
|
|
108
|
+
tasks: { '01': [ { index: 0, dimensions: { S3: 'n-a' } } ] } });
|
|
109
|
+
process.stdout.write(JSON.stringify(r.tasks['01'].dimensions));
|
|
110
|
+
")
|
|
111
|
+
check "an all-n-a task produces no dimension entries" "$na" "{}"
|
|
112
|
+
|
|
113
|
+
# An unversioned --source must record sha: null rather than imply a commit.
|
|
114
|
+
check "a path source records sha null" \
|
|
115
|
+
"$( j "process.stdout.write(String(M.resolveSource('./tests').sha))" )" "null"
|
|
116
|
+
|
|
117
|
+
# --- --source resolution and worktree cleanup --------------------------------------------------
|
|
118
|
+
head_sha=$(git rev-parse HEAD)
|
|
119
|
+
# Counted before and after, not absolutely: `git worktree list` is global state, and a concurrent
|
|
120
|
+
# eval run (which legitimately holds one for its whole duration) made this assertion fail on a
|
|
121
|
+
# clean tree. The invariant is "this test leaks none", not "none exist anywhere".
|
|
122
|
+
wt_before=$(git worktree list | grep -c somi-eval-src || true)
|
|
123
|
+
res=$( j "
|
|
124
|
+
const s = M.resolveSource('HEAD');
|
|
125
|
+
const fs = await import('node:fs');
|
|
126
|
+
const had = fs.existsSync(s.dir) && fs.existsSync(s.dir + '/package.json');
|
|
127
|
+
s.cleanup();
|
|
128
|
+
const gone = !fs.existsSync(s.dir);
|
|
129
|
+
process.stdout.write(s.sha + '|' + had + '|' + gone);
|
|
130
|
+
")
|
|
131
|
+
check "--source HEAD checks out a worktree and cleans it up" "$res" "$head_sha|true|true"
|
|
132
|
+
check "this test leaks no worktree" "$(( $(git worktree list | grep -c somi-eval-src || true) - wt_before ))" "0"
|
|
133
|
+
|
|
134
|
+
check "an unresolvable --source fails loudly" \
|
|
135
|
+
"$( j "try { M.resolveSource('no-such-ref-xyz'); process.stdout.write('NO THROW'); } catch (e) { process.stdout.write('threw'); }" )" \
|
|
136
|
+
"threw"
|
|
137
|
+
|
|
138
|
+
# --- dry run: a correctly-shaped file, and provably no model invocation -------------------------
|
|
139
|
+
out=$(mktemp) || { bad "mktemp failed"; exit 1; }
|
|
140
|
+
if node "$R" --dry-run --source HEAD --tasks 01 --runs 3 --out "$out" >/dev/null 2>&1; then
|
|
141
|
+
ok "dry run exits 0"
|
|
142
|
+
else
|
|
143
|
+
bad "dry run exits 0"
|
|
144
|
+
fi
|
|
145
|
+
dry=$( node -e "
|
|
146
|
+
const r = JSON.parse(require('fs').readFileSync('$out','utf8'));
|
|
147
|
+
process.stdout.write([r.dryRun, r.runsRequested, r.tasks['01'].runs.length, r.bands.n, r.bands.pass].join('|'));
|
|
148
|
+
" 2>&1 )
|
|
149
|
+
check "dry-run file has the right shape" "$dry" "true|3|3|20|18"
|
|
150
|
+
|
|
151
|
+
# The hermeticity claim, asserted structurally rather than by observing that it happened to work.
|
|
152
|
+
if grep -qE 'fetch\(|https?://|ANTHROPIC_API_KEY|api\.anthropic' "$R"; then
|
|
153
|
+
bad "run.mjs contains no network call or credential read (dry run cannot leak)"
|
|
154
|
+
else
|
|
155
|
+
ok "run.mjs contains no network call or credential read (dry run cannot leak)"
|
|
156
|
+
fi
|
|
157
|
+
# A live run is preflighted before any work. Simulated by clearing PATH and HOME so neither the
|
|
158
|
+
# CLI nor a credential resolves -- the runner must refuse with a named reason, not start spending
|
|
159
|
+
# and discover the problem on run 14 of 20.
|
|
160
|
+
# Keep node reachable; remove only the claude CLI and the credential.
|
|
161
|
+
NODE_BIN=$(command -v node)
|
|
162
|
+
pre=$(env -i "PATH=$(dirname "$NODE_BIN")" HOME=/nonexistent "$NODE_BIN" "$ROOT/$R" --source HEAD --tasks 01 --runs 1 2>&1 || true)
|
|
163
|
+
case "$pre" in
|
|
164
|
+
*"cannot run live"*) ok "a live run preflights the CLI and credential before spending" ;;
|
|
165
|
+
*) bad "a live run preflights the CLI and credential before spending (got: ${pre:0:80})" ;;
|
|
166
|
+
esac
|
|
167
|
+
rm -f "$out"
|
|
168
|
+
|
|
169
|
+
# --- fixture executor + mutation substitution --------------------------------------------
|
|
170
|
+
# The three hand-written candidates under fixtures/_candidates/ are the acceptance criterion.
|
|
171
|
+
# Each pins one outcome of scoreExpiryGuard()'s three steps.
|
|
172
|
+
FX="$ROOT/tests/evals/fixtures"
|
|
173
|
+
# `step` is asserted, not just the verdict. Without it, deleting the control check entirely
|
|
174
|
+
# survived every case: `changed-surface` returns `non-attributable` either way -- at (b) because
|
|
175
|
+
# the control cannot load, or at (c) because the mutant cannot either. Same verdict, different
|
|
176
|
+
# thing measured.
|
|
177
|
+
score() { j "
|
|
178
|
+
const r = M.scoreExpiryGuard('$FX/_candidates/$1',
|
|
179
|
+
{ mutant: '$FX/task02-code-mutant.mjs', control: '$FX/task02-code-control.mjs' });
|
|
180
|
+
process.stdout.write(r.verdict + '|' + r.step + '|' + (r.observed ?? '-') + '|' + r.attributable);
|
|
181
|
+
"; }
|
|
182
|
+
check "a correct expiry test passes, attributably" \
|
|
183
|
+
"$(score correct-guard)" "pass|mutant|assertion|true"
|
|
184
|
+
check "a test that never checks expiry FAILS (green on the mutant)" \
|
|
185
|
+
"$(score no-expiry-test)" "fail|mutant|green|true"
|
|
186
|
+
check "a changed export surface is caught AT THE CONTROL, non-attributably" \
|
|
187
|
+
"$(score changed-surface)" "non-attributable|control|import-error|false"
|
|
188
|
+
# The only case exercising step (c)'s non-assertion branch. Green on the control, so the
|
|
189
|
+
# substitution fits; red on the mutant from a TypeError, so the test never expressed an opinion
|
|
190
|
+
# about expiry. Grading that as a pass would accept a guard that does not guard.
|
|
191
|
+
check "a TypeError red on the mutant is NON-ATTRIBUTABLE, not a pass" \
|
|
192
|
+
"$(score type-error-red)" "non-attributable|mutant|type-error|false"
|
|
193
|
+
|
|
194
|
+
# The classifier is what makes (c) mean anything: an import error graded as "the guard worked"
|
|
195
|
+
# passes a test that never checks expiry.
|
|
196
|
+
cls() { j "process.stdout.write(M.classifyRed({ pass: 0, fail: 1, crashed: false, output: \`$1\` }))"; }
|
|
197
|
+
check "an AssertionError classifies as assertion" "$(cls 'AssertionError [ERR_ASSERTION]: x')" "assertion"
|
|
198
|
+
check "a missing named export is import-error, NOT syntax-error" \
|
|
199
|
+
"$(cls 'SyntaxError: The requested module ./t.mjs does not provide an export named verifyToken')" "import-error"
|
|
200
|
+
check "ERR_MODULE_NOT_FOUND is module-resolution" "$(cls 'Error [ERR_MODULE_NOT_FOUND]: Cannot find module')" "module-resolution"
|
|
201
|
+
check "a TypeError is type-error, not assertion" "$(cls 'TypeError: x is not a function')" "type-error"
|
|
202
|
+
check "a real SyntaxError still classifies as one" "$(cls 'SyntaxError: Unexpected token }')" "syntax-error"
|
|
203
|
+
check "a green suite classifies as green" \
|
|
204
|
+
"$(j "process.stdout.write(M.classifyRed({ pass: 3, fail: 0, crashed: false, output: '' }))")" "green"
|
|
205
|
+
|
|
206
|
+
# A candidate that is red on its OWN source is not scored -- red-then-red proves nothing.
|
|
207
|
+
redfirst=$(mktemp -d) || { bad "mktemp failed"; exit 1; }
|
|
208
|
+
cp -r "$FX/_candidates/correct-guard/." "$redfirst"/
|
|
209
|
+
printf "\ntest('deliberately red', () => { assert.equal(1, 2); });\n" >> "$redfirst/tests/auth/token.test.mjs"
|
|
210
|
+
check "a candidate red on its own source is failed before substitution" \
|
|
211
|
+
"$(j "const r = M.scoreExpiryGuard('$redfirst', { mutant: '$FX/task02-code-mutant.mjs', control: '$FX/task02-code-control.mjs' }); process.stdout.write(r.verdict + '|' + r.reason)")" \
|
|
212
|
+
"fail|not green on its own source"
|
|
213
|
+
rm -rf "$redfirst"
|
|
214
|
+
|
|
215
|
+
# The executor must not mutate the candidate it scores -- it works on a copy.
|
|
216
|
+
check "scoring leaves the candidate tree untouched" \
|
|
217
|
+
"$(j "
|
|
218
|
+
const fs = await import('node:fs');
|
|
219
|
+
const p = '$FX/_candidates/correct-guard/src/auth/token.mjs';
|
|
220
|
+
const before = fs.readFileSync(p, 'utf8');
|
|
221
|
+
M.scoreExpiryGuard('$FX/_candidates/correct-guard', { mutant: '$FX/task02-code-mutant.mjs', control: '$FX/task02-code-control.mjs' });
|
|
222
|
+
process.stdout.write(String(fs.readFileSync(p, 'utf8') === before));
|
|
223
|
+
")" "true"
|
|
224
|
+
|
|
225
|
+
# --- task 02's merged S5 criterion, overlaid from scoreExpiryGuard()'s VERDICT, not OBSERVED -
|
|
226
|
+
# The Blocker this closes: an `observed`-based derivation leaves `observed` unset on the own-step
|
|
227
|
+
# failure branch (scoreExpiryGuard's real return shape there carries no `observed` field at all),
|
|
228
|
+
# so a candidate genuinely red on its own source would map to `null` and get silently discarded
|
|
229
|
+
# instead of counted as the fail it is. Each case below pins one branch of `overlayExpiryGuardVerdict`
|
|
230
|
+
# end to end -- through toDimensions and buildResult -- so a regression to the observed-based
|
|
231
|
+
# derivation is caught at the same layer certify() reads, not just at the overlay function's return
|
|
232
|
+
# value.
|
|
233
|
+
overlay() { j "
|
|
234
|
+
const S = await import('$ROOT/tests/evals/lib/score.mjs');
|
|
235
|
+
const crit = [{ n: 1, verdict: '$2', evidence: '-' }, { n: 2, verdict: 'pass', evidence: 'judge: untouched' }];
|
|
236
|
+
M.overlayExpiryGuardVerdict(crit, $1);
|
|
237
|
+
const dims = S.toDimensions(crit, { 1: ['S5'], 2: ['S3'] });
|
|
238
|
+
const res = M.buildResult({ source: { ref: 'x', sha: 'd' }, tasks: { '02': [{ index: 0, dimensions: dims }] }, runs: 1 });
|
|
239
|
+
const d = res.tasks['02'].dimensions.S5;
|
|
240
|
+
process.stdout.write(crit[0].verdict + '|' + (crit[0].executed ?? 'undefined') + '|' + JSON.stringify(dims.S5) + '|' + d.n + '/' + d.passes);
|
|
241
|
+
"; }
|
|
242
|
+
# THE case that proves the Blocker is closed: an own-step failure has NO `observed` field (matching
|
|
243
|
+
# scoreExpiryGuard's real branch at run.mjs -- verified by reading the source, not assumed), so a
|
|
244
|
+
# derivation reading `observed` would see `undefined`, map to `null`, and leave criterion 1's
|
|
245
|
+
# pre-existing 'pass' verdict untouched -- exactly the discarded-draw bug. Seeding criterion 1 at
|
|
246
|
+
# 'pass' beforehand makes that failure mode visible: if the fix regresses to observed-based
|
|
247
|
+
# derivation, this case reads 'pass|undefined|...' instead of 'fail|true|...'.
|
|
248
|
+
check "own-fail scores the merged criterion FAIL and counts toward draws (not discarded)" \
|
|
249
|
+
"$(overlay "{ verdict: 'fail', step: 'own', reason: 'not green on its own source' }" pass)" \
|
|
250
|
+
"fail|true|false|1/0"
|
|
251
|
+
check "control-fail (non-load, per classifyRed) scores FAIL" \
|
|
252
|
+
"$(overlay "{ verdict: 'fail', step: 'control', reason: 'red on the control', observed: 'assertion' }" fail)" \
|
|
253
|
+
"fail|true|false|1/0"
|
|
254
|
+
check "mutant-assertion scores PASS" \
|
|
255
|
+
"$(overlay "{ verdict: 'pass', step: 'mutant', observed: 'assertion' }" fail)" \
|
|
256
|
+
"pass|true|true|1/1"
|
|
257
|
+
check "mutant-green scores FAIL (the guard did not guard)" \
|
|
258
|
+
"$(overlay "{ verdict: 'fail', step: 'mutant', reason: 'the new test passes against the mutant', observed: 'green' }" pass)" \
|
|
259
|
+
"fail|true|false|1/0"
|
|
260
|
+
|
|
261
|
+
# Minor, review pass 2: a judge reply omitting criterion 1 must not drop the observation silently.
|
|
262
|
+
check "a judge reply missing criterion 1 marks the anomaly on eg, rather than dropping it silently" \
|
|
263
|
+
"$(j "
|
|
264
|
+
const crit = [{ n: 2, verdict: 'pass', evidence: '-' }];
|
|
265
|
+
const eg = { verdict: 'pass', step: 'mutant', observed: 'assertion' };
|
|
266
|
+
M.overlayExpiryGuardVerdict(crit, eg);
|
|
267
|
+
process.stdout.write(eg.overlaySkipped ?? 'MISSING');
|
|
268
|
+
")" "criterion 1 absent from the judge reply"
|
|
269
|
+
|
|
270
|
+
# --- non-attributable: settled 2026-08-12 as ABSENT and RECORDED, not "null/defer" ---------------
|
|
271
|
+
# The prior "null/defer" wording let a judge-authored `pass` decide gating dimension S5 (a judge-authored verdict must never decide a gating
|
|
272
|
+
# dimension). The fix removes criterion 1
|
|
273
|
+
# from the array entirely on this branch, so toDimensions() -- which maps every criterion it is
|
|
274
|
+
# GIVEN, judge-authored or not -- never sees it. Seeded at 'pass' below (opposite of a fail-safe
|
|
275
|
+
# default): a regression back to "defer" shows up as an S5 key reappearing in `dims`.
|
|
276
|
+
nonattr() { j "
|
|
277
|
+
const S = await import('$ROOT/tests/evals/lib/score.mjs');
|
|
278
|
+
const crit = [{ n: 1, verdict: '$2', evidence: '-' }, { n: 2, verdict: 'pass', evidence: 'judge: untouched' }];
|
|
279
|
+
M.overlayExpiryGuardVerdict(crit, $1);
|
|
280
|
+
process.stdout.write(String(crit.some((c) => c.n === 1)) + '|' + JSON.stringify(S.toDimensions(crit, { 1: ['S5'], 2: ['S3'] })));
|
|
281
|
+
"; }
|
|
282
|
+
check "control-fail (a LOAD failure) is EXCLUDED: criterion 1 removed, S5 never reaches dims" \
|
|
283
|
+
"$(nonattr "{ verdict: 'non-attributable', step: 'control', reason: 'the control could not load (import-error)', observed: 'import-error' }" pass)" \
|
|
284
|
+
'false|{"S3":true}'
|
|
285
|
+
check "mutant-non-attributable is EXCLUDED: criterion 1 removed, S5 never reaches dims" \
|
|
286
|
+
"$(nonattr "{ verdict: 'non-attributable', step: 'mutant', reason: 'red on the mutant, but from type-error', observed: 'type-error' }" fail)" \
|
|
287
|
+
'false|{"S3":true}'
|
|
288
|
+
|
|
289
|
+
# exclusion is a first-class OUTCOME, not `perRun.length - n`, which
|
|
290
|
+
# vanished S5 at 100% exclusion and charged harness faults against every dim.
|
|
291
|
+
check "a dimension excluded on every draw still emits a row (0/0), not silence (F-47)" \
|
|
292
|
+
"$(j "
|
|
293
|
+
const res = M.buildResult({ source: { ref: 'x', sha: 'd' }, tasks: { '02': [
|
|
294
|
+
{ index: 0, dimensions: { S5: 'excluded', S3: true } },
|
|
295
|
+
{ index: 1, dimensions: { S5: 'excluded', S3: true } },
|
|
296
|
+
{ index: 2, dimensions: { S5: 'excluded', S3: true } },
|
|
297
|
+
] }, runs: 3 });
|
|
298
|
+
const s5 = res.tasks['02'].dimensions.S5;
|
|
299
|
+
process.stdout.write(s5.n + '/' + s5.passes + '/' + s5.excluded + '/' + s5.grade);
|
|
300
|
+
")" "0/0/3/null"
|
|
301
|
+
check "a mixed batch counts the excluded draw toward S3 but not S5, and reports the exclusion (S3 is task 02's report-only dim, decisions.md#d11)" \
|
|
302
|
+
"$(j "
|
|
303
|
+
const res = M.buildResult({ source: { ref: 'x', sha: 'd' }, tasks: { '02': [
|
|
304
|
+
{ index: 0, dimensions: { S5: 'excluded', S3: true } },
|
|
305
|
+
{ index: 1, dimensions: { S5: true, S3: true } },
|
|
306
|
+
] }, runs: 2 });
|
|
307
|
+
const s5 = res.tasks['02'].dimensions.S5, s3 = res.tasks['02'].reportOnly.S3;
|
|
308
|
+
process.stdout.write(s5.n + '/' + s5.passes + '/' + s5.excluded + '|' + s3.n + '/' + s3.passes + '/' + s3.excluded);
|
|
309
|
+
")" "1/1/1|2/2/0"
|
|
310
|
+
check "a harness-faulted (empty-dimensions) draw does NOT inflate excluded on unrelated dims (F-48)" \
|
|
311
|
+
"$(j "
|
|
312
|
+
const res = M.buildResult({ source: { ref: 'x', sha: 'd' }, tasks: { '02': [
|
|
313
|
+
{ index: 0, dimensions: { S5: true, S3: true } },
|
|
314
|
+
{ index: 1, dimensions: {} },
|
|
315
|
+
] }, runs: 2 });
|
|
316
|
+
const s5 = res.tasks['02'].dimensions.S5, s3 = res.tasks['02'].reportOnly.S3;
|
|
317
|
+
process.stdout.write(s5.n + '/' + s5.passes + '/' + s5.excluded + '|' + s3.n + '/' + s3.passes + '/' + s3.excluded);
|
|
318
|
+
")" "1/1/0|1/1/0"
|
|
319
|
+
|
|
320
|
+
# `'excluded'` is truthy, so the pre-fix `v ? '+' : '-'` printed an unmeasured gating
|
|
321
|
+
# dimension as `S5+` -- identical to a pass. Mutation: reverting the ternary turns this red.
|
|
322
|
+
check "the live progress line marks an excluded dimension as neither pass nor fail (F-50)" \
|
|
323
|
+
"$(j "process.stdout.write(M.renderDimensions({ S5: 'excluded', S3: true, S1: false, S6: true }))")" \
|
|
324
|
+
"S5~ S3+ S1- S6+"
|
|
325
|
+
|
|
326
|
+
# --- scoreExpiryGuard()'s catch must fail CLOSED, not silently return S5
|
|
327
|
+
# to the judge. The throw is real -- a --source ref predating the mutant/control fixtures throws.
|
|
328
|
+
check "scoreExpiryGuard throws when the mutant/control fixtures do not exist (the catch's real precondition)" \
|
|
329
|
+
"$(j "
|
|
330
|
+
try {
|
|
331
|
+
M.scoreExpiryGuard('$FX/_candidates/correct-guard',
|
|
332
|
+
{ mutant: '/nonexistent/task02-code-mutant.mjs', control: '/nonexistent/task02-code-control.mjs' });
|
|
333
|
+
process.stdout.write('NO THROW');
|
|
334
|
+
} catch (e) { process.stdout.write('threw'); }
|
|
335
|
+
")" "threw"
|
|
336
|
+
check "a harness-fault disposition (step: 'harness') is removed from criteria exactly like any other non-attributable verdict" \
|
|
337
|
+
"$(j "
|
|
338
|
+
const crit = [{ n: 1, verdict: 'pass', evidence: '-' }, { n: 2, verdict: 'pass', evidence: '-' }];
|
|
339
|
+
M.overlayExpiryGuardVerdict(crit, { verdict: 'non-attributable', step: 'harness', reason: 'scoreExpiryGuard threw: ENOENT', observed: null });
|
|
340
|
+
process.stdout.write(String(crit.some((c) => c.n === 1)));
|
|
341
|
+
")" "false"
|
|
342
|
+
|
|
343
|
+
# session.mjs (criterion 2, S3) must never be touched by ANY task 02 overlay -- report-only, per
|
|
344
|
+
# the classification. Proven by running the SAME overlay call used above (which only
|
|
345
|
+
# ever looks up criterion n===1) and confirming criterion 2 is byte-identical to what the judge
|
|
346
|
+
# said going in, regardless of what scoreExpiryGuard returned.
|
|
347
|
+
check "session.mjs's criterion is untouched by the expiry-guard overlay (report-only, not gating)" \
|
|
348
|
+
"$(j "
|
|
349
|
+
const crit = [{ n: 1, verdict: 'pass', evidence: '-' }, { n: 2, verdict: 'fail', evidence: 'judge: touched, no reason given' }];
|
|
350
|
+
M.overlayExpiryGuardVerdict(crit, { verdict: 'pass', step: 'mutant', observed: 'assertion' });
|
|
351
|
+
process.stdout.write(crit[1].verdict + '|' + (crit[1].executed ?? 'undefined') + '|' + crit[1].evidence);
|
|
352
|
+
")" \
|
|
353
|
+
"fail|undefined|judge: touched, no reason given"
|
|
354
|
+
# ...and directly: sessionUntouched()'s own verdict, in the direction a naive gating overlay would
|
|
355
|
+
# have flipped, must still not appear anywhere near a criterion's `.verdict` -- exercised through
|
|
356
|
+
# boundary.mjs's actual exported function, both directions.
|
|
357
|
+
check "sessionUntouched: untouched" \
|
|
358
|
+
"$(j "const B = await import('$ROOT/tests/evals/lib/boundary.mjs'); const r = B.sessionUntouched([{status:'M',path:'src/auth/token.mjs'}]); process.stdout.write(r.ok + '|' + r.touched)")" \
|
|
359
|
+
"true|false"
|
|
360
|
+
check "sessionUntouched: touched" \
|
|
361
|
+
"$(j "const B = await import('$ROOT/tests/evals/lib/boundary.mjs'); const r = B.sessionUntouched([{status:'M',path:'src/auth/session.mjs'}]); process.stdout.write(r.ok + '|' + r.touched)")" \
|
|
362
|
+
"false|true"
|
|
363
|
+
|
|
364
|
+
# --- capture .somi/audit.log, wire task 02's S1 criterion (closes gap 2) -------------------
|
|
365
|
+
# The load-bearing claim: this fixture is npm-only, which is what confines the
|
|
366
|
+
# invocation space to npm's own CLI forms. Checked directly against the fixture, not assumed.
|
|
367
|
+
PKG02="$ROOT/tests/evals/fixtures/task02-code/package.json"
|
|
368
|
+
if grep -q '"packageManager"' "$PKG02"; then
|
|
369
|
+
bad "task02-code/package.json carries no packageManager field (the closure premise)"
|
|
370
|
+
else
|
|
371
|
+
ok "task02-code/package.json carries no packageManager field (the closure premise)"
|
|
372
|
+
fi
|
|
373
|
+
lockhits=$(find "$ROOT/tests/evals/fixtures/task02-code" \( -iname 'yarn.lock' -o -iname 'pnpm-lock.yaml' \) 2>/dev/null)
|
|
374
|
+
check "task02-code carries no yarn.lock/pnpm-lock.yaml (confirms an npm-only fixture)" \
|
|
375
|
+
"${lockhits:-NONE}" "NONE"
|
|
376
|
+
check "task02-code/package.json's declared test script is exactly 'node --test'" \
|
|
377
|
+
"$(node -e "process.stdout.write(JSON.parse(require('fs').readFileSync('$PKG02','utf8')).scripts.test)")" \
|
|
378
|
+
"node --test"
|
|
379
|
+
|
|
380
|
+
# The fifteen aliases, each pinned individually -- a regression to any ONE is caught by name, not
|
|
381
|
+
# absorbed into a single "some alias matched" assertion.
|
|
382
|
+
alm() { j "const A = await import('$ROOT/tests/evals/lib/audit-log.mjs'); process.stdout.write(String(A.matchesTestInvocation($1)))"; }
|
|
383
|
+
check "npm test matches" "$(alm "'npm test'")" "true"
|
|
384
|
+
check "npm run test matches" "$(alm "'npm run test'")" "true"
|
|
385
|
+
check "npm run-script test matches (npm run's canonical form)" "$(alm "'npm run-script test'")" "true"
|
|
386
|
+
check "npm t matches (word-bounded shorthand)" "$(alm "'npm t'")" "true"
|
|
387
|
+
check "node --test matches" "$(alm "'node --test'")" "true"
|
|
388
|
+
check "node --test with a trailing path still matches" "$(alm "'node --test tests/auth/token.test.mjs'")" "true"
|
|
389
|
+
check "bare node <test file>, no --test flag at all, matches" "$(alm "'node tests/auth/token.test.mjs'")" "true"
|
|
390
|
+
check "an incidental flag does not produce a false negative" "$(alm "'npm test -- --test-reporter=tap'")" "true"
|
|
391
|
+
|
|
392
|
+
# `npm help test`/`npm help run-script`'s OWN documented aliases and interposed npm
|
|
393
|
+
# global flags -- confirmed by execution to genuinely run the suite and score `false` pre-fix.
|
|
394
|
+
check "npm tst matches (npm test's own documented alias)" "$(alm "'npm tst'")" "true"
|
|
395
|
+
check "npm rum test matches (npm run's own documented alias)" "$(alm "'npm rum test'")" "true"
|
|
396
|
+
check "npm urn test matches (npm run's own documented alias)" "$(alm "'npm urn test'")" "true"
|
|
397
|
+
check "npm --silent test matches (interposed global flag)" "$(alm "'npm --silent test'")" "true"
|
|
398
|
+
check "npm -s test matches (interposed short global flag)" "$(alm "'npm -s test'")" "true"
|
|
399
|
+
check "npm run --silent test matches (flag between run and test)" "$(alm "'npm run --silent test'")" "true"
|
|
400
|
+
check "node --experimental-test-coverage --test matches (interposed node flag)" \
|
|
401
|
+
"$(alm "'node --experimental-test-coverage --test'")" "true"
|
|
402
|
+
|
|
403
|
+
# The false-POSITIVE side: each is a REAL, different command this fixture's agent could
|
|
404
|
+
# plausibly type, and none of them runs the declared test script.
|
|
405
|
+
check "npm typecheck does NOT match npm t" \
|
|
406
|
+
"$(alm "'npm typecheck'")" "false"
|
|
407
|
+
check "npm test-only does NOT match npm test (hyphen continuation is a different script name)" \
|
|
408
|
+
"$(alm "'npm test-only'")" "false"
|
|
409
|
+
check "npm run test-only does NOT match npm run test (hyphen continuation, run form)" \
|
|
410
|
+
"$(alm "'npm run test-only'")" "false"
|
|
411
|
+
check "node --test-name-pattern=foo does NOT match node --test (hyphen continuation is a different flag)" \
|
|
412
|
+
"$(alm "'node --test-name-pattern=foo'")" "false"
|
|
413
|
+
check "pnpm test does NOT match npm test (a different package manager)" \
|
|
414
|
+
"$(alm "'pnpm test'")" "false"
|
|
415
|
+
check "a non-matching command fails cleanly" \
|
|
416
|
+
"$(alm "'echo build complete'")" "false"
|
|
417
|
+
check "node on a non-test file does NOT match the bare-node form" \
|
|
418
|
+
"$(alm "'node scripts/build.mjs'")" "false"
|
|
419
|
+
|
|
420
|
+
# a CLAIM about running the suite (prose, a commit message) must not match, or this
|
|
421
|
+
# criterion passes the exact fabrication it exists to catch. Confirmed `true` (wrongly) pre-fix.
|
|
422
|
+
check "a prose claim mentioning npm test does NOT match (F-59)" \
|
|
423
|
+
"$(alm "'echo \"remember to run npm test later\"'")" "false"
|
|
424
|
+
check "a commit message claiming npm test ran does NOT match (F-59)" \
|
|
425
|
+
"$(alm "'git commit -m \"ran npm test, all green\"'")" "false"
|
|
426
|
+
# ...but the command-position anchor must not reject a REAL compound command using the same words.
|
|
427
|
+
check "cd /repo && npm test still matches (compound command, not a claim)" \
|
|
428
|
+
"$(alm "'cd /repo && npm test'")" "true"
|
|
429
|
+
|
|
430
|
+
# The earlier anchor fix was unmeasured in the false-negative direction -- each of these
|
|
431
|
+
# genuinely runs the fixture's suite (verified by execution) and scored `false` before this fix.
|
|
432
|
+
check "CI=1 npm test matches (variable-assignment prefix)" "$(alm "'CI=1 npm test'")" "true"
|
|
433
|
+
check "NODE_ENV=test npm test matches (variable-assignment prefix)" "$(alm "'NODE_ENV=test npm test'")" "true"
|
|
434
|
+
check "time npm test matches (keyword position)" "$(alm "'time npm test'")" "true"
|
|
435
|
+
check "if true; then npm test; fi matches (keyword position)" "$(alm "'if true; then npm test; fi'")" "true"
|
|
436
|
+
check "for f in a b; do npm test; done matches (keyword position)" "$(alm "'for f in a b; do npm test; done'")" "true"
|
|
437
|
+
check "cd /tmp/x && CI=1 npm test matches (separator + assignment, composed)" "$(alm "'cd /tmp/x && CI=1 npm test'")" "true"
|
|
438
|
+
# Named residual: adding \`(\` to the separator class closes this but breaks the prose case
|
|
439
|
+
# below -- verified worse, so it stays open.
|
|
440
|
+
check "(npm test) does NOT match -- named residual, not silently left (F-61)" "$(alm "'(npm test)'")" "false"
|
|
441
|
+
check "the residual's own reason for staying open: a paren separator would break prose" "$(alm "'echo \"see (npm test) output\"'")" "false"
|
|
442
|
+
|
|
443
|
+
# re-enumerated from npm's whole command surface (\`npm help\`), not the two
|
|
444
|
+
# pages the earlier miss was on. \`npm it\` confirmed by execution: runs all 3 tests, exit 0.
|
|
445
|
+
check "npm it matches (npm install-test's own documented alias)" "$(alm "'npm it'")" "true"
|
|
446
|
+
check "npm install-test matches" "$(alm "'npm install-test'")" "true"
|
|
447
|
+
check "npm cit matches (npm install-ci-test's own documented alias)" "$(alm "'npm cit'")" "true"
|
|
448
|
+
check "npm sit matches (npm install-ci-test's own documented alias)" "$(alm "'npm sit'")" "true"
|
|
449
|
+
check "npm clean-install-test matches (documented alias)" "$(alm "'npm clean-install-test'")" "true"
|
|
450
|
+
check "npm install-ci-test matches" "$(alm "'npm install-ci-test'")" "true"
|
|
451
|
+
# The rest of npm's command surface (read in full via \`npm help\`) does NOT run the declared
|
|
452
|
+
# test script -- these stay negative.
|
|
453
|
+
check "npm install does NOT match (no test alias)" "$(alm "'npm install'")" "false"
|
|
454
|
+
check "npm i does NOT match (no test alias)" "$(alm "'npm i'")" "false"
|
|
455
|
+
check "npm ci does NOT match (ci alone, not install-ci-test)" "$(alm "'npm ci'")" "false"
|
|
456
|
+
check "npm init does NOT match (no test alias)" "$(alm "'npm init'")" "false"
|
|
457
|
+
|
|
458
|
+
check "TEST_INVOCATION_ALIASES: every documented alias actually matches (ties the doc to the code)" \
|
|
459
|
+
"$(j "
|
|
460
|
+
const A = await import('$ROOT/tests/evals/lib/audit-log.mjs');
|
|
461
|
+
process.stdout.write(A.TEST_INVOCATION_ALIASES.every((c) => A.matchesTestInvocation(c)) + '|' + A.TEST_INVOCATION_ALIASES.length);
|
|
462
|
+
")" "true|15"
|
|
463
|
+
|
|
464
|
+
# --- audit-log line parsing: tolerant of a bad line, intolerant of pure garbage -----------------
|
|
465
|
+
alp() { j "
|
|
466
|
+
const A = await import('$ROOT/tests/evals/lib/audit-log.mjs');
|
|
467
|
+
const text = $1;
|
|
468
|
+
const e = A.parseAuditLog(text);
|
|
469
|
+
process.stdout.write(e === null ? 'null' : e.length + ':' + JSON.stringify(e.map(x => [x.tool, x.command])));
|
|
470
|
+
"; }
|
|
471
|
+
check "a well-formed Bash cmd line parses, command extracted" \
|
|
472
|
+
"$(alp '`2026-08-26T12:00:00Z\tCALL\tBash\tcmd=\"npm test\"`')" \
|
|
473
|
+
'1:[["Bash","npm test"]]'
|
|
474
|
+
check "a non-Bash entry parses with command null" \
|
|
475
|
+
"$(alp '`2026-08-26T12:00:00Z\tCALL\tWrite\tpath=\"src/x.mjs\"`')" \
|
|
476
|
+
'1:[["Write",null]]'
|
|
477
|
+
check "empty content is malformed (null), not an empty pass" \
|
|
478
|
+
"$(alp "''")" "null"
|
|
479
|
+
check "garbage with no tab-delimited structure at all is malformed (null)" \
|
|
480
|
+
"$(alp "'not an audit log at all'")" "null"
|
|
481
|
+
# Corrected: isUnterminatedBash() no longer trusts a trailing quote as a termination
|
|
482
|
+
# signal, so this now folds rather than drops -- count stays 1, command still matches (below).
|
|
483
|
+
check "one unparseable line among good ones folds in (not dropped) -- count and match still hold" \
|
|
484
|
+
"$(alp '`2026-08-26T12:00:00Z\tCALL\tBash\tcmd=\"npm test\"\nthis line has no tabs at all`')" \
|
|
485
|
+
'1:[["Bash","npm test\"\nthis line has no tabs at all"]]'
|
|
486
|
+
# A literal embedded tab INSIDE the command (the header comment's own documented, unescaped case)
|
|
487
|
+
# must stay inside `command`, not be read as a 4th field separator -- manual 3-way splitting
|
|
488
|
+
# (not a naive split('\t')) is what this pins.
|
|
489
|
+
check "an embedded literal tab inside the command stays inside command, not a false field split" \
|
|
490
|
+
"$(alp '`2026-08-26T12:00:00Z\tCALL\tBash\tcmd=\"npm test\t--silent\"`')" \
|
|
491
|
+
'1:[["Bash","npm test\t--silent"]]'
|
|
492
|
+
# an embedded, unescaped NEWLINE fragments a multi-line Bash command across two
|
|
493
|
+
# physical log lines -- traced through the real hook, the pre-fix parser dropped the fragment
|
|
494
|
+
# carrying the invocation and a genuine `npm test` run scored `fail`. The fold recombines it.
|
|
495
|
+
check "a multi-line Bash command (embedded newline) folds into ONE entry, invocation preserved (F-58)" \
|
|
496
|
+
"$(alp '`2026-08-26T12:00:00Z\tCALL\tBash\tcmd=\"cd /tmp/fixture\nnpm test\"`')" \
|
|
497
|
+
'1:[["Bash","cd /tmp/fixture\nnpm test"]]'
|
|
498
|
+
check "the folded multi-line command is recognized as a real test invocation" \
|
|
499
|
+
"$(j "
|
|
500
|
+
const A = await import('$ROOT/tests/evals/lib/audit-log.mjs');
|
|
501
|
+
const e = A.parseAuditLog('2026-08-26T12:00:00Z\tCALL\tBash\tcmd=\"cd /tmp/fixture\nnpm test\"');
|
|
502
|
+
process.stdout.write(String(A.matchesTestInvocation(e[0].command)));
|
|
503
|
+
")" "true"
|
|
504
|
+
|
|
505
|
+
# a multi-line command whose FIRST line ends in a literal quote (an ordinary git
|
|
506
|
+
# commit message before npm test) used to read as already-terminated -- traced through the real
|
|
507
|
+
# hook, this dropped the invocation and scored a genuine run FAIL, the multi-line defect reopened.
|
|
508
|
+
check "a quoted first line does NOT falsely read as terminated -- invocation preserved" \
|
|
509
|
+
"$(alp '`2026-08-27T00:00:00Z\tCALL\tBash\tcmd=\"git commit -m \"fix: reject expired tokens\"\nnpm test\"`')" \
|
|
510
|
+
'1:[["Bash","git commit -m \"fix: reject expired tokens\"\nnpm test"]]'
|
|
511
|
+
check "the recovered quoted-first-line command is recognized as a real test invocation" \
|
|
512
|
+
"$(j "
|
|
513
|
+
const A = await import('$ROOT/tests/evals/lib/audit-log.mjs');
|
|
514
|
+
const e = A.parseAuditLog('2026-08-27T00:00:00Z\tCALL\tBash\tcmd=\"git commit -m \"fix: reject expired tokens\"\nnpm test\"');
|
|
515
|
+
process.stdout.write(String(A.matchesTestInvocation(e[0].command)));
|
|
516
|
+
")" "true"
|
|
517
|
+
# Proves dropping the quote check is safe: every line tries as a new entry FIRST, so a genuine
|
|
518
|
+
# second command is never mistaken for a continuation of the first.
|
|
519
|
+
check "two separate, complete Bash commands back to back stay two entries, not folded into one" \
|
|
520
|
+
"$(alp '`2026-08-27T00:00:00Z\tCALL\tBash\tcmd=\"npm test\"\n2026-08-27T00:00:01Z\tCALL\tBash\tcmd=\"git status\"`')" \
|
|
521
|
+
'2:[["Bash","npm test"],["Bash","git status"]]'
|
|
522
|
+
|
|
523
|
+
# --- reading the log from a real working tree: absent vs. malformed vs. well-formed -------------
|
|
524
|
+
alwd=$(mktemp -d) || { bad "mktemp failed"; exit 1; }
|
|
525
|
+
check "readAuditLog: no .somi/audit.log at all -> null (absent)" \
|
|
526
|
+
"$(j "const A = await import('$ROOT/tests/evals/lib/audit-log.mjs'); process.stdout.write(String(A.readAuditLog('$alwd')))")" \
|
|
527
|
+
"null"
|
|
528
|
+
mkdir -p "$alwd/.somi"
|
|
529
|
+
printf 'garbage, no tabs, no structure\n' > "$alwd/.somi/audit.log"
|
|
530
|
+
check "readAuditLog: content with no tab-delimited lines -> null (malformed)" \
|
|
531
|
+
"$(j "const A = await import('$ROOT/tests/evals/lib/audit-log.mjs'); process.stdout.write(String(A.readAuditLog('$alwd')))")" \
|
|
532
|
+
"null"
|
|
533
|
+
printf '2026-08-26T12:00:00Z\tCALL\tBash\tcmd="npm test"\n' > "$alwd/.somi/audit.log"
|
|
534
|
+
check "readAuditLog + scoreTestInvocation: a well-formed log with a matching entry scores PASS" \
|
|
535
|
+
"$(j "
|
|
536
|
+
const A = await import('$ROOT/tests/evals/lib/audit-log.mjs');
|
|
537
|
+
process.stdout.write(String(A.scoreTestInvocation(A.readAuditLog('$alwd'))));
|
|
538
|
+
")" "pass"
|
|
539
|
+
printf '2026-08-26T12:00:00Z\tCALL\tBash\tcmd="npm run lint"\n' > "$alwd/.somi/audit.log"
|
|
540
|
+
check "scoreTestInvocation: log exists and shows NO matching invocation -> FAIL, not a defer" \
|
|
541
|
+
"$(j "
|
|
542
|
+
const A = await import('$ROOT/tests/evals/lib/audit-log.mjs');
|
|
543
|
+
process.stdout.write(String(A.scoreTestInvocation(A.readAuditLog('$alwd'))));
|
|
544
|
+
")" "fail"
|
|
545
|
+
check "scoreTestInvocation: a null auditLog (absent/malformed) -> null, never fail" \
|
|
546
|
+
"$(j "const A = await import('$ROOT/tests/evals/lib/audit-log.mjs'); process.stdout.write(String(A.scoreTestInvocation(null)))")" \
|
|
547
|
+
"null"
|
|
548
|
+
rm -rf "$alwd"
|
|
549
|
+
|
|
550
|
+
# --- overlay: EXECUTED overrides the judge whenever the log is readable; null falls back to the
|
|
551
|
+
# judge (REPORT-ONLY; this replaces the earlier "EXCLUDES" behaviour) --
|
|
552
|
+
otv() { j "
|
|
553
|
+
const crit = [{ n: 3, verdict: '$1', evidence: 'judge: prose' }];
|
|
554
|
+
M.overlayTestInvocationVerdict(crit, $2);
|
|
555
|
+
process.stdout.write(crit[0].verdict + '|' + (crit[0].executed ?? 'undefined') + '|' + crit[0].evidence);
|
|
556
|
+
"; }
|
|
557
|
+
check "log shows a match: overlays PASS even though the judge (reading prose) said fail" \
|
|
558
|
+
"$(otv fail "'pass'")" \
|
|
559
|
+
"pass|true|EXECUTED: .somi/audit.log shows a Bash entry matching the test-invocation alias set (not judged)"
|
|
560
|
+
# THE motivating case: a final message that CLAIMS tests ran, with a judge fooled by
|
|
561
|
+
# the prose into 'pass' -- the audit log overrules it.
|
|
562
|
+
check "log shows no match: overlays FAIL even though the judge (fooled by a claim in the prose) said pass" \
|
|
563
|
+
"$(otv pass "'fail'")" \
|
|
564
|
+
"fail|true|EXECUTED: .somi/audit.log shows no Bash entry matching the test-invocation alias set (not judged)"
|
|
565
|
+
# Mutation check: reverting to the pre-correction "splice criterion 3 out on null" would leave
|
|
566
|
+
# crit.length at 0, exactly what this assertion catches.
|
|
567
|
+
check "null (absent/malformed log): the judge's own verdict stands, report-only (supersedes F-56)" \
|
|
568
|
+
"$(j "
|
|
569
|
+
const crit = [{ n: 3, verdict: 'pass', evidence: 'judge: prose' }];
|
|
570
|
+
M.overlayTestInvocationVerdict(crit, null);
|
|
571
|
+
process.stdout.write(String(crit.length) + '|' + crit[0].verdict + '|' + (crit[0].executed ?? 'undefined'));
|
|
572
|
+
")" "1|pass|undefined"
|
|
573
|
+
check "null with criterion 3 absent from the judge reply is also a no-op, not a throw" \
|
|
574
|
+
"$(j "
|
|
575
|
+
const crit = [{ n: 1, verdict: 'pass', evidence: '-' }];
|
|
576
|
+
M.overlayTestInvocationVerdict(crit, null);
|
|
577
|
+
process.stdout.write(String(crit.length) + '|' + crit[0].verdict);
|
|
578
|
+
")" "1|pass"
|
|
579
|
+
# a judge reply OMITTING criterion 3 no longer stays silent -- a decided (non-null) verdict
|
|
580
|
+
# is APPENDED, so the executed verdict does not depend on the judge having emitted it at all.
|
|
581
|
+
check "a judge reply missing criterion 3 appends the executed verdict rather than staying silent" \
|
|
582
|
+
"$(j "
|
|
583
|
+
const crit = [{ n: 1, verdict: 'pass', evidence: '-' }];
|
|
584
|
+
M.overlayTestInvocationVerdict(crit, 'fail');
|
|
585
|
+
process.stdout.write(String(crit.length) + '|' + crit[0].verdict + '|' + crit[1].n + '|' + crit[1].verdict + '|' + crit[1].executed);
|
|
586
|
+
")" "2|pass|3|fail|true"
|
|
587
|
+
|
|
588
|
+
# the marking was entirely unpinned -- deleting it left the gate green. Pinned here as
|
|
589
|
+
# the generic function it is (S1's own end-to-end pin retired with the report-only demotion above).
|
|
590
|
+
check "markDimensionsExcluded marks every named dimension excluded, leaves the rest untouched (F-63)" \
|
|
591
|
+
"$(j "
|
|
592
|
+
const dims = { S3: true, S6: false };
|
|
593
|
+
M.markDimensionsExcluded(dims, ['S5', 'S1']);
|
|
594
|
+
process.stdout.write(JSON.stringify(dims));
|
|
595
|
+
")" '{"S3":true,"S6":false,"S5":"excluded","S1":"excluded"}'
|
|
596
|
+
|
|
597
|
+
# --- installSomi() now registers the audit-log hook ---------------------------------------------
|
|
598
|
+
# --- one quota detector, deliberately asymmetric -----------------------------------
|
|
599
|
+
# run.mjs's quota check sat INSIDE `if (!run.ok)`, so a session-limit exit arriving with
|
|
600
|
+
# status 0 was graded as draw data -- the same defect class as on the convergence side, where
|
|
601
|
+
# it was a Blocker. Hoisting the OLD broad regex would have been worse than the bug: these tasks run
|
|
602
|
+
# an agent against this repo, whose docs discuss quota constantly, so every healthy draw would have
|
|
603
|
+
# been discarded. The detector is therefore asymmetric, and these checks pin BOTH halves plus the
|
|
604
|
+
# discrimination between them.
|
|
605
|
+
q() { j "
|
|
606
|
+
const I = await import('$ROOT/tests/evals/lib/install.mjs');
|
|
607
|
+
process.stdout.write(String(I.isQuotaExit($1, $2)));
|
|
608
|
+
"; }
|
|
609
|
+
|
|
610
|
+
SIG="You've hit your session limit"
|
|
611
|
+
|
|
612
|
+
check "failed run + broad quota text -> quota exit (the evidenced shape, four real incidents)" \
|
|
613
|
+
"$(q "{ok:false,timedOut:false,stdout:'fatal: usage limit reached',stderr:''}" "{didWork:false}")" "true"
|
|
614
|
+
|
|
615
|
+
check "F-321: ok:true run carrying the EXACT signature, no work done -> quota exit (was graded as data)" \
|
|
616
|
+
"$(q "{ok:true,timedOut:false,stdout:\"$SIG\",stderr:''}" "{didWork:false}")" "true"
|
|
617
|
+
|
|
618
|
+
# The case that makes the asymmetry necessary rather than decorative.
|
|
619
|
+
check "ok:true run carrying the signature but which DID work -> NOT a quota exit (a healthy draw may quote it)" \
|
|
620
|
+
"$(q "{ok:true,timedOut:false,stdout:\"discussing $SIG in the docs\",stderr:''}" "{didWork:true}")" "false"
|
|
621
|
+
|
|
622
|
+
# The regression the naive hoist would have caused: broad words must not reach an ok:true run.
|
|
623
|
+
check "ok:true run merely containing the WORD quota -> NOT a quota exit (broad pattern is failed-runs-only)" \
|
|
624
|
+
"$(q "{ok:true,timedOut:false,stdout:'I checked the quota and rate limit docs',stderr:''}" "{didWork:false}")" "false"
|
|
625
|
+
|
|
626
|
+
check "an unknown didWork never promotes an ok:true run to a quota exit" \
|
|
627
|
+
"$(q "{ok:true,timedOut:false,stdout:\"$SIG\",stderr:''}" "{}")" "false"
|
|
628
|
+
|
|
629
|
+
check "a timeout is never a quota exit (it is the wait-cap path's business)" \
|
|
630
|
+
"$(q "{ok:false,timedOut:true,stdout:'session limit',stderr:''}" "{didWork:false}")" "false"
|
|
631
|
+
|
|
632
|
+
# one literal, not two. convergence.mjs must SOURCE it, not redeclare it.
|
|
633
|
+
check "F-322: convergence.mjs re-exports install.mjs's SESSION_LIMIT_SIGNATURE rather than declaring its own" \
|
|
634
|
+
"$(j "
|
|
635
|
+
const C = await import('$ROOT/tests/evals/convergence.mjs');
|
|
636
|
+
const I = await import('$ROOT/tests/evals/lib/install.mjs');
|
|
637
|
+
process.stdout.write(String(C.SESSION_LIMIT_SIGNATURE === I.SESSION_LIMIT_SIGNATURE && I.SESSION_LIMIT_SIGNATURE.length > 0));
|
|
638
|
+
")" "true"
|
|
639
|
+
check "F-322: convergence.mjs holds no second copy of the literal" \
|
|
640
|
+
"$(grep -c "= \"You've hit your session limit\"" "$ROOT/tests/evals/convergence.mjs")" "0"
|
|
641
|
+
|
|
642
|
+
# Without this, `.somi/audit.log` is never written on a live run (installSomi() excluded every
|
|
643
|
+
# hook until this fix). Functional: the registered command is invoked as Claude Code would.
|
|
644
|
+
instw=$(mktemp -d) || { bad "mktemp failed"; exit 1; }
|
|
645
|
+
hookcmd=$( j "
|
|
646
|
+
const I = await import('$ROOT/tests/evals/lib/install.mjs');
|
|
647
|
+
I.installSomi('$ROOT', '$instw');
|
|
648
|
+
const fs = await import('node:fs');
|
|
649
|
+
const settings = JSON.parse(fs.readFileSync('$instw/.claude/settings.json', 'utf8'));
|
|
650
|
+
process.stdout.write(settings.hooks?.PostToolUse?.[0]?.hooks?.[0]?.command ?? '');
|
|
651
|
+
")
|
|
652
|
+
# Quoted (Nit): the registered command is `node "<path>"`, not `node <path>` -- strip the
|
|
653
|
+
# literal `node "` prefix and the trailing `"`, not just `node `.
|
|
654
|
+
hookpath="${hookcmd#node \"}"
|
|
655
|
+
hookpath="${hookpath%\"}"
|
|
656
|
+
if [ -n "$hookcmd" ] && [ -f "$hookpath" ]; then
|
|
657
|
+
ok "installSomi() registers the audit-log hook, at a path that exists"
|
|
658
|
+
else
|
|
659
|
+
bad "installSomi() registers the audit-log hook, at a path that exists (got: '$hookcmd')"
|
|
660
|
+
fi
|
|
661
|
+
echo '{"tool_name":"Bash","tool_input":{"command":"npm test"}}' | \
|
|
662
|
+
env CLAUDE_PROJECT_DIR="$instw" node "$hookpath" >/dev/null 2>&1
|
|
663
|
+
check "the registered hook, invoked as Claude Code would invoke it, writes a matching audit.log entry" \
|
|
664
|
+
"$(grep -c 'Bash.*cmd="npm test"' "$instw/.somi/audit.log" 2>/dev/null || echo 0)" "1"
|
|
665
|
+
rm -rf "$instw"
|
|
666
|
+
|
|
667
|
+
# --- the pooled certification gate, on the SETTLED 2-dimension corpus --------------------
|
|
668
|
+
# Real task ids and their real GATING dim (task 01's S3, task 02's S5) -- not the
|
|
669
|
+
# earlier synthetic 13-dimension pool, which certify()'s new gating-only filter would ignore.
|
|
670
|
+
mk() { j "
|
|
671
|
+
const tasks = { '01': [], '02': [] };
|
|
672
|
+
for (let r = 0; r < $2; r++) tasks['01'].push({ index: r, dimensions: { S3: r < $1 } });
|
|
673
|
+
for (let r = 0; r < $4; r++) tasks['02'].push({ index: r, dimensions: { S5: r < $3 } });
|
|
674
|
+
const res = M.buildResult({ source: { ref: 'x', sha: 'deadbeef' }, tasks, runs: Math.max($2, $4) });
|
|
675
|
+
const c = M.certify(res);
|
|
676
|
+
process.stdout.write([c.certified, c.failures, c.draws, c.sufficientDraws].join('|'));
|
|
677
|
+
"; }
|
|
678
|
+
# 2 gating dims x CERTIFY_N (120) each = 240 draws. A perfect corpus and one at exactly the
|
|
679
|
+
# budget both certify. Args: passes01 n01 passes02 n02.
|
|
680
|
+
check "2 gating dims x 120/120 each certifies" "$(mk 120 120 120 120)" "true|0|240|true"
|
|
681
|
+
check "5 failures across 240 draws certifies (at the bar)" "$(mk 115 120 120 120)" "true|5|240|true"
|
|
682
|
+
check "6 failures across 240 draws does NOT certify" "$(mk 114 120 120 120)" "false|6|240|true"
|
|
683
|
+
|
|
684
|
+
# The case the gate exists for: ONE dimension secretly at 0.90 while the other holds. grade()'s
|
|
685
|
+
# own per-dimension band (>=18/20, scaled to >=108/120) would call this dimension PASS on its own;
|
|
686
|
+
# pooled catches it, because 12 failures from one dimension alone crosses the budget of 5.
|
|
687
|
+
check "task 01's S3 quietly at 90% (would grade PASS alone) is caught by the pooled budget" "$(j "
|
|
688
|
+
const tasks = { '01': [], '02': [] };
|
|
689
|
+
for (let r = 0; r < 120; r++) tasks['01'].push({ index: r, dimensions: { S3: r < 108 } });
|
|
690
|
+
for (let r = 0; r < 120; r++) tasks['02'].push({ index: r, dimensions: { S5: true } });
|
|
691
|
+
const c = M.certify(M.buildResult({ source: {ref:'x',sha:'d'}, tasks, runs: 120 }));
|
|
692
|
+
process.stdout.write([c.certified, c.failures, c.softest[0].task, c.softest[0].rate.toFixed(2)].join('|'));")" \
|
|
693
|
+
"false|12|01|0.90"
|
|
694
|
+
|
|
695
|
+
# A short run must not read as certified. 0 failures out of 20 draws is not a sharp corpus; it is
|
|
696
|
+
# a corpus that has barely been sampled.
|
|
697
|
+
mk1() { j "
|
|
698
|
+
const tasks = { '01': [] };
|
|
699
|
+
for (let r = 0; r < $2; r++) tasks['01'].push({ index: r, dimensions: { S3: r < $1 } });
|
|
700
|
+
const c = M.certify(M.buildResult({ source: { ref: 'x', sha: 'deadbeef' }, tasks, runs: $2 }));
|
|
701
|
+
process.stdout.write([c.certified, c.failures, c.draws, c.sufficientDraws].join('|'));
|
|
702
|
+
"; }
|
|
703
|
+
check "a 20-draw run cannot certify, however clean" "$(mk1 20 20)" "false|0|20|false"
|
|
704
|
+
|
|
705
|
+
# --- 2.4b acceptance point 2: both directions, at the derived draw count ------------------------
|
|
706
|
+
check "a fully-conforming corpus at 240 draws (99.6% pass) certifies" "$(mk 119 120 120 120)" "true|1|240|true"
|
|
707
|
+
check "a soft corpus at 240 draws (95% pass) does NOT certify" "$(mk 114 120 114 120)" "false|12|240|true"
|
|
708
|
+
|
|
709
|
+
# --- 2.4b acceptance point 1: a report-only dimension never reaches `dimensions` -----------------
|
|
710
|
+
check "a report-only dimension appears in reportOnly, absent from dimensions" "$(j "
|
|
711
|
+
const r = M.buildResult({ source: {ref:'x',sha:'d'}, tasks: { '01': [{ index: 0, dimensions: { S3: true, S1: true } }] }, runs: 1 });
|
|
712
|
+
const d = r.tasks['01'];
|
|
713
|
+
process.stdout.write(('S1' in d.dimensions) + '|' + ('S1' in d.reportOnly) + '|' + ('S3' in d.dimensions));
|
|
714
|
+
")" "false|true|true"
|
|
715
|
+
|
|
716
|
+
# --- 2.4b acceptance point 4: the drift-guard checks buildResult()'s REAL output, not the table
|
|
717
|
+
# a second time -- a table-to-constant comparison alone cannot see a document-vs-code gap.
|
|
718
|
+
check "SCOPES.full.draws equals (gating dims buildResult() actually emits for a synthetic full run) x CERTIFY_N" "$(j "
|
|
719
|
+
const tasks = { '01': [{ index: 0, dimensions: { S3: true } }], '02': [{ index: 0, dimensions: { S5: true } }] };
|
|
720
|
+
const r = M.buildResult({ source: { ref: 'x', sha: 'd' }, tasks, runs: 1 });
|
|
721
|
+
let n = 0; for (const t of Object.values(r.tasks)) n += Object.keys(t.dimensions).length;
|
|
722
|
+
process.stdout.write(String(M.SCOPES.full.draws === n * M.CERTIFY_N) + '|' + n + '|' + M.CERTIFY_N + '|' + M.SCOPES.full.draws);
|
|
723
|
+
")" "true|2|120|240"
|
|
724
|
+
|
|
725
|
+
# --- 2.4b acceptance points 7 and 8: the per-dimension floor, both shapes a missing
|
|
726
|
+
# observation takes, through the SAME mechanism. In both, pooled draws/failures look clean --
|
|
727
|
+
# only the per-dimension floor (`d.n >= CERTIFY_N` for EVERY gating dim) can catch this.
|
|
728
|
+
check "S5 present as {n:0, excluded:N} (100% exclusion) fails the floor though pooled draws/failures look clean" "$(j "
|
|
729
|
+
const tasks = { '01': [], '02': [] };
|
|
730
|
+
for (let r = 0; r < 240; r++) tasks['01'].push({ index: r, dimensions: { S3: true } });
|
|
731
|
+
for (let r = 0; r < 240; r++) tasks['02'].push({ index: r, dimensions: { S5: 'excluded' } });
|
|
732
|
+
const c = M.certify(M.buildResult({ source: {ref:'x',sha:'d'}, tasks, runs: 240 }));
|
|
733
|
+
process.stdout.write([c.certified, c.draws, c.failures, c.underFloor.length, c.underFloor[0]?.task + '/' + c.underFloor[0]?.dim].join('|'));
|
|
734
|
+
")" "false|240|0|1|02/S5"
|
|
735
|
+
check "S5 absent from dimensions entirely (every task-02 draw returned no observation) fails the SAME floor, not a second mechanism" "$(j "
|
|
736
|
+
const tasks = { '01': [], '02': [] };
|
|
737
|
+
for (let r = 0; r < 240; r++) tasks['01'].push({ index: r, dimensions: { S3: true } });
|
|
738
|
+
for (let r = 0; r < 240; r++) tasks['02'].push({ index: r, dimensions: {} });
|
|
739
|
+
const r2 = M.buildResult({ source: {ref:'x',sha:'d'}, tasks, runs: 240 });
|
|
740
|
+
const c = M.certify(r2);
|
|
741
|
+
process.stdout.write([c.certified, c.draws, c.failures, ('S5' in r2.tasks['02'].dimensions), c.underFloor.length, c.underFloor[0]?.task + '/' + c.underFloor[0]?.dim].join('|'));
|
|
742
|
+
")" "false|240|0|false|1|02/S5"
|
|
743
|
+
|
|
744
|
+
# --- sharding, resume and merge: what makes a 260-draw certification batchable ------------------
|
|
745
|
+
# Certification is hours of wall clock. Each run is persisted the moment it finishes so a crash at
|
|
746
|
+
# run 19 does not discard eighteen paid-for runs, and a later invocation skips what is already on
|
|
747
|
+
# disk. Tested by writing shards directly -- no model, no network.
|
|
748
|
+
SHARD_SHA="testsha$(date +%s)"
|
|
749
|
+
# Each task's shard uses its own real GATING dim (task 01's S3, task 02's S5) --
|
|
750
|
+
# certify() reads exclusively from `dimensions`, so a shard tagged with any other dim would never
|
|
751
|
+
# reach it.
|
|
752
|
+
# Built through M.shardRecord() -- the SAME function main()'s drawing loop is meant to write
|
|
753
|
+
# through -- not a hand-built literal checked against a hand-built expectation.
|
|
754
|
+
mk_shard() { j "
|
|
755
|
+
const fs = await import('node:fs');
|
|
756
|
+
const dim = '$1' === '01' ? 'S3' : 'S5';
|
|
757
|
+
const p = M.shardPath('$SHARD_SHA', '$1', $2);
|
|
758
|
+
fs.mkdirSync(p.replace(/\/[^/]+\$/, ''), { recursive: true });
|
|
759
|
+
fs.writeFileSync(p, JSON.stringify(M.shardRecord('$SHARD_SHA', '$1', { index: $2, dimensions: { [dim]: $3 }, criteria: null, error: null })));
|
|
760
|
+
process.stdout.write('ok');
|
|
761
|
+
"; }
|
|
762
|
+
mk_shard 01 0 true >/dev/null; mk_shard 01 1 true >/dev/null
|
|
763
|
+
mk_shard 01 2 false >/dev/null; mk_shard 02 0 true >/dev/null
|
|
764
|
+
|
|
765
|
+
check "shardRecord() produces the shape both the production writer and this fixture share (F-133)" \
|
|
766
|
+
"$(j "process.stdout.write(JSON.stringify(M.shardRecord('s','01',{index:0})))")" \
|
|
767
|
+
'{"sha":"s","taskId":"01","schema":2,"run":{"index":0}}'
|
|
768
|
+
# the check above pins shardRecord()'s OWN shape, not that the live-agent-gated production
|
|
769
|
+
# write reaches it -- no test does. Pinned structurally: grepping the FULL `writeFileSync(shard,
|
|
770
|
+
# ...)` prefix, not just `shardRecord(...)` alone, which used to also match the docstring's prose.
|
|
771
|
+
check "main()'s drawing loop writes the shard through shardRecord(), not a parallel literal (F-136)" \
|
|
772
|
+
"$(grep -c 'writeFileSync(shard, JSON.stringify(shardRecord(source\.sha, id, r)' "$ROOT/$R")" "1"
|
|
773
|
+
|
|
774
|
+
check "completedIndices sees the shards already on disk" \
|
|
775
|
+
"$(j "process.stdout.write([...M.completedIndices('$SHARD_SHA','01',5)].join(','))")" "0,1,2"
|
|
776
|
+
check "an unwritten index is not reported complete" \
|
|
777
|
+
"$(j "process.stdout.write(String(M.completedIndices('$SHARD_SHA','01',5).has(4)))")" "false"
|
|
778
|
+
|
|
779
|
+
merged=$( j "
|
|
780
|
+
const r = M.mergeShards('$SHARD_SHA', { runs: 3 });
|
|
781
|
+
const d = r.tasks['01'].dimensions.S3;
|
|
782
|
+
process.stdout.write([Object.keys(r.tasks).sort().join('+'), r.tasks['01'].runs.length, d.passes + '/' + d.n, r.source.sha].join('|'));
|
|
783
|
+
")
|
|
784
|
+
check "mergeShards folds every shard, per task, in index order" "$merged" "01+02|3|2/3|$SHARD_SHA"
|
|
785
|
+
|
|
786
|
+
# Shards are keyed by SHA. Pooling draws scored against DIFFERENT definition sets would answer a
|
|
787
|
+
# question nobody asked -- and `--source HEAD` is how that happens, because HEAD moves between
|
|
788
|
+
# batches.
|
|
789
|
+
check "a different sha has no shards" \
|
|
790
|
+
"$(j "try { M.mergeShards('${SHARD_SHA}-other'); process.stdout.write('MERGED'); } catch { process.stdout.write('threw'); }")" \
|
|
791
|
+
"threw"
|
|
792
|
+
|
|
793
|
+
# Certification reads the merged view, so a partial run reports honestly rather than certifying.
|
|
794
|
+
part=$( j "
|
|
795
|
+
const c = M.certify(M.mergeShards('$SHARD_SHA', { runs: 3 }));
|
|
796
|
+
process.stdout.write([c.certified, c.failures, c.draws, c.sufficientDraws].join('|'));
|
|
797
|
+
")
|
|
798
|
+
check "a partial corpus cannot certify on few failures alone" "$part" "false|1|4|false"
|
|
799
|
+
|
|
800
|
+
rm -rf "$ROOT/tests/evals/results/$SHARD_SHA"
|
|
801
|
+
check "shard directory is removable and merge then fails loudly" \
|
|
802
|
+
"$(j "try { M.mergeShards('$SHARD_SHA'); process.stdout.write('MERGED'); } catch { process.stdout.write('threw'); }")" \
|
|
803
|
+
"threw"
|
|
804
|
+
|
|
805
|
+
# --- mergeShards() skips a shard from a prior schema, with a clear message ----------------
|
|
806
|
+
# SCHEMA_VERSION was bumped 1 -> 2 but nothing read it back -- this is the pass that gives
|
|
807
|
+
# it a job. A trimmed copy of a real shard from before the schema field existed (committed as a
|
|
808
|
+
# fixture so this runs on a fresh checkout) is copied into a throwaway SHA, never mutated in place.
|
|
809
|
+
legacysha="legacytest$(date +%s)"
|
|
810
|
+
legacydir="$ROOT/tests/evals/results/$legacysha"
|
|
811
|
+
mkdir -p "$legacydir"
|
|
812
|
+
cp "$ROOT/tests/scripts/fixtures/legacy-shard-no-schema.json" "$legacydir/01-000.json"
|
|
813
|
+
legacyerrfile=$(mktemp)
|
|
814
|
+
legacyout=$(node --input-type=module -e "
|
|
815
|
+
const M = await import('$ROOT/$R');
|
|
816
|
+
process.stdout.write(String(M.certify(M.mergeShards('$legacysha')).draws));
|
|
817
|
+
" 2>"$legacyerrfile")
|
|
818
|
+
legacyerr=$(cat "$legacyerrfile"); rm -f "$legacyerrfile"
|
|
819
|
+
check "mergeShards() skips a real, schema-less legacy shard rather than merging it" "$legacyout" "0"
|
|
820
|
+
case "$legacyerr" in
|
|
821
|
+
*"schema"*"01-000.json"*) ok "mergeShards() names the skipped shard and the reason in a clear message" ;;
|
|
822
|
+
*) bad "mergeShards() names the skipped shard and the reason in a clear message (got: ${legacyerr:0:200})" ;;
|
|
823
|
+
esac
|
|
824
|
+
# The guard is per-shard, not "give up on the whole directory": a CURRENT-schema shard alongside
|
|
825
|
+
# the skipped legacy one must still merge normally. stdout only (stderr carries the warning above
|
|
826
|
+
# and `j()` merges the two, which would corrupt this numeric comparison).
|
|
827
|
+
j "
|
|
828
|
+
const fs = await import('node:fs');
|
|
829
|
+
fs.writeFileSync(M.shardPath('$legacysha','01',1), JSON.stringify({ sha: '$legacysha', taskId: '01', schema: M.SCHEMA_VERSION, run: { index: 1, dimensions: { S3: true }, criteria: null, error: null } }));
|
|
830
|
+
" >/dev/null
|
|
831
|
+
check "a current-schema shard alongside a skipped legacy one still merges" \
|
|
832
|
+
"$(node --input-type=module -e "const M = await import('$ROOT/$R'); process.stdout.write(String(M.certify(M.mergeShards('$legacysha')).draws));" 2>/dev/null)" "1"
|
|
833
|
+
# the pass-1 Nit's fix was two halves -- stderr (pinned above via $legacyerr) and stdout,
|
|
834
|
+
# the half that actually survives `--certify sha > cert.txt`. stdout only (2>/dev/null): a caller
|
|
835
|
+
# reading just the redirected file must still see the pointer.
|
|
836
|
+
legacycertout=$(node "$R" --certify "$legacysha" 2>/dev/null)
|
|
837
|
+
case "$legacycertout" in
|
|
838
|
+
*"(skipped 1 shard(s) from a prior schema -- see stderr, or re-run --rescore to upgrade them)"*)
|
|
839
|
+
ok "certify()'s skipped-shard pointer survives a stdout-only redirect (F-143)" ;;
|
|
840
|
+
*) bad "certify()'s skipped-shard pointer survives a stdout-only redirect (got: ${legacycertout: -300})" ;;
|
|
841
|
+
esac
|
|
842
|
+
rm -rf "$legacydir"
|
|
843
|
+
|
|
844
|
+
# --- 2.4c (fixed pass 2): the resume-read in main()'s drawing loop applies the SAME schema check
|
|
845
|
+
# as mergeShards(), via the shared readShard(). A stale-schema shard used to be resumed
|
|
846
|
+
# from silently, carrying judge-authored dimensions from before this version's semantics -- measured
|
|
847
|
+
# on a copy of the same real legacy shard above, read back {"S2":true,...,"S3":true} with S3
|
|
848
|
+
# judge-authored from before boundaryRespected was wired. Fixed: excluded and warned about, NOT
|
|
849
|
+
# redrawn automatically (the settled answer -- a redraw is ~10 minutes of a live agent
|
|
850
|
+
# run, the maintainer's call, not this loop's). Both indices below are already shard-backed, so the
|
|
851
|
+
# drawing loop never falls through to a live agent or judge call; the `claude` stub only satisfies
|
|
852
|
+
# preflight()'s `command -v` check.
|
|
853
|
+
resumebin=$(mktemp -d) || { bad "mktemp failed"; exit 1; }
|
|
854
|
+
cat > "$resumebin/claude" <<'STUB'
|
|
855
|
+
#!/usr/bin/env bash
|
|
856
|
+
echo 'unused -- every requested index is already shard-backed'
|
|
857
|
+
STUB
|
|
858
|
+
chmod +x "$resumebin/claude"
|
|
859
|
+
resumedir="$ROOT/tests/evals/results/unversioned"
|
|
860
|
+
# NOT a scratch namespace like every other shard test's $(date +%s) sha -- shardPath(null,
|
|
861
|
+
# ...) always resolves here, and a real, quota-paid draw can genuinely live at this path. Move it
|
|
862
|
+
# aside and restore it; an unconditional rm -rf would silently unpay a real run and report green.
|
|
863
|
+
resumedir_backup=""
|
|
864
|
+
if [ -d "$resumedir" ]; then
|
|
865
|
+
resumedir_backup="$(mktemp -d)/unversioned"
|
|
866
|
+
# unchecked, a failed mv (e.g. TMPDIR full) leaves the real directory in place while the
|
|
867
|
+
# rest of this block proceeds to write fixtures into it and rm -rf it below -- fail loud instead.
|
|
868
|
+
mv "$resumedir" "$resumedir_backup" || { bad "F-135: could not move aside real results/unversioned -- refusing to proceed"; exit 1; }
|
|
869
|
+
echo " (moved aside real results/unversioned to $resumedir_backup for restore)"
|
|
870
|
+
fi
|
|
871
|
+
mkdir -p "$resumedir"
|
|
872
|
+
j "
|
|
873
|
+
const fs = await import('node:fs');
|
|
874
|
+
fs.writeFileSync(M.shardPath(null,'01',0), JSON.stringify(M.shardRecord(null,'01',{ index: 0, dimensions: { S3: true }, criteria: null, error: null })));
|
|
875
|
+
" >/dev/null
|
|
876
|
+
cp "$ROOT/tests/scripts/fixtures/legacy-shard-no-schema.json" "$resumedir/01-001.json"
|
|
877
|
+
resumeout=$(ANTHROPIC_API_KEY=test-stub-key PATH="$resumebin:$PATH" node "$R" --source . --tasks 01 --runs 2 --out "$(mktemp)" 2>&1)
|
|
878
|
+
case "$resumeout" in
|
|
879
|
+
*"skipped"*"01-001.json"*) ok "the resume-read skips a stale-schema shard rather than resuming from it (F-131)" ;;
|
|
880
|
+
*) bad "the resume-read skips a stale-schema shard rather than resuming from it (got: ${resumeout:0:400})" ;;
|
|
881
|
+
esac
|
|
882
|
+
case "$resumeout" in
|
|
883
|
+
*"01 run 1/2: (already done)"*) ok "a current-schema shard alongside the skipped one still resumes normally" ;;
|
|
884
|
+
*) bad "a current-schema shard alongside the skipped one still resumes normally (got: ${resumeout:0:400})" ;;
|
|
885
|
+
esac
|
|
886
|
+
rm -rf "$resumebin" "$resumedir"
|
|
887
|
+
[ -n "$resumedir_backup" ] && mv "$resumedir_backup" "$resumedir"
|
|
888
|
+
|
|
889
|
+
# --- executed criterion: task 03 criterion 3, scored by running it rather than judging it -------
|
|
890
|
+
rep() { j "
|
|
891
|
+
const R = await import('$ROOT/tests/evals/lib/reproduce.mjs');
|
|
892
|
+
const refs = await (await import('$ROOT/$R')).task03Reference('$ROOT');
|
|
893
|
+
process.stdout.write(String(R.reproduces(\`$1\`, refs)));
|
|
894
|
+
"; }
|
|
895
|
+
check "a cited 31-day date reproduces the defect" "$(rep 'the bug hits on 2026-07-16')" "true"
|
|
896
|
+
check "a cited 30-day date does NOT reproduce" "$(rep 'consider 2026-04-16 here')" "false"
|
|
897
|
+
check "a named 31-day month reproduces" "$(rep 'on July 16 it under-credits')" "true"
|
|
898
|
+
check "a named 30-day month does not" "$(rep 'on June 16 it under-credits')" "false"
|
|
899
|
+
# Fails SAFE. A parser returning `false` on an unrecognised phrasing would fail a correct review
|
|
900
|
+
# for citing its case in a form nobody anticipated -- the "criterion that fails a conforming run"
|
|
901
|
+
# this corpus keeps rediscovering. null means "fall back to the judge".
|
|
902
|
+
check "a hedge with no date returns null (judge fallback)" "$(rep 'the proration logic may be wrong')" "null"
|
|
903
|
+
|
|
904
|
+
# Reverted after the first agreement check disagreed on 1 of 6 verdicts. `null` means "whatever
|
|
905
|
+
# the CLI defaults to" -- the larger model -- not "unset by accident".
|
|
906
|
+
check "the judge does NOT default to a cheaper model" \
|
|
907
|
+
"$(j "process.stdout.write(String((await import('$ROOT/tests/evals/lib/score.mjs')).DEFAULT_JUDGE_MODEL))")" "null"
|
|
908
|
+
|
|
909
|
+
# --- judge-agreement.mjs and --judge-model: the judge machinery is removed -------------
|
|
910
|
+
check "judge-agreement.mjs no longer exists" \
|
|
911
|
+
"$(j "process.stdout.write(String((await import('node:fs')).existsSync('$ROOT/tests/evals/judge-agreement.mjs')))")" "false"
|
|
912
|
+
case "$(node "$R" --judge-model sonnet --dry-run --source HEAD --tasks 01 --runs 1 2>&1; echo "EXIT:$?")" in
|
|
913
|
+
*"unknown argument: --judge-model"*"EXIT:1") ok "--judge-model is not a recognized flag (removed outright)" ;;
|
|
914
|
+
*) bad "--judge-model is not a recognized flag (removed outright)" ;;
|
|
915
|
+
esac
|
|
916
|
+
|
|
917
|
+
# --- parseVerdict() rejects a judge reply with duplicate n --------------------------------
|
|
918
|
+
# `criteria` is keyed by n, not positional -- a duplicate n is not a shape any
|
|
919
|
+
# downstream consumer (toDimensions, the splice-based overlays) can safely reduce over. Mutated
|
|
920
|
+
# from a genuinely well-formed reply, not hand-built already-broken, so a reversion of the check
|
|
921
|
+
# below is provably what turns this red.
|
|
922
|
+
pv() { j "
|
|
923
|
+
const S = await import('$ROOT/tests/evals/lib/score.mjs');
|
|
924
|
+
const v = S.parseVerdict($1);
|
|
925
|
+
process.stdout.write(v.ok ? 'ok' : v.error);
|
|
926
|
+
"; }
|
|
927
|
+
check "a well-formed reply with distinct n parses ok" \
|
|
928
|
+
"$(pv "'{\"criteria\":[{\"n\":1,\"verdict\":\"pass\"},{\"n\":2,\"verdict\":\"fail\"}]}'")" "ok"
|
|
929
|
+
check "a duplicate n is rejected, not silently accepted" \
|
|
930
|
+
"$(pv "'{\"criteria\":[{\"n\":1,\"verdict\":\"pass\"},{\"n\":1,\"verdict\":\"fail\"}]}'")" \
|
|
931
|
+
"duplicate criterion n=1 in judge reply"
|
|
932
|
+
|
|
933
|
+
bnd() { j "
|
|
934
|
+
const B = await import('$ROOT/tests/evals/lib/boundary.mjs');
|
|
935
|
+
const r = B.boundaryRespected($1);
|
|
936
|
+
process.stdout.write(r.ok + (r.offenders.length ? ':' + r.offenders.join(',') : ''));
|
|
937
|
+
"; }
|
|
938
|
+
check "a conforming /plan run respects the boundary" \
|
|
939
|
+
"$(bnd "[{path:'.somi/README.md'},{path:'.somi/audit.log'},{path:'.somi/somi-state/x'},{path:'.somi/plans/y/spec.md'}]")" "true"
|
|
940
|
+
check "a touched source file is caught, and named" \
|
|
941
|
+
"$(bnd "[{path:'src/ingest/handler.mjs'}]")" "false:src/ingest/handler.mjs"
|
|
942
|
+
check "a stray root file is caught" \
|
|
943
|
+
"$(bnd "[{path:'NOTES.md'}]")" "false:NOTES.md"
|
|
944
|
+
|
|
945
|
+
# --- boundaryRespected's `slug` parameter, wired through (was accepted and never used) -----
|
|
946
|
+
bnd_slug() { j "
|
|
947
|
+
const B = await import('$ROOT/tests/evals/lib/boundary.mjs');
|
|
948
|
+
const r = B.boundaryRespected($1, { slug: $2 });
|
|
949
|
+
process.stdout.write(r.ok + (r.offenders.length ? ':' + r.offenders.join(',') : ''));
|
|
950
|
+
"; }
|
|
951
|
+
# boundaryRespected is called only from the taskId === '01' block (run.mjs), so its slug is always
|
|
952
|
+
# TASK-01-SHAPED -- `ingest-audit-trail` is a real slug from a stored task-01 shard
|
|
953
|
+
# (results/4ff4da62.../01-000.json), used here rather than task02-code's fixture slug (Nit, review
|
|
954
|
+
# pass 1: the prior comment named a call that does not exist). A write into a DIFFERENT slug's plan
|
|
955
|
+
# directory must be rejected -- unreachable before this fix, since the old unscoped allowlist
|
|
956
|
+
# matched any .somi/plans/ path.
|
|
957
|
+
check "boundaryRespected REJECTS a write into a different slug's plan directory" \
|
|
958
|
+
"$(bnd_slug "[{path:'.somi/plans/other-slug/spec.md'}]" "'ingest-audit-trail'")" \
|
|
959
|
+
"false:.somi/plans/other-slug/spec.md"
|
|
960
|
+
# Bidirectional: the same slug-scoped allowlist must still accept the running draw's OWN directory.
|
|
961
|
+
check "boundaryRespected ACCEPTS a write into the running draw's own slug directory" \
|
|
962
|
+
"$(bnd_slug "[{path:'.somi/plans/ingest-audit-trail/progress.md'}]" "'ingest-audit-trail'")" "true"
|
|
963
|
+
# The sole fallback path: slug discovery came back null (no plan directory was ever created for
|
|
964
|
+
# this draw) -- boundaryRespected must fall back to the broad prefix and ACCEPT, never reject.
|
|
965
|
+
# A false `fail` on 1 of 3 gating dimensions is worse than the over-permissiveness this replaces.
|
|
966
|
+
check "boundaryRespected: null slug falls back to the broad prefix and ACCEPTS, does not reject" \
|
|
967
|
+
"$(bnd_slug "[{path:'.somi/plans/other-slug/spec.md'}]" "null")" "true"
|
|
968
|
+
|
|
969
|
+
# --- a slug with regex metacharacters behaves as a plain prefix, not a pattern -------------
|
|
970
|
+
# Verified that the OLD `new RegExp` version threw on `fix(auth`, false-failed the
|
|
971
|
+
# draw's own write on `plan[1]`, and over-matched `a.b` against `aXb`. These pin all three
|
|
972
|
+
# directions as a measurement, not a claim.
|
|
973
|
+
check "a slug with regex metacharacters does not throw and accepts the draw's own write" \
|
|
974
|
+
"$(bnd_slug "[{path:'.somi/plans/fix(auth/spec.md'}]" "'fix(auth'")" "true"
|
|
975
|
+
check "a slug with a character-class metacharacter does not false-fail the draw's own write" \
|
|
976
|
+
"$(bnd_slug "[{path:'.somi/plans/plan[1]/spec.md'}]" "'plan[1]'")" "true"
|
|
977
|
+
check "a slug with a '.' does not over-match a different, similarly-named slug's directory" \
|
|
978
|
+
"$(bnd_slug "[{path:'.somi/plans/aXb/spec.md'}]" "'a.b'")" \
|
|
979
|
+
"false:.somi/plans/aXb/spec.md"
|
|
980
|
+
|
|
981
|
+
# --- task 01 scored from the ARTIFACT, not the prose -------------------------------------------
|
|
982
|
+
# Certification failed with a clean pattern: executed criteria 4/4, near-mechanical 4/4, semantic
|
|
983
|
+
# judged ones 3/4, 3/4, 2/4. A model judge cannot deliver the >=99% consistency the error budget
|
|
984
|
+
# assumes. The criteria were semantic because prose was all there was to score -- the mandated
|
|
985
|
+
# DECISIONS-NEEDED structure is destroyed by the command's relay in --print mode (measured: 0 of 4
|
|
986
|
+
# runs emitted the fenced block). decisions.md survives on disk, and parsing it is deterministic.
|
|
987
|
+
SAMPLE="$ROOT/tests/evals/fixtures/_candidates/decisions-sample.md"
|
|
988
|
+
t01() { j "
|
|
989
|
+
const fs = await import('node:fs');
|
|
990
|
+
const S = await import('$ROOT/tests/evals/lib/score-task01.mjs');
|
|
991
|
+
let md = fs.readFileSync('$SAMPLE','utf8');
|
|
992
|
+
$1
|
|
993
|
+
const v = S.executedVerdicts(md);
|
|
994
|
+
process.stdout.write(Object.keys(v).filter(k=>/^\d+$/.test(k)).sort().map(k=>k+'='+v[k]).join(' '));
|
|
995
|
+
"; }
|
|
996
|
+
# THE case that invalidated artifact scoring for this task. Task 01 scores the RESEARCH pass,
|
|
997
|
+
# which halts before anything is verified, so decisions.md is scaffolded from the template and
|
|
998
|
+
# correctly left empty. Reading placeholders as content returned FALSE and manufactured failures
|
|
999
|
+
# on runs that did nothing wrong -- observed live: the run with a scaffold scored S2- S1-, the run
|
|
1000
|
+
# with no artifact deferred to the judge and scored S1+.
|
|
1001
|
+
check "an unfilled template defers every criterion instead of failing them" \
|
|
1002
|
+
"$(t01 "md = '# Decisions — <work item name>\n\n## D1 — <decision title in noun form>\n\n### Decision\n\n<one sentence>\n';")" \
|
|
1003
|
+
'1=null 2=null 3=null 4=null 5=null'
|
|
1004
|
+
check "a conforming artifact satisfies the structural criteria" \
|
|
1005
|
+
"$(t01 '')" '1=null 2=null 3=true 4=null 5=null'
|
|
1006
|
+
check "an absent artifact defers every criterion to the judge" \
|
|
1007
|
+
"$(t01 "md = '';")" '1=null 2=null 3=null 4=null 5=null'
|
|
1008
|
+
check "an invented volume figure fails criterion 3" \
|
|
1009
|
+
"$(t01 "md += '\nExpect ~400M rows/yr.';")" '1=null 2=null 3=false 4=null 5=null'
|
|
1010
|
+
check "a Reverses field saying only cheaply fails criterion 5" \
|
|
1011
|
+
"$(t01 "md = md.replace(/\\*\\*Reverses\\*\\*:[^\\n]*/, '**Reverses**: cheaply');")" \
|
|
1012
|
+
'1=null 2=null 3=true 4=null 5=null'
|
|
1013
|
+
check "an unnamed ADR fails criterion 4" \
|
|
1014
|
+
"$(t01 "md = md.replace(/ADR 0004[^\\n]*/, 'The architecture decision applies.');")" \
|
|
1015
|
+
'1=null 2=null 3=true 4=false 5=null'
|
|
1016
|
+
|
|
1017
|
+
# --- task 01 scored from the FENCED BLOCK, the third target tried ------------------------------
|
|
1018
|
+
# 1. the prose relay -- semantic, so judged, so 2/4-3/4 against a >=99% bar
|
|
1019
|
+
# 2. decisions.md -- structured but EMPTY in the research pass; parsing it manufactured failures
|
|
1020
|
+
# 3. the fence -- the planner's own block, relayed verbatim, present in every run
|
|
1021
|
+
blk() { j "
|
|
1022
|
+
const S = await import('$ROOT/tests/evals/lib/score-task01.mjs');
|
|
1023
|
+
const body = 'D1: Audit-trail storage architecture\\n Decides: where 7 years of rows live\\n Option A — Partitioned Postgres — RECOMMENDED\\n Pros: no new store\\n Cons: partition maintenance for a two-person team\\n Reverses: detach partitions; the down migration ships in the same PR\\n';
|
|
1024
|
+
let out = 'prose\\n\\n\\u0060\\u0060\\u0060decisions-needed\\n' + body + '\\u0060\\u0060\\u0060\\n ADR 0004 requires a migration path.';
|
|
1025
|
+
$1
|
|
1026
|
+
const v = S.blockVerdicts(out);
|
|
1027
|
+
process.stdout.write(Object.keys(v).filter(k=>/^\d+$/.test(k)).sort().map(k=>k+'='+v[k]).join(' '));
|
|
1028
|
+
"; }
|
|
1029
|
+
check "a conforming fence scores the structural criteria" \
|
|
1030
|
+
"$(blk '')" '1=null 2=null 3=true 4=null 5=null'
|
|
1031
|
+
# A run predating the relay change, or one that omits the fence, must DEFER -- not be failed for a
|
|
1032
|
+
# format it was never given. Same fail-safe the scaffold case needed.
|
|
1033
|
+
check "no fence defers every criterion to the judge" \
|
|
1034
|
+
"$(blk "out = 'just prose';")" '1=null 2=null 3=null 4=null 5=null'
|
|
1035
|
+
check "a missing Reverses field fails criterion 5" \
|
|
1036
|
+
"$(blk "out = out.replace(/ Reverses:[^\\n]*\\n/, '');")" \
|
|
1037
|
+
'1=null 2=null 3=true 4=null 5=null'
|
|
1038
|
+
check "an invented magnitude fails criterion 3" \
|
|
1039
|
+
"$(blk "out += ' Expect ~400M rows/yr.';")" '1=null 2=null 3=false 4=null 5=null'
|
|
1040
|
+
check "an unnamed ADR fails criterion 4" \
|
|
1041
|
+
"$(blk "out = out.replace(/ADR 0004[^\\n]*/, 'the architecture decision');")" \
|
|
1042
|
+
'1=null 2=null 3=true 4=false 5=null'
|
|
1043
|
+
|
|
1044
|
+
# --- a run already over budget must say so, not keep drawing -----------------------------------
|
|
1045
|
+
# Failures only accumulate, so once the count exceeds the budget no sequence of remaining draws
|
|
1046
|
+
# can recover it. Without this, task 01 sat at 4 failures against a budget of 2 with 80 draws
|
|
1047
|
+
# left -- about seven quota windows -- to confirm an outcome the arithmetic had already fixed.
|
|
1048
|
+
over() { j "
|
|
1049
|
+
const tasks = { '01': [] };
|
|
1050
|
+
for (let i = 0; i < $1; i++) tasks['01'].push({ index: i, dimensions: { S3: i >= $2 } });
|
|
1051
|
+
const c = M.certify(M.buildResult({ source: {ref:'x',sha:'d'}, tasks, runs: $1 }));
|
|
1052
|
+
process.stdout.write([c.cannotCertify, c.failures, c.maxFailures].join('|'));
|
|
1053
|
+
"; }
|
|
1054
|
+
check "6 failures against a budget of 5 is unrecoverable" "$(over 10 6)" "true|6|5"
|
|
1055
|
+
check "5 failures against a budget of 5 is still open" "$(over 10 5)" "false|5|5"
|
|
1056
|
+
check "0 failures is still open" "$(over 10 0)" "false|0|5"
|
|
1057
|
+
|
|
1058
|
+
# --- the agent timeout must clear the observed spread ------------------------------------------
|
|
1059
|
+
# A timeout is the most expensive possible outcome: the run is fully paid for and nothing is
|
|
1060
|
+
# recorded. 900s cost a draw when observed runs already reached 13 minutes.
|
|
1061
|
+
check "the agent timeout leaves headroom over the observed 13-minute maximum" \
|
|
1062
|
+
"$(j "
|
|
1063
|
+
const fs = await import('node:fs');
|
|
1064
|
+
const src = fs.readFileSync('$ROOT/tests/evals/lib/install.mjs','utf8');
|
|
1065
|
+
const m = src.match(/timeoutMs = ([0-9_]+)/);
|
|
1066
|
+
process.stdout.write(String(Number(m[1].replace(/_/g,'')) >= 1500000));
|
|
1067
|
+
")" "true"
|
|
1068
|
+
|
|
1069
|
+
# --- SCOPES.task01 is REMOVED, not relabeled; SCOPES.full re-derived from CERTIFY_N -------
|
|
1070
|
+
# At 1 gating dimension (S3 alone) the best available budget clears a
|
|
1071
|
+
# genuinely-soft corpus 73.58% of the time -- worse than not gating -- so `task01` is gone
|
|
1072
|
+
# entirely, and there is exactly one scope left.
|
|
1073
|
+
check "SCOPES.task01 no longer exists (removed, not merely relabeled)" \
|
|
1074
|
+
"$(j "process.stdout.write(String('task01' in M.SCOPES))")" "false"
|
|
1075
|
+
check "CERTIFY_N is a distinct constant from BANDS.n (raising it must not touch routine trim draws)" \
|
|
1076
|
+
"$(j "process.stdout.write(M.CERTIFY_N + '|' + M.BANDS.n)")" "120|20"
|
|
1077
|
+
# The derived budget, pinned -- not a preference. Re-derived (not scaled) at 2 gating dimensions
|
|
1078
|
+
# (after task 02's S1 was demoted to report-only): the same method lands on CERTIFY_N=120,
|
|
1079
|
+
# more per dimension than the prior 3-dimension figure (80), since the pooled false-accept target
|
|
1080
|
+
# is reached at the same total draw count (240) regardless of how many dimensions share it.
|
|
1081
|
+
check "SCOPES.full is derived from CERTIFY_N x 2 gating dimensions: 240 draws, budget 5, ~96.5%/~1.8% power" \
|
|
1082
|
+
"$(j "const s = M.SCOPES.full; process.stdout.write([s.draws, s.maxFailures, s.powerGood.toFixed(4), s.powerSoft.toFixed(4), s.covers].join('|'))")" \
|
|
1083
|
+
"240|5|0.9651|0.0181|2 of 13 task-dimensions"
|
|
1084
|
+
check "power is reported on certify()'s own return value" \
|
|
1085
|
+
"$(j "const c = M.certify({tasks:{}}); process.stdout.write(c.powerGood + '/' + c.powerSoft)")" "0.9651/0.0181"
|
|
1086
|
+
|
|
1087
|
+
# --- 2.4b acceptance point 6: --scope is fully removed, not silently falling back to full --------
|
|
1088
|
+
scopeout=$(node "$R" --scope task01 --dry-run --source HEAD --tasks 01 --runs 1 2>&1; echo "EXIT:$?")
|
|
1089
|
+
case "$scopeout" in
|
|
1090
|
+
*"unknown argument: --scope"*"EXIT:1") ok "--scope is not a recognized flag (removed outright)" ;;
|
|
1091
|
+
*) bad "--scope is not a recognized flag (removed outright) (got: ${scopeout:0:160})" ;;
|
|
1092
|
+
esac
|
|
1093
|
+
|
|
1094
|
+
# --- 2.4b acceptance point 5: the exact --runs guidance, appended to certify()'s own message ------
|
|
1095
|
+
CERT_SHA="certtest$(date +%s)"
|
|
1096
|
+
j "
|
|
1097
|
+
const fs = await import('node:fs');
|
|
1098
|
+
const p = M.shardPath('$CERT_SHA', '01', 0);
|
|
1099
|
+
fs.mkdirSync(p.replace(/\/[^/]+\$/, ''), { recursive: true });
|
|
1100
|
+
fs.writeFileSync(p, JSON.stringify({ sha: '$CERT_SHA', taskId: '01', schema: M.SCHEMA_VERSION, run: { index: 0, dimensions: { S3: false, S1: false }, criteria: null, error: null } }));
|
|
1101
|
+
" >/dev/null
|
|
1102
|
+
certout=$(node "$R" --certify "$CERT_SHA" 2>&1)
|
|
1103
|
+
case "$certout" in
|
|
1104
|
+
*"enough draws: false (need 240, have 1) — draw with --runs 120"*)
|
|
1105
|
+
ok "certify()'s 'enough draws: false' message names --runs \$CERTIFY_N exactly, derived from the same constant" ;;
|
|
1106
|
+
*)
|
|
1107
|
+
bad "certify()'s 'enough draws: false' message names --runs \$CERTIFY_N exactly (got: ${certout:0:300})" ;;
|
|
1108
|
+
esac
|
|
1109
|
+
|
|
1110
|
+
# --- certified-line parenthetical, UNDER FLOOR block, harnessFaults -- each left 215/0 ----
|
|
1111
|
+
case "$certout" in
|
|
1112
|
+
*"certified: false (1 gating dimension(s) measured, false-accept 1.81% if all are soft, 27.00% if one alone)"*) ok "certify()'s 'certified:' line states the gating-dimension count and BOTH false-accept rates" ;;
|
|
1113
|
+
*) bad "certify()'s 'certified:' line states the gating-dimension count/both false-accept rates (got: ${certout:0:300})" ;;
|
|
1114
|
+
esac
|
|
1115
|
+
# The single-soft figure is the one a reader actually needs and the one that was missing: a bare
|
|
1116
|
+
# 1.81% describes every gating dimension going soft together, while one soft against a healthy
|
|
1117
|
+
# sibling certifies 27.00% of the time. Asserted separately so deleting it cannot pass as a
|
|
1118
|
+
# reformat of the line above.
|
|
1119
|
+
case "$certout" in
|
|
1120
|
+
*"27.00% if one alone"*) ok "certify() states the SINGLE-soft-dimension false-accept rate, not only the joint one" ;;
|
|
1121
|
+
*) bad "certify() states the single-soft-dimension false-accept rate (got: ${certout:0:400})" ;;
|
|
1122
|
+
esac
|
|
1123
|
+
# The gate's POWER should be printed on every run, not only its false-accept rate. The
|
|
1124
|
+
# figure is `SCOPES.full.powerGood`, the converse error to the 1.81% on the `certified:` line --
|
|
1125
|
+
# so this asserts both that it prints and that it is not a second copy of the false-accept rate.
|
|
1126
|
+
case "$certout" in
|
|
1127
|
+
*"gate power: 96.51%"*) ok "certify() prints the gate's power (§6), distinct from its false-accept rate" ;;
|
|
1128
|
+
*) bad "certify() prints the gate's power (§6) (got: ${certout:0:400})" ;;
|
|
1129
|
+
esac
|
|
1130
|
+
|
|
1131
|
+
case "$certout" in
|
|
1132
|
+
*"UNDER FLOOR: 01/S3 (1/120), 02/S5 (0/120)"*) ok "certify()'s UNDER FLOOR block names each under-floor gating dimension" ;;
|
|
1133
|
+
*) bad "certify()'s UNDER FLOOR block names each under-floor gating dimension (got: ${certout:0:400})" ;;
|
|
1134
|
+
esac
|
|
1135
|
+
case "$certout" in
|
|
1136
|
+
*"1 failure(s) across 1 draw(s)"*" 01 S3: 0/1"*"report-only 01 S1: 0/1"*) ok "certify()'s summary pools ONLY the gating row, and prints the report-only row after it" ;;
|
|
1137
|
+
*) bad "certify()'s summary pools ONLY the gating row, and prints the report-only row after it (got: ${certout:0:400})" ;;
|
|
1138
|
+
esac
|
|
1139
|
+
# {error:'timeout'} (the shape this check used to write) is not a shape a shard can ever
|
|
1140
|
+
# carry -- runOnce()'s timeout/quota/judge-fault path always sets harnessFault:true, which the
|
|
1141
|
+
# drawing loop's write guard never persists. The one error a shard CAN carry unflagged is :680's.
|
|
1142
|
+
j "const fs = await import('node:fs'); fs.writeFileSync(M.shardPath('$CERT_SHA','01',1), JSON.stringify({sha:'$CERT_SHA',taskId:'01',schema:M.SCHEMA_VERSION,run:{index:1,dimensions:{},criteria:null,error:'no prompt found in the task spec'}}));" >/dev/null
|
|
1143
|
+
case "$(node "$R" --certify "$CERT_SHA" 2>&1)" in
|
|
1144
|
+
*"harness faults: 1"*) ok "certify()'s harnessFaults count reflects a persistable error-bearing run, not a hardcoded 0" ;;
|
|
1145
|
+
*) bad "certify()'s harnessFaults count reflects a persistable error-bearing run" ;;
|
|
1146
|
+
esac
|
|
1147
|
+
rm -rf "$ROOT/tests/evals/results/$CERT_SHA"
|
|
1148
|
+
|
|
1149
|
+
# --- a malformed judge reply must not discard the agent run that preceded it -------------------
|
|
1150
|
+
# Observed once in three runs: the judge returned unparseable JSON and a ~12-minute agent run was
|
|
1151
|
+
# thrown away. At ~90% of a usage cap per batch that is not affordable. Only a PARSE failure is
|
|
1152
|
+
# retried -- a quota outage is not, since the next call fails identically and burns budget proving
|
|
1153
|
+
# it. Asserted on the REAL classifier, exported as `isRetryableJudgeError` -- a hand-copied regex
|
|
1154
|
+
# literal here could not fail (a regression guard for the shared classifier).
|
|
1155
|
+
mal() { node --input-type=module -e "
|
|
1156
|
+
const S = await import('$ROOT/tests/evals/lib/score.mjs');
|
|
1157
|
+
process.stdout.write(String(S.isRetryableJudgeError('$1')));
|
|
1158
|
+
" 2>&1; }
|
|
1159
|
+
check "an unparseable reply is retryable" "$(mal 'judge reply is not valid JSON: x')" "true"
|
|
1160
|
+
check "a missing criteria array is retryable" "$(mal 'judge reply has no criteria array')" "true"
|
|
1161
|
+
check "a quota outage is NOT retryable" "$(mal 'quota exhausted')" "false"
|
|
1162
|
+
check "a generic exit is NOT retryable" "$(mal 'judge exited 1')" "false"
|
|
1163
|
+
# asserted against the REAL `judge()`, spawning a stubbed `claude` end to end -- the only
|
|
1164
|
+
# check here that would catch a break in `judgeOnce()`'s own retry wiring, not just in the
|
|
1165
|
+
# classifier `mal()` now shares with it. Stub replies duplicate-n on the FIRST call,
|
|
1166
|
+
# well-formed on the SECOND; `judge()` must retry and return the second's verdict.
|
|
1167
|
+
dupbin=$(mktemp -d) || { bad "mktemp failed"; exit 1; }
|
|
1168
|
+
cat > "$dupbin/claude" <<STUB
|
|
1169
|
+
#!/usr/bin/env bash
|
|
1170
|
+
if [ -e "$dupbin/.hit" ]; then
|
|
1171
|
+
echo '{"criteria":[{"n":1,"verdict":"pass","evidence":"e"}]}'
|
|
1172
|
+
else
|
|
1173
|
+
touch "$dupbin/.hit"
|
|
1174
|
+
echo '{"criteria":[{"n":1,"verdict":"pass","evidence":"e"},{"n":1,"verdict":"pass","evidence":"e"}]}'
|
|
1175
|
+
fi
|
|
1176
|
+
STUB
|
|
1177
|
+
chmod +x "$dupbin/claude"
|
|
1178
|
+
dupout=$(PATH="$dupbin:$PATH" node --input-type=module -e "
|
|
1179
|
+
const S = await import('$ROOT/tests/evals/lib/score.mjs');
|
|
1180
|
+
const v = S.judge('spec text', 'evidence text');
|
|
1181
|
+
process.stdout.write(v.ok + '|' + (v.retried ?? false));
|
|
1182
|
+
" 2>&1)
|
|
1183
|
+
check "a duplicate-n reply is retried against the real judge(), not treated as an unrecoverable harness fault (F-130)" \
|
|
1184
|
+
"$dupout" "true|true"
|
|
1185
|
+
rm -rf "$dupbin"
|
|
1186
|
+
|
|
1187
|
+
# --- rescore reads the CURRENT scorer, not the pinned one --------------------------------------
|
|
1188
|
+
# Two sources, and conflating them makes rescore silently do nothing. The DEFINITION SET is pinned
|
|
1189
|
+
# by the sha (that is what was measured); the TASK SPEC is the SCORER, and the whole reason to
|
|
1190
|
+
# rescore is that the scorer changed. Passing the pinned worktree for both re-judges against the
|
|
1191
|
+
# criterion you just replaced and reports "unchanged" for every shard -- which is what the first
|
|
1192
|
+
# attempt did, convincingly and wrongly.
|
|
1193
|
+
check "rescoreShards defaults its spec source to the repo, not a pinned tree" \
|
|
1194
|
+
"$(j "process.stdout.write(String(M.rescoreShards.length))")" "1"
|
|
1195
|
+
|
|
1196
|
+
# --- applyExecutedOverlays() -- the shared function closing gap 3 --------------------------
|
|
1197
|
+
# runOnce() and rescoreShards() now call ONE function for every executed-criterion overlay. Pinned
|
|
1198
|
+
# here with data shaped like the real, already-on-disk shard the gap was found against
|
|
1199
|
+
# (results/4ff4da62.../01-000.json: decisionsMd null, a fenced decisions-needed block in the
|
|
1200
|
+
# transcript, no `changed` field -- that shard predates the schema addition).
|
|
1201
|
+
aeo() { j "
|
|
1202
|
+
const BT = String.fromCharCode(96).repeat(3), NL = String.fromCharCode(10);
|
|
1203
|
+
const crit = $1;
|
|
1204
|
+
const dims = {};
|
|
1205
|
+
await M.applyExecutedOverlays('$2', crit, dims, $3, $4);
|
|
1206
|
+
process.stdout.write(JSON.stringify(crit.map((c) => [c.n, c.verdict, c.executed ?? null])) + '|' + JSON.stringify(dims));
|
|
1207
|
+
"; }
|
|
1208
|
+
check "criterion 3 reproduces EXECUTED evidence from the transcript's fence alone (decisionsMd null, matching the real shard)" \
|
|
1209
|
+
"$(aeo "[{n:3,verdict:'fail',evidence:'judge'}]" 01 "{3:['S7']}" "{decisionsMd:null,transcript:[BT+'decisions-needed','D1: x',' Option A - y',' Pros: p',' Cons: q',BT,'no digits here'].join(NL)}")" \
|
|
1210
|
+
'[[3,"pass",true]]|{"S7":true}'
|
|
1211
|
+
# 'changed' absent used to leave the JUDGE's own verdict standing
|
|
1212
|
+
# for a GATING dimension -- the exact door a judge-authored gating verdict uses, reopened via a missing field instead of a
|
|
1213
|
+
# fresh judge call. Now spliced + excluded, the disposition S5 already uses for its own
|
|
1214
|
+
# non-attributable case. Reverting the `else` branch in applyExecutedOverlays() (the fix below)
|
|
1215
|
+
# turns this red: criterion 6 would stay in `criteria` as the judge's raw 'fail' and S3 would read
|
|
1216
|
+
# `false` instead of "excluded" -- a judge-authored gating verdict, exactly what the fix closes.
|
|
1217
|
+
check "criterion 6 is EXCLUDED, not judge-authored, when 'changed' is absent -- an older shard" \
|
|
1218
|
+
"$(aeo "[{n:6,verdict:'fail',evidence:'judge'}]" 01 "{6:['S3']}" "{transcript:''}")" \
|
|
1219
|
+
'[]|{"S3":"excluded"}'
|
|
1220
|
+
check "criterion 6 reproduces EXECUTED evidence when 'changed' is present, correctly REJECTING an out-of-allowlist path" \
|
|
1221
|
+
"$(aeo "[{n:6,verdict:'pass',evidence:'judge'}]" 01 "{6:['S3']}" "{transcript:'',tree:[{status:'M',path:'src/x.mjs'}],slug:'s'}")" \
|
|
1222
|
+
'[[6,"fail",true]]|{"S3":false}'
|
|
1223
|
+
check "criterion 6 reproduces EXECUTED evidence and PASSES for an in-allowlist path (Nit, pass 1 review: the accept direction was under-asserted)" \
|
|
1224
|
+
"$(aeo "[{n:6,verdict:'fail',evidence:'judge'}]" 01 "{6:['S3']}" "{transcript:'',tree:[{status:'A',path:'.somi/plans/s/context.md'}],slug:'s'}")" \
|
|
1225
|
+
'[[6,"pass",true]]|{"S3":true}'
|
|
1226
|
+
# Major (pass 2 review, "Also fix" item): a judge reply OMITTING criterion 6 entirely used to make
|
|
1227
|
+
# S3 vanish from `dimensions` rather than fail closed -- toDimensions() had nothing tagged S3 to
|
|
1228
|
+
# read. Now appended, exactly like criterion 3's sibling overlay already does.
|
|
1229
|
+
check "criterion 6 is APPENDED, not silently absent, when the judge's reply omits it and 'changed' is present" \
|
|
1230
|
+
"$(aeo "[]" 01 "{6:['S3']}" "{transcript:'',tree:[{status:'M',path:'src/x.mjs'}],slug:'s'}")" \
|
|
1231
|
+
'[[6,"fail",true]]|{"S3":false}'
|
|
1232
|
+
check "task 02's S5 is driven by the STORED expiryGuard, never recomputed -- excluded key always present, S1 reapplied alongside it (F-55/2.3)" \
|
|
1233
|
+
"$(aeo "[{n:1,verdict:'pass',evidence:'judge'},{n:3,verdict:'pass',evidence:'judge'}]" 02 "{1:['S5'],3:['S1']}" "{expiryGuard:{verdict:'non-attributable',step:'mutant',observed:'type-error'},testInvocation:'fail'}")" \
|
|
1234
|
+
'[[3,"fail",true]]|{"S1":false,"S5":"excluded"}'
|
|
1235
|
+
# the overlay's splice removes only the FIRST `n === 1` entry
|
|
1236
|
+
# (`findIndex` + `splice(i, 1)`), so a judge reply carrying criterion 1 TWICE leaves a second entry
|
|
1237
|
+
# standing with its own verdict. Outcome-sampling alone (`criteria.some(...)`) still finds that
|
|
1238
|
+
# survivor and stays silent -- S5 published the judge's own `true` on a gating dimension, the same
|
|
1239
|
+
# door. Reverting the `expiryGuard.verdict` half of the fix above turns this red.
|
|
1240
|
+
check "S5 is EXCLUDED, not judge-authored, when the judge reply carries criterion 1 TWICE and expiryGuard is non-attributable (F-86)" \
|
|
1241
|
+
"$(aeo "[{n:1,verdict:'pass',evidence:'judge'},{n:1,verdict:'pass',evidence:'judge'}]" 02 "{1:['S5']}" "{expiryGuard:{verdict:'non-attributable',step:'mutant',observed:'type-error'}}")" \
|
|
1242
|
+
'[[1,"pass",null]]|{"S5":"excluded"}'
|
|
1243
|
+
check "S5 is EXCLUDED, not judge-authored, when expiryGuard is absent entirely -- a shard predating the field (F-76)" \
|
|
1244
|
+
"$(aeo "[{n:1,verdict:'pass',evidence:'judge'}]" 02 "{1:['S5']}" "{expiryGuard:null}")" \
|
|
1245
|
+
'[[1,"pass",null]]|{"S5":"excluded"}'
|
|
1246
|
+
# Major (pass 2 review, "Also fix" item): a judge reply OMITTING criterion 1 while `expiryGuard`
|
|
1247
|
+
# genuinely PASSED used to make S5 vanish from `dimensions` entirely (the overlay can only record
|
|
1248
|
+
# `overlaySkipped` when the criterion isn't there to mutate -- it cannot fabricate a pass/fail
|
|
1249
|
+
# criterion the judge never sent). Now excluded, matching the non-attributable disposition, rather
|
|
1250
|
+
# than invisible to certify()'s per-dimension floor.
|
|
1251
|
+
check "S5 is EXCLUDED, not silently absent, when the judge's reply omits criterion 1 -- even on a genuine pass" \
|
|
1252
|
+
"$(aeo "[{n:3,verdict:'pass',evidence:'judge'}]" 02 "{1:['S5'],3:['S1']}" "{expiryGuard:{verdict:'pass',step:'mutant',observed:'assertion'},testInvocation:null}")" \
|
|
1253
|
+
'[[3,"pass",null]]|{"S1":true,"S5":"excluded"}'
|
|
1254
|
+
check "task 03 criterion 3 reproduces EXECUTED evidence from the stored transcript alone" \
|
|
1255
|
+
"$(aeo "[{n:3,verdict:'fail',evidence:'judge'}]" 03 "{3:['S1']}" "{transcript:'Filed against 2024-03-31.',task03Refs:{correct:(a,b,d)=>({net:1}),patched:(a,b,d)=>({net:2})}}")" \
|
|
1256
|
+
'[[3,"pass",true]]|{"S1":true}'
|
|
1257
|
+
|
|
1258
|
+
# --- rescoreShards() actually reapplies the overlays, end to end ----------------------------
|
|
1259
|
+
# judge() shells out to a real `claude` binary; stubbed here with a script returning a FIXED, WRONG
|
|
1260
|
+
# verdict for every criterion, so only a correctly-reapplied overlay can flip the result -- the
|
|
1261
|
+
# "mutate one call site, confirm red" proof for the call site runOnce() cannot pin (no test in this
|
|
1262
|
+
# hermetic suite reaches runOnce()'s own execution). Reverting rescoreShards to its pre-2.3 body
|
|
1263
|
+
# (plain toDimensions(verdict.criteria, tags), no overlay call) was verified by hand to turn this
|
|
1264
|
+
# red: false|false|false|true|false|false|false instead of the line below (7 fields since two more were added).
|
|
1265
|
+
rsbin=$(mktemp -d) || { bad "mktemp failed"; exit 1; }
|
|
1266
|
+
cat > "$rsbin/claude" <<'STUB'
|
|
1267
|
+
#!/usr/bin/env bash
|
|
1268
|
+
echo '{"criteria":[{"n":1,"verdict":"fail","evidence":"judge"},{"n":3,"verdict":"fail","evidence":"judge"},{"n":6,"verdict":"fail","evidence":"judge"}]}'
|
|
1269
|
+
STUB
|
|
1270
|
+
chmod +x "$rsbin/claude"
|
|
1271
|
+
rssha="rescoretest0000000000000000000000000000"
|
|
1272
|
+
rsdir="$ROOT/tests/evals/results/$rssha"
|
|
1273
|
+
mkdir -p "$rsdir"
|
|
1274
|
+
cat > "$rsdir/01-000.json" <<'EOF'
|
|
1275
|
+
{"sha":"x","taskId":"01","run":{"index":0,"dimensions":{},"criteria":[],"error":null,"decisionsMd":null,"changed":[{"status":"A","path":".somi/plans/x/context.md"}],"slug":"x","transcript":"```decisions-needed\nD1: x\n Option A - y\n Pros: p\n Cons: q\n```\nno digits here"}}
|
|
1276
|
+
EOF
|
|
1277
|
+
cat > "$rsdir/02-000.json" <<'EOF'
|
|
1278
|
+
{"sha":"x","taskId":"02","run":{"index":0,"dimensions":{},"criteria":[],"error":null,"decisionsMd":null,"transcript":"t","expiryGuard":{"verdict":"non-attributable","step":"mutant","observed":"type-error"},"testInvocation":"fail"}}
|
|
1279
|
+
EOF
|
|
1280
|
+
# The destructive-write proof: a shard shaped EXACTLY like the real, on-disk
|
|
1281
|
+
# results/4ff4da62.../01-003.json -- criterion 6 already EXECUTED, S3 already true, no `changed`/
|
|
1282
|
+
# `slug` field (the historical gap). The in-memory-only version of this proof is not enough
|
|
1283
|
+
#: the defect was a `writeFileSync` that overwrote real evidence on disk with no undo, so
|
|
1284
|
+
# this reads the FILE back after rescoring, not just rescoreShards()'s return value.
|
|
1285
|
+
cat > "$rsdir/01-001.json" <<'EOF'
|
|
1286
|
+
{"sha":"x","taskId":"01","run":{"index":1,"dimensions":{"S3":true},"criteria":[{"n":3,"verdict":"pass","evidence":"EXECUTED against decisions.md: satisfied (not judged)","executed":true},{"n":6,"verdict":"pass","evidence":"EXECUTED: every changed path is inside the allowlist (slug-scoped: x) (not judged)","executed":true}],"error":null,"decisionsMd":null,"transcript":"no digits here"}}
|
|
1287
|
+
EOF
|
|
1288
|
+
rsout=$(PATH="$rsbin:$PATH" node --input-type=module -e "
|
|
1289
|
+
const M = await import('$ROOT/$R');
|
|
1290
|
+
await M.rescoreShards('$rssha', '$ROOT');
|
|
1291
|
+
const fs = await import('node:fs');
|
|
1292
|
+
const r1 = JSON.parse(fs.readFileSync('$rsdir/01-000.json', 'utf8'));
|
|
1293
|
+
const r2 = JSON.parse(fs.readFileSync('$rsdir/02-000.json', 'utf8'));
|
|
1294
|
+
const r3 = JSON.parse(fs.readFileSync('$rsdir/01-001.json', 'utf8'));
|
|
1295
|
+
const c3 = r1.run.criteria.find((c) => c.n === 3), c6 = r1.run.criteria.find((c) => c.n === 6);
|
|
1296
|
+
const c3b = r2.run.criteria.find((c) => c.n === 3);
|
|
1297
|
+
const c6legacy = r3.run.criteria.find((c) => c.n === 6);
|
|
1298
|
+
process.stdout.write([c3.evidence.startsWith('EXECUTED'), c6.evidence.startsWith('EXECUTED'),
|
|
1299
|
+
r2.run.dimensions.S5, 'S5' in r2.run.dimensions, c3b.evidence.startsWith('EXECUTED'),
|
|
1300
|
+
c6legacy === undefined, r3.run.dimensions.S3].join('|'));
|
|
1301
|
+
" 2>&1)
|
|
1302
|
+
check "rescoreShards reapplies task 01's criteria 3+6 and task 02's S5/S1 overlays; a legacy shard's stale EXECUTED criterion 6 is excluded on disk, never overwritten with judge prose (F-71)" \
|
|
1303
|
+
"$rsout" "true|true|excluded|true|true|true|excluded"
|
|
1304
|
+
rm -rf "$rsbin" "$rsdir"
|
|
1305
|
+
|
|
1306
|
+
# --- 2.4c acceptance: "no judged criterion can gate", re-checked at mergeShards()'s output for
|
|
1307
|
+
# the --rescore PATH specifically (previously pinned only at the individual-shard/applyExecutedOverlays
|
|
1308
|
+
# level, never end to end through mergeShards()+certify()) -------------------------------------
|
|
1309
|
+
rs2bin=$(mktemp -d) || { bad "mktemp failed"; exit 1; }
|
|
1310
|
+
cat > "$rs2bin/claude" <<'STUB'
|
|
1311
|
+
#!/usr/bin/env bash
|
|
1312
|
+
echo '{"criteria":[{"n":1,"verdict":"pass","evidence":"e"},{"n":2,"verdict":"pass","evidence":"e"},{"n":3,"verdict":"pass","evidence":"e"},{"n":4,"verdict":"pass","evidence":"e"}]}'
|
|
1313
|
+
STUB
|
|
1314
|
+
chmod +x "$rs2bin/claude"
|
|
1315
|
+
rs2sha="rescoretest2$(date +%s)"
|
|
1316
|
+
rs2dir="$ROOT/tests/evals/results/$rs2sha"
|
|
1317
|
+
mkdir -p "$rs2dir"
|
|
1318
|
+
# The stub judge says criterion 1 (S5, GATING) PASSES. The stored expiryGuard -- the mechanical
|
|
1319
|
+
# fact -- says it FAILED. If the overlay were bypassed on this path, S5 would read pass/1 below.
|
|
1320
|
+
j "
|
|
1321
|
+
const fs = await import('node:fs');
|
|
1322
|
+
fs.writeFileSync(M.shardPath('$rs2sha','02',0), JSON.stringify({ sha: '$rs2sha', taskId: '02', schema: M.SCHEMA_VERSION, run: { index: 0, dimensions: {}, criteria: [], error: null, transcript: 't', expiryGuard: { verdict: 'fail', step: 'mutant', reason: 'r', observed: 'assertion' }, testInvocation: 'pass' } }));
|
|
1323
|
+
" >/dev/null
|
|
1324
|
+
PATH="$rs2bin:$PATH" node --input-type=module -e "const M = await import('$ROOT/$R'); await M.rescoreShards('$rs2sha', '$ROOT');" >/dev/null 2>&1
|
|
1325
|
+
rs2merge=$(j "
|
|
1326
|
+
const c = M.certify(M.mergeShards('$rs2sha'));
|
|
1327
|
+
const s5 = c.dimensions.find((d) => d.task === '02' && d.dim === 'S5');
|
|
1328
|
+
process.stdout.write(s5 ? s5.passes + '/' + s5.n : 'MISSING');
|
|
1329
|
+
")
|
|
1330
|
+
check "mergeShards()+certify() after --rescore reflects the MECHANICAL expiryGuard verdict (fail) on gating dimension S5, never the stub judge's own 'pass'" \
|
|
1331
|
+
"$rs2merge" "0/1"
|
|
1332
|
+
rm -rf "$rs2bin" "$rs2dir"
|
|
1333
|
+
|
|
1334
|
+
# --- 2.4c acceptance: --report is a separate, opt-in pass; its shard cannot change certify() -----
|
|
1335
|
+
rptbin=$(mktemp -d) || { bad "mktemp failed"; exit 1; }
|
|
1336
|
+
cat > "$rptbin/claude" <<'STUB'
|
|
1337
|
+
#!/usr/bin/env bash
|
|
1338
|
+
echo '{"criteria":[{"n":1,"verdict":"pass","evidence":"e"},{"n":2,"verdict":"pass","evidence":"e"},{"n":3,"verdict":"pass","evidence":"e"},{"n":4,"verdict":"pass","evidence":"e"}]}'
|
|
1339
|
+
STUB
|
|
1340
|
+
chmod +x "$rptbin/claude"
|
|
1341
|
+
rptsha="reporttest$(date +%s)"
|
|
1342
|
+
rptdir="$ROOT/tests/evals/results/$rptsha"
|
|
1343
|
+
mkdir -p "$rptdir"
|
|
1344
|
+
# The STORED gating dimensions are all false; the mechanical facts (expiryGuard/testInvocation)
|
|
1345
|
+
# and the stub judge would, if freshly recomputed, produce all true -- deliberately mismatched
|
|
1346
|
+
# from what is on disk, so a report-pass leak into the gating namespace is NOT masked by the two
|
|
1347
|
+
# computations coincidentally agreeing (mutation-verified: writing report output into the gating
|
|
1348
|
+
# namespace directly turns this check red, where a same-valued fixture would not have).
|
|
1349
|
+
j "
|
|
1350
|
+
const fs = await import('node:fs');
|
|
1351
|
+
fs.writeFileSync(M.shardPath('$rptsha','02',0), JSON.stringify({ sha: '$rptsha', taskId: '02', schema: M.SCHEMA_VERSION, run: { index: 0, dimensions: { S5: false, S3: false, S1: false, S6: false }, criteria: [], error: null, transcript: 't', expiryGuard: { verdict: 'pass', step: 'mutant', observed: 'assertion' }, testInvocation: 'pass' } }));
|
|
1352
|
+
" >/dev/null
|
|
1353
|
+
before=$(j "process.stdout.write(JSON.stringify(M.certify(M.mergeShards('$rptsha'))))")
|
|
1354
|
+
rptout=$(PATH="$rptbin:$PATH" node "$R" --report "$rptsha" 2>&1)
|
|
1355
|
+
after=$(j "process.stdout.write(JSON.stringify(M.certify(M.mergeShards('$rptsha'))))")
|
|
1356
|
+
check "a --report shard present under a SHA does not change that SHA's certify() output" "$after" "$before"
|
|
1357
|
+
case "$rptout" in
|
|
1358
|
+
*"report-only:"*"report-only 02 S3: 1/1"*) ok "--report prints a report-only: summary line" ;;
|
|
1359
|
+
*) bad "--report prints a report-only: summary line (got: ${rptout:0:300})" ;;
|
|
1360
|
+
esac
|
|
1361
|
+
check "a --report shard lands under results/<sha>/report/, structurally separate from the gating namespace mergeShards()/completedIndices() glob" \
|
|
1362
|
+
"$(j "process.stdout.write(String((await import('node:fs')).existsSync('$rptdir/report/02-000.json')))")" "true"
|
|
1363
|
+
# the written report record is filtered to the report-only half before it
|
|
1364
|
+
# touches disk -- applyExecutedOverlays() writes every TAGGED dimension, gating included, so an
|
|
1365
|
+
# unfiltered write would carry a GATING dimension's value (S5, here genuinely true) under this
|
|
1366
|
+
# pass's `schema: 2` stamp, the same stamp a real gating shard carries but a different, incompatible
|
|
1367
|
+
# record shape.
|
|
1368
|
+
check "the written report shard excludes the gating dimension (S5), keeping only report-only ones under the gating schema stamp" \
|
|
1369
|
+
"$(j "process.stdout.write(String('S5' in JSON.parse((await import('node:fs')).readFileSync('$rptdir/report/02-000.json','utf8')).run.dimensions))")" \
|
|
1370
|
+
"false"
|
|
1371
|
+
# `schema: 2` alone still means two incompatible shapes -- readShard() would accept a
|
|
1372
|
+
# report record as current if anything ever pointed it at `report/`. `kind: 'report'` fixes that.
|
|
1373
|
+
check "the written report shard is discriminated from a gating shard by kind: 'report'" \
|
|
1374
|
+
"$(j "process.stdout.write(String(JSON.parse((await import('node:fs')).readFileSync('$rptdir/report/02-000.json','utf8')).kind))")" \
|
|
1375
|
+
"report"
|
|
1376
|
+
|
|
1377
|
+
# --- --report honors --runs as a real cap on which shards it judges, not a
|
|
1378
|
+
# value that reaches the result shape while every shard on disk gets judged regardless (the settled answer for the report pass's own N). Two more gating shards are added
|
|
1379
|
+
# for indices 1 and 2; `--runs 1` must judge only index 0 (already report-shard-backed above) and
|
|
1380
|
+
# leave 1/2 untouched -- no report/02-001.json, no report/02-002.json.
|
|
1381
|
+
j "
|
|
1382
|
+
const fs = await import('node:fs');
|
|
1383
|
+
fs.writeFileSync(M.shardPath('$rptsha','02',1), JSON.stringify({ sha: '$rptsha', taskId: '02', schema: M.SCHEMA_VERSION, run: { index: 1, dimensions: {}, criteria: [], error: null, transcript: 't1' } }));
|
|
1384
|
+
fs.writeFileSync(M.shardPath('$rptsha','02',2), JSON.stringify({ sha: '$rptsha', taskId: '02', schema: M.SCHEMA_VERSION, run: { index: 2, dimensions: {}, criteria: [], error: null, transcript: 't2' } }));
|
|
1385
|
+
" >/dev/null
|
|
1386
|
+
PATH="$rptbin:$PATH" node "$R" --report "$rptsha" --runs 1 >/dev/null 2>&1
|
|
1387
|
+
check "--report honors --runs as a cap on which shards it judges (F-132)" \
|
|
1388
|
+
"$(ls "$rptdir/report" | wc -l | tr -d ' ')" "1"
|
|
1389
|
+
rm -rf "$rptbin" "$rptdir"
|
|
1390
|
+
|
|
1391
|
+
# --- --report threads task03Refs exactly like --rescore does, so both print
|
|
1392
|
+
# the SAME EXECUTED verdict for task 03's one report-only dimension (S1) rather than opposite ones
|
|
1393
|
+
#. The stub judge says criterion 3 PASSES; the cited date is a 30-day month, so the
|
|
1394
|
+
# EXECUTED overlay must override it to FAIL on both paths -- a stub-agreeing fixture would not
|
|
1395
|
+
# discriminate a leaked docstring claim from a real fix.
|
|
1396
|
+
t3bin=$(mktemp -d) || { bad "mktemp failed"; exit 1; }
|
|
1397
|
+
cat > "$t3bin/claude" <<'STUB'
|
|
1398
|
+
#!/usr/bin/env bash
|
|
1399
|
+
echo '{"criteria":[{"n":1,"verdict":"pass","evidence":"e"},{"n":2,"verdict":"pass","evidence":"e"},{"n":3,"verdict":"pass","evidence":"e"},{"n":4,"verdict":"pass","evidence":"e"},{"n":5,"verdict":"pass","evidence":"e"}]}'
|
|
1400
|
+
STUB
|
|
1401
|
+
chmod +x "$t3bin/claude"
|
|
1402
|
+
t3sha_a="task03refsA$(date +%s)"; t3sha_b="task03refsB$(date +%s)"
|
|
1403
|
+
for sha in "$t3sha_a" "$t3sha_b"; do
|
|
1404
|
+
mkdir -p "$ROOT/tests/evals/results/$sha"
|
|
1405
|
+
j "
|
|
1406
|
+
const fs = await import('node:fs');
|
|
1407
|
+
fs.writeFileSync(M.shardPath('$sha','03',0), JSON.stringify({ sha: '$sha', taskId: '03', schema: M.SCHEMA_VERSION, run: { index: 0, dimensions: {}, criteria: [], error: null, transcript: 'Filed against 2026-04-16.' } }));
|
|
1408
|
+
" >/dev/null
|
|
1409
|
+
done
|
|
1410
|
+
PATH="$t3bin:$PATH" node --input-type=module -e "const M = await import('$ROOT/$R'); await M.rescoreShards('$t3sha_a', '$ROOT');" >/dev/null 2>&1
|
|
1411
|
+
PATH="$t3bin:$PATH" node "$R" --report "$t3sha_b" >/dev/null 2>&1
|
|
1412
|
+
rescoreS1=$(j "process.stdout.write(String(JSON.parse((await import('node:fs')).readFileSync('$ROOT/tests/evals/results/$t3sha_a/03-000.json','utf8')).run.dimensions.S1))")
|
|
1413
|
+
reportS1=$(j "process.stdout.write(String(JSON.parse((await import('node:fs')).readFileSync('$ROOT/tests/evals/results/$t3sha_b/report/03-000.json','utf8')).run.dimensions.S1))")
|
|
1414
|
+
check "--report's task-03 S1 matches --rescore's EXECUTED verdict on the same shard content (F-129)" "$reportS1" "$rescoreS1"
|
|
1415
|
+
check "and both are the mechanical 'fail' the citation produces, not the stub judge's raw 'pass'" "$reportS1" "false"
|
|
1416
|
+
rm -rf "$t3bin" "$ROOT/tests/evals/results/$t3sha_a" "$ROOT/tests/evals/results/$t3sha_b"
|
|
1417
|
+
|
|
1418
|
+
# --- Nit: reportShards() on an unknown SHA throws a clear error, matching
|
|
1419
|
+
# mergeShards()'s existsSync guard, not the raw "Command failed: ls" a bare execFileSync produces.
|
|
1420
|
+
check "reportShards() on an unknown SHA throws loudly, not with a raw 'ls' failure" \
|
|
1421
|
+
"$(j "try { await M.reportShards('${SHARD_SHA}-nope'); process.stdout.write('REPORTED'); } catch (e) { process.stdout.write(e.message); }")" \
|
|
1422
|
+
"no shards for ${SHARD_SHA}-nope at $ROOT/tests/evals/results/${SHARD_SHA}-nope"
|
|
1423
|
+
|
|
1424
|
+
# --- quota outages are named, not lumped into a generic exit code ------------------------------
|
|
1425
|
+
# Both the agent path and the judge path must recognise an exhausted limit. Without it a rescore
|
|
1426
|
+
# burned four consecutive judge calls against a dead quota and reported four indistinguishable
|
|
1427
|
+
# `judge exited 1` errors -- the caller could not tell "wait and retry" from "malformed reply".
|
|
1428
|
+
check "a quota message in judge output is classified as quota" \
|
|
1429
|
+
"$(j "
|
|
1430
|
+
const S = await import('$ROOT/tests/evals/lib/score.mjs');
|
|
1431
|
+
// parseVerdict is the non-error path; the quota branch lives in judge()'s spawn handling, so
|
|
1432
|
+
// assert the DETECTOR shape the branch uses rather than spawning a real CLI.
|
|
1433
|
+
const out = 'You\\'ve hit your session limit · resets 7:30pm';
|
|
1434
|
+
process.stdout.write(String(/session limit|rate limit|usage limit|quota/i.test(out)));
|
|
1435
|
+
")" "true"
|
|
1436
|
+
check "an ordinary judge failure is NOT classified as quota" \
|
|
1437
|
+
"$(j "process.stdout.write(String(/session limit|rate limit|usage limit|quota/i.test('SyntaxError: unexpected token')))")" "false"
|
|
1438
|
+
|
|
1439
|
+
# --- certification cannot pass on a partial run ------------------------------------------------
|
|
1440
|
+
# It printed `certified: true` on 25 draws by reading 3 raw failures against a budget defined for
|
|
1441
|
+
# 260 -- a rate projecting to ~31 failures, six times over. The vacuous-pass class again, this
|
|
1442
|
+
# time in the check that decides whether every other check passed.
|
|
1443
|
+
partial=$( j "
|
|
1444
|
+
const tasks = { '01': [] };
|
|
1445
|
+
for (let i = 0; i < 5; i++) tasks['01'].push({ index: i, dimensions: { S3: i < 2 } });
|
|
1446
|
+
const c = M.certify(M.buildResult({ source: {ref:'x',sha:'d'}, tasks, runs: 5 }));
|
|
1447
|
+
process.stdout.write([c.certified, c.onTrack, c.projectedFailures, c.sufficientDraws].join('|'));
|
|
1448
|
+
")
|
|
1449
|
+
check "a partial run cannot certify, and reports its projection" "$partial" "false|false|144|false"
|
|
1450
|
+
|
|
1451
|
+
# --- npm test must not invoke this runner ------------------------------------------------------
|
|
1452
|
+
# Structural: a `node --check` glob merely NAMING the directory is
|
|
1453
|
+
# explicitly permitted; what is forbidden is executing it.
|
|
1454
|
+
# Scoped to what `npm test` reaches. package.json's eval:behavioral script references the runner
|
|
1455
|
+
# ON PURPOSE -- that is the escape hatch. The full invariant (packaging + hermeticity) is owned by
|
|
1456
|
+
# tests/scripts/evals-packaging.sh; this is the narrow version, kept here so this file's own guard
|
|
1457
|
+
# fails if someone wires the runner into validate.sh.
|
|
1458
|
+
if grep -nE '(node|bash)[^|]*tests/evals/run\.mjs' scripts/validate.sh >/dev/null 2>&1; then
|
|
1459
|
+
bad "validate.sh does not execute the eval runner"
|
|
1460
|
+
else
|
|
1461
|
+
ok "validate.sh does not execute the eval runner"
|
|
1462
|
+
fi
|
|
1463
|
+
|
|
1464
|
+
# --- classification.mjs: the diff mechanism itself, unconditional -----------------------
|
|
1465
|
+
# These need no file on disk -- they prove `diffClassification` can actually detect a changed
|
|
1466
|
+
# verdict and a missing row, and that it reports no difference for two copies of the same table.
|
|
1467
|
+
# That is necessary for the decisions.md comparison below to mean anything, but it is NOT the
|
|
1468
|
+
# drift check itself: these three run against synthetic tables built from CLASSIFICATION alone and
|
|
1469
|
+
# would stay green even if CLASSIFICATION had drifted from the maintained classification table completely.
|
|
1470
|
+
check "classification.mjs: 15 criteria, no duplicate (task, criterion) pairs" \
|
|
1471
|
+
"$(j "
|
|
1472
|
+
const C = await import('$ROOT/tests/evals/lib/classification.mjs');
|
|
1473
|
+
const keys = C.CLASSIFICATION.map((r) => r.task + ':' + r.criterion);
|
|
1474
|
+
process.stdout.write(String(C.CLASSIFICATION.length) + '|' + String(new Set(keys).size));
|
|
1475
|
+
")" "15|15"
|
|
1476
|
+
check "classification.mjs: 2 of 13 task-dimensions gate (task 01's S3, task 02's S5; task 03 zero)" \
|
|
1477
|
+
"$(j "
|
|
1478
|
+
const C = await import('$ROOT/tests/evals/lib/classification.mjs');
|
|
1479
|
+
const dims = C.taskDimensions();
|
|
1480
|
+
const gating = dims.filter((d) => d.verdict === 'gating').map((d) => d.task + '/' + d.dim).sort();
|
|
1481
|
+
process.stdout.write(dims.length + '|' + gating.join(','));
|
|
1482
|
+
")" "13|01/S3,02/S5"
|
|
1483
|
+
check "diffClassification: identical tables match" \
|
|
1484
|
+
"$(j "
|
|
1485
|
+
const C = await import('$ROOT/tests/evals/lib/classification.mjs');
|
|
1486
|
+
process.stdout.write(String(C.diffClassification(C.CLASSIFICATION, C.CLASSIFICATION)));
|
|
1487
|
+
")" "null"
|
|
1488
|
+
check "diffClassification: a changed verdict is caught (mutation self-check)" \
|
|
1489
|
+
"$(j "
|
|
1490
|
+
const C = await import('$ROOT/tests/evals/lib/classification.mjs');
|
|
1491
|
+
const mutated = C.CLASSIFICATION.map((r) => (r.task === '02' && r.criterion === 3) ? { ...r, verdict: 'gating' } : r);
|
|
1492
|
+
process.stdout.write(String(C.diffClassification(mutated, C.CLASSIFICATION)));
|
|
1493
|
+
")" "mismatch:02:3:got=S1/gating:want=S1/report-only"
|
|
1494
|
+
check "diffClassification: a missing row is caught" \
|
|
1495
|
+
"$(j "
|
|
1496
|
+
const C = await import('$ROOT/tests/evals/lib/classification.mjs');
|
|
1497
|
+
const truncated = C.CLASSIFICATION.filter((r) => !(r.task === '01' && r.criterion === 6));
|
|
1498
|
+
process.stdout.write(String(C.diffClassification(truncated, C.CLASSIFICATION)));
|
|
1499
|
+
")" "missing:01:6"
|
|
1500
|
+
|
|
1501
|
+
# --- decisionsMdClassification's multi-table, append-order mechanism, unconditional (including the verdict-cell throw) ---------------------------
|
|
1502
|
+
# The classification's corrections to date have every one of them been APPENDED as a new dated section, never
|
|
1503
|
+
# an edit to prior text in place. These three cases pin that the parser actually behaves that way on
|
|
1504
|
+
# a synthetic (no file involved) classification-shaped span, not merely against today's decisions.md content.
|
|
1505
|
+
check "decisionsMdClassification: a later table's copy of a shared row wins over an earlier table's (was reversed)" \
|
|
1506
|
+
"$(j "
|
|
1507
|
+
const C = await import('$ROOT/tests/evals/lib/classification.mjs');
|
|
1508
|
+
const text = [
|
|
1509
|
+
'## D11 -- synthetic',
|
|
1510
|
+
'',
|
|
1511
|
+
'| task | crit | dim | mechanism | bidirectional? | sound? | verdict |',
|
|
1512
|
+
'|---|---|---|---|---|---|---|',
|
|
1513
|
+
'| 01 | 6 | S3 | x | yes | yes | GATING |',
|
|
1514
|
+
'| 03 | 1 | S4 | x | no | -- | report-only |',
|
|
1515
|
+
'',
|
|
1516
|
+
'prose sitting between the two tables',
|
|
1517
|
+
'',
|
|
1518
|
+
'| task | criterion | dimension | executor | verdict |',
|
|
1519
|
+
'|---|---|---|---|---|',
|
|
1520
|
+
'| 01 | 6 | S3 | x | report-only |',
|
|
1521
|
+
'',
|
|
1522
|
+
'## Superseded entries',
|
|
1523
|
+
].join('\n');
|
|
1524
|
+
const derived = C.decisionsMdClassification(text);
|
|
1525
|
+
process.stdout.write(derived.find((r) => r.task === '01' && r.criterion === 6).verdict);
|
|
1526
|
+
")" "report-only"
|
|
1527
|
+
check "decisionsMdClassification: a table appended after the settled resolution overrides it, not invisible (F-84)" \
|
|
1528
|
+
"$(j "
|
|
1529
|
+
const C = await import('$ROOT/tests/evals/lib/classification.mjs');
|
|
1530
|
+
const settled = [
|
|
1531
|
+
'## D11 -- synthetic',
|
|
1532
|
+
'',
|
|
1533
|
+
'| task | crit | dim | mechanism | bidirectional? | sound? | verdict |',
|
|
1534
|
+
'|---|---|---|---|---|---|---|',
|
|
1535
|
+
'| 01 | 6 | S3 | x | yes | yes | GATING |',
|
|
1536
|
+
'',
|
|
1537
|
+
'prose',
|
|
1538
|
+
'',
|
|
1539
|
+
'| task | criterion | dimension | executor | verdict |',
|
|
1540
|
+
'|---|---|---|---|---|',
|
|
1541
|
+
'| 01 | 6 | S3 | x | GATING |',
|
|
1542
|
+
'',
|
|
1543
|
+
].join('\n');
|
|
1544
|
+
const withLaterCorrection = settled + [
|
|
1545
|
+
'a still later, appended correction',
|
|
1546
|
+
'',
|
|
1547
|
+
'| task | criterion | dimension | executor | verdict |',
|
|
1548
|
+
'|---|---|---|---|---|',
|
|
1549
|
+
'| 01 | 6 | S3 | x | report-only |',
|
|
1550
|
+
'',
|
|
1551
|
+
'## Superseded entries',
|
|
1552
|
+
].join('\n');
|
|
1553
|
+
const derived = C.decisionsMdClassification(withLaterCorrection);
|
|
1554
|
+
process.stdout.write(derived.find((r) => r.task === '01' && r.criterion === 6).verdict);
|
|
1555
|
+
")" "report-only"
|
|
1556
|
+
check "decisionsMdClassification: an off-convention verdict spelling throws, not silently dropped (F-88)" \
|
|
1557
|
+
"$(j "
|
|
1558
|
+
const C = await import('$ROOT/tests/evals/lib/classification.mjs');
|
|
1559
|
+
const text = ['## D11 -- synthetic', '', '| 01 | 6 | S3 | x | GATING |', '', 'p', '',
|
|
1560
|
+
'| 01 | 6 | S3 | x | GATING |', '| 03 | 1 | S4 | x | \`report-only\` |', '', '## End'].join('\n');
|
|
1561
|
+
try { C.decisionsMdClassification(text); process.stdout.write('NO THROW'); }
|
|
1562
|
+
catch (e) { process.stdout.write(/unrecognized verdict cell/.test(e.message) ? 'threw' : 'wrong:' + e.message); }
|
|
1563
|
+
")" "threw"
|
|
1564
|
+
|
|
1565
|
+
# --- classification.mjs vs the live task specs: criterionTags(), tracked everywhere -----------------------------------------------------------------------------------------
|
|
1566
|
+
# tests/evals/tasks/*.md are TRACKED (unlike decisions.md), so this runs in CI and in a fresh
|
|
1567
|
+
# checkout -- three of CLASSIFICATION's four columns (task, criterion, dim) covered everywhere,
|
|
1568
|
+
# strictly more reach than the decisions.md-conditional check below can ever have. `verdict` stays
|
|
1569
|
+
# decisions.md-only; nothing here asserts gating/report-only, only that the (task, criterion, dim)
|
|
1570
|
+
# triples themselves haven't drifted from what the live spec actually tags.
|
|
1571
|
+
check "classification.mjs's (task, criterion, dim) triples match the live task specs' criterionTags()" \
|
|
1572
|
+
"$(j "
|
|
1573
|
+
const C = await import('$ROOT/tests/evals/lib/classification.mjs');
|
|
1574
|
+
const S = await import('$ROOT/tests/evals/lib/score.mjs');
|
|
1575
|
+
const fs = await import('node:fs');
|
|
1576
|
+
const dir = '$ROOT/tests/evals/tasks';
|
|
1577
|
+
const rows = [];
|
|
1578
|
+
for (const f of fs.readdirSync(dir).filter((f) => /^\d\d-.*\.md\$/.test(f))) {
|
|
1579
|
+
const task = f.slice(0, 2);
|
|
1580
|
+
const tags = S.criterionTags(fs.readFileSync(dir + '/' + f, 'utf8'));
|
|
1581
|
+
for (const [n, dims] of Object.entries(tags)) {
|
|
1582
|
+
if (dims.length !== 1) { process.stdout.write('multi-tag:' + task + ':' + n); process.exit(0); }
|
|
1583
|
+
rows.push(task + ':' + n + ':' + dims[0]);
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
const actual = rows.sort().join(',');
|
|
1587
|
+
const expected = C.CLASSIFICATION.map((r) => r.task + ':' + r.criterion + ':' + r.dim).sort().join(',');
|
|
1588
|
+
process.stdout.write(actual === expected ? 'match' : 'actual=' + actual + '|expected=' + expected);
|
|
1589
|
+
")" "match"
|
|
1590
|
+
|
|
1591
|
+
# --- classification.mjs vs the maintained classification's actual content: the real drift check -------
|
|
1592
|
+
# `.somi/` is gitignored repo-wide (scripts/check-links.mjs's own header: "`git ls-files` can never
|
|
1593
|
+
# produce a path inside it") -- decisions.md exists only on a machine actively working this plan,
|
|
1594
|
+
# never in a clean checkout or in CI. So this runs in one of two modes, never a third: present, or
|
|
1595
|
+
# loudly skipped when the plan directory itself is absent. There is no silent-pass path, and an
|
|
1596
|
+
# absent decisions.md next to a PRESENT plan directory is not the expected-skip case -- that is a
|
|
1597
|
+
# real gap (a renamed/moved/deleted file on a machine this check is supposed to protect) and fails
|
|
1598
|
+
# loudly rather than reading identically to the honest CI skip. When present, it is genuinely
|
|
1599
|
+
# bidirectional -- verified by hand this pass: flipping one row's verdict in
|
|
1600
|
+
# CLASSIFICATION with decisions.md untouched, and separately flipping the same row's verdict in
|
|
1601
|
+
# decisions.md with CLASSIFICATION untouched, each independently produced the `mismatch:...` line
|
|
1602
|
+
# the check below would print, in the opposite direction (got/want swapped) each time, then
|
|
1603
|
+
# reverted. Also verified this pass: appending a synthetic dated correction demoting
|
|
1604
|
+
# `01|6` reds the check; flipping the SETTLED table's own copy of `01|6` reds it; flipping only the
|
|
1605
|
+
# ORIGINAL table's copy (now correctly superseded) does not. Neither direction is covered when
|
|
1606
|
+
# decisions.md is absent -- that gap is real and is not claimed to be closed by the checks above.
|
|
1607
|
+
D11_PLAN_DIR="$ROOT/.somi/plans/eval-corpus-rebuild"
|
|
1608
|
+
D11_DECISIONS="$D11_PLAN_DIR/decisions.md"
|
|
1609
|
+
if [ -f "$D11_DECISIONS" ]; then
|
|
1610
|
+
drift=$(j "
|
|
1611
|
+
const C = await import('$ROOT/tests/evals/lib/classification.mjs');
|
|
1612
|
+
const fs = await import('node:fs');
|
|
1613
|
+
const text = fs.readFileSync('$D11_DECISIONS', 'utf8');
|
|
1614
|
+
let expected;
|
|
1615
|
+
try { expected = C.decisionsMdClassification(text); }
|
|
1616
|
+
catch (e) { process.stdout.write('throw:' + e.message); process.exit(0); }
|
|
1617
|
+
process.stdout.write(String(C.diffClassification(C.CLASSIFICATION, expected)));
|
|
1618
|
+
")
|
|
1619
|
+
check "classification.mjs matches decisions.md#d11's settled table exactly (task, criterion, dimension, verdict)" \
|
|
1620
|
+
"$drift" "null"
|
|
1621
|
+
elif [ -d "$D11_PLAN_DIR" ]; then
|
|
1622
|
+
bad "decisions.md#d11 drift check: $D11_PLAN_DIR exists but decisions.md is missing -- a real gap, not the expected CI/fresh-checkout absence"
|
|
1623
|
+
else
|
|
1624
|
+
echo " (skipped: $D11_PLAN_DIR not present -- .somi/ is gitignored, this check only runs where the plan directory is on disk)"
|
|
1625
|
+
fi
|
|
1626
|
+
|
|
1627
|
+
# --- smoke.mjs -- frontmatter-driven, zero-model-call smoke check for the
|
|
1628
|
+
# commands the live-model corpus does not gate with a live-model corpus -------------------------------
|
|
1629
|
+
# The 3 genuinely gated commands: /plan, /code, /review (the rebuilt task gate).
|
|
1630
|
+
# /code-loop's own convergence gate was once unbuilt, and labeling it `gate` excluded it from smoke
|
|
1631
|
+
# for a mechanism that did not exist. It then joined THIS tier, the same treatment /ship-loop gets
|
|
1632
|
+
# for its own deferred gate. Commands on disk today minus the gated set is what
|
|
1633
|
+
# remains in the smoke tier -- both counted below, not assumed (currently 24 minus 4 = 20).
|
|
1634
|
+
#
|
|
1635
|
+
# this set used to be spelled independently at three sites (now three still --
|
|
1636
|
+
# GATED_COMMANDS_JS plus the two hardcoded expected.set('code-loop', ...)/('ship-loop', ...) rows
|
|
1637
|
+
# in the cross-check below, both deliberately NOT members of this set) -- one check widening its
|
|
1638
|
+
# own copy silently zeroed that check's coverage while the others stayed green (demonstrated before).
|
|
1639
|
+
#
|
|
1640
|
+
# 'code-loop' MOVES INTO this set here -- its own convergence gate now exists and has
|
|
1641
|
+
# a CLI (tests/evals/convergence.mjs), so it is no longer only frontmatter-and-install-checked. The
|
|
1642
|
+
# 2.6 cross-check below flips its docs/EVALS.md label to `gate` the moment
|
|
1643
|
+
# tests/scripts/convergence-runner.sh exists -- keyed on THAT file rather than on this set, per its
|
|
1644
|
+
# own comment; this line is what actually removes it from the smoke tier's 21.
|
|
1645
|
+
GATED_COMMANDS_JS="new Set(['plan', 'code', 'review', 'code-loop'])"
|
|
1646
|
+
|
|
1647
|
+
# A new command (commands/refactor-design.md) joined the smoke tier like every other ungated
|
|
1648
|
+
# reason alone; removing /somi (2.2.1) then took them to 24 and 20.
|
|
1649
|
+
# reason alone.
|
|
1650
|
+
check "24 commands on disk today (commands/*.md)" \
|
|
1651
|
+
"$(ls "$ROOT"/commands/*.md | wc -l | tr -d ' ')" "24"
|
|
1652
|
+
|
|
1653
|
+
check "discoverUngatedCommands() finds exactly the 20 D8 scopes this smoke check to (3.4: code-loop moved into GATED_COMMANDS_JS, 21 -> 20; a new command joined the smoke tier, 20 -> 21)" \
|
|
1654
|
+
"$(j "
|
|
1655
|
+
const S = await import('$ROOT/tests/evals/lib/smoke.mjs');
|
|
1656
|
+
const gated = $GATED_COMMANDS_JS;
|
|
1657
|
+
process.stdout.write(String(S.discoverUngatedCommands('$ROOT/commands', gated).length));
|
|
1658
|
+
")" "20"
|
|
1659
|
+
|
|
1660
|
+
# The load-bearing negative constraint, made structural rather than trusted by intention (this
|
|
1661
|
+
# phase has twice needed a grep pin, not trust, to keep "no test reaches this site" honest --
|
|
1662
|
+
# the shard-write path, the judge-machinery deletion). Neither check names the model-invoking export in
|
|
1663
|
+
# this comment, on purpose -- a docstring quoting it as prose is exactly the false-positive shape
|
|
1664
|
+
# the shard-write pin already caught once. Static, so neither survives a ROUTE change (a computed property name,
|
|
1665
|
+
# or a call from elsewhere) -- the behavioral pin further below covers that.
|
|
1666
|
+
check "smoke.mjs imports ONLY installSomi and DEFINITION_DIRS from install.mjs" \
|
|
1667
|
+
"$(grep -c "from './install.mjs';" "$ROOT/tests/evals/lib/smoke.mjs")" "1"
|
|
1668
|
+
check "smoke.mjs never references install.mjs's model-invoking export, anywhere in the file" \
|
|
1669
|
+
"$(grep -c 'invokeCommand' "$ROOT/tests/evals/lib/smoke.mjs")" "0"
|
|
1670
|
+
|
|
1671
|
+
# Behavioral pin: a stub `claude` on PATH proves NO route reaches the model -- not just
|
|
1672
|
+
# that the two static greps above hold. Every un-gated command is run through smokeCheck() with
|
|
1673
|
+
# the stub in front of the real binary; the sentinel it touches must stay absent no matter how
|
|
1674
|
+
# smoke.mjs got to this point.
|
|
1675
|
+
stub_bin=$(mktemp -d)
|
|
1676
|
+
stub_sentinel="$stub_bin/touched"
|
|
1677
|
+
printf '#!/bin/sh\n%s "%s"\nexit 1\n' "$(command -v touch)" "$stub_sentinel" > "$stub_bin/claude"
|
|
1678
|
+
chmod +x "$stub_bin/claude"
|
|
1679
|
+
stub_iters=$(PATH="$stub_bin:$PATH" node --input-type=module -e "
|
|
1680
|
+
const S = await import('$ROOT/tests/evals/lib/smoke.mjs');
|
|
1681
|
+
const gated = $GATED_COMMANDS_JS;
|
|
1682
|
+
const files = S.discoverUngatedCommands('$ROOT/commands', gated);
|
|
1683
|
+
for (const f of files) S.smokeCheck(f); process.stdout.write(String(files.length));
|
|
1684
|
+
" 2>/dev/null)
|
|
1685
|
+
# proves the loop iterated the shared gated-set constant for real (a throw before the final
|
|
1686
|
+
# write also leaves this empty, subsuming the old exit-status check) -- not a stale count reused
|
|
1687
|
+
# from a different check.
|
|
1688
|
+
check "the stub-claude loop iterated all 20 currently un-gated commands, so ABSENT below can't mean it never ran" \
|
|
1689
|
+
"$stub_iters" "20"
|
|
1690
|
+
check "no smokeCheck() call reaches a stub claude on PATH (sentinel stays absent)" \
|
|
1691
|
+
"$([ -e "$stub_sentinel" ] && echo TOUCHED || echo ABSENT)" "ABSENT"
|
|
1692
|
+
|
|
1693
|
+
# Positive control: proves the stub is reachable on PATH at all -- a bad mktemp/chmod would
|
|
1694
|
+
# otherwise leave ABSENT true for the wrong reason, with the check reading green regardless.
|
|
1695
|
+
PATH="$stub_bin" claude >/dev/null 2>&1
|
|
1696
|
+
check "positive control: claude invoked directly under the same stub touches the sentinel" \
|
|
1697
|
+
"$([ -e "$stub_sentinel" ] && echo TOUCHED || echo ABSENT)" "TOUCHED"
|
|
1698
|
+
rm -rf "$stub_bin"
|
|
1699
|
+
|
|
1700
|
+
check "CLAUDE_CODE_TOOLS allowlist is non-empty (D3: a literal constant, not a dependency)" \
|
|
1701
|
+
"$(j "const S = await import('$ROOT/tests/evals/lib/smoke.mjs'); process.stdout.write(String(S.CLAUDE_CODE_TOOLS.size > 0));")" "true"
|
|
1702
|
+
|
|
1703
|
+
# The acceptance criterion: smokeCheck() succeeds for every one of the 21
|
|
1704
|
+
# currently un-gated commands. Real commands are never mutated to make this pass (scope
|
|
1705
|
+
# discipline, stated in the coder's own brief) -- a real command failing here is a finding to
|
|
1706
|
+
# report, not a fixture to fix.
|
|
1707
|
+
allpass=$(j "
|
|
1708
|
+
const S = await import('$ROOT/tests/evals/lib/smoke.mjs');
|
|
1709
|
+
const gated = $GATED_COMMANDS_JS;
|
|
1710
|
+
const files = S.discoverUngatedCommands('$ROOT/commands', gated);
|
|
1711
|
+
const failed = files.map((f) => [f, S.smokeCheck(f)]).filter(([, r]) => !r.ok);
|
|
1712
|
+
process.stdout.write(failed.length === 0 ? 'ALL PASS' : failed.map(([f, r]) => f + ':' + r.field + ':' + r.reason).join(' | '));
|
|
1713
|
+
")
|
|
1714
|
+
check "smokeCheck() succeeds for all 20 currently un-gated commands" "$allpass" "ALL PASS"
|
|
1715
|
+
|
|
1716
|
+
# --- 2.5 acceptance: each of the four staged mutations fails with a SPECIFIC, ATTRIBUTABLE reason
|
|
1717
|
+
# -- part of the acceptance criterion, not added at review. Staged against a
|
|
1718
|
+
# REAL, installed command file (pr.md, arbitrarily -- any un-gated command would do), never a
|
|
1719
|
+
# hand-built fixture (adversarial mutations are staged against real, committed inputs).
|
|
1720
|
+
# `orig` is read once and held in memory -- copied aside, never `git checkout`'d -- and the mutant
|
|
1721
|
+
# lives only in a throwaway `installSomi()` temp dir that is removed at the end of every case;
|
|
1722
|
+
# `commands/pr.md` in the repo is never touched.
|
|
1723
|
+
smoke_mutation_case() {
|
|
1724
|
+
local got
|
|
1725
|
+
got=$(j "
|
|
1726
|
+
const fs = await import('node:fs');
|
|
1727
|
+
const os = await import('node:os');
|
|
1728
|
+
const path = await import('node:path');
|
|
1729
|
+
const { installSomi } = await import('$ROOT/tests/evals/lib/install.mjs');
|
|
1730
|
+
const S = await import('$ROOT/tests/evals/lib/smoke.mjs');
|
|
1731
|
+
const mutbin = fs.mkdtempSync(path.join(os.tmpdir(), 'somi-smoke-mut-'));
|
|
1732
|
+
installSomi('$ROOT', mutbin);
|
|
1733
|
+
const target = path.join(mutbin, '.claude', 'commands', 'pr.md');
|
|
1734
|
+
const orig = fs.readFileSync(target, 'utf8');
|
|
1735
|
+
$2
|
|
1736
|
+
fs.writeFileSync(target, mutated);
|
|
1737
|
+
const r = S.smokeCheck(target);
|
|
1738
|
+
fs.rmSync(mutbin, { recursive: true, force: true });
|
|
1739
|
+
process.stdout.write(r.ok ? 'PASSED-BUT-SHOULD-FAIL' : r.field + ':' + r.reason);
|
|
1740
|
+
")
|
|
1741
|
+
check "$1" "$got" "$3"
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
# Control first (every gate's suite asserts a healthy input is NOT rejected, not only
|
|
1745
|
+
# that a degraded one is caught) -- proves the four failures below are attributable to each
|
|
1746
|
+
# specific mutation, not to something already wrong with the fixture itself.
|
|
1747
|
+
smoke_control=$(j "
|
|
1748
|
+
const fs = await import('node:fs');
|
|
1749
|
+
const os = await import('node:os');
|
|
1750
|
+
const path = await import('node:path');
|
|
1751
|
+
const { installSomi } = await import('$ROOT/tests/evals/lib/install.mjs');
|
|
1752
|
+
const S = await import('$ROOT/tests/evals/lib/smoke.mjs');
|
|
1753
|
+
const mutbin = fs.mkdtempSync(path.join(os.tmpdir(), 'somi-smoke-mut-'));
|
|
1754
|
+
installSomi('$ROOT', mutbin);
|
|
1755
|
+
const target = path.join(mutbin, '.claude', 'commands', 'pr.md');
|
|
1756
|
+
const r = S.smokeCheck(target);
|
|
1757
|
+
fs.rmSync(mutbin, { recursive: true, force: true });
|
|
1758
|
+
process.stdout.write(r.ok ? 'PASS' : 'field:' + r.field + ' reason:' + r.reason);
|
|
1759
|
+
")
|
|
1760
|
+
check "control: the real, unmutated pr.md passes smokeCheck()" "$smoke_control" "PASS"
|
|
1761
|
+
|
|
1762
|
+
smoke_mutation_case "staged failure 1/4: a missing description fails, attributed to 'description'" \
|
|
1763
|
+
"const mutated = orig.replace(/^description:.*\n/m, '');" \
|
|
1764
|
+
"description:pr.md: frontmatter has no non-empty 'description'"
|
|
1765
|
+
|
|
1766
|
+
smoke_mutation_case "staged failure 2/4: a non-existent allowed-tools entry fails, attributed to 'allowed-tools'" \
|
|
1767
|
+
"const mutated = orig.replace(/^allowed-tools:.*\$/m, 'allowed-tools: Read, Grep, Glob, Bash, FrobnicateTool');" \
|
|
1768
|
+
"allowed-tools:pr.md: 'FrobnicateTool' is not a Claude Code tool this repo recognizes (not in CLAUDE_CODE_TOOLS)"
|
|
1769
|
+
|
|
1770
|
+
# Commands no longer declare model: at all (the front door dispatches this command's paired agent
|
|
1771
|
+
# at the agent's own declared cost/model instead) -- so the mutation for this slot is INSERTING
|
|
1772
|
+
# one, not un-recognizing one. pr.md carries no `model:` line post-conversion, so the mutation
|
|
1773
|
+
# prepends one right after the frontmatter's opening fence rather than replacing an existing line.
|
|
1774
|
+
smoke_mutation_case "staged failure 3/4: a re-added model: on a command fails, attributed to 'model'" \
|
|
1775
|
+
"const mutated = orig.replace(/^---\$/m, '---\nmodel: sonnet');" \
|
|
1776
|
+
"model:pr.md: frontmatter declares 'model: sonnet' -- commands no longer declare a model of their own; the front door dispatches this command's paired agent at the agent's own declared cost/model instead"
|
|
1777
|
+
|
|
1778
|
+
# The fix, proven both ways: FrobnicateTool (not real, above) still fails; TodoWrite (real, but
|
|
1779
|
+
# declared by no command in this repo today) now passes -- via the allowlist, not popularity. The
|
|
1780
|
+
# old, corpus-only predicate false-failed this case (the check taxed the first adopter of anything).
|
|
1781
|
+
smoke_todowrite=$(j "
|
|
1782
|
+
const fs = await import('node:fs');
|
|
1783
|
+
const os = await import('node:os');
|
|
1784
|
+
const path = await import('node:path');
|
|
1785
|
+
const { installSomi } = await import('$ROOT/tests/evals/lib/install.mjs');
|
|
1786
|
+
const S = await import('$ROOT/tests/evals/lib/smoke.mjs');
|
|
1787
|
+
const mutbin = fs.mkdtempSync(path.join(os.tmpdir(), 'somi-smoke-mut-'));
|
|
1788
|
+
installSomi('$ROOT', mutbin);
|
|
1789
|
+
const target = path.join(mutbin, '.claude', 'commands', 'pr.md');
|
|
1790
|
+
const orig = fs.readFileSync(target, 'utf8');
|
|
1791
|
+
const mutated = orig.replace(/^allowed-tools:.*\$/m, 'allowed-tools: Read, Grep, Glob, Bash, TodoWrite');
|
|
1792
|
+
fs.writeFileSync(target, mutated);
|
|
1793
|
+
const r = S.smokeCheck(target);
|
|
1794
|
+
fs.rmSync(mutbin, { recursive: true, force: true });
|
|
1795
|
+
process.stdout.write(r.ok ? 'PASS' : 'field:' + r.field + ' reason:' + r.reason);
|
|
1796
|
+
")
|
|
1797
|
+
check "TodoWrite -- real, but declared by no other command -- passes via the allowlist" \
|
|
1798
|
+
"$smoke_todowrite" "PASS"
|
|
1799
|
+
|
|
1800
|
+
# DEFINITION_DIRS pinned literally -- installSomi() and smokeCheck() both iterate this one
|
|
1801
|
+
# constant, so comparing the two sides against each other (as the mutation below does) can't catch
|
|
1802
|
+
# a dropped/renamed entry; only a pin against the literal value can.
|
|
1803
|
+
check "DEFINITION_DIRS is pinned literally" \
|
|
1804
|
+
"$(j "const { DEFINITION_DIRS } = await import('$ROOT/tests/evals/lib/install.mjs'); process.stdout.write(JSON.stringify(DEFINITION_DIRS));")" \
|
|
1805
|
+
'["commands","agents","skills","rules"]'
|
|
1806
|
+
|
|
1807
|
+
# The replacement: the path check no longer walks a command's body links (that duplicated
|
|
1808
|
+
# scripts/check-links.mjs and reintroduced the fence-blindness it was rewritten to remove). It now
|
|
1809
|
+
# asserts the installed tree contains every install.mjs DEFINITION_DIRS entry -- staged here by
|
|
1810
|
+
# deleting the installed 'skills' dir before smokeCheck() re-installs from it. The `all 21` check
|
|
1811
|
+
# alone is blind to dropping 'skills' from DEFINITION_DIRS -- both sides iterate
|
|
1812
|
+
# the same constant, so 0 of 21 go red there; staged failure 4/4 goes red on that drop too.
|
|
1813
|
+
smoke_missing_dir=$(j "
|
|
1814
|
+
const fs = await import('node:fs');
|
|
1815
|
+
const os = await import('node:os');
|
|
1816
|
+
const path = await import('node:path');
|
|
1817
|
+
const { installSomi } = await import('$ROOT/tests/evals/lib/install.mjs');
|
|
1818
|
+
const S = await import('$ROOT/tests/evals/lib/smoke.mjs');
|
|
1819
|
+
const mutbin = fs.mkdtempSync(path.join(os.tmpdir(), 'somi-smoke-mut-'));
|
|
1820
|
+
installSomi('$ROOT', mutbin);
|
|
1821
|
+
fs.rmSync(path.join(mutbin, '.claude', 'skills'), { recursive: true, force: true });
|
|
1822
|
+
const target = path.join(mutbin, '.claude', 'commands', 'pr.md');
|
|
1823
|
+
const r = S.smokeCheck(target);
|
|
1824
|
+
fs.rmSync(mutbin, { recursive: true, force: true });
|
|
1825
|
+
const matched = !r.ok && r.field === 'install' && r.reason.includes(\"did not install the 'skills' directory\");
|
|
1826
|
+
process.stdout.write(r.ok ? 'PASSED-BUT-SHOULD-FAIL' : (matched ? 'install:MATCH' : r.field + ':' + r.reason));
|
|
1827
|
+
")
|
|
1828
|
+
check "staged failure 4/4: the installed tree missing a DEFINITION_DIRS entry (skills/) fails, attributed to 'install'" \
|
|
1829
|
+
"$smoke_missing_dir" "install:MATCH"
|
|
1830
|
+
|
|
1831
|
+
# --- docs/EVALS.md's coverage table, cross-checked against classification.mjs and the live
|
|
1832
|
+
# SCOPES -- not against a second document. A document-to-document comparison cannot see a
|
|
1833
|
+
# document-vs-code gap (the lesson applied here to a new pair: the doc and the code it
|
|
1834
|
+
# describes, not two hand-authored copies of the same fact). --------------------------------------
|
|
1835
|
+
|
|
1836
|
+
# The per-command floor rule, with its zero-dimension exception: zero gating dimensions reads
|
|
1837
|
+
# report-only, never partial (even though 0/total is also "fewer than half"); fewer than half reads
|
|
1838
|
+
# partial; half or more reads gate. The zero-dimension-label guard: a naive `< 0.5 -> partial` rule
|
|
1839
|
+
# with no zero branch would mislabel task 03 (0 of 4) as `partial`, implying gating capability it
|
|
1840
|
+
# does not have -- exactly the overstatement the zero-dimension exception exists to forbid.
|
|
1841
|
+
check "coverage label floor rule: zero gating reads report-only, never partial (the zero-dimension guard); fewer-than-half reads partial; half-or-more reads gate" \
|
|
1842
|
+
"$(j "
|
|
1843
|
+
function labelFor(g, t) { if (g === 0) return 'report-only'; return (g / t) < 0.5 ? 'partial' : 'gate'; }
|
|
1844
|
+
const cases = [[0, 4], [0, 1], [1, 4], [2, 4], [1, 2], [3, 4]];
|
|
1845
|
+
process.stdout.write(cases.map(([g, t]) => labelFor(g, t)).join(','));
|
|
1846
|
+
")" "report-only,report-only,partial,gate,gate,gate"
|
|
1847
|
+
|
|
1848
|
+
# The task->command mapping is derived from each task spec's own header line (the same
|
|
1849
|
+
# `Command under test: \`/name\`` idiom run.mjs's own taskPrompt() parses), not hand-typed --
|
|
1850
|
+
# a task file renamed to a different command would move this, not silently leave it stale.
|
|
1851
|
+
check "task-to-command mapping is derived from each task spec's own header, not hardcoded" \
|
|
1852
|
+
"$(j "
|
|
1853
|
+
const fs = await import('node:fs');
|
|
1854
|
+
const dir = '$ROOT/tests/evals/tasks';
|
|
1855
|
+
const map = {};
|
|
1856
|
+
for (const f of fs.readdirSync(dir).filter((f) => /^\d\d-.*\.md\$/.test(f))) {
|
|
1857
|
+
const text = fs.readFileSync(dir + '/' + f, 'utf8');
|
|
1858
|
+
const m = text.match(/Command under test: \`\/(\w[\w-]*)\`/);
|
|
1859
|
+
map[f.slice(0, 2)] = m ? m[1] : null;
|
|
1860
|
+
}
|
|
1861
|
+
process.stdout.write(JSON.stringify(map));
|
|
1862
|
+
")" '{"01":"plan","02":"code","03":"review"}'
|
|
1863
|
+
|
|
1864
|
+
# The real check: parse docs/EVALS.md's actual coverage table (git-tracked, always present --
|
|
1865
|
+
# unlike decisions.md, this runs unconditionally, no CI-skip branch) and compare every row against
|
|
1866
|
+
# a label derived from classification.mjs's live CLASSIFICATION table, not from this comment or
|
|
1867
|
+
# from decisions.md's prose. /code-loop and /ship-loop sit outside classification.mjs's data model
|
|
1868
|
+
# (no task spec, no criteria -- the convergence gate and the deferred ship-loop gate respectively) and are
|
|
1869
|
+
# asserted directly for that stated reason, not derived from a table that was never built to cover
|
|
1870
|
+
# them; every other command name is read live off commands/*.md, so a 25th command or a rename
|
|
1871
|
+
# shows up as a missing/extra row rather than silently passing.
|
|
1872
|
+
coverage_check=$(j "
|
|
1873
|
+
const fs = await import('node:fs');
|
|
1874
|
+
const path = await import('node:path');
|
|
1875
|
+
const C = await import('$ROOT/tests/evals/lib/classification.mjs');
|
|
1876
|
+
function labelFor(g, t) { if (g === 0) return 'report-only'; return (g / t) < 0.5 ? 'partial' : 'gate'; }
|
|
1877
|
+
|
|
1878
|
+
const tasksDir = '$ROOT/tests/evals/tasks';
|
|
1879
|
+
const taskToCommand = {};
|
|
1880
|
+
for (const f of fs.readdirSync(tasksDir).filter((f) => /^\d\d-.*\.md\$/.test(f))) {
|
|
1881
|
+
const text = fs.readFileSync(path.join(tasksDir, f), 'utf8');
|
|
1882
|
+
const m = text.match(/Command under test: \`\/(\w[\w-]*)\`/);
|
|
1883
|
+
taskToCommand[f.slice(0, 2)] = m[1];
|
|
1884
|
+
}
|
|
1885
|
+
const byTask = {};
|
|
1886
|
+
for (const d of C.taskDimensions()) {
|
|
1887
|
+
byTask[d.task] ??= { gating: 0, total: 0 };
|
|
1888
|
+
byTask[d.task].total += 1;
|
|
1889
|
+
if (d.verdict === 'gating') byTask[d.task].gating += 1;
|
|
1890
|
+
}
|
|
1891
|
+
const expected = new Map();
|
|
1892
|
+
for (const [task, command] of Object.entries(taskToCommand)) {
|
|
1893
|
+
const { gating, total } = byTask[task];
|
|
1894
|
+
expected.set(command, { label: labelFor(gating, total), ratio: gating + ' of ' + total });
|
|
1895
|
+
}
|
|
1896
|
+
// F-170: 'smoke'/'phase 3' is only true while phase 3's gate isn't wired. Flip the expectation
|
|
1897
|
+
// once it lands, so this pin fails loudly on the transition instead of going stale through it --
|
|
1898
|
+
// the exact way /code-loop's 'gate' label went stale the first time (F-163).
|
|
1899
|
+
// F-175: keyed on 3.4's own artifact (tests/scripts/convergence-runner.sh), NOT on 3.3's
|
|
1900
|
+
// tests/evals/convergence.mjs. 3.3's Files line creates only that module; the instruction to
|
|
1901
|
+
// flip this label and move /code-loop into GATED_COMMANDS_JS lives solely in 3.4's Acceptance
|
|
1902
|
+
// (phases/03-convergence-gating.md). Keying on 3.3's file would redden this pin the moment 3.3
|
|
1903
|
+
// lands -- a full iteration before the fix instruction that explains it exists -- and the
|
|
1904
|
+
// cheapest escape from an unexplained red suite is publishing 'gate' before the gate runs
|
|
1905
|
+
// (F-163 a third time). \"being built in phase 3, not yet landed\" is still true at the end of
|
|
1906
|
+
// 3.3, so the doc row isn't stale there; a pin that reddens before its own claim goes false
|
|
1907
|
+
// teaches people to route around it.
|
|
1908
|
+
const convergenceBuilt = fs.existsSync('$ROOT/tests/scripts/convergence-runner.sh');
|
|
1909
|
+
expected.set('code-loop', convergenceBuilt
|
|
1910
|
+
? { label: 'gate' }
|
|
1911
|
+
: { label: 'smoke', mustMention: 'phase 3' });
|
|
1912
|
+
expected.set('ship-loop', { label: 'smoke', mustMention: 'deferred' });
|
|
1913
|
+
for (const f of fs.readdirSync('$ROOT/commands').filter((f) => f.endsWith('.md'))) {
|
|
1914
|
+
const name = f.slice(0, -3);
|
|
1915
|
+
if (!expected.has(name)) expected.set(name, { label: 'smoke' });
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
function parseCoverageTable(text) {
|
|
1919
|
+
// F-166: was \`(.+?)\s*\|\$\`, /m -- a lazy group anchored only at END OF LINE doesn't stop at
|
|
1920
|
+
// an embedded \`|\`; a future 4th column would silently fold into \`detail\`, so a row could
|
|
1921
|
+
// state the wrong ratio in its own cell and still pass on a substring match against the
|
|
1922
|
+
// absorbed neighbour. Split into exactly 3 non-empty cells instead; a row with more or fewer
|
|
1923
|
+
// fails to match at all (reported \`missing:<name>\`) rather than over-capturing.
|
|
1924
|
+
const actual = new Map();
|
|
1925
|
+
const re = /^\|([^|\n]*)\|([^|\n]*)\|([^|\n]*)\|\s*\$/gm;
|
|
1926
|
+
let m;
|
|
1927
|
+
while ((m = re.exec(text))) {
|
|
1928
|
+
const nm = m[1].trim().match(/^\`\/([\w-]+)\`\$/);
|
|
1929
|
+
const label = m[2].trim(), detail = m[3].trim();
|
|
1930
|
+
if (nm && label && detail) {
|
|
1931
|
+
if (actual.has(nm[1])) throw new Error('duplicate coverage row: ' + nm[1]);
|
|
1932
|
+
actual.set(nm[1], { label, detail });
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
return actual;
|
|
1936
|
+
}
|
|
1937
|
+
function diff(actual, expected) {
|
|
1938
|
+
const problems = [];
|
|
1939
|
+
for (const [name, exp] of expected) {
|
|
1940
|
+
const got = actual.get(name);
|
|
1941
|
+
if (!got) { problems.push('missing:' + name); continue; }
|
|
1942
|
+
if (got.label !== exp.label) problems.push('label:' + name + ':got=' + got.label + ':want=' + exp.label);
|
|
1943
|
+
if (exp.ratio && !got.detail.includes(exp.ratio)) problems.push('ratio:' + name + ':want ' + exp.ratio + ' in \"' + got.detail + '\"');
|
|
1944
|
+
if (exp.mustMention && !got.detail.toLowerCase().includes(exp.mustMention)) problems.push('mention:' + name + ':want \"' + exp.mustMention + '\" in \"' + got.detail + '\"');
|
|
1945
|
+
}
|
|
1946
|
+
for (const name of actual.keys()) if (!expected.has(name)) problems.push('extra:' + name);
|
|
1947
|
+
return problems;
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
const docText = fs.readFileSync('$ROOT/docs/EVALS.md', 'utf8');
|
|
1951
|
+
const actual = parseCoverageTable(docText);
|
|
1952
|
+
const problems = diff(actual, expected);
|
|
1953
|
+
process.stdout.write(problems.length === 0 ? 'MATCH:' + actual.size : problems.join(' | '));
|
|
1954
|
+
")
|
|
1955
|
+
check "docs/EVALS.md's coverage table (24 rows) matches labels derived from classification.mjs + D8's floor rule, live -- not copied from the plan" \
|
|
1956
|
+
"$coverage_check" "MATCH:24"
|
|
1957
|
+
|
|
1958
|
+
# The full-scope numeric row, same discipline: parsed off docs/EVALS.md's actual text, compared
|
|
1959
|
+
# against SCOPES.full imported live from run.mjs, formatted exactly as certify()'s own CLI output
|
|
1960
|
+
# formats it (toFixed(2)) so the doc and the printed run summary can never read differently.
|
|
1961
|
+
check "docs/EVALS.md's \`full\` scope row (draws, budget, all three power figures, covers) matches SCOPES.full live -- 240 draws / 1.81% all-soft / 27.00% one-soft" \
|
|
1962
|
+
"$(j "
|
|
1963
|
+
const fs = await import('node:fs');
|
|
1964
|
+
function parseFullScopeRow(text) {
|
|
1965
|
+
const m = text.match(/\|\s*\`full\`\s*\|\s*(\d+)\s*\|\s*≤(\d+)\s*\|\s*([\d.]+)%\s*\|\s*\*{0,2}([\d.]+)%\*{0,2}\s*\|\s*\*{0,2}([\d.]+)%\*{0,2}\s*\|\s*([^|]+?)\s*\|/);
|
|
1966
|
+
return m && { draws: Number(m[1]), maxFailures: Number(m[2]), powerGood: m[3], powerSoft: m[4], powerSoftOne: m[5], covers: m[6].trim() };
|
|
1967
|
+
}
|
|
1968
|
+
const parsed = parseFullScopeRow(fs.readFileSync('$ROOT/docs/EVALS.md', 'utf8'));
|
|
1969
|
+
const sc = M.SCOPES.full;
|
|
1970
|
+
const expected = { draws: sc.draws, maxFailures: sc.maxFailures, powerGood: (sc.powerGood * 100).toFixed(2), powerSoft: (sc.powerSoft * 100).toFixed(2), powerSoftOne: (sc.powerSoftOne * 100).toFixed(2), covers: sc.covers };
|
|
1971
|
+
process.stdout.write(JSON.stringify(parsed) === JSON.stringify(expected) ? 'match' : 'parsed=' + JSON.stringify(parsed) + ' expected=' + JSON.stringify(expected));
|
|
1972
|
+
")" "match"
|
|
1973
|
+
|
|
1974
|
+
# the doc restates SCOPES.full.draws again in its own prose sentence, 95 lines below the
|
|
1975
|
+
# pinned table above -- pin that copy too, or one number stays free to drift while the other is
|
|
1976
|
+
# checked (exactly how "260" survived next to a pinned "240").
|
|
1977
|
+
check "docs/EVALS.md's 'A full certification is N draws' sentence matches SCOPES.full.draws live" \
|
|
1978
|
+
"$(j "
|
|
1979
|
+
const fs = await import('node:fs');
|
|
1980
|
+
const t = fs.readFileSync('$ROOT/docs/EVALS.md', 'utf8');
|
|
1981
|
+
const m = t.match(/A full certification is (\d+) draws\./);
|
|
1982
|
+
process.stdout.write(m ? String(Number(m[1]) === M.SCOPES.full.draws) : 'no-match');
|
|
1983
|
+
")" "true"
|
|
1984
|
+
|
|
1985
|
+
# Both failure directions, shipped as permanent regression guards. Neither touches disk -- the
|
|
1986
|
+
# doc-direction case mutates a STRING copy of the real file's text in memory; the code-direction
|
|
1987
|
+
# case mutates a spread COPY of the real SCOPES.full object -- so neither risks corrupting a real
|
|
1988
|
+
# file if interrupted, per the "copy aside, never mutate in place" discipline applied to
|
|
1989
|
+
# a check's own fixtures. Also verified this pass against the real files on disk directly (mutate
|
|
1990
|
+
# docs/EVALS.md, confirm red, restore from a copy; mutate a copy of run.mjs's CERTIFY_N, confirm
|
|
1991
|
+
# red, restore) -- reported once at the time, not re-run on every suite invocation.
|
|
1992
|
+
check "the cross-check catches a wrong DOC number (240 -> 260), SCOPES held real" \
|
|
1993
|
+
"$(j "
|
|
1994
|
+
const fs = await import('node:fs');
|
|
1995
|
+
function parseFullScopeRow(text) {
|
|
1996
|
+
const m = text.match(/\|\s*\`full\`\s*\|\s*(\d+)\s*\|\s*≤(\d+)\s*\|\s*([\d.]+)%\s*\|\s*\*{0,2}([\d.]+)%\*{0,2}\s*\|\s*\*{0,2}([\d.]+)%\*{0,2}\s*\|\s*([^|]+?)\s*\|/);
|
|
1997
|
+
return m && { draws: Number(m[1]), maxFailures: Number(m[2]), powerGood: m[3], powerSoft: m[4], powerSoftOne: m[5], covers: m[6].trim() };
|
|
1998
|
+
}
|
|
1999
|
+
const real = fs.readFileSync('$ROOT/docs/EVALS.md', 'utf8');
|
|
2000
|
+
const mutated = real.replace('| \`full\` | 240 |', '| \`full\` | 260 |');
|
|
2001
|
+
const parsed = parseFullScopeRow(mutated);
|
|
2002
|
+
const sc = M.SCOPES.full;
|
|
2003
|
+
const expected = { draws: sc.draws, maxFailures: sc.maxFailures, powerGood: (sc.powerGood * 100).toFixed(2), powerSoft: (sc.powerSoft * 100).toFixed(2), powerSoftOne: (sc.powerSoftOne * 100).toFixed(2), covers: sc.covers };
|
|
2004
|
+
process.stdout.write(String(JSON.stringify(parsed) === JSON.stringify(expected)));
|
|
2005
|
+
")" "false"
|
|
2006
|
+
check "the cross-check catches a wrong CODE number (SCOPES.full.draws mutated), doc held real" \
|
|
2007
|
+
"$(j "
|
|
2008
|
+
const fs = await import('node:fs');
|
|
2009
|
+
function parseFullScopeRow(text) {
|
|
2010
|
+
const m = text.match(/\|\s*\`full\`\s*\|\s*(\d+)\s*\|\s*≤(\d+)\s*\|\s*([\d.]+)%\s*\|\s*\*{0,2}([\d.]+)%\*{0,2}\s*\|\s*\*{0,2}([\d.]+)%\*{0,2}\s*\|\s*([^|]+?)\s*\|/);
|
|
2011
|
+
return m && { draws: Number(m[1]), maxFailures: Number(m[2]), powerGood: m[3], powerSoft: m[4], powerSoftOne: m[5], covers: m[6].trim() };
|
|
2012
|
+
}
|
|
2013
|
+
const real = fs.readFileSync('$ROOT/docs/EVALS.md', 'utf8');
|
|
2014
|
+
const parsed = parseFullScopeRow(real);
|
|
2015
|
+
const mutatedScopesFull = { ...M.SCOPES.full, draws: 200 };
|
|
2016
|
+
const expected = { draws: mutatedScopesFull.draws, maxFailures: mutatedScopesFull.maxFailures, powerGood: (mutatedScopesFull.powerGood * 100).toFixed(2), powerSoft: (mutatedScopesFull.powerSoft * 100).toFixed(2), powerSoftOne: (mutatedScopesFull.powerSoftOne * 100).toFixed(2), covers: mutatedScopesFull.covers };
|
|
2017
|
+
process.stdout.write(String(JSON.stringify(parsed) === JSON.stringify(expected)));
|
|
2018
|
+
")" "false"
|
|
2019
|
+
|
|
2020
|
+
# --- convergence extractor -- reads /code-loop's loop-state JSON, classifies cap-breach ----
|
|
2021
|
+
# (R3). Two independent extractors -- passesToApprove() (a pure field read) and capBreached() (a
|
|
2022
|
+
# status classifier); neither calls the other, keeping the extractors code-disjoint from each other.
|
|
2023
|
+
CONV=tests/evals/lib/convergence.mjs
|
|
2024
|
+
cj() { node --input-type=module -e "const M = await import('$ROOT/$CONV'); $1" 2>&1; }
|
|
2025
|
+
|
|
2026
|
+
echo "== convergence extractor (3.1) =="
|
|
2027
|
+
|
|
2028
|
+
# --- passesToApprove(): fails safe (null) on anything that isn't a finite non-negative integer --
|
|
2029
|
+
check "passesToApprove(null) is null" "$(cj "process.stdout.write(String(M.passesToApprove(null)));")" "null"
|
|
2030
|
+
check "passesToApprove(undefined) is null" "$(cj "process.stdout.write(String(M.passesToApprove(undefined)));")" "null"
|
|
2031
|
+
check "passesToApprove({}) is null (no pass field)" "$(cj "process.stdout.write(String(M.passesToApprove({})));")" "null"
|
|
2032
|
+
check "passesToApprove('raw json string') is null (not pre-parsed -- fails safe, not JSON.parse'd for you)" \
|
|
2033
|
+
"$(cj "process.stdout.write(String(M.passesToApprove('{\"pass\":4}')));")" "null"
|
|
2034
|
+
check "passesToApprove({pass:'4'}) is null (string, not number)" "$(cj "process.stdout.write(String(M.passesToApprove({pass:'4'})));")" "null"
|
|
2035
|
+
check "passesToApprove({pass:-1}) is null (negative)" "$(cj "process.stdout.write(String(M.passesToApprove({pass:-1})));")" "null"
|
|
2036
|
+
check "passesToApprove({pass:1.5}) is null (non-integer)" "$(cj "process.stdout.write(String(M.passesToApprove({pass:1.5})));")" "null"
|
|
2037
|
+
check "passesToApprove({pass:0}) is 0 (a real, valid boundary value -- not treated as falsy/missing)" \
|
|
2038
|
+
"$(cj "process.stdout.write(String(M.passesToApprove({pass:0})));")" "0"
|
|
2039
|
+
check "passesToApprove({pass:4}) is 4 (the ordinary case)" "$(cj "process.stdout.write(String(M.passesToApprove({pass:4})));")" "4"
|
|
2040
|
+
# passesToApprove() is deliberately status-blind -- a RUNNING loop's provisional pass count comes
|
|
2041
|
+
# back as-is; the caller (the convergence driver) must gate on status/capBreached() separately
|
|
2042
|
+
# before treating it as a completed draw. Synthetic, not tied to any real file's live status, so
|
|
2043
|
+
# this stays a permanent, deterministic pin of the contract rather than depending on ambient state
|
|
2044
|
+
# that changes the moment a real loop finishes (see the guarded block below for why).
|
|
2045
|
+
check "passesToApprove() is status-blind: returns a RUNNING loop's provisional pass count as-is" \
|
|
2046
|
+
"$(cj "process.stdout.write(String(M.passesToApprove({status:'running', pass:1})));")" "1"
|
|
2047
|
+
|
|
2048
|
+
# --- capBreached(): fails safe (null) on anything that isn't a recognised status string ----------
|
|
2049
|
+
check "capBreached(null) is null" "$(cj "process.stdout.write(String(M.capBreached(null)));")" "null"
|
|
2050
|
+
check "capBreached({}) is null (no status field)" "$(cj "process.stdout.write(String(M.capBreached({})));")" "null"
|
|
2051
|
+
check "capBreached({status:123}) is null (not a string)" "$(cj "process.stdout.write(String(M.capBreached({status:123})));")" "null"
|
|
2052
|
+
check "capBreached({status:'pending'}) is null (not a documented status at all)" \
|
|
2053
|
+
"$(cj "process.stdout.write(String(M.capBreached({status:'pending'})));")" "null"
|
|
2054
|
+
check "capBreached({status:'diff-cap-exceded'}) is null (one-letter typo of a real breach status -- exact match, not fuzzy)" \
|
|
2055
|
+
"$(cj "process.stdout.write(String(M.capBreached({status:'diff-cap-exceded'})));")" "null"
|
|
2056
|
+
# the typo case above REMOVES a letter, so a loosened matcher (substring/prefix/case-fold/
|
|
2057
|
+
# trim) also returns null on it and passes -- it does not test exactness at all. These seven are
|
|
2058
|
+
# near-misses a loosened matcher would wrongly accept: the first three kill substring/prefix
|
|
2059
|
+
# containment (each embeds or extends a real status), 'DONE' kills case-folding and 'done ' kills
|
|
2060
|
+
# trimming -- both on the `done` arm. Those two alone left the *breach*-set lookup's own
|
|
2061
|
+
# case-fold/trim unmeasured -- `CAP_BREACH_STATUSES.has(status.toLowerCase())` and
|
|
2062
|
+
# `CAP_BREACH_STATUSES.has(status.trim())` both survived at 303/0, over-detecting a breach on
|
|
2063
|
+
# 'MAX-PASSES-EXCEEDED' where the module answers null. 'MAX-PASSES-EXCEEDED' kills case-folding and
|
|
2064
|
+
# 'max-passes-exceeded ' kills trimming on that arm specifically. Real module confirmed to answer
|
|
2065
|
+
# null on all seven before writing this.
|
|
2066
|
+
NEAR_MISS_STATUSES=('user-stopped' 'not-max-passes-exceeded' 'max-passes-exceeded-recovered' 'DONE' 'done ' 'MAX-PASSES-EXCEEDED' 'max-passes-exceeded ')
|
|
2067
|
+
for s in "${NEAR_MISS_STATUSES[@]}"; do
|
|
2068
|
+
check "capBreached({status:'$s'}) is null (near-miss of a real status -- exact match, not fuzzy)" \
|
|
2069
|
+
"$(cj "process.stdout.write(String(M.capBreached({status:'$s'})));")" "null"
|
|
2070
|
+
done
|
|
2071
|
+
check "capBreached({status:'done'}) is false" "$(cj "process.stdout.write(String(M.capBreached({status:'done'})));")" "false"
|
|
2072
|
+
# Decision, made deliberately rather than defaulted into: a RUNNING loop is neither a confirmed
|
|
2073
|
+
# pass nor a confirmed breach. false would assert "confirmed clean" (not yet true); true would mark
|
|
2074
|
+
# a live loop as a cap failure it has not committed -- exactly the corpus-measuring-itself trap
|
|
2075
|
+
# the standing design brief. null is the only answer that doesn't overclaim either way.
|
|
2076
|
+
check "capBreached({status:'running'}) is null, NOT false and NOT true (the deliberate 'not done != breached' decision)" \
|
|
2077
|
+
"$(cj "process.stdout.write(String(M.capBreached({status:'running'})));")" "null"
|
|
2078
|
+
# Every documented terminal cap-breach status, individually -- catches an implementation that only
|
|
2079
|
+
# recognises one or two of the five (`commands/code-loop.md`'s enum), not just the first tried.
|
|
2080
|
+
# derived from the module's own exported CAP_BREACH_STATUSES, not retyped -- a status added,
|
|
2081
|
+
# renamed, or dropped there is reflected here without a second edit. Reflection is
|
|
2082
|
+
# exactly why a RENAME went undetected -- `circuit-breaker` -> `circuit-breakers` passed 306/0,
|
|
2083
|
+
# because the loop derived both its subjects AND its only independent check (a count) from the same
|
|
2084
|
+
# constant under test. Pinned instead against `commands/code-loop.md`'s own enum -- a source of
|
|
2085
|
+
# truth outside the module that a rename cannot drag along with it -- via set-equality, which also
|
|
2086
|
+
# subsumes the count (an empty derivation compares "" against 5 real entries and fails loudly on
|
|
2087
|
+
# either side alone; both sides empty at once -- un-export AND the doc anchor
|
|
2088
|
+
# renamed -- printed `ok` at 300/1 without the sentinel default on DOC_STATUSES below, which
|
|
2089
|
+
# breaks that symmetry). This is the "vacuous zero-iteration pass" shape, closed here instead
|
|
2090
|
+
# of by counting. Matches this file's own precedent at ~1803: every other command name is read
|
|
2091
|
+
# live off `commands/*.md`, not retyped, so drift between the module and the doc shows up here too,
|
|
2092
|
+
# not just drift within the module. Filtered on an identifier-safe allowlist -- letters, digits,
|
|
2093
|
+
# underscore, hyphen -- rather than the doc's `[a-z-]` alphabet: sharing that
|
|
2094
|
+
# alphabet as the filter was itself a blind spot -- a status outside it drops from both sides
|
|
2095
|
+
# symmetrically and set-equality still compares equal (measured: `quota-cap-2` added to the module
|
|
2096
|
+
# AND documented gives 306/0, the string asserted nowhere). An allowlist, not a denylist of just
|
|
2097
|
+
# whitespace/quote/backslash: measured on this un-export mutation's actual stderr, a bare
|
|
2098
|
+
# `file:///.../[eval1]:1` frame contains none of those three and would have slipped through as a
|
|
2099
|
+
# bogus status. The allowlist keeps the actual concern -- stopping a failed import's stderr
|
|
2100
|
+
# from landing as a raw token inside the single-quoted JS literals below -- while still being
|
|
2101
|
+
# strictly wider than the doc's alphabet, so a real status outside `[a-z-]` surfaces as a
|
|
2102
|
+
# set-equality mismatch instead of vanishing from both sides. Also drops `mapfile` (a minor portability cleanup),
|
|
2103
|
+
# this script's only bash-4-only builtin.
|
|
2104
|
+
BREACH_STATUSES=()
|
|
2105
|
+
while IFS= read -r s; do
|
|
2106
|
+
[[ "$s" =~ ^[A-Za-z0-9_-]+$ ]] && BREACH_STATUSES+=("$s")
|
|
2107
|
+
done < <(cj "for (const s of M.CAP_BREACH_STATUSES) process.stdout.write(s + '\n');")
|
|
2108
|
+
DOC_STATUSES="$(grep -A1 'Loop status:' "$ROOT/commands/code-loop.md" | grep -o '`[a-z-]*`' | tr -d '`' | grep -v '^done$' | sort)"
|
|
2109
|
+
check "the module's CAP_BREACH_STATUSES matches commands/code-loop.md's documented enum exactly (set-equality, not a count)" \
|
|
2110
|
+
"$(printf '%s\n' ${BREACH_STATUSES[@]+"${BREACH_STATUSES[@]}"} | sort)" "${DOC_STATUSES:-<doc-derivation-empty>}"
|
|
2111
|
+
for s in "${BREACH_STATUSES[@]}"; do
|
|
2112
|
+
check "capBreached({status:'$s'}) is true (documented breach terminal)" \
|
|
2113
|
+
"$(cj "process.stdout.write(String(M.capBreached({status:'$s'})));")" "true"
|
|
2114
|
+
done
|
|
2115
|
+
# The literal acceptance criterion: true against a synthetic file staged with
|
|
2116
|
+
# status:"max-passes-exceeded" -- restated once more here as its own named check, not only folded
|
|
2117
|
+
# into the loop above, so this specific acceptance point has its own visible pass/fail line.
|
|
2118
|
+
check "capBreached() on a synthetic file staged with status:\"max-passes-exceeded\" is true (phase 3.1's own acceptance wording)" \
|
|
2119
|
+
"$(cj "process.stdout.write(String(M.capBreached({status:'max-passes-exceeded'})));")" "true"
|
|
2120
|
+
|
|
2121
|
+
# --- breachReason(): the SPECIFIC cap-breach reason, not merely the
|
|
2122
|
+
# boolean capBreached() already returns -- gates on capBreached() === true and strips the same
|
|
2123
|
+
# stopped-<reason> prefix capBreached() already strips internally but never exposes.
|
|
2124
|
+
# multipass-fixture's own driver fix (tests/evals/convergence.mjs's fillArm()) threads THIS
|
|
2125
|
+
# function's return through the breach branch; these are the extractor's own direct tests, same
|
|
2126
|
+
# split as capBreached()/classifyDraw() above (the extractor is tested here; the driver call site
|
|
2127
|
+
# is tested in the 3.3 section below via fillArm() directly).
|
|
2128
|
+
check "breachReason(null) is null" "$(cj "process.stdout.write(String(M.breachReason(null)));")" "null"
|
|
2129
|
+
check "breachReason({}) is null (no status field)" "$(cj "process.stdout.write(String(M.breachReason({})));")" "null"
|
|
2130
|
+
check "breachReason({status:123}) is null (not a string)" "$(cj "process.stdout.write(String(M.breachReason({status:123})));")" "null"
|
|
2131
|
+
check "breachReason({status:'done'}) is null (the success terminal, not a breach)" \
|
|
2132
|
+
"$(cj "process.stdout.write(String(M.breachReason({status:'done'})));")" "null"
|
|
2133
|
+
check "breachReason({status:'stopped-done'}) is null (F-239's own guard: never legitimately stopped-, and breachReason gates through capBreached() so it inherits that)" \
|
|
2134
|
+
"$(cj "process.stdout.write(String(M.breachReason({status:'stopped-done'})));")" "null"
|
|
2135
|
+
check "breachReason({status:'running'}) is null (neither converged nor breached yet)" \
|
|
2136
|
+
"$(cj "process.stdout.write(String(M.breachReason({status:'running'})));")" "null"
|
|
2137
|
+
check "breachReason({status:'pending'}) is null (undocumented status, not a near-miss guess)" \
|
|
2138
|
+
"$(cj "process.stdout.write(String(M.breachReason({status:'pending'})));")" "null"
|
|
2139
|
+
# Every documented terminal cap-breach status, individually, in BOTH the bare and the documented
|
|
2140
|
+
# stopped-<reason> finish-path form -- reuses BREACH_STATUSES (derived above
|
|
2141
|
+
# from the module's own exported CAP_BREACH_STATUSES, not retyped), so all five are covered, not
|
|
2142
|
+
# just the two named by example, and a status added/renamed/dropped there is
|
|
2143
|
+
# reflected here without a second edit.
|
|
2144
|
+
for s in "${BREACH_STATUSES[@]}"; do
|
|
2145
|
+
check "breachReason({status:'$s'}) is '$s' (bare form)" \
|
|
2146
|
+
"$(cj "process.stdout.write(String(M.breachReason({status:'$s'})));")" "$s"
|
|
2147
|
+
check "breachReason({status:'stopped-$s'}) is '$s', the BARE reason -- not the prefixed string (documented stopped-<reason> finish form, F-235)" \
|
|
2148
|
+
"$(cj "process.stdout.write(String(M.breachReason({status:'stopped-$s'})));")" "$s"
|
|
2149
|
+
done
|
|
2150
|
+
|
|
2151
|
+
# --- Against the real population the baseline was independently computed from -------------------------
|
|
2152
|
+
# .somi/ is gitignored (confirmed: .gitignore lines 3-4/8/34) -- .somi/somi-state/loop/ will not
|
|
2153
|
+
# exist on a fresh checkout or in a from-scratch CI clone, same precondition the classification
|
|
2154
|
+
# drift check above already handles. Guarded the same way, for the same reason.
|
|
2155
|
+
LOOPDIR="$ROOT/.somi/somi-state/loop"
|
|
2156
|
+
if [ -d "$LOOPDIR" ]; then
|
|
2157
|
+
# NAMED EXPLICITLY, not globbed. .somi/somi-state/loop/*.json has grown to 34 files since
|
|
2158
|
+
# the baseline was computed from 21 -- many of the new ones are the maintainers' own in-progress
|
|
2159
|
+
# loop-state files. A glob over *.json today would silently validate against a
|
|
2160
|
+
# DIFFERENT, still-growing population, not the one the baseline was independently computed from. This list is
|
|
2161
|
+
# that population, identified by name: composition cross-checked against its own breakdown
|
|
2162
|
+
# before trusting it (9 code + 1 plan under context-economy-overhaul, 4 code + 1 plan under
|
|
2163
|
+
# reasoning-craft, 5 code + 1 plan under somi-orchestrator = 21) and its values reproduce the
|
|
2164
|
+
# stated mean (2.142857...) and sample sd (1.236354...) exactly -- verified below, not assumed.
|
|
2165
|
+
BASELINE_21=(
|
|
2166
|
+
context-economy-overhaul.1.1 context-economy-overhaul.1.2 context-economy-overhaul.1.3
|
|
2167
|
+
context-economy-overhaul.2.1 context-economy-overhaul.2.2 context-economy-overhaul.2.3
|
|
2168
|
+
context-economy-overhaul.3.1 context-economy-overhaul.3.2 context-economy-overhaul.3.3
|
|
2169
|
+
context-economy-overhaul
|
|
2170
|
+
reasoning-craft.1.1 reasoning-craft.1.2 reasoning-craft.1.3 reasoning-craft.1.4
|
|
2171
|
+
reasoning-craft
|
|
2172
|
+
somi-orchestrator.1.1 somi-orchestrator.2.1 somi-orchestrator.3.1 somi-orchestrator.3.2 somi-orchestrator.4.1
|
|
2173
|
+
somi-orchestrator
|
|
2174
|
+
)
|
|
2175
|
+
names_js="["
|
|
2176
|
+
for n in "${BASELINE_21[@]}"; do names_js+="'$n',"; done
|
|
2177
|
+
names_js+="]"
|
|
2178
|
+
|
|
2179
|
+
missing=""
|
|
2180
|
+
for name in "${BASELINE_21[@]}"; do
|
|
2181
|
+
[ -f "$LOOPDIR/$name.json" ] || missing="$missing $name"
|
|
2182
|
+
done
|
|
2183
|
+
if [ -z "$missing" ]; then
|
|
2184
|
+
check "all 21 of context.md §2.2's named baseline files still exist on disk" "present" "present"
|
|
2185
|
+
else
|
|
2186
|
+
check "all 21 of context.md §2.2's named baseline files still exist on disk" "MISSING:$missing" "present"
|
|
2187
|
+
fi
|
|
2188
|
+
|
|
2189
|
+
check "passesToApprove() reproduces exactly context.md §2.2's 21 values, by name not by glob" \
|
|
2190
|
+
"$(cj "
|
|
2191
|
+
const fs = await import('node:fs');
|
|
2192
|
+
const names = $names_js;
|
|
2193
|
+
const dir = '$LOOPDIR';
|
|
2194
|
+
const got = names.map((n) => M.passesToApprove(JSON.parse(fs.readFileSync(dir + '/' + n + '.json', 'utf8'))));
|
|
2195
|
+
process.stdout.write(JSON.stringify(got));
|
|
2196
|
+
")" \
|
|
2197
|
+
"[4,4,5,2,3,2,3,3,3,3,1,1,1,1,2,1,1,1,1,1,2]"
|
|
2198
|
+
|
|
2199
|
+
check "the 21 extracted values' mean/sd match context.md §2.2 exactly (2.142857.../1.236354...)" \
|
|
2200
|
+
"$(cj "
|
|
2201
|
+
const fs = await import('node:fs');
|
|
2202
|
+
const names = $names_js;
|
|
2203
|
+
const dir = '$LOOPDIR';
|
|
2204
|
+
const p = names.map((n) => M.passesToApprove(JSON.parse(fs.readFileSync(dir + '/' + n + '.json', 'utf8'))));
|
|
2205
|
+
const mean = p.reduce((a, b) => a + b, 0) / p.length;
|
|
2206
|
+
const sd = Math.sqrt(p.reduce((a, b) => a + (b - mean) ** 2, 0) / (p.length - 1));
|
|
2207
|
+
process.stdout.write(mean.toFixed(6) + '/' + sd.toFixed(6));
|
|
2208
|
+
")" \
|
|
2209
|
+
"2.142857/1.236354"
|
|
2210
|
+
|
|
2211
|
+
check "capBreached() is false for all 21 of context.md §2.2's named files (all real status:\"done\")" \
|
|
2212
|
+
"$(cj "
|
|
2213
|
+
const fs = await import('node:fs');
|
|
2214
|
+
const names = $names_js;
|
|
2215
|
+
const dir = '$LOOPDIR';
|
|
2216
|
+
const got = names.map((n) => M.capBreached(JSON.parse(fs.readFileSync(dir + '/' + n + '.json', 'utf8'))));
|
|
2217
|
+
process.stdout.write(String(got.every((b) => b === false)) + ':' + got.length);
|
|
2218
|
+
")" \
|
|
2219
|
+
"true:21"
|
|
2220
|
+
|
|
2221
|
+
# The corpus grew a second way since: it now contains loop-state files that are neither
|
|
2222
|
+
# done nor a cap-breach -- status:"running" (a few in-progress files). Discovered DYNAMICALLY, by count, rather than by
|
|
2223
|
+
# naming these specific files: an in-progress state file WILL flip to "done" the moment
|
|
2224
|
+
# its loop finishes, so a check hardcoded to a fixed filename/count would go stale for a reason
|
|
2225
|
+
# unrelated to correctness the moment that loop closes. The invariant under test
|
|
2226
|
+
# (capBreached() is null for a real running file, never false or true) holds regardless of how
|
|
2227
|
+
# many such files exist at any given moment, including zero.
|
|
2228
|
+
running_check=$(cj "
|
|
2229
|
+
const fs = await import('node:fs');
|
|
2230
|
+
const files = fs.readdirSync('$LOOPDIR').filter((f) => f.endsWith('.json'));
|
|
2231
|
+
const runningResults = [];
|
|
2232
|
+
for (const f of files) {
|
|
2233
|
+
const o = JSON.parse(fs.readFileSync('$LOOPDIR/' + f, 'utf8'));
|
|
2234
|
+
if (o.status === 'running') runningResults.push(M.capBreached(o));
|
|
2235
|
+
}
|
|
2236
|
+
process.stdout.write(runningResults.length + ':' + runningResults.every((r) => r === null));
|
|
2237
|
+
")
|
|
2238
|
+
running_count="${running_check%%:*}"
|
|
2239
|
+
running_all_null="${running_check##*:}"
|
|
2240
|
+
if [ "$running_count" = "0" ]; then
|
|
2241
|
+
echo " (skipped: no real status:\"running\" loop-state file on disk right now to check capBreached() against)"
|
|
2242
|
+
else
|
|
2243
|
+
check "capBreached() is null for every real loop-state file currently status:\"running\" ($running_count found right now)" \
|
|
2244
|
+
"$running_all_null" "true"
|
|
2245
|
+
fi
|
|
2246
|
+
|
|
2247
|
+
# the check above is SELF-SELECTING -- it discovers subjects by the exact string
|
|
2248
|
+
# (o.status === 'running') it then asserts capBreached() classifies. If the schema renamed
|
|
2249
|
+
# 'running' to something else, zero files would match, running_count would read 0, and the block
|
|
2250
|
+
# above would print a skip rather than fail -- silent, not loud. Supplemented (not replaced) with
|
|
2251
|
+
# a check that scans EVERY real file in $LOOPDIR and asserts its status is one of the documented
|
|
2252
|
+
# ones, independent of which specific string it discovers first. This is what actually catches a
|
|
2253
|
+
# status the module has never seen, and cannot silently skip -- an empty $LOOPDIR still passes
|
|
2254
|
+
# vacuously (nothing to violate), but a non-empty one with an unrecognised status always fails.
|
|
2255
|
+
# 'done'/'running' are the two non-breach terminals this module itself recognises; the
|
|
2256
|
+
# five breach terminals come from M.CAP_BREACH_STATUSES directly, not a third hardcoded copy.
|
|
2257
|
+
known_status_check=$(cj "
|
|
2258
|
+
const fs = await import('node:fs');
|
|
2259
|
+
const files = fs.readdirSync('$LOOPDIR').filter((f) => f.endsWith('.json'));
|
|
2260
|
+
const known = new Set(['done', 'running', ...M.CAP_BREACH_STATUSES]);
|
|
2261
|
+
const unknown = [];
|
|
2262
|
+
for (const f of files) {
|
|
2263
|
+
const o = JSON.parse(fs.readFileSync('$LOOPDIR/' + f, 'utf8'));
|
|
2264
|
+
// F-236: bare membership missed the documented stopped-<reason> form -- go through
|
|
2265
|
+
// capBreached() itself (it strips the prefix) rather than a second un-prefixed spelling.
|
|
2266
|
+
if (!known.has(o.status) && M.capBreached(o) !== true) unknown.push(f + ':' + String(o.status));
|
|
2267
|
+
}
|
|
2268
|
+
process.stdout.write(unknown.length === 0 ? 'ALL_KNOWN' : unknown.join(','));
|
|
2269
|
+
")
|
|
2270
|
+
check "every real loop-state file's status is in {done} ∪ CAP_BREACH_STATUSES ∪ {stopped-<reason> : reason ∈ CAP_BREACH_STATUSES} ∪ {running} ($LOOPDIR)" \
|
|
2271
|
+
"$known_status_check" "ALL_KNOWN"
|
|
2272
|
+
else
|
|
2273
|
+
echo " (skipped: $LOOPDIR not present -- .somi/ is gitignored, this block only runs where real loop-state history is on disk)"
|
|
2274
|
+
fi
|
|
2275
|
+
|
|
2276
|
+
# --- Mutation testing: staged against COPIES of a real, COMMITTED loop-state file --
|
|
2277
|
+
# never against the file itself, and never against inputs invented to be easy to pass. Runs
|
|
2278
|
+
# unconditionally -- unlike the block above, this one does NOT read $LOOPDIR (these mutation tests
|
|
2279
|
+
# used to read the same gitignored directory, so a "committed" claim was false; a
|
|
2280
|
+
# contributor whose loop directory existed but lacked these two exact named files would also have
|
|
2281
|
+
# hit an unhandled read failure on this block, the same shape of machine-dependence, just not the
|
|
2282
|
+
# one a review happened to test). DONE_FIXTURE is `context-economy-overhaul.2.1.json`, committed
|
|
2283
|
+
# verbatim (pass=2, status=done).
|
|
2284
|
+
DONE_FIXTURE="$ROOT/tests/scripts/goldens/loop-state-done.json"
|
|
2285
|
+
scratch=$(mktemp -d)
|
|
2286
|
+
|
|
2287
|
+
check "mutation (wrong field name: pass -> passes) on a COPY of a real, committed loop-state file is caught" \
|
|
2288
|
+
"$(cj "
|
|
2289
|
+
const fs = await import('node:fs');
|
|
2290
|
+
const obj = JSON.parse(fs.readFileSync('$DONE_FIXTURE', 'utf8'));
|
|
2291
|
+
obj.passes = obj.pass; delete obj.pass;
|
|
2292
|
+
fs.writeFileSync('$scratch/wrong-field.json', JSON.stringify(obj));
|
|
2293
|
+
process.stdout.write(String(M.passesToApprove(JSON.parse(fs.readFileSync('$scratch/wrong-field.json', 'utf8')))));
|
|
2294
|
+
")" \
|
|
2295
|
+
"null"
|
|
2296
|
+
check "...the fixture itself was never touched by that mutation -- passesToApprove() on the original still returns 2" \
|
|
2297
|
+
"$(cj "const fs = await import('node:fs'); process.stdout.write(String(M.passesToApprove(JSON.parse(fs.readFileSync('$DONE_FIXTURE', 'utf8')))));")" \
|
|
2298
|
+
"2"
|
|
2299
|
+
|
|
2300
|
+
check "mutation (swapped status string: done -> diff-cap-exceeded) on a COPY of a real, committed loop-state file is caught" \
|
|
2301
|
+
"$(cj "
|
|
2302
|
+
const fs = await import('node:fs');
|
|
2303
|
+
const obj = JSON.parse(fs.readFileSync('$DONE_FIXTURE', 'utf8'));
|
|
2304
|
+
obj.status = 'diff-cap-exceeded';
|
|
2305
|
+
fs.writeFileSync('$scratch/swapped-status.json', JSON.stringify(obj));
|
|
2306
|
+
process.stdout.write(String(M.capBreached(JSON.parse(fs.readFileSync('$scratch/swapped-status.json', 'utf8')))));
|
|
2307
|
+
")" \
|
|
2308
|
+
"true"
|
|
2309
|
+
check "...the fixture itself was never touched by that mutation -- capBreached() on the original still returns false" \
|
|
2310
|
+
"$(cj "const fs = await import('node:fs'); process.stdout.write(String(M.capBreached(JSON.parse(fs.readFileSync('$DONE_FIXTURE', 'utf8')))));")" \
|
|
2311
|
+
"false"
|
|
2312
|
+
|
|
2313
|
+
rm -rf "$scratch"
|
|
2314
|
+
|
|
2315
|
+
# --- tie-conditional Mann-Whitney U via Monte Carlo, with a real oracle -----------
|
|
2316
|
+
# Two independent oracles, both required (an earlier self-referential oracle was rewritten twice and
|
|
2317
|
+
# deleted once, so a self-referential check is not trusted here). Oracle 1: published small-n
|
|
2318
|
+
# worked examples on UNTIED data, where the tie-conditional distribution this module computes and
|
|
2319
|
+
# the classic exact distribution agree (sources cited below). Oracle 2: brute-force permutation
|
|
2320
|
+
# enumeration on small TIED data (n1=n2=5 over {1,2,3}, C(10,5)=252 splits -- exhaustive, not
|
|
2321
|
+
# sampled), computed HERE, independently of mannWhitneyU's own code.
|
|
2322
|
+
MW=tests/evals/lib/mann-whitney.mjs
|
|
2323
|
+
# optional 2nd arg overrides the import path (defaults to the real file) -- lets the
|
|
2324
|
+
# mutation section below import a scratch COPY instead, without touching every existing call site.
|
|
2325
|
+
mwj() { node --input-type=module -e "const M = await import('${2:-$ROOT/$MW}'); $1" 2>&1; }
|
|
2326
|
+
|
|
2327
|
+
echo "== tie-conditional Mann-Whitney U (3.2) =="
|
|
2328
|
+
|
|
2329
|
+
# --- input validation: throws, never guesses -- mirrors run.mjs's grade() "throws rather than
|
|
2330
|
+
# grading" precedent (this file, ~line 40) applied to the new module. ---
|
|
2331
|
+
for bad in "[], [1]" "[1], []" "[1,'a'], [1]" "[1], [NaN]" "[1], [Infinity]" "null, [1]" \
|
|
2332
|
+
"[1], [1], {resamples:0}" "[1], [1], {resamples:-5}" "[1], [1], {resamples:1.5}" \
|
|
2333
|
+
"[1], [1], {resamples:10000001}" "[1], [1], {rng: 5}"; do
|
|
2334
|
+
got=$(mwj "try { M.mannWhitneyU($bad); process.stdout.write('NO THROW'); } catch (e) { process.stdout.write(e.constructor.name); }")
|
|
2335
|
+
check "mannWhitneyU($bad) throws rather than guessing" "$got" "RangeError"
|
|
2336
|
+
done
|
|
2337
|
+
check "a valid, minimal call does not throw (the validation above doesn't also reject healthy input)" \
|
|
2338
|
+
"$(mwj "try { M.mannWhitneyU([1],[2],{resamples:1000}); process.stdout.write('ok'); } catch (e) { process.stdout.write('THREW:'+e.constructor.name); }")" "ok"
|
|
2339
|
+
# every probe above sits on the REJECTING side of both thresholds, so neither accepting
|
|
2340
|
+
# edge (resamples===1, resamples===MAX_RESAMPLES) was ever exercised -- a >=-for-> slip and its
|
|
2341
|
+
# <=-for-< mirror both passed all 333 checks, measured. Reads M.MAX_RESAMPLES, not a literal, so
|
|
2342
|
+
# this can't drift if the cap is ever raised.
|
|
2343
|
+
check "mannWhitneyU accepts BOTH true accepting edges: resamples===1 and resamples===MAX_RESAMPLES (F-216)" \
|
|
2344
|
+
"$(mwj "
|
|
2345
|
+
let ok1 = false, ok2 = false;
|
|
2346
|
+
try { M.mannWhitneyU([1],[2],{resamples:1}); ok1 = true; } catch {}
|
|
2347
|
+
try { M.mannWhitneyU([1],[2],{resamples:M.MAX_RESAMPLES}); ok2 = true; } catch {}
|
|
2348
|
+
process.stdout.write(String(ok1 && ok2));
|
|
2349
|
+
")" "true"
|
|
2350
|
+
|
|
2351
|
+
# --- the documented contract itself: resample count and its own stated MC-error formula ---
|
|
2352
|
+
check "DEFAULT_RESAMPLES is exported as exactly 200000 (the 'low hundred-thousands' figure this file's own docstring commits to and derives its worst-case SE from)" \
|
|
2353
|
+
"$(mwj "process.stdout.write(String(M.DEFAULT_RESAMPLES));")" "200000"
|
|
2354
|
+
check "returned mcError matches sqrt(p*(1-p)/resamples) recomputed from the returned p -- the stated formula, not a different one" \
|
|
2355
|
+
"$(mwj "
|
|
2356
|
+
const r = M.mannWhitneyU([1,2,3,4,5], [2,3,4,5,6], {resamples: 20000});
|
|
2357
|
+
const recomputed = Math.sqrt(r.p * (1 - r.p) / 20000);
|
|
2358
|
+
process.stdout.write(String(Math.abs(r.mcError - recomputed) < 1e-12));
|
|
2359
|
+
")" "true"
|
|
2360
|
+
check "p is bounded away from exact 0 (F-200 add-one correction)" "$(mwj "const r = M.mannWhitneyU(Array(15).fill(1), Array(15).fill(5), {resamples: 20000}); process.stdout.write(String(r.p === 1/20001 && r.mcError > 0));")" "true"
|
|
2361
|
+
check "direction is one of the three documented states (A>B / B>A / tie)" \
|
|
2362
|
+
"$(mwj "
|
|
2363
|
+
const r = M.mannWhitneyU([1,2,3], [4,5,6], {resamples: 5000});
|
|
2364
|
+
process.stdout.write(String(['A>B','B>A','tie'].includes(r.direction)));
|
|
2365
|
+
")" "true"
|
|
2366
|
+
check "F-203: two mannWhitneyU calls seeded with the same mulberry32(seed) reproduce the identical p (replayable from stored arms)" \
|
|
2367
|
+
"$(mwj "
|
|
2368
|
+
const a = M.mannWhitneyU([1,2,3,4,5], [3,4,5,6,7], {resamples: 5000, rng: M.mulberry32(7)});
|
|
2369
|
+
const b = M.mannWhitneyU([1,2,3,4,5], [3,4,5,6,7], {resamples: 5000, rng: M.mulberry32(7)});
|
|
2370
|
+
process.stdout.write(String(a.p === b.p && a.U === b.U));
|
|
2371
|
+
")" "true"
|
|
2372
|
+
|
|
2373
|
+
# --- Oracle 1: published worked examples on UNTIED data (known U and exact p from OUTSIDE this
|
|
2374
|
+
# module). Tolerance is DERIVED from the resample count under test (the "stated tolerance"
|
|
2375
|
+
# requirement), never loosened to fit: the Monte Carlo standard error of a resampled proportion is
|
|
2376
|
+
# sqrt(p(1-p)/R); 5x that SE bounds a correct implementation's false-failure rate at ~5.7e-7
|
|
2377
|
+
# (two-sided z), tight enough that the 1.5-3.6x conservative bias this test exists to rule out
|
|
2378
|
+
# would clear it by roughly two orders of magnitude, not a near-miss.
|
|
2379
|
+
ORACLE_RESAMPLES=200000
|
|
2380
|
+
|
|
2381
|
+
# shared enumeration helpers -- u() the same rank-sum computation as rankSumU, combos() a
|
|
2382
|
+
# k-combination generator, enumeratedP() "what fraction of every C(n,k) index-split is >= U",
|
|
2383
|
+
# computed HERE, independently of mannWhitneyU. Oracle 2 originally defined its own copy of
|
|
2384
|
+
# u()/combos() inline; shared here so oracle 1a/1b's cited p becomes p enumerated the same way,
|
|
2385
|
+
# not a second (or third) off-machine number the acceptance checks below have to trust.
|
|
2386
|
+
# run_mw_oracles() below deliberately does NOT reuse MW_ENUM -- it keeps its own cited
|
|
2387
|
+
# trueP1/trueP2/0.5 so the mutation evidence stays independent of enumeratedP; the positive
|
|
2388
|
+
# control that follows it is what pins those three numbers correct.
|
|
2389
|
+
MW_ENUM='
|
|
2390
|
+
function u(a,b){ let s=0; for (const bv of b) for (const av of a) { if (bv>av) s+=1; else if (bv===av) s+=0.5; } return s; }
|
|
2391
|
+
function combos(n,k){ const res=[]; const idx=Array.from({length:k},(_,i)=>i); while (true) { res.push(idx.slice()); let i=k-1; while (i>=0 && idx[i]===n-k+i) i--; if (i<0) break; idx[i]++; for (let j=i+1;j<k;j++) idx[j]=idx[j-1]+1; } return res; }
|
|
2392
|
+
function enumeratedP(a, b, observedU) {
|
|
2393
|
+
const pool = a.concat(b), n1 = a.length, N = pool.length;
|
|
2394
|
+
const subsets = combos(N, n1);
|
|
2395
|
+
let extreme = 0;
|
|
2396
|
+
for (const sub of subsets) {
|
|
2397
|
+
const inA = new Set(sub);
|
|
2398
|
+
const A = [], B = [];
|
|
2399
|
+
for (let i = 0; i < N; i++) (inA.has(i) ? A : B).push(pool[i]);
|
|
2400
|
+
if (u(A, B) >= observedU) extreme++;
|
|
2401
|
+
}
|
|
2402
|
+
return extreme / subsets.length;
|
|
2403
|
+
}
|
|
2404
|
+
'
|
|
2405
|
+
|
|
2406
|
+
# Example 1 -- Hollander & Wolfe (1973), "Nonparametric Statistical Methods", pp. 27-33 & 68-75:
|
|
2407
|
+
# permeability constants of the human chorioamnion, term (x) vs. 12-26wk gestation (y). This is
|
|
2408
|
+
# the canonical worked example in R's own stats::wilcox.test() documentation (Examples section);
|
|
2409
|
+
# the pooled 15 values are confirmed distinct (no ties). Exact U and one-sided p (x stochastically
|
|
2410
|
+
# greater than y) independently cross-checked via SciPy 1.17.1's
|
|
2411
|
+
# scipy.stats.mannwhitneyu(x, y, alternative='greater', method='exact') -- an unrelated,
|
|
2412
|
+
# independently-implemented realization of Mann & Whitney's (1947) own exact null-distribution
|
|
2413
|
+
# algorithm, not this module's code in any form: U=35, matching this module's own convention. Cited
|
|
2414
|
+
# below only as C(15,5)=3003; the exact p itself is now enumerated in-suite, not cited --
|
|
2415
|
+
# reusing MW_ENUM removes the only place this suite trusted an off-machine tool. armA is the
|
|
2416
|
+
# smaller (y) arm, armB the larger (x) arm, matching this module's tested direction (armB
|
|
2417
|
+
# stochastically greater than armA).
|
|
2418
|
+
check "C(15,5) = 3003 (oracle 1a's own denominator, verified, not assumed)" \
|
|
2419
|
+
"$(node -e "let r=1; for (let i=0;i<5;i++) r=r*(15-i)/(i+1); process.stdout.write(String(Math.round(r)));")" "3003"
|
|
2420
|
+
check "oracle 1a (Hollander & Wolfe 1973 permeability data, untied): U matches exactly, p (enumerated over all C(15,5)=3003 splits, not cited) within 5x its own Monte Carlo SE" \
|
|
2421
|
+
"$(mwj "$MW_ENUM
|
|
2422
|
+
const armA = [1.15, 0.88, 0.90, 0.74, 1.21];
|
|
2423
|
+
const armB = [0.80, 0.83, 1.89, 1.04, 1.45, 1.38, 1.91, 1.64, 0.73, 1.46];
|
|
2424
|
+
const r = M.mannWhitneyU(armA, armB, {resamples: $ORACLE_RESAMPLES});
|
|
2425
|
+
const pExact = enumeratedP(armA, armB, r.U);
|
|
2426
|
+
const tol = 5 * Math.sqrt(pExact * (1 - pExact) / $ORACLE_RESAMPLES);
|
|
2427
|
+
process.stdout.write(String(r.U === 35 && Math.abs(r.p - pExact) <= tol));
|
|
2428
|
+
")" "true"
|
|
2429
|
+
|
|
2430
|
+
# Example 2 -- Wikipedia, "Mann-Whitney U test", the tortoise/hare illustration: finishing order
|
|
2431
|
+
# 'T H H H H H T T T T T H' (6 of each; a permutation of 1..12, no ties). Ascending finish-position
|
|
2432
|
+
# values (1 = first place); tortoise as armB, hare as armA, exercising the same B-relative-to-A
|
|
2433
|
+
# convention oracle 1a does. The article's own rank-sum arithmetic (32/46, its own reversed-rank
|
|
2434
|
+
# convention) reproduces exactly as armA/armB's complementary pair (U_A+U_B=n1*n2=36, confirmed
|
|
2435
|
+
# while sourcing this example). Exact one-sided p cross-checked the same way as example 1 (SciPy,
|
|
2436
|
+
# method='exact'): U=25 (matching this module's convention); p enumerated in-suite, not
|
|
2437
|
+
# cited -- see C(12,6)=924 below.
|
|
2438
|
+
check "C(12,6) = 924 (oracle 1b's own denominator, verified, not assumed)" \
|
|
2439
|
+
"$(node -e "let r=1; for (let i=0;i<6;i++) r=r*(12-i)/(i+1); process.stdout.write(String(Math.round(r)));")" "924"
|
|
2440
|
+
check "oracle 1b (Wikipedia tortoise/hare, untied): U matches exactly, p (enumerated over all C(12,6)=924 splits, not cited) within 5x its own Monte Carlo SE" \
|
|
2441
|
+
"$(mwj "$MW_ENUM
|
|
2442
|
+
const armA = [2,3,4,5,6,12];
|
|
2443
|
+
const armB = [1,7,8,9,10,11];
|
|
2444
|
+
const r = M.mannWhitneyU(armA, armB, {resamples: $ORACLE_RESAMPLES});
|
|
2445
|
+
const pExact = enumeratedP(armA, armB, r.U);
|
|
2446
|
+
const tol = 5 * Math.sqrt(pExact * (1 - pExact) / $ORACLE_RESAMPLES);
|
|
2447
|
+
process.stdout.write(String(r.U === 25 && Math.abs(r.p - pExact) <= tol));
|
|
2448
|
+
")" "true"
|
|
2449
|
+
|
|
2450
|
+
# --- Oracle 2: brute-force permutation enumeration on small TIED data, computed OUTSIDE
|
|
2451
|
+
# mannWhitneyU entirely -- the real oracle for the tie case, sharing none of the implementation's
|
|
2452
|
+
# own assumptions. n1=n2=5 over {1,2,3}: C(10,5)=252, exhaustively enumerable (verified below, not
|
|
2453
|
+
# assumed). armA=[1,1,2,3,3], armB=[1,2,2,3,3] -- ties both within and across arms, the shape the
|
|
2454
|
+
# untied DP recursion (the rejected original method) cannot represent at all.
|
|
2455
|
+
check "C(10,5) = 252 (oracle 2's own denominator, verified, not assumed)" \
|
|
2456
|
+
"$(node -e "let r=1; for (let i=0;i<5;i++) r=r*(10-i)/(i+1); process.stdout.write(String(Math.round(r)));")" "252"
|
|
2457
|
+
|
|
2458
|
+
MW_ORACLE2_SNIPPET="$MW_ENUM"'
|
|
2459
|
+
const armA = [1,1,2,3,3];
|
|
2460
|
+
const armB = [1,2,2,3,3];
|
|
2461
|
+
const observedU = u(armA, armB);
|
|
2462
|
+
const r = M.mannWhitneyU(armA, armB, {resamples: '"$ORACLE_RESAMPLES"'});
|
|
2463
|
+
const pExact = enumeratedP(armA, armB, observedU);
|
|
2464
|
+
const tol = 5 * Math.sqrt(pExact * (1 - pExact) / '"$ORACLE_RESAMPLES"');
|
|
2465
|
+
process.stdout.write(String(r.U === observedU && Math.abs(r.p - pExact) <= tol));
|
|
2466
|
+
'
|
|
2467
|
+
check "oracle 2 (brute-force enumeration, n1=n2=5 over {1,2,3}, all 252 splits): U matches exactly, p within 5x its own Monte Carlo SE of the enumerated exact p" \
|
|
2468
|
+
"$(mwj "$MW_ORACLE2_SNIPPET")" "true"
|
|
2469
|
+
|
|
2470
|
+
# --- Mutation testing: staged against a COPY of mann-whitney.mjs, never the tracked
|
|
2471
|
+
# file itself (following the earlier precedent -- "staged against COPIES ...
|
|
2472
|
+
# never against the files themselves"). Both mutants are part of the acceptance
|
|
2473
|
+
# criterion, each confirmed caught by re-implementations of all three oracles above (
|
|
2474
|
+
# deliberately independent of MW_ENUM's enumeratedP), not by a case the implementation was written
|
|
2475
|
+
# to satisfy. mwj's optional path argument (above) is what makes this a one-line change per call
|
|
2476
|
+
# site: the scratch copy is mutated and imported directly, so the real file is never written.
|
|
2477
|
+
MW_SCRATCH_DIR=$(mktemp -d) || { bad "mktemp failed"; exit 1; }
|
|
2478
|
+
MW_SCRATCH="$MW_SCRATCH_DIR/mann-whitney.mjs"
|
|
2479
|
+
cp "$ROOT/$MW" "$MW_SCRATCH"
|
|
2480
|
+
trap 'rm -rf "$MW_SCRATCH_DIR"' EXIT
|
|
2481
|
+
|
|
2482
|
+
run_mw_oracles() {
|
|
2483
|
+
# returns 'ok1/ok2/ok3', not ok1&&ok2&&ok3 -- a conjunction can't tell "one oracle caught
|
|
2484
|
+
# it" from "all three did", and the acceptance requires catching by more than a single check.
|
|
2485
|
+
# $1 (optional): import path, forwarded to mwj -- defaults to the real, unmutated file.
|
|
2486
|
+
mwj "
|
|
2487
|
+
const armA1 = [1.15, 0.88, 0.90, 0.74, 1.21];
|
|
2488
|
+
const armB1 = [0.80, 0.83, 1.89, 1.04, 1.45, 1.38, 1.91, 1.64, 0.73, 1.46];
|
|
2489
|
+
const r1 = M.mannWhitneyU(armA1, armB1, {resamples: $ORACLE_RESAMPLES});
|
|
2490
|
+
const trueP1 = 382 / 3003;
|
|
2491
|
+
const ok1 = r1.U === 35 && Math.abs(r1.p - trueP1) <= 5 * Math.sqrt(trueP1 * (1 - trueP1) / $ORACLE_RESAMPLES);
|
|
2492
|
+
|
|
2493
|
+
const armA2 = [2,3,4,5,6,12];
|
|
2494
|
+
const armB2 = [1,7,8,9,10,11];
|
|
2495
|
+
const r2 = M.mannWhitneyU(armA2, armB2, {resamples: $ORACLE_RESAMPLES});
|
|
2496
|
+
const trueP2 = 13 / 84;
|
|
2497
|
+
const ok2 = r2.U === 25 && Math.abs(r2.p - trueP2) <= 5 * Math.sqrt(trueP2 * (1 - trueP2) / $ORACLE_RESAMPLES);
|
|
2498
|
+
|
|
2499
|
+
const armA3 = [1,1,2,3,3];
|
|
2500
|
+
const armB3 = [1,2,2,3,3];
|
|
2501
|
+
const r3 = M.mannWhitneyU(armA3, armB3, {resamples: $ORACLE_RESAMPLES});
|
|
2502
|
+
const ok3 = r3.U === 14 && Math.abs(r3.p - 0.5) <= 5 * Math.sqrt(0.5 * 0.5 / $ORACLE_RESAMPLES);
|
|
2503
|
+
|
|
2504
|
+
process.stdout.write(ok1 + '/' + ok2 + '/' + ok3);
|
|
2505
|
+
" "${1:-}"
|
|
2506
|
+
}
|
|
2507
|
+
|
|
2508
|
+
# positive control -- without this, any harness failure (a drifted literal, a typo in
|
|
2509
|
+
# armA3, a changed default) would leave both mutant checks reading "false/false/false" and
|
|
2510
|
+
# passing, indistinguishable from a real catch.
|
|
2511
|
+
check "positive control: pristine mann-whitney.mjs passes all three oracles" "$(run_mw_oracles)" "true/true/true"
|
|
2512
|
+
|
|
2513
|
+
# Mutant 1 -- off-by-one in the resampling logic: the B-side loop starts one index late, silently
|
|
2514
|
+
# dropping one pooled element from every resample's B side (a realistic single-character-shift
|
|
2515
|
+
# bug: 'n1' -> 'n1 + 1'). The resampled-A subset is still drawn correctly; only which indices count
|
|
2516
|
+
# toward B's side of U is wrong.
|
|
2517
|
+
node -e "
|
|
2518
|
+
const fs = require('fs');
|
|
2519
|
+
const p = '$MW_SCRATCH';
|
|
2520
|
+
const s = fs.readFileSync(p, 'utf8');
|
|
2521
|
+
const FROM = 'for (let bi = n1; bi < N; bi++) {';
|
|
2522
|
+
const TO = 'for (let bi = n1 + 1; bi < N; bi++) {';
|
|
2523
|
+
if (!s.includes(FROM)) throw new Error('mutant 1 pattern not found in $MW_SCRATCH -- source moved, update this mutation');
|
|
2524
|
+
fs.writeFileSync(p, s.replace(FROM, TO));
|
|
2525
|
+
"
|
|
2526
|
+
check "mutant 1 (off-by-one: B-side resample loop starts at n1+1, dropping one element) fails all three oracles (ok1/ok2/ok3)" \
|
|
2527
|
+
"$(run_mw_oracles "$MW_SCRATCH")" "false/false/false"
|
|
2528
|
+
cp "$ROOT/$MW" "$MW_SCRATCH" # reset the scratch copy to pristine before mutant 2
|
|
2529
|
+
|
|
2530
|
+
# Mutant 2 -- sampling WITH replacement instead of without: the exact defect an earlier
|
|
2531
|
+
# review named ('a bootstrap-with-replacement resampler').
|
|
2532
|
+
# Breaks tie-conditioning entirely -- every comparison draws independently from the full pool,
|
|
2533
|
+
# rather than resampling a fixed n1/n2 split of the pool's actual indices.
|
|
2534
|
+
node -e "
|
|
2535
|
+
const fs = require('fs');
|
|
2536
|
+
const p = '$MW_SCRATCH';
|
|
2537
|
+
const s = fs.readFileSync(p, 'utf8');
|
|
2538
|
+
const FROM = [
|
|
2539
|
+
' for (let i = 0; i < n1; i++) {',
|
|
2540
|
+
' const j = i + Math.floor(rng() * (N - i));',
|
|
2541
|
+
' const tmp = idx[i]; idx[i] = idx[j]; idx[j] = tmp;',
|
|
2542
|
+
' }',
|
|
2543
|
+
' let uSample = 0;',
|
|
2544
|
+
' for (let bi = n1; bi < N; bi++) {',
|
|
2545
|
+
' const bv = pool[idx[bi]];',
|
|
2546
|
+
' for (let ai = 0; ai < n1; ai++) {',
|
|
2547
|
+
' const av = pool[idx[ai]];',
|
|
2548
|
+
' if (bv > av) uSample += 1;',
|
|
2549
|
+
' else if (bv === av) uSample += 0.5;',
|
|
2550
|
+
' }',
|
|
2551
|
+
' }',
|
|
2552
|
+
].join('\n');
|
|
2553
|
+
const TO = [
|
|
2554
|
+
' let uSample = 0;',
|
|
2555
|
+
' for (let bi = 0; bi < n2; bi++) {',
|
|
2556
|
+
' const bv = pool[Math.floor(rng() * N)];',
|
|
2557
|
+
' for (let ai = 0; ai < n1; ai++) {',
|
|
2558
|
+
' const av = pool[Math.floor(rng() * N)];',
|
|
2559
|
+
' if (bv > av) uSample += 1;',
|
|
2560
|
+
' else if (bv === av) uSample += 0.5;',
|
|
2561
|
+
' }',
|
|
2562
|
+
' }',
|
|
2563
|
+
].join('\n');
|
|
2564
|
+
if (!s.includes(FROM)) throw new Error('mutant 2 pattern not found in $MW_SCRATCH -- source moved, update this mutation');
|
|
2565
|
+
fs.writeFileSync(p, s.replace(FROM, TO));
|
|
2566
|
+
"
|
|
2567
|
+
check "mutant 2 (sampling WITH replacement -- does not condition on the observed multiset) fails all three oracles (ok1/ok2/ok3)" \
|
|
2568
|
+
"$(run_mw_oracles "$MW_SCRATCH")" "false/false/false"
|
|
2569
|
+
|
|
2570
|
+
# repeat the positive control against the TRACKED file (no path arg -> mwj's default)
|
|
2571
|
+
# after both mutants -- closes the gap where a leaked write to the real file would silently
|
|
2572
|
+
# propagate through the next mutant's `cp` reset instead of being caught.
|
|
2573
|
+
check "positive control (after mutation): the tracked module is still pristine" "$(run_mw_oracles)" "true/true/true"
|
|
2574
|
+
|
|
2575
|
+
# the check above is what pins "the real file was never written", not an argument for it;
|
|
2576
|
+
# only $MW_SCRATCH was ever mutated. Cleanup: bash's `trap` for a signal REPLACES the handler, it
|
|
2577
|
+
# does not append -- so this registration alone would not survive
|
|
2578
|
+
# CVD_SCRATCH_DIR's own `trap` call below (:~2610), which is why THAT later registration names
|
|
2579
|
+
# BOTH scratch dirs rather than just its own, and is pinned by its own "names both" check right
|
|
2580
|
+
# after it. The combined trap removes both on any normal exit, including SIGINT/SIGTERM (a
|
|
2581
|
+
# SIGKILL bypasses any trap, leaking the scratch dir -- not the tracked file).
|
|
2582
|
+
|
|
2583
|
+
# --- convergence gate DRIVER. The module is split along its own section divider:
|
|
2584
|
+
# classifyDraw, fillArm, safeCleanup; compareArms, estimatePower, runComparison; and
|
|
2585
|
+
# loopShardPath/resumeArm/prepareDrawDir/startDraw/drawArmForSha -- the resume/namespace layer and
|
|
2586
|
+
# the live-draw mechanism (the workDir-contract and resume-gap checks). Hermetic throughout: every case below is a direct function call against
|
|
2587
|
+
# synthetic/injected input, or a setup-only seam (prepareDrawDir), never a live /code-loop
|
|
2588
|
+
# invocation (the full driver is run against the model for real only in a live batch).
|
|
2589
|
+
CVD=tests/evals/convergence.mjs
|
|
2590
|
+
cvj() { node --input-type=module -e "const M = await import('${2:-$ROOT/$CVD}'); $1" 2>&1; }
|
|
2591
|
+
|
|
2592
|
+
echo "== convergence gate driver, classification + arm-filling + comparison/verdict + shards/live-draw (3.3a+3.3b+3.3c) =="
|
|
2593
|
+
|
|
2594
|
+
# --- point 4 (first half): N_PER_ARM pinned as a literal, independent of any draw outcome -------
|
|
2595
|
+
check "N_PER_ARM is exactly 15" "$(cvj "process.stdout.write(String(M.N_PER_ARM));")" "15"
|
|
2596
|
+
# REGRESSION_SHIFT pinned as a literal too, same discipline -- the functional pin (does the
|
|
2597
|
+
# margin actually BITE at 0.5 and not at 1) lives further down, after the mutation-testing section,
|
|
2598
|
+
# since it needs $CVD_SCRATCH's revert-and-reassert idiom, not just a value read.
|
|
2599
|
+
check "REGRESSION_SHIFT is exactly 0.5 (D16)" "$(cvj "process.stdout.write(String(M.REGRESSION_SHIFT));")" "0.5"
|
|
2600
|
+
|
|
2601
|
+
# --- point 5: classifyDraw distinguishes breach / done / running / malformed -- the two null
|
|
2602
|
+
# causes told apart, not conflated under one null-means-skip catch-all --------------------
|
|
2603
|
+
check "classifyDraw: a documented breach status is 'breach'" \
|
|
2604
|
+
"$(cvj "process.stdout.write(M.classifyDraw({status:'max-passes-exceeded', pass:6}).kind);")" "breach"
|
|
2605
|
+
check "classifyDraw: the SAME breach status written with commands/code-loop.md's documented 'stopped-<reason>' finish-path prefix is ALSO 'breach', not malformed/undetermined (F-235)" \
|
|
2606
|
+
"$(cvj "process.stdout.write(M.classifyDraw({status:'stopped-max-passes-exceeded', pass:6}).kind);")" "breach"
|
|
2607
|
+
check "classifyDraw: status:done with a real pass field is 'done'" \
|
|
2608
|
+
"$(cvj "process.stdout.write(M.classifyDraw({status:'done', pass:2}).kind);")" "done"
|
|
2609
|
+
check "classifyDraw: status:running is 'running' -- 'not done != breached', distinct from malformed" \
|
|
2610
|
+
"$(cvj "process.stdout.write(M.classifyDraw({status:'running', pass:1}).kind);")" "running"
|
|
2611
|
+
check "classifyDraw: an unrecognised status is 'malformed', distinct from 'running' (closes F-184)" \
|
|
2612
|
+
"$(cvj "process.stdout.write(M.classifyDraw({status:'pending'}).kind);")" "malformed"
|
|
2613
|
+
check "classifyDraw(null) is 'malformed'" "$(cvj "process.stdout.write(M.classifyDraw(null).kind);")" "malformed"
|
|
2614
|
+
check "classifyDraw: status:done with an unreadable pass field is 'malformed', never silently 'done'" \
|
|
2615
|
+
"$(cvj "process.stdout.write(M.classifyDraw({status:'done', pass:'x'}).kind);")" "malformed"
|
|
2616
|
+
|
|
2617
|
+
# --- commands/code-loop.md
|
|
2618
|
+
# :136 documents `--status stopped-<reason>` as the STOP path's write; lib/convergence.mjs's
|
|
2619
|
+
# capBreached() matched only the bare <reason> forms, so a cap-breach recorded through the
|
|
2620
|
+
# DOCUMENTED path read null ("undetermined"), not true -- and classifyDraw() above inherited the
|
|
2621
|
+
# hole, since it calls capBreached() directly rather than re-matching status itself. Discovered by
|
|
2622
|
+
# the first status:"stopped-*" file this corpus ever produced: every real file before it was
|
|
2623
|
+
# `done` or `running`, so this branch had never fired against real data. The two checks above
|
|
2624
|
+
# already pin classifyDraw()'s own behaviour on the tracked module; this pins capBreached() itself,
|
|
2625
|
+
# mutation-verified, against a SCRATCH COPY of lib/convergence.mjs -- never the tracked file, and
|
|
2626
|
+
# never through the CVD_SCRATCH/lib symlink below (that symlink points at the REAL lib/ dir, so
|
|
2627
|
+
# mutating through it would mutate the repo's own source, not a copy).
|
|
2628
|
+
lib_conv_scratch=$(mktemp -d)
|
|
2629
|
+
cp "$ROOT/tests/evals/lib/convergence.mjs" "$lib_conv_scratch/convergence.mjs"
|
|
2630
|
+
libj() { node --input-type=module -e "const M = await import('$lib_conv_scratch/convergence.mjs'); $1" 2>&1; }
|
|
2631
|
+
check "capBreached: the bare reason and commands/code-loop.md's documented stopped-<reason> form both return true (F-235)" \
|
|
2632
|
+
"$(libj "process.stdout.write(String(M.capBreached({status:'max-passes-exceeded'})) + '/' + String(M.capBreached({status:'stopped-max-passes-exceeded'})));")" \
|
|
2633
|
+
"true/true"
|
|
2634
|
+
# Anchor text updated: the strip this mutant targets moved into its own
|
|
2635
|
+
# `stripStoppedPrefix()` helper, shared with breachReason() -- the anchor's own resilience covers a
|
|
2636
|
+
# change to lines AROUND it, not a change WITHIN the exact line it matches, so this needed a manual
|
|
2637
|
+
# update (the SAME "additive field collided with an existing anchor" shape Mutant B
|
|
2638
|
+
# already hit once -- caught here by running the suite, not by inspection).
|
|
2639
|
+
# Occurrence-count guard adopted while already touching this anchor.
|
|
2640
|
+
node -e "
|
|
2641
|
+
const fs = require('fs'); const p = '$lib_conv_scratch/convergence.mjs'; const s = fs.readFileSync(p, 'utf8');
|
|
2642
|
+
const FROM = 'const reason = stripStoppedPrefix(status);\n if (CAP_BREACH_STATUSES.has(reason)) return true;';
|
|
2643
|
+
const TO = 'const reason = status; // MUTANT (F-235): stopped- prefix stripping removed\n if (CAP_BREACH_STATUSES.has(reason)) return true;';
|
|
2644
|
+
const count = s.split(FROM).length - 1;
|
|
2645
|
+
if (count !== 1) throw new Error('F-235 mutant anchor occurs ' + count + ' time(s), not exactly 1 in lib/convergence.mjs -- source moved, update this mutation');
|
|
2646
|
+
fs.writeFileSync(p, s.replace(FROM, TO));
|
|
2647
|
+
"
|
|
2648
|
+
check "mutant (F-235: stopped- prefix stripping removed) is caught -- the documented stopped-<reason> form reads null again, the bare form is unaffected" \
|
|
2649
|
+
"$(libj "process.stdout.write(String(M.capBreached({status:'stopped-max-passes-exceeded'})) + '/' + String(M.capBreached({status:'max-passes-exceeded'})));")" \
|
|
2650
|
+
"null/true"
|
|
2651
|
+
rm -rf "$lib_conv_scratch"
|
|
2652
|
+
|
|
2653
|
+
# --- staged against a COMMITTED fixture, not a live-directory
|
|
2654
|
+
# scan -- the scan below is now an opportunistic supplement, never this assertion's only subject.
|
|
2655
|
+
# BREACH_FIXTURE is eval-corpus-rebuild.3.3.json, committed verbatim (status:"stopped-user-stop",
|
|
2656
|
+
# the DOCUMENTED stop-path write form, closed to that form via the real `somi-loop.mjs finish`
|
|
2657
|
+
# command not a hand-edit). Runs unconditionally -- in CI and on every
|
|
2658
|
+
# contributor's machine, regardless of whether $LOOPDIR exists or holds a stopped-* file, which is
|
|
2659
|
+
# almost none of them. Anchored to a re-runnable
|
|
2660
|
+
# command rather than a snapshot count, since a snapshot goes stale as this corpus grows on its own
|
|
2661
|
+
# -- this line's earlier "36 of 37" (files NOT stopped-*) already read "37 of 38" one iteration
|
|
2662
|
+
# later. The command below reproduces the RARE side of that instead -- a stopped-*
|
|
2663
|
+
# file, which is 1 of this repo's own 39 today. Reproduce with:
|
|
2664
|
+
# node -e "const fs=require('fs'),d='.somi/somi-state/loop';const f=fs.readdirSync(d)
|
|
2665
|
+
# .filter(x=>x.endsWith('.json'));let n=0;for(const x of f){try{if(/^stopped-/.test(
|
|
2666
|
+
# JSON.parse(fs.readFileSync(d+'/'+x,'utf8')).status))n++}catch{}}console.log(n+'/'+f.length)"
|
|
2667
|
+
# not self-selecting -- the subject is a FIXED committed file, not one discovered by the
|
|
2668
|
+
# predicate under test, and the raw `status` string is asserted alongside `kind` rather than only
|
|
2669
|
+
# the classifier's own output.
|
|
2670
|
+
BREACH_FIXTURE="$ROOT/tests/scripts/goldens/loop-state-breach.json"
|
|
2671
|
+
check "classifyDraw on the committed cap-breach fixture is 'breach', raw status is the documented stopped-<reason> form (F-241/F-242)" \
|
|
2672
|
+
"$(cvj "
|
|
2673
|
+
const fs = await import('node:fs');
|
|
2674
|
+
const o = JSON.parse(fs.readFileSync('$BREACH_FIXTURE', 'utf8'));
|
|
2675
|
+
process.stdout.write(M.classifyDraw(o).kind + '/' + o.status);
|
|
2676
|
+
")" "breach/stopped-user-stop"
|
|
2677
|
+
|
|
2678
|
+
LOOPDIR=".somi/somi-state/loop"
|
|
2679
|
+
if [ -d "$ROOT/$LOOPDIR" ]; then
|
|
2680
|
+
# the per-file parse below is wrapped in its OWN try/catch, not
|
|
2681
|
+
# left to `cvj`'s outer 2>&1 capture -- one unparseable .json (a file killed mid-write) used to
|
|
2682
|
+
# throw out of JSON.parse, and the captured stack trace (non-empty) then satisfied `[ -n "$var" ]`
|
|
2683
|
+
# below, so the following check tried to read a FILE NAMED BY THE STACK TRACE and failed loudly on
|
|
2684
|
+
# the wrong thing. A malformed file is skipped here exactly like an unreadable one -- this scan is
|
|
2685
|
+
# an opportunistic supplement and must degrade gracefully on corruption, not just absence.
|
|
2686
|
+
running_real=$(cvj "
|
|
2687
|
+
const fs = await import('node:fs');
|
|
2688
|
+
const files = fs.readdirSync('$ROOT/$LOOPDIR').filter((f) => f.endsWith('.json'));
|
|
2689
|
+
let found = '';
|
|
2690
|
+
for (const f of files) {
|
|
2691
|
+
let o;
|
|
2692
|
+
try { o = JSON.parse(fs.readFileSync('$ROOT/$LOOPDIR/' + f, 'utf8')); } catch { continue; }
|
|
2693
|
+
if (o.status === 'running') { found = f; break; }
|
|
2694
|
+
}
|
|
2695
|
+
process.stdout.write(found);
|
|
2696
|
+
")
|
|
2697
|
+
if [ -n "$running_real" ]; then
|
|
2698
|
+
check "classifyDraw on a real, currently-running loop-state file is 'running' ($running_real)" \
|
|
2699
|
+
"$(cvj "const fs = await import('node:fs'); process.stdout.write(M.classifyDraw(JSON.parse(fs.readFileSync('$ROOT/$LOOPDIR/$running_real', 'utf8'))).kind);")" "running"
|
|
2700
|
+
else
|
|
2701
|
+
echo " (skipped: no real status:\"running\" loop-state file on disk right now)"
|
|
2702
|
+
fi
|
|
2703
|
+
# Opportunistic supplement to the committed fixture above, not a replacement for it.
|
|
2704
|
+
# SELF-SELECTING, same shape running_real's own comment names above -- discovers by
|
|
2705
|
+
# the exact predicate (classifyDraw(...).kind === 'breach') it then asserts. An over-admitting
|
|
2706
|
+
# classifyDraw would pass this alone; the committed fixture's raw-status assertion is the one
|
|
2707
|
+
# that cannot be fooled that way. Degrades gracefully (skips, never fails) when absent OR
|
|
2708
|
+
# malformed (same fix as running_real above -- the per-file parse gets its own try/catch
|
|
2709
|
+
# rather than relying on `.find()`'s single expression to short-circuit on a thrown parse).
|
|
2710
|
+
breach_real=$(cvj "
|
|
2711
|
+
const fs = await import('node:fs');
|
|
2712
|
+
const files = fs.readdirSync('$ROOT/$LOOPDIR').filter((f) => f.endsWith('.json'));
|
|
2713
|
+
let found = '';
|
|
2714
|
+
for (const f of files) {
|
|
2715
|
+
let o;
|
|
2716
|
+
try { o = JSON.parse(fs.readFileSync('$ROOT/$LOOPDIR/' + f, 'utf8')); } catch { continue; }
|
|
2717
|
+
if (M.classifyDraw(o).kind === 'breach') { found = f; break; }
|
|
2718
|
+
}
|
|
2719
|
+
process.stdout.write(found);
|
|
2720
|
+
")
|
|
2721
|
+
if [ -n "$breach_real" ]; then
|
|
2722
|
+
check "classifyDraw on a real cap-breach loop-state file is 'breach' ($breach_real)" \
|
|
2723
|
+
"$(cvj "const fs = await import('node:fs'); process.stdout.write(M.classifyDraw(JSON.parse(fs.readFileSync('$ROOT/$LOOPDIR/$breach_real', 'utf8'))).kind);")" "breach"
|
|
2724
|
+
else
|
|
2725
|
+
echo " (skipped: no real cap-breach loop-state file on disk right now -- the committed fixture above already covers this branch)"
|
|
2726
|
+
fi
|
|
2727
|
+
else
|
|
2728
|
+
echo " (skipped: $LOOPDIR not present)"
|
|
2729
|
+
fi
|
|
2730
|
+
|
|
2731
|
+
# Staged on a COPY of a real, COMMITTED loop-state file (the scorer discipline),
|
|
2732
|
+
# unconditional for the same reason the mutation tests above are (DONE_FIXTURE, set
|
|
2733
|
+
# there, is reused rather than redefined).
|
|
2734
|
+
cvd_scratch=$(mktemp -d)
|
|
2735
|
+
check "mutation (status: done -> pemding, an unrecognised near-miss) on a COPY is malformed, not silently done" \
|
|
2736
|
+
"$(cvj "
|
|
2737
|
+
const fs = await import('node:fs');
|
|
2738
|
+
const obj = JSON.parse(fs.readFileSync('$DONE_FIXTURE', 'utf8'));
|
|
2739
|
+
obj.status = 'pemding';
|
|
2740
|
+
fs.writeFileSync('$cvd_scratch/typo-status.json', JSON.stringify(obj));
|
|
2741
|
+
process.stdout.write(M.classifyDraw(JSON.parse(fs.readFileSync('$cvd_scratch/typo-status.json', 'utf8'))).kind);
|
|
2742
|
+
")" "malformed"
|
|
2743
|
+
check "...the fixture itself was never touched -- classifyDraw on the original is still 'done'" \
|
|
2744
|
+
"$(cvj "const fs = await import('node:fs'); process.stdout.write(M.classifyDraw(JSON.parse(fs.readFileSync('$DONE_FIXTURE', 'utf8'))).kind);")" "done"
|
|
2745
|
+
rm -rf "$cvd_scratch"
|
|
2746
|
+
|
|
2747
|
+
# --- fillArm: draw policy (point 4, second half; point 5 at the arm level) -----------------------
|
|
2748
|
+
# seq[i] is the state sequence one draw handle steps through on successive retry()s; a fresh
|
|
2749
|
+
# newDraw() call advances to the next slot's sequence -- a REPLACEMENT, never a revisit.
|
|
2750
|
+
CVD_HELPERS='
|
|
2751
|
+
function mkSeqDraw(seq) {
|
|
2752
|
+
let i = 0;
|
|
2753
|
+
return () => {
|
|
2754
|
+
const states = seq[i++]; let idx = 0;
|
|
2755
|
+
return { read: () => states[idx], retry: () => { idx = Math.min(idx + 1, states.length - 1); } };
|
|
2756
|
+
};
|
|
2757
|
+
}
|
|
2758
|
+
'
|
|
2759
|
+
check "fillArm: a running draw is waited on and RE-READ from the SAME handle (retry), never replaced" \
|
|
2760
|
+
"$(cvj "$CVD_HELPERS
|
|
2761
|
+
const r = M.fillArm(mkSeqDraw([[{status:'running'}, {status:'done', pass:3}]]), { n: 1, report: () => {} });
|
|
2762
|
+
process.stdout.write(JSON.stringify({ arm: r.arm, stillRunning: r.stillRunning, replaced: r.replaced }));
|
|
2763
|
+
")" '{"arm":[3],"stillRunning":1,"replaced":0}'
|
|
2764
|
+
check "fillArm: a malformed draw is discarded and REPLACED with a fresh handle, reported loudly" \
|
|
2765
|
+
"$(cvj "$CVD_HELPERS
|
|
2766
|
+
let reports = 0;
|
|
2767
|
+
const r = M.fillArm(mkSeqDraw([[{status:'bogus'}], [{status:'done', pass:2}]]), { n: 1, report: () => { reports++; } });
|
|
2768
|
+
process.stdout.write(JSON.stringify({ arm: r.arm, replaced: r.replaced, reports }));
|
|
2769
|
+
")" '{"arm":[2],"replaced":1,"reports":1}'
|
|
2770
|
+
check "fillArm: exhausting the wait budget STOPS filling -- the slot is left unfilled, not topped up (F-194)" \
|
|
2771
|
+
"$(cvj "$CVD_HELPERS
|
|
2772
|
+
const seq = [[{status:'running'}, {status:'running'}, {status:'running'}], [{status:'done', pass:1}]];
|
|
2773
|
+
const r = M.fillArm(mkSeqDraw(seq), { n: 2, maxWaitAttempts: 1, report: () => {} });
|
|
2774
|
+
process.stdout.write(JSON.stringify({ breach: r.breach, arm: r.arm, waitExhausted: r.waitExhausted }));
|
|
2775
|
+
")" '{"breach":false,"arm":[],"waitExhausted":true}'
|
|
2776
|
+
check "fillArm: a breach fails the WHOLE arm outright, even after usable draws were already collected" \
|
|
2777
|
+
"$(cvj "$CVD_HELPERS
|
|
2778
|
+
const seq = [[{status:'done', pass:1}], [{status:'max-passes-exceeded', pass:6}]];
|
|
2779
|
+
const r = M.fillArm(mkSeqDraw(seq), { n: 2, report: () => {} });
|
|
2780
|
+
process.stdout.write(JSON.stringify({ breach: r.breach, arm: r.arm }));
|
|
2781
|
+
")" '{"breach":true,"arm":[1]}'
|
|
2782
|
+
|
|
2783
|
+
# --- fillArm()'s breach branch threads the SPECIFIC cap-breach
|
|
2784
|
+
# reason, not just the boolean above -- before this change, all five CAP_BREACH_STATUSES read
|
|
2785
|
+
# identically as {breach:true}, undiagnosable downstream. The literal acceptance
|
|
2786
|
+
# wording, restated as its own named check: a stubbed loop-state carrying the documented
|
|
2787
|
+
# stopped-<reason> finish form surfaces the BARE reason on fillArm()'s return.
|
|
2788
|
+
check "fillArm: breachReason is threaded through on a breach -- stopped-max-passes-exceeded surfaces as the bare 'max-passes-exceeded' (D6, phase file's own acceptance wording)" \
|
|
2789
|
+
"$(cvj "$CVD_HELPERS
|
|
2790
|
+
const r = M.fillArm(mkSeqDraw([[{status:'stopped-max-passes-exceeded', pass:6}]]), { n: 1, report: () => {} });
|
|
2791
|
+
process.stdout.write(String(r.breachReason));
|
|
2792
|
+
")" "max-passes-exceeded"
|
|
2793
|
+
check "fillArm: same, for diff-cap-exceeded (the phase file's second named example)" \
|
|
2794
|
+
"$(cvj "$CVD_HELPERS
|
|
2795
|
+
const r = M.fillArm(mkSeqDraw([[{status:'stopped-diff-cap-exceeded', pass:2}]]), { n: 1, report: () => {} });
|
|
2796
|
+
process.stdout.write(String(r.breachReason));
|
|
2797
|
+
")" "diff-cap-exceeded"
|
|
2798
|
+
# All five, not just the two named by example (the gap that kept being found) -- both the bare and the documented stopped-<reason> form, driven end-to-end
|
|
2799
|
+
# through fillArm() itself, not just the lib extractor tested above. Reuses BREACH_STATUSES,
|
|
2800
|
+
# derived earlier from the module's own CAP_BREACH_STATUSES.
|
|
2801
|
+
for s in "${BREACH_STATUSES[@]}"; do
|
|
2802
|
+
check "fillArm: breachReason is '$s' on a bare '$s' breach status" \
|
|
2803
|
+
"$(cvj "$CVD_HELPERS
|
|
2804
|
+
const r = M.fillArm(mkSeqDraw([[{status:'$s', pass:9}]]), { n: 1, report: () => {} });
|
|
2805
|
+
process.stdout.write(String(r.breachReason));
|
|
2806
|
+
")" "$s"
|
|
2807
|
+
check "fillArm: breachReason is the bare '$s' on a stopped-$s breach status (F-235 finish form)" \
|
|
2808
|
+
"$(cvj "$CVD_HELPERS
|
|
2809
|
+
const r = M.fillArm(mkSeqDraw([[{status:'stopped-$s', pass:9}]]), { n: 1, report: () => {} });
|
|
2810
|
+
process.stdout.write(String(r.breachReason));
|
|
2811
|
+
")" "$s"
|
|
2812
|
+
done
|
|
2813
|
+
# Additive field, always present (same "absent vs null vs present" convention run.verdict/
|
|
2814
|
+
# run.terminal/fixture already established) -- breachReason reads null, not absent/undefined, on
|
|
2815
|
+
# every NON-breach terminal path, so a caller never needs an `in` check before reading it.
|
|
2816
|
+
check "fillArm: breachReason is null (not absent/undefined) on the wait-exhausted path -- additive field, always present" \
|
|
2817
|
+
"$(cvj "$CVD_HELPERS
|
|
2818
|
+
const seq = [[{status:'running'}, {status:'running'}], [{status:'done', pass:1}]];
|
|
2819
|
+
const r = M.fillArm(mkSeqDraw(seq), { n: 2, maxWaitAttempts: 1, report: () => {} });
|
|
2820
|
+
process.stdout.write(JSON.stringify({ has: 'breachReason' in r, value: r.breachReason }));
|
|
2821
|
+
")" '{"has":true,"value":null}'
|
|
2822
|
+
check "fillArm: breachReason is null on a clean, fully-filled successful arm" \
|
|
2823
|
+
"$(cvj "$CVD_HELPERS
|
|
2824
|
+
const r = M.fillArm(mkSeqDraw([[{status:'done', pass:2}]]), { n: 1, report: () => {} });
|
|
2825
|
+
process.stdout.write(JSON.stringify({ has: 'breachReason' in r, value: r.breachReason }));
|
|
2826
|
+
")" '{"has":true,"value":null}'
|
|
2827
|
+
# --- Ordering: this handle's read() THROWS if ever called again after cleanup() -- if a future
|
|
2828
|
+
# edit recomputed breachReason from a fresh draw.read() post-cleanup instead of the already-in-
|
|
2829
|
+
# memory `state` local, THIS check fails loudly (an uncaught throw corrupts cvj's captured stdout,
|
|
2830
|
+
# which then fails to match), not silently. Detects exactly ONE failure mode -- a fresh read()
|
|
2831
|
+
# issued after cleanup() -- not a reorder that still uses the cached `state` local with no read()
|
|
2832
|
+
# call at all; nothing in fillArm() itself makes that second reorder impossible (the prior name here claimed "by construction", a guarantee the mechanism doesn't
|
|
2833
|
+
# deliver). Mutant F below stages that exact reorder against a REAL startDraw()-shaped handle and
|
|
2834
|
+
# is the strongest available check for it short of a refactor.
|
|
2835
|
+
check "fillArm: breachReason is derived from the ALREADY-READ state, never a fresh read() issued after cleanup() -- the reason is never read from a spent handle: a post-cleanup read() throws" \
|
|
2836
|
+
"$(cvj "
|
|
2837
|
+
function mkOrderedBreachDraw(status) {
|
|
2838
|
+
let cleaned = false;
|
|
2839
|
+
const state = { status, pass: 4 };
|
|
2840
|
+
return () => ({
|
|
2841
|
+
read: () => { if (cleaned) throw new Error('read() called after cleanup() -- ordering violated'); return state; },
|
|
2842
|
+
retry: () => {},
|
|
2843
|
+
cleanup: () => { cleaned = true; },
|
|
2844
|
+
});
|
|
2845
|
+
}
|
|
2846
|
+
const r = M.fillArm(mkOrderedBreachDraw('circuit-breaker'), { n: 1, report: () => {} });
|
|
2847
|
+
process.stdout.write(String(r.breachReason));
|
|
2848
|
+
")" "circuit-breaker"
|
|
2849
|
+
|
|
2850
|
+
# 3.3c: startDraw() is the FIRST real cleanup() a draw handle ever carries (mkSeqDraw above has
|
|
2851
|
+
# none, so safeCleanup()'s `draw.cleanup?.()` was a silent no-op in every fillArm test above --
|
|
2852
|
+
# none of them could have caught a recurrence). This is the seam that matters now that a real,
|
|
2853
|
+
# disk-touching cleanup exists to actually leave uncalled: 1.7 MB / 187 files per draw, ~51 MB per
|
|
2854
|
+
# certification. Verified on all four terminal paths a single draw
|
|
2855
|
+
# can end on, not just the two (done/malformed) the existing reports/replaced assertions above
|
|
2856
|
+
# already exercise indirectly.
|
|
2857
|
+
CVD_HELPERS_CLEANUP='
|
|
2858
|
+
function mkTrackedDraw(seq) {
|
|
2859
|
+
let i = 0; const calls = [];
|
|
2860
|
+
const next = () => {
|
|
2861
|
+
const states = seq[i]; let idx = 0; const mine = i; i++;
|
|
2862
|
+
return { read: () => states[idx], retry: () => { idx = Math.min(idx + 1, states.length - 1); }, cleanup: () => calls.push(mine) };
|
|
2863
|
+
};
|
|
2864
|
+
next.calls = calls;
|
|
2865
|
+
return next;
|
|
2866
|
+
}
|
|
2867
|
+
'
|
|
2868
|
+
check "fillArm calls the draw handle's cleanup() on EVERY terminal path -- breach/done/malformed/wait-exhausted, not just the two the arm-content assertions above already imply (F-226, closed against a REAL cleanup() for the first time now that startDraw provides one)" \
|
|
2869
|
+
"$(cvj "$CVD_HELPERS_CLEANUP
|
|
2870
|
+
const breachDraw = mkTrackedDraw([[{status:'max-passes-exceeded', pass:6}]]);
|
|
2871
|
+
M.fillArm(breachDraw, { n: 1, report: () => {} });
|
|
2872
|
+
const doneDraw = mkTrackedDraw([[{status:'done', pass:2}]]);
|
|
2873
|
+
M.fillArm(doneDraw, { n: 1, report: () => {} });
|
|
2874
|
+
const malformedDraw = mkTrackedDraw([[{status:'bogus'}], [{status:'done', pass:2}]]);
|
|
2875
|
+
M.fillArm(malformedDraw, { n: 1, report: () => {} });
|
|
2876
|
+
const waitExhaustedDraw = mkTrackedDraw([[{status:'running'}, {status:'running'}]]);
|
|
2877
|
+
M.fillArm(waitExhaustedDraw, { n: 1, maxWaitAttempts: 1, report: () => {} });
|
|
2878
|
+
process.stdout.write(JSON.stringify({
|
|
2879
|
+
breach: breachDraw.calls.length, done: doneDraw.calls.length,
|
|
2880
|
+
malformed: malformedDraw.calls.length, waitExhausted: waitExhaustedDraw.calls.length,
|
|
2881
|
+
}));
|
|
2882
|
+
")" '{"breach":1,"done":1,"malformed":2,"waitExhausted":1}'
|
|
2883
|
+
|
|
2884
|
+
# --- point 3: a cap-breach fails the WHOLE comparison outright, independent of the p-value -------
|
|
2885
|
+
check "runComparison: a breach in the CANDIDATE arm fails outright, regardless of the baseline's own values" \
|
|
2886
|
+
"$(cvj "$CVD_HELPERS
|
|
2887
|
+
const bl = [[{status:'done',pass:1}],[{status:'done',pass:1}],[{status:'done',pass:1}]];
|
|
2888
|
+
const cd = [[{status:'done',pass:1}],[{status:'max-passes-exceeded',pass:6}]];
|
|
2889
|
+
const r = M.runComparison(mkSeqDraw(bl), mkSeqDraw(cd), { n: 3, report: () => {} });
|
|
2890
|
+
process.stdout.write(JSON.stringify({ verdict: r.verdict, breachArm: r.breachArm }));
|
|
2891
|
+
")" '{"verdict":"cap-breach","breachArm":"candidate"}'
|
|
2892
|
+
check "runComparison: a breach in the BASELINE arm fails outright -- the candidate is never even drawn" \
|
|
2893
|
+
"$(cvj "$CVD_HELPERS
|
|
2894
|
+
let candidateDrawn = false;
|
|
2895
|
+
const newCandidate = () => { candidateDrawn = true; return mkSeqDraw([[{status:'done',pass:1}]])(); };
|
|
2896
|
+
const r = M.runComparison(mkSeqDraw([[{status:'max-passes-exceeded',pass:6}]]), newCandidate, { n: 1, report: () => {} });
|
|
2897
|
+
process.stdout.write(JSON.stringify({ verdict: r.verdict, breachArm: r.breachArm, candidateDrawn }));
|
|
2898
|
+
")" '{"verdict":"cap-breach","breachArm":"baseline","candidateDrawn":false}'
|
|
2899
|
+
check "runComparison: insufficient-draws (point 4) on a realized shortfall, measured on the actual array, not the requested count" \
|
|
2900
|
+
"$(cvj "$CVD_HELPERS
|
|
2901
|
+
const bl = [[{status:'running'},{status:'running'},{status:'running'}]];
|
|
2902
|
+
const cd = [[{status:'done',pass:2}],[{status:'done',pass:2}]];
|
|
2903
|
+
const r = M.runComparison(mkSeqDraw(bl), mkSeqDraw(cd), { n: 2, maxWaitAttempts: 1, report: () => {} });
|
|
2904
|
+
process.stdout.write(JSON.stringify({ verdict: r.verdict, deficit: r.deficit }));
|
|
2905
|
+
")" '{"verdict":"insufficient-draws","deficit":{"baseline":2,"candidate":0}}'
|
|
2906
|
+
# --- point 6: every OTHER check in this suite bounds a
|
|
2907
|
+
# false ACCEPT; none bounded a false BLOCK. A one-line mutant (`verdict = 'inconclusive'` always)
|
|
2908
|
+
# passed points 1/2/4/5 AND the old membership assertion below, improving point 2 to 0.0000. Two
|
|
2909
|
+
# assertions close it -- the first is this rewritten check itself.
|
|
2910
|
+
# margin change (REGRESSION_SHIFT 1 -> 0.5): checked, not assumed -- this arm is TWO constant arms (every
|
|
2911
|
+
# draw pass:2), so `shifted` is also constant, strictly less than `baseline` for ANY positive
|
|
2912
|
+
# shift; the tie-conditional rank test only sees a fully-separated ordering, which is identical at
|
|
2913
|
+
# shift=0.5 and shift=1 (verified directly: equivalence.p is bit-identical, 0.0002, at both). This
|
|
2914
|
+
# check is margin-INVARIANT by construction, not because it happens to still pass -- left as-is.
|
|
2915
|
+
check "point 6 (1/2) -- a healthy, well-filled comparison returns no-regression ITSELF, not merely membership in the verdict set (F-221: the old '['regression','no-regression','inconclusive'].includes(verdict)' assertion was true of every value compareArms() can return, including a gate that never accepts)" \
|
|
2916
|
+
"$(cvj "$CVD_HELPERS
|
|
2917
|
+
const arm = Array.from({length:15}, () => [{status:'done',pass:2}]);
|
|
2918
|
+
const r = M.runComparison(mkSeqDraw(arm.slice()), mkSeqDraw(arm.slice()), { resamples: 5000, report: () => {} });
|
|
2919
|
+
process.stdout.write(r.verdict);
|
|
2920
|
+
")" "no-regression"
|
|
2921
|
+
|
|
2922
|
+
# --- the power statement and the top-level censoring
|
|
2923
|
+
# counts, both an observability deliverable and an exit criterion.
|
|
2924
|
+
check "runComparison's healthy-input result carries a LIVE power estimate in [0,1] (computed from THIS run's own realized arms, not a static 71.6% citation)" \
|
|
2925
|
+
"$(cvj "$CVD_HELPERS
|
|
2926
|
+
const arm = Array.from({length:15}, () => [{status:'done',pass:2}]);
|
|
2927
|
+
const r = M.runComparison(mkSeqDraw(arm.slice()), mkSeqDraw(arm.slice()), { resamples: 5000, report: () => {}, powerTrials: 30, powerResamples: 500 });
|
|
2928
|
+
process.stdout.write(String(typeof r.power === 'number' && r.power >= 0 && r.power <= 1));
|
|
2929
|
+
")" "true"
|
|
2930
|
+
check "compareArms() does NOT compute power unless asked -- opt-in, so it never nests inside its own estimatePower() trial loop or points 1/2's T=600 mass-simulation loops below" \
|
|
2931
|
+
"$(cvj "
|
|
2932
|
+
const arm = Array.from({length:15}, () => 2);
|
|
2933
|
+
const r = M.compareArms(arm, arm, { resamples: 2000 });
|
|
2934
|
+
process.stdout.write(String('power' in r && r.power === undefined));
|
|
2935
|
+
")" "true"
|
|
2936
|
+
check "runComparison surfaces stillRunning/replaced at the TOP level on the SUCCESS path too (F-223, point 4's 'censoring stays visible even when the floor is satisfied' -- unmet on this path before)" \
|
|
2937
|
+
"$(cvj "$CVD_HELPERS
|
|
2938
|
+
const censored = [[{status:'running'}, {status:'done', pass:2}]];
|
|
2939
|
+
const plain = Array.from({length:14}, () => [{status:'done',pass:2}]);
|
|
2940
|
+
const r = M.runComparison(mkSeqDraw([...censored, ...plain]), mkSeqDraw(Array.from({length:15}, () => [{status:'done',pass:2}])), { resamples: 5000, report: () => {} });
|
|
2941
|
+
process.stdout.write(JSON.stringify({ stillRunning: r.stillRunning, replaced: r.replaced }));
|
|
2942
|
+
")" '{"stillRunning":{"baseline":1,"candidate":0},"replaced":{"baseline":0,"candidate":0}}'
|
|
2943
|
+
|
|
2944
|
+
# --- convergence shards get their OWN namespace, OWN
|
|
2945
|
+
# schema, decoupled from run.mjs's SCHEMA_VERSION -- verified by execution, not merely by reading
|
|
2946
|
+
# the source, that the split actually removes the collision (the namespace-split option; see
|
|
2947
|
+
# convergence.mjs's own comment above LOOP_SCHEMA_VERSION for the "was schema:1 deliberate?"
|
|
2948
|
+
# answer: no, and it now is).
|
|
2949
|
+
check "convergence shards land under shardDir(sha)/convergence/ -- run.mjs's REAL mergeShards() (not a mimic of its listing) never sees them (F-249)" \
|
|
2950
|
+
"$(cvj "
|
|
2951
|
+
const fs = await import('node:fs'); const path = await import('node:path');
|
|
2952
|
+
const runMod = await import('$ROOT/tests/evals/run.mjs');
|
|
2953
|
+
const sha = 'f225ns' + Date.now();
|
|
2954
|
+
const p = M.loopShardPath(sha, M.TASK_ID, 0);
|
|
2955
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
2956
|
+
fs.writeFileSync(p, JSON.stringify({ sha, taskId: M.TASK_ID, schema: M.LOOP_SCHEMA_VERSION, run: { index: 0, pass: 2 } }));
|
|
2957
|
+
const dir = runMod.shardDir(sha);
|
|
2958
|
+
const merged = runMod.mergeShards(sha, { runs: 3 });
|
|
2959
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
2960
|
+
process.stdout.write(JSON.stringify([Object.keys(merged.tasks).length, merged.skippedShards.length]));
|
|
2961
|
+
")" "[0,0]"
|
|
2962
|
+
# --- resumeArm's nextIndex targets the first genuinely MISSING slot, not
|
|
2963
|
+
# done.length -- shards {0,2} present must never overwrite shard 2 or leave 1 unwritten forever.
|
|
2964
|
+
check "resumeArm: shards {0,2} present -- resume holds both, nextIndex fills the GAP at 1, never targets 2 (F-230)" \
|
|
2965
|
+
"$(cvj "
|
|
2966
|
+
const fs = await import('node:fs'); const path = await import('node:path');
|
|
2967
|
+
const sha = 'f230gap' + Date.now();
|
|
2968
|
+
for (const i of [0, 2]) {
|
|
2969
|
+
const p = M.loopShardPath(sha, M.TASK_ID, i);
|
|
2970
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
2971
|
+
fs.writeFileSync(p, JSON.stringify({ sha, taskId: M.TASK_ID, schema: M.LOOP_SCHEMA_VERSION, run: { index: i, pass: i + 10 } }));
|
|
2972
|
+
}
|
|
2973
|
+
const r = M.resumeArm(sha, M.TASK_ID, 3);
|
|
2974
|
+
fs.rmSync(path.dirname(path.dirname(M.loopShardPath(sha, M.TASK_ID, 0))), { recursive: true, force: true });
|
|
2975
|
+
process.stdout.write(JSON.stringify({ resume: r.resume, nextIndex: r.nextIndex, occupied: [...r.occupied].sort((a,b)=>a-b) }));
|
|
2976
|
+
")" '{"resume":[10,12],"nextIndex":1,"occupied":[0,2]}'
|
|
2977
|
+
# A corrupted shard (killed process mid-write) must not crash the read, must not silently push
|
|
2978
|
+
# garbage into an arm, and must not have its slot immediately overwritten either -- readShard's
|
|
2979
|
+
# own discipline of refusing a stale-schema shard, applied to THIS module's namespace, the third caller
|
|
2980
|
+
# that had been skipping it.
|
|
2981
|
+
check "resumeArm: a corrupted shard is treated as absent from resume, without crashing, and its slot stays occupied (not silently overwritten) (F-225)" \
|
|
2982
|
+
"$(cvj "
|
|
2983
|
+
const fs = await import('node:fs'); const path = await import('node:path');
|
|
2984
|
+
const sha = 'f225corrupt' + Date.now();
|
|
2985
|
+
const p = M.loopShardPath(sha, M.TASK_ID, 0);
|
|
2986
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
2987
|
+
fs.writeFileSync(p, 'not json');
|
|
2988
|
+
const r = M.resumeArm(sha, M.TASK_ID, 1);
|
|
2989
|
+
fs.rmSync(path.dirname(path.dirname(p)), { recursive: true, force: true });
|
|
2990
|
+
process.stdout.write(JSON.stringify({ resume: r.resume, nextIndex: r.nextIndex, occupied: [...r.occupied] }));
|
|
2991
|
+
")" '{"resume":[],"nextIndex":1,"occupied":[0]}'
|
|
2992
|
+
# resumeArm's occupied set means nothing if the CONSUMER re-collides
|
|
2993
|
+
# with it -- writeNextShard is drawArmForSha's onDraw, exercised directly (no live draw, no quota).
|
|
2994
|
+
check "writeNextShard: n=5, shards {0,2} occupied, three sequential draws land exactly on the GAPS -- {1,3,4}, never re-touching 2 (F-248)" \
|
|
2995
|
+
"$(cvj "
|
|
2996
|
+
const fs = await import('node:fs'); const path = await import('node:path'); const sha = 'f248gap' + Date.now(); const occ = new Set([0, 2]); let i = 1; const w = []; for (let k = 0; k < 3; k++) { i = M.writeNextShard(sha, M.TASK_ID, 5, occ, i, 7) + 1; w.push(i - 1); } const onDisk = fs.readdirSync(path.dirname(M.loopShardPath(sha, M.TASK_ID, 0))).filter(f => f.endsWith('.json')).map(f => Number(f.match(/-(\d+)\.json\$/)[1])).sort((a,b)=>a-b); fs.rmSync(path.dirname(path.dirname(M.loopShardPath(sha, M.TASK_ID, 0))), { recursive: true, force: true }); process.stdout.write(JSON.stringify([w, onDisk]));
|
|
2997
|
+
")" "[[1,3,4],[1,3,4]]"
|
|
2998
|
+
check "writeNextShard: n=5, a corrupted-but-occupied shard 0 plus 1,2 valid -- the slot at n=5 throws instead of writing out of range where loopCompletedIndices() could never find it again (F-248)" \
|
|
2999
|
+
"$(cvj "
|
|
3000
|
+
const fs = await import('node:fs'); const path = await import('node:path'); const sha = 'f248oob' + Date.now(); const occ = new Set([0, 1, 2]); let i = 3; i = M.writeNextShard(sha, M.TASK_ID, 5, occ, i, 7) + 1; i = M.writeNextShard(sha, M.TASK_ID, 5, occ, i, 7) + 1; let threw = false; try { M.writeNextShard(sha, M.TASK_ID, 5, occ, i, 7); } catch (e) { threw = /no free shard slot/.test(e.message); } const onDisk = fs.readdirSync(path.dirname(M.loopShardPath(sha, M.TASK_ID, 0))).filter(f => f.endsWith('.json')).length; fs.rmSync(path.dirname(path.dirname(M.loopShardPath(sha, M.TASK_ID, 0))), { recursive: true, force: true }); process.stdout.write(JSON.stringify([threw, onDisk]));
|
|
3001
|
+
")" "[true,2]"
|
|
3002
|
+
|
|
3003
|
+
# --- writeBreachRecord/breachRecordPath: persists fillArm()'s
|
|
3004
|
+
# breachReason alongside the fixture-namespaced shard directory, generalizing writeCensorRecord's
|
|
3005
|
+
# existing per-fixture convention -- exercised directly (no live draw, no quota), same idiom as
|
|
3006
|
+
# writeNextShard's own tests just above.
|
|
3007
|
+
check "breachRecordPath: a real fixtureId lands INSIDE that fixture's own shard directory, as a breach/ sibling to the numbered shards (not the flat legacy bucket)" \
|
|
3008
|
+
"$(cvj "
|
|
3009
|
+
const path = await import('node:path');
|
|
3010
|
+
const sha = 'd6ns' + Date.now();
|
|
3011
|
+
const bp = M.breachRecordPath(sha, M.TASK_ID, 0, 'fixtureA');
|
|
3012
|
+
const shardDirForFixtureA = path.dirname(M.loopShardPath(sha, M.TASK_ID, 0, 'fixtureA'));
|
|
3013
|
+
process.stdout.write(JSON.stringify({ underShardDir: path.dirname(bp) === path.join(shardDirForFixtureA, 'breach'), basename: path.basename(bp) }));
|
|
3014
|
+
")" '{"underShardDir":true,"basename":"loop-code-loop-000.json"}'
|
|
3015
|
+
check "writeBreachRecord: fixtureId='fixA' writes under fixA's own namespace, as a breach/ sibling to the numbered shards -- what THIS proves is the write side lands in the right place; no read path exists yet to close the F-284/F-285 write-moved/read-didn't class against (F-44 -- the class stays deferred, not closed, until phases/04 reads a breach record). Cleanup anchored on run.mjs's OWN shardDir(sha) (F-225's precedent below), not hand-counted dirname() calls -- a hand-counted depth is exactly the kind of arithmetic that is easy to get wrong without leaving evidence (verified against this test's own first draft, which did)." \
|
|
3016
|
+
"$(cvj "
|
|
3017
|
+
const fs = await import('node:fs');
|
|
3018
|
+
const runMod = await import('$ROOT/tests/evals/run.mjs');
|
|
3019
|
+
const sha = 'd6iso' + Date.now();
|
|
3020
|
+
M.writeBreachRecord(sha, M.TASK_ID, 'max-passes-exceeded', 'fixA');
|
|
3021
|
+
const fixAHasIt = fs.existsSync(M.breachRecordPath(sha, M.TASK_ID, 0, 'fixA'));
|
|
3022
|
+
fs.rmSync(runMod.shardDir(sha), { recursive: true, force: true });
|
|
3023
|
+
process.stdout.write(JSON.stringify({ fixAHasIt }));
|
|
3024
|
+
")" '{"fixAHasIt":true}'
|
|
3025
|
+
check "writeBreachRecord: two DIFFERENT fixtures under the SAME sha never collide -- independent seq counters, each starting at 0" \
|
|
3026
|
+
"$(cvj "
|
|
3027
|
+
const fs = await import('node:fs');
|
|
3028
|
+
const runMod = await import('$ROOT/tests/evals/run.mjs');
|
|
3029
|
+
const sha = 'd6two' + Date.now();
|
|
3030
|
+
const seqA = M.writeBreachRecord(sha, M.TASK_ID, 'diff-cap-exceeded', 'fixA');
|
|
3031
|
+
const seqB = M.writeBreachRecord(sha, M.TASK_ID, 'scope-expansion', 'fixB');
|
|
3032
|
+
const contentA = JSON.parse(fs.readFileSync(M.breachRecordPath(sha, M.TASK_ID, 0, 'fixA'), 'utf8'));
|
|
3033
|
+
const contentB = JSON.parse(fs.readFileSync(M.breachRecordPath(sha, M.TASK_ID, 0, 'fixB'), 'utf8'));
|
|
3034
|
+
fs.rmSync(runMod.shardDir(sha), { recursive: true, force: true });
|
|
3035
|
+
process.stdout.write(JSON.stringify({ seqA, seqB, reasonA: contentA.breachReason, reasonB: contentB.breachReason, fixtureA: contentA.fixture, fixtureB: contentB.fixture }));
|
|
3036
|
+
")" '{"seqA":0,"seqB":0,"reasonA":"diff-cap-exceeded","reasonB":"scope-expansion","fixtureA":"fixA","fixtureB":"fixB"}'
|
|
3037
|
+
check "writeBreachRecord: self-healing first-free-slot write, same idiom as writeCensorRecord/writeNextShard -- a second call to the SAME fixture advances to seq 1, never overwrites seq 0" \
|
|
3038
|
+
"$(cvj "
|
|
3039
|
+
const fs = await import('node:fs');
|
|
3040
|
+
const runMod = await import('$ROOT/tests/evals/run.mjs');
|
|
3041
|
+
const sha = 'd6seq' + Date.now();
|
|
3042
|
+
const seq0 = M.writeBreachRecord(sha, M.TASK_ID, 'circuit-breaker', 'fixA');
|
|
3043
|
+
const seq1 = M.writeBreachRecord(sha, M.TASK_ID, 'user-stop', 'fixA');
|
|
3044
|
+
const first = JSON.parse(fs.readFileSync(M.breachRecordPath(sha, M.TASK_ID, 0, 'fixA'), 'utf8'));
|
|
3045
|
+
fs.rmSync(runMod.shardDir(sha), { recursive: true, force: true });
|
|
3046
|
+
process.stdout.write(JSON.stringify({ seq0, seq1, firstUntouched: first.breachReason === 'circuit-breaker' }));
|
|
3047
|
+
")" '{"seq0":0,"seq1":1,"firstUntouched":true}'
|
|
3048
|
+
# unlike writeNextShard()/writeCensorRecord(), breach records are NEW
|
|
3049
|
+
# -- there is no legacy fixture-less data sitting in a flat bucket for a defaulted
|
|
3050
|
+
# fixtureId to stay compatible with, so an omitted/null fixtureId is never a legitimate "unknown
|
|
3051
|
+
# fixture" read here. The prior version of this check entrenched exactly the hazard a
|
|
3052
|
+
# review measured (a qualified write, an unqualified default-arg read, silently landing in a
|
|
3053
|
+
# DIFFERENT directory with no error) -- replaced with the throw that closes it: a loud TypeError
|
|
3054
|
+
# at the call site instead of a quiet empty read at whatever future reader queries the
|
|
3055
|
+
# wrong path.
|
|
3056
|
+
check "writeBreachRecord: fixtureId omitted throws -- no flat legacy bucket for breach records to fall back to (F-42)" \
|
|
3057
|
+
"$(cvj "
|
|
3058
|
+
let threw = false, isTypeError = false, mentionsFixtureId = false;
|
|
3059
|
+
try { M.writeBreachRecord('d6nofix' + Date.now(), M.TASK_ID, 'max-passes-exceeded'); }
|
|
3060
|
+
catch (e) { threw = true; isTypeError = e instanceof TypeError; mentionsFixtureId = /fixtureId/.test(e.message); }
|
|
3061
|
+
process.stdout.write(JSON.stringify({ threw, isTypeError, mentionsFixtureId }));
|
|
3062
|
+
")" '{"threw":true,"isTypeError":true,"mentionsFixtureId":true}'
|
|
3063
|
+
check "writeBreachRecord: fixtureId explicitly null (not merely omitted) throws the same way -- 'not a real fixture' has exactly one spelling here, not two" \
|
|
3064
|
+
"$(cvj "
|
|
3065
|
+
let threw = false;
|
|
3066
|
+
try { M.writeBreachRecord('d6nofix2' + Date.now(), M.TASK_ID, 'max-passes-exceeded', null); }
|
|
3067
|
+
catch (e) { threw = e instanceof TypeError; }
|
|
3068
|
+
process.stdout.write(String(threw));
|
|
3069
|
+
")" "true"
|
|
3070
|
+
check "breachRecordPath: fixtureId omitted throws too -- same guard, reachable directly, not only through writeBreachRecord's own call into it" \
|
|
3071
|
+
"$(cvj "
|
|
3072
|
+
let threw = false;
|
|
3073
|
+
try { M.breachRecordPath('d6nofix3' + Date.now(), M.TASK_ID, 0); } catch (e) { threw = e instanceof TypeError; }
|
|
3074
|
+
process.stdout.write(String(threw));
|
|
3075
|
+
")" "true"
|
|
3076
|
+
|
|
3077
|
+
# the fillArm() -> writeBreachRecord() ASSEMBLY drawArmForSha() uses,
|
|
3078
|
+
# driven for real through fillArm() with a synthetic (non-live) draw handle -- no /code-loop
|
|
3079
|
+
# invocation, no quota spent. Mirrors convergence-runner.sh:461-476's identical censor-assembly
|
|
3080
|
+
# precedent (and the other "the exact assembly drawArmForSha() uses" wiring tests) -- the
|
|
3081
|
+
# precedent a review found was checkably wrong to cite as untestable:
|
|
3082
|
+
# that precedent tests exactly this shape of composition, hermetically, so this does too, threading
|
|
3083
|
+
# the REAL r.breachReason (not a literal) into the REAL writer at the REAL namespace.
|
|
3084
|
+
check "the exact assembly drawArmForSha() uses (fillArm's breach return + writeBreachRecord) persists a breached draw's specific reason, without a live draw (F-43)" \
|
|
3085
|
+
"$(cvj "$CVD_HELPERS
|
|
3086
|
+
const fs = await import('node:fs');
|
|
3087
|
+
const runMod = await import('$ROOT/tests/evals/run.mjs');
|
|
3088
|
+
const sha = 'd6wiring' + Date.now();
|
|
3089
|
+
const r = M.fillArm(mkSeqDraw([[{status:'stopped-diff-cap-exceeded', pass:6}]]), { n: 1, report: () => {} });
|
|
3090
|
+
const seq = r.breach ? M.writeBreachRecord(sha, M.TASK_ID, r.breachReason, 'fixW') : null;
|
|
3091
|
+
const rec = seq === null ? null : JSON.parse(fs.readFileSync(M.breachRecordPath(sha, M.TASK_ID, seq, 'fixW'), 'utf8'));
|
|
3092
|
+
fs.rmSync(runMod.shardDir(sha), { recursive: true, force: true });
|
|
3093
|
+
process.stdout.write(JSON.stringify({ breach: r.breach, persistedReason: rec ? rec.breachReason : null }));
|
|
3094
|
+
")" '{"breach":true,"persistedReason":"diff-cap-exceeded"}'
|
|
3095
|
+
|
|
3096
|
+
# --- prepareDrawDir() is startDraw()'s setup ONLY
|
|
3097
|
+
# (no invocation), the injection seam neither disclosed deviation had coverage through before this
|
|
3098
|
+
# -- the seam that would have caught the missing scripts/ copy by evidence, not by reasoning.
|
|
3099
|
+
check "prepareDrawDir: workDir contains scripts/somi-loop.mjs and .claude/commands/, zero model calls (F-227)" \
|
|
3100
|
+
"$(cvj "
|
|
3101
|
+
const fs = await import('node:fs'); const path = await import('node:path');
|
|
3102
|
+
const work = M.prepareDrawDir('$ROOT', '$ROOT/tests/evals/fixtures/task02-code');
|
|
3103
|
+
const ok = fs.existsSync(path.join(work, 'scripts', 'somi-loop.mjs')) && fs.existsSync(path.join(work, '.claude', 'commands'));
|
|
3104
|
+
fs.rmSync(work, { recursive: true, force: true });
|
|
3105
|
+
process.stdout.write(String(ok));
|
|
3106
|
+
")" "true"
|
|
3107
|
+
check "prepareDrawDir: throws when scripts/ is missing at the source, named and immediate -- not silently skipped into six wasted model calls (F-228)" \
|
|
3108
|
+
"$(cvj "
|
|
3109
|
+
const fs = await import('node:fs'); const os = await import('node:os'); const path = await import('node:path');
|
|
3110
|
+
const emptySource = fs.mkdtempSync(path.join(os.tmpdir(), 'somi-eval-nosource-'));
|
|
3111
|
+
let threw = false;
|
|
3112
|
+
try { M.prepareDrawDir(emptySource, '$ROOT/tests/evals/fixtures/task02-code'); } catch (e) { threw = /scripts.*missing/.test(e.message); }
|
|
3113
|
+
fs.rmSync(emptySource, { recursive: true, force: true });
|
|
3114
|
+
process.stdout.write(String(threw));
|
|
3115
|
+
")" "true"
|
|
3116
|
+
|
|
3117
|
+
# --- drawArmForSha() preflights before any work, matching run.mjs's own precedent
|
|
3118
|
+
# (:150-165 above) -- simulated the same way, by stripping PATH/HOME so neither the CLI nor a
|
|
3119
|
+
# credential resolves, never by mocking preflight() itself.
|
|
3120
|
+
NODE_BIN=$(command -v node)
|
|
3121
|
+
cvd_preflight=$(env -i "PATH=$(dirname "$NODE_BIN")" HOME=/nonexistent "$NODE_BIN" --input-type=module -e "
|
|
3122
|
+
const M = await import('$ROOT/$CVD');
|
|
3123
|
+
try { M.drawArmForSha('$ROOT', '$ROOT/tests/evals/fixtures/task02-code', 'f229preflight', { n: 1 }); process.stdout.write('no-throw'); }
|
|
3124
|
+
catch (e) { process.stdout.write(e.message); }
|
|
3125
|
+
" 2>&1)
|
|
3126
|
+
case "$cvd_preflight" in
|
|
3127
|
+
*"not ready to draw"*) ok "drawArmForSha preflights the CLI and credential before spending any quota (F-229)" ;;
|
|
3128
|
+
*) bad "drawArmForSha preflights the CLI and credential before spending any quota (F-229) (got: ${cvd_preflight:0:80})" ;;
|
|
3129
|
+
esac
|
|
3130
|
+
|
|
3131
|
+
# --- Mutation testing: staged against a COPY of convergence.mjs, never the tracked
|
|
3132
|
+
# file, following the mann-whitney scratch-copy precedent -- one scratch dir, reset via `cp` between mutants.
|
|
3133
|
+
CVD_SCRATCH_DIR=$(mktemp -d) || { bad "mktemp failed"; exit 1; }
|
|
3134
|
+
CVD_SCRATCH="$CVD_SCRATCH_DIR/convergence.mjs"
|
|
3135
|
+
# `trap ... EXIT` REPLACES the handler, it does not
|
|
3136
|
+
# append -- registering `rm -rf "$CVD_SCRATCH_DIR"' alone here would silently drop :2380's
|
|
3137
|
+
# MW_SCRATCH_DIR cleanup (measured: baseline d9421b3's runner cleans it, this one did not, until
|
|
3138
|
+
# this line named both). Name every scratch dir the suite has created so far, not just this one.
|
|
3139
|
+
trap 'rm -rf "$MW_SCRATCH_DIR" "$CVD_SCRATCH_DIR"' EXIT
|
|
3140
|
+
# `trap -p EXIT` prints the REGISTERED command text verbatim (single-quoted at registration, so
|
|
3141
|
+
# the variable REFERENCES are still literal `$MW_SCRATCH_DIR`/`$CVD_SCRATCH_DIR` text, not their
|
|
3142
|
+
# expanded paths) -- pin on the variable names, which is what proves both are named in the SAME
|
|
3143
|
+
# trap command, not on their runtime values.
|
|
3144
|
+
check "F-222: the EXIT trap names BOTH scratch dirs (trap REPLACES, not appends -- a registration naming only its own dir silently drops every earlier one)" \
|
|
3145
|
+
"$(trap -p EXIT | grep -qF 'MW_SCRATCH_DIR' && trap -p EXIT | grep -qF 'CVD_SCRATCH_DIR' && echo true || echo false)" "true"
|
|
3146
|
+
# Symlinked, not copied: only convergence.mjs itself is ever mutated; its relative imports
|
|
3147
|
+
# (lib/, run.mjs) resolve straight through to the real, pristine files -- same isolation guarantee
|
|
3148
|
+
# as MW_SCRATCH's single-file copy, extended to a module with real sibling dependencies (3.3c adds
|
|
3149
|
+
# the top-level `import { shardDir } from './run.mjs'`, so the scratch copy needs run.mjs
|
|
3150
|
+
# resolvable too, not just lib/).
|
|
3151
|
+
ln -s "$ROOT/tests/evals/lib" "$CVD_SCRATCH_DIR/lib"
|
|
3152
|
+
ln -s "$ROOT/tests/evals/run.mjs" "$CVD_SCRATCH_DIR/run.mjs"
|
|
3153
|
+
cp "$ROOT/$CVD" "$CVD_SCRATCH"
|
|
3154
|
+
|
|
3155
|
+
# CVD_SIM: shared population/trial-loop preamble for points 1, 2 and 6, and for mutant D's second
|
|
3156
|
+
# check below (all draw from the tied historical MIXED-HISTORY histogram,
|
|
3157
|
+
# {1:9,2:4,3:5,4:2,5:1}, sd~1.24). Defined here, before the mutation section, since mutant D needs
|
|
3158
|
+
# it too.
|
|
3159
|
+
# TWO independent seeded streams, not one shared between arm
|
|
3160
|
+
# generation and the rank test's own resampling -- compareArms() short-circuits on p < alpha, so a
|
|
3161
|
+
# single shared stream let the number of rng() calls consumed per trial depend on that trial's own
|
|
3162
|
+
# outcome, and no single trial could be replayed in isolation. dataRng draws the synthetic arms;
|
|
3163
|
+
# testRng is the ONLY stream compareArms()/mannWhitneyU ever consumes.
|
|
3164
|
+
#
|
|
3165
|
+
# it was measured that this is NOT the population a real
|
|
3166
|
+
# /code-loop draws are shaped like -- the real baseline has sd 0.5164,
|
|
3167
|
+
# materially tighter than this histogram's ~1.24. Every target/floor computed under CVD_SIM below
|
|
3168
|
+
# is calibrated to THIS wider, tied-mixed-history population, and states how the verdict logic
|
|
3169
|
+
# behaves under HIGH VARIANCE -- a genuine, deliberately kept stress case -- not what the margin-gated
|
|
3170
|
+
# comparison the real gate runs actually accepts or rejects on real draws. Read a CVD_SIM
|
|
3171
|
+
# target/floor as "how the logic holds up under stress," never as a claim about the operative
|
|
3172
|
+
# gate's real accept rate; CVD_SIM_D13 below (bootstrapped from the real baseline) is what states
|
|
3173
|
+
# that instead.
|
|
3174
|
+
CVD_SIM='
|
|
3175
|
+
const MWmod = await import("'"$ROOT"'/tests/evals/lib/mann-whitney.mjs");
|
|
3176
|
+
const dataRng = MWmod.mulberry32(1234);
|
|
3177
|
+
const testRng = MWmod.mulberry32(5678);
|
|
3178
|
+
const weights = [[1,9],[2,4],[3,5],[4,2],[5,1]];
|
|
3179
|
+
const total = weights.reduce((s,[,w]) => s + w, 0);
|
|
3180
|
+
function drawOne() { let r = dataRng() * total; for (const [v,w] of weights) { if (r < w) return v; r -= w; } return weights.at(-1)[0]; }
|
|
3181
|
+
function drawArm(n) { return Array.from({ length: n }, drawOne); }
|
|
3182
|
+
const T = 600, RESAMPLES = 3000, N = 15;
|
|
3183
|
+
'
|
|
3184
|
+
|
|
3185
|
+
# CVD_SIM_D13: same shared preamble SHAPE as CVD_SIM (the two-independent-streams discipline),
|
|
3186
|
+
# but the population is bootstrap-resampled WITH REPLACEMENT from the real measured 15-draw
|
|
3187
|
+
# baseline arm ([2,1,2,1,2,1,1,2,1,1,2,2,2,1,2], mean 1.5333, sd 0.5164) instead
|
|
3188
|
+
# of the mixed-history histogram -- the population the margin-gated /code-loop comparison actually
|
|
3189
|
+
# draws from. `dataRng` draws the bootstrap sample (both baseline's and candidate's shared
|
|
3190
|
+
# draws, same convention as CVD_SIM's `drawArm`); `bumpRng` is a THIRD independent stream, used only
|
|
3191
|
+
# by the point-2 analogue further down, for the "gains a pass with probability 0.5" degradation
|
|
3192
|
+
# model the earlier resampling scripts used to report "+0.5 pass"
|
|
3193
|
+
# (the earlier resampling scripts) -- kept separate from `dataRng` for the same reason
|
|
3194
|
+
# the suite separates `dataRng` from `testRng`: no single stream's call count may depend on another
|
|
3195
|
+
# draw's own outcome. `testRng` is the ONLY stream compareArms()/mannWhitneyU ever consumes, same
|
|
3196
|
+
# as CVD_SIM. Independently derived by Monte Carlo, not copied from the earlier scripts (which
|
|
3197
|
+
# share one rng stream where this suite's discipline keeps three -- a design difference, NOT
|
|
3198
|
+
# the reason the two readings differ; the point-2 analogue below carries the arithmetic), so
|
|
3199
|
+
# the two are expected to agree in magnitude, not to the decimal, as independent estimates -- checked: this harness's own CVD_SIM point-6-equivalent measurement of the already-
|
|
3200
|
+
# published 0.4250 (margin 0.5, historical population) reproduces bit-for-bit (see point 6 below), which is
|
|
3201
|
+
# the cross-check that this harness is faithful to the real module before trusting new numbers from it.
|
|
3202
|
+
CVD_SIM_D13='
|
|
3203
|
+
const MWmod = await import("'"$ROOT"'/tests/evals/lib/mann-whitney.mjs");
|
|
3204
|
+
const D13_ARM = [2,1,2,1,2,1,1,2,1,1,2,2,2,1,2];
|
|
3205
|
+
const dataRng = MWmod.mulberry32(1234);
|
|
3206
|
+
const bumpRng = MWmod.mulberry32(4321);
|
|
3207
|
+
const testRng = MWmod.mulberry32(5678);
|
|
3208
|
+
function drawOne() { return D13_ARM[Math.floor(dataRng() * D13_ARM.length)]; }
|
|
3209
|
+
function drawArm(n) { return Array.from({ length: n }, drawOne); }
|
|
3210
|
+
const T = 600, RESAMPLES = 3000, N = 15;
|
|
3211
|
+
'
|
|
3212
|
+
|
|
3213
|
+
# Mutant A -- reintroduces the running-as-done defect: collapses capBreached()'s null (running OR malformed) into the
|
|
3214
|
+
# non-breach/done branch -- the natural-but-wrong `if (!capBreached(o)) arm.push(...)` shape.
|
|
3215
|
+
node -e "
|
|
3216
|
+
const fs = require('fs'); const p = '$CVD_SCRATCH'; const s = fs.readFileSync(p, 'utf8');
|
|
3217
|
+
const FROM = 'if (breach === true) return { kind: \'breach\' };\n if (breach === false) {';
|
|
3218
|
+
const TO = 'if (breach === true) return { kind: \'breach\' };\n if (breach !== true) {';
|
|
3219
|
+
if (!s.includes(FROM)) throw new Error('mutant A pattern not found -- source moved');
|
|
3220
|
+
fs.writeFileSync(p, s.replace(FROM, TO));
|
|
3221
|
+
"
|
|
3222
|
+
check "mutant A (F-182: null collapsed into done) is caught -- a running loop's pass count reads as 'done', not 'running'" \
|
|
3223
|
+
"$(cvj "process.stdout.write(M.classifyDraw({status:'running', pass:0}).kind);" "$CVD_SCRATCH")" "done"
|
|
3224
|
+
cp "$ROOT/$CVD" "$CVD_SCRATCH"
|
|
3225
|
+
|
|
3226
|
+
# Mutant B -- reintroduces the re-draw defect: exhausting the wait budget re-draws a FRESH handle instead of
|
|
3227
|
+
# stopping, re-rolling exactly the censored draw and pulling the arm mean down.
|
|
3228
|
+
# Anchored on the return statement alone, not the surrounding block (a later change
|
|
3229
|
+
# added a diagnostic censor record and a comment ahead of this same return inside convergence.mjs's
|
|
3230
|
+
# own scope) -- narrowing the anchor here keeps this guard resilient to that kind of addition
|
|
3231
|
+
# without needing to track every line around it. Anchor text updated
|
|
3232
|
+
# for the additive `breachReason: null` field this same return statement now also carries -- the
|
|
3233
|
+
# anchor's OWN resilience covers a change to lines AROUND it, not a change WITHIN the exact
|
|
3234
|
+
# return statement it matches, so this one line's text needed a manual update; what the check
|
|
3235
|
+
# below asserts (arm/waitExhausted) is unchanged.
|
|
3236
|
+
# Occurrence count asserted, not just presence: an anchor
|
|
3237
|
+
# edit (above) demonstrated a bare .includes() guard can silently match the wrong thing once a
|
|
3238
|
+
# nearby line changes -- adopting the same discipline the fixture-identity anchors already use
|
|
3239
|
+
# (see convergence-runner.sh), not just a presence check.
|
|
3240
|
+
node -e "
|
|
3241
|
+
const fs = require('fs'); const p = '$CVD_SCRATCH'; const s = fs.readFileSync(p, 'utf8');
|
|
3242
|
+
const FROM = 'return { breach: false, arm, stillRunning, replaced, waitExhausted: true, censor, breachReason: null };';
|
|
3243
|
+
const TO = 'replaced++; break; // MUTANT: re-roll instead of stopping';
|
|
3244
|
+
const count = s.split(FROM).length - 1;
|
|
3245
|
+
if (count !== 1) throw new Error('mutant B pattern occurs ' + count + ' time(s), not exactly 1 -- source moved, update this mutation');
|
|
3246
|
+
fs.writeFileSync(p, s.replace(FROM, TO));
|
|
3247
|
+
"
|
|
3248
|
+
check "mutant B (F-194: wait-exhaustion re-rolls instead of stopping) is caught -- the censored slot gets topped up, not left short" \
|
|
3249
|
+
"$(cvj "$CVD_HELPERS
|
|
3250
|
+
const seq = [[{status:'running'}, {status:'running'}, {status:'running'}], [{status:'done', pass:1}]];
|
|
3251
|
+
const r = M.fillArm(mkSeqDraw(seq), { n: 1, maxWaitAttempts: 1, report: () => {} });
|
|
3252
|
+
process.stdout.write(JSON.stringify({ arm: r.arm, waitExhausted: r.waitExhausted }));
|
|
3253
|
+
" "$CVD_SCRATCH")" '{"arm":[1],"waitExhausted":false}'
|
|
3254
|
+
cp "$ROOT/$CVD" "$CVD_SCRATCH"
|
|
3255
|
+
|
|
3256
|
+
# Mutant C -- reintroduces the collapsed-verdict bug points 1/2 exist to catch: no-regression
|
|
3257
|
+
# whenever p >= alpha (the exact "p >= alpha alone is no-regression" shape spec.md forbids). Arms
|
|
3258
|
+
# below are a real inconclusive pair under the PRISTINE module (primary.p=0.137, unaffected by
|
|
3259
|
+
# REGRESSION_SHIFT since `shift` is never read before the primary-test return; equiv.p=0.084 at
|
|
3260
|
+
# the previous margin of 1, re-measured at ~0.38 under the new 0.5 -- both readings >= alpha, so this
|
|
3261
|
+
# is still a genuine inconclusive pair at the new margin, just less marginal -- found by
|
|
3262
|
+
# simulation, not hand-picked to be easy), so the mutant's forced flip to 'no-regression' is a
|
|
3263
|
+
# visible change from the correct verdict, not masked by an earlier primary-regression return.
|
|
3264
|
+
# the paragraph above ASSERTED the pristine premise only in prose --
|
|
3265
|
+
# closed with a direct check, against the tracked module, before the mutation below is applied.
|
|
3266
|
+
check "mutant C's pair is a genuine inconclusive pair UNDER THE UNMODIFIED module (F-313) -- the premise the mutation below is supposed to visibly change, checked directly rather than only claimed in a comment" \
|
|
3267
|
+
"$(cvj "
|
|
3268
|
+
const a = [1,3,2,3,1,3,1,1,1,3,1,1,1,3,1];
|
|
3269
|
+
const b = [1,2,3,2,1,2,3,1,3,5,2,1,5,1,2];
|
|
3270
|
+
process.stdout.write(M.compareArms(a, b, { resamples: 20000 }).verdict);
|
|
3271
|
+
")" "inconclusive"
|
|
3272
|
+
node -e "
|
|
3273
|
+
const fs = require('fs'); const p = '$CVD_SCRATCH'; const s = fs.readFileSync(p, 'utf8');
|
|
3274
|
+
const FROM = \"const shifted = candidateArm.map((v) => v - shift);\n const equivalence = mannWhitneyU(shifted, baselineArm, mwOpts);\n const verdict = equivalence.p < alpha ? 'no-regression' : 'inconclusive';\n return { verdict, primary, equivalence, alpha, shift, power };\";
|
|
3275
|
+
const TO = \"const verdict = 'no-regression'; // MUTANT\n return { verdict, primary, alpha, shift, power };\";
|
|
3276
|
+
if (!s.includes(FROM)) throw new Error('mutant C pattern not found -- source moved');
|
|
3277
|
+
fs.writeFileSync(p, s.replace(FROM, TO));
|
|
3278
|
+
"
|
|
3279
|
+
check "mutant C ('p >= alpha alone is no-regression') is caught -- a real inconclusive pair now reads no-regression" \
|
|
3280
|
+
"$(cvj "
|
|
3281
|
+
const a = [1,3,2,3,1,3,1,1,1,3,1,1,1,3,1];
|
|
3282
|
+
const b = [1,2,3,2,1,2,3,1,3,5,2,1,5,1,2];
|
|
3283
|
+
process.stdout.write(M.compareArms(a, b, { resamples: 20000 }).verdict);
|
|
3284
|
+
" "$CVD_SCRATCH")" "no-regression"
|
|
3285
|
+
cp "$ROOT/$CVD" "$CVD_SCRATCH"
|
|
3286
|
+
|
|
3287
|
+
# Mutant D -- reintroduces the NEVER-ACCEPTS direction:
|
|
3288
|
+
# a gate that can never return no-regression. Every other check in this suite bounds a false
|
|
3289
|
+
# ACCEPT; this is the direction only point 6 (below) bounds. Short-circuits compareArms() to a
|
|
3290
|
+
# hardcoded verdict -- the rest of the function body is then dead code, which is fine, this is a
|
|
3291
|
+
# staged mutant, not shipped source.
|
|
3292
|
+
node -e "
|
|
3293
|
+
const fs = require('fs'); const p = '$CVD_SCRATCH'; const s = fs.readFileSync(p, 'utf8');
|
|
3294
|
+
const FROM = 'export function compareArms(baselineArm, candidateArm, opts = {}) {';
|
|
3295
|
+
const TO = 'export function compareArms(baselineArm, candidateArm, opts = {}) { return { verdict: \'inconclusive\' }; // MUTANT (F-221): never accepts';
|
|
3296
|
+
if (!s.includes(FROM)) throw new Error('mutant D pattern not found -- source moved');
|
|
3297
|
+
fs.writeFileSync(p, s.replace(FROM, TO));
|
|
3298
|
+
"
|
|
3299
|
+
check "mutant D (F-221: verdict is always 'inconclusive') is caught by point 6's FIRST half -- a clean, healthy pair now reads inconclusive, not no-regression" \
|
|
3300
|
+
"$(cvj "$CVD_HELPERS
|
|
3301
|
+
const arm = Array.from({length:15}, () => [{status:'done',pass:2}]);
|
|
3302
|
+
const r = M.runComparison(mkSeqDraw(arm.slice()), mkSeqDraw(arm.slice()), { resamples: 5000, report: () => {} });
|
|
3303
|
+
process.stdout.write(r.verdict);
|
|
3304
|
+
" "$CVD_SCRATCH")" "inconclusive"
|
|
3305
|
+
check "mutant D is ALSO caught by point 6's SECOND half -- the no-regression rate on unshifted pairs collapses to 0, far below point 6's floor (D16, re-derived below for REGRESSION_SHIFT=0.5)" \
|
|
3306
|
+
"$(cvj "$CVD_SIM
|
|
3307
|
+
process.stdout.write(String(M.estimatePower(drawOne, N, { rng: testRng, resamples: RESAMPLES, trials: 50 })));
|
|
3308
|
+
" "$CVD_SCRATCH")" "0"
|
|
3309
|
+
# the never-accepting direction is caught the SAME way on the baseline-population
|
|
3310
|
+
# analogue (defined below) -- staged here, on the SAME mutant, rather than re-mutating a second
|
|
3311
|
+
# scratch copy, since the mutation itself doesn't depend on which population later draws from it.
|
|
3312
|
+
check "mutant D is ALSO caught by the D13-population point 6 analogue (F-309) -- the healthy-pair no-regression rate collapses to 0 there too, independent of which population is used" \
|
|
3313
|
+
"$(cvj "$CVD_SIM_D13
|
|
3314
|
+
process.stdout.write(String(M.estimatePower(drawOne, N, { rng: testRng, resamples: RESAMPLES, trials: 50 })));
|
|
3315
|
+
" "$CVD_SCRATCH")" "0"
|
|
3316
|
+
cp "$ROOT/$CVD" "$CVD_SCRATCH"
|
|
3317
|
+
|
|
3318
|
+
check "positive control: the tracked convergence.mjs is pristine after all four mutants (F-231: now also exercises fillArm, the seam mutant B mutates -- reusing the n:2/maxWaitAttempts:1 case)" \
|
|
3319
|
+
"$(cvj "$CVD_HELPERS
|
|
3320
|
+
const a = [1,3,2,3,1,3,1,1,1,3,1,1,1,3,1];
|
|
3321
|
+
const b = [1,2,3,2,1,2,3,1,3,5,2,1,5,1,2];
|
|
3322
|
+
const seq = [[{status:'running'}, {status:'running'}, {status:'running'}], [{status:'done', pass:1}]];
|
|
3323
|
+
const fr = M.fillArm(mkSeqDraw(seq), { n: 2, maxWaitAttempts: 1, report: () => {} });
|
|
3324
|
+
process.stdout.write(M.classifyDraw({status:'running', pass:0}).kind + '/' + M.compareArms(a, b, { resamples: 20000 }).verdict + '/' + JSON.stringify({ arm: fr.arm, waitExhausted: fr.waitExhausted }));
|
|
3325
|
+
")" 'running/inconclusive/{"arm":[],"waitExhausted":true}'
|
|
3326
|
+
|
|
3327
|
+
# Mutant E -- the literal PRE-FIX code path: fillArm()'s breach branch
|
|
3328
|
+
# reverted to dropping breachReason entirely, exactly as it read before the fix
|
|
3329
|
+
# (`return { breach: true, arm, stillRunning, replaced, waitExhausted: false, censor: null };`,
|
|
3330
|
+
# as it read before). The "shown to fail, shown to pass"
|
|
3331
|
+
# discipline, applied here as a genuine mutation-test rather than only the direct checks above.
|
|
3332
|
+
node -e "
|
|
3333
|
+
const fs = require('fs'); const p = '$CVD_SCRATCH'; const s = fs.readFileSync(p, 'utf8');
|
|
3334
|
+
const FROM = 'return { breach: true, arm, stillRunning, replaced, waitExhausted: false, censor: null, breachReason: reason };';
|
|
3335
|
+
const TO = 'return { breach: true, arm, stillRunning, replaced, waitExhausted: false, censor: null }; // MUTANT (D6): pre-fix -- breachReason dropped entirely';
|
|
3336
|
+
if (!s.includes(FROM)) throw new Error('mutant E pattern not found -- source moved');
|
|
3337
|
+
fs.writeFileSync(p, s.replace(FROM, TO));
|
|
3338
|
+
"
|
|
3339
|
+
check "mutant E (D6 pre-fix: breachReason dropped from the breach return) is caught -- a documented breach status no longer surfaces its specific reason" \
|
|
3340
|
+
"$(cvj "$CVD_HELPERS
|
|
3341
|
+
const r = M.fillArm(mkSeqDraw([[{status:'stopped-max-passes-exceeded', pass:6}]]), { n: 1, report: () => {} });
|
|
3342
|
+
process.stdout.write(String(r.breachReason));
|
|
3343
|
+
" "$CVD_SCRATCH")" "undefined"
|
|
3344
|
+
cp "$ROOT/$CVD" "$CVD_SCRATCH"
|
|
3345
|
+
check "mutant E reverted -- the tracked convergence.mjs's breach branch threads breachReason again" \
|
|
3346
|
+
"$(cvj "$CVD_HELPERS
|
|
3347
|
+
const r = M.fillArm(mkSeqDraw([[{status:'stopped-max-passes-exceeded', pass:6}]]), { n: 1, report: () => {} });
|
|
3348
|
+
process.stdout.write(String(r.breachReason));
|
|
3349
|
+
" "$CVD_SCRATCH")" "max-passes-exceeded"
|
|
3350
|
+
|
|
3351
|
+
# Mutant F -- an INTENTIONALLY-BROKEN threading, distinct from mutant E's plain omission: reads
|
|
3352
|
+
# the reason via a FRESH draw.read() issued AFTER safeCleanup(draw), instead of the
|
|
3353
|
+
# already-captured `state` local -- the exact ordering mistake to watch for (a naive re-read after the workDir is gone). startDraw()'s real read() returns
|
|
3354
|
+
# `null` once statePath no longer exists (existsSync guard), so this mutant's breachReason
|
|
3355
|
+
# collapses to null on every real breach -- caught by the SAME direct check already used for the
|
|
3356
|
+
# stopped-<reason> case above, no new assertion shape needed.
|
|
3357
|
+
node -e "
|
|
3358
|
+
const fs = require('fs'); const p = '$CVD_SCRATCH'; const s = fs.readFileSync(p, 'utf8');
|
|
3359
|
+
const FROM = 'const reason = breachReason(state);\n safeCleanup(draw);\n return { breach: true, arm, stillRunning, replaced, waitExhausted: false, censor: null, breachReason: reason };';
|
|
3360
|
+
const TO = 'safeCleanup(draw);\n const reason = breachReason(draw.read()); // MUTANT (D6): re-read AFTER cleanup, not the cached state\n return { breach: true, arm, stillRunning, replaced, waitExhausted: false, censor: null, breachReason: reason };';
|
|
3361
|
+
if (!s.includes(FROM)) throw new Error('mutant F pattern not found -- source moved');
|
|
3362
|
+
fs.writeFileSync(p, s.replace(FROM, TO));
|
|
3363
|
+
"
|
|
3364
|
+
check "mutant F (D6: reason re-read from draw.read() AFTER safeCleanup, not the cached state) is caught -- against a REAL startDraw()-shaped handle whose read() returns null once the workDir is gone, this reads null instead of the real reason" \
|
|
3365
|
+
"$(cvj "
|
|
3366
|
+
function mkPostCleanupNullDraw(status) {
|
|
3367
|
+
let cleaned = false;
|
|
3368
|
+
const state = { status, pass: 6 };
|
|
3369
|
+
return () => ({
|
|
3370
|
+
read: () => (cleaned ? null : state), // mirrors startDraw()'s own read(): null once the statePath is gone
|
|
3371
|
+
retry: () => {},
|
|
3372
|
+
cleanup: () => { cleaned = true; },
|
|
3373
|
+
});
|
|
3374
|
+
}
|
|
3375
|
+
const r = M.fillArm(mkPostCleanupNullDraw('stopped-max-passes-exceeded'), { n: 1, report: () => {} });
|
|
3376
|
+
process.stdout.write(String(r.breachReason));
|
|
3377
|
+
" "$CVD_SCRATCH")" "null"
|
|
3378
|
+
cp "$ROOT/$CVD" "$CVD_SCRATCH"
|
|
3379
|
+
check "mutant F reverted -- the same post-cleanup-null handle now correctly reads the reason from the state captured BEFORE cleanup" \
|
|
3380
|
+
"$(cvj "
|
|
3381
|
+
function mkPostCleanupNullDraw(status) {
|
|
3382
|
+
let cleaned = false;
|
|
3383
|
+
const state = { status, pass: 6 };
|
|
3384
|
+
return () => ({
|
|
3385
|
+
read: () => (cleaned ? null : state),
|
|
3386
|
+
retry: () => {},
|
|
3387
|
+
cleanup: () => { cleaned = true; },
|
|
3388
|
+
});
|
|
3389
|
+
}
|
|
3390
|
+
const r = M.fillArm(mkPostCleanupNullDraw('stopped-max-passes-exceeded'), { n: 1, report: () => {} });
|
|
3391
|
+
process.stdout.write(String(r.breachReason));
|
|
3392
|
+
" "$CVD_SCRATCH")" "max-passes-exceeded"
|
|
3393
|
+
|
|
3394
|
+
# --- margin pin: the margin's EFFECT, not just its literal value -- a fixed baseline/candidate pair
|
|
3395
|
+
# that reads no-regression at shift=1 and reads something else at the DEFAULT shift (module's own
|
|
3396
|
+
# REGRESSION_SHIFT). `baseline` is the real measured 15-draw arm ([2,1,2,1,2,1,1,2,1,1,2,2,2,1,2],
|
|
3397
|
+
# ); `candidate` bumps its first 4 draws by one pass each -- found by grid search
|
|
3398
|
+
# over "how many draws bumped" (0/2 draws: no-regression at both margins; 8+: regression at both,
|
|
3399
|
+
# shift never even read; 4 draws is the band between, verified stable across 5 independent rng
|
|
3400
|
+
# seeds before picking it). A fixed `rng` (mulberry32) makes this deterministic -- Math.random()
|
|
3401
|
+
# would make a boundary-straddling pair flaky across runs, unlike Mutant C's pair above, which only
|
|
3402
|
+
# needs a stable VERDICT under a mutant that ignores the data outright.
|
|
3403
|
+
# Addendum: this pin's (1/2)-vs-(2/2) contrast only proves the
|
|
3404
|
+
# constant separates a margin of 1 from something strictly BELOW 1 -- on integer pass counts every
|
|
3405
|
+
# value in (0,1) is functionally identical (`c - s < b` <=> `c <= b`), so this pin cannot and does
|
|
3406
|
+
# not claim 0.5 itself is a meaningful tolerance; it would read identically if the module held 0.25
|
|
3407
|
+
# or 0.9 instead of 0.5. The exact literal 0.5 is pinned only by the separate "REGRESSION_SHIFT is
|
|
3408
|
+
# exactly 0.5" literal check (point 4's own discipline, above the classifyDraw section) -- that is
|
|
3409
|
+
# the ONLY check in this suite that would fail if 0.5 moved to another sub-1 value.
|
|
3410
|
+
CVD_PIN_DATA='
|
|
3411
|
+
const baseline = [2,1,2,1,2,1,1,2,1,1,2,2,2,1,2];
|
|
3412
|
+
const candidate = [3,2,3,2,2,1,1,2,1,1,2,2,2,1,2];
|
|
3413
|
+
const MWmod = await import("'"$ROOT"'/tests/evals/lib/mann-whitney.mjs");
|
|
3414
|
+
'
|
|
3415
|
+
check "D16 pin (1/2): explicit shift:1 on the constructed pair reads no-regression -- doesn't depend on the module constant at all (opts.shift passed explicitly)" \
|
|
3416
|
+
"$(cvj "$CVD_PIN_DATA
|
|
3417
|
+
const r = M.compareArms(baseline, candidate, { resamples: 20000, shift: 1, rng: MWmod.mulberry32(20260914) });
|
|
3418
|
+
process.stdout.write(r.verdict);
|
|
3419
|
+
")" "no-regression"
|
|
3420
|
+
check "D16 pin (2/2): the SAME pair through the DEFAULT shift (no opts.shift -- reads REGRESSION_SHIFT off the module) reads inconclusive, not no-regression -- this is what actually proves the constant is 0.5, not 1" \
|
|
3421
|
+
"$(cvj "$CVD_PIN_DATA
|
|
3422
|
+
const r = M.compareArms(baseline, candidate, { resamples: 20000, rng: MWmod.mulberry32(20260914) });
|
|
3423
|
+
process.stdout.write(r.verdict);
|
|
3424
|
+
")" "inconclusive"
|
|
3425
|
+
# Staged: revert REGRESSION_SHIFT to 1 (the previous margin) on the scratch copy and show pin (2/2) turns red --
|
|
3426
|
+
# once the constant is 1 again, the DEFAULT-shift call becomes identical to pin (1/2)'s explicit
|
|
3427
|
+
# shift:1 call, so it reads no-regression instead of the expected inconclusive.
|
|
3428
|
+
node -e "
|
|
3429
|
+
const fs = require('fs'); const p = '$CVD_SCRATCH'; const s = fs.readFileSync(p, 'utf8');
|
|
3430
|
+
const FROM = 'export const REGRESSION_SHIFT = 0.5;';
|
|
3431
|
+
const TO = 'export const REGRESSION_SHIFT = 1; // MUTANT (D16 reverted): pre-tightening margin';
|
|
3432
|
+
if (!s.includes(FROM)) throw new Error('REGRESSION_SHIFT literal not found -- source moved');
|
|
3433
|
+
fs.writeFileSync(p, s.replace(FROM, TO));
|
|
3434
|
+
"
|
|
3435
|
+
check "mutant (REGRESSION_SHIFT reverted to 1) is caught -- pin (2/2) now reads no-regression, not the expected inconclusive, proving the pin is load-bearing on the actual constant" \
|
|
3436
|
+
"$(cvj "$CVD_PIN_DATA
|
|
3437
|
+
const r = M.compareArms(baseline, candidate, { resamples: 20000, rng: MWmod.mulberry32(20260914) });
|
|
3438
|
+
process.stdout.write(r.verdict);
|
|
3439
|
+
" "$CVD_SCRATCH")" "no-regression"
|
|
3440
|
+
cp "$ROOT/$CVD" "$CVD_SCRATCH"
|
|
3441
|
+
|
|
3442
|
+
# --- confirm, by direct execution, that CVD_SIM's own point-6 floor
|
|
3443
|
+
# barely discriminates a moderately over-conservative gate -- mutating ALPHA to 0.025 on a
|
|
3444
|
+
# scratch copy and re-running CVD_SIM's own point-6 trial loop (unchanged T=600/RESAMPLES=3000,
|
|
3445
|
+
# committed seeds) below. The review's own report cited this mutant as "passing only by
|
|
3446
|
+
# floating-point rounding" (power 0.3000 read as >= a 0.30000000000000004 floor); reproduced here
|
|
3447
|
+
# EXACTLY on the two headline numbers (180/600 accepted, floor 0.30000000000000004), but the
|
|
3448
|
+
# STRICT comparison this suite's own `power >= floor` actually evaluates is the other way: 180/600
|
|
3449
|
+
# is 0.29999999999999998890 as a double, one ULP-scale hair BELOW the floor, not above it -- this
|
|
3450
|
+
# specific mutant is (barely) CAUGHT under the exact committed seeds, not a silent pass. The
|
|
3451
|
+
# underlying concern stands regardless of which side of that hair this run lands on: 181 accepted
|
|
3452
|
+
# trials instead of 180 (one trial out of 600) would flip `power >= floor` to true and let the
|
|
3453
|
+
# mutant through -- the floor has essentially ZERO real margin against this specific mutant either
|
|
3454
|
+
# way, which is the actual defect this comment records. Not staged as a `check` -- there is nothing
|
|
3455
|
+
# stable to gate on a margin this thin; the committed guard against the underlying weakness is the
|
|
3456
|
+
# baseline-population mutant staged right after, which has a real (non-hair-width) margin instead.
|
|
3457
|
+
node -e "
|
|
3458
|
+
const fs = require('fs'); const p = '$CVD_SCRATCH'; const s = fs.readFileSync(p, 'utf8');
|
|
3459
|
+
const FROM = 'export const ALPHA = 0.05; // D5.';
|
|
3460
|
+
const TO = 'export const ALPHA = 0.025; // MUTANT (F-310 confirm): moderately over-conservative gate';
|
|
3461
|
+
if (!s.includes(FROM)) throw new Error('ALPHA literal not found -- source moved');
|
|
3462
|
+
fs.writeFileSync(p, s.replace(FROM, TO));
|
|
3463
|
+
"
|
|
3464
|
+
F310_CONFIRM=$(cvj "$CVD_SIM
|
|
3465
|
+
const power = M.estimatePower(drawOne, N, { rng: testRng, resamples: RESAMPLES, trials: T });
|
|
3466
|
+
const target = 0.40, floor = target - 5 * Math.sqrt(target * (1 - target) / T);
|
|
3467
|
+
process.stdout.write(power.toPrecision(20) + ' >= ' + floor.toPrecision(20) + ' -> ' + (power >= floor));
|
|
3468
|
+
" "$CVD_SCRATCH")
|
|
3469
|
+
echo " (F-310 confirm -- CVD_SIM point 6 under ALPHA=0.025 mutant: $F310_CONFIRM)"
|
|
3470
|
+
cp "$ROOT/$CVD" "$CVD_SCRATCH"
|
|
3471
|
+
|
|
3472
|
+
# the ALPHA=0.01 mutant staged here was reasoned about BACKWARDS --
|
|
3473
|
+
# "0.01 is stricter than the earlier 0.025, so at least as hard a case" is wrong: a LOWER alpha
|
|
3474
|
+
# suppresses `equivalence.p < alpha` MORE, so the healthy-pair no-regression rate FALLS further,
|
|
3475
|
+
# which makes 0.01 the EASIER mutant to catch, not the harder one. Measured directly at the OLD
|
|
3476
|
+
# T=600/RESAMPLES=3000: pristine 0.8300, ALPHA=0.025 -> 0.7283 (passed the OLD 0.6954 floor -- NOT
|
|
3477
|
+
# caught), ALPHA=0.01 -> 0.6150 (caught). The case actually intended -- 0.025 -- escaped this
|
|
3478
|
+
# guard exactly as it escaped CVD_SIM's own, though it was reported fixed regardless.
|
|
3479
|
+
#
|
|
3480
|
+
# The root cause is the floor's WIDTH, not its target: 5x its own Monte Carlo SE at T=600 is
|
|
3481
|
+
# +/-0.0846 around 0.78, ~8 SE below the true ~0.83 rate -- room enough for a moderately
|
|
3482
|
+
# over-conservative gate to hide inside it. Fixed by widening T/RESAMPLES for THIS check (and the
|
|
3483
|
+
# mutant staged against it) alone -- to T=3000/RESAMPLES=1500 (~2.5x wall cost, single-digit
|
|
3484
|
+
# seconds), not by moving the target: 5x SE shrinks to ~0.0378, floor ~0.7422. Re-derived by my own
|
|
3485
|
+
# scan (10 independent seed/resample/trial-count combinations, T in [1500,4000], resamples in
|
|
3486
|
+
# [1000,1800]): pristine range [0.7847, 0.8304] (committed seeds 0.8300, matching the old T=600
|
|
3487
|
+
# reading to 4 decimals -- expected, since raising T narrows precision, not the expected value);
|
|
3488
|
+
# ALPHA=0.025 mutant range [0.6700, 0.7228] across the SAME combinations, under the new 0.7422 floor
|
|
3489
|
+
# at every one (margin >=0.0194, >=58 trials at T=3000; committed seeds 0.7120, margin 0.0302, ~90
|
|
3490
|
+
# trials). ALPHA=0.01 is therefore SUBSUMED -- anything that catches 0.025 with real margin catches
|
|
3491
|
+
# every stricter (lower) alpha too -- and is dropped as the committed mutant; staging both would
|
|
3492
|
+
# test nothing 0.025 alone doesn't.
|
|
3493
|
+
node -e "
|
|
3494
|
+
const fs = require('fs'); const p = '$CVD_SCRATCH'; const s = fs.readFileSync(p, 'utf8');
|
|
3495
|
+
const FROM = 'export const ALPHA = 0.05; // D5.';
|
|
3496
|
+
const TO = 'export const ALPHA = 0.025; // MUTANT (F-314): the case F-310 named, moderately over-conservative';
|
|
3497
|
+
if (!s.includes(FROM)) throw new Error('ALPHA literal not found -- source moved');
|
|
3498
|
+
fs.writeFileSync(p, s.replace(FROM, TO));
|
|
3499
|
+
"
|
|
3500
|
+
D13_ALPHA025=$(cvj "$CVD_SIM_D13
|
|
3501
|
+
const T6 = 3000, RESAMPLES6 = 1500; // F-314: trials raised 600 -> 3000 (resamples traded down 3000 -> 1500 to hold cost at ~2.5x); the floor's width depends on T alone. This check only.
|
|
3502
|
+
const power = M.estimatePower(drawOne, N, { rng: testRng, resamples: RESAMPLES6, trials: T6 });
|
|
3503
|
+
const target = 0.78, floor = target - 5 * Math.sqrt(target * (1 - target) / T6);
|
|
3504
|
+
process.stdout.write(power.toFixed(4) + '>=' + floor.toFixed(4) + ' ' + (power >= floor));
|
|
3505
|
+
" "$CVD_SCRATCH")
|
|
3506
|
+
echo " (D13 point 6 analogue under ALPHA=0.025 mutant, T=3000/RESAMPLES=1500: $D13_ALPHA025)"
|
|
3507
|
+
check "ALPHA=0.025 mutant (F-310's own case; F-314) is caught by the D13-population point 6 analogue with real margin at the widened T -- not the easier ALPHA=0.01 substitute" \
|
|
3508
|
+
"$(echo "$D13_ALPHA025" | awk '{print $2}')" "false"
|
|
3509
|
+
cp "$ROOT/$CVD" "$CVD_SCRATCH"
|
|
3510
|
+
|
|
3511
|
+
# --- points 1, 2 and 6: Monte-Carlo property bounds on the verdict logic built atop the already-
|
|
3512
|
+
# oracle-verified rank procedure (3.2 owns rank-procedure correctness; this does not re-check it).
|
|
3513
|
+
# All three draw from the tied historical histogram ({1:9,2:4,3:5,4:2,5:1}) via CVD_SIM,
|
|
3514
|
+
# defined above (before the mutation section, since mutant D's second check needs it too). Trial/
|
|
3515
|
+
# resample counts are stated so every tolerance is derived, never loosened to fit.
|
|
3516
|
+
#
|
|
3517
|
+
# margin change (REGRESSION_SHIFT 1 -> 0.5): point 1's target is UNCHANGED -- `regression` is decided from
|
|
3518
|
+
# `primary.p < alpha` alone, before `compareArms()` ever reads `shift` (see the early return above
|
|
3519
|
+
# `shifted` is computed), so this rate is a function of ALPHA and the historical sigma only, never the margin.
|
|
3520
|
+
# Checked directly, not assumed: re-run against the tracked module with shift explicitly 1 and 0.5,
|
|
3521
|
+
# both gave 0.0367 to four decimals, same seeds. Left as-is; this is the original-sigma case, left alone and noted rather than re-derived.
|
|
3522
|
+
POINT1=$(cvj "$CVD_SIM
|
|
3523
|
+
let regressions = 0;
|
|
3524
|
+
for (let t = 0; t < T; t++) {
|
|
3525
|
+
const r = M.compareArms(drawArm(N), drawArm(N), { resamples: RESAMPLES, rng: testRng });
|
|
3526
|
+
if (r.verdict === 'regression') regressions++;
|
|
3527
|
+
}
|
|
3528
|
+
const rate = regressions / T, bound = 0.05 + 5 * Math.sqrt(0.05 * 0.95 / T);
|
|
3529
|
+
process.stdout.write(rate.toFixed(4) + '<=' + bound.toFixed(4) + ' ' + (rate <= bound));
|
|
3530
|
+
")
|
|
3531
|
+
echo " (point 1 measured: $POINT1)"
|
|
3532
|
+
check "point 1 -- one-sided size bound: empirical regression rate on UNSHIFTED (null) pairs <= 0.05 + 5x its own Monte Carlo SE, T=600 (one-sided, not a tight two-sided interval; margin-invariant, D16 -- see comment above)" \
|
|
3533
|
+
"$(echo "$POINT1" | awk '{print $2}')" "true"
|
|
3534
|
+
|
|
3535
|
+
# Margin change: this bound DOES depend on the margin, and is re-derived, not left in place. The scenario is
|
|
3536
|
+
# unchanged (a genuinely +1-pass-degraded arm) but the margin no longer sits AT that effect size --
|
|
3537
|
+
# at REGRESSION_SHIFT=1 the shifted candidate reduces to a resample of the baseline's own
|
|
3538
|
+
# distribution (a null test, false-accept rate near ALPHA, which is why the old target was 0.08).
|
|
3539
|
+
# At 0.5 the shifted candidate is still elevated 0.5 passes over baseline, so equivalence rarely
|
|
3540
|
+
# reads significant. Re-measured (this exact CVD_SIM population/seeds, module REGRESSION_SHIFT=0.5):
|
|
3541
|
+
# 0.33% at T=600; independently reconfirmed across 5 other seed/resample/trial-count combinations
|
|
3542
|
+
# (T up to 6000) at 0.20%-0.33%, never above -- the range this target is drawn from, same method
|
|
3543
|
+
# used to set the original 0.08 from its own "4.7-8% depending on resample count" scan.
|
|
3544
|
+
# Target 0.005 sits above every measured reading, not fitted to the committed run's own 0.33%.
|
|
3545
|
+
POINT2=$(cvj "$CVD_SIM
|
|
3546
|
+
let falseAccepts = 0;
|
|
3547
|
+
for (let t = 0; t < T; t++) {
|
|
3548
|
+
const r = M.compareArms(drawArm(N), drawArm(N).map((v) => v + 1), { resamples: RESAMPLES, rng: testRng });
|
|
3549
|
+
if (r.verdict === 'no-regression') falseAccepts++;
|
|
3550
|
+
}
|
|
3551
|
+
const rate = falseAccepts / T, bound = 0.005 + 5 * Math.sqrt(0.005 * 0.995 / T);
|
|
3552
|
+
process.stdout.write(rate.toFixed(4) + '<=' + bound.toFixed(4) + ' ' + (rate <= bound));
|
|
3553
|
+
")
|
|
3554
|
+
echo " (point 2 measured: $POINT2)"
|
|
3555
|
+
check "point 2 -- bound the false no-regression rate on truly-shifted (+1 pass, degraded) arms: <= 0.005 + 5x its own Monte Carlo SE, T=600 -- re-derived for D16's 0.5 margin (was 0.08 at margin 1; see comment above), the number the three-state verdict exists to control" \
|
|
3556
|
+
"$(echo "$POINT2" | awk '{print $2}')" "true"
|
|
3557
|
+
|
|
3558
|
+
# point 6's SECOND half: a lower bound on the no-regression rate for UNSHIFTED
|
|
3559
|
+
# (healthy) pairs -- the direction NOTHING else in this suite bounds. Reuses estimatePower()
|
|
3560
|
+
# itself (built once inside convergence.mjs), not a hand-rolled reimplementation of the
|
|
3561
|
+
# same trial loop -- CVD_SIM's own `drawOne` is passed straight through.
|
|
3562
|
+
#
|
|
3563
|
+
# Margin change: the old floor was the original STATED normal-approximation power for a +1-pass shift (0.716),
|
|
3564
|
+
# which happened to sit within ~1 point of this test's own tie-conditional measurement (~0.72) at
|
|
3565
|
+
# margin 1 -- a coincidence of that specific margin, not a property of the method. At margin
|
|
3566
|
+
# 0.5 the same normal-approximation formula (d = 0.5/1.236354, n=15, the original
|
|
3567
|
+
# Phi(d*sqrt(n/2) - z_0.05)) predicts ~29.6% -- but the ACTUAL tie-conditional Monte Carlo rate
|
|
3568
|
+
# (the real, in-use test) measures materially higher: 39.8%-42.65% across 5 independent
|
|
3569
|
+
# seed/resample/trial-count combinations, including the committed seeds' own 42.5%. The normal
|
|
3570
|
+
# approximation is known invalid for this heavily-tied integer data (a known correction) -- more
|
|
3571
|
+
# so the smaller the effect, since ties dominate a smaller shift more. The floor below is derived
|
|
3572
|
+
# from the MEASURED range -- target 0.40 is CLOSE to that range, NOT below every reading in it (the
|
|
3573
|
+
# lowest scan, 39.8%, sits below 0.40 -- corrected here: an earlier version of this
|
|
3574
|
+
# comment claimed the opposite, "sits at/below every reading," which was false by inspection of its
|
|
3575
|
+
# own cited numbers). The real safety margin is the floor's own 5x-Monte-Carlo-SE subtraction (0.40
|
|
3576
|
+
# -> 0.30), which every one of the 39.8%-42.65% readings clears comfortably; the target itself is
|
|
3577
|
+
# not, and does not need to be, a lower bound on the scan -- only the floor does that job.
|
|
3578
|
+
#
|
|
3579
|
+
# this is CVD_SIM's stress-case population (sd~1.24) -- see the
|
|
3580
|
+
# relabeling comment at CVD_SIM's own definition above. This floor is also known WEAK against a
|
|
3581
|
+
# moderately over-conservative gate specifically: an ALPHA=0.025 mutant measures 180/600=0.3000
|
|
3582
|
+
# here, against a floor of 0.30000000000000004 -- one ULP-scale hair below it (verified above: this
|
|
3583
|
+
# specific committed run is barely CAUGHT, not a silent pass, but a single trial's outcome either
|
|
3584
|
+
# way, 179 or 181 of 600, would flip the verdict). Effectively zero real margin either direction,
|
|
3585
|
+
# which is the actual weakness -- not fixed here since CVD_SIM is the deliberate stress case.
|
|
3586
|
+
# The baseline-population analogue below does not share this weakness -- staged against the SAME
|
|
3587
|
+
# ALPHA=0.025 mutant that nearly slipped past CVD_SIM's own floor here (not the easier
|
|
3588
|
+
# ALPHA=0.01 substitute this comment cited before), at a widened T=3000/RESAMPLES=1500 (the floor's
|
|
3589
|
+
# WIDTH, not its target, was the actual gap), it is caught with a real (non-hair-width) margin,
|
|
3590
|
+
# 0.7120 against a 0.7422 floor -- ~90 trials at T=3000, not a single-trial hair.
|
|
3591
|
+
POINT6=$(cvj "$CVD_SIM
|
|
3592
|
+
const power = M.estimatePower(drawOne, N, { rng: testRng, resamples: RESAMPLES, trials: T });
|
|
3593
|
+
const target = 0.40; // measured tie-conditional floor at REGRESSION_SHIFT=0.5, D16 -- see comment above
|
|
3594
|
+
const floor = target - 5 * Math.sqrt(target * (1 - target) / T);
|
|
3595
|
+
process.stdout.write(power.toFixed(4) + '>=' + floor.toFixed(4) + ' ' + (power >= floor));
|
|
3596
|
+
")
|
|
3597
|
+
echo " (point 6 measured: $POINT6)"
|
|
3598
|
+
check "point 6 (2/2) -- lower bound on the no-regression rate for UNSHIFTED (healthy) pairs, >= 0.40 (measured tie-conditional floor, D16 -- was D2's stated 0.716 at margin 1) minus 5x its own Monte Carlo SE, T=600 -- bounds the direction F-221 found unbounded" \
|
|
3599
|
+
"$(echo "$POINT6" | awk '{print $2}')" "true"
|
|
3600
|
+
|
|
3601
|
+
# --- baseline-population analogues: it was measured that the real
|
|
3602
|
+
# baseline ([2,1,2,1,2,1,1,2,1,1,2,2,2,1,2], mean 1.5333, sd 0.5164) is the
|
|
3603
|
+
# population the margin-gated /code-loop comparison actually draws from, NOT the wider mixed-history
|
|
3604
|
+
# one CVD_SIM uses (point 2/6 above). Re-derived independently here by bootstrap resampling
|
|
3605
|
+
# (CVD_SIM_D13, defined near CVD_SIM above), own committed seeds. T differs per check: the point-2 analogue below runs at the preamble's own T=600/RESAMPLES=3000; the
|
|
3606
|
+
# point-6 analogue runs at T=3000/RESAMPLES=1500, widened because the floor's width
|
|
3607
|
+
# depends on T alone. Not copied from the earlier resampling scripts
|
|
3608
|
+
# (which share one rng stream where this suite's discipline keeps three -- a design
|
|
3609
|
+
# difference, NOT the reason the two readings differ; see the point-2 analogue's own note below),
|
|
3610
|
+
# so the two are expected to agree in MAGNITUDE, not to the decimal, as independent Monte Carlo
|
|
3611
|
+
# estimates of the same quantity.
|
|
3612
|
+
|
|
3613
|
+
# baseline point 6 analogue: healthy-pair (no injected degradation) no-regression rate.
|
|
3614
|
+
#
|
|
3615
|
+
# T/RESAMPLES for THIS check widened from the shared CVD_SIM_D13
|
|
3616
|
+
# preamble's T=600/RESAMPLES=3000 to T=3000/RESAMPLES=1500 -- trials raised, resamples traded down,
|
|
3617
|
+
# ~2.5x wall cost (single-digit seconds); the floor's width depends on T alone
|
|
3618
|
+
# -- the floor's WIDTH, not its target, was what let a moderately over-conservative gate
|
|
3619
|
+
# (ALPHA=0.025, the intended case) escape at T=600: 5x this floor's own Monte Carlo SE there is
|
|
3620
|
+
# 0.0846, ~8 SE below the true ~0.83 rate, room enough to hide a real weakening of the gate's own
|
|
3621
|
+
# strictness. At T=3000 the same 5x SE shrinks to ~0.0378 -- see the ALPHA mutant staged against
|
|
3622
|
+
# this exact check, in the mutation section above (it also subsumes the
|
|
3623
|
+
# easier ALPHA=0.01 substitute).
|
|
3624
|
+
#
|
|
3625
|
+
# Re-scanned at the new T (my own scan, not pasted from the review): 10 independent
|
|
3626
|
+
# seed/resample/trial-count combinations, T in [1500,4000], resamples in [1000,1800]: range
|
|
3627
|
+
# [0.7847, 0.8304] (committed seeds 0.8300, unchanged from the old T=600 reading to 4 decimals --
|
|
3628
|
+
# expected, since a larger T narrows precision, not the expected value). Target stays 0.78. It sits
|
|
3629
|
+
# below every reading in THIS scan, but that is not relied on as a guaranteed property of the
|
|
3630
|
+
# population -- the "strictly below" framing this comment used to make is exactly the overclaim
|
|
3631
|
+
# found elsewhere in this file (a wider scan can always turn up a lower reading, as
|
|
3632
|
+
# it did for the CVD_SIM point 6 target and for this same target at the old T=600 width). The real
|
|
3633
|
+
# safety margin is the floor's own 5x-Monte-Carlo-SE subtraction (0.78 -> ~0.7422 at T=3000), which
|
|
3634
|
+
# every one of the 10 readings above clears with real room (>=0.0425).
|
|
3635
|
+
D13_POINT6=$(cvj "$CVD_SIM_D13
|
|
3636
|
+
const T6 = 3000, RESAMPLES6 = 1500; // F-314: widened from the shared T/RESAMPLES above, this check only
|
|
3637
|
+
const power = M.estimatePower(drawOne, N, { rng: testRng, resamples: RESAMPLES6, trials: T6 });
|
|
3638
|
+
const target = 0.78; // measured floor, D13 population, F-309/F-314 -- see comment above
|
|
3639
|
+
const floor = target - 5 * Math.sqrt(target * (1 - target) / T6);
|
|
3640
|
+
process.stdout.write(power.toFixed(4) + '>=' + floor.toFixed(4) + ' ' + (power >= floor));
|
|
3641
|
+
")
|
|
3642
|
+
echo " (D13 point 6 analogue measured, T=3000/RESAMPLES=1500: $D13_POINT6)"
|
|
3643
|
+
check "D13-population point 6 analogue -- lower bound on the no-regression rate for UNSHIFTED (healthy) pairs drawn from the REAL baseline population, >= 0.78 minus 5x its own Monte Carlo SE, T=3000 (F-309/F-314: this is what the operative D16 gate's real accept rate looks like, not CVD_SIM's stress-case figure)" \
|
|
3644
|
+
"$(echo "$D13_POINT6" | awk '{print $2}')" "true"
|
|
3645
|
+
|
|
3646
|
+
# baseline point 2 analogue: false no-regression rate under a genuinely +0.5-pass DEGRADED candidate --
|
|
3647
|
+
# the SAME "each draw gains a pass with probability 0.5" model the earlier resampling used to
|
|
3648
|
+
# report "+0.5 pass" (distinct from points 1/2's own flat +1 CVD_SIM shift above, which models the
|
|
3649
|
+
# original alternative hypothesis). Scanned across 8 independent seed/resample/trial-count combinations: range measured
|
|
3650
|
+
# [0.0533, 0.0883] (committed seeds: 0.0767). Target set to 0.10, strictly ABOVE every reading in
|
|
3651
|
+
# that scan -- comfortably clear of the earlier cited ~5.3%.
|
|
3652
|
+
#
|
|
3653
|
+
# a prior version of this comment attributed the gap between this
|
|
3654
|
+
# harness's reading (0.0767) and the earlier cited ~5.3% to rng-stream discipline (three independent
|
|
3655
|
+
# streams here vs. one shared stream in the earlier script). Wrong on two counts, checked
|
|
3656
|
+
# directly rather than assumed. (1) The degradation model does NOT differ: both apply
|
|
3657
|
+
# a Bernoulli draw with p=0.5, plus 1, to the same bootstrapped draw (`bumpRng() < 0.5 ? 1 : 0` here;
|
|
3658
|
+
# `rng() < 0.5 ? v+1 : v` in the earlier resampling script -- read side by side, not
|
|
3659
|
+
# just described). (2) Stream-sharing reads HIGHER than three streams, not lower -- the opposite
|
|
3660
|
+
# sign a "three streams understate it" story would need: an independent scan (shared-stream mean
|
|
3661
|
+
# 0.0700 across 10 seeds vs. three-stream mean 0.0680 across 10 combinations, both at
|
|
3662
|
+
# T=600/RESAMPLES=3000) shows no systematic direction from stream count at all.
|
|
3663
|
+
#
|
|
3664
|
+
# The gap is Monte Carlo noise, not methodology. The earlier cited 5.3% is 16 of 300 trials at its own
|
|
3665
|
+
# script's defaults (SE = sqrt(0.053*0.947/300) ~= 1.3%); re-running that SAME script
|
|
3666
|
+
# (the earlier resampling script, unedited, its own defaults) just now gives **7.0%** --
|
|
3667
|
+
# about 1.3 SE from the recorded 5.3%, i.e. ordinary trial-to-trial noise at TRIALS=300, not a
|
|
3668
|
+
# discrepancy needing a cause. This harness's own three-stream committed reading is 0.0767; an
|
|
3669
|
+
# independent 10+10-seed scan combining both stream disciplines spans [0.0483, 0.0850]. All of this
|
|
3670
|
+
# sits well inside the target's own 0.10 bound. The three-independent-streams discipline itself
|
|
3671
|
+
# stays (the no-shared-call-count-dependency reasoning, restated at CVD_SIM_D13's
|
|
3672
|
+
# definition above) -- it is a design choice made for its own reason, not an explanation for a
|
|
3673
|
+
# discrepancy that turned out to be ordinary sampling noise.
|
|
3674
|
+
D13_POINT2=$(cvj "$CVD_SIM_D13
|
|
3675
|
+
let falseAccepts = 0;
|
|
3676
|
+
for (let t = 0; t < T; t++) {
|
|
3677
|
+
const baseline = drawArm(N);
|
|
3678
|
+
const candidate = drawArm(N).map((v) => v + (bumpRng() < 0.5 ? 1 : 0));
|
|
3679
|
+
const r = M.compareArms(baseline, candidate, { resamples: RESAMPLES, rng: testRng });
|
|
3680
|
+
if (r.verdict === 'no-regression') falseAccepts++;
|
|
3681
|
+
}
|
|
3682
|
+
const rate = falseAccepts / T, bound = 0.10 + 5 * Math.sqrt(0.10 * 0.90 / T);
|
|
3683
|
+
process.stdout.write(rate.toFixed(4) + '<=' + bound.toFixed(4) + ' ' + (rate <= bound));
|
|
3684
|
+
")
|
|
3685
|
+
echo " (D13 point 2 analogue measured: $D13_POINT2)"
|
|
3686
|
+
check "D13-population point 2 analogue -- bound the false no-regression rate on a truly +0.5-pass-degraded arm (Bernoulli model, D15/D16), drawn from the REAL baseline population: <= 0.10 + 5x its own Monte Carlo SE, T=600 (F-309)" \
|
|
3687
|
+
"$(echo "$D13_POINT2" | awk '{print $2}')" "true"
|
|
3688
|
+
|
|
3689
|
+
echo
|
|
3690
|
+
printf ' %d passed, %d failed\n' "$pass" "$fail"
|
|
3691
|
+
[ "$fail" -eq 0 ]
|