OpenClaw: Add --coverage flag to proxy-utest.sh for per-function coverage reporting

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
winlin 2026-04-18 09:21:56 -04:00
parent 460412c4b5
commit e1a581c6e9
2 changed files with 39 additions and 3 deletions

View File

@ -107,7 +107,7 @@ Only after the user confirms the routing do you proceed to Step 2.
1. Implement the code change.
2. Run the proxy unit tests to verify:
```
bash scripts/proxy-utest.sh
bash scripts/proxy-utest.sh --coverage
```
3. Run the proxy E2E test (starts proxy + SRS origin, publishes RTMP, verifies playback):
```

View File

@ -2,6 +2,30 @@
# Run unit tests for the proxy server (cmd/ and internal/ packages).
set -e
usage() {
cat <<'EOF'
Run unit tests for the proxy server (cmd/ and internal/ packages).
Usage:
proxy-utest.sh # run tests
proxy-utest.sh --coverage # run tests and print per-function coverage
proxy-utest.sh -c # short form of --coverage
EOF
}
COVERAGE=0
for arg in "$@"; do
case "$arg" in
-c|--coverage) COVERAGE=1 ;;
-h|--help) usage; exit 0 ;;
*)
echo "Error: unknown argument: $arg" >&2
usage >&2
exit 2
;;
esac
done
SCRIPT_DIR="$(cd -P "$(dirname "$0")" && pwd)"
# Navigate: scripts/ -> srs-develop/ -> skills/ -> .openclaw/ -> srs
WORKSPACE="$(cd -P "$SCRIPT_DIR/../../../.." && pwd)"
@ -12,6 +36,18 @@ if [[ ! -f "$WORKSPACE/go.mod" ]]; then
fi
cd "$WORKSPACE"
echo "Running proxy unit tests in: $WORKSPACE"
go test ./cmd/... ./internal/... -v
PACKAGES=(./cmd/... ./internal/...)
if [[ $COVERAGE -eq 1 ]]; then
COVER_FILE="$(mktemp -t proxy-utest-coverage.XXXXXX.out)"
trap 'rm -f "$COVER_FILE"' EXIT
echo "Running proxy unit tests with coverage in: $WORKSPACE"
go test "${PACKAGES[@]}" -v -coverprofile="$COVER_FILE" -coverpkg=./cmd/...,./internal/...
echo
echo "=== Coverage (per function) ==="
go tool cover -func="$COVER_FILE"
else
echo "Running proxy unit tests in: $WORKSPACE"
go test "${PACKAGES[@]}" -v
fi