textmachine/platform/docs/p8-review/axis4-metrics/60-mutations.sh

52 lines
3.2 KiB
Bash
Executable file

#!/usr/bin/env bash
case "${P8_COPY:-}" in *projects/textmachine*) echo "refusing to mutate the live repository"; exit 2;; esac
# ⚠ Путь копии параметризован при сдаче пака: задайте P8_COPY=/path/to/copy/platform.
# A4/metrics — the six mutations of the axis, planted and reverted in the REVIEW COPY of the tree
# (never in the repository). Each one breaks an invariant the code or STACK_DECISIONS §24/§25 names,
# and the script prints whether the battery reddens.
#
# A1 the stalled-run gauge is always 0 (= PD-346's failure mode) -> SURVIVES
# A2 a pass that ran out of time never says so (= PD-351's failure mode) -> SURVIVES
# A3 queue_depth and live_runs are swapped -> SURVIVES
# B the route label carries the raw path (§24 cardinality) -> caught
# C the recorder loses Unwrap (§25's own claimed mutation) -> caught
# D the method label is the caller's token verbatim (PD-184) -> caught
#
# A1..A3 live in cmd/tmplatformd/runner.go, which no test in the battery touches: run with
# FULL=1 to spend the ~3.5 minutes proving it over `make check` instead of the two packages.
set -uo pipefail
P=${P8_COPY:?set P8_COPY to a COPY of platform/}
export TM_PLATFORM_TEST_DSN="postgres://postgres@/tmp8rev_a4?host=/tmp&port=55433&sslmode=disable"
export TM_PLATFORM_TEST_ENGINE_BIN=$HOME/tmstand-work/tmctl TM_PLATFORM_TEST_BOOK_TEMPLATE=$HOME/tmstand-work/book-template.yaml
cd "$P"
R=cmd/tmplatformd/runner.go; M=internal/metrics/metrics.go
cp $R /tmp/a4.runner.bak; cp $M /tmp/a4.metrics.bak
revert() { cp /tmp/a4.runner.bak $R; cp /tmp/a4.metrics.bak $M; }
trap revert EXIT
run() { echo "--- $*"; if [ "${FULL:-0}" = 1 ]; then make check 2>&1 | grep -E '^(FAIL|--- FAIL|ok)' ; else go test "$@" -count=1 2>&1 | grep -E '^(ok|FAIL|--- FAIL)'; fi; }
echo "=== A1+A2+A3: the telemetry seam (observe + pass) ==="
sed -i 's/StalledRuns: o.StalledRuns,/StalledRuns: 0,/' $R
sed -i 's/s.metrics.ObserveSweep(name, time.Since(start), errors.Is(err, context.DeadlineExceeded))/s.metrics.ObserveSweep(name, time.Since(start), false)/' $R
sed -i 's/QueueDepth: o.QueueDepth,/QueueDepth: o.LiveRuns,/' $R
sed -i 's/LiveRuns: o.LiveRuns,/LiveRuns: o.QueueDepth,/' $R
grep -n "StalledRuns: 0\|ObserveSweep(name, time.Since(start), false)\|QueueDepth: o.LiveRuns" $R
run ./cmd/tmplatformd/ ./internal/metrics/ ./internal/runs/
revert
echo "=== B: the route label carries the raw path ==="
sed -i 's/route := r.Pattern/route := r.URL.Path/' $M
run ./internal/metrics/ ./internal/httpapi/
revert
echo "=== C: the recorder loses Unwrap ==="
sed -i 's|^func (r \*recorder) Unwrap() http.ResponseWriter { return r.ResponseWriter }|// mutation A4-C: Unwrap removed|' $M
run ./internal/metrics/ ./internal/httpapi/
revert
echo "=== D: the method label is the caller's token ==="
sed -i 's/method := knownMethod(r.Method)/method := r.Method/' $M
run ./internal/metrics/
revert
echo "=== tree restored ==="; diff -r --brief /home/ubuntu-26/projects/textmachine/platform "$P" | grep -v "^Only in /home/ubuntu-26/projects" || echo "identical to the repository"