droboticflow/tests/frontend/rework-emphasis.test.mjs
2026-10-19 11:05:43 +08:00

800 lines
32 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import assert from "node:assert/strict";
import test from "node:test";
import {
computeReworkEmphasis,
emptyReworkEmphasis,
nextReworkJump,
reworkLocatePlan,
reworkSubtitleRows,
} from "../../src/lib/rework-emphasis.js";
const baseline = {
round: 1,
problems: [
{ id: "op-task", scope: "task", text: "整体偏暗" },
{ id: "op-slice", scope: "slice", sliceId: "s1", text: "切片命名错误" },
{ id: "op-action", scope: "action", sliceId: "s1", actionId: "a1", text: "描述错误" },
{ id: "op-ts", scope: "timestamp", sliceId: "s1", atSeconds: 2.5, timeBasis: "capture-seconds", text: "画面问题" },
],
slices: [
{ id: "s1", name: "拿取", start: 0, end: 10 },
{ id: "s2", name: "放回", start: 10, end: 20 },
],
actions: [{ id: "a1", description: "拿起商品", start: 0, end: 5 }],
};
const currentUnchanged = {
slices: [
{ id: "s1", name: "拿取", start: 0, end: 10 },
{ id: "s2", name: "放回", start: 10, end: 20 },
],
actions: [{ id: "a1", description: "拿起商品", start: 0, end: 5 }],
};
const bucket = (map, key) => map.get(key) || { red: [], gray: [], skipped: [], old: [] };
test("unchanged workspace keeps every opinion red", () => {
const e = computeReworkEmphasis({
baselines: [baseline],
currentSlices: currentUnchanged.slices,
currentActions: currentUnchanged.actions,
});
assert.equal(e.active, true);
// ADR 0009:整体意见不可见——不计数、不进任何桶(fixture 里的 op-task 被无视)。
assert.equal(e.totalOpinions, 3);
assert.equal(e.unclearedCount, 3);
assert.equal(e.clearedCount, 0);
assert.equal(bucket(e.sliceStates, "s1").red.length, 3); // slice + action + timestamp
assert.equal(bucket(e.actionStates, "a1").red.length, 2);
assert.equal(e.task.red.length, 0);
assert.equal(e.jumpOrder.filter((entry) => entry.opinion.scope === "task").length, 0);
assert.equal(e.markers.length, 1);
assert.equal(e.markers[0].state, "red");
});
test("editing an action marks its slice, action and timestamp opinions modified, not QC resolved", () => {
const actions = [{ id: "a1", description: "拿起商品并扫码", start: 0, end: 5 }];
const e = computeReworkEmphasis({
baselines: [baseline],
currentSlices: currentUnchanged.slices,
currentActions: actions,
});
assert.equal(e.unclearedCount, 0); // 切片内容包含片内动作;这里只表示已修改,质检仍须判定。
assert.equal(bucket(e.actionStates, "a1").red.length, 0);
assert.equal(bucket(e.actionStates, "a1").gray.length, 2); // 动作 + 时间点归属该动作
assert.equal(e.markers[0].state, "gray");
});
test("editing the targeted slice clears slice-scope opinion", () => {
const slices = [
{ id: "s1", name: "取放商品", start: 0, end: 10 },
{ id: "s2", name: "放回", start: 10, end: 20 },
];
const e = computeReworkEmphasis({
baselines: [baseline],
currentSlices: slices,
currentActions: currentUnchanged.actions,
});
assert.equal(bucket(e.sliceStates, "s1").red.length, 2); // 动作 + 时间点仍红
const sliceOpinion = bucket(e.sliceStates, "s1").gray.find((entry) => entry.id === "op-slice");
assert.ok(sliceOpinion, "slice opinion must be gray");
});
test("merged slice reattaches opinions to the surviving slice and stays red until it changes", () => {
// s1 被合并进 s2(s2 扩展覆盖 0–20,s1 消失),存活块内容相对基线已变化 → 视为已处理。
const slices = [{ id: "s2", name: "放回", start: 0, end: 20 }];
const e = computeReworkEmphasis({
baselines: [baseline],
currentSlices: slices,
currentActions: currentUnchanged.actions,
});
const sliceBucket = bucket(e.sliceStates, "s2");
assert.ok(sliceBucket.gray.some((entry) => entry.id === "op-slice" && entry.reattached));
});
test("skip marks persist per opinion and clear red without edits", () => {
const e = computeReworkEmphasis({
baselines: [baseline],
currentSlices: currentUnchanged.slices,
currentActions: currentUnchanged.actions,
skippedOpinionIds: ["op-task", "op-slice"],
});
assert.equal(e.unclearedCount, 2);
assert.equal(e.skippedCount, 1); // op-slice;op-task 不可见不产生跳过态
assert.equal(e.task.red.length, 0);
assert.equal(e.task.skipped.length, 0);
assert.equal(bucket(e.sliceStates, "s1").red.length, 2);
});
test("older rounds render dimmed (old) and never count as uncleared", () => {
const round2 = {
round: 2,
problems: [{ id: "op-2", scope: "slice", sliceId: "s2", text: "第二轮意见" }],
slices: currentUnchanged.slices,
actions: currentUnchanged.actions,
};
const e = computeReworkEmphasis({
baselines: [baseline, round2],
currentSlices: currentUnchanged.slices,
currentActions: currentUnchanged.actions,
});
assert.equal(e.round, 2);
assert.equal(e.unclearedCount, 1); // 只有第二轮
assert.equal(bucket(e.sliceStates, "s2").red.length, 1);
assert.equal(bucket(e.sliceStates, "s1").old.length, 3);
assert.equal(e.task.old.length, 0); // ADR 0009:整体意见不可见
});
test("slice-seconds timestamp converts to absolute using baseline slice start", () => {
const withRelative = {
...baseline,
problems: [
{ id: "op-rel", scope: "timestamp", sliceId: "s2", atSeconds: 2, timeBasis: "slice-seconds", text: "相对时间" },
],
};
const e = computeReworkEmphasis({
baselines: [withRelative],
currentSlices: currentUnchanged.slices,
currentActions: currentUnchanged.actions,
});
assert.equal(e.markers[0].atSeconds, 12);
assert.equal(e.markers[0].state, "red");
});
test("empty input degrades to inactive", () => {
assert.deepEqual(computeReworkEmphasis({ baselines: [] }), emptyReworkEmphasis());
assert.equal(emptyReworkEmphasis().active, false);
});
test("jumpOrder lists all opinions with state: red → skipped → gray, anchor-sorted within group", () => {
// 修改 a1 描述 → op-action/op-ts 变 gray;跳过 op-slice。
// ADR 0009:整体意见不进跳转序。
const actions = [{ id: "a1", description: "拿起商品并扫码", start: 0, end: 5 }];
const e = computeReworkEmphasis({
baselines: [baseline],
currentSlices: currentUnchanged.slices,
currentActions: actions,
skippedOpinionIds: ["op-slice"],
});
assert.deepEqual(
e.jumpOrder.map((entry) => entry.opinion.id),
["op-slice", "op-action", "op-ts"],
);
assert.deepEqual(
e.jumpOrder.map((entry) => entry.state),
["skipped", "gray", "gray"],
);
});
test("regression: editing slice taskLabelId clears the slice opinion (was missing from key)", () => {
const slices = [
{ id: "s1", name: "拿取", start: 0, end: 10, taskLabelId: "tl-9" },
{ id: "s2", name: "放回", start: 10, end: 20 },
];
const e = computeReworkEmphasis({
baselines: [baseline],
currentSlices: slices,
currentActions: currentUnchanged.actions,
});
assert.ok(bucket(e.sliceStates, "s1").gray.some((entry) => entry.id === "op-slice"));
});
test("regression: editing action labelId or handedness clears the action opinion (was missing from key)", () => {
for (const mutate of [(action) => ({ ...action, labelId: "L2" }), (action) => ({ ...action, handedness: "left" })]) {
const actions = [mutate({ id: "a1", description: "拿起商品", start: 0, end: 5 })];
const e = computeReworkEmphasis({
baselines: [baseline],
currentSlices: currentUnchanged.slices,
currentActions: actions,
});
assert.equal(bucket(e.actionStates, "a1").gray.length, 2); // 动作 + 其时间点
assert.equal(bucket(e.actionStates, "a1").red.length, 0);
}
});
test("ADR 0009: task-scope opinions are invisible in every projection", () => {
// 不派生红/灰、不计数、不进跳转序——无论工作区是否改动、是否被标"不改"。
const only = { ...baseline, problems: [{ id: "op-task", scope: "task", text: "整体偏暗" }] };
for (const actions of [currentUnchanged.actions, [{ id: "a1", description: "拿起商品并贴签", start: 0, end: 5 }]]) {
const e = computeReworkEmphasis({
baselines: [only],
currentSlices: currentUnchanged.slices,
currentActions: actions,
});
assert.equal(e.totalOpinions, 0);
assert.equal(e.unclearedCount, 0);
assert.equal(e.jumpOrder.length, 0);
assert.deepEqual(e.task, { red: [], gray: [], skipped: [], old: [] });
}
const skipped = computeReworkEmphasis({
baselines: [only],
currentSlices: currentUnchanged.slices,
currentActions: currentUnchanged.actions,
skippedOpinionIds: ["op-task"],
});
assert.equal(skipped.skippedCount, 0);
assert.deepEqual(skipped.task, { red: [], gray: [], skipped: [], old: [] });
});
test("nextReworkJump wraps around the full sequence", () => {
const e = computeReworkEmphasis({
baselines: [baseline],
currentSlices: currentUnchanged.slices,
currentActions: currentUnchanged.actions,
});
const last = nextReworkJump(e, e.jumpOrder.length - 1, 1);
assert.equal(last.index, 0);
const prev = nextReworkJump(e, 0, -1);
assert.equal(prev.index, e.jumpOrder.length - 1);
});
test("older-round opinions keep state old and sort after current round", () => {
const round2 = {
round: 2,
problems: [{ id: "op2-slice", scope: "slice", sliceId: "s2", text: "第二轮切片意见" }],
slices: currentUnchanged.slices,
actions: currentUnchanged.actions,
};
const e = computeReworkEmphasis({
baselines: [baseline, round2],
currentSlices: currentUnchanged.slices,
currentActions: currentUnchanged.actions,
});
assert.equal(e.round, 2);
assert.equal(e.jumpOrder[0].opinion.id, "op2-slice");
assert.equal(e.jumpOrder[0].state, "red");
const oldIds = e.jumpOrder.filter((entry) => entry.state === "old").map((entry) => entry.opinion.id);
assert.equal(oldIds.length, 3); // 第一轮局部意见全部转历史(整体意见不可见)
assert.equal(e.jumpOrder[e.jumpOrder.length - 1].state, "old");
});
test("gate list still derivable: red-only filter over jumpOrder equals unclearedCount", () => {
const actions = [{ id: "a1", description: "拿起商品并扫码", start: 0, end: 5 }];
const e = computeReworkEmphasis({
baselines: [baseline],
currentSlices: currentUnchanged.slices,
currentActions: actions,
skippedOpinionIds: ["op-slice"],
});
assert.equal(e.jumpOrder.filter((entry) => entry.state === "red").length, e.unclearedCount);
});
test("reworkSubtitleRows: empty/null bucket yields no rows", () => {
assert.deepEqual(reworkSubtitleRows(null), []);
assert.deepEqual(reworkSubtitleRows({ red: [], gray: [], skipped: [], old: [] }), []);
});
test("reworkSubtitleRows: groups a slice bucket into slice/action/timestamp rows in order", () => {
const e = computeReworkEmphasis({
baselines: [baseline],
currentSlices: currentUnchanged.slices,
currentActions: currentUnchanged.actions,
});
// 字幕跟播放头:播放头在 a1(0–5s)上,动作/时间点排显示 a1 的意见。
const rows = reworkSubtitleRows(e.sliceStates.get("s1"), { actionId: "a1" });
assert.equal(rows.length, 3);
assert.deepEqual(
rows.map((row) => row.kind),
["slice", "action", "timestamp"],
);
assert.equal(rows[0].items.length, 1);
assert.equal(rows[0].items[0].state, "red");
assert.equal(rows[0].items[0].text, "切片命名错误");
// 时间点排保留秒数,供字幕显示 "2.50s …"
const ts = rows[2].items[0];
assert.equal(ts.atSeconds, 2.5);
assert.equal(ts.state, "red");
});
test("reworkSubtitleRows: rows follow the playhead action — other actions' opinions hidden", () => {
const multi = {
round: 1,
problems: [
{ id: "op-slice", scope: "slice", sliceId: "s1", text: "切片命名错误" },
{ id: "op-a1", scope: "action", sliceId: "s1", actionId: "a1", text: "a1 描述错误" },
{ id: "op-a2", scope: "action", sliceId: "s1", actionId: "a2", text: "a2 类别错误" },
// 9s 不被任何动作覆盖 → 孤儿时间点意见,随切片显示
{
id: "op-orphan",
scope: "timestamp",
sliceId: "s1",
atSeconds: 9,
timeBasis: "capture-seconds",
text: "画面问题",
},
],
slices: [{ id: "s1", name: "拿取", start: 0, end: 10 }],
actions: [
{ id: "a1", description: "拿起商品", start: 0, end: 5 },
{ id: "a2", description: "放回商品", start: 5, end: 8 },
],
};
const e = computeReworkEmphasis({ baselines: [multi], currentSlices: multi.slices, currentActions: multi.actions });
// 播放头在 a1:只看到 a1 的意见 + 孤儿时间点
const atA1 = reworkSubtitleRows(e.sliceStates.get("s1"), { actionId: "a1" });
assert.deepEqual(
atA1.map((row) => row.kind),
["slice", "action", "timestamp"],
);
assert.deepEqual(
atA1[1].items.map((item) => item.id),
["op-a1"],
);
assert.deepEqual(
atA1[2].items.map((item) => item.id),
["op-orphan"],
);
// 播放头在 a2:动作排切换为 a2 的意见
const atA2 = reworkSubtitleRows(e.sliceStates.get("s1"), { actionId: "a2" });
assert.deepEqual(
atA2[1].items.map((item) => item.id),
["op-a2"],
);
assert.deepEqual(
atA2[2].items.map((item) => item.id),
["op-orphan"],
);
// 播放头在动作间隙(无当前动作):只剩切片排 + 孤儿时间点
const atGap = reworkSubtitleRows(e.sliceStates.get("s1"), { actionId: null });
assert.deepEqual(
atGap.map((row) => row.kind),
["slice", "timestamp"],
);
// 播放头不在任何切片:整层隐藏(bucket 取不到)
assert.deepEqual(reworkSubtitleRows(e.sliceStates.get("nope"), { actionId: "a1" }), []);
});
test("reworkSubtitleRows: handled opinions fade — red stays first, others join same rows", () => {
const actions = [{ id: "a1", description: "拿起商品并扫码", start: 0, end: 5 }];
const e = computeReworkEmphasis({
baselines: [baseline],
currentSlices: currentUnchanged.slices,
currentActions: actions,
skippedOpinionIds: ["op-slice"],
});
const rows = reworkSubtitleRows(e.sliceStates.get("s1"), { actionId: "a1" });
const sliceRow = rows.find((row) => row.kind === "slice");
assert.equal(sliceRow.items[0].id, "op-slice");
assert.equal(sliceRow.items[0].state, "skipped");
const actionRow = rows.find((row) => row.kind === "action");
assert.equal(actionRow.items[0].state, "gray");
const timestampRow = rows.find((row) => row.kind === "timestamp");
// 时间点意见归属 a1(0–5s):动作描述改了,它随归属动作一起消红。
assert.equal(timestampRow.items[0].state, "gray");
});
test("reworkSubtitleRows: omits empty rows and never includes task-scope opinions", () => {
const only = { ...baseline, problems: [{ id: "op-task", scope: "task", text: "整体偏暗" }] };
const e = computeReworkEmphasis({
baselines: [only],
currentSlices: currentUnchanged.slices,
currentActions: currentUnchanged.actions,
});
assert.deepEqual(reworkSubtitleRows(e.sliceStates.get("s1")), []);
// 手工桶防御:task 意见即便混入桶也不上字幕。
const polluted = { red: [{ id: "x", scope: "task", text: "整体" }], gray: [], skipped: [], old: [] };
assert.deepEqual(reworkSubtitleRows(polluted), []);
});
// —— 票 04:意见跟块消红扩展到切片结构变化(合并/拆分/舍弃,spec §3.3、Q5:a / R2-Q4:a)——
// 拆分布局:s1(0-10) 拆成 s1a(0-5) + s1b(5-10),s2 不动;a1 完整落入 s1a。
const splitSlices = (keepIdOnRight = false) =>
keepIdOnRight
? [
{ id: "s1a", name: "拿取", start: 0, end: 5 },
{ id: "s1", name: "拿取", start: 5, end: 10 },
{ id: "s2", name: "放回", start: 10, end: 20 },
]
: [
{ id: "s1a", name: "拿取", start: 0, end: 5 },
{ id: "s1b", name: "拿取", start: 5, end: 10 },
{ id: "s2", name: "放回", start: 10, end: 20 },
];
test("slice merge: three-level opinions all follow to the new block (task hidden per ADR 0009)", () => {
// s1 被合并进 s2(s2 扩展覆盖 0–20,s1 消失)。
const slices = [{ id: "s2", name: "放回", start: 0, end: 20 }];
const e = computeReworkEmphasis({ baselines: [baseline], currentSlices: slices, currentActions: baseline.actions });
// 切片级:跟到新块 s2,被审内容已不存在 → 已处理(灰)且标记跟块。
const sliceOpinion = bucket(e.sliceStates, "s2").gray.find((entry) => entry.id === "op-slice");
assert.ok(sliceOpinion, "slice opinion must land on the merged block as gray");
assert.ok(sliceOpinion.reattached);
// 动作级:动作未动仍红(时间点意见也随归属动作仍红),但按时间包含自动落到新块(sliceStates s2 桶)。
assert.ok(bucket(e.actionStates, "a1").red.some((entry) => entry.id === "op-action"));
assert.ok(bucket(e.sliceStates, "s2").red.some((entry) => entry.id === "op-action"));
// 时间点级:归属动作未动仍红,展示落点跟到新块。
assert.equal(e.markers[0].state, "red");
assert.equal(e.markers[0].sliceId, "s2");
// 整体级:ADR 0009 停用——不可见、不保持红。
assert.equal(e.task.red.length, 0);
});
test("slice split: slice-scope opinion follows the new piece containing its time footprint", () => {
// 两条切片级意见的足迹分别在两半 → 各自跟到所在的新片(R1-Q5:a)。
const split = {
...baseline,
problems: [
{
id: "op-left",
scope: "slice",
sliceId: "s1",
atSeconds: 2.5,
timeBasis: "capture-seconds",
text: "左半命名错误",
},
{
id: "op-right",
scope: "slice",
sliceId: "s1",
atSeconds: 7.5,
timeBasis: "capture-seconds",
text: "右半命名错误",
},
],
};
const e = computeReworkEmphasis({
baselines: [split],
currentSlices: splitSlices(),
currentActions: baseline.actions,
});
assert.ok(bucket(e.sliceStates, "s1a").gray.some((entry) => entry.id === "op-left" && entry.reattached));
assert.ok(bucket(e.sliceStates, "s1b").gray.some((entry) => entry.id === "op-right" && entry.reattached));
// 足迹所在片之外的半片不再挂这条意见。
assert.ok(!bucket(e.sliceStates, "s1b").gray.some((entry) => entry.id === "op-left"));
assert.ok(!bucket(e.sliceStates, "s1a").gray.some((entry) => entry.id === "op-right"));
});
test("slice split: footprint binding wins over the surviving id (opinion is about the time region, not the id)", () => {
// 拆分后原 id 留在右半:足迹在左半的意见仍归左半新片。
const split = {
...baseline,
problems: [
{
id: "op-left",
scope: "slice",
sliceId: "s1",
atSeconds: 2.5,
timeBasis: "capture-seconds",
text: "左半命名错误",
},
],
};
const e = computeReworkEmphasis({
baselines: [split],
currentSlices: splitSlices(true),
currentActions: baseline.actions,
});
assert.ok(bucket(e.sliceStates, "s1a").gray.some((entry) => entry.id === "op-left" && entry.reattached));
assert.ok(!bucket(e.sliceStates, "s1").gray.some((entry) => entry.id === "op-left"));
});
test("slice split without recorded anchor falls back to the audited slice's start", () => {
// 老数据的切片级意见没有 atSeconds:足迹回退到被审切片起点 → 跟到包含起点的新片。
const split = { ...baseline, problems: [{ id: "op-slice", scope: "slice", sliceId: "s1", text: "切片命名错误" }] };
const e = computeReworkEmphasis({
baselines: [split],
currentSlices: splitSlices(),
currentActions: baseline.actions,
});
assert.ok(bucket(e.sliceStates, "s1a").gray.some((entry) => entry.id === "op-slice" && entry.reattached));
});
test("footprint start exactly on the split line goes to the new piece that starts at the line", () => {
// 拆分线 5s:切片级与时间点级意见的足迹起点都恰在线上 → 归以 5 为起点的右半 s1b。
// a1 收窄到 4.5 结束,避免动作归属干扰纯线点判定。
const onLine = {
...baseline,
problems: [
{
id: "op-slice-line",
scope: "slice",
sliceId: "s1",
atSeconds: 5,
timeBasis: "capture-seconds",
text: "线上切片意见",
},
{
id: "op-ts-line",
scope: "timestamp",
sliceId: "s1",
atSeconds: 5,
timeBasis: "capture-seconds",
text: "线上时间点意见",
},
],
actions: [{ id: "a1", description: "拿起商品", start: 0, end: 4.5 }],
};
const e = computeReworkEmphasis({
baselines: [onLine],
currentSlices: splitSlices(),
currentActions: onLine.actions,
});
const sliceOpinion = bucket(e.sliceStates, "s1b").gray.find((entry) => entry.id === "op-slice-line");
assert.ok(sliceOpinion && sliceOpinion.reattached, "on-line slice opinion must land on the right piece");
assert.ok(!bucket(e.sliceStates, "s1a").gray.some((entry) => entry.id === "op-slice-line"));
assert.equal(e.markers.find((marker) => marker.id === "op-ts-line").sliceId, "s1b");
// 归属切片被拆、被审内容已不存在 → 已处理。
assert.equal(e.markers.find((marker) => marker.id === "op-ts-line").state, "gray");
});
test("discarding the slice auto-processes every opinion on it; restoring brings all back to red", () => {
const discardBase = {
...baseline,
slices: [
{ id: "s1", name: "拿取", start: 0, end: 10, deliveryDisposition: "keep" },
{ id: "s2", name: "放回", start: 10, end: 20, deliveryDisposition: "keep" },
],
};
const discardedSlices = [
{ id: "s1", name: "拿取", start: 0, end: 10, deliveryDisposition: "discard", discardReason: "镜头被遮挡" },
{ id: "s2", name: "放回", start: 10, end: 20, deliveryDisposition: "keep" },
];
// 动作记录本身未改动(无 status 字段)——"舍弃片下动作全部转无效"由纯函数按域规则推导。
const e = computeReworkEmphasis({
baselines: [discardBase],
currentSlices: discardedSlices,
currentActions: baseline.actions,
});
assert.equal(e.unclearedCount, 0, "discard clears the whole slice's opinions");
// 三级各自判定:切片级 / 动作级(推导无效 → 已处理)/ 时间点级(归属动作推导无效)。
assert.ok(bucket(e.sliceStates, "s1").gray.some((entry) => entry.id === "op-slice"));
assert.ok(bucket(e.actionStates, "a1").gray.some((entry) => entry.id === "op-action"));
assert.equal(e.markers[0].state, "gray");
// 整体级:ADR 0009 停用——不可见、不参与判定。
assert.equal(e.task.gray.length, 0);
assert.equal(e.task.red.length, 0);
// 恢复舍弃:意见回到未处理。
const restored = computeReworkEmphasis({
baselines: [discardBase],
currentSlices: discardBase.slices,
currentActions: baseline.actions,
});
assert.equal(restored.unclearedCount, 3); // 局部意见回到未处理(整体意见不可见)
assert.equal(bucket(restored.sliceStates, "s1").red.length, 3);
assert.equal(restored.task.red.length, 0);
});
test("multi-round: round-2 stays red while restructured round-1 opinions follow their blocks as dimmed old", () => {
const round1 = {
...baseline,
problems: [
{
id: "op-slice",
scope: "slice",
sliceId: "s1",
atSeconds: 7.5,
timeBasis: "capture-seconds",
text: "切片命名错误",
},
{ id: "op-task", scope: "task", text: "整体偏暗" },
],
};
const round2 = {
round: 2,
problems: [{ id: "op2-slice", scope: "slice", sliceId: "s2", text: "第二轮意见" }],
slices: baseline.slices,
actions: baseline.actions,
};
const e = computeReworkEmphasis({
baselines: [round1, round2],
currentSlices: splitSlices(),
currentActions: baseline.actions,
});
assert.equal(e.round, 2);
assert.equal(e.unclearedCount, 1);
// 第 2 轮:目标未动 → 红。
assert.ok(bucket(e.sliceStates, "s2").red.some((entry) => entry.id === "op2-slice"));
// 第 1 轮:全部转历史灰显,切片意见按足迹(7.5s)跟到右半 s1b。
assert.ok(bucket(e.sliceStates, "s1b").old.some((entry) => entry.id === "op-slice" && entry.reattached));
assert.equal(e.task.old.length, 0); // ADR 0009:整体意见不可见
// 导航序:红在前、历史轮在后。
assert.deepEqual(
e.jumpOrder.map((entry) => entry.state),
["red", "old"],
);
});
// ---- reworkLocatePlan(票 slice-edit-ux-rework 02 · I1 键盘/点击路径对齐)----
// 定位决策共用输入:当前选中 s1;意见锚定 a2(几何归属 s2)。
const locateSlices = [
{ id: "s1", name: "拿取", start: 0, end: 10 },
{ id: "s2", name: "放回", start: 10, end: 20 },
];
const locateActions = [
{ id: "a1", description: "拿起商品", start: 0, end: 5 },
{ id: "a2", description: "放回商品", start: 12, end: 18 },
];
const locateBase = {
selectedSliceId: "s1",
slices: locateSlices,
segments: locateActions,
};
test("reworkLocatePlan: jump cross-slice to action-anchored opinion selects owner slice and opens anchored editor", () => {
const plan = reworkLocatePlan({
...locateBase,
mode: "jump",
opinion: { id: "op-a2", scope: "action", sliceId: "s2", actionId: "a2", atSeconds: 12 },
anchor: 12,
});
assert.equal(plan.kind, "select");
assert.equal(plan.slice.id, "s2");
assert.equal(plan.time, 12);
assert.equal(plan.openActionId, "a2");
});
test("reworkLocatePlan: click path mirrors jump cross-slice (same select+open plan) and opens editor same-slice", () => {
const clickCross = reworkLocatePlan({
...locateBase,
mode: "click",
opinion: { id: "op-a2", scope: "action", sliceId: "s2", actionId: "a2", atSeconds: 12 },
anchor: 12,
});
assert.deepEqual(
{ ...clickCross, slice: clickCross.slice.id },
{ kind: "select", slice: "s2", time: 12, openActionId: "a2" },
);
// 同片点击(既有行为保持):直接点开锚定动作编辑器。
const clickSame = reworkLocatePlan({
...locateBase,
mode: "click",
opinion: { id: "op-a1", scope: "action", sliceId: "s1", actionId: "a1", atSeconds: 1 },
anchor: 1,
});
assert.deepEqual({ ...clickSame, segment: clickSame.segment.id }, { kind: "annotate", segment: "a1", time: 0 });
});
test("reworkLocatePlan: discarded owner slice or parked draft keeps openActionId null (read-only / draft preserved)", () => {
const discardedSlices = [
{ id: "s1", name: "拿取", start: 0, end: 10 },
{ id: "s2", name: "放回", start: 10, end: 20, deliveryDisposition: "discard" },
];
const opinion = { id: "op-a2", scope: "action", sliceId: "s2", actionId: "a2", atSeconds: 12 };
const onDiscarded = reworkLocatePlan({
...locateBase,
slices: discardedSlices,
mode: "jump",
opinion,
anchor: 12,
});
assert.equal(onDiscarded.kind, "select");
assert.equal(onDiscarded.slice.id, "s2");
assert.equal(onDiscarded.openActionId, null);
// 目标片有停泊编辑器(未保存草稿):跳转不覆盖,交回 selectSlice 恢复。
const withParked = reworkLocatePlan({
...locateBase,
mode: "jump",
opinion,
anchor: 12,
parkedAnnotationBySlice: { s2: "a2" },
});
assert.equal(withParked.kind, "select");
assert.equal(withParked.openActionId, null);
});
test("reworkLocatePlan: preserved fallbacks — same-slice jump seeks only; slice/timestamp/task opinions keep legacy branches", () => {
// 同片 J/K(锚定动作在当前片):只 seek 不重开面板(现状保持);
// D6 后跳转计划统一带 sliceEdit 意图(非切片问题 → "close" 收起面板)。
const jumpSame = reworkLocatePlan({
...locateBase,
mode: "jump",
opinion: { id: "op-a1", scope: "action", sliceId: "s1", actionId: "a1", atSeconds: 3 },
anchor: 3,
});
assert.deepEqual(jumpSame, { kind: "seek", time: 3, sliceEdit: "close" });
// 切片意见跨片:select,时间退回 atSeconds ?? slice.start。
const sliceOpinion = reworkLocatePlan({
...locateBase,
mode: "jump",
opinion: { id: "op-s2", scope: "slice", sliceId: "s2", text: "…" },
anchor: 15,
});
assert.deepEqual(
{ ...sliceOpinion, slice: sliceOpinion.slice.id },
{ kind: "select", slice: "s2", time: 15, openActionId: null, sliceEdit: { sliceId: "s2" } },
);
const sliceNoAnchor = reworkLocatePlan({
...locateBase,
mode: "click",
opinion: { id: "op-s2", scope: "slice", sliceId: "s2", text: "…" },
anchor: null,
});
assert.equal(sliceNoAnchor.time, 10);
// 锚定动作已被删除:退回切片分支(跳转不再指向已删动作)。
const deletedAction = reworkLocatePlan({
...locateBase,
mode: "jump",
opinion: { id: "op-gone", scope: "action", sliceId: "s2", actionId: "aX", atSeconds: 14 },
anchor: 14,
});
assert.deepEqual(
{ ...deletedAction, slice: deletedAction.slice.id },
{ kind: "select", slice: "s2", time: 14, openActionId: null, sliceEdit: "close" },
);
// 整体意见(无锚点无切片):只设焦点,不动进度条。
const taskOpinion = reworkLocatePlan({
...locateBase,
mode: "jump",
opinion: { id: "op-task", scope: "task", text: "…" },
anchor: -1,
});
assert.deepEqual(taskOpinion, { kind: "seek", time: null, sliceEdit: "close" });
});
// ---- reworkLocatePlan 面板联动意图(rework-ux-adjust 04 · D6)----
// J/K 落切片问题 → { sliceId }(自动打开/切换 E 面板目标,目标须为当前工作区存活
// 切片);落动作/时间点/整体问题 → "close"(收起面板,未应用改动由工作台驻留)。
// 点击路径不带意图(面板交互现状不变)。
test("reworkLocatePlan: jump to slice-scope opinion carries open-panel intent (cross-slice and same-slice)", () => {
const cross = reworkLocatePlan({
...locateBase,
mode: "jump",
opinion: { id: "op-s2", scope: "slice", sliceId: "s2", text: "边界不对" },
anchor: 15,
});
assert.equal(cross.kind, "select");
assert.equal(cross.sliceEdit.sliceId, "s2");
const same = reworkLocatePlan({
...locateBase,
mode: "jump",
opinion: { id: "op-s1", scope: "slice", sliceId: "s1", text: "边界不对" },
anchor: 5,
});
assert.deepEqual(same, { kind: "seek", time: 5, sliceEdit: { sliceId: "s1" } });
// 无锚点时间退回目标片 start,意图仍指向该切片。
const noAnchor = reworkLocatePlan({
...locateBase,
mode: "jump",
opinion: { id: "op-s2", scope: "slice", sliceId: "s2", text: "…" },
anchor: null,
});
assert.deepEqual(
{ ...noAnchor, slice: noAnchor.slice.id },
{ kind: "select", slice: "s2", time: 10, openActionId: null, sliceEdit: { sliceId: "s2" } },
);
// 目标切片不在当前工作区(合并/删除后无落点):不开面板,按非切片问题收起。
const gone = reworkLocatePlan({
...locateBase,
mode: "jump",
opinion: { id: "op-x", scope: "slice", sliceId: "sx", text: "…" },
anchor: 3,
});
assert.deepEqual(gone, { kind: "seek", time: 3, sliceEdit: "close" });
});
test("reworkLocatePlan: jump to non-slice problems carries close intent; click path carries none", () => {
// 时间点问题(同片):只 seek,收起面板意图。
const timestamp = reworkLocatePlan({
...locateBase,
mode: "jump",
opinion: { id: "op-t1", scope: "timestamp", atSeconds: 3 },
anchor: 3,
});
assert.deepEqual(timestamp, { kind: "seek", time: 3, sliceEdit: "close" });
// 跨片动作问题:select 计划同样带 close(切选后收起面板、打开动作编辑器)。
const crossAction = reworkLocatePlan({
...locateBase,
mode: "jump",
opinion: { id: "op-a2", scope: "action", sliceId: "s2", actionId: "a2", atSeconds: 12 },
anchor: 12,
});
assert.equal(crossAction.sliceEdit, "close");
// 点击路径:计划不带 sliceEdit 字段(面板交互现状不变)。
const clickSame = reworkLocatePlan({
...locateBase,
mode: "click",
opinion: { id: "op-a1", scope: "action", sliceId: "s1", actionId: "a1", atSeconds: 1 },
anchor: 1,
});
assert.deepEqual({ ...clickSame, segment: clickSame.segment.id }, { kind: "annotate", segment: "a1", time: 0 });
const clickSlice = reworkLocatePlan({
...locateBase,
mode: "click",
opinion: { id: "op-s2", scope: "slice", sliceId: "s2", text: "…" },
anchor: 15,
});
assert.equal(clickSlice.sliceEdit, undefined);
});