Files
2026-11-16 17:26:44 -08:00

61 lines
3.5 KiB
TypeScript

import { test, expect, describe } from "bun:test";
import {
QA_REOPEN_JUDGE_PROMPT_TEMPLATE, parseQaReopenJudgment, qaReopenSignature, renderQaReopenJudgePrompt,
} from "@bbbug/shared/qa_reopen_prompt";
describe("QA 重开:要不要再跑一轮", () => {
test("只有 decision=rework 且 kind 是三种值得重修之一才算要跑", () => {
expect(parseQaReopenJudgment(`{"decision":"rework","kind":"fix_wrong","summary":"点两次还会进两个页面"}`))
.toEqual({ decision: "rework", kind: "fix_wrong", summary: "点两次还会进两个页面" });
expect(parseQaReopenJudgment(`好的\n\`\`\`json\n{"decision":"rework","kind":"new_repro","summary":"x"}\n\`\`\``)?.decision).toBe("rework");
// decision 和 kind 对不上:以不跑为准
expect(parseQaReopenJudgment(`{"decision":"rework","kind":"needs_info","summary":"x"}`))
.toEqual({ decision: "wait", kind: "needs_info", summary: "x" });
expect(parseQaReopenJudgment(`{"decision":"rework","kind":"whatever"}`)?.decision).toBe("wait");
expect(parseQaReopenJudgment(`{"decision":"maybe","kind":"fix_wrong"}`)).toEqual({ decision: "wait", kind: "no_signal", summary: "" });
});
test("读不出 JSON 返回 null(调用方稍后再判、期间不跑)", () => {
expect(parseQaReopenJudgment("我觉得应该重修")).toBeNull();
expect(parseQaReopenJudgment("{not json}")).toBeNull();
expect(parseQaReopenJudgment("")).toBeNull();
});
test("summary 截断,防止模型写长文", () => {
const j = parseQaReopenJudgment(JSON.stringify({ decision: "wait", kind: "question", summary: "长".repeat(500) }));
expect(j!.summary.length).toBe(160);
});
test("提示词填满所有占位,留言原文、复现背景都在里面", () => {
const p = renderQaReopenJudgePrompt({
from: "fix", title: "发布时去掉首尾空格", description: "Thought Features Bugbash 第 40 行", reproSteps: "",
priorNotes: [],
comments: [{ who: "tongjiao", at: Date.UTC(2026, 10, 7, 0, 16), text: "验证停在信息校验,不是验证通过。\n@Larry Guo 请补全操作步骤", images: 0 }],
});
expect(p).not.toMatch(/\{\{\w+\}\}/);
expect(p).toContain("验证停在信息校验");
expect(p).toContain("tongjiao");
expect(p).toContain("已经修完并交给 QA 验收");
expect(p).toContain("复现步骤:\n(无)");
expect(p).toContain("以前的复核意见(最近几条,可能为空)\n(无)");
const u = renderQaReopenJudgePrompt({ from: "unrepro", title: "t", description: "", reproSteps: "", priorNotes: ["a", "b", "c", "d"], comments: [{ who: null, at: 0, text: "x", images: 2 }] });
expect(u).toContain("没有复现出来");
expect(u).toContain("未知(附 2 张图)");
expect(u).not.toContain("【第 4 条】"); // 只带最近三条
expect(u).toContain("【第 1 条】\nb");
});
test("模板要求拿不准时不跑", () => {
expect(QA_REOPEN_JUDGE_PROMPT_TEMPLATE).toContain("拿不准时选 wait");
});
test("签名:留言不变就不变,补一条、改一条都会变", () => {
const c = [{ author: "u1", at: 1, text: "abc", imageUuids: [] as string[] }];
const s1 = qaReopenSignature(100, c);
expect(qaReopenSignature(100, [...c])).toBe(s1);
expect(qaReopenSignature(100, [...c, { author: "u2", at: 2, text: "补充", imageUuids: [] }])).not.toBe(s1);
expect(qaReopenSignature(100, [{ ...c[0], text: "abcd" }])).not.toBe(s1);
expect(qaReopenSignature(200, c)).not.toBe(s1); // 下一次交 QA 之后的重开是另一回事
});
});