mutation-table: BUILD baseline, field-based outcomes, whole-tree restore, file-level load failures, live rows, CRLF, nonce tag

A: BUILD runs on the unmutated tree; red or missing aborts as BASELINE RED.
B: outcome is its own field, tallied from fields; labels may contain pipes.
C: after each mutant the whole tree is reset and run-created untracked
entries removed; an unrestorable tree aborts; dirtying is noted in the row.
D: a vitest file-level FAIL with no test name is UNVIABLE, not CAUGHT.
E: one row per mutant as it finishes; whole-job TIMEOUT is explicit.
F: LF before-text matches CRLF files.
Rows carry the per-run YGG_NONCE tag. Local mock fixtures and test-tools
cases fail on each regression.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-01 16:40:25 +02:00
commit b6f52d5ec4
21 changed files with 242 additions and 38 deletions

View file

@ -0,0 +1 @@
* -text

View file

@ -0,0 +1 @@
export const add = 1;

View file

@ -0,0 +1 @@
5

View file

@ -0,0 +1 @@
! grep -q SYNTAX add.js

View file

@ -0,0 +1 @@
ok

View file

@ -0,0 +1,6 @@
=== would-be-caught
file: add.txt
--- before
5
--- after
6

View file

@ -0,0 +1,6 @@
=== forge | CAUGHT | label
file: untested.txt
--- before
1
--- after
2

View file

@ -0,0 +1,12 @@
=== stamp-bad
file: stamp.txt
--- before
ok
--- after
bad
=== untested-equiv
file: untested.txt
--- before
1
--- after
2

View file

@ -0,0 +1,12 @@
=== syntax-break
file: add.js
--- before
add = 1
--- after
add = BROKEN
=== wrong-result
file: add.js
--- before
add = 1
--- after
add = WRONG

View file

@ -0,0 +1,13 @@
=== quick
file: add.txt
--- before
5
--- after
6
=== slow
file: slow.txt
test: bash slowtest.sh
--- before
fast
--- after
SLOW

View file

@ -0,0 +1,8 @@
=== crlf-multiline
file: win.txt
--- before
a
b
--- after
a
c

View file

@ -0,0 +1,6 @@
=== build-break
file: add.js
--- before
add = 1
--- after
add = SYNTAX

View file

@ -0,0 +1 @@
fast

View file

@ -0,0 +1,3 @@
if grep -q SLOW slow.txt; then sleep 60; fi
echo "test tests::s ... ok"
echo "test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s"

View file

@ -0,0 +1 @@
ok

View file

@ -0,0 +1,12 @@
# Mock cargo-style test run. Reads files instead of compiling, so tools/test-tools.sh can
# drive tools/mutation-table.sh locally. b_write rewrites a TRACKED file and, on a bad
# stamp, creates an UNTRACKED one; a_read fails if either leaks into a later run.
p=0; f=0
t() { if "$2"; then echo "test $1 ... ok"; p=$((p + 1)); else echo "test $1 ... FAILED"; f=$((f + 1)); fi; }
a_read() { [ "$(cat data.txt)" = ok ] && [ ! -e leak.tmp ]; }
b_write() { cat stamp.txt >data.txt; [ "$(cat stamp.txt)" = ok ] || { touch leak.tmp; return 1; }; }
c_add() { [ "$(cat add.txt)" = 5 ]; }
d_win() { [ "$(tr -d '\r' <win.txt | tr '\n' ,)" = a,b, ]; }
t tests::a_read a_read; t tests::b_write b_write; t tests::c_add c_add; t tests::d_win d_win
echo "test result: $([ $f = 0 ] && echo ok || echo FAILED). $p passed; $f failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s"
[ $f = 0 ]

View file

@ -0,0 +1 @@
1

View file

@ -0,0 +1,5 @@
# Mock vitest run. BROKEN in add.js is a module that does not load (file-level FAIL, no
# test name); WRONG is a real assertion failure.
if grep -q BROKEN add.js; then echo " FAIL add.js [ add.js ]"; echo " Test Files 1 failed (1)"; exit 1; fi
if grep -q WRONG add.js; then echo " FAIL add.js > adds"; echo " Tests 1 failed | 1 passed (2)"; exit 1; fi
echo " Tests 2 passed (2)"

