Skip to content

[architect] refactor: enforce behave suite environment quarantine-gate contract (new tests/unit/test_suite_environment_contract.py) - #765

Open
kubestellar-hive[bot] wants to merge 1 commit into
mainfrom
arch/testsuite-suite-env-contract
Open

[architect] refactor: enforce behave suite environment quarantine-gate contract (new tests/unit/test_suite_environment_contract.py)#765
kubestellar-hive[bot] wants to merge 1 commit into
mainfrom
arch/testsuite-suite-env-contract

Conversation

@kubestellar-hive

Copy link
Copy Markdown
Contributor

Refactor

Claimed ground — exact files/functions/cluster this PR occupies:

No existing file is touched. git show --stat on this branch is one added file.

What this changes structurally

Every behave suite ships its own tests/<suite>/features/environment.py — 14 of
them, from 26 lines (nvidia) to 469 lines (smoke). There is no shared base and
no mixin, so the cross-cutting hooks they are all expected to honour are copy-pasted
rather than inherited, and nothing detects a suite that silently drops one.

tests/shared/quarantine.py is the gate that keeps @quarantine, @future,
@pending and @hardware_blocked scenarios from executing.
tests/unit/test_quarantine.py covers that helper thoroughly in isolation, but it
says nothing about whether any suite calls it. A suite that omits the call runs its
known-failing scenarios for real — and because those tags exist precisely because
those scenarios are known-failing, the omission does not fail at authoring time. It
surfaces later as a red E2E gate that looks like a product regression.

That drift is not hypothetical: the same copy-paste shape already produced a gap in
the sibling concern. record_start/record_end from tests/shared/timing.py is
wired in only 10 of the 14 suites — bazzite, flatcar, nvidia and security
silently record nothing. See #763 for the full matrix.

This PR converts the quarantine convention into an enforced contract. The new module
parses each tests/*/features/environment.py with ast — no imports, no behave
runtime, no VM, no selenium — and asserts three things per suite:

  1. before_scenario is defined.
  2. before_scenario calls skip_quarantine.
  3. skip_quarantine is imported from tests.shared.quarantine and not redefined
    locally, so the skip-tag precedence stays in exactly one place.

A fourth non-parametrised guard fails if the discovery glob ever collects zero
suites, so the parametrised assertions cannot quietly become vacuous.

Scope discipline

This is enforcement only — no runtime behaviour change, no production code
touched, no suite rewired. Deliberately excluded from this PR:

Verification

$ python -m pytest tests/unit/test_suite_environment_contract.py -q
43 passed in 0.80s

All 14 existing suites already satisfy the contract, so this is green on arrival.

Mutation-checked that the test is not tautological — replacing the gate in
tests/nvidia/features/environment.py with if False: produces:

FAILED tests/unit/test_suite_environment_contract.py::test_before_scenario_applies_quarantine_gate[nvidia]
AssertionError: tests/nvidia/features/environment.py: before_scenario never calls
skip_quarantine(). Every suite must apply the shared gate from
tests/shared/quarantine.py, otherwise its @quarantine, @future, @pending and
@hardware_blocked scenarios run instead of being skipped.
1 failed, 42 passed

The mutation was reverted; the diff contains only the new file.

Disjointness from open hold-gated PRs

Checked against the open snapshot for this repo via gh pr view --json title,files:

Neither touches tests/*/features/environment.py, tests/shared/quarantine.py, or
the new file. No overlap.

Refs #763


Filed by architect agent (ACMM L5 — hold-gated mode). Hold-gated: human review required.

— hive: agent=architect backend=copilot model=claude-opus-5

…-gate contract

Every behave suite ships its own tests/<suite>/features/environment.py. The
cross-cutting hooks they are all expected to honour are copy-pasted rather than
inherited from a shared base, so nothing detects a suite that silently drops one.

tests/shared/quarantine.py is the gate that keeps @quarantine, @future, @pending
and @hardware_blocked scenarios from executing. tests/unit/test_quarantine.py
covers that helper's own logic thoroughly, but nothing asserts a suite calls it.
A suite that omits the call runs its known-failing scenarios for real, which
surfaces later as a red E2E gate that reads like a product regression.

Adds tests/unit/test_suite_environment_contract.py, which parses each
tests/*/features/environment.py with ast -- no imports, no behave runtime, no VM
-- and asserts that the suite defines before_scenario, calls skip_quarantine from
it, and imports that helper from tests.shared.quarantine rather than redefining
it locally. A guard test fails if the discovery glob ever collects nothing, so
the parametrised assertions cannot become vacuous.

No runtime behaviour changes: this adds a test file only and turns an existing
unenforced convention into an enforced contract. All 14 current suites already
satisfy it (43 passed).

Refs #763

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: kubestellar-hive[bot] <280983584+kubestellar-hive[bot]@users.noreply.github.com>
@kubestellar-hive kubestellar-hive Bot added hold Work is intentionally paused. architecture Approved by a Hive merger/owner for auto-merge on green CI agent/architect Approved by a Hive merger/owner for auto-merge on green CI hive/hosted-projectbluefin-knuckle-gjvq Approved by a Hive merger/owner for auto-merge on green CI labels Aug 27, 2026
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 98.33333% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tests/unit/test_suite_environment_contract.py 98.33% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent/architect Approved by a Hive merger/owner for auto-merge on green CI architecture Approved by a Hive merger/owner for auto-merge on green CI hive/hosted-projectbluefin-knuckle-gjvq Approved by a Hive merger/owner for auto-merge on green CI hold Work is intentionally paused.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant