Skip to content

Test refactor: contract assertions use prefix-match instead of exact-equality #24

@kiki830621

Description

@kiki830621

Problem

From verification of #8/#11/#12 by devils-advocate (MEDIUM):
「七個 throws-based test 升級成 exact-string equality(#11):

XCTAssertEqual(
    (error as? HandlerArgError)?.description,
    "max_messages exceeds 10_000 cap; got 50000. Use since_date/until_date to narrow the range."
)

問題:

  1. 鎖死 cap 數值 10_000。如果未來 cap policy 改成 5_000所有相關 test 同時 failvalidateMaxMessagesCap 的「single source of truth」精神被測試打破了。
  2. 鎖死 error suggestion 文字。本意是 helpful UX,但每次 wording 微調都觸發 test failure。
  3. 鎖死 錯誤訊息結尾的句點

#11 issue body 原文要求是「assert error message TEXT」,並沒指定 exact equality。實作選擇 exact 是 over-shoot。」
— Source: team:devils-advocate

Type

enhancement (test refactor)

Expected

把 7 個 exact-equality assertion 改成 prefix-match:

// Before:
XCTAssertEqual(
    (error as? HandlerArgError)?.description,
    "max_messages exceeds 10_000 cap; got 50000. Use since_date/until_date to narrow the range."
)

// After:
XCTAssertTrue(
    (error as? HandlerArgError)?.description.hasPrefix("max_messages exceeds") == true,
    "expected cap-error prefix; got \(...)"
)

平衡 contract 鎖定(前綴是 caller 可能 substring-match 的 stable surface)和 implementation 彈性(cap 數值 / suggestion 文字可調)。

Acceptance

  • 7 個 contract assertion 從 XCTAssertEqual 改成 hasPrefix / contains
  • 鎖前綴關鍵詞而非完整訊息
  • cap 數值 / suggestion 文字未來變更不再 break test

Code Reference

  • Tests/CheTelegramAllMCPTests/ServerHandlerLogicTests.swift 7 個 throws-based test 的 trailing closures (search "XCTAssertEqual.*description")

Related: #8, #11

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