import { describe, expect, test } from "bun:test"; import { approvedBugRejectable, bugReworkable, featureReworkable } from "@bbbug/shared/types"; // 「打回修改」:复核通过但修复还没落地的 bug 才能打回(面板按钮和 /review/reject 共用这一道)。 const t = (over: Partial<{ status: string; mrState: string | null; meegoState: string | null; mergedIntoBaseAt: number | null }>) => ({ status: "fix_succeeded", mrState: "opened", meegoState: "RESOLVED", mergedIntoBaseAt: null, ...over }); describe("approvedBugRejectable", () => { test("待 QA 确认、MR 待合入、mr_sync 还没回填:能打回", () => { expect(approvedBugRejectable(t({ meegoState: "RESOLVED" }))).toBe(true); expect(approvedBugRejectable(t({ meegoState: "CLOSED", mrState: "opened" }))).toBe(true); expect(approvedBugRejectable(t({ meegoState: "CLOSED", mrState: null }))).toBe(true); expect(approvedBugRejectable(t({ meegoState: null, mrState: null }))).toBe(true); }); test("已合入 / 关单且 MR 已关 / 历史上平台自己合回基线:没有可改的东西", () => { expect(approvedBugRejectable(t({ mrState: "merged" }))).toBe(false); expect(approvedBugRejectable(t({ meegoState: "CLOSED", mrState: "closed" }))).toBe(false); expect(approvedBugRejectable(t({ mergedIntoBaseAt: 1_790_000_000_000 }))).toBe(false); }); test("QA 打回走自己的重开流程;其它状态不归这里管", () => { expect(approvedBugRejectable(t({ meegoState: "REOPENED" }))).toBe(false); expect(approvedBugRejectable(t({ status: "manual_review" }))).toBe(false); expect(approvedBugRejectable(t({ status: "archived" }))).toBe(false); }); }); // 右下角「修改意见」:这一轮停下来、修复还没落地的单都能带意见打回(面板入口和 /review/reject 共用)。 describe("bugReworkable", () => { test("待复核 / 复现不了 / 修复失败 / 待 QA / 待合入 / QA 打回:能打回", () => { for (const status of ["manual_review", "unreproducible", "fix_failed"]) expect(bugReworkable(t({ status }))).toBe(true); expect(bugReworkable(t({ meegoState: "RESOLVED" }))).toBe(true); expect(bugReworkable(t({ meegoState: "CLOSED", mrState: "opened" }))).toBe(true); expect(bugReworkable(t({ meegoState: null, mrState: null }))).toBe(true); // 8ec5eb5e:QA 重开、留言没说清,平台先不重修 —— RD 得能自己写意见接着改 expect(bugReworkable(t({ meegoState: "REOPENED" }))).toBe(true); }); test("已合入(含合入后又被 QA 打回)/ 关单且 MR 已关 / 平台合回基线:不能", () => { expect(bugReworkable(t({ mrState: "merged" }))).toBe(false); expect(bugReworkable(t({ mrState: "merged", meegoState: "REOPENED" }))).toBe(false); expect(bugReworkable(t({ meegoState: "CLOSED", mrState: "closed" }))).toBe(false); expect(bugReworkable(t({ mergedIntoBaseAt: 1_790_000_000_000 }))).toBe(false); }); test("正在排队 / 评估 / 修,或已经结束:不能", () => { for (const status of ["initializing", "info_required", "pending_confirmation", "awaiting_fix", "fixing", "archived", "cancelled", "evaluate_finish"]) { expect(bugReworkable(t({ status }))).toBe(false); } }); }); describe("featureReworkable", () => { test("待复核 / 实现失败 / 已完成能打回,其余不能", () => { for (const status of ["manual_review", "implementation_failed", "completed"]) expect(featureReworkable({ status })).toBe(true); for (const status of ["initializing", "pending_confirmation", "awaiting_implementation", "implementing", "archived", "cancelled"]) { expect(featureReworkable({ status })).toBe(false); } }); });