Merge branch 'codex/ise-08' into codex/inplace-slice-editing

This commit is contained in:
d-robotics 2026-10-13 15:55:49 +05:30
commit d904ae1e10
12 changed files with 965 additions and 17 deletions

View File

@ -1,6 +1,6 @@
# 08 · QC:同款返修接收视图
Status: ready-for-agent
Status: resolved
Type: task
Blocked by: 01, 04, 07
Spec: [spec.md](../spec.md) §3.6、§2 R2-Q3:a+b / R2-Q5:a / R2-Q8:a、§7
@ -25,3 +25,20 @@ Spec: [spec.md](../spec.md) §3.6、§2 R2-Q3:a+b / R2-Q5:a / R2-Q8:a、§7
## Comments
- Blocked by 07 是演示链完整性要求(QC 看的对照数据来自标注员重新送检记录),代码硬依赖只有 01 + 04。
## Answer
在 `codex/ise-08`(基线 84ea2da7)完成,提交 `97081da1`(认领 `ab7589ff`)。
交付与验收勾稽:
1. **意见栏 + 字幕** ✅:页面审查面板组合 `ReworkOpinionRail`(不传 `onSkipToggle`,QC 无跳过按钮);
`ReworkProblemSubtitles` 经 workbench 新 prop `reviewReworkEmphasis` 在审查视角渲染三排字幕(左右相机各一份,`isReviewViewing` 门控,与标注员侧 `reworkActive` 互斥)。
2. **J/K 逐条跳意见** ✅:`review-shortcuts.js` 注册 `next-rework-opinion`/`previous-rework-opinion`(新 `reworkOpinions` 上下文,仅返修接收视图挂载时占用,输入框/修饰键/长按语义与其他审查键一致);workbench 分发给页面 `onReviewReworkNavigate`,定位经 `ReviewViewingController` 的 `seekAction/seekTime/seekSlice`(`nextReworkJump` 复用),不搬 workbench 内部导航。
3. **判定列** ✅:`ReworkComparisonPanel` 新增可选 `emphasis`,按落点逐行渲染 `reworkTargetVerdictChips`(未处理/已处理/不改留痕/历史轮 计数芯片;拆分段聚合各段芯片)。
4. **红灰对照双栏** ✅:新组件 `ReworkContrastView`,行数据纯函数 `reworkContrastRows`(左=本轮退回基线按时间重叠对齐、右=提交版本落点;整体意见文本通栏;state/reattached 透传不重算)。
5. **结构摘要横幅** ✅:`ReworkReceiveBanner` 读 `useReworkReviewEmphasis` 从 getTask 最后一条切片修订带出的 `structureChangeSummary`(票 07 契约;首标无摘要不渲染)。
6. **D7 留位** ✅:`ReviewProblemPanel` 及其 props 零改动,仍在意见栏下方原位。
7. **QC 输入 = 已保存工作区** ✅:新 hook `useReworkReviewEmphasis` 以 getTask 最后修订为输入(非页面实时草稿),与 `useReworkEmphasis`(标注员实时)语义分开。
验证:`npx tsc --noEmit` exit 0;`node --test tests/frontend/*.test.mjs` 基线 713/699/14 → 改后 723/709/14,14 个失败名集合逐字节一致(既有债,均在 ProjectDetail/workflow/shell/raw-human-profile);新增 seam ③ 用例 1 条(J/K 注册与零冲突)+ 判定/对照行推导用例 9 条,全绿(TDD 先红后绿)。QC 视图家族对 `CaptureAnnotationWorkbench` 的 import 为零(票 01 验收延续)。未动 `.go` 文件(无 Go 测试需要)。UI 交互按项目决策不自动化,按 spec §4-⑨⑩ 人工验收。

View File

