#!/usr/bin/env bash
# kitsubito gate legs for PR #217 @ 1ebd03dc: clippy, brain-read-check (clean), mutant proof, restore, xtask check, nextest xtask.
source ~/.cargo/env
R=~/spt-core-gate-w2; O=~/gate-293c-out; cd "$R" || exit 99
SHA=1ebd03dcd66fcc794ed86b16cefb88621f01f045
git fetch -q /tmp/217b.bundle refs/gate/217b:refs/gate/217b || { echo 98 > $O/legs217b.exit; exit 98; }
git checkout -q --detach $SHA || { echo 97 > $O/legs217b.exit; exit 97; }
echo "HEAD $(git rev-parse HEAD) dirty=$(git status --short | wc -l) $(date -u +%H:%M:%SZ)" > $O/legs217b.log
cargo clippy --workspace --all-targets -- -D warnings > $O/b-clippy.raw 2>&1; echo $? > $O/b-clippy.exit
cargo run -q -p xtask -- brain-read-check > $O/b-clean.raw 2>&1; echo $? > $O/b-clean.exit
# MUTANT: one feed back to call_deadline (serve_registry_feed), assert the mutation LANDED, verb must exit 1 naming it.
python3 - <<'PY'
import io,re
p='crates/spt-daemon/src/dispatch.rs'; d=io.open(p,'rb').read()
i=d.find(b'fn serve_registry_feed'); assert i>0
j=d.find(b'let deadline: Option<Instant> = None;', i); assert j>0 and j-i<4000, (i,j)
d2=d[:j]+b'let deadline = brain.call_deadline();'+d[j+len(b'let deadline: Option<Instant> = None;'):]
io.open(p,'wb').write(d2); print('MUTATION LANDED at byte',j)
PY
git diff --stat >> $O/legs217b.log
cargo run -q -p xtask -- brain-read-check > $O/b-mutant.raw 2>&1; echo $? > $O/b-mutant.exit
git checkout -q -- crates/spt-daemon/src/dispatch.rs
echo "restored dirty=$(git status --short | wc -l)" >> $O/legs217b.log
cargo run -q -p xtask -- brain-read-check > $O/b-restored.raw 2>&1; echo $? > $O/b-restored.exit
cargo run -q -p xtask -- check > $O/b-xcheck.raw 2>&1; echo $? > $O/b-xcheck.exit
git status --short >> $O/legs217b.log
cargo nextest run -p xtask -E "kind(bin)" --no-fail-fast > $O/b-nextest.raw 2>&1; echo $? > $O/b-nextest.exit
echo "DONE $(date -u +%H:%M:%SZ)" >> $O/legs217b.log
echo 0 > $O/legs217b.exit
