Skip to content

test: executed coverage for tools/rebuild_matrix.py — tests/test_rebuild_matrix.py - #192

Merged
castrojo merged 5 commits into
mainfrom
quality/test-rebuild-matrix-coverage
Sep 27, 2026
Merged

castrojo merged 5 commits into
mainfrom
quality/test-rebuild-matrix-coverage

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Test Improvement

Adds tests/test_rebuild_matrix.py. Touches exactly one file, and it is a new
test file — no production code and no existing test is modified.

tools/rebuild_matrix.py is the driver .github/workflows/rebuild-rpms.yml:240
runs to decide which packages a rebuild builds, and it reported 0% of its 104
statements
. tests/test_factory_witness.py:129 names the file, but only reads
it as text (REBUILD_MATRIX.read_text()), so nothing ever executed it.

What is now covered

31 cases over changed_recipes, changed_inventory, fetch_primary,
hummingbird_baseurl, fetch_published and main(). subprocess,
urllib.request.urlopen and the module's ROOT are redirected at the module
object, so no case touches the network or a real git repository.

The decisions that had nothing holding them in place:

  • The base-sha guard. An absent, all-zero or malformed BASE_SHA must read
    no range at all; the tests assert subprocess.check_output is never called,
    not merely that the result is empty. Were that guard to regress, every
    scheduled run would shell out to git diff <empty>..HEAD and fail the job.
  • changed_inventory proving nothing rather than everything when the old
    config is absent or unparseable at the base commit, plus the case it exists
    for: a stage move, invisible in the published NEVR.
  • fetch_primary — the repomd indirection, the trailing slash that has to
    be added exactly once, and both decompression paths (the .zst case is
    gated on zstandard being importable, and was run with it installed).
  • Mirror failure rebuilds everything instead of skipping, and the
    Hummingbird listing being unreachable is survivable rather than fatal.
  • The operator-facing rebuild reasons: rebuild <name>: published build requires <cap>, which nothing provides and rebuild <name>: depends on something being rebuilt, and that a stale package is kept out of
    cacheable so the cache cannot hand back the broken build.
  • The >250-package chunk split, asserting the split changes the handover
    and never the selection — a stage above the 256-job cap expands to nothing
    rather than failing.
  • SystemExit on a stage with no job, which is the guard that stops the
    factory publishing a repository quietly missing those packages.
  • GITHUB_OUTPUT is appended to, not rewritten over the other steps in the job.

Verification

Coverage evidence, on this branch:

$ python3 -m pytest tests -q --cov=tools --cov-report=term-missing
tools/rebuild_matrix.py   104   1   99%   220
427 passed, 2138 subtests passed

Before, on main at 3d38215:

tools/rebuild_matrix.py   104   104   0%   9-220
396 passed, 2131 subtests passed

0% -> 99%; the one remaining line is the if __name__ == "__main__" guard,
which is not reachable under import. Suite 396 -> 427 passed, no pre-existing
test changed. just check (tools/factory_contract.py, tools/validate.py)
also passes.

End-to-end evidence: this repository has no end-to-end suite, so the module was
covered by neither unit nor end-to-end tests. Nothing here claims end-to-end
coverage.

Related Issue

Closes #142


Filed by quality agent (hold-gated mode). Human review required.

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

…ild_matrix.py

tools/rebuild_matrix.py is the driver .github/workflows/rebuild-rpms.yml runs
to decide which packages a rebuild builds, and it reported 0% of its 104
statements. tests/test_factory_witness.py names the file but only reads it as
text, so nothing ever executed it.

Adds tests/test_rebuild_matrix.py: 31 cases over changed_recipes,
changed_inventory, fetch_primary, hummingbird_baseurl, fetch_published and
main(). subprocess, urllib.request.urlopen and the module's ROOT are redirected
at the module object, so no case touches the network or a real git repository.

Covered decisions that had nothing holding them in place: the base-sha guard
that keeps a scheduled run from shelling out to an empty diff range; the
inventory reader that proves nothing rather than everything when the old config
is absent or unparseable; the mirror failure that rebuilds everything instead
of skipping; the stale and dependent-drag rebuild reasons; the >250-package
chunk split; and the SystemExit on a stage with no job.

Coverage for the module goes 0% -> 99%; the remaining line is the __main__
guard. Suite goes 396 -> 427 passed.

Assisted-by: Claude Opus 5 via GitHub Copilot
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: sec-check[bot] <sec-check[bot]@users.noreply.github.com>
@hivecommons-hive hivecommons-hive Bot added the hold Work is intentionally paused. label Sep 20, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

Important

Held for human review by the hive's ACMM level gate.

This PR was opened by the "quality" agent while Hive policy required a human checkpoint for that agent. Non-outreach agents are held at ACMM L3–L5; the outreach agent is always held because it publishes project-facing communication.

Hive will automatically remove the hold label once current policy no longer requires a level hold for "quality". If this is an outreach PR, a human must review it and remove the label.

