fix(ssh): resolve ssh config path lazily and tolerate match-only stanzas#72
Open
wietzesuijker wants to merge 1 commit into
Open
fix(ssh): resolve ssh config path lazily and tolerate match-only stanzas#72wietzesuijker wants to merge 1 commit into
wietzesuijker wants to merge 1 commit into
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If you run
pytest tests/test_integration.pylocally on cluv main and your~/.ssh/confighappens to contain aMatch host X exec ...block, sixtest_initparametrizations crash withKeyError: '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.pyevaluatesSSH_CONFIG_PATHat module import, so by the timetmp_pathmonkeypatchesPath.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'sSSHConfig.get_hostnames()indexesentry["host"]unconditionally, which a pureMatchblock doesn't have, so it raises.The fix resolves the path inside
get_ssh_hostnamesso the fixture's monkeypatch actually applies, and wraps the paramiko call in a try/except that falls back to scanning_configand skipping match-only entries.AI (Claude) supported my development of this PR.