Skip to content

Test: assert MCP handler error message text (contract test) #11

@kiki830621

Description

@kiki830621

Problem

ServerHandlerLogicTests.swift 目前的測試鎖定了「會拋 error」但沒有 assert specific error text:

XCTAssertThrowsError(try parseGetChatHistoryArgs([
    "chat_id": .int(100),
    "max_messages": .int(0),
]))

From verification of #7 by Codex:
「測試目前有鎖『會丟錯』,但沒有鎖使用者實際會看到的錯誤文字。如果錯誤訊息也算 MCP 契約的一部分,建議再補 1 到 2 個訊息比對。」

未來若有人把 errorResult("max_messages must be positive; got \(mm)") 改成模糊訊息(如 errorResult("invalid arg")),測試不會抓到——但 MCP caller 可能依賴訊息格式做錯誤處理。

Type

enhancement

Expected

補測試 assert (error as? HandlerArgError)?.description(error as? DateParseError)?.description 的 prefix / substring,確保 error message 是契約的一部分。

Code Reference

  • Tests/CheTelegramAllMCPTests/ServerHandlerLogicTests.swift:54-63(max_messages)
  • Tests/CheTelegramAllMCPTests/ServerHandlerLogicTests.swift:106-114(invalid date)

Related: #7


Current Status

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

Key Decisions

Scope Changes

(none — pure test contract tightening)

Blocking

(none)

Test counts

Commits

Follow-up

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