@castrojo castrojo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged origin/main to resolve the post-#191 baseline drift (dropping the 7 deferred base packages) and updated tests/test_rebuild_matrix.py to scaffold config/hummingbird-provided-sources.json and reflect that FACTORY_REPO is queried on FULL=1 for source pruning. Full test suite and validation gates pass cleanly.

@Danathar Danathar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at d1dbde4. The only change is the new tests/test_rebuild_matrix.py; no tool or existing test is touched. The 31 cases call the real functions with subprocess, urllib and ROOT patched at the module, so nothing hits git or the network, and pytest --cov reports 97% of tools/rebuild_matrix.py executed (only the zstandard branch is skipped here, since that module is not installed). To check the tests hold behaviour rather than text, I made four one-line mutations to tools/rebuild_matrix.py (dropping the all-zero BASE_SHA guard, dropping the stage-11 SystemExit, opening GITHUB_OUTPUT with w instead of a, and dropping the stale rebuild reason) and each one made exactly one test fail. The full suite passes at this head (432 passed) and after a trial merge of current main (441 passed), and validate.py, factory_contract.py, runtime_contract.py --check and check_workflow_quoting.py pass.

@hanthor hanthor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are good and pass at the PR head, but they've drifted from main. After a local merge with main, tests/test_rebuild_matrix.py:450-459 (test_a_stage_with_no_job_is_fatal) errors with ValueError: unknown stage for late: 11 from tools/package_inventory.py:73. Since #232, load_source_locks rejects out-of-range stages before main() reaches the "no job exists for stage 11" check the test expects.

Please rebase, then either assert the new earlier error or inject the lock past the validator. Everything else is ready. It would be good to land this before #195 so these tests guard that refactor.

@castrojo

Copy link
Copy Markdown
Contributor

Verification & Status:

  • Diff: Adds tests/test_rebuild_matrix.py (31 unit tests) covering tools/rebuild_matrix.py.
  • Rebase / Test status: hanthor requested changes on 2026-09-25: test_a_stage_with_no_job_is_fatal failed because load_source_locks rejects out-of-range stages before main() reaches the check. Since commit cbfa446 (#264), tools/rebuild_matrix.py also integrates build_graph and factory_state, resulting in 5 test errors and 3 test failures when merged against current main.
  • Review state: Danathar approved; hanthor requested changes.
  • Blockers: Addressing the test failures requires adapting the test fixtures to the refactored rebuild matrix (including factory_state current input digests and wave chunking).

Next action: Author (@app/hivecommons-hive or maintainer) must update tests/test_rebuild_matrix.py to match tools/rebuild_matrix.py on current main. hanthor must re-review and approve before merge.

castrojo and others added 2 commits September 26, 2026 15:33
…ut format

Assisted-by: Gemini via GitHub Copilot
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@castrojo castrojo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased on origin/main and resolved test drift in tests/test_rebuild_matrix.py (commit db6cacc): added dummy sources file in write_root fixture for factory_state hashing, updated output string assertions to match current format (diff changed string, wave naming, trusted output list, and KNOWN_STAGES ValueError). All 30 tests in the file and 684 suite tests pass cleanly. Ready for @hanthor to re-review and clear CHANGES_REQUESTED.

@Danathar Danathar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at db6cacc. hanthor's point is fixed: test_a_stage_with_no_job_is_fatal now asserts the ValueError "unknown stage for late: 11" that load_source_locks raises first, which was one of the two options he offered, and the other drift fixes only follow main's new output text (wave, trusted list, change detection). Locally the file passes (30 passed, 1 skipped) and the full suite passes (684 passed). Four one-line mutations to tools/rebuild_matrix.py each fail one test: dropping the all-zero BASE_SHA guard, opening GITHUB_OUTPUT with "w", dropping the stale rebuild reason, and letting stale builds stay cacheable. One gap, which can be a follow-up: the SystemExit for a BuildRequires chain deeper than the workflow's waves is no longer covered (disabling it passes the whole suite), so the description's "SystemExit on a stage with no job" bullet is out of date.

@castrojo
castrojo dismissed hanthor’s stale review September 27, 2026 00:32

Point-by-point: (1) 'drifted from main; test_a_stage_with_no_job_is_fatal errors with ValueError unknown stage for late: 11' -> fixed in db6cacc, which rebases on main and asserts the ValueError that load_source_locks now raises first (the first option offered). (2) 'please rebase' -> db6cacc sits on current main. Verified: tests/test_rebuild_matrix.py 30 passed, full suite 684 passed locally at db6cacc; Canary green (run 36268047543); Danathar approved at db6cacc.

@castrojo
castrojo merged commit 5ab6846 into main Sep 27, 2026
17 checks passed
@castrojo

Copy link
Copy Markdown
Contributor

Merge record: R5 (stale-drift CR dismissed after verified fix in db6cacc). Independent approver: @Danathar (approved at head db6cacc).

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

Labels

hold Work is intentionally paused.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[quality] coverage-gap: tools/rebuild_matrix.py has zero test coverage — the rebuild-rpms.yml driver

3 participants