Skip to content

fix(ssh): resolve ssh config path lazily and tolerate match-only stanzas#72

Open
wietzesuijker wants to merge 1 commit into
mila-iqia:masterfrom
wietzesuijker:fix/ssh-config-hermeticity
Open

fix(ssh): resolve ssh config path lazily and tolerate match-only stanzas#72
wietzesuijker wants to merge 1 commit into
mila-iqia:masterfrom
wietzesuijker:fix/ssh-config-hermeticity

Conversation

@wietzesuijker
Copy link
Copy Markdown

If you run pytest tests/test_integration.py locally on cluv main and your ~/.ssh/config happens to contain a Match host X exec ... block, six test_init parametrizations crash with KeyError: 'host' inside paramiko. CI passes because CI's ssh config has none, so the breakage only shows up on dev laptops.

Two small things combine to cause it. cluv/ssh.py evaluates SSH_CONFIG_PATH at module import, so by the time tmp_path monkeypatches Path.home, the constant already points at your real home directory. The tests end up reading whatever you have on disk. And paramiko 4.0.0's SSHConfig.get_hostnames() indexes entry["host"] unconditionally, which a pure Match block doesn't have, so it raises.

The fix resolves the path inside get_ssh_hostnames so the fixture's monkeypatch actually applies, and wraps the paramiko call in a try/except that falls back to scanning _config and skipping match-only entries.


AI (Claude) supported my development of this PR.

`SSH_CONFIG_PATH` was captured at module import, so tests that
monkeypatch `Path.home` to a `tmp_path` still read the developer's real
~/.ssh/config. Local runs of `tests/test_integration.py::test_init`
crash on `KeyError: 'host'` when paramiko 4.0.0 hits `Match host ... exec ...`
blocks; CI passes because CI's ssh config has no such stanza.

Resolve the path inside `get_ssh_hostnames` so the fixture's monkeypatch
applies, and fall back to scanning the parsed entries when paramiko's
`get_hostnames` trips on match-only stanzas.
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.

1 participant