Skip to content

Look a repository up on the host an SSH alias stands for - #166

Open
ammartahamohamedy wants to merge 1 commit into
prooflinedev:mainfrom
ammar-taha-dev:fix/ssh-host-alias
Open

ammartahamohamedy wants to merge 1 commit into
prooflinedev:mainfrom
ammar-taha-dev:fix/ssh-host-alias

Conversation

@ammartahamohamedy

Copy link
Copy Markdown

Fixes #165

Problem

The CLI looked a repository up by the host its remote names, while Git connects through SSH, which resolves Host aliases. A remote like git@github-work:acme/web.git, or a github.com remote that url.<alias>.insteadOf rewrites to one, sent host=github-work, so every repository command and every hook review got 404: repository not found. Hooks have no --repo to work around it.

Fix

  • Lookup first, SSH second (lib.rs source(), both lookup call sites). The repository is looked up on the remote's own host, as before. Only when that returns 404 for an ssh or scp-style remote does the CLI ask SSH for the host it connects to, and look there.
    • Lookup first keeps every working lookup as it is, including GitHub's SSH over port 443 (Host github.com → HostName ssh.github.com, Port 443), and runs ssh only on the failure path.
    • The second lookup guesses the provider from the resolved host, unless --source-provider names one, so an alias for gitlab.com is looked up as GitLab.
  • git::ssh_host(host) runs ssh -G -- <host> and returns its hostname (with a non-22 port, as parse writes hosts) only when it differs from host. ssh.github.com counts as github.com.
    • Fails soft: no ssh, a non-zero exit, a missing or malformed hostname, or the 5-second timeout means no second lookup.
    • A host that starts with - is never passed to ssh, and -- comes first. Stdin and stderr are closed.
    • RemoteRepository gains an ssh flag, set by parse for ssh:// and scp-style URLs; parsing is otherwise unchanged.
  • A 404 names what was looked up, for commands and hooks: looked up acme/web on host github-work and on host github.com, its SSH host: … returned HTTP 404: repository not found, or just the one host when SSH resolves nothing. That covers what ssh -G can't resolve: an alias that only core.sshCommand -F or PuTTY knows, or a repository that isn't connected. Other errors are unchanged.
  • README: one sentence on each.
before: Proofline could not review the staged changes: https://proofline.sh returned HTTP 404: repository not found
after:  (reviewed: github-work 404s, its SSH host github.com is found)

Tests (written first; failed before the change)

Test What it checks
git::tests::an_ssh_alias_reads_as_the_host_ssh_connects_to (new) ssh -G output: an alias becomes its hostname, a non-22 port is kept, ssh.github.com on 443 is github.com, a host that is no alias resolves to nothing (whatever port SSH uses), and output with no usable host (missing, empty, option-like, whitespace, a path) resolves to nothing
git::tests::ssh_is_never_asked_about_a_host_that_reads_as_an_option (new) a host starting with - resolves to nothing
git::tests::reads_owner_and_name_from_remote_urls (extended) the ssh flag: set for ssh://, unset for https://
ssh_over_port_443_keeps_the_github_com_lookup (new, tests/hooks.rs, Unix) with github.com → ssh.github.com:443 in a stand-in ssh, a git@github.com: remote is reviewed and ssh is never run
an_ssh_host_alias_is_looked_up_on_the_host_it_stands_for (new, Unix) the pre-commit hook reviews through an alias remote, an alias for ssh.github.com:443 and an insteadOf rewrite, and review --repo git@github-work:… does too
a_repository_missing_on_both_hosts_names_both (new, Unix) the 404 names the alias and its SSH host, for the hook and findings --pr; the console sees exactly those two lookups, the second for a gitlab.com alias as GitLab
a_repository_the_console_cannot_find_is_named_with_its_host (new) a host SSH doesn't resolve is looked up once, and the 404 names it, for the hook and findings --pr

The hooks stand-in console now answers 404 for a host other than github.com, as the real console does, instead of failing an assertion; existing tests are unaffected.

Mutation checks: each of these fails a test: ignoring SSH's port, resolving a host that is no alias, accepting a hostname with a path, keeping ssh.github.com as is, marking every remote as SSH, dropping the 404 context, no SSH fallback, a second lookup that asks for the alias again, not re-guessing the provider, and a 404 that names only one host.

Checks

  • cargo fmt --check: ✅

  • cargo clippy --locked --all-targets -- -D warnings: ✅ on Linux (Debian, 1.100.0). On Windows it stops at the 2 errors main already has there (src/agent/tests.rs).

  • cargo test --locked: ✅ on Linux, every suite passes (175 tests, 1 ignored as on main). On Windows, the same 12 failures as on main (tests/mcp.rs ×7, agent_install ×2, update, local_patch, hooks on a Windows push URL); the three Unix-only tests don't run there.

  • After rebasing onto 16a230f: the same results, except setup::tests::setup_brief_commands_are_available_in_this_release, which fails on clean 16a230f too (Linux and Windows), so it isn't from this change.

  • cargo deny check: no dependency changes.

  • End to end (Linux, a throwaway SSH config read by real OpenSSH, a stand-in console that knows acme/web only on github.com), upstream 430cb44 → this branch:

    Case Before After
    review --pr 7 on git@github-work:acme/web.git 404 github-work 404, then found on github.com
    pre-commit hook, same remote could not review … 404 reviewed
    git@github.com:… rewritten to the alias by insteadOf 404 found on github.com
    alias only core.sshCommand -F knows 404 404, looked up acme/web on host github-other
    git@github.com:… with GitHub's SSH over port 443 configured found found, one lookup, ssh not run
  • Fork CI: ✅ check and windows pass on ammar-taha-dev/proofline-cli#9.

Overlaps: #130 and #163 each add a second get-url + parse lookup (remote_repository_in); parse now sets the ssh flag their repositories carry, so a lookup of them through source() gets the fallback. No textual conflict.

Proofline review log

Fork review PR: ammar-taha-dev/proofline-cli#9. Rounds capped at 2.

Round Finding What I made of it Outcome
1 None — Clean on the first round
2 Two warnings in src/init.rs (proofline init): the install address is printed raw, and a null or non-HTTPS primary address skips the fallback Both right, but in upstream code from 16a230f: after the rebase the fork's main still sat at 430cb44, so the fork PR showed upstream's new commits too. Nothing in this change touches init.rs Not changed here; the fork's main was synced, and both are noted for separate issues

The prompts below are the ones that drove this implementation; the investigation, reproduction and fix scope were done before them and aren't included.

This branch has not been deployed

No deployments
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.

A checkout cloned through an SSH host alias gets "404: repository not found" from every repository command and hook

1 participant