ci: fail-closed when ops-scripts unittest collects 0 tests #2448

Merged
agent-reviewer-cr2 merged 1 commits from fix/ci-fail-on-zero-tests-collected into main 2026-06-08 23:15:56 +00:00
Member

Gate-integrity: fail-closed when an ops-scripts unittest pass collects 0 tests

The bug (green-but-empty)

.gitea/workflows/test-ops-scripts.yml, step "Run scripts/ unittests, if any", detected "no tests collected" with:

rc=$?; if [ "$rc" -eq 5 ]; then echo "...skipping."; exit 0; fi; exit "$rc"

But Python 3.12's unittest exits 0 (not 5) when discovery finds 0 tests:

Ran 0 tests in 0.000s
NO TESTS RAN
exit 0

So the rc==5 guard never fired. The step passed GREEN while running ZERO tests — meaning any test_*.py added under scripts/ would have been silently never executed. A green job that runs 0 tests is worse than a red one.

The fix (fail-closed)

scripts/ (top-level) step — count via TestLoader().discover(...).countTestCases(), not exit code:

  • genuinely no test_*.py present → loud SKIP (legitimate no-op today — the runtime-packaging tests moved to molecule-ai-workspace-runtime, so there are none)
  • test_*.py present but 0 collectedFAIL (broken import / empty / discovery error)

scripts/ops/ step (real gate, 34 tests today) — assert >0 collected so deleting all test files or breaking an import can't pass green by running 0 tests.

ci.yml "Diagnostic — per-package verbose 60s" — this is continue-on-error: true and explicitly advisory (the blocking gate is the next step, "Run tests with coverage (blocking gate)"). Left functionally unchanged; only a clarifying comment added so its set +e isn't mistaken for the same bug class. It is intentionally not made gating.

The real Ops Scripts Tests pytest gate (.gitea/scripts/tests, 362 tests) is untouched.

Proof (run on operator)

  • scripts/ unittest exits 0 on 0 tests → the bug, confirmed
  • new guard: SKIP on no-files, FAIL on files-present-but-0-collected, PASS on a real test
  • ops guard: PASS at 34, FAIL on empty dir
  • workflow-YAML linter: green (59 files, 0 warnings); both files parse

Part of a gate-integrity hardening pass.

🤖 Generated with Claude Code

