const test = require("node:test"); const assert = require("node:assert/strict"); const { buildGroupMessageFrame, pickReplyReqId } = require("../group_message_frame.cjs"); test("group reply never uses stream", () => { const withCb = buildGroupMessageFrame({ chatId: "wr_1", content: "工单号:WO202609210001", callbackReqId: "cb_1", }); assert.notEqual(withCb.body.msgtype, "stream"); assert.equal(withCb.body.msgtype, "markdown"); assert.equal(withCb.cmd, "aibot_respond_msg"); assert.equal(withCb.body.chatid, "wr_1"); assert.equal(withCb.body.markdown.feedback, undefined); const proactive = buildGroupMessageFrame({ chatId: "wr_1", content: "附件已保存", callbackReqId: "", }); assert.equal(proactive.cmd, "aibot_send_msg"); assert.equal(proactive.body.msgtype, "markdown"); assert.equal(proactive.body.markdown.feedback, undefined); }); test("dimension asterisks stay visible in group markdown", () => { const frame = buildGroupMessageFrame({ chatId: "wr_1", content: "体积(CBM)(必填):1.1*2.1*2.1", callbackReqId: "", }); assert.equal(frame.body.markdown.content, "体积(CBM)(必填):`1.1*2.1*2.1`"); const again = buildGroupMessageFrame({ chatId: "wr_1", content: frame.body.markdown.content, callbackReqId: "", }); assert.equal(again.body.markdown.content, "体积(CBM)(必填):`1.1*2.1*2.1`"); }); test("reply req id only uses the same chat, never the last inbound from another chat", () => { assert.equal(pickReplyReqId({ fromCaller: "cb_1", fromChat: "old" }), "cb_1"); assert.equal(pickReplyReqId({ fromCaller: "", fromChat: "chat_cb" }), "chat_cb"); // 2026-11-21 测服事故:没有本群 req_id 时必须主动发言,不能借用别的群 req_id。 assert.equal(pickReplyReqId({ fromCaller: "", fromChat: "" }), ""); }); test("proactive message to a chat without its own callback uses aibot_send_msg", () => { const frame = buildGroupMessageFrame({ chatId: "wr_land_group", content: "产品响应超时", callbackReqId: pickReplyReqId({ fromCaller: "", fromChat: "" }), }); assert.equal(frame.cmd, "aibot_send_msg"); assert.equal(frame.body.chatid, "wr_land_group"); });