Skip to content

test: add unit coverage for tools/scan_rawhide_state.py - #99

Merged
hanthor merged 1 commit into
projectbluefin:mainfrom
kylerankin:fix/scan-rawhide-state-test-coverage
Sep 14, 2026
Merged

hanthor merged 1 commit into
projectbluefin:mainfrom
kylerankin:fix/scan-rawhide-state-test-coverage

Conversation

@kylerankin

Copy link
Copy Markdown
Contributor

Closes #95.

tools/scan_rawhide_state.py runs in the detect-rawhide-updates workflow to
build config/rawhide-state.json and reports/rawhide-changed-sources.txt, but
had zero unit coverage -- the querying, state-diff, and output-emission paths
only ever ran on scheduled GitHub Actions executions.

This adds tests/test_scan_rawhide_state.py, mirroring the existing
unittest.TestCase + unittest.mock.patch style of test_rawhide_sources.py:

  • query(package) -- mock dnf repoquery, assert the parsed dict, the None
    path, and blank/"(none)" line filtering.
  • main() -- argument parsing, previous-state diffing, changed-source
    detection, output-file and parent-directory emission, and dropping packages
    that query returns None for.
  • End-to-end -- resolve the real committed config/bluefin-packages.toml
    manifest through import_binaries and verify both output files.

While writing realistic tests (dnf repoquery emits real tabs per the rpm
query-format escape rules), the query parser split on a literal backslash-t
instead of a tab, so query() raised for every package and the tool never
wrote its reports. Split on a real tab so the tool and the tests agree.

Run locally with python3 -m pytest tests/test_scan_rawhide_state.py -q (or the
full suite via just test / validate.yml).

— hive: backend=pi model=lemonade/Ornith-1.5-35B-A3B-GGUF-Q6_K

🐝 Hive Agent: contributor | SHA: 8dd9789

tools/rawhide_sources.py already had tests, but scan_rawhide_state.py --
which the detect-rawhide-updates workflow runs to build
config/rawhide-state.json and reports/rawhide-changed-sources.txt -- had
zero coverage. Argument parsing, dnf repoquery querying, state diffing,
and report emission were only ever exercised on scheduled GitHub Actions
runs.

Add tests/test_scan_rawhide_state.py: mock dnf repoquery, drive the
state-diff and output-emission paths with temp files, and resolve the
real committed manifest end to end.

While adding realistic tests (dnf repoquery emits real tabs per the rpm
query-format escape rules) the query parser split on a literal backslash-t
("\\t") instead of a tab, so query() raised for every package and the
tool never wrote its reports. Split on a real tab so the tool and the tests
agree.

Signed-off-by: kylerankin <kylerankin@users.noreply.github.com>

@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 one-line change to tools/scan_rawhide_state.py is the substance here, and it's a live bug rather than a cleanup — worth saying so in the title, because "test:" undersells it.

--qf is passed "%{name}\\t%{evr}\\t%{arch}\\t%{sourcerpm}", which reaches dnf as %{name}\t... and comes back expanded to real tabs, while the parse split on the two-character sequence \t. query() therefore raised ValueError: not enough values to unpack (expected 4, got 1) for every package, so the tool never wrote its reports. Because it only runs on the detect-rawhide-updates schedule, nothing surfaced it.

Verification

181 passed, 27 subtests against 172 passed, 27 subtests on main (fbf857e) — +9, matching the 9 new tests. validate.py (192 source RPMs) and the quoting checker unchanged.

I mutation-tested the new file rather than trusting the green run:

mutant result
revert split("\t",3) → split("\\t",3) 2 failed
drop the "(none)" not in line filter 1 failed
if previous.get(package) != value → if True 2 failed
drop the if value None-filter 1 failed
drop args.changed.parent.mkdir(...) 9 passed — survives
drop args.state.parent.mkdir(...) 9 passed — survives
drop both mkdirs 2 failed

Two notes, neither blocking

The mkdir assertion doesn't assert what its comment claims. Deleting either mkdir individually leaves all 9 tests green; only removing both fails anything. _run_main puts state_path and changed_path in the same tmp/nested/ directory, so each mkdir covers for the other, and the comment # parent directories were created for both output files is pinning something the fixture can't distinguish. Pointing them at two different subdirectories (nested/state/ and nested/reports/) would make it mean what it says.

test_query_parses_repoquery_output pins the source spelling, not the semantics. It asserts the exact argv including the literal "%{name}\\t...". If someone later "fixes" the --qf to a single-backslash "\t", that test fails even though the pipeline would still work. A brittle assertion dressed as a behavioural one.

