Skip to content

Real Server.handleToolCall integration test (HandlerGlueTests is structural mimicry only) #27

@kiki830621

Description

@kiki830621

Problem

From verification of #9/#10/#14 by devils-advocate (HIGH) + Codex:
HandlerGlueTests.testGetChatHistoryGlueChatIdMissing 的程式形狀:

do {
    _ = try parseGetChatHistoryArgs([:])
} catch {
    result = errorResultFromParse(error)   // ← 測試自己呼叫
}

問題:這段程式不在 Server.swift 裡執行。它只是模仿 Server.swift 的程式形狀。

如果有人把 Server.swift 從 return errorResultFromParse(error) 改成 hardcode return errorResult("changed!")

  • HandlerGlueTests 全部 6 個測試仍然 PASS — 因為它們測 errorResultFromParse(_:) 本身
  • production code 已經回傳 "changed!" 給 MCP client,但整個 test suite 不會炸
    — Source: team:devils-advocate (HIGH) + Codex independent confirmation

#14 + #18 因此標 PARTIALLY closed。需要真正打到 Server.handleToolCall entry point 的 integration test。

Type

enhancement (test infrastructure)

Expected

Server.handleToolCallprivateinternal(或抽出 testable wrapper),寫 1-2 個 integration test:

func testHandleToolCallGetChatHistoryWithMissingChatIdReturnsError() async {
    let server = makeTestServer()  // needs TDLib stub state
    let result = await server.handleToolCall(name: "get_chat_history", arguments: [:])
    XCTAssertTrue(result.isError ?? false)
    if case let .text(text, _, _) = result.content[0] {
        XCTAssertTrue(text.hasPrefix("Error: chat_id is required"))
    }
}

挑戰:

  • Server 需要 TDLibClient 實例 — 需 stub init flow(TDLibClient.makeStubForTesting()?)
  • 或:抽 private func handleToolCall 為獨立 dispatch function 接受 closure dependency

兩個方案都涉及 architectural change。第二方案更乾淨(純函式 dispatch)但動到更多 code。

Acceptance

  • Server.handleToolCall 變 testable(升 visibility 或抽 dispatch function)
  • 2-4 個 integration test 真的呼叫 handleToolCall(...) 並斷言 CallTool.Result.isError == true + text payload
  • 至少覆蓋 get_chat_history 與 dump_chat_to_markdown 兩個 catch chain handler
  • Mutation test guarantee: 把 Server.swift catch arm 改成 hardcode errorResult("changed!") 應立即造成 1+ integration test fail

Code Reference

  • Sources/CheTelegramAllMCPCore/Server.swift:280 (handleToolCall — currently private)
  • Sources/CheTelegramAllMCPCore/Server.swift:391-405 (get_chat_history catch arm)
  • Sources/CheTelegramAllMCPCore/Server.swift:509-517 (dump_chat_to_markdown catch arm)
  • Tests/CheTelegramAllMCPTests/HandlerGlueTests.swift (current test approach — needs supplement)

Related: #14, #18, #7

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions