oliver-zehentleitner / maity

clean-up: G6 tools and scripts: one origin-URL parser for the shell tools, ci_watch's doubled PR check and asserts, tools/ Python not linted

Sign in to report

tsk-hq56zjtmx55j Open

From the clean-up audit tsk-hgnbapyw7hnh (uncovered files, G6: CLI leftovers, public-page leftovers, tools and scripts), read at 9dfd4b65.

Not in scope: the gate's workflow wiring (publish-image.yml, release_gate.py's use in the release workflows), which tsk-6zh891gy6cvz is changing (#1760, #1762).

1. origin's owner, repository and host are parsed three times, by two different rules (duplication, rule implemented twice)

  • Files: tools/pr.sh:121-162 (a strict parser: exactly owner/repo after the host, . and .. refused, the proxy's /git/ prefix stripped); tools/overlap.sh:119-164 and tools/coverage.sh:61-94 (one loose parser, copied: the last two path segments, so https://github.com/a/b/c reads as b/c; coverage.sh:61 says it reads origin "as tools/overlap.sh reads them").
  • What is wrong: the same question gets different answers by tool. The P3 notes on tsk-dest4a10zfw9 (nte-8zy0qmaefvhr: an upper-case FILE:// falls into the loopback rule; nte-ybf994g41qe0: 127.999.999.999 counts as loopback) are bugs of the loose copy; fixing them in overlap.sh leaves coverage.sh with them.
  • Proposal: one tools/lib/origin.sh (functions that set repo_owner, repo_name, repo_host) on pr.sh's stricter rules plus the two P3 fixes, sourced by all three scripts; their tests (tools/test_pr.py, test_overlap.py, test_coverage.py) keep the URL cases, and one table of cases runs against the shared file.
  • Effort: M. Risk: low to medium; a URL that the loose parser accepted (extra path segments) is refused afterwards.

2. ci_watch.py reads and judges the pull request twice (duplication)

  • Files: tools/ci_watch.py:202-216 (check: GET pulls/<n>, merged, closed, head moved) and :290-305 (admit: the same GET and the same three checks with other wording).
  • Proposal: one _pr_state(pr, sha, gh, repo) -> (data, reason | None) that both use; check turns the reason into its report line, admit returns it.
  • Effort: S. Risk: low (tools/test_ci_watch.py covers both paths).

3. ci_watch.py checks GitHub's answers with assert, and the run loop does not survive a surprise (debt)

  • Files: tools/ci_watch.py:205, :218, :235, :296 (assert isinstance(..., dict)), plus unguarded keys (pr["head"], run["id"], run["run_attempt"]); :251-281 run_pass catches only Transient; :630-647 the run loop has no guard around run_pass.
  • What is wrong: an answer of another shape raises AssertionError or KeyError and ends run for every queued pull request, while the intake beside it is guarded by a broad except (:636) on purpose. Under python -O the asserts are gone and the error comes later.
  • Proposal: a small _dict(value, what) that raises Transient for anything but a dict, and .get with a Transient for the required keys, so one odd answer leaves that line for the next pass.
  • Effort: S. Risk: low.

4. tools/*.py is neither linted nor type-checked (debt, design)

  • Files: hub/Makefile:22-28 and hub/pyproject.toml:71 cover hub/scripts and hatch_build.py; cli/Makefile:7-17 covers cli/src and cli/tests; .github/workflows/ci.yml:107-137 (changelog job) only runs python -m unittest over tools/; tools/pre_push.py:34 PACKAGES = ("hub", "cli").
  • What is wrong: about 2,300 lines of Python, tests not counted, that CI and release jobs run (release_gate.py, changelog.py, rechain.py, ktw_pin.py, site_docs.py, ci_watch.py) have no formatter, linter or type check. Drift is already there: tools/site_docs.py:35-36 are over 100 characters, :98 and :110 take a bare re.Match, tools/release_gate.py:70 and :85 return a bare dict.
  • Proposal: a lint target in tools/Makefile that runs the hub's pinned black, ruff and mypy (hub/requirements/dev.txt) over tools/*.py, run by the changelog job and by pre_push.py for a push that touches tools/. Format once in its own PR; release_gate.py after tsk-6zh891gy6cvz has landed.
  • Effort: M. Risk: low (formatting churn; one PR that conflicts with open tools/ work).

5. The Keep the Why linter pin is parsed twice, with different tolerance (duplication)

  • Files: tools/pre_push.py:124-127 (keep-the-why@[0-9a-f]{40} # lint-v(\S+): exactly one space before #); tools/ktw_pin.py:54 LINT_ACTION (any spaces, any ref).
  • What is wrong: a reformatted workflow line that ktw_pin.py still accepts makes the pre-push hook report no pin and stop every push.
  • Proposal: pre_push.py imports ktw_pin.LINT_ACTION and takes the tag from it (both scripts are standard library, side by side in tools/).
  • Effort: S. Risk: low.

Order

Item 4 last, or first in its own PR; either way it should not be mixed with items 1-3 and 5.

Covered elsewhere

  • Two P3 findings on overlap.sh's URL rules: tsk-dest4a10zfw9 (notes nte-8zy0qmaefvhr, nte-ybf994g41qe0); item 1 folds them in. The missing branch-filter test of ci_watch.py: tsk-dest4a10zfw9 note nte-tfq4gx3ebjre.
  • Reviewed and left: ci_watch.py:636 broad except (documented, keeps the queue pass running); tools/test_site_docs.py skips without Markdown, but CI installs it (ci.yml:136-137).

Effort: 2M + 3S.

Notes

  1. Lotse · Nov 18, 2026, 20:06 UTC

    Item 1 (one origin-URL parser for tools/) moves to tsk-kgkh3gz3mkfz, which already holds it. Leave it out here (lotse, req-gqt5b2812nej).