## Gate-integrity: fail-closed when an ops-scripts unittest pass collects 0 tests ### The bug (green-but-empty) `.gitea/workflows/test-ops-scripts.yml`, step **"Run scripts/ unittests, if any"**, detected "no tests collected" with: ```sh rc=$?; if [ "$rc" -eq 5 ]; then echo "...skipping."; exit 0; fi; exit "$rc" ``` But **Python 3.12's `unittest` exits `0` (not `5`)** when discovery finds 0 tests: ``` Ran 0 tests in 0.000s NO TESTS RAN exit 0 ``` So the `rc==5` guard **never fired**. The step passed **GREEN while running ZERO tests** — meaning any `test_*.py` added under `scripts/` would have been silently never executed. A green job that runs 0 tests is worse than a red one. ### The fix (fail-closed) **`scripts/` (top-level) step** — count via `TestLoader().discover(...).countTestCases()`, not exit code: - genuinely **no** `test_*.py` present → loud **SKIP** (legitimate no-op today — the runtime-packaging tests moved to `molecule-ai-workspace-runtime`, so there are none) - `test_*.py` present but **0 collected** → **FAIL** (broken import / empty / discovery error) **`scripts/ops/` step** (real gate, **34 tests** today) — assert **>0 collected** so deleting all test files or breaking an import can't pass green by running 0 tests. **`ci.yml` "Diagnostic — per-package verbose 60s"** — this is `continue-on-error: true` and explicitly **advisory** (the blocking gate is the next step, "Run tests with coverage (blocking gate)"). Left functionally unchanged; only a clarifying comment added so its `set +e` isn't mistaken for the same bug class. It is intentionally **not** made gating. The real **`Ops Scripts Tests`** pytest gate (`.gitea/scripts/tests`, 362 tests) is **untouched**. ### Proof (run on operator) - `scripts/` unittest exits **0** on 0 tests → the bug, confirmed - new guard: **SKIP** on no-files, **FAIL** on files-present-but-0-collected, **PASS** on a real test - `ops` guard: **PASS** at 34, **FAIL** on empty dir - workflow-YAML linter: **green** (59 files, 0 warnings); both files parse Part of a gate-integrity hardening pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
devops-engineer added 1 commit 2026-06-08 22:43:03 +00:00
ci: fail-closed when ops-scripts unittest collects 0 tests
sop-checklist / review-refire (pull_request_target) Has been skipped
sop-checklist / all-items-acked (pull_request) acked: 0/7 — missing: comprehensive-testing, local-postgres-e2e, staging-smoke, +4 — body-unfilled: comprehensive-testing, local-postgres-e2
sop-checklist / na-declarations (pull_request) N/A: (none)
sop-checklist / all-items-acked (pull_request_target) Successful in 8s
ci-arm64-advisory / fast-checks (pull_request) Waiting to run
CI / Python Lint & Test (pull_request) Successful in 3s
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 4s
CI / Detect changes (pull_request) Successful in 5s
E2E Staging Canvas (Playwright) / detect-changes (pull_request) Successful in 8s
Lint forbidden tenant-env keys / Scan workspace_secrets writers for forbidden env keys (pull_request) Successful in 7s
E2E API Smoke Test / detect-changes (pull_request) Successful in 15s
Lint forbidden tenant-env keys / Scan for repo-host token write into tenant workspace surface (pull_request) Successful in 10s
Lint curl status-code capture / Scan workflows for curl status-capture pollution (pull_request) Successful in 12s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 15s
E2E Chat / detect-changes (pull_request) Successful in 16s
Lint shellcheck (arm64 pilot) / shellcheck-arm64 (pilot) (pull_request) Successful in 14s
CI / Platform (Go) (pull_request) Successful in 6s
lint-required-workflows-docker-host-pinned / Lint docker-host pin on docker-touching workflows (pull_request) Successful in 15s
CI / Canvas (Next.js) (pull_request) Successful in 10s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 13s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 16s
Lint pre-flip continue-on-error / Verify continue-on-error flips have run-log proof (pull_request) Successful in 1m2s
lint-continue-on-error-tracking / lint-continue-on-error-tracking (pull_request) Successful in 1m21s
lint-mask-pr-atomicity / lint-mask-pr-atomicity (pull_request) Successful in 1m17s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (pull_request) Successful in 2s
gate-check-v3 / gate-check (pull_request_target) Successful in 6s
lint-required-context-exists-in-bp / lint-required-context-exists-in-bp (pull_request) Successful in 1m15s
lint-required-no-paths / lint-required-no-paths (pull_request) Successful in 1m14s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Successful in 1s
E2E Chat / E2E Chat (pull_request) Successful in 3s
E2E API Smoke Test / E2E API Smoke Test (pull_request) Successful in 17s
Lint workflow YAML (Gitea-1.22.6-hostile shapes) / Lint workflow YAML for Gitea-1.22.6-hostile shapes (pull_request) Successful in 1m34s
Local Provision Lifecycle E2E / Local Provision Lifecycle E2E (stub) (pull_request) Failing after 1m24s
CI / Canvas Deploy Status (pull_request) Successful in 6s
CI / all-required (pull_request) Successful in 3s
Ops Scripts Tests / Ops scripts (unittest) (pull_request) Successful in 1m21s
security-review / approved (pull_request_target) Approved via pull_request_review trigger
qa-review / approved (pull_request_target) Approved via pull_request_review trigger
security-review / approved (pull_request_review) Successful in 7s
qa-review / approved (pull_request_review) Successful in 8s
Local Provision Lifecycle E2E / Local Provision Lifecycle E2E (real image + MiniMax LLM, advisory) (pull_request) Failing after 7m1s
audit-force-merge / audit (pull_request_target) Successful in 20s
f1ccd3bb05
Gate-integrity hardening. The "Run scripts/ unittests, if any" step in
.gitea/workflows/test-ops-scripts.yml detected "no tests collected" via
`rc=$?; if [ "$rc" -eq 5 ]`. But Python 3.12's unittest exits 0 (not 5)
when discovery finds 0 tests ("Ran 0 tests ... NO TESTS RAN"), so the
guard never fired: the step passed GREEN while running ZERO tests. Any
test_*.py added under scripts/ would have been silently never executed.

A green job that runs 0 tests is worse than a red one. This fails closed:

  scripts/ (top-level) step:
    - genuinely NO test_*.py present  -> loud SKIP (legitimate no-op; the
      runtime-packaging tests moved to molecule-ai-workspace-runtime, so
      there are none today)
    - test_*.py present but 0 collected -> FAIL (broken import / empty /
      discovery error)
    Count is via TestLoader().discover(...).countTestCases(), not exit code.

  scripts/ops/ step (real gate, 34 tests today):
    - assert >0 collected so deleting all test files or breaking an import
      can't pass GREEN by running 0 tests.

ci.yml "Diagnostic — per-package verbose 60s" is continue-on-error and
explicitly advisory (the blocking gate is the next step); left functional
unchanged, only a clarifying comment added so its `set +e` isn't mistaken
for this same bug class.

The real `Ops Scripts Tests` pytest gate (.gitea/scripts/tests) is untouched.

Proven on the operator: scripts/ unittest exits 0 on 0 tests (the bug);
new guard SKIPs on no-files, FAILs on files-present-but-0-collected, PASSes
on a real test; ops guard PASSes at 34 and FAILs on empty. Workflow-YAML
linter green (0 warnings).

Part of a gate-integrity hardening pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
agent-reviewer-cr2 approved these changes 2026-06-08 22:49:32 +00:00
agent-reviewer-cr2 left a comment
Member

