68 lines
3.4 KiB
TypeScript
68 lines
3.4 KiB
TypeScript
import { test, expect, describe } from "bun:test";
|
|
import { reportFreshness } from "@bbbug/shared/types";
|
|
|
|
/**
|
|
* 这个判定挡的是一类**不报错**的误读:报告的 live 列只前进不清空(一次失败的重生成
|
|
* 不该抹掉上一版好报告),所以新一批开工到新报告生成完之间,页面上挂着的是上一批
|
|
* 那份,绿标结论一应俱全。生产上出现过:一条 feature 16:51 开始重修,17:11 面板上
|
|
* 仍是 15:50 那份,没有一处提示。
|
|
*
|
|
* 判错的代价不对称,所以两个方向都要钉住:
|
|
* - 漏报(该说旧却说不旧)→ 有人拿上一批的结论下判断;
|
|
* - 误报(该说新却说旧)→ 每份报告顶上挂一条狼来了,横幅很快就没人看。
|
|
*/
|
|
describe("reportFreshness", () => {
|
|
test("正在执行这一批 —— 屏幕上的一切都是上一批的", () => {
|
|
for (const status of ["fixing", "implementing", "security_running"]) {
|
|
const f = reportFreshness({ status, attempts: 10, readableReportRound: 9 });
|
|
expect(f.stale).toBe(true);
|
|
expect(f.reason).toBe("running");
|
|
expect(f.reportRound).toBe(9);
|
|
expect(f.currentRound).toBe(10);
|
|
}
|
|
});
|
|
|
|
test("执行中即便报告号称是这一批的,也仍然算旧 —— 本批还没收尾", () => {
|
|
// 人在执行途中手动重生成过报告:批次号会等于当前批,但那份正文讲的仍然
|
|
// 不可能是这一批的结论(ImplReport.md 要等 agent 收尾才落盘)。
|
|
const f = reportFreshness({ status: "implementing", attempts: 10, readableReportRound: 10 });
|
|
expect(f.stale).toBe(true);
|
|
expect(f.reason).toBe("running");
|
|
});
|
|
|
|
test("被打回、重新排队 —— 结论已被推翻,新一批还没开始", () => {
|
|
for (const status of ["awaiting_fix", "awaiting_implementation", "awaiting_security", "pending_confirmation"]) {
|
|
const f = reportFreshness({ status, attempts: 3, readableReportRound: 3 });
|
|
expect(f.stale).toBe(true);
|
|
expect(f.reason).toBe("queued");
|
|
}
|
|
});
|
|
|
|
test("一批都没跑过的排队不是「上一批的报告」——那是首次排队", () => {
|
|
const f = reportFreshness({ status: "awaiting_implementation", attempts: 0, readableReportRound: null });
|
|
expect(f.stale).toBe(false);
|
|
});
|
|
|
|
test("这一批已收尾、新报告还没生成完 —— 只有正文旧", () => {
|
|
const f = reportFreshness({ status: "manual_review", attempts: 10, readableReportRound: 9 });
|
|
expect(f.stale).toBe(true);
|
|
expect(f.reason).toBe("pending");
|
|
});
|
|
|
|
test("终态且报告就是这一批的 —— 不提示", () => {
|
|
for (const status of ["manual_review", "completed", "fix_succeeded", "implementation_failed"]) {
|
|
expect(reportFreshness({ status, attempts: 10, readableReportRound: 10 }).stale).toBe(false);
|
|
}
|
|
});
|
|
|
|
test("存量报告(批次未知)在终态不误报,在执行中照样提示", () => {
|
|
// 猜一个批次号写进去就是制造假事实,所以终态这一档对存量行沉默……
|
|
expect(reportFreshness({ status: "manual_review", attempts: 7, readableReportRound: null }).stale).toBe(false);
|
|
// ……但「正在跑」跟批次号无关,存量行同样该提示。
|
|
const running = reportFreshness({ status: "implementing", attempts: 7, readableReportRound: null });
|
|
expect(running.stale).toBe(true);
|
|
expect(running.reportRound).toBeNull();
|
|
expect(running.currentRound).toBe(7);
|
|
});
|
|
});
|