Skip to content

fix(ssh): replace private _username with public get_extra_info API#408

Open
xingyug wants to merge 1 commit intorhel-lightspeed:mainfrom
xingyug:fix/replace-private-username-api
Open

fix(ssh): replace private _username with public get_extra_info API#408
xingyug wants to merge 1 commit intorhel-lightspeed:mainfrom
xingyug:fix/replace-private-username-api

Conversation

@xingyug
Copy link
Copy Markdown
Contributor

@xingyug xingyug commented Apr 16, 2026

Summary

Replace all usages of asyncssh's private conn._username attribute with the public conn.get_extra_info("username") API.

Motivation

The codebase accesses SSHClientConnection._username in 5 places for audit logging and error messages. This is a private attribute (prefixed with _) that is not part of asyncssh's public API contract. While it works today, it could break on any future asyncssh release without notice.

asyncssh provides get_extra_info("username") as the documented public API for retrieving the authenticated username. It returns the same value — verified to be the exact same object (is identity) in testing.

Changes

src/linux_mcp_server/connection/ssh.py (5 replacements):

  • Connection pool reuse audit log (L122)
  • New connection audit log (L160)
  • Command timeout error message (L244)
  • get_remote_bin_path() SSH error message (L325)
  • get_remote_bin_path() not-found error message (L330)

Tests (3 files, mock pattern updated):

# Before: setting private attribute directly
Mock(SSHClientConnection, _username="testuser")

# After: mocking the public API
mock = Mock(SSHClientConnection)
mock.get_extra_info.return_value = "testuser"

Verification

  • make verify passes (ruff ✅, pyright ✅, 487 tests ✅)
  • Manually verified get_extra_info("username") returns identical results to _username across multiple scenarios (explicit username, SSH config inferred username)

Replace all usages of asyncssh's private `conn._username` attribute
with the public `conn.get_extra_info('username')` API. This decouples
us from asyncssh's internal implementation details and prevents
potential breakage on future asyncssh upgrades.

5 occurrences replaced in ssh.py, corresponding test mocks updated.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown

For team members: test commit 145428d in internal GitLab

@xingyug xingyug marked this pull request as ready for review April 16, 2026 13:15
@xingyug xingyug requested a review from a team as a code owner April 16, 2026 13:15
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 96.47% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/linux_mcp_server/connection/ssh.py 93.44% <100.00%> (ø)
tests/connection/ssh/test_connection_manager.py 100.00% <100.00%> (ø)
tests/connection/ssh/test_get_bin_path.py 100.00% <100.00%> (ø)
tests/connection/ssh/test_timeout.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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