Skip to content

refactor(tools): wrap check_workflow_quoting and validate in testable functions - #73

Merged
castrojo merged 1 commit into
mainfrom
quality/issue64-testable-scripts
Sep 12, 2026
Merged

castrojo merged 1 commit into
mainfrom
quality/issue64-testable-scripts

Conversation

@castrojo

Copy link
Copy Markdown
Contributor

Summary

Wrap module-level scripts into callable functions with testable seams, keeping existing CLI behavior and exit codes identical:

  • tools/check_workflow_quoting.py:

    • Extracted def offending_lines(workflows: Iterable[Path]) -> list[tuple[str, int, str]]
    • Extracted def main(workflows_dir: Path | None = None) -> int
    • Guarded execution with if __name__ == "__main__": raise SystemExit(main())
  • tools/validate.py:

    • Extracted def check_provenance(path: Path, data: dict) -> None
    • Extracted def main(root: Path = Path(".")) -> int
    • Guarded execution with if __name__ == "__main__": raise SystemExit(main())

This provides the necessary seams so unit tests can pass synthetic workflow files and .hummingbird-upstream.json fixtures without executing the scripts against the real repo at module import time.

Closes #64

… functions

Extract offending_lines() and check_provenance() functions alongside main()
entry points to allow unit testing with synthetic fixtures without executing
at module import time. CLI behavior and exit codes remain unchanged.

Closes #64

@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.

Small, behaviour-preserving, and it unblocks four other open PRs. This looks ready.

Gates are identical to the unmodified-main baseline, which is what a pure refactor should produce. Merged into main (54cc8d1):

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

Baseline: 193 SRPMs, 72 passed, 72 contract packages. No delta anywhere — the CLI paths behave exactly as before.

Both scripts are live CI gates, so the seams matter. I confirmed how they are invoked:

  • tools/validate.py — the entire validate job in .github/workflows/validate.yml (- run: python3 tools/validate.py), plus just validate via the check recipe.
  • tools/check_workflow_quoting.py — first line of the Validate factory policy and tests step in rebuild-rpms.yml's prepare job, ahead of runtime_contract.py and the unittest discovery.

Both currently run as module-level scripts, so any test has to shell out or fake sys.argv and the real repo tree. raise SystemExit(main()) under a __main__ guard with main(root: Path = Path(".")) / main(workflows_dir: Path | None = None) is the minimal change that fixes that, and it keeps exit codes identical — which is the property that matters, since rebuild-rpms.yml reads them.

It composes with the test PRs. #61 and #71 both add tests/test_validate.py, and #59/#61 both add tests/test_check_workflow_quoting.py. Those suites drive the scripts through the CLI, so they neither need nor break this refactor. Confirmed:

$ git merge pr/73 && git merge pr/61 && python3 -m pytest tests -q
97 passed in 1.54s

No conflict. Worth landing this first regardless, so the next round of tests can call offending_lines() and check_provenance() directly instead of round-tripping through a subprocess and a synthetic factory tree. That is the whole point of issue #64 and this PR delivers it.

Two minor notes, neither blocking:

  1. check_workflow_quoting.py currently reports checked 10 workflows: no build script contains a quote that would close it — that count is a useful assertion for whichever test PR lands, and it changed recently (commit 54cc8d1 widened the scan from rebuild-rpms.yml to every workflow). Nothing to do here, just worth knowing the behaviour being wrapped is two commits old.

  2. offending_lines() returning list[tuple[str, int, str]] is fine, but a small named tuple or dataclass would make the eventual test assertions read better than result[0][1] == 42. Entirely optional.

No CI has run on this PR (get_check_runs → total_count: 0), but given the change is two __main__ guards and two function extractions with no behaviour delta, and both gates pass locally on the merged tree, I do not think that is a blocker here the way it is for the larger PRs.


Generated by Claude Code

@castrojo castrojo added the lgtm Approved by a Hive merger/owner for auto-merge on green CI label Sep 12, 2026
@castrojo
castrojo merged commit 7e7fc75 into main Sep 12, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm Approved by a Hive merger/owner for auto-merge on green CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[quality] tools/check_workflow_quoting.py and tools/validate.py are untestable module-level scripts

2 participants