Skip to content

Node registry, dry-run, and execSSH error mapping have no unit tests #100

Closed

Description

@TMHSDigital

Summary

The functions that route every one of the 50 tools to a host have no unit tests: node registry parsing, node lookup, dry-run handling, execSSH error mapping, and errorResponse.

Where

  • mcp-server/src/utils/ssh-api.ts:46-90 (getNodesRegistry, getNodeConfig, listNodes)
  • :98 (dry-run check), :146-165 (error mapping), :185-232 (errorResponse, getErrorSuggestion)
  • integration.test.ts:3-21 mocks listNodes and getNodeConfig entirely. ssh-guard.test.ts covers only the command guard and the dry-run happy path.

Suggested fix

Add mcp-server/src/utils/__tests__/ssh-api.test.ts, mocking ssh2.Client for the connection cases:

  • HOMELAB_NODES unset: listNodes() returns only the default node
  • Valid JSON using user and using username: mapping is correct and the default user is pi
  • Malformed JSON: assert the intended behavior (an error or warning, not silent {})
  • getNodeConfig("missing") throws SSHError whose message lists the available nodes
  • getNodeConfig("default") with no registry entry returns the env config
  • Dry-run with HOMELAB_DRY_RUN set to "false", "0", and "true": pin the semantics
  • Mocked client: ECONNREFUSED gives SSHConnectionError, and "All configured authentication methods failed" gives SSHAuthError
  • Mocked client: a non-zero exit gives CommandFailedError carrying stderr
  • Fake timers: the timeout path gives SSHTimeoutError and the connection is ended
  • errorResponse includes the right Suggestion line for each error class

Acceptance criteria

  • The new test file covers the cases above and runs in CI

Getting started

  • Relevant files: mcp-server/src/utils/ssh-api.ts, mcp-server/src/utils/errors.ts
  • How to run tests: cd mcp-server && npm test

Filed by repo-audit/full-audit at 9cfe5e3. Severity: medium. Effort: M. audit-key: testing|mcp-server/src/utils/ssh-api.ts|getNodesRegistry

Activity

  1. added
    help wanted
    testing
    severity: medium
    on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedseverity: mediumtesting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions