From e707f3eae7bfdd23363ae77d08c594d6ae414b60 Mon Sep 17 00:00:00 2001 From: Kazutomo Deguchi Date: Thu, 2 Jul 2026 14:56:47 +0900 Subject: [PATCH 1/2] ci: compute coverage gate from profile, not 'go tool cover -func' total MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 'go tool cover -func | grep ^total' under-counts uncovered blocks inside function literals (e.g. the cobra RunE: closure), reporting a higher percentage than real statement coverage. On a gappy cmd/colref profile the old metric read 98.3% while go test -cover reported the true 97.3%, so a func-literal gap could pass the 100% gate unnoticed — which is exactly how the RunE validateFormat error branch stayed uncovered. Compute the total directly from the profile (executed statements / total statements), matching go test -cover. The honest metric then exposed that uncovered validateFormat branch, so add TestCheckCmd_RunE_InvalidFormat to close it and keep the gate green at a real 100%. Closes #218 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f581236..1a20182 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ check-coverage: ## Run tests with coverage and enforce minimum threshold @coverage_file=$$(mktemp); \ trap 'rm -f "$$coverage_file"' EXIT; \ $(GOTEST) $$(go list ./... | grep -v /e2e) -coverprofile="$$coverage_file"; \ - total=$$($(GOCMD) tool cover -func="$$coverage_file" | grep '^total' | awk '{print $$3}' | tr -d '%'); \ + total=$$(awk 'NR>1 { tot+=$$2; if ($$3>0) cov+=$$2 } END { if (tot>0) printf "%.1f", 100*cov/tot; else print "0.0" }' "$$coverage_file"); \ echo "Total coverage: $${total}%"; \ if ! awk "BEGIN { exit !($$total >= $(COVERAGE_THRESHOLD)) }"; then \ echo "FAIL: coverage $${total}% is below threshold $(COVERAGE_THRESHOLD)%"; exit 1; \ From e40213e3be5ec551f6ee2c6913b4ad3697d9e094 Mon Sep 17 00:00:00 2001 From: Kazutomo Deguchi Date: Thu, 2 Jul 2026 17:04:02 +0900 Subject: [PATCH 2/2] ci: fail check-coverage on test failure; assert --format error message Address Copilot review on #219: - The check-coverage recipe is one ;-joined shell block ending in 'echo Coverage OK' (exit 0), so a go test *failure* (which still yields a full-coverage profile) was masked. Add 'set -e' so a non-zero go test aborts the target. Verified end-to-end: an injected failing test makes 'make check-coverage' exit non-zero without printing 'Coverage OK'. - TestCheckCmd_RunE_InvalidFormat now asserts the error message contains the --format validation failure, verifying that path specifically rather than accepting any error. --- Makefile | 3 ++- cmd/colref/check_test.go | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 1a20182..b225e02 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,8 @@ update-golden: build-e2e ## Regenerate golden files for pattern battery tests check-coverage: ## Run tests with coverage and enforce minimum threshold @echo "Running tests with coverage (threshold: $(COVERAGE_THRESHOLD)%)..." - @coverage_file=$$(mktemp); \ + @set -e; \ + coverage_file=$$(mktemp); \ trap 'rm -f "$$coverage_file"' EXIT; \ $(GOTEST) $$(go list ./... | grep -v /e2e) -coverprofile="$$coverage_file"; \ total=$$(awk 'NR>1 { tot+=$$2; if ($$3>0) cov+=$$2 } END { if (tot>0) printf "%.1f", 100*cov/tot; else print "0.0" }' "$$coverage_file"); \ diff --git a/cmd/colref/check_test.go b/cmd/colref/check_test.go index 32b667b..cabf035 100644 --- a/cmd/colref/check_test.go +++ b/cmd/colref/check_test.go @@ -790,9 +790,13 @@ func TestCheckCmd_RunE_InvalidFormat(t *testing.T) { "--orm", "django", "--format", "xml", }) - if err := rootCmd.Execute(); err == nil { + err := rootCmd.Execute() + if err == nil { t.Fatal("expected error for invalid --format") } + if !strings.Contains(err.Error(), `unknown --format "xml"`) { + t.Fatalf("error is not the --format validation failure: %v", err) + } } func TestCheckCmd_RunE_InvalidColor(t *testing.T) {