Files
boshu2__agentops/scripts/check-cmd-ao-coverage.sh
T
Boden Fuller c971679901 fix(ci): ratchet cmd/ao coverage floor 75→76 (soc-wxh5.1)
Cycle 170 of the v2.41-evolve-run loop. Real cmd/ao statement coverage
climbed to 76.1% (23553/30953) on the v2.41-evolve-run baseline — the
soc-wxh5.1 climb-back tracker is satisfied. Bumping MIN_COVERAGE in
scripts/check-cmd-ao-coverage.sh back to 76 in lockstep with reality,
where it was before the cycle-60 recalibration to 75.

Drive-by: documented the .agents/operator/ write surface introduced by
the BC4 OperatorPort adapters (cli/cmd/ao/operator_adapter.go +
operator_cmd.go) under docs/contracts/agents-write-surfaces.md — both
the allowlist entry and the classification table row. Required to
clear scripts/pre-push-gate.sh --fast.

Closes soc-wxh5.1.
2026-05-13 22:55:54 -04:00

103 lines
3.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# check-cmd-ao-coverage.sh — Enforce a per-package coverage floor for
# cli/cmd/ao. Reads an existing Go coverage profile (default cli/coverage.out)
# rather than re-running the test suite, so it composes with the existing
# `go test -coverprofile=coverage.out -covermode=atomic ./...` step in CI.
#
# Threshold ratchet: cmd/ao was 76.8% statement-weighted against the
# full-suite coverage.out on 2026-04-15. By 2026-05-12 actual coverage
# had drifted down to 75.7% — a 1pp regression that kept go-build red
# across cycles 49-59. Floor was recalibrated 76→75 on 2026-05-12 to
# unblock go-build, with soc-wxh5.1 tracking the climb back. Cycle 170
# (2026-05-13) ratchets the floor back to 76 after actual coverage
# climbed to 76.1% (23553/30953) on the v2.41-evolve-run baseline.
# Source epic `evolve-cycle-6-coverage-85pct` is driving this to 85%.
# Each time real coverage rises, bump MIN_COVERAGE here in lockstep;
# never lower without an explicit recalibration cycle that files
# paired bd work.
#
# Usage:
# scripts/check-cmd-ao-coverage.sh # default profile + threshold
# scripts/check-cmd-ao-coverage.sh --profile path/to.out
# scripts/check-cmd-ao-coverage.sh --min 80
# MIN_COVERAGE=80 scripts/check-cmd-ao-coverage.sh
#
# Exits 0 on pass, 1 on shortfall, 2 on misuse / missing profile.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
PROFILE="${COVERAGE_PROFILE:-$REPO_ROOT/cli/coverage.out}"
MIN_COVERAGE="${MIN_COVERAGE:-76}"
PKG_PREFIX="github.com/boshu2/agentops/cli/cmd/ao/"
while [[ $# -gt 0 ]]; do
case "$1" in
--profile)
PROFILE="$2"
shift 2
;;
--min)
MIN_COVERAGE="$2"
shift 2
;;
-h|--help)
sed -n '3,20p' "$0"
exit 0
;;
*)
echo "ERROR: unknown argument: $1" >&2
exit 2
;;
esac
done
if [[ ! -f "$PROFILE" ]]; then
echo "ERROR: coverage profile not found at $PROFILE" >&2
echo "Hint: run 'cd cli && go test -coverprofile=coverage.out -covermode=atomic ./...' first." >&2
exit 2
fi
# Filter the profile to lines whose source path starts with the cmd/ao package
# prefix, then aggregate covered/total statements. The Go cover profile format
# is space-separated:
#
# mode: atomic
# <import-path>/<file>.go:<startLine>.<startCol>,<endLine>.<endCol> <numStmt> <count>
#
# So $1 is the location, $2 is numStmt, $3 is execution count.
stats=$(
awk -v prefix="$PKG_PREFIX" '
index($1, prefix) == 1 {
n = $2 + 0
total += n
if ($3 + 0 > 0) covered += n
}
END { printf "%d %d\n", covered+0, total+0 }
' "$PROFILE"
)
covered=${stats% *}
total=${stats#* }
if [[ "$total" -eq 0 ]]; then
echo "ERROR: no statements found for package prefix $PKG_PREFIX in $PROFILE" >&2
echo "Hint: ensure the test run included ./cmd/ao/..." >&2
exit 2
fi
pct=$(awk -v c="$covered" -v t="$total" 'BEGIN { printf "%.1f", (c / t) * 100 }')
pct_int=$(awk -v c="$covered" -v t="$total" 'BEGIN { printf "%d", (c * 100) / t }')
echo "cmd/ao coverage: ${pct}% (${covered}/${total} statements, threshold: ${MIN_COVERAGE}%)"
if [[ "$pct_int" -lt "$MIN_COVERAGE" ]]; then
echo "FAIL: cmd/ao coverage ${pct}% is below the ${MIN_COVERAGE}% floor."
echo " Add tests under cli/cmd/ao/ until coverage clears the gate, or"
echo " bump MIN_COVERAGE in scripts/check-cmd-ao-coverage.sh if the floor was raised intentionally."
exit 1
fi
echo "PASS: cmd/ao coverage ${pct}% meets ${MIN_COVERAGE}% floor."