Initial import of streamline
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
import "./setup_env";
|
||||
import { test, expect, describe } from "bun:test";
|
||||
import { mergeReportRounds } from "../src/report_rounds";
|
||||
|
||||
/**
|
||||
* 批次切换器的选项是从**两份**归档拼出来的:原始报告按批次存在
|
||||
* fix_report_versions / impl_report_versions,大白话正文存在 readable_report_runs
|
||||
* (0018 之后才带批次号)。两边都可能缺其中一批:
|
||||
*
|
||||
* - 节点在归档窗口里离线 → 有正文、没 raw;
|
||||
* - 生成失败 / 存量批次 → 有 raw、没正文。
|
||||
*
|
||||
* 只取交集的话,这两种批次会在切换器里**凭空消失** —— 而「那一批到底发生了什么」
|
||||
* 恰恰是最需要翻回去看的两种。所以这里钉的是并集,以及「存量 run 不认领任何一批」。
|
||||
*/
|
||||
const note = (round: number, source: "human" | "critic" | "mr_review", text: string) =>
|
||||
({ at: 1_700_000_000_000 + round, source, round, text });
|
||||
|
||||
describe("mergeReportRounds", () => {
|
||||
test("两份归档取并集,从新到旧", () => {
|
||||
const rounds = mergeReportRounds({
|
||||
currentRound: 3,
|
||||
archives: [
|
||||
{ round: 1, createdAt: 100, chars: 1200 },
|
||||
{ round: 2, createdAt: 200, chars: 1500 },
|
||||
],
|
||||
// 第 3 批只有正文(raw 没抓到),第 1 批只有 raw
|
||||
runs: [
|
||||
{ round: 2, generatedAt: 250, promptName: "baseline" },
|
||||
{ round: 3, generatedAt: 350, promptName: "baseline" },
|
||||
],
|
||||
history: null,
|
||||
});
|
||||
expect(rounds.map((r) => r.round)).toEqual([3, 2, 1]);
|
||||
expect(rounds[0]).toMatchObject({ round: 3, hasMarkdown: false, hasReadable: true, isCurrent: true });
|
||||
expect(rounds[1]).toMatchObject({ round: 2, hasMarkdown: true, hasReadable: true, isCurrent: false });
|
||||
expect(rounds[2]).toMatchObject({ round: 1, hasMarkdown: true, hasReadable: false, markdownChars: 1200 });
|
||||
});
|
||||
|
||||
test("存量 run(批次未知)不认领任何一批", () => {
|
||||
const rounds = mergeReportRounds({
|
||||
currentRound: 2,
|
||||
archives: [{ round: 2, createdAt: 200, chars: 10 }],
|
||||
runs: [{ round: null, generatedAt: 999, promptName: "legacy" }],
|
||||
history: null,
|
||||
});
|
||||
expect(rounds).toHaveLength(1);
|
||||
expect(rounds[0]).toMatchObject({ round: 2, hasReadable: false });
|
||||
});
|
||||
|
||||
test("同一批生成过多次时记最新那次", () => {
|
||||
const rounds = mergeReportRounds({
|
||||
currentRound: 1,
|
||||
archives: [],
|
||||
runs: [
|
||||
{ round: 1, generatedAt: 100, promptName: "旧版" },
|
||||
{ round: 1, generatedAt: 500, promptName: "新版" },
|
||||
{ round: 1, generatedAt: 300, promptName: "中间那次" },
|
||||
],
|
||||
history: null,
|
||||
});
|
||||
expect(rounds).toHaveLength(1);
|
||||
expect(rounds[0].readableAt).toBe(500);
|
||||
expect(rounds[0].readablePromptName).toBe("新版");
|
||||
});
|
||||
|
||||
test("复核意见按它打回的那一批挂上去", () => {
|
||||
const rounds = mergeReportRounds({
|
||||
currentRound: 2,
|
||||
archives: [
|
||||
{ round: 1, createdAt: 100, chars: 10 },
|
||||
{ round: 2, createdAt: 200, chars: 10 },
|
||||
],
|
||||
runs: [],
|
||||
history: [note(1, "human", "胶囊没加全圆角"), note(1, "critic", "只改了一半"), note(2, "human", "还差一个")],
|
||||
});
|
||||
const r1 = rounds.find((r) => r.round === 1)!;
|
||||
const r2 = rounds.find((r) => r.round === 2)!;
|
||||
expect(r1.reviewNotes.map((n) => n.text)).toEqual(["胶囊没加全圆角", "只改了一半"]);
|
||||
expect(r2.reviewNotes.map((n) => n.text)).toEqual(["还差一个"]);
|
||||
});
|
||||
|
||||
test("reviewHistory 是原始 JSON 字符串时也能解析(列表载荷就是这个形状)", () => {
|
||||
const rounds = mergeReportRounds({
|
||||
currentRound: 1,
|
||||
archives: [{ round: 1, createdAt: 100, chars: 10 }],
|
||||
runs: [],
|
||||
history: JSON.stringify([note(1, "human", "再改一版")]),
|
||||
});
|
||||
expect(rounds[0].reviewNotes.map((n) => n.text)).toEqual(["再改一版"]);
|
||||
});
|
||||
|
||||
test("一批都没有时给空列表,而不是造一个第 0 批", () => {
|
||||
expect(mergeReportRounds({ currentRound: 0, archives: [], runs: [], history: null })).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user