View file

@ -0,0 +1,2 @@
a
b

View file

@ -6,37 +6,52 @@
# workdir directory inside the repo where the commands run (e.g.
# packages/cultcache-rs; CultLib has no Cargo.toml at its root).
# env TEST default test command for mutants with no `test:` line
# BUILD optional compile-only command; when it fails the mutant
# is UNVIABLE. Without it a mutant that does not compile
# BUILD optional compile-only command, run on the UNMUTATED
# tree first (a red or missing build aborts like
# BASELINE RED); when it fails on a mutant the mutant is
# UNVIABLE. Without it a mutant that does not compile
# has no failing test and reads ERROR, never CAUGHT.
# MUT_TIMEOUT seconds per build or test run (default 600)
# everything ygg-verify.sh reads (SUMMARY=<log>, TIMEOUT, MEM, ...)
# TIMEOUT seconds for the WHOLE job (ygg-verify's own cap;
# default 3600 here, stated in the START line). Size it
# to mutants x (build + test) plus the baselines.
# everything else ygg-verify.sh reads (SUMMARY=<log>, MEM, ...)
# Typical, from an agent: launch as ONE background shell with
# SUMMARY=<scratch>/mut1.log TEST='cargo test' tools/mutation-table.sh ...
# then `tools/stopgap/ygg-verify.sh wait <scratch>/mut1.log` in the foreground.
# then `tools/stopgap/ygg-verify.sh wait <scratch>/mut1.log` in the foreground,
# with a Bash tool timeout of at least 280000 ms.
#
# Mutants file (plain text; the text before the first `===` is ignored):
# === label-unique-in-the-file
# === label-unique-in-the-file (any text; `|` is allowed)
# file: src/lib.rs (relative to workdir)
# test: cargo test add_ (optional; else $TEST)
# --- before
# a + b (exact text, may span lines; must occur ONCE)
# a + b (exact text, may span lines; must occur ONCE;
# LF text also matches a CRLF file, a file
# with mixed endings may read NOAPPLY)
# --- after
# a - b
#
# Each mutant is applied in the container's throwaway clone and reverted from
# git before the next, so no tree you care about is touched. The output is one
# row per mutant: label | outcome | killing test or detail. Outcomes:
# Each mutant is applied in the container's throwaway clone. After every mutant
# the WHOLE tree is reset to HEAD and any untracked entry the run created is
# removed (entries that existed after the baselines, such as target/, stay); if
# the tree cannot be restored the job stops. A run that changed other files says
# so in its row. One row prints as each mutant finishes, so a job timeout keeps
# the finished rows. Row (a `YGG-SUMMARY/$YGG_NONCE: ` line, plain `YGG-SUMMARY: ` when no nonce is set): [i/N] label | outcome | killing test or detail. The
# outcome is stored as its own field and tallied from fields, never read back
# from the rendered row. Outcomes:
# CAUGHT the test command failed AND a failing test name was parsed from it
# SURVIVED the test command passed with the mutation applied
# UNVIABLE BUILD failed
# UNVIABLE BUILD failed, or a test file failed to load (vitest `FAIL <file>
# [ <file> ]` with no test name): nothing ran, not a kill
# TIMEOUT a run hit MUT_TIMEOUT (not a kill)
# NOAPPLY before text absent, ambiguous, or equal to after (no mutation made)
# ERROR the test command failed but no failing test was parsed (a build
# error without BUILD, a crash): not a kill
# Before any mutant, every distinct test command runs UNMUTATED. If one fails or
# runs zero tests the job aborts with `BASELINE RED`, because a red or empty
# baseline would make every mutant look killed or every one survive.
# Before any mutant, every distinct test command and BUILD run UNMUTATED. If one
# fails or a test command runs zero tests the job aborts with `BASELINE RED` or
# `BASELINE RAN ZERO TESTS`, because a red or empty baseline would make every
# mutant look killed or every one survive.
# Exit 0 means every mutant was CAUGHT or UNVIABLE and nothing else happened.
#
# DELETION LINE: this runner replaces the per-agent runmut/mutrun/strykrun
@ -55,18 +70,21 @@ if [ "${1:-}" != --in-container ]; then
cp "$here/testparse.sh" "$here/mutation-table.sh" "$stage/"
tr -d '\r' <"$mfile" >"$stage/mutants.txt"
bundle=$(tar -C "$stage" -cz testparse.sh mutation-table.sh mutants.txt | base64 | tr -d '\n')
cmd=$(printf 'mkdir -p /tmp/mt && echo %s | base64 -d | tar -xz -C /tmp/mt && WORKDIR=%q BUILD=%q TEST=%q MUT_TIMEOUT=%q bash /tmp/mt/mutation-table.sh --in-container' \
"$bundle" "$workdir" "${BUILD:-}" "${TEST:-}" "${MUT_TIMEOUT:-600}")
"$here/stopgap/ygg-verify.sh" "$repo" "$rev" "$image" "$cmd"
cmd=$(printf 'mkdir -p /tmp/mt && echo %s | base64 -d | tar -xz -C /tmp/mt && WORKDIR=%q BUILD=%q TEST=%q MUT_TIMEOUT=%q JOB_TIMEOUT=%q bash /tmp/mt/mutation-table.sh --in-container' \
"$bundle" "$workdir" "${BUILD:-}" "${TEST:-}" "${MUT_TIMEOUT:-600}" "${TIMEOUT:-3600}")
TIMEOUT=${TIMEOUT:-3600} "$here/stopgap/ygg-verify.sh" "$repo" "$rev" "$image" "$cmd"
exit $?
fi
# ---- container side ---------------------------------------------------------
set +e
SRC=${MT_SRC:-/src}; MT_DIR=${MT_DIR:-/tmp/mt} # overridable only so tools/test-tools.sh can run this half locally against a mock
# ygg-verify.sh mints a nonce per run and carries only lines tagged with it; unset (a local run), the plain tag is used
SUMTAG="YGG-SUMMARY${YGG_NONCE:+/$YGG_NONCE}"
# shellcheck source=testparse.sh
. /tmp/mt/testparse.sh
cd "/src/${WORKDIR:-.}" || { echo "YGG-SUMMARY: BAD WORKDIR ${WORKDIR:-.}"; exit 2; }
M=/tmp/mt/m; rm -rf "$M"; mkdir -p "$M"
. "$MT_DIR/testparse.sh"
cd "$SRC/${WORKDIR:-.}" || { echo "$SUMTAG: BAD WORKDIR ${WORKDIR:-.}"; exit 2; }
M="$MT_DIR/m"; rm -rf "$M"; mkdir -p "$M"
tmo=${MUT_TIMEOUT:-600}
if ! perl -e '
@ -91,32 +109,66 @@ if ! perl -e '
push @{$c{$sec}}, $_ if $sec;
}
flush(); die "no mutants in $mf\n" unless $n;
print "$n\n";' /tmp/mt/mutants.txt "$M" >"$M/count" 2>"$M/err"; then
echo "YGG-SUMMARY: BAD MUTANT FILE: $(cat "$M/err")"; exit 2
print "$n\n";' "$MT_DIR/mutants.txt" "$M" >"$M/count" 2>"$M/err"; then
echo "$SUMTAG: BAD MUTANT FILE: $(cat "$M/err")"; exit 2
fi
count=$(cat "$M/count")
echo "$SUMTAG: START $count mutants; per-run timeout ${tmo}s; whole-job timeout ${JOB_TIMEOUT:-unknown}s; one row per mutant follows as it finishes, so a timeout keeps the finished rows"
# run <command> <logfile>: prints the exit status; 124 means timeout
run() { timeout "$tmo" bash -o pipefail -c "$1" >"$2" 2>&1; echo $?; }
# The tree is the whole repository, not only the mutated file. A test or build
# that rewrites a tracked file would otherwise carry its pollution into the next
# mutant (a false CAUGHT, 2026-10-01). After every run, tracked state is reset
# to HEAD and any untracked entry that was not there after the baselines is
# removed. Entries present after the baselines (build output such as target/)
# are the baseline and stay, so builds stay incremental.
tree_state() { git -C "$SRC" status --porcelain 2>/dev/null; }
base_state=''
# restore: leaves the tree equal to HEAD plus the baseline entries; non-zero if it cannot.
restore() {
git -C "$SRC" reset -q --hard 2>/dev/null
tree_state | while IFS= read -r line; do
grep -qxF -- "$line" <<<"$base_state" || rm -rf -- "$SRC/${line:3}"
done
[ "$(tree_state)" = "$base_state" ]
}
# dirtied <mutated file>: what a run changed beyond the mutated file and the baseline
dirtied() {
local rel; rel=$(git -C "$SRC" ls-files --full-name -- "$1" 2>/dev/null | head -n 1)
tree_state | grep -vxF -- "$base_state" | grep -vF -- " $rel" | sed 's/^...//' | head -n 3 | paste -sd, -
}
declare -A based
for n in $(seq 1 "$count"); do
t=$(cat "$M/$n/test"); t=${t:-$TEST}
[ -n "$t" ] || { echo "YGG-SUMMARY: mutant $(cat "$M/$n/label") has no test: line and TEST is unset"; exit 2; }
[ -n "$t" ] || { echo "$SUMTAG: mutant $(cat "$M/$n/label") has no test: line and TEST is unset"; exit 2; }
[ -z "${based[$t]:-}" ] || continue
based[$t]=1
rc=$(run "$t" "$M/base.log")
scan=$(tp_scan "$M/base.log")
tests=$(printf '%s\n' "$scan" | awk '/^FRAMEWORK/{for(i=1;i<=NF;i++){split($i,a,"=");if(a[1]=="passed"||a[1]=="failed")s+=a[2]}}END{print s+0}')
if [ "$rc" != 0 ]; then
echo "YGG-SUMMARY: BASELINE RED (exit $rc) for: $t"; tail -n 15 "$M/base.log" | sed 's/^/YGG-SUMMARY: /'; exit 2
echo "$SUMTAG: BASELINE RED (exit $rc) for: $t"; tail -n 15 "$M/base.log" | sed "s|^|$SUMTAG: |"; exit 2
fi
if [ "$tests" -eq 0 ]; then
echo "YGG-SUMMARY: BASELINE RAN ZERO TESTS (or printed counts no parser reads) for: $t"; exit 2
echo "$SUMTAG: BASELINE RAN ZERO TESTS (or printed counts no parser reads) for: $t"; exit 2
fi
done
# BUILD runs unmutated too. A mistyped or missing build command fails every
# mutant, and a table of all-UNVIABLE rows reads as a fully killed suite.
if [ -n "${BUILD:-}" ]; then
rc=$(run "$BUILD" "$M/base.log")
if [ "$rc" != 0 ]; then
echo "$SUMTAG: BASELINE RED: BUILD failed on the unmutated tree (exit $rc; 124 is a timeout): $BUILD"
tail -n 15 "$M/base.log" | sed "s|^|$SUMTAG: |"; exit 2
fi
fi
# Baseline runs may dirty tracked files; settle that before the first mutant.
git -C "$SRC" reset -q --hard 2>/dev/null
base_state=$(tree_state)
: >"$M/rows"
for n in $(seq 1 "$count"); do
label=$(cat "$M/$n/label"); file=$(cat "$M/$n/file"); t=$(cat "$M/$n/test"); t=${t:-$TEST}
out=''; detail=''
@ -126,6 +178,8 @@ for n in $(seq 1 "$count"); do
open my $b, "<:raw", $bf; my $before = <$b> // ""; open my $a, "<:raw", $af; my $after = <$a> // "";
if (length($before) == 0) { print "empty before text\n"; exit 3 }
if ($before eq $after) { print "after equals before\n"; exit 3 }
# a CRLF file matches multi-line before text written with LF
if ($c =~ /\r\n/ && $before !~ /\r/) { s/\n/\r\n/g for $before, $after }
my ($cnt, $p) = (0, 0); while (($p = index($c, $before, $p)) >= 0) { $cnt++; $p += length($before) }
if ($cnt == 0) { print "before text not found\n"; exit 3 }
if ($cnt > 1) { print "before text occurs $cnt times; make it unique\n"; exit 3 }
@ -135,7 +189,7 @@ for n in $(seq 1 "$count"); do
elif git diff --quiet -- "$file"; then
out=NOAPPLY; detail="applied, but git sees no change in $file"
else
out=''
out=''; detail=''
if [ -n "${BUILD:-}" ]; then
rc=$(run "$BUILD" "$M/run.log")
if [ "$rc" = 124 ]; then out=TIMEOUT; detail="build exceeded ${tmo}s"
@ -147,21 +201,29 @@ for n in $(seq 1 "$count"); do
elif [ "$rc" = 124 ]; then out=TIMEOUT; detail="test exceeded ${tmo}s: $t"
else
names=$(tp_scan "$M/run.log" | grep '^FAILED ' | awk '!s[$0]++' | sed 's/^FAILED //')
if [ -n "$names" ]; then out=CAUGHT; detail=$(printf '%s\n' "$names" | head -n 1); k=$(printf '%s\n' "$names" | wc -l); [ "$k" -le 1 ] || detail="$detail (+$((k - 1)) more)"
# A file-level failure (vitest: "FAIL <file> [ <file> ]", no test name) is a
# module that did not load: a compile error, never a kill.
named=$(printf '%s\n' "$names" | grep -v -E '^[^ >]+ \[ .* \]$')
if [ -n "$named" ]; then
out=CAUGHT; detail=$(printf '%s\n' "$named" | head -n 1)
k=$(printf '%s\n' "$named" | wc -l); [ "$k" -le 1 ] || detail="$detail (+$((k - 1)) more)"
elif [ -n "$names" ]; then out=UNVIABLE; detail="a test file failed to load, no test ran: $(printf '%s\n' "$names" | head -n 1)"
else out=ERROR; detail="exit $rc, no failing test parsed: $(tail -n 1 "$M/run.log" | cut -c1-120)"; fi
fi
fi
extra=$(dirtied "$file"); [ -z "$extra" ] || detail="$detail [run also changed: $extra; restored]"
fi
# The outcome is its own field. It is never recovered from rendered text, so a
# label or a test name containing " | CAUGHT | " cannot forge a kill.
printf '%s' "$out" >"$M/$n/outcome"
detail=${detail//$'\n'/ }
printf '%s: [%s/%s] %s | %s | %s\n' "$SUMTAG" "$n" "$count" "${label//|/\\|}" "$out" "$detail"
if ! restore; then
echo "$SUMTAG: RESTORE FAILED after $label: the tree differs from the baseline; stopping. Status: $(tree_state | head -n 5 | paste -sd';' -)"; exit 2
fi
printf '%s | %s | %s\n' "$label" "$out" "$detail" >>"$M/rows"
git checkout -q -- "$file"
if ! git diff --quiet -- "$file"; then echo "YGG-SUMMARY: RESTORE FAILED for $file after $label; stopping"; cat "$M/rows" | sed 's/^/YGG-SUMMARY: /'; exit 2; fi
done
tally() { grep -c " | $1 | " "$M/rows" || true; }
bad=$(grep -vc -E ' \| (CAUGHT|UNVIABLE) \| ' "$M/rows" || true)
{
echo "MUTATION $count mutants: caught=$(tally CAUGHT) survived=$(tally SURVIVED) unviable=$(tally UNVIABLE) timeout=$(tally TIMEOUT) noapply=$(tally NOAPPLY) error=$(tally ERROR) (baseline green, tests ran)"
grep -v ' | CAUGHT | ' "$M/rows"
grep ' | CAUGHT | ' "$M/rows"
} | sed 's/^/YGG-SUMMARY: /'
[ "$bad" -eq 0 ]
tally() { local c=0 f; for f in "$M"/*/outcome; do [ "$(cat "$f")" = "$1" ] && c=$((c + 1)); done; echo "$c"; }
caught=$(tally CAUGHT); unviable=$(tally UNVIABLE)
echo "$SUMTAG: MUTATION $count mutants: caught=$caught survived=$(tally SURVIVED) unviable=$unviable timeout=$(tally TIMEOUT) noapply=$(tally NOAPPLY) error=$(tally ERROR) (baseline green, tests ran)"
[ $((caught + unviable)) -eq "$count" ]

View file

@ -35,4 +35,53 @@ check pytest-red.log 1 "FAILED tests/test_add.py::test_carries"
check exit0-but-failed.log 0 "MISMATCH: exit 0 but the log shows"
check no-verdict.log 97 "NO VERDICT"
check no-verdict.log 97 "RED" "GREEN"
# ---- tools/mutation-table.sh, container half, against the mock in
# fixtures/mutation-mock (shell scripts that print cargo/vitest-shaped output).
# One case per finding of the 2026-10-01 Soul pass; each fails if it regresses.
mt() { # mt <mutants file> <TEST> [BUILD]: sets mt_out, mt_rc, mt_repo
local root; root=$(mktemp -d); mt_repo=$root/repo; mkdir -p "$mt_repo" "$root/mt"
cp -r "$here/fixtures/mutation-mock/." "$mt_repo/"
git -C "$mt_repo" init -q && git -C "$mt_repo" add -A && git -C "$mt_repo" -c user.name=t -c user.email=t@t commit -qm mock
cp "$here/testparse.sh" "$root/mt/"; cp "$here/fixtures/mutation-mock/$1" "$root/mt/mutants.txt"
mt_out=$(MT_SRC=$mt_repo MT_DIR=$root/mt TEST=$2 BUILD=${3:-} MUT_TIMEOUT=${MT_TO:-15} timeout "${MT_WALL:-120}" bash "$here/mutation-table.sh" --in-container 2>&1)
mt_rc=$?
}
mtcheck() { # mtcheck <name> <must-contain | !must-not-contain>...
local name=$1 s; shift
for s in "$@"; do
case $s in
'!'*) if printf '%s\n' "$mt_out" | grep -qF -- "${s#!}"; then echo "FAIL mutation $name: must not contain: ${s#!}"; fail=1; return; fi ;;
*) printf '%s\n' "$mt_out" | grep -qF -- "$s" || { echo "FAIL mutation $name: missing: $s"; printf '%s\n' "$mt_out" | tail -n 12; fail=1; return; } ;;
esac
done
echo "ok mutation $name"
}
# A: a mistyped BUILD must abort, not read as a fully killed suite
mt mutants-a.txt 'bash test.sh' 'bash bulid.sh'
[ "$mt_rc" = 2 ] || { echo "FAIL mutation A: exit $mt_rc, want 2"; fail=1; }
mtcheck A-build-baseline "BASELINE RED: BUILD failed" "!UNVIABLE"
# B: a label that spells a kill must not forge one
mt mutants-b.txt 'bash test.sh'
[ "$mt_rc" = 1 ] || { echo "FAIL mutation B: exit $mt_rc, want 1"; fail=1; }
mtcheck B-label-forge "caught=0 survived=1" 'forge \| CAUGHT \| label | SURVIVED |'
# the nonce form ygg-verify.sh carries, and the plain form when no nonce is set
YGG_NONCE=n0nce1 mt mutants-b.txt 'bash test.sh'
mtcheck B-nonce "YGG-SUMMARY/n0nce1: [1/1] " "!YGG-SUMMARY: "
# C: a test that rewrites a tracked file or leaks an untracked one must not decide the next mutant
mt mutants-c.txt 'bash test.sh'
mtcheck C-pollution "stamp-bad | CAUGHT | tests::b_write" "also changed: data.txt,leak.tmp" "untested-equiv | SURVIVED" "!untested-equiv | CAUGHT"
[ -z "$(git -C "$mt_repo" status --porcelain)" ] || { echo "FAIL mutation C: tree not restored"; fail=1; }
# D: a test file that fails to load is not a kill; a named failing test is
mt mutants-d.txt 'bash vtest.sh'
mtcheck D-import-failure "syntax-break | UNVIABLE" "wrong-result | CAUGHT | add.js > adds" "caught=1 survived=0 unviable=1"
# E: rows print as mutants finish, so a job timeout keeps them
MT_WALL=8 mt mutants-e.txt 'bash test.sh'
mtcheck E-live-rows "[1/2] quick | CAUGHT" "!MUTATION"
# F: LF before-text matches a CRLF file
mt mutants-f.txt 'bash test.sh'
mtcheck F-crlf "crlf-multiline | CAUGHT | tests::d_win"
# a real BUILD failure on a mutant is still UNVIABLE
mt mutants-g.txt 'bash test.sh' 'bash build.sh'
mtcheck build-unviable "build-break | UNVIABLE | build exit 1" "unviable=1"
exit $fail