oliver-zehentleitner / maity

clean-up: CLI + runner: one repository URL normalisation instead of three parsers (gitfacts, runner/config)

Sign in to report

tsk-90ck9k4f24gd Open

From the clean-up audit tsk-hgnbapyw7hnh, the cross-area findings (areas 9 and 13) that the per-area cards left to one shared card. Read at main 80647565; every line number is at that SHA, so check it against current main first.

Kind: duplication / docs drift. Effort: M. Risk: medium. The runner's repository allowlist and the clone check depend on it, so a changed result can refuse a project or admit a different one.

Order:

  • tsk-egaycsbdwmeq item 8 makes gitfacts._branch public, and item 9 adds maity/names.py. The shared helper can live beside names.py. Coordinate, or do this after it.
  • tsk-qtr9myhtysbs (security, in progress) validates repository owner and name on the hub. Keep the CLI's accepted forms no wider than the hub's.
  • tsk-rzhydxnsav4m (repository URL on any forge host) may widen which hosts and paths count. Do this after it, or make the helper take any host.

What is wrong

Three functions in cli/src/maity parse a Git remote or repository URL, each in its own way:

  • gitfacts.py:429-443 repository_key(value) -> (host, path): handles https://, ssh://, the scp form git@host:owner/name and bare host/owner/name. It drops the user and the port (via hostname), lowercases the host and strips / and .git. Used by repository_mismatch (:446-456, the join's advisory check).
  • runner/config.py:452-466 normalise_repository(value) -> "host/owner/name": drops the scheme and user, keeps a port, strips / and .git, and lowercases the host. It does not handle the scp form: git@github.com:o/n becomes github.com:o/n, which REPOSITORY (config.py:40) then refuses. Used at config.py:356, :427, :434, :496, :504, adapters.py:354, supervisor.py:803 and :1020, and workspace.py:162 (the clone's origin against the placement's repository).
  • gitfacts.py:147-155 remote_host(url): a third parse, only for the host (with a Windows drive-path rule that neither of the others has). Used at gitfacts.py:166.
  • (supervisor.py:1035-1036 also takes urlsplit(...).hostname of the repository inline.)

This contradicts cli/context/runner.md:37-49 (b1571548, "Repository entries and project URLs go through one normalisation"). That entry covers the runner only, but the CLI has a second, different normalisation for the same values. The two also disagree on the port: repository_key drops it, normalise_repository keeps it.

Proposal

  • One module (for example maity/repourl.py, or next to names.py from tsk-egaycsbdwmeq) with parse(value) -> Repo(host, port, path) that handles https, ssh, scp form and bare host/owner/name, plus key(repo) for comparisons and host(value) for remote_host.
  • normalise_repository, repository_key and remote_host become thin wrappers or are replaced at their call sites. repository_url_ok (config.py:472-488) stays the gate for what the runner may clone.
  • Update runner.md b1571548 to name the shared function and say whether the scp form is accepted in config entries.
  • Tests: the parametrised cases in cli/tests/test_runner.py:120 (test_normalise_repository) and cli/tests/test_report.py:215 (test_remote_host) become one table that all three wrappers must pass.

Open questions

  • Can runner config entries be in scp form? At 80647565 they cannot. normalise_repository("git@github.com:o/n") gives github.com:o/n, and _repositories (config.py:501-509) refuses it with "expected host/owner/name", which does not tell the operator why. The project's repository.url cannot be scp either: repository_url_ok (config.py:472-488) accepts only https and ssh URLs. So today the gap causes a confusing refusal, not a wrong match. Decide: accept the scp form in limits.repositories and [repositories.*] (normalised to host/owner/name), or refuse it with a clear message.
  • Port: should github.com:2222/o/n and github.com/o/n be the same repository? The runner says no (the port is kept, and REPOSITORY allows it). The join check says yes. Pick one.

Left out as duplicates: none. Searched: normalise_repository, repository_key, remote_host. tsk-egaycsbdwmeq covers the git-call wrappers, not URL parsing.

Effort: M = 3 points.