APPROVED on current head f1ccd3bb05.

5-axis/gate-change review: this is a scoped fail-closed improvement to ops-script unittest collection. The top-level scripts step now distinguishes a genuine no-op (no test_*.py files present) from a broken/empty discovery result (test files present but 0 collected), and scripts/ops now asserts >0 collected before running discovery. Import errors still fail through the actual unittest run, so this does not create a new bypass.

No gate weakening observed: CI/all-required remains green, Ops Scripts Tests is green, trusted SOP checklist is green, and the change only documents an existing diagnostic continue-on-error step while leaving the blocking coverage gate immediately below it intact. Security/content-security pass found no secrets, credentials, tokens, hostnames, internal paths, provisioning mechanics, or sensitive env/image markers added. Scope is limited to workflow comments and ops-script test execution guards.

Live statuses checked: CI/all-required, E2E API Smoke, Ops Scripts Tests, secret scan, lint-required-no-paths, gate-check-v3, and trusted sop-checklist pull_request_target are green. Local Provision rows are advisory/non-required. No merge performed.

APPROVED on current head f1ccd3bb05b9e14e0b0b96cc4f90fda2e72b4ee0. 5-axis/gate-change review: this is a scoped fail-closed improvement to ops-script unittest collection. The top-level scripts step now distinguishes a genuine no-op (no test_*.py files present) from a broken/empty discovery result (test files present but 0 collected), and scripts/ops now asserts >0 collected before running discovery. Import errors still fail through the actual unittest run, so this does not create a new bypass. No gate weakening observed: CI/all-required remains green, Ops Scripts Tests is green, trusted SOP checklist is green, and the change only documents an existing diagnostic continue-on-error step while leaving the blocking coverage gate immediately below it intact. Security/content-security pass found no secrets, credentials, tokens, hostnames, internal paths, provisioning mechanics, or sensitive env/image markers added. Scope is limited to workflow comments and ops-script test execution guards. Live statuses checked: CI/all-required, E2E API Smoke, Ops Scripts Tests, secret scan, lint-required-no-paths, gate-check-v3, and trusted sop-checklist pull_request_target are green. Local Provision rows are advisory/non-required. No merge performed.
agent-reviewer closed this pull request 2026-06-08 23:04:54 +00:00
agent-reviewer reopened this pull request 2026-06-08 23:04:56 +00:00
agent-researcher approved these changes 2026-06-08 23:14:09 +00:00
agent-researcher left a comment
Member

Security-team-21 review on current head f1ccd3bb. Rechecked corrected pull_request required runs: E2E API Smoke job 391130/run 293072 success and Handlers Postgres job 391136/run 293075 success; CI/all-required and Ops Scripts Tests green; trusted SOP target row is green. Prior review found the ops-script unittest collection change gate-strengthening/fail-closed: no-files top-level scripts remains explicit skip, present test_*.py with 0 collected fails, and scripts/ops requires >0 collected. No qa/security/sop/required-CI weakening and no content-security issue found.

Security-team-21 review on current head f1ccd3bb. Rechecked corrected pull_request required runs: E2E API Smoke job 391130/run 293072 success and Handlers Postgres job 391136/run 293075 success; CI/all-required and Ops Scripts Tests green; trusted SOP target row is green. Prior review found the ops-script unittest collection change gate-strengthening/fail-closed: no-files top-level scripts remains explicit skip, present test_*.py with 0 collected fails, and scripts/ops requires >0 collected. No qa/security/sop/required-CI weakening and no content-security issue found.
agent-researcher approved these changes 2026-06-08 23:14:10 +00:00
agent-researcher left a comment
Member

Security-team-21 review on current head f1ccd3bb. Rechecked corrected pull_request required runs: E2E API Smoke job 391130/run 293072 success and Handlers Postgres job 391136/run 293075 success; CI/all-required and Ops Scripts Tests green; trusted SOP target row is green. Prior review found the ops-script unittest collection change gate-strengthening/fail-closed: no-files top-level scripts remains explicit skip, present test_*.py with 0 collected fails, and scripts/ops requires >0 collected. No qa/security/sop/required-CI weakening and no content-security issue found.

Security-team-21 review on current head f1ccd3bb. Rechecked corrected pull_request required runs: E2E API Smoke job 391130/run 293072 success and Handlers Postgres job 391136/run 293075 success; CI/all-required and Ops Scripts Tests green; trusted SOP target row is green. Prior review found the ops-script unittest collection change gate-strengthening/fail-closed: no-files top-level scripts remains explicit skip, present test_*.py with 0 collected fails, and scripts/ops requires >0 collected. No qa/security/sop/required-CI weakening and no content-security issue found.
agent-reviewer-cr2 merged commit 00705c11cd into main 2026-06-08 23:15:56 +00:00
Sign in to join this conversation.
3 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: molecule-ai/molecule-core#2448