Skip to content

MCP 層補 handler 行為 unit test(get_chat_history) #7

@kiki830621

Description

@kiki830621

Problem

From verification of #3, #4:
「MCP 層的測試只驗 schema,沒有驗 handler 行為。ServerDumpChatToolTests.swift:71 只確認 get_chat_history 有六個欄位,沒有驗證 from_message_id == 0 時是否真的自動把 max_messages = limit,也沒有驗證 since_date / until_date / max_messages 是否真的傳進 TDLibClient
— Sources: codex + team:regression

目前 get_chat_history 的 MCP 層只有 schema shape test,沒有 handler 行為 test。#3 的核心 fix(fromMsgId==0 時自動帶 maxMessages=limit)完全沒有 unit test 保護,只靠間接的 E2E test。

Type

enhancement

Expected

加入 unit tests 驗證 MCP handler 行為(至少不依賴真實 TDLib 連線):

  • fromMsgId == 0 且無 max_messagesTDLibClient.getChatHistory 被呼叫時帶 maxMessages == limit
  • fromMsgId > 0 且無 max_messagesmaxMessages == nil(backward-compat path)
  • 傳入 since_date / until_date → 正確解析為 Date 並傳入
  • 傳入 max_messages → 覆蓋上面的隱式默認

Actual

只有 testGetChatHistoryProperties 驗證 schema 有 6 個 properties。

Impact

Technical Approach

可能需要 mock 或 fake TDLibClient 來驗證 handler 傳給 library 層的參數。參考 TDLibClientBackwardCompatTests 的 pattern(pure compilation + signature tests)。

Code Reference

  • Handler: Sources/CheTelegramAllMCPCore/Server.swift:345-363
  • Existing schema test: Tests/CheTelegramAllMCPTests/ServerDumpChatToolTests.swift:71-82

Related: #3, #4

Current Status

Phase: closed
Last updated: 2026-04-26 by idd-close

Key Decisions

Scope Changes

(none)

Follow-up

Commits

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions