test(e2e): guard staging orphan cleanup coverage
ci-arm64-advisory / fast-checks (push) Waiting to run
Block internal-flavored paths / Block forbidden paths (push) Successful in 5s
CI / Python Lint & Test (push) Successful in 7s
Lint shellcheck (arm64 pilot) / shellcheck-arm64 (pilot) (push) Successful in 10s
CI / Detect changes (push) Successful in 13s
Handlers Postgres Integration / detect-changes (push) Successful in 13s
E2E Chat / detect-changes (push) Successful in 22s
Lint forbidden tenant-env keys / Scan workspace_secrets writers for forbidden env keys (push) Successful in 16s
E2E Staging Canvas (Playwright) / detect-changes (push) Successful in 20s
E2E API Smoke Test / detect-changes (push) Successful in 23s
Lint no tenant GITEA or GITHUB token write / Scan for repo-host token write into tenant workspace surface (push) Successful in 11s
Secret scan / Scan diff for credential-shaped strings (push) Successful in 7s
CI / Platform (Go) (push) Successful in 5s
CI / Canvas (Next.js) (push) Successful in 5s
E2E Chat / E2E Chat (push) Successful in 5s
CI / Shellcheck (E2E scripts) (push) Successful in 21s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (push) Successful in 15s
CI / Canvas Deploy Reminder (push) Successful in 5s
CI / all-required (push) Successful in 59s
E2E API Smoke Test / E2E API Smoke Test (push) Successful in 1m34s
Handlers Postgres Integration / Handlers Postgres Integration (push) Successful in 2m0s
publish-workspace-server-image / build-and-push (push) Successful in 8m0s
publish-workspace-server-image / Production auto-deploy (push) Successful in 2m37s
Sweep stale AWS Secrets Manager secrets / Sweep AWS Secrets Manager (push) Successful in 26s
Sweep stale Cloudflare Tunnels / Sweep CF tunnels (push) Successful in 4s
E2E Staging SaaS (full lifecycle) / pr-validate (push) Successful in 46s
main-red-watchdog / watchdog (push) Successful in 56s
Staging SaaS smoke (every 30 min) / Staging SaaS smoke (push) Successful in 4m34s
gate-check-v3 / gate-check (push) Successful in 53s
Continuous synthetic E2E (staging) / Synthetic E2E against staging (push) Successful in 4m41s
E2E Staging SaaS (full lifecycle) / E2E Staging SaaS (push) Successful in 6m42s
Sweep stale e2e-* orgs (staging) / Sweep e2e orgs (push) Successful in 6s
Sweep stale Cloudflare DNS records / Sweep CF orphans (push) Successful in 15s
ci-required-drift / drift (push) Successful in 1m34s

Merge PR #1784
This commit was merged in pull request #1784.
This commit is contained in:
2026-05-24 06:19:46 +00:00
+81 -4
View File
@@ -2,10 +2,16 @@
# lint_cleanup_traps.sh — regression gate for the OSS-shape program's
# "all E2E tests must have proper cleanup" bar (RFC #2873).
#
# Asserts: every shell file under tests/e2e/ that calls `mktemp` ALSO
# installs an `EXIT` trap somewhere in the file. The trap is the
# minimum-viable guarantee that scratch files won't leak when an
# assertion or curl exits the script non-zero.
# Asserts:
# 1. every shell file under tests/e2e/ that calls `mktemp` ALSO
# installs an `EXIT` trap somewhere in the file.
# 2. every staging tenant E2E script that provisions a real org uses a
# slug prefix caught by sweep-stale-e2e-orgs.yml and installs an
# EXIT trap.
#
# These are the minimum-viable guarantees that scratch files and real
# staging EC2 tenants converge back to zero when an assertion or curl
# exits the script non-zero.
#
# Why this lints (instead of the test runner enforcing): shell scripts
# can't easily be wrapped by an outer harness without breaking the
@@ -21,6 +27,7 @@
set -euo pipefail
cd "$(dirname "$0")"
repo_root="$(cd ../.. && pwd)"
violations=0
for f in test_*.sh; do
@@ -32,6 +39,76 @@ for f in test_*.sh; do
fi
done
if ! python3 - "$repo_root" <<'PY'
import re
import sys
from pathlib import Path
repo = Path(sys.argv[1])
e2e_dir = repo / "tests" / "e2e"
sweeper = repo / ".gitea" / "workflows" / "sweep-stale-e2e-orgs.yml"
errors: list[str] = []
sweeper_text = sweeper.read_text()
required_sweeper_prefixes = ('"e2e-"', '"rt-e2e-"')
for prefix in required_sweeper_prefixes:
if prefix not in sweeper_text:
errors.append(
f"::error file=.gitea/workflows/sweep-stale-e2e-orgs.yml::"
f"missing stale-org sweeper prefix {prefix}"
)
slug_assignment_re = re.compile(r'^\s*SLUG=(["\'])(?P<value>.+?)\1', re.MULTILINE)
covered_prefixes = ("e2e-", "rt-e2e-")
for path in sorted(e2e_dir.glob("test_*staging*.sh")):
text = path.read_text()
creates_org = "/cp/admin/orgs" in text and re.search(r"\bPOST\b", text)
deletes_org = "/cp/admin/tenants" in text and re.search(r"\bDELETE\b", text)
if not (creates_org or deletes_org):
continue
rel = path.relative_to(repo)
if not re.search(r"trap\s+.*\bEXIT\b", text):
errors.append(
f"::error file={rel}::staging tenant E2E touches CP org lifecycle "
"but has no EXIT trap for teardown"
)
assignments = [m.group("value") for m in slug_assignment_re.finditer(text)]
if not assignments:
errors.append(
f"::error file={rel}::staging tenant E2E touches CP org lifecycle "
"but has no quoted SLUG=... assignment for scoped cleanup"
)
continue
for value in assignments:
literal_prefix = re.split(r"[$`]", value, maxsplit=1)[0]
if not literal_prefix:
errors.append(
f"::error file={rel}::SLUG assignment starts with dynamic data "
f"({value!r}); use a fixed e2e-* or rt-e2e-* prefix so "
"sweep-stale-e2e-orgs can reap orphans"
)
continue
if not literal_prefix.startswith(covered_prefixes):
errors.append(
f"::error file={rel}::SLUG prefix {literal_prefix!r} is not "
"covered by sweep-stale-e2e-orgs.yml; use e2e-* or rt-e2e-*"
)
if errors:
print("\n".join(errors))
raise SystemExit(1)
print("✓ staging tenant E2E slug prefixes are covered by sweep-stale-e2e-orgs and use EXIT traps")
PY
then
violations=$((violations + 1))
fi
if [ "$violations" -gt 0 ]; then
echo "::error::$violations shell E2E file(s) leak scratch on early exit. See above."
exit 1