写→审链新增第五审「人物塑造」(灵感③/D2):advisory 单维——仅建议、不阻断
验收(不进 conflicts、不碰 assert_conflicts_resolved、不入 REVIEW_RESERVED_NAMES);
只做人物塑造、不做氛围。
- SPEC characterization_spec(analyst,reads=("characters",),writes=())+
prompts/characterization.md(只读、显式忽略文本长度与辞藻华丽度、引用逐字片段+置信度)
- schema CharacterizationReview{issues[...]}(全字段默认值守解析韧性)+ 注册 catalog
- 计数三处 22→23 + regen prompt_hashes.json(仅加一条)
- DB chapter_reviews 加 characterization JSONB nullable 列(迁移 f6a7b8c9d0e1)
- 接线:graph REVIEW_SPECS 追加 · chain ReviewRecordRepo · collect(extract/record) ·
review_repo(Protocol/Sql/_to_view/ReviewView) · sse(event/factory/section) · normalize 自动纳入
- 契约 ReviewHistoryItem 加 characterization(gen:api 已重生成)
- 前端 sse/history/useReviewStream + CharacterizationPanel(只展示无裁决 UI、置信度降序+低置信折叠)+ ReviewReport 挂面板
- 测试 test_characterization_does_not_block_accept + 计数/golden + collect/normalize + 前端 reducer/normalize/parse
守不变量 #2/#3/#9;依赖 ⑧(motive/appearance 作客观锚点)。
190 lines
5.0 KiB
TypeScript
190 lines
5.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import type { ReviewConflictView, ReviewHistoryItem } from "@/lib/api/types";
|
|
import {
|
|
latestReview,
|
|
normalizeCharacterization,
|
|
normalizeConflicts,
|
|
normalizeForeshadowSug,
|
|
normalizePace,
|
|
} from "./history";
|
|
|
|
const item = (
|
|
conflicts: ReviewConflictView[],
|
|
): ReviewHistoryItem => ({
|
|
id: "00000000-0000-0000-0000-000000000001",
|
|
project_id: "00000000-0000-0000-0000-000000000002",
|
|
chapter_no: 128,
|
|
conflicts,
|
|
});
|
|
|
|
describe("normalizeConflicts", () => {
|
|
it("tightens loose dicts into ReviewConflict, preserving order", () => {
|
|
const out = normalizeConflicts(
|
|
item([
|
|
{
|
|
type: "设定违例",
|
|
where: "第4段",
|
|
refs: ["第30章"],
|
|
suggestion: "统一血脉",
|
|
},
|
|
{ type: "时间线倒错", where: "第8段", refs: [], suggestion: "调整" },
|
|
]),
|
|
);
|
|
expect(out).toEqual([
|
|
{
|
|
type: "设定违例",
|
|
where: "第4段",
|
|
refs: ["第30章"],
|
|
suggestion: "统一血脉",
|
|
original: null,
|
|
replacement: null,
|
|
},
|
|
{
|
|
type: "时间线倒错",
|
|
where: "第8段",
|
|
refs: [],
|
|
suggestion: "调整",
|
|
original: null,
|
|
replacement: null,
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("falls back type to 未分类 and tolerates missing refs", () => {
|
|
const out = normalizeConflicts(
|
|
item([{ type: "", where: "", suggestion: "" }]),
|
|
);
|
|
expect(out).toEqual([
|
|
{
|
|
type: "未分类",
|
|
where: "",
|
|
refs: [],
|
|
suggestion: "",
|
|
original: null,
|
|
replacement: null,
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("returns [] for undefined item or missing conflicts", () => {
|
|
expect(normalizeConflicts(undefined)).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe("normalizeForeshadowSug", () => {
|
|
it("tightens flat list with kind, defaulting kind to planted", () => {
|
|
const out = normalizeForeshadowSug({
|
|
...item([]),
|
|
foreshadow_sug: [
|
|
{ kind: "resolved", code: "F-012", title: "神秘玉佩", where: "第4段" },
|
|
{ title: "残破地图" },
|
|
],
|
|
});
|
|
expect(out).toEqual([
|
|
{
|
|
kind: "resolved",
|
|
code: "F-012",
|
|
title: "神秘玉佩",
|
|
where: "第4段",
|
|
note: null,
|
|
},
|
|
{ kind: "planted", code: null, title: "残破地图", where: null, note: null },
|
|
]);
|
|
});
|
|
|
|
it("returns [] when missing", () => {
|
|
expect(normalizeForeshadowSug(item([]))).toEqual([]);
|
|
expect(normalizeForeshadowSug(undefined)).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe("normalizePace", () => {
|
|
it("tightens dict into PaceReport, filtering bad water/beats", () => {
|
|
const out = normalizePace({
|
|
...item([]),
|
|
pace: {
|
|
water: [{ where: "第3段", reason: "注水" }, "junk"],
|
|
hook: true,
|
|
beat_map: [1, 3, "x", 5],
|
|
},
|
|
});
|
|
expect(out).toEqual({
|
|
water: [{ where: "第3段", reason: "注水" }],
|
|
hook: true,
|
|
beat_map: [1, 3, 5],
|
|
});
|
|
});
|
|
|
|
it("returns null when pace is missing or not a dict", () => {
|
|
expect(normalizePace(item([]))).toBeNull();
|
|
expect(normalizePace(undefined)).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("normalizeCharacterization", () => {
|
|
it("tightens dict into CharacterizationReport with field defaults", () => {
|
|
const out = normalizeCharacterization({
|
|
...item([]),
|
|
characterization: {
|
|
issues: [
|
|
{
|
|
character: "沈砚",
|
|
aspect: "动机一致性",
|
|
where: "第3段",
|
|
quote: "他忽然转身。",
|
|
diagnosis: "动机断裂",
|
|
suggestion: "扣回护妹动机",
|
|
confidence: 0.82,
|
|
},
|
|
// 缺字段的畸形条目:安全默认,不丢整条
|
|
{ character: "阿黎" },
|
|
],
|
|
},
|
|
});
|
|
expect(out).toEqual({
|
|
issues: [
|
|
{
|
|
character: "沈砚",
|
|
aspect: "动机一致性",
|
|
where: "第3段",
|
|
quote: "他忽然转身。",
|
|
diagnosis: "动机断裂",
|
|
suggestion: "扣回护妹动机",
|
|
confidence: 0.82,
|
|
},
|
|
{
|
|
character: "阿黎",
|
|
aspect: "",
|
|
where: "",
|
|
quote: "",
|
|
diagnosis: "",
|
|
suggestion: "",
|
|
confidence: 0,
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
it("returns empty issues when characterization is present but issues missing", () => {
|
|
expect(
|
|
normalizeCharacterization({ ...item([]), characterization: {} }),
|
|
).toEqual({ issues: [] });
|
|
});
|
|
|
|
it("returns null when characterization is missing or not a dict", () => {
|
|
expect(normalizeCharacterization(item([]))).toBeNull();
|
|
expect(normalizeCharacterization(undefined)).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("latestReview", () => {
|
|
it("returns first item (history is newest-first)", () => {
|
|
const a = item([]);
|
|
const b = item([]);
|
|
expect(latestReview([a, b])).toBe(a);
|
|
expect(latestReview([])).toBeUndefined();
|
|
expect(latestReview(undefined)).toBeUndefined();
|
|
});
|
|
});
|