chore(autoresearch): re-baseline harness on pinned real-risk yardstick

The committed golangci gate now reports 0 issues, so the previous
lint_issues metric was saturated and could no longer measure progress.
Measure debt against an immutable .auto/lint.ref.yaml snapshot that adds
analyzers for genuine defects (panics, error unwrapping, dead stores,
missing enum cases, method ordering, suppression hygiene) while excluding
cosmetic churn (tagliatelle, wrapcheck). Guard enforces build, vet, tests,
the Cordis architecture gate, and anti-cheat floors: the yardstick cannot
be edited, the project gate may only be strengthened, nolint directives may
only shrink, and no test may disappear.
This commit is contained in:
ryan
2026-08-29 07:52:03 +08:00
parent 4f30e2d57b
commit 5971e2a9ed
8 changed files with 404 additions and 20 deletions
+31 -11
View File
@@ -1,18 +1,38 @@
#!/bin/bash
# Autoresearch measure: golangci-lint issue count (primary) + dupl subset + test packages
set -euo pipefail
# Autoresearch measure — pinned yardstick.
# debt : findings under .auto/lint.ref.yaml (lower is better) [PRIMARY]
# nolint_dirs : raw //nolint directive count (lower is better, floor 0)
# tests_passed : go test packages passing (floor, must never drop)
# test_funcs : total Test*/Benchmark* funcs (floor, must never drop)
# arch_viol : Cordis architecture script violations (floor 0)
# coverage : backend statement coverage % (informational)
set -uo pipefail
cd "$(dirname "$0")/../backend"
# Primary metric: total golangci-lint issues (non-test code)
golangci-lint run > /tmp/ar_lint.txt 2>&1 || true
LINT_ISSUES=$(grep -cE '(^|[/\\])[^/\\:]+\.go:[0-9]+:' /tmp/ar_lint.txt || true)
REF_CFG="$(cd .. && pwd)/.auto/lint.ref.yaml"
# Secondary: dupl-specific issues
DUP_ISSUES=$(grep -cE '\(dupl\)$' /tmp/ar_lint.txt || true)
# Primary: pinned yardstick findings (never the mutable project config).
golangci-lint run -c "${REF_CFG}" > /tmp/ar_debt.txt 2>&1 || true
DEBT=$(grep -cE '\.go:[0-9]+:[0-9]+: ' /tmp/ar_debt.txt || true)
# Secondary: passing test packages (regression guard)
TESTS_PASSED=$(go test ./... 2>&1 | grep -c '^ok' || true)
# Suppression reliance — anti-cheat signal.
NOLINT=$(rg '//\s*nolint' --glob '*.go' 2>/dev/null | wc -l | tr -d ' ')
echo "METRIC lint_issues=${LINT_ISSUES}"
echo "METRIC dup_issues=${DUP_ISSUES}"
# Regression floors. One covered run feeds both the pass floor and coverage.
go test -cover ./... > /tmp/ar_test.txt 2>&1 || true
TESTS_PASSED=$(grep -c '^ok' /tmp/ar_test.txt || true)
FAILS=$(grep -cE '^(FAIL|--- FAIL)' /tmp/ar_test.txt || true)
TEST_FUNCS=$(rg -c '^(func Test|func Benchmark)' --glob '*_test.go' 2>/dev/null | awk -F: '{s+=$2} END {print s+0}')
# Cordis architecture violations (count of FAIL lines emitted by the gate script).
ARCH_VIOL=$("../scripts/check_cordis_architecture.sh" 2>&1 | grep -c 'FAIL' || true)
COVERAGE=$(grep -oE 'coverage: [0-9.]+%' /tmp/ar_test.txt | awk '{gsub("%","",$2); s+=$2; n++} END {if(n>0) printf "%.2f", s/n; else print "0"}')
echo "METRIC debt=${DEBT}"
echo "METRIC nolint_dirs=${NOLINT}"
echo "METRIC tests_passed=${TESTS_PASSED}"
echo "METRIC test_funcs=${TEST_FUNCS}"
echo "METRIC arch_viol=${ARCH_VIOL}"
echo "METRIC coverage=${COVERAGE}"
echo "INFO test_failures=${FAILS}"