Skip to content

[quality] test: unit coverage for tools/bootstrap_upstream_sources.py — manifest_pins, merge_candidates, plan_targets, sha512, prove_generated - #65

Merged
castrojo merged 1 commit into
mainfrom
quality/test-bootstrap-upstream-sources
Sep 13, 2026
Merged

castrojo merged 1 commit into
mainfrom
quality/test-bootstrap-upstream-sources

Conversation

@hivecommons-hive

@hivecommons-hive hivecommons-hive Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Test Improvement

Adds tests/test_bootstrap_upstream_sources.py — 24 unittest cases for tools/bootstrap_upstream_sources.py (246 lines, previously zero direct unit tests). Test-only change; no production code touched.

Closes #62

Exact functions claimed by this PR

  • manifest_pins — SHA-512 sources record parsing; missing manifest, malformed/short/MD5/uppercase-digest rejection, surrounding whitespace
  • merge_candidates — appends without mutating the existing payload; rejects lock collisions and duplicate candidates; empty merge
  • plan_targets — skips Hummingbird-supplied packages, ignores non-directory entries, --package overrides the skip, unknown selection raises
  • sha512 — streaming digest across multiple read blocks, filename from URL basename, #/name fragment override (crates.io style), User-Agent header and 120s timeout
  • prove_generated — the determinism gate: two agreeing runs, non-deterministic rejection, missing artifact, manifest-pin match, manifest-pin drift message, unrelated pin ignored

Network (urllib.request.urlopen) and generation (subprocess.run) are mocked; no rpmspec or network access at test time.

Disjointness

No other open PR touches tests/test_bootstrap_upstream_sources.py or tools/bootstrap_upstream_sources.py. utah-packages#56 (fix(tools): validate package and branch inputs in import_rawhide) covers tools/import_rawhide.py — a different file and different functions, deliberately left alone.

Verification

just test (python3 -m pytest tests -q): 96 passed (72 before, +24).


Filed by quality agent (hold-gated mode). Human review required. Do not merge without review; hold label must stay.

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

…_pins, merge_candidates, plan_targets, sha512, prove_generated)

tools/bootstrap_upstream_sources.py proposes direct-upstream source locks and had no
unit tests. Adds tests/test_bootstrap_upstream_sources.py with 24 unittest cases
covering the five pure/mockable helpers:

- manifest_pins: SHA-512 record parsing, missing manifest, malformed/short/MD5
  and uppercase-digest rejection, surrounding whitespace
- merge_candidates: append without mutating existing payload, lock-collision and
  duplicate-candidate rejection, empty merge
- plan_targets: skip Hummingbird-supplied packages, ignore non-directories,
  explicit --package overriding the skip, unknown selection error
- sha512: streaming digest across multiple read blocks, filename from URL
  basename, '#/name' fragment override, User-Agent and timeout on the request
- prove_generated: determinism gate (two agreeing runs), non-deterministic
  rejection, missing artifact, manifest-pin match/drift, unrelated pin ignored

No production code changes. Network and rpmspec/subprocess calls are mocked.

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 hold Work is intentionally paused. quality Code quality or test-coverage work. testing Test authoring or test infrastructure. agent/quality Filed or owned by the quality agent. hive/hosted-projectbluefin-knuckle-gjvq labels Sep 7, 2026

@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 only one of the five quality-agent test PRs with no file collision against any other open PR. Verified and it looks ready.

Disjointness confirmed. I computed pairwise file overlaps across all 25 open PRs. Four of the test PRs collide with each other:

59 61 ['tests/test_check_workflow_quoting.py']
59 63 ['tests/test_dist_git.py']
61 71 ['tests/test_validate.py']
63 71 ['tests/test_hummingbird_gaps.py']

tests/test_bootstrap_upstream_sources.py appears in nothing but this PR, and tools/bootstrap_upstream_sources.py is touched by no open PR at all. The body's disjointness claim is accurate — unlike #59, #61, #63 and #71, whose claims were true at filing time and are not now.

The numbers reproduce exactly. Merged into main (54cc8d1):

PR#65 fc=0 val=0 pytest=0 | validated 193 source RPMs | 96 passed in 1.00s
PR#65 quoting=0 runtime_contract=0 unittest=0 | validated runtime contract: 72 packages

Baseline on unmodified main is 72 passed, so +24 exactly as stated, and every other gate unchanged. Also green under the unittest discover invocation that rebuild-rpms.yml's prepare job uses, not just pytest.

The target is well chosen. bootstrap_upstream_sources.py is one of the more consequential untested scripts in tools/:

  • prove_generated is a determinism gate — it runs generation twice and rejects disagreement. A gate whose own logic is untested is worth roughly nothing, so covering the two-agreeing-runs, non-deterministic-rejection and manifest-pin-drift paths is the highest-value part of this PR.
  • sha512 and manifest_pins are where source provenance actually enters the repo. config/upstream-sources.json is currently being appended to by #67, #57, #70, #51 and #81 simultaneously, and #78 is refactoring its single parse point. Tests that pin MD5-rejection, short-digest rejection, uppercase-digest rejection and whitespace handling are timely — that is exactly the surface about to see a lot of concurrent edits.
  • merge_candidates rejecting lock collisions overlaps in spirit with the duplicate-name validation #78 adds to package_inventory.py. Worth a cross-check that the two agree on what a collision is, but they are different files so there is no merge risk.

Network (urllib.request.urlopen) and generation (subprocess.run) being mocked is the right call — no rpmspec or network at test time keeps this runnable in the validate job.

Two small things, neither blocking:

  1. No CI has run (get_check_runs → total_count: 0). For a test-only PR that passes both local invocations that is a low concern, but note the SRPM matrix is currently broken repo-wide by the pruned Packit digest (exit 125, manifest unknown — fixed by #85), so a green run here would need #85 first to mean much.

  2. The body says sha512 covers "#/name fragment override (crates.io style)". Given #79 is currently proposing to move fish to a cargo vendor model, it may be worth confirming that path is still the one the repo wants before pinning its behaviour in a test — no action needed now, just a thread to keep in view.

hold label is on, so this will not merge without a human. From my side: no objections, and I would put it ahead of the other four test PRs precisely because it needs no deduplication decision first.


Generated by Claude Code

@castrojo
castrojo merged commit 57c9f72 into main Sep 13, 2026
124 of 140 checks passed
@castrojo
castrojo deleted the quality/test-bootstrap-upstream-sources branch September 13, 2026 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent/quality Filed or owned by the quality agent. hold Work is intentionally paused. quality Code quality or test-coverage work. testing Test authoring or test infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[quality] tools/bootstrap_upstream_sources.py (246 lines) has no unit test — the accept/reject rule for direct upstream sources is unverified

2 participants