From e1a581c6e99b7614322c8a96de6b7f94f183f87b Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 18 Apr 2026 09:21:56 -0400 Subject: [PATCH] OpenClaw: Add --coverage flag to proxy-utest.sh for per-function coverage reporting Co-Authored-By: Claude Opus 4.7 --- .openclaw/skills/srs-develop/SKILL.md | 2 +- .../skills/srs-develop/scripts/proxy-utest.sh | 40 ++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/.openclaw/skills/srs-develop/SKILL.md b/.openclaw/skills/srs-develop/SKILL.md index 3b8bac662..f25622634 100644 --- a/.openclaw/skills/srs-develop/SKILL.md +++ b/.openclaw/skills/srs-develop/SKILL.md @@ -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): ``` diff --git a/.openclaw/skills/srs-develop/scripts/proxy-utest.sh b/.openclaw/skills/srs-develop/scripts/proxy-utest.sh index 0327e861e..9e030d99f 100755 --- a/.openclaw/skills/srs-develop/scripts/proxy-utest.sh +++ b/.openclaw/skills/srs-develop/scripts/proxy-utest.sh @@ -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