@ -157,6 +157,12 @@ type Props = ReviewViewingProps & {
reworkNotice?: ReworkNotice;
/** 返工强调层:按"退回基线 vs 当前工作区"算出的红/灰/跳过投影;null=非返工或旧格式退回(走遗留文本匹配)。 */
reworkEmphasis?: ReworkEmphasisView | null;
/**
* QC 返修接收视图的强调层(票 08):输入是已保存工作区(ADR 0006:31),
* 与标注员侧 reworkEmphasis(实时草稿)语义分开;仅供审查视角渲染意见字幕,
* 不解锁任何编辑能力。null=非返修复审(意见栏/判定列由页面在审查面板侧组合)。
*/
reviewReworkEmphasis?: ReworkEmphasisView | null;
/** 标注员一键"不改了"(skip=true)/撤销(skip=false),由页面落库到 rework-handling。 */
onReworkSkipToggle?: (opinionId: string, skipped: boolean) => void;
onChange: (segments: AnnotationSegment[]) => void;
@ -295,6 +301,7 @@ export function CaptureAnnotationWorkbench({
onReviewProblem,
onReviewSave,
onReviewProblemNavigate,
onReviewReworkNavigate,
onReviewTimestampJump,
reviewTimestampOpinions,
onReviewProblemEdit,
@ -307,6 +314,7 @@ export function CaptureAnnotationWorkbench({
onReject,
reworkNotice,
reworkEmphasis = null,
reviewReworkEmphasis = null,
onReworkSkipToggle,
onChange,
onPlayheadChange,
@ -1117,6 +1125,14 @@ export function CaptureAnnotationWorkbench({
actionId: displayedAction?.id ?? null,
})
: [];
// QC 返修接收视图的意见字幕(票 08):同一三排渲染,输入是已保存工作区的
// 强调层(reviewReworkEmphasis);与标注员侧互斥——审查视角不进 reworkActive。
const reviewReworkSubtitleRowList =
reviewReworkEmphasis?.active && isReviewViewing
? reworkSubtitleRows((reviewReworkEmphasis.sliceStates || new Map()).get(playheadSlice?.id ?? ""), {
actionId: displayedAction?.id ?? null,
})
: [];
const [reworkFocus, setReworkFocus] = useState<{ opinionId: string; seq: number } | null>(null);
const reworkJumpIndexRef = useRef(-1);
const jumpReworkProblem = (direction: 1 | -1) => {
@ -2459,6 +2475,8 @@ export function CaptureAnnotationWorkbench({
Boolean(target.closest("textarea, select, input:not([type='range']):not([readonly])")),
nativeControl: Boolean(target.closest("button, a, input, select, [role='button']")),
noteInput: Boolean(target.closest("[data-review-note-input]")),
// 返修接收视图挂载时 J/K 才进审查键表(review-shortcuts 的 reworkOpinions 上下文)。
reworkOpinions: Boolean(onReviewReworkNavigate),
},
);
if (!command) return;
@ -2483,6 +2501,9 @@ export function CaptureAnnotationWorkbench({
else if (command === "previous-problem" || command === "next-problem")
onReviewProblemNavigate?.(command === "previous-problem" ? -1 : 1);
else if (command === "jump-timestamp-problem") onReviewTimestampJump?.();
else if (command === "next-rework-opinion" || command === "previous-rework-opinion")
// 返修接收视图 J/K:定位由页面绑 ReviewViewingController 原语(票 08)。
onReviewReworkNavigate?.(command === "next-rework-opinion" ? 1 : -1);
else if (command === "edit-problem") onReviewProblemEdit?.();
else if (command === "delete-problem") onReviewProblemDelete?.();
}
@ -3207,6 +3228,26 @@ export function CaptureAnnotationWorkbench({
)}
</>
)}
{reviewReworkSubtitleRowList.length > 0 && (
<>
<ReworkProblemSubtitles
videoRef={leftVideoRef}
surfaceRef={videoSurfaceRef}
rows={reviewReworkSubtitleRowList}
viewKey={`${captionViewKey}:${playheadSlice?.id ?? "none"}:${displayedAction?.id ?? "none"}`}
camera="left"
/>
{rightSource && (
<ReworkProblemSubtitles
videoRef={rightVideoRef}
surfaceRef={videoSurfaceRef}
rows={reviewReworkSubtitleRowList}
viewKey={`${captionViewKey}:${playheadSlice?.id ?? "none"}:${displayedAction?.id ?? "none"}`}
camera="right"
/>
)}
</>
)}
{useMoviVideo ? (
<MoviVideo
ref={leftVideoRef}

View File

@ -1,6 +1,8 @@
import { useEffect, useState } from "react";
import type { ReworkBaseline } from "../services/api/rework";
import { annotationOperationsApi } from "../services/api/annotation-operations";
import type { ReworkEmphasisView } from "../lib/rework-emphasis-types";
import { reworkTargetVerdictChips } from "../lib/rework-review-rows.js";
type SliceLike = {
id: string;
@ -15,12 +17,31 @@ type ActionLike = { id: string; description?: string; start: number; end: number
const fmt = (v: number) => v.toFixed(2) + "s";
const same = (a: number, b: number) => Math.abs(a - b) <= 1e-6;
type VerdictChip = { state: string; label: string; count: number };
const chipClass: Record<string, string> = {
red: "bg-rose-600 text-white",
skipped: "bg-slate-400 text-white",
gray: "bg-slate-200 text-slate-600 dark:bg-slate-700 dark:text-slate-300",
old: "bg-slate-100 text-slate-400 dark:bg-slate-800 dark:text-slate-500",
};
/**
* B03 上下对比(spec §5.1/§5.3 + §11.2 零新媒体结论):退回基线 vs 当前已保存工作区的
* 结构对比——切片定义、动作文字、无效/舍弃判断、起止边界。红色强调变化;未变部分正常显示;
* 没有原意见的新改动也列出。双视频同屏非首版要求,画面核对走定位按钮。
* 票 08(R2-Q3:a)叠加意见级红/灰判定列:emphasis 提供时按落点逐块给出
* 未处理/已处理/跳过/历史 计数芯片(判定唯一来源 computeReworkEmphasis)。
*/
export function ReworkComparisonPanel({ taskId, baseline }: { taskId: string; baseline: ReworkBaseline }) {
export function ReworkComparisonPanel({
taskId,
baseline,
emphasis = null,
}: {
taskId: string;
baseline: ReworkBaseline;
emphasis?: ReworkEmphasisView | null;
}) {
const [current, setCurrent] = useState<{ slices: SliceLike[]; actions: ActionLike[] } | null>(null);
const [error, setError] = useState("");
useEffect(() => {
@ -47,12 +68,17 @@ export function ReworkComparisonPanel({ taskId, baseline }: { taskId: string; ba
if (!current) return null;
const baseSlices = (baseline.slices ?? []) as SliceLike[];
const sliceRows: { label: string; detail: string; tone: "changed" | "added" | "removed" | "same" }[] = [];
const sliceRows: {
label: string;
detail: string;
tone: "changed" | "added" | "removed" | "same";
chips: VerdictChip[];
}[] = [];
const baseIds = new Set(baseSlices.map((s) => s.id));
for (const base of baseSlices) {
const now = current.slices.find((s) => s.id === base.id);
if (!now) {
sliceRows.push({ label: `切片 ${base.name || base.id}`, detail: "已移除", tone: "removed" });
sliceRows.push({ label: `切片 ${base.name || base.id}`, detail: "已移除", tone: "removed", chips: [] });
continue;
}
const moved = !same(base.start, now.start) || !same(base.end, now.end);
@ -64,17 +90,38 @@ export function ReworkComparisonPanel({ taskId, baseline }: { taskId: string; ba
if (renamed) parts.push(`名称 ${base.name || "—"} → ${now.name || "—"}`);
if (dispositionChanged)
parts.push(`处置 ${base.deliveryDisposition || "keep"} → ${now.deliveryDisposition || "keep"}`);
sliceRows.push({ label: `切片 ${base.name || base.id}`, detail: parts.join(";"), tone: "changed" });
sliceRows.push({
label: `切片 ${base.name || base.id}`,
detail: parts.join(";"),
tone: "changed",
chips: reworkTargetVerdictChips(emphasis?.sliceStates?.get(now.id)),
});
} else {
sliceRows.push({ label: `切片 ${base.name || base.id}`, detail: "未变", tone: "same" });
sliceRows.push({
label: `切片 ${base.name || base.id}`,
detail: "未变",
tone: "same",
chips: reworkTargetVerdictChips(emphasis?.sliceStates?.get(now.id)),
});
}
}
for (const now of current.slices) {
if (!baseIds.has(now.id)) sliceRows.push({ label: `切片 ${now.name || now.id}`, detail: "新增", tone: "added" });
if (!baseIds.has(now.id))
sliceRows.push({
label: `切片 ${now.name || now.id}`,
detail: "新增",
tone: "added",
chips: reworkTargetVerdictChips(emphasis?.sliceStates?.get(now.id)),
});
}
const baseActions = (baseline.actions ?? []) as ActionLike[];
const actionRows: { label: string; detail: string; tone: "changed" | "added" | "removed" | "same" }[] = [];
const actionRows: {
label: string;
detail: string;
tone: "changed" | "added" | "removed" | "same";
chips: VerdictChip[];
}[] = [];
const baseActionIds = new Set(baseActions.map((a) => a.id));
for (const base of baseActions) {
const now = current.actions.find((a) => a.id === base.id);
@ -86,10 +133,11 @@ export function ReworkComparisonPanel({ taskId, baseline }: { taskId: string; ba
label: `动作 ${fmt(base.start)}`,
detail: `已按新边界拆成 ${splitParts.length} 段待核对`,
tone: "changed",
chips: splitParts.flatMap((part) => reworkTargetVerdictChips(emphasis?.actionStates?.get(part.id))),
});
continue;
}
actionRows.push({ label: `动作 ${fmt(base.start)}`, detail: "已移除", tone: "removed" });
actionRows.push({ label: `动作 ${fmt(base.start)}`, detail: "已移除", tone: "removed", chips: [] });
continue;
}
const textChanged = (base.description || "") !== (now.description || "");
@ -98,9 +146,19 @@ export function ReworkComparisonPanel({ taskId, baseline }: { taskId: string; ba
const parts: string[] = [];
if (textChanged) parts.push("描述已修改");
if (moved) parts.push(`边界 ${fmt(base.start)}–${fmt(base.end)} → ${fmt(now.start)}–${fmt(now.end)}`);
actionRows.push({ label: `动作 ${fmt(base.start)}`, detail: parts.join(";"), tone: "changed" });
actionRows.push({
label: `动作 ${fmt(base.start)}`,
detail: parts.join(";"),
tone: "changed",
chips: reworkTargetVerdictChips(emphasis?.actionStates?.get(now.id)),
});
} else {
actionRows.push({ label: `动作 ${fmt(base.start)}`, detail: base.description || "待标注", tone: "same" });
actionRows.push({
label: `动作 ${fmt(base.start)}`,
detail: base.description || "待标注",
tone: "same",
chips: reworkTargetVerdictChips(emphasis?.actionStates?.get(now.id)),
});
}
}
for (const now of current.actions) {
@ -109,6 +167,7 @@ export function ReworkComparisonPanel({ taskId, baseline }: { taskId: string; ba
label: `动作 ${fmt(now.start)}`,
detail: `新增:${now.description || "待标注"}`,
tone: "added",
chips: reworkTargetVerdictChips(emphasis?.actionStates?.get(now.id)),
});
}
}
@ -119,10 +178,28 @@ export function ReworkComparisonPanel({ taskId, baseline }: { taskId: string; ba
removed: "text-slate-400 line-through",
same: "text-slate-500",
} as const;
const renderChips = (chips: VerdictChip[]) =>
chips.length ? (
<span className="ml-auto flex shrink-0 flex-wrap justify-end gap-1 pl-2" aria-label="意见级判定">
{chips.map((chip) => (
<span
key={chip.state}
className={`rounded px-1 py-0.5 text-[10px] font-bold ${chipClass[chip.state] || chipClass.gray}`}
>
{chip.label} {chip.count}
</span>
))}
</span>
) : null;
const renderRows = (rows: typeof sliceRows) =>
rows.map((row, i) => (
<p key={i} className={toneClass[row.tone]}>
{row.label}:{row.detail}
<span className="flex items-start gap-1">
<span className="min-w-0 break-words">
{row.label}:{row.detail}
</span>
{renderChips(row.chips)}
</span>
</p>
));
const changedCount = [...sliceRows, ...actionRows].filter((r) => r.tone === "changed" || r.tone === "added").length;
@ -142,7 +219,10 @@ export function ReworkComparisonPanel({ taskId, baseline }: { taskId: string; ba
<div className="mt-1 space-y-0.5">{renderRows(actionRows)}</div>
</section>
</div>
<p className="mt-2 text-[10px] text-slate-400">红色=有修改;删除线=已移除;拆分段在工作台动作列表标“待核对”。</p>
<p className="mt-2 text-[10px] text-slate-400">
红色=有修改;删除线=已移除;拆分段在工作台动作列表标“待核对”。
{emphasis ? "右侧芯片=落在该块上的返修意见判定(未处理/已处理/不改留痕/历史轮)。" : ""}
</p>
</details>
);
}

View File

@ -0,0 +1,135 @@
import type { ReworkEmphasisView } from "../lib/rework-emphasis-types";
import type { ReworkBaseline } from "../services/api/rework";
import { reworkContrastRows, reworkVerdictLabels } from "../lib/rework-review-rows.js";
import { cn } from "../lib/utils";
type Block = {
kind: "slice" | "action";
id: string;
name?: string;
description?: string;
start: number;
end: number;
discarded?: boolean;
};
const fmt = (v: number) => (Number(v) || 0).toFixed(2) + "s";
/**
* 红灰对照双栏视图(R2-Q3:b——管"改了没",与结构对比面板并存不替换):
* 左 = 退回基线、右 = 提交版本,按意见目标对齐渲染切片/动作结构;
* 未解决意见红显、已处理/跳过/历史轮灰显。行数据由纯函数
* reworkContrastRows 推导(判定唯一来源 computeReworkEmphasis,票 04)。
*/
export function ReworkContrastView({
emphasis,
baseline,
workspace,
}: {
emphasis: ReworkEmphasisView | null;
baseline: ReworkBaseline | null;
workspace: { slices: unknown[]; actions: unknown[] } | null;
}) {
const rows = emphasis?.active
? reworkContrastRows(emphasis, {
baselineSlices: baseline?.slices ?? [],
baselineActions: baseline?.actions ?? [],
currentSlices: workspace?.slices ?? [],
currentActions: workspace?.actions ?? [],
})
: [];
if (!rows.length) return null;
const blockLabel = (block: Block) =>
block.kind === "slice"
? `切片 ${block.name || block.id}${block.discarded ? "(已舍弃)" : ""}`
: `动作 ${block.description || "待标注"}`;
return (
<details
data-testid="rework-contrast-view"
className="mb-2 rounded-xl border border-slate-300 bg-[color:var(--app-panel)] p-2 text-xs dark:border-slate-700"
>
<summary className="cursor-pointer font-semibold text-slate-600 dark:text-slate-300">
红灰对照(第 {emphasis?.round} 轮意见 · 按意见目标对齐)· 未处理 {emphasis?.unclearedCount}
</summary>
<div className="mt-2 grid grid-cols-[5rem_1fr_1fr] gap-1 border-b border-slate-200 pb-1 text-[10px] font-semibold text-slate-400 dark:border-slate-700">
<span>意见</span>
<span>退回基线</span>
<span>提交版本</span>
</div>
<ul className="mt-1 space-y-1">
{rows.map((row) => (
<li
key={row.key}
data-rework-state={row.state}
className={cn(
"grid grid-cols-[5rem_1fr_1fr] items-start gap-1 rounded border px-1 py-1",
row.state === "red"
? "border-rose-300 bg-rose-50/80 dark:border-rose-800 dark:bg-rose-950/40"
: "border-slate-200 bg-white/60 dark:border-slate-700 dark:bg-slate-800/30",
)}
>
<span className="flex flex-col gap-0.5 text-[10px] leading-tight">
<span
className={cn(
"rounded px-1 py-0.5 font-bold",
row.state === "red" ? "bg-rose-600 text-white" : "bg-slate-400 text-white",
)}
title={reworkVerdictLabels[row.state]}
>
{row.round}轮
</span>
<span className="text-slate-400">{reworkVerdictLabels[row.state]}</span>
{row.reattached && (
<span className="text-slate-400" title="原目标结构已变,意见跟随到现块">
已跟随
</span>
)}
</span>
<span className="min-w-0 break-words text-slate-600 dark:text-slate-300">
{row.scope === "task" ? (
<em className="text-slate-500">整体意见(无结构目标):{row.text}</em>
) : (
<>
{row.baseline?.length ? (
row.baseline.map((block) => (
<span key={block.id} className="block">
{blockLabel(block)}{" "}
<span className="font-mono text-[10px] text-slate-400">
{fmt(block.start)}–{fmt(block.end)}
</span>
</span>
))
) : row.current ? (
<span className="text-slate-400">基线无对应结构</span>
) : (
<span className="text-slate-400">—</span>
)}
</>
)}
</span>
<span className="min-w-0 break-words text-slate-600 dark:text-slate-300">
{row.scope === "task" ? (
<em className="text-slate-500">见左侧整体意见文字</em>
) : row.current?.length ? (
row.current.map((block) => (
<span key={block.id} className="block">
{blockLabel(block)}{" "}
<span className="font-mono text-[10px] text-slate-400">
{fmt(block.start)}–{fmt(block.end)}
</span>
</span>
))
) : (
<span className="text-slate-400">无承接结构(已消解)</span>
)}
{row.scope !== "task" && <span className="mt-0.5 block text-[10px] text-slate-400">{row.text}</span>}
</span>
</li>
))}
</ul>
<p className="mt-2 text-[10px] text-slate-400">
红=未处理;灰=已处理/跳过留痕/历史轮;左列为此前打回时的结构。
</p>
</details>
);
}

View File

@ -0,0 +1,33 @@
/**
* 顶部结构摘要横幅(票 08 消费票 07 契约,spec §3.6 / Q7:b):
* 标注员返工送检时由服务端从"退回基线 vs 提交工作区"算出的净计数,
* 显示在质检页顶部。首标送检无退回基线,摘要缺省时不渲染。
*/
export function ReworkReceiveBanner({
round,
summary,
}: {
round: number;
summary?: { merged: number; split: number; discarded: number; boundaryMoves: number } | null;
}) {
if (!summary) return null;
const parts: string[] = [];
if (summary.merged > 0) parts.push(`合并 ${summary.merged}`);
if (summary.split > 0) parts.push(`拆分 ${summary.split}`);
if (summary.discarded > 0) parts.push(`弃用 ${summary.discarded}`);
if (summary.boundaryMoves > 0) parts.push(`挪边 ${summary.boundaryMoves}`);
return (
<p
data-testid="rework-receive-banner"
className="mb-2 rounded-lg border border-sky-300 bg-sky-50 px-3 py-2 text-xs text-sky-900 dark:border-sky-700 dark:bg-sky-950/40 dark:text-sky-100"
>
<span className="font-semibold">第 {round} 轮返工送检 · 结构变更摘要:</span>
{parts.length ? (
<span className="ml-1 font-mono">{parts.join(" / ")}</span>
) : (
<span className="ml-1">本轮结构无变化</span>
)}
<span className="ml-2 font-normal text-slate-500 dark:text-slate-400">对照下方红灰视图逐条核对</span>
</p>
);
}

View File

@ -41,6 +41,12 @@ export type ReviewViewingProps = {
onReviewSave?: () => void;
/** Saved-problem list keyboard navigation: selects and seeks only, never enters text. */
onReviewProblemNavigate?: (direction: -1 | 1) => void;
/**
* 返修接收视图 J/K 逐条跳意见(票 08,R2-Q5:a):定位走 ReviewViewingController
* 的 seekAction/seekTime/seekSlice 原语。仅 QC 返修接收视图挂载时传入——
* 不传时审查键表保持 J/K 空闲(review-shortcuts 的 reworkOpinions 上下文)。
*/
onReviewReworkNavigate?: (direction: -1 | 1) => void;
onReviewTimestampJump?: () => void;
/** maintenance-backlog#02:审查侧时间点意见(切片时间轴顶部标记渲染;§4.3 点位不涂红父切片)。 */
reviewTimestampOpinions?: ReviewTimestampOpinion[];

View File

@ -0,0 +1,83 @@
import { useEffect, useMemo, useState } from "react";
import { reworkApi, type ReworkBaseline, type ReworkHandling } from "../services/api/rework";
import { annotationOperationsApi } from "../services/api/annotation-operations";
import { computeReworkEmphasis } from "../lib/rework-emphasis.js";
import type { SliceSegment } from "../types";
/**
* QC 返修接收视图的强调层投影(票 08,spec §3.6):
* 与标注员侧 useReworkEmphasis 的差别只在输入——QC 输入 = 已保存工作区
* (复审以保存后差异为准,ADR 0006:31),不是页面实时草稿。
* 数据来源与 ReworkComparisonPanel 同一读路径(getTask 的最后一条切片/动作修订),
* 同时带出票 07 落在送检修订上的 structureChangeSummary 供顶部横幅展示。
*/
export function useReworkReviewEmphasis(itemId: string, round: number, taskId: string, enabled: boolean) {
const [baselines, setBaselines] = useState<ReworkBaseline[]>([]);
const [handling, setHandling] = useState<ReworkHandling | null>(null);
const [workspace, setWorkspace] = useState<{
slices: SliceSegment[];
actions: Array<{ id: string; description?: string; start: number; end: number; status?: string }>;
structureChangeSummary?: { merged: number; split: number; discarded: number; boundaryMoves: number };
} | null>(null);
useEffect(() => {
if (!enabled || !itemId || round < 1 || !taskId) {
setBaselines([]);
setHandling(null);
setWorkspace(null);
return;
}
let alive = true;
const rounds = Array.from({ length: round }, (_, index) => index + 1);
void Promise.all([
Promise.all(
rounds.map((r) =>
reworkApi
.baseline(itemId, r)
.then((response) => response.baseline)
.catch(() => null),
),
),
reworkApi
.handling(itemId, round)
.then((response) => response.handling)
.catch(() => null),
annotationOperationsApi.getTask(taskId).catch(() => null),
]).then(([list, currentHandling, detail]) => {
if (!alive) return;
setBaselines(list.filter((item): item is ReworkBaseline => Boolean(item)));
setHandling(currentHandling || null);
if (detail) {
const sliceRevision = detail.sliceRevisions[detail.sliceRevisions.length - 1];
const annotationRevision = detail.revisions[detail.revisions.length - 1];
setWorkspace({
slices: (sliceRevision?.segments as SliceSegment[] | undefined) || [],
actions:
(annotationRevision?.segments as
Array<{ id: string; description?: string; start: number; end: number; status?: string }> | undefined) ||
[],
structureChangeSummary: sliceRevision?.structureChangeSummary,
});
} else {
setWorkspace(null);
}
});
return () => {
alive = false;
};
}, [itemId, round, taskId, enabled]);
const emphasis = useMemo(
() =>
computeReworkEmphasis({
baselines,
currentSlices: workspace?.slices || [],
currentActions: workspace?.actions || [],
skippedOpinionIds: handling?.skippedOpinionIds || [],
currentRound: round,
}),
[baselines, workspace, handling, round],
);
return { emphasis, workspace, handling };
}

View File

@ -2,7 +2,10 @@
const macPlatform = () =>
typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent || "");
export function reviewShortcut(event, { editable = false, nativeControl = false, noteInput = false, mac } = {}) {
export function reviewShortcut(
event,
{ editable = false, nativeControl = false, noteInput = false, reworkOpinions = false, mac } = {},
) {
if (event.defaultPrevented || event.isComposing || event.keyCode === 229) return null;
const { key, ctrlKey, metaKey, altKey, shiftKey, repeat } = event;
if (key === "Escape") return repeat ? "consume" : "escape";
@ -37,6 +40,9 @@ export function reviewShortcut(event, { editable = false, nativeControl = false,
f: "problem",
g: "jump-timestamp-problem",
"?": "help",
// 返修接收视图(spec §3.6,R2-Q5:a):J/K 逐条跳意见,与标注员同一肌肉记忆。
// 仅在 QC 返修接收视图挂载(reworkOpinions 上下文为真)时占用,平时保持空闲。
...(reworkOpinions ? { j: "next-rework-opinion", k: "previous-rework-opinion" } : {}),
}[key.length === 1 ? key.toLowerCase() : key];
return command ? (repeat && !command.startsWith("step-") ? "consume" : command) : null;
}
@ -49,6 +55,7 @@ export const reviewShortcutHelp = [
{ keys: "B", label: "从当前片头复查,片尾暂停" },
{ keys: "F", label: "暂停并选择意见范围;编辑已有意见,没有则填写" },
{ keys: "G", label: "跳到下一个时间点意见并显示内容(循环;D5 独立键,不占用卡片导航)" },
{ keys: "J / K", label: "下一条/上一条返修意见,定位到意见位置(返修复审时可用;与标注员同一肌肉记忆)" },
{ keys: "Ctrl / ⌘ + ↑ / ↓", label: "选择整体/当前切片/当前动作意见;到首尾停止" },
{ keys: "Enter", label: "编辑选中的意见卡片;点击卡片也可编辑" },
{ keys: "Ctrl / ⌘ + Enter", label: "保存当前意见;删空已有内容后确认清除,不会提交审核决定" },

View File

@ -0,0 +1,157 @@
// QC 返修接收视图的展示行推导(票 08,spec §3.6 / R2-Q3、R2-Q4):
// 消费票 04 computeReworkEmphasis 的判定结果(red/gray/skipped/old + 落点 + reattached),
// 推导"意见 → 展示行"映射,不做任何判定重算——红/灰语义的唯一来源是 rework-emphasis.js。
// 纯函数、无副作用;QC 侧与标注员侧共用同一判定,展示层各自取形。
/** 意见判定 → 展示标签(与 ReworkOpinionRail 的状态角标同一词汇)。 */
export const reworkVerdictLabels = {
red: "未处理",
gray: "已处理",
skipped: "不改(留痕)",
old: "历史轮",
};
const VERDICT_ORDER = ["red", "skipped", "gray", "old"];
/**
* 结构对比面板的意见级判定列(R2-Q3:a):一个目标块(切片/动作)的意见桶
* 聚合成状态芯片 [{ state, label, count }],按 red → skipped → gray → old 排序,
* 空状态不产出。
*/
export function reworkTargetVerdictChips(bucket) {
const chips = [];
if (!bucket) return chips;
for (const state of VERDICT_ORDER) {
const items = Array.isArray(bucket[state]) ? bucket[state] : [];
if (items.length) chips.push({ state, label: reworkVerdictLabels[state], count: items.length });
}
return chips;
}
/** 意见栏切片显示名 "003 · 名称"(与标注员侧 ReworkOpinionRail 同款格式)。 */
export function reworkSliceLabelOf(slices, sliceId) {
if (!sliceId || !Array.isArray(slices)) return null;
const index = slices.findIndex((slice) => slice.id === sliceId);
if (index < 0) return null;
return `${String(index + 1).padStart(3, "0")} · ${slices[index].name || "未命名"}`;
}
function coveringSlice(slices, start, end) {
const list = Array.isArray(slices) ? slices : [];
const inside = list.find((slice) => start >= slice.start - 1e-6 && end <= slice.end + 1e-6);
if (inside) return inside;
return list.find((slice) => start < slice.end && end > slice.start) || null;
}
/** 动作在所属切片内的序号(1 起),与标注员侧意见栏同一归属语义(包含优先、重叠兜底)。 */
export function reworkActionIndexOf(slices, actions, actionId) {
const list = Array.isArray(actions) ? actions : [];
const action = list.find((item) => item.id === actionId);
if (!action) return null;
const owner = coveringSlice(slices, action.start, action.end);
if (!owner) return null;
const inSlice = list.filter((item) => coveringSlice(slices, item.start, item.end)?.id === owner.id);
const index = inSlice.findIndex((item) => item.id === actionId);
return index >= 0 ? index + 1 : null;
}
// ---- 红灰对照双栏(R2-Q3:b):按意见目标对齐"退回基线 vs 提交版本" ----
const toBlock = (kind, block) => ({
kind,
id: block.id,
name: block.name,
description: block.description,
start: block.start,
end: block.end,
discarded: block.deliveryDisposition === "discard" || undefined,
});
/** 时间跨度内重叠的基线块(合并 → 左侧多块;起止排序稳定)。 */
const blocksOverlapping = (kind, blocks, span) =>
(Array.isArray(blocks) ? blocks : [])
.filter((block) => span.start < block.end && span.end > block.start)
.sort((a, b) => (a.start || 0) - (b.start || 0))
.map((block) => toBlock(kind, block));
/** 覆盖某时间点的块;恰落边界线上归以该点为起点的右侧块(与足迹归属同一语义)。 */
const rawCovering = (blocks, at) => {
const candidates = (Array.isArray(blocks) ? blocks : [])
.filter((block) => at >= (block.start || 0) - 1e-6 && at <= (block.end || 0) + 1e-6)
.sort((a, b) => (b.start || 0) - (a.start || 0));
return candidates[0] || null;
};
const sliceById = (slices, id) => (Array.isArray(slices) ? slices.find((slice) => slice.id === id) : null) || null;
/**
* 红灰对照行(意见 → 展示行映射的主推导):
* 逐条 walk emphasis.jumpOrder,右侧 = 意见落点在提交版本的结构块数组
* (动作落点优先,缺失按锚点回退到覆盖动作/切片),左侧 = 退回基线中与右侧
* 时间跨度重叠的结构块数组(按意见目标种类对齐:动作意见对动作、切片意见对切片、
* 时间点意见对覆盖该时刻的块;合并意见左侧自然出现多块)。整体意见无结构目标,
* 两侧为 null,由 UI 文本通栏渲染。state / reattached 原样透传
* (判定来源唯一:computeReworkEmphasis)。
*/
export function reworkContrastRows(
emphasis,
{ baselineSlices = [], baselineActions = [], currentSlices = [], currentActions = [] } = {},
) {
const rows = [];
for (const entry of emphasis?.jumpOrder || []) {
const opinion = entry.opinion || {};
const anchor = typeof entry.anchor === "number" ? entry.anchor : null;
let current = null;
let baseline = null;
if (opinion.scope === "action") {
const live =
(Array.isArray(currentActions) ? currentActions.find((action) => action.id === entry.actionId) : null) ||
(anchor != null ? rawCovering(currentActions, anchor) : null);
if (live) {
current = [toBlock("action", live)];
baseline = blocksOverlapping("action", baselineActions, live);
} else {
const slice =
sliceById(currentSlices, entry.sliceId) || (anchor != null ? rawCovering(currentSlices, anchor) : null);
if (slice) {
current = [toBlock("slice", slice)];
baseline = blocksOverlapping("slice", baselineSlices, slice);
}
}
} else if (opinion.scope === "slice") {
const slice =
sliceById(currentSlices, entry.sliceId) || (anchor != null ? rawCovering(currentSlices, anchor) : null);
if (slice) {
current = [toBlock("slice", slice)];
baseline = blocksOverlapping("slice", baselineSlices, slice);
}
} else if (opinion.scope === "timestamp") {
const at = typeof opinion.atSeconds === "number" ? opinion.atSeconds : anchor;
if (at != null) {
const liveAction = rawCovering(currentActions, at);
const liveSlice = rawCovering(currentSlices, at);
if (liveAction) {
current = [toBlock("action", liveAction)];
baseline = blocksOverlapping("action", baselineActions, liveAction);
} else if (liveSlice) {
current = [toBlock("slice", liveSlice)];
baseline = blocksOverlapping("slice", baselineSlices, liveSlice);
}
}
}
rows.push({
key: `${opinion.round || 0}:${opinion.id}`,
id: opinion.id,
round: opinion.round || 0,
scope: opinion.scope,
text: opinion.text,
atSeconds: opinion.atSeconds,
state: entry.state,
reattached: Boolean(opinion.reattached),
anchor,
baseline: current ? baseline : null,
current,
});
}
return rows;
}

View File

@ -9,8 +9,16 @@ import { reviewDecisionApi } from "../services/api/review-decision";
import { useReviewDecision, type ReviewDecisionRequest } from "../hooks/useReviewDecision";
import { ReviewProblemPanel } from "../components/ReviewProblemPanel";
import { useReworkReviewData } from "../hooks/useReworkReviewData";
import { useReworkReviewEmphasis } from "../hooks/useReworkReviewEmphasis";
import { useReworkEmphasis } from "../hooks/useReworkEmphasis";
import { ReworkComparisonPanel } from "../components/ReworkComparisonPanel";
import { ReworkContrastView } from "../components/ReworkContrastView";
import { ReworkReceiveBanner } from "../components/ReworkReceiveBanner";
import { ReworkOpinionRail } from "../components/ReworkOpinionRail";
import { nextReworkJump } from "../lib/rework-emphasis.js";
import { reworkActionIndexOf, reworkSliceLabelOf } from "../lib/rework-review-rows.js";
import type { ReworkOpinionView } from "../lib/rework-emphasis-types";
import type { ReviewViewingController } from "../components/review-viewing";
import { useReviewDraft } from "../hooks/useReviewDraft";
import type { ReviewProblem } from "../services/api/review-draft";
import { APIError } from "../services/api/client";
@ -2048,9 +2056,83 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
reviewDraft.draft?.reviewRound || 0,
Boolean(reviewSessionEnabled && reviewReceiptSupported && (reviewDraft.draft?.reviewRound || 0) >= 1),
);
// QC 返修接收视图(票 08):强调层输入 = 已保存工作区(ADR 0006:31),与标注员侧
// 实时草稿语义分开;同一 getTask 读路径带出票 07 的送检结构变更摘要。
const reworkReceiveEligible = Boolean(
reviewSessionEnabled && reviewReceiptSupported && (reviewDraft.draft?.reviewRound || 0) >= 1 && detail?.task?.id,
);
const reworkReceive = useReworkReviewEmphasis(
reviewDraft.draft?.itemId || "",
reviewDraft.draft?.reviewRound || 0,
detail?.task?.id || "",
reworkReceiveEligible,
);
const reworkReceiveEmphasis = reworkReceiveEligible && reworkReceive.emphasis.active ? reworkReceive.emphasis : null;
// J/K 逐条跳意见(R2-Q5:a):定位绑 ReviewViewingController 现成原语,不搬 workbench 导航。
const reviewControllerRef = useRef<ReviewViewingController | null>(null);
const [reviewReworkFocus, setReviewReworkFocus] = useState<{ opinionId: string; seq: number } | null>(null);
const reviewReworkJumpIndexRef = useRef(-1);
const seekReviewReworkEntry = (entry: {
opinion: ReworkOpinionView;
anchor: number | null;
sliceId: string | null;
actionId: string | null;
}) => {
const controller = reviewControllerRef.current;
if (!controller) return;
if (entry.actionId && controller.seekAction(entry.actionId)) return;
const anchor = typeof entry.anchor === "number" && entry.anchor >= 0 ? entry.anchor : null;
if (anchor != null) {
controller.seekTime(anchor);
return;
}
if (entry.sliceId) controller.seekSlice(entry.sliceId);
};
const onReviewReworkNavigate = (direction: 1 | -1) => {
const emphasis = reworkReceiveEmphasis;
if (!emphasis?.jumpOrder.length) return;
const jump = nextReworkJump(emphasis, reviewReworkJumpIndexRef.current, direction);
if (!jump) return;
reviewReworkJumpIndexRef.current = jump.index;
setReviewReworkFocus((current) => ({ opinionId: jump.entry.opinion.id, seq: (current?.seq || 0) + 1 }));
seekReviewReworkEntry(jump.entry);
};
const locateReviewReworkOpinion = (opinion: ReworkOpinionView) => {
const emphasis = reworkReceiveEmphasis;
const index = emphasis?.jumpOrder.findIndex((entry) => entry.opinion.id === opinion.id) ?? -1;
if (index >= 0) reviewReworkJumpIndexRef.current = index;
setReviewReworkFocus((current) => ({ opinionId: opinion.id, seq: (current?.seq || 0) + 1 }));
if (index >= 0 && emphasis) seekReviewReworkEntry(emphasis.jumpOrder[index]);
};
const reworkReceiveSliceLabelOf = (sliceId: string | null) =>
reworkSliceLabelOf(reworkReceive.workspace?.slices || [], sliceId);
const reworkReceiveActionIndexOf = (actionId: string) =>
reworkActionIndexOf(reworkReceive.workspace?.slices || [], reworkReceive.workspace?.actions || [], actionId);
const handleReviewController = useCallback(
(controller: ReviewViewingController | null) => {
reviewControllerRef.current = controller;
reviewDraft.onController(controller);
},
[reviewDraft.onController],
);
const reviewProblemPanel =
reviewSessionEnabled && reviewReceiptSupported ? (
<>
{reworkReceiveEmphasis && (
<ReworkReceiveBanner
round={reworkReceiveEmphasis.round}
summary={reworkReceive.workspace?.structureChangeSummary || null}
/>
)}
{reworkReceiveEmphasis && reworkReceiveEmphasis.jumpOrder.length > 0 && (
<ReworkOpinionRail
emphasis={reworkReceiveEmphasis}
focus={reviewReworkFocus}
onLocate={locateReviewReworkOpinion}
sliceLabelOf={reworkReceiveSliceLabelOf}
actionIndexOf={reworkReceiveActionIndexOf}
/>
)}
<ReviewProblemPanel
review={reviewDraft}
writeLocked={Boolean(reviewDecision.pending)}
@ -2060,8 +2142,19 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
reworkHandling={reworkReviewData.handling}
/>
{reworkReviewData.baseline && detail?.task?.id && (
<ReworkComparisonPanel taskId={detail.task.id} baseline={reworkReviewData.baseline} />
)}
<ReworkComparisonPanel
taskId={detail.task.id}
baseline={reworkReviewData.baseline}
emphasis={reworkReceiveEmphasis}
/>
)}
{reworkReviewData.baseline && (
<ReworkContrastView
emphasis={reworkReceiveEmphasis}
baseline={reworkReviewData.baseline}
workspace={reworkReceive.workspace}
/>
)}
</>
) : undefined;
useEffect(() => {
@ -6266,7 +6359,11 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
reviewProblemPanel={reviewProblemPanel}
onReviewNavigate={reviewDraft.onNavigate}
onReviewPositionChange={reviewDraft.onPosition}
onReviewController={reviewDraft.onController}
onReviewController={handleReviewController}
onReviewReworkNavigate={
reworkReceiveEmphasis?.jumpOrder.length ? onReviewReworkNavigate : undefined
}
reviewReworkEmphasis={reworkReceiveEmphasis}
onReviewProblem={reviewDraft.beginProblem}
onReviewSave={() => {
if (!reviewDecision.pending) void reviewDraft.save();

View File

@ -70,3 +70,31 @@ test("G jumps between timestamp problems as an independent key (D5)", () => {
assert.equal(parse("g", {}, { editable: true }), null, "输入框内保持原生键位");
assert.equal(parse("g", { ctrlKey: true }), null, "带修饰键不触发");
});
test("J/K navigate rework opinions only while the QC rework receive view is attached (spec §3.6, R2-Q5:a)", () => {
const parse = (key, extra = {}, context = {}) => reviewShortcut({ key, ...extra }, context);
assert.equal(parse("j", {}, { reworkOpinions: true }), "next-rework-opinion");
assert.equal(parse("k", {}, { reworkOpinions: true }), "previous-rework-opinion");
assert.equal(parse("J", {}, { reworkOpinions: true }), "next-rework-opinion", "大写归一化与标注员侧同款");
assert.equal(parse("K", {}, { reworkOpinions: true }), "previous-rework-opinion");
assert.equal(parse("j"), null, "无返修意见时 J/K 保持空闲");
assert.equal(parse("k"), null);
assert.equal(parse("j", {}, { reworkOpinions: true, editable: true }), null, "输入框内保持原生键位");
assert.equal(parse("j", { ctrlKey: true }, { reworkOpinions: true }), null, "带修饰键不触发");
assert.equal(parse("j", { altKey: true }, { reworkOpinions: true }), null);
assert.equal(parse("j", { repeat: true }, { reworkOpinions: true }), "consume");
// 不与现有审查键冲突:既有绑定逐个复核。
const occupied = {
" ": "play",
ArrowLeft: "step-back",
ArrowRight: "step-forward",
ArrowUp: "previous-action",
ArrowDown: "next-action",
b: "review-slice",
f: "problem",
g: "jump-timestamp-problem",
"?": "help",
};
for (const [key, command] of Object.entries(occupied))
assert.equal(parse(key, key === "?" ? { shiftKey: true } : {}, { reworkOpinions: true }), command);
});

View File

@ -0,0 +1,264 @@
import test from "node:test";
import assert from "node:assert/strict";
import {
reworkVerdictLabels,
reworkTargetVerdictChips,
reworkSliceLabelOf,
reworkActionIndexOf,
reworkContrastRows,
} from "../../src/lib/rework-review-rows.js";
// 手搓的最小 emphasis 形状(与 rework-emphasis.js 的输出契约一致,但数据是独立构造的
// 固定样例——判定语义(红/灰/跳过/历史 + 落点)来自票 04 的领域规则,这里只消费)。
const opinion = (id, round, scope, extra = {}) => ({
id,
round,
scope,
text: `意见${id}`,
...extra,
});
test("verdict chips aggregate a target bucket with canonical state order and labels", () => {
const bucket = {
red: [opinion("a", 2, "slice"), opinion("b", 2, "action")],
skipped: [opinion("c", 2, "slice")],
gray: [opinion("d", 2, "slice"), opinion("e", 2, "timestamp"), opinion("f", 2, "slice")],
old: [opinion("g", 1, "slice")],
};
assert.deepEqual(reworkTargetVerdictChips(bucket), [
{ state: "red", label: reworkVerdictLabels.red, count: 2 },
{ state: "skipped", label: reworkVerdictLabels.skipped, count: 1 },
{ state: "gray", label: reworkVerdictLabels.gray, count: 3 },
{ state: "old", label: reworkVerdictLabels.old, count: 1 },
]);
assert.deepEqual(reworkTargetVerdictChips({ red: [], gray: [], skipped: [], old: [] }), []);
assert.deepEqual(reworkTargetVerdictChips(undefined), []);
});
test("slice labels mirror the annotator rail format (003 · name, unnamed fallback)", () => {
const slices = [
{ id: "s1", name: "俯身取物", start: 0, end: 10 },
{ id: "s2", start: 10, end: 20 },
{ id: "s3", name: "起身", start: 20, end: 30 },
];
assert.equal(reworkSliceLabelOf(slices, "s3"), "003 · 起身");
assert.equal(reworkSliceLabelOf(slices, "s2"), "002 · 未命名");
assert.equal(reworkSliceLabelOf(slices, "nope"), null);
assert.equal(reworkSliceLabelOf(slices, null), null);
});
test("action index is 1-based within the covering slice with overlap fallback", () => {
const slices = [
{ id: "s1", name: "A", start: 0, end: 10 },
{ id: "s2", name: "B", start: 10, end: 20 },
];
const actions = [
{ id: "a1", start: 0, end: 3 },
{ id: "a2", start: 3, end: 7 },
{ id: "a3", start: 7, end: 10 },
{ id: "a4", start: 10, end: 14 },
{ id: "cross", start: 9.5, end: 12 },
];
assert.equal(reworkActionIndexOf(slices, actions, "a3"), 3);
assert.equal(reworkActionIndexOf(slices, actions, "a4"), 1);
assert.equal(reworkActionIndexOf(slices, actions, "cross"), 4, "跨界动作归重叠最多语义下的包含侧兜底");
assert.equal(reworkActionIndexOf(slices, actions, "nope"), null);
});
test("contrast rows align baseline vs submitted structure per slice opinion (merge shows two on the left)", () => {
const emphasis = {
active: true,
round: 2,
jumpOrder: [
{
opinion: opinion("o1", 2, "slice", { sliceId: "m1" }),
anchor: 12,
sliceId: "m1",
actionId: null,
state: "red",
},
],
};
const rows = reworkContrastRows(emphasis, {
baselineSlices: [
{ id: "b1", name: "左片", start: 10, end: 15 },
{ id: "b2", name: "右片", start: 15, end: 20 },
],
baselineActions: [],
currentSlices: [{ id: "m1", name: "合并片", start: 10, end: 20 }],
currentActions: [],
});
assert.equal(rows.length, 1);
assert.equal(rows[0].state, "red");
assert.equal(rows[0].scope, "slice");
assert.deepEqual(
rows[0].baseline.map((block) => block.id),
["b1", "b2"],
"合并意见左侧显示两个基线片",
);
assert.deepEqual(
rows[0].current.map((block) => block.id),
["m1"],
);
assert.equal(rows[0].baseline[0].kind, "slice");
assert.equal(rows[0].reattached, false);
});
test("contrast rows follow the reattached action landing and mark the opinion as followed", () => {
const emphasis = {
active: true,
round: 2,
jumpOrder: [
{
opinion: opinion("o2", 2, "action", { sliceId: "s1", actionId: "n1", reattached: true }),
anchor: 3,
sliceId: "s1",
actionId: "n1",
state: "gray",
},
],
};
const rows = reworkContrastRows(emphasis, {
baselineSlices: [{ id: "b1", name: "片", start: 0, end: 10 }],
baselineActions: [{ id: "bAct", description: "旧描述", start: 2, end: 5 }],
currentSlices: [{ id: "s1", name: "片", start: 0, end: 10 }],
currentActions: [{ id: "n1", description: "新描述", start: 2.5, end: 6 }],
});
assert.equal(rows.length, 1);
assert.equal(rows[0].state, "gray");
assert.equal(rows[0].reattached, true);
assert.deepEqual(
rows[0].current.map((b) => b.id),
["n1"],
);
assert.deepEqual(
rows[0].baseline.map((b) => b.id),
["bAct"],
"基线侧按时间重叠对齐",
);
assert.equal(rows[0].baseline[0].kind, "action");
});
test("timestamp opinions contrast the blocks covering the moment on both sides", () => {
const emphasis = {
active: true,
round: 2,
jumpOrder: [
{
opinion: opinion("o3", 2, "timestamp", { atSeconds: 3.2, sliceId: "s1", actionId: "a2" }),
anchor: 3.2,
sliceId: "s1",
actionId: "a2",
state: "red",
},
],
};
const rows = reworkContrastRows(emphasis, {
baselineSlices: [{ id: "b1", name: "片", start: 0, end: 10 }],
baselineActions: [
{ id: "bA1", start: 0, end: 3 },
{ id: "bA2", start: 3, end: 6 },
],
currentSlices: [{ id: "s1", name: "片", start: 0, end: 10 }],
currentActions: [{ id: "a2", description: "改后", start: 3, end: 6 }],
});
assert.deepEqual(
rows[0].current.map((b) => b.id),
["a2"],
);
assert.deepEqual(
rows[0].baseline.map((b) => b.id),
["bA2"],
);
});
test("task opinions carry no structural target and stay as text-only rows", () => {
const emphasis = {
active: true,
round: 2,
jumpOrder: [{ opinion: opinion("o4", 2, "task"), anchor: -1, sliceId: null, actionId: null, state: "gray" }],
};
const rows = reworkContrastRows(emphasis, {
baselineSlices: [{ id: "b1", start: 0, end: 10 }],
currentSlices: [{ id: "s1", start: 0, end: 10 }],
});
assert.equal(rows.length, 1);
assert.equal(rows[0].scope, "task");
assert.equal(rows[0].baseline, null);
assert.equal(rows[0].current, null);
assert.equal(rows[0].state, "gray");
});
test("missing landing falls back to anchor lookup and discarded landing keeps the slice kind", () => {
const emphasis = {
active: true,
round: 2,
jumpOrder: [
{
// 拆分后落点动作已不存在:按锚点回退到覆盖动作/切片。
opinion: opinion("o5", 2, "action", { actionId: "gone" }),
anchor: 17,
sliceId: "s2",
actionId: "gone",
state: "gray",
},
{
// 舍弃片自动消红:落点是切片(无动作),保留 discarded 标记。
opinion: opinion("o6", 2, "slice", { sliceId: "s3" }),
anchor: 25,
sliceId: "s3",
actionId: null,
state: "gray",
},
],
};
const rows = reworkContrastRows(emphasis, {
baselineSlices: [
{ id: "b1", start: 10, end: 20 },
{ id: "b2", start: 20, end: 30 },
],
baselineActions: [{ id: "bAct", start: 15, end: 18 }],
currentSlices: [
{ id: "s2", start: 10, end: 20 },
{ id: "s3", start: 20, end: 30, deliveryDisposition: "discard" },
],
currentActions: [{ id: "live", start: 16, end: 18 }],
});
assert.deepEqual(
rows[0].current.map((b) => b.id),
["live"],
"动作落点缺失回退到锚点覆盖动作",
);
assert.deepEqual(
rows[0].baseline.map((b) => b.id),
["bAct"],
);
assert.deepEqual(
rows[1].current.map((b) => b.id),
["s3"],
);
assert.equal(rows[1].current[0].discarded, true, "舍弃落点携带 discarded 供右侧渲染");
assert.deepEqual(
rows[1].baseline.map((b) => b.id),
["b2"],
);
});
test("contrast rows keep jump order and key uniqueness across rounds", () => {
const emphasis = {
active: true,
round: 2,
jumpOrder: [
{ opinion: opinion("x", 2, "slice", { sliceId: "s1" }), anchor: 1, sliceId: "s1", actionId: null, state: "red" },
{ opinion: opinion("x", 1, "slice", { sliceId: "s1" }), anchor: 2, sliceId: "s1", actionId: null, state: "old" },
],
};
const rows = reworkContrastRows(emphasis, {
baselineSlices: [{ id: "b1", start: 0, end: 10 }],
currentSlices: [{ id: "s1", start: 0, end: 10 }],
});
assert.deepEqual(
rows.map((row) => row.key),
["2:x", "1:x"],
);
});