test(ssh): cover FindPrivateKeys edge cases - #1025
Merged
Merged
Conversation
# pkg/ssh: cover FindPrivateKeys edge cases ## Package reviewed `pkg/ssh` (SSH/git/credentials category) ## Issue found `FindPrivateKeys` (in `pkg/ssh/ssh_add.go`) had **no test coverage**. It reads the user's `~/.ssh` directory, parses each entry as a private key, and returns the paths that parse successfully. Its real edge cases were unverified: - a missing `.ssh` directory surfaces a read error, - non-key files (`.pub`, `config`) and subdirectories must be skipped, - an empty `.ssh` directory yields no keys (no error). ## Change Add `pkg/ssh/ssh_add_test.go` with three table-style tests exercising those paths: - `TestFindPrivateKeys_MissingSSHDirReturnsError` — `~/.ssh` absent → error. - `TestFindPrivateKeys_ReturnsOnlyValidPrivateKeys` — a generated RSA private key is returned, while an adjacent `.pub`, `config` file, and subdirectory are skipped. Uses a real generated key (`rsa.GenerateKey`) — no mocks. - `TestFindPrivateKeys_EmptySSHDirReturnsNoKeys` — empty `.ssh` → no keys, no error. No behavioral change to production code. ## Verification performed - `task cli:format` — clean. - `task cli:lint:ci` — **0 issues** (new-from-patch against origin/main). - `task cli:test` — passes. The only failing package is `pkg/git` (`TestRepoClone*`), the known pre-existing failure on origin/main, unrelated to this change (which touches only `pkg/ssh`). - Focused run: `go test ./pkg/ssh/ -run TestFindPrivateKeys -v` — all 3 pass. This PR was created by an AI agent as part of an automated daily package review job.
✅ Deploy Preview for devsydev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for images-devsy-sh ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
AI Reviewer: run a review on demand. To trigger the first review automatically, go to your organization or repository integration settings. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes.
Use 0o600 for the public key and config fixture files so gosec G306 (Expect WriteFile permissions to be 0600 or less) passes. The files are throwaway fixtures under a temp .ssh dir, so the stricter mode does not change test behavior. This commit was created by an AI agent (OpenHands) on behalf of the user.
skevetter
marked this pull request as ready for review
August 18, 2026 04:10
|
Tick the box to add this pull request to the merge queue (same as
|
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.
pkg/ssh: cover FindPrivateKeys edge cases
Package reviewed
pkg/ssh(SSH/git/credentials category)Issue found
FindPrivateKeys(inpkg/ssh/ssh_add.go) had no test coverage. It reads theuser's
~/.sshdirectory, parses each entry as a private key, and returns the pathsthat parse successfully. Its real edge cases were unverified:
.sshdirectory surfaces a read error,.pub,config) and subdirectories must be skipped,.sshdirectory yields no keys (no error).Change
Add
pkg/ssh/ssh_add_test.gowith three table-style tests exercising those paths:TestFindPrivateKeys_MissingSSHDirReturnsError—~/.sshabsent → error.TestFindPrivateKeys_ReturnsOnlyValidPrivateKeys— a generated RSA private key isreturned, while an adjacent
.pub,configfile, and subdirectory are skipped.Uses a real generated key (
rsa.GenerateKey) — no mocks.TestFindPrivateKeys_EmptySSHDirReturnsNoKeys— empty.ssh→ no keys, no error.No behavioral change to production code.
Verification performed
task cli:format— clean.task cli:lint:ci— 0 issues (new-from-patch against origin/main).task cli:test— passes. The only failing package ispkg/git(
TestRepoClone*), the known pre-existing failure on origin/main, unrelated tothis change (which touches only
pkg/ssh).go test ./pkg/ssh/ -run TestFindPrivateKeys -v— all 3 pass.This PR was created by an AI agent as part of an automated daily package review job.