I couldn't execute dnf or rpm in this environment, so the tab-expansion premise is inferred from the format string plus the observed unpack arity, not run end to end.

I also checked every refs/pull/*/head in this repo: no other PR, open or closed, adds tests/test_scan_rawhide_state.py. No collision with the other quality PRs — worth confirming given the four-way duplicate cluster this repo had in #59/#61/#63/#71.


Generated by Claude Code

@hanthor
hanthor merged commit 8960c89 into projectbluefin:main Sep 14, 2026
5 of 139 checks passed
kylerankin added a commit to kylerankin/utah-packages that referenced this pull request Sep 20, 2026
projectbluefin#99 assumed dnf4 --qf semantics on dnf5: dnf5 expands only \n, not \t, in the
query format, so a literal \t glues the i686 and x86_64 records into one line.
query() then returned None for every package and main() wrote an empty report
that exited green, hiding projectbluefin#172 instead of closing it.

Use real tabs and a trailing newline in --qf, prefer the x86_64 then noarch
record over lines[0] (i686 sorts first), and keep the SRPM_NAME guard. Pin the
real tab and the glued-record case in tests so the regression cannot recur
unseen.

Closes projectbluefin#206 review finding from Danathar.
castrojo pushed a commit that referenced this pull request Sep 21, 2026
#206)

* fix(scan): skip malformed repoquery lines instead of crashing the scan

scan_rawhide_state.query() unpacked the first non-empty repoquery line
into four tab-separated fields, so any dnf5 warning or unexpected line
raised ValueError and took down the whole nightly report (issue #172).

Skip lines that are not the expected four-field shape, pick the first
line that is, and log the discarded line to stderr so a systematically
malformed query stays visible. Add unit tests covering a stdout that
mixes a warning line with a good one and one with no good line.

Signed-off-by: kylerankin <kylerankin@users.noreply.github.com>

* fix(scan): reject four-field lines whose sourcerpm is not a src.rpm

A warning/progress line can carry 3+ tabs and pass the field-count guard,
then feed source_name() a non-SRPM sourcerpm that would raise. Require the
sourcerpm to end in .src.rpm in query() so such a line is skipped (this PR's
job) instead of reaching source_name(). Regression test added.

Addresses the low finding in #206.

* fix(scan): validate sourcerpm with SRPM_NAME, not a suffix check

The guard added in the previous commit only required the fourth field to
end in `.src.rpm`. That is a weaker grammar than `SRPM_NAME`, which
`source_name()` applies: a line such as `foo\tbar\tbaz\tqux.src.rpm`
passed the guard, was written into `config/rawhide-state.json`, and then
crashed `main()` when `source_name()` raised `ValueError` on it. That is
the residual sliver of the issue #172 crash class the guard was meant to
close, and it made the accompanying comment inaccurate.

Validate with `SRPM_NAME` so the skip decision uses exactly the grammar
that `source_name()` will later demand, and nothing that would raise can
reach state. Tests cover the suffix-only case, and a well-formed source
RPM whose name contains `-`, so the stronger guard is pinned in both
directions.

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

* fix(scan): emit real tabs in dnf5 --qf, prefer x86_64/noarch

#99 assumed dnf4 --qf semantics on dnf5: dnf5 expands only \n, not \t, in the
query format, so a literal \t glues the i686 and x86_64 records into one line.
query() then returned None for every package and main() wrote an empty report
that exited green, hiding #172 instead of closing it.

Use real tabs and a trailing newline in --qf, prefer the x86_64 then noarch
record over lines[0] (i686 sorts first), and keep the SRPM_NAME guard. Pin the
real tab and the glued-record case in tests so the regression cannot recur
unseen.

Closes #206 review finding from Danathar.

* fix(scan): log every discarded repoquery line and arch-filtered drop

The PR body and rule 16 promise that a discarded line is logged to stderr so a
systematically malformed query stays visible, but only four-field lines with a
non-SRPM sourcerpm were logged: lines failing the field-count check hit a bare
continue, and a package whose records are all non-x86_64/noarch was dropped by
the arch preference with no trace at all.

Parse the lines once into an arch-keyed map, logging both discard reasons, then
apply the x86_64-then-noarch preference over that map and log the package when
neither arch is present. Behavior for well-formed output is unchanged.

Also fix test_query_skips_srpm_suffixed_line_source_name_cannot_parse, which
used arch 'baz': the arch preference rejected the line before the SRPM_NAME
guard the test claims to pin ever ran. It now uses x86_64 and asserts the
guard's own stderr message.

---------

Signed-off-by: kylerankin <kylerankin@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

testing: tools/scan_rawhide_state.py has no unit test coverage

2 participants