weopqrst/mooncassette/matcher does not have a README file

    Candidate

    pub(all) struct Candidate {
    index : Int
    provider : String
    model : String
    differing_paths : Array[String]
    } derive(Eq)

    诊断中的一条候选记录。

    Diagnosis

    pub(all) struct Diagnosis {
    policy : MatchPolicy
    cursor : Int
    total : Int
    candidates : Array[Candidate]
    } derive(Eq)

    一次未命中的诊断结果。

    Diagnosis::hint

    fn Diagnosis::hint(self : Diagnosis) -> String

    一行结论,可直接拼进错误消息。

    Diagnosis::lines

    fn Diagnosis::lines(self : Diagnosis) -> Array[String]

    多行报告,便于打印或写进 CI 日志。

    MatchPolicy

    pub(all) enum MatchPolicy {
    Exact
    FingerprintOnly
    Subset(Array[String])
    Sequential
    } derive(Eq)

    回放时使用的匹配策略。

    MatchPolicy::name

    fn MatchPolicy::name(self : MatchPolicy) -> String

    策略名,用于日志与诊断输出。

    单独提供而不复用 Show:诊断报告需要的是稳定、可断言的短标识, Show 的输出格式属于展示细节,将来可能调整。

    MatchResult

    pub(all) struct MatchResult {
    index : Int
    interaction :
    Interaction

    } derive(Eq)

    一次成功匹配的结果。

    diagnose

    fn diagnose(request :
    Request
    , interactions : ArrayView[
    Interaction
    ], policy : MatchPolicy, cursor : Int, top? : Int) -> Diagnosis

    诊断一次未命中:找出与 request 最接近的记录,以及差在哪些字段。

    调用方应先对 request 做规范化(必要时再脱敏),否则差异里会混进 易变字段,噪声会盖住真正的原因。@recorder.Session::diagnose 已经代劳。

    代价是 O(记录数 × 字段数):它会把请求与每一条记录做一次结构比较。 这是排错路径,不在回放的正常路径上。

    find_match

    cursor 处开始查找匹配的记录。

    查找顺序为 cursor, cursor+1, ..., 末尾, 开头, ..., cursor-1(环形)。 这样既能正确处理「同一请求被录制多次、按调用次序依次回放」, 又能在实际调用次数多于录制次数时复用最早的一条,而不是直接失败。

    返回 None 表示当前 cassette 中没有候选。是否把它当作错误, 由调用方决定(回放模式报错,自动模式回落真实调用)。

    只有当指纹相同而规范请求不同(即真实哈希碰撞)时才抛错: 那是数据层面的异常,静默容忍会掩盖问题。

    is_exhausted

    fn is_exhausted(policy : MatchPolicy, cursor : Int, total : Int) -> Bool

    判断「没找到」是不是因为录制已耗尽

    只有 Sequential 会耗尽:它按位置消费,游标越界就意味着录制的条数不够用。 环形模式(Exact / FingerprintOnly / Subset)永远会回卷,因此它们返回 「没找到」一定是确实没有对应记录。

    区分这两种情况的意义在于修法不同:耗尽要补录制,没有对应记录要改请求 或换匹配策略。把前者报成「没有匹配记录」会把用户引向错误的方向。

    空 cassette 不算耗尽:那属于「一条都没录」,报「没有匹配记录」更贴切。