fix(09): WR-18 judge the gate's zero-test check per package
This commit is contained in:
@@ -22,11 +22,15 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
# phase9_detect reads go test -json. Exit 1 fail, 2 skip, 3 zero tests.
|
# phase9_detect reads go test -json. Exit 1 fail, 2 skip, 3 zero tests.
|
||||||
|
# Zero tests is judged per package: every package the run reports on must pass
|
||||||
|
# at least one test, so a package whose tests were renamed or deleted cannot
|
||||||
|
# hide behind a passing test in another package of the same invocation.
|
||||||
phase9_detect() {
|
phase9_detect() {
|
||||||
python3 - "$1" <<'PY'
|
python3 - "$1" <<'PY'
|
||||||
import json, sys
|
import json, sys
|
||||||
path = sys.argv[1]
|
path = sys.argv[1]
|
||||||
saw = False
|
pkgs = set()
|
||||||
|
passed = set()
|
||||||
with open(path, encoding="utf-8", errors="replace") as fh:
|
with open(path, encoding="utf-8", errors="replace") as fh:
|
||||||
for raw in fh:
|
for raw in fh:
|
||||||
line = raw.strip()
|
line = raw.strip()
|
||||||
@@ -39,6 +43,9 @@ with open(path, encoding="utf-8", errors="replace") as fh:
|
|||||||
sys.exit(4)
|
sys.exit(4)
|
||||||
action = ev.get("Action")
|
action = ev.get("Action")
|
||||||
test = ev.get("Test") or ""
|
test = ev.get("Test") or ""
|
||||||
|
pkg = ev.get("Package") or ""
|
||||||
|
if pkg:
|
||||||
|
pkgs.add(pkg)
|
||||||
if action == "skip" and test:
|
if action == "skip" and test:
|
||||||
print(f"refuse: skipped {test}", file=sys.stderr)
|
print(f"refuse: skipped {test}", file=sys.stderr)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
@@ -47,10 +54,14 @@ with open(path, encoding="utf-8", errors="replace") as fh:
|
|||||||
print(f"refuse: failed {name}", file=sys.stderr)
|
print(f"refuse: failed {name}", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if action == "pass" and test:
|
if action == "pass" and test:
|
||||||
saw = True
|
passed.add(pkg)
|
||||||
if not saw:
|
if not passed:
|
||||||
print("refuse: zero tests", file=sys.stderr)
|
print("refuse: zero tests", file=sys.stderr)
|
||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
|
empty = sorted(pkgs - passed)
|
||||||
|
if empty:
|
||||||
|
print("refuse: zero tests in " + ", ".join(empty), file=sys.stderr)
|
||||||
|
sys.exit(3)
|
||||||
PY
|
PY
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,10 +110,16 @@ run_self_test() {
|
|||||||
log="$(mktemp)"
|
log="$(mktemp)"
|
||||||
printf '%s\n' '{"Action":"pass","Test":"TestPhase09GuardIsolation"}' >"$log"
|
printf '%s\n' '{"Action":"pass","Test":"TestPhase09GuardIsolation"}' >"$log"
|
||||||
phase9_detect "$log"
|
phase9_detect "$log"
|
||||||
|
printf '%s\n' '{"Action":"pass","Package":"a/bouncer","Test":"TestPhase09A"}' '{"Action":"pass","Package":"a/bouncer"}' '{"Action":"pass","Package":"a/cabana","Test":"TestPhase09B"}' '{"Action":"pass","Package":"a/cabana"}' >"$log"
|
||||||
|
phase9_detect "$log"
|
||||||
rm -f "$log"
|
rm -f "$log"
|
||||||
expect_detect_fails skip '{"Action":"skip","Test":"TestPhase09MigrationsFreshRollback"}'
|
expect_detect_fails skip '{"Action":"skip","Test":"TestPhase09MigrationsFreshRollback"}'
|
||||||
expect_detect_fails zero '{"Action":"pass","Package":"git.golem15.com/golem15/summercms/modules/lagoon"}'
|
expect_detect_fails zero '{"Action":"pass","Package":"git.golem15.com/golem15/summercms/modules/lagoon"}'
|
||||||
expect_detect_fails fail '{"Action":"fail","Test":"TestPhase09ContractInventory"}'
|
expect_detect_fails fail '{"Action":"fail","Test":"TestPhase09ContractInventory"}'
|
||||||
|
# One package passes a test, the other reports none: still a refusal.
|
||||||
|
expect_detect_fails zero-in-one-package '{"Action":"pass","Package":"a/bouncer","Test":"TestPhase09A"}
|
||||||
|
{"Action":"pass","Package":"a/bouncer"}
|
||||||
|
{"Action":"pass","Package":"a/cabana"}'
|
||||||
for flag in --self-test --security --postgres --openapi --evidence --all; do
|
for flag in --self-test --security --postgres --openapi --evidence --all; do
|
||||||
grep -q -- "$flag" "${BASH_SOURCE[0]}" || {
|
grep -q -- "$flag" "${BASH_SOURCE[0]}" || {
|
||||||
echo "refuse: missing mode $flag" >&2
|
echo "refuse: missing mode $flag" >&2
|
||||||
|
|||||||
Reference in New Issue
Block a user