Prhub

#47883 [Rust Frontend] Add roundtrip fixtures for more chat parsers

原始 PR 作者 reidliu41 合并时间 2026-07-10 18:03 文件变更 1 提交数 3 评论 5 代码增减 +42 / -0

执行摘要

为 MiniMax-M3、GLM-4.5、Nemotron V3 新增 roundtrip 测试

PR body 明确指出目的:为已有 parser 路由补充 roundtrip 测试覆盖。原始 PR 包含 GLM-4.6,但 reviewer BugenZhao 认为其格式与 GLM-4.5 基本相同,无必要单独测试,作者同意后移除。

值得合并。这是一个低风险、高质量的测试补充 PR。新增的 fixture 覆盖了 3 种不同的推理标签格式(<mm:think><think><|im_end|>),丰富了测试矩阵。移除冗余用例的操作体现了良好的工程判断。建议团队在后续新增 parser 路由时,将 roundtrip fixture 作为合入前置条件之一。

讨论亮点

仅有一条有效讨论:BugenZhao 评论认为 GLM-4.6 格式与 GLM-4.5 基本相同,“没必要单独测试”(原文:"the format for GLM-4.6 is mostly the same as GLM-4.5 so it may not be necessary")。作者 reidliu41 回复 "Makes sense, thanks" 并随后在合并 PR 时通过 commit 移除了该用例。这体现了 reviewer 对测试冗余度的审慎把控。

实现拆解

  1. 新增 fixture 定义:在 RoundtripCase impl 块中新增 3 个构造方法:
    • minimax_m3():使用 MiniMaxAI/MiniMax-M3<mm:think> 推理标签,ThinkingBehavior::Always
    • glm45():使用 zai-org/GLM-4.5,空 assistant_stop_suffixThinkingBehavior::Toggleable 默认开启。
    • nemotron_v3():使用 nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16<|im_end|>\n stop suffix,ThinkingBehavior::Always
  2. 注册到宏调用:在 roundtrip_tests! 宏中注册新增的 fixture:
    • minimax_m3 同时参与 reasoning_and_contenttool_call_mix 测试。
    • glm45 同时参与 reasoning_and_contenttool_call_mix 测试。
    • nemotron_v3 仅参与 reasoning_and_content 测试。
  3. 移除冗余用例:在合并过程中移除了原作者最初包含的 glm46 fixture(commit 5d6f619),因为其格式与 glm45 高度重复。
文件 模块 状态 重要度
rust/src/chat/tests/roundtrip.rs 测试套件 modified 5.64

关键符号

minimax_m3 glm45 nemotron_v3

关键源码片段

rust/src/chat/tests/roundtrip.rs test-coverage

唯一变更文件,新增 3 组测试 fixture 并注册到宏中,同时移除了冗余的 GLM-4.6 用例。

// 文件:rust/src/chat/tests/roundtrip.rs
// 新增的三个 fixture 定义,遵循已有模式:使用 ParserSelection::Auto
// 让测试框架自动选择合适的 parser,分别验证不同模型变体的推理标签和工具调用格式/// MiniMax M3 invoke format with `<mm:think>` reasoning tags.
fn minimax_m3() -> Self {
    Self {
        model_id: "MiniMaxAI/MiniMax-M3",
        assistant_stop_suffix: "[e~[\n",
        tool_call_parser: ParserSelection::Auto,
        reasoning_parser: ParserSelection::Auto,
        // MiniMax 系列总是启用思考行为
        thinking_behavior: ThinkingBehavior::Always { value: true },
        json_fmt: compact_json_fmt(),
        sort_json_keys: false,
    }
}/// GLM-4.5 XML-like argument format with `<think>` reasoning tags.
fn glm45() -> Self {
    Self {
        model_id: "zai-org/GLM-4.5",
        assistant_stop_suffix: "", // GLM 系列没有专门的 assistant stop token
        tool_call_parser: ParserSelection::Auto,
        reasoning_parser: ParserSelection::Auto,
        // 可切换的思考行为,默认开启
        thinking_behavior: ThinkingBehavior::Toggleable { default: true },
        json_fmt: compact_json_fmt(),
        sort_json_keys: false,
    }
}/// Nemotron V3 with `<think>` / `</think>` reasoning tags.
fn nemotron_v3() -> Self {
    Self {
        model_id: "nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16",
        assistant_stop_suffix: "<|im_end|>\n",
        tool_call_parser: ParserSelection::Auto,
        reasoning_parser: ParserSelection::Auto,
        // Nemotron 总是启用思考行为
        thinking_behavior: ThinkingBehavior::Always { value: true },
        json_fmt: compact_json_fmt(),
        sort_json_keys: false,
    }
}

// 在 roundtrip_tests! 宏调用中注册新增的 fixture
// minimax_m3 和 glm45 参与两种测试场景,nemotron_v3 仅参与 reasoning + content
roundtrip_tests! {
    // ... 已有条目 ...
    minimax_m3 => [reasoning_and_content, tool_call_mix],
    glm45 => [reasoning_and_content, tool_call_mix],
    nemotron_v3 => [reasoning_and_content],
    // ... 其他条目 ...
}

评论区精华

GLM-4.6 用例的冗余性 设计

BugenZhao 认为 GLM-4.6 与 GLM-4.5 格式基本相同,没必要单独添加 roundtrip 测试。

结论:作者同意并移除了 GLM-4.6 fixture(commit 5d6f619)。 · 已解决

风险与影响

无显著风险。该 PR 仅新增测试 fixture,不涉及生产代码变更。新增的 fixture 均使用已有 parser 配置(tool_call_parser: Autoreasoning_parser: Auto),依赖已在生产环境中验证的 parser 逻辑。唯一的潜在风险是如果 fixture 中指定的 model_id 在测试环境中不可用(如模型未下载),但 roundtrip 测试通常只验证解析逻辑而非实际模型推理,因此风险很低。

影响范围:仅影响 Rust 前端的 roundtrip 测试套件,新增 3 组测试用例(共 5 个测试点)。对生产系统无任何影响,因为不修改任何业务代码、配置或 API。影响程度:小。提升了对 MiniMax-M3、GLM-4.5、Nemotron V3 这些模型 parser 的回归防护能力,有助于在后续 parser 重构或新增路由时及早发现回退。

关联 Issue

未识别关联 Issue

当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。

完整报告

参与讨论