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

35 lines
2.3 KiB
TypeScript

import { test, expect } from "bun:test";
import { parseArchiveFeedback } from "../src/archive_feedback_db";
import { ARCHIVE_NOTE_MAX, archiveReasonLabel, archivedReopenTarget } from "@bbbug/shared/archive_reasons";
test("unknown codes are dropped; notes are trimmed and capped; empty parses to nulls (route rejects it)", () => {
expect(parseArchiveFeedback(undefined)).toEqual({ reason: null, note: null });
expect(parseArchiveFeedback({})).toEqual({ reason: null, note: null });
expect(parseArchiveFeedback({ reason: "ai_fix_wrong", note: " 改动方向不对 " })).toEqual({ reason: "ai_fix_wrong", note: "改动方向不对" });
expect(parseArchiveFeedback({ reason: "server_bug" })).toEqual({ reason: "server_bug", note: null });
// 已下架的 code 不再接受(历史记录里还在,见 archive_reasons.ts)。
expect(parseArchiveFeedback({ reason: "duplicate" })).toEqual({ reason: null, note: null });
expect(parseArchiveFeedback({ reason: "drop table", note: " " })).toEqual({ reason: null, note: null });
expect(parseArchiveFeedback({ note: "x".repeat(ARCHIVE_NOTE_MAX + 50) }).note!.length).toBe(ARCHIVE_NOTE_MAX);
});
test("labels cover live and retired codes; unknown codes pass through", () => {
expect(archiveReasonLabel("server_bug", "zh")).toBe("服务端 bug");
expect(archiveReasonLabel("duplicate", "zh")).toBe("重复单");
expect(archiveReasonLabel("whatever", "en")).toBe("whatever");
expect(archiveReasonLabel(null, "zh")).toBeNull();
});
test("reopening an archived item goes back to the stage it was archived from", () => {
// 跑完过一轮的回人工复核;老单查不到归档前状态,同样回人工复核(原来的行为)。
for (const st of ["manual_review", "fix_failed", "fix_succeeded", "unreproducible", "implementation_failed", null, undefined]) {
expect(archivedReopenTarget(st)).toBe("manual_review");
}
// 还没跑完一轮的回确认计划,执行中被归档的也是(那一轮已经停掉)。
for (const st of ["pending_confirmation", "awaiting_fix", "awaiting_implementation", "fixing", "implementing"]) {
expect(archivedReopenTarget(st)).toBe("pending_confirmation");
}
expect(archivedReopenTarget("initializing")).toBe("initializing");
expect(archivedReopenTarget("info_required")).toBe("info_required");
});