16 tools have no handler test; ssh-api test mocks are copied and have drifted

未關閉
#164 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
55/100
Issue 類型
重構
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
node.js, typescript
領域
testing

研究方向

Start by reading mcp-server/src/utils/ssh-api.ts around the exported helpers and the checkSSHAvailable reference, then compare it with the hand-written mocks in handlers.test.ts, integration.test.ts and confirm-gates.test.ts. Create one shared mock factory that uses importOriginal() and overrides only execSSH, then migrate one test file at a time and run cd mcp-server && npm install && npm test. Done means every listed tool has at least one handler test, checkSSHAvailable and its mock are gone, and the tests pass against the real helper shapes.

由索引模型根據 Issue 內容生成。

描述

help wanted severity: low testing

Summary

Sixteen tools have only schema and registration coverage, and each test file hand-writes its own ssh-api mock, which no longer matches the real module.

Where

  • mcp-server/src/tools/__tests__/handlers.test.ts:3-13, :59-61, :227-241
  • mcp-server/src/tools/__tests__/integration.test.ts:3-28
  • mcp-server/src/tools/__tests__/confirm-gates.test.ts:6-17
  • mcp-server/src/utils/ssh-api.ts:406-412 (checkSSHAvailable, unused)

Details

No handler or command test for: adguardQueryLog, aptUpgradable, certList, composePull, containerScan, diskUsage, fail2banStatus, journalLogs, kernelInfo, networkInfo, npmCerts, ntfySend, openPorts, serviceLogs, speedtestResults, ufwStatus. piStatus's node: "all" path is untested.

Mock drift: handlers.test.ts's getNodeConfig returns no port; its nodeSetting ignores per-node env; errorResponse is re-implemented as error.message; TIMEOUTS values are copied; integration still mocks the unused checkSSHAvailable. The fan-out test installs a mockImplementation and resets it only on its last line, so one failed assertion cascades into later tests (vi.clearAllMocks keeps implementations).

Impact

Changes to URLs, token flow, default ports and empty-output messages in these tools would not be caught, and tool tests pass against behavior the real helpers do not have.

Suggested fix

  • Add a shared mock helper that spreads importOriginal() and overrides only execSSH; switch confirm-gates, handlers and integration to it one at a time.
  • Use vi.resetAllMocks() (or mockReset in afterEach).
  • Delete checkSSHAvailable and its mock.
  • Handler tests: ntfySend (URL, optional headers, empty-output message, exit 7); certList and npmCerts (login then Bearer GET, non-JSON login); composePull (discovery, HOMELAB_COMPOSE_FILES, TIMEOUTS.long); piStatus node: "all"; adguardQueryLog (URL-encoded search, default limit=25); serviceLogs and journalLogs (since conversion, empty output).
  • One per-node env test: HOMELAB_NODES={"nas":{"host":"nas.local","env":{"HOMELAB_ADGUARD_PORT":"3001"}}} uses port 3001 for node: "nas".

Acceptance criteria

  • Every tool has at least one handler test
  • Test files share one mock factory based on the real module

Related: #101

Getting started

  • Relevant files: mcp-server/src/tools/__tests__/handlers.test.ts, mcp-server/src/tools/__tests__/integration.test.ts, mcp-server/src/tools/__tests__/confirm-gates.test.ts, mcp-server/src/utils/ssh-api.ts
  • How to run tests: cd mcp-server && npm install && npm test (and npm run typecheck); structure tests: pip install -r requirements-test.txt && pytest tests/ -v
  • Conventions: see CLAUDE.md and CONTRIBUTING.md

Filed by repo-audit/full-audit at 636fefb. Severity: low. Effort: M. audit-key: testing|mcp-server/src/tools|handler-coverage

主要語言
TypeScript
星號
0
分支
4
平均合併
10 小時 16 分鐘
30 天內合併 PR
2

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

TMHSDigital/Home-Lab-Developer-Tools 的其他 Issue

查看 TMHSDigital/Home-Lab-Developer-Tools 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。