Skip to content

test(ssh): cover GetUser config parsing - #956

Merged
skevetter merged 2 commits into
mainfrom
pkg-ssh-git/getuser-tests
Aug 9, 2026
Merged

skevetter merged 2 commits into
mainfrom
pkg-ssh-git/getuser-tests

Conversation

@devsy-app

@devsy-app devsy-app Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Package reviewed

pkg/ssh (SSH/git/credentials category — scope: pkg/ssh, pkg/gitsshsigning, pkg/gitcredentials, pkg/credentials, pkg/pty, pkg/shell, pkg/dotfiles, pkg/gpg).

Issue found

GetUser in pkg/ssh/config.go resolves the SSH User directive for a workspace host but had no direct unit-test coverage. The parsing logic (host-section matching, Include precedence, empty-path defaulting to ~/.ssh/config, quoted-value unquoting, and the root fallback) was exercised only indirectly, so regressions in any of those branches could land unnoticed.

Change

Add pkg/ssh/config_getuser_test.go with 7 focused unit tests covering the previously-untested paths:

  • TestGetUser_ReturnsRootWhenConfigMissing — default root when no config file exists.
  • TestGetUser_ReturnsConfiguredUser — reads the User directive from the workspace host section.
  • TestGetUser_ReturnsRootWhenNoUserDirective — default when the host section exists but lacks a User line.
  • TestGetUser_ReturnsRootWhenHostSectionAbsent — default when the config has no section for the workspace.
  • TestGetUser_IncludePathTakesPrecedence — when an include path is supplied, the user is read from it rather than the primary config.
  • TestGetUser_EmptyPathResolvesHome — an empty path resolves to ~/.ssh/config (the same default ConfigureSSHConfig writes to).
  • TestGetUser_UnquotesQuotedUser — a quoted User value (without inner spaces) is unquoted, as written by SSH clients that quote values containing special characters.

No production code is changed — tests only.

Verification performed

  • task cli:format — clean (no formatting changes).
  • task cli:lint:ci — 0 new issues.
  • task cli:test — pkg/ssh tests pass (7/7 new tests pass). The only failures are the known pre-existing ones unrelated to this change: pkg/git (TestRepoClone*, stale assertion on origin/main) and e2e (TestRunE2ETests).

This PR was created by an AI agent as part of an automated daily package review job.

Add unit tests for GetUser in pkg/ssh/config.go, which previously had no direct test coverage. Tests cover: default root user when config is missing, reading a configured User directive, default when the host section lacks a User line, default when no section exists for the workspace, include path taking precedence over the primary config, empty path resolving to ~/.ssh/config, and unquoting of quoted User values. No behavioral change.
@netlify

netlify Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for images-devsy-sh canceled.

Name Link
🔨 Latest commit 237ed7e
🔍 Latest deploy log https://app.netlify.com/projects/images-devsy-sh/deploys/6a78b17b04fa0000083c779c

@netlify

netlify Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for devsydev canceled.

Name Link
🔨 Latest commit 237ed7e
🔍 Latest deploy log https://app.netlify.com/projects/devsydev/deploys/6a78b17b2545650008c5b385

@github-actions github-actions Bot added the size/m label Aug 9, 2026
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 9 complexity · 9 duplication

Metric Results
Complexity 9
Duplication 9

View in Codacy

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.

Run reviewer

TIP This summary will be updated as you push new changes.

@skevetter
skevetter marked this pull request as ready for review August 9, 2026 16:52
Signed-off-by: GitHub <noreply@github.com>
@skevetter
skevetter merged commit 9da5d6c into main Aug 9, 2026
67 checks passed
@skevetter
skevetter deleted the pkg-ssh-git/getuser-tests branch August 9, 2026 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant