forked from longtao.wu/droboticflow
- mergeDegenerateProducts: straddle pieces within EPS merge into a same-status neighbour (coverage unchanged) so degenerate boundary structures can no longer persist invisible zero-width segments that intervalStyle renders as display:none - scanSliceEditConflicts now returns autoFollows (silently-following edge-glued invalid actions) + conflictAutoFollowHint derivation for the collapsed conflict-list hint row (panel and drag quick paths) - invalid track blocks get a min-width visibility marker so needle-width invalid intervals stay visible on the track - 5 new engine tests (guard x3, autoFollows, hint); workbench source guards updated to pin the corrected wiring; repro record updated with post-fix matrix
663 lines
26 KiB
JavaScript
663 lines
26 KiB
JavaScript
import assert from "node:assert/strict";
|
||
import test from "node:test";
|
||
import {
|
||
resolveSliceEditConflicts,
|
||
scanSliceEditConflicts,
|
||
conflictAutoFollowHint,
|
||
} from "../../src/lib/slice-edit-conflict.js";
|
||
|
||
// —— 票 03:几何引擎——残段显式化与冲突解析(spec §2 R2-Q1/R2-Q2/R3-Q1、§4 seam ①)——
|
||
//
|
||
// 基础夹具:基线两片共享边界 180,预览把边界挪到 185;Q[183,190] 完整落在基线右片
|
||
// 且被新边界穿过(票面 T1 场景:判无效后"缺一块"的原始几何)。
|
||
|
||
const cutBaseSlices = [
|
||
{ id: "s1", name: "拿取", start: 170, end: 180 },
|
||
{ id: "s2", name: "放回", start: 180, end: 200 },
|
||
];
|
||
const cutPendingSlices = [
|
||
{ id: "s1", name: "拿取", start: 170, end: 185 },
|
||
{ id: "s2", name: "放回", start: 185, end: 200 },
|
||
];
|
||
const straddledAction = {
|
||
id: "q1",
|
||
label: "取放",
|
||
labelId: "L1",
|
||
description: "取放商品",
|
||
start: 183,
|
||
end: 190,
|
||
status: "described",
|
||
};
|
||
|
||
test("straddled scan: one entry with cuts geometry, three choices and truncate default", () => {
|
||
const scan = scanSliceEditConflicts({
|
||
baseSlices: cutBaseSlices,
|
||
pendingSlices: cutPendingSlices,
|
||
actions: [straddledAction],
|
||
});
|
||
assert.equal(scan.clean, false);
|
||
assert.equal(scan.entries.length, 1);
|
||
const entry = scan.entries[0];
|
||
assert.equal(entry.id, "q1");
|
||
assert.equal(entry.actionId, "q1");
|
||
assert.equal(entry.kind, "straddled");
|
||
assert.deepEqual(entry.relation, { start: 183, end: 190, cuts: [185] });
|
||
assert.deepEqual(entry.choices, ["truncate", "move", "invalidate"]);
|
||
assert.equal(entry.defaultChoice, "truncate");
|
||
});
|
||
|
||
test("T1 pin: invalidate converts the whole straddled span to invalid pieces — no residue evaporates", () => {
|
||
const done = resolveSliceEditConflicts({
|
||
baseSlices: cutBaseSlices,
|
||
pendingSlices: cutPendingSlices,
|
||
actions: [straddledAction],
|
||
choices: { q1: "invalidate" },
|
||
});
|
||
assert.equal(done.effective, true);
|
||
assert.deepEqual(
|
||
done.actions.map((piece) => [piece.start, piece.end, piece.status, piece.isInvalid]),
|
||
[
|
||
[183, 185, "invalid", true],
|
||
[185, 190, "invalid", true],
|
||
],
|
||
);
|
||
// R3-Q1:自动无效段与手工无效动作完全同形——手工保存路径的字段形状,
|
||
// 不带任何"系统生成"标记。
|
||
for (const piece of done.actions) {
|
||
assert.equal(piece.description, "无效片段");
|
||
assert.equal(piece.label, "无效片段");
|
||
assert.equal(piece.labelId, "");
|
||
}
|
||
// 处置审计:供 04/05 撤销与 QC 结构摘要横幅复用。
|
||
assert.equal(done.applied.length, 1);
|
||
assert.equal(done.applied[0].actionId, "q1");
|
||
assert.equal(done.applied[0].kind, "straddled");
|
||
assert.equal(done.applied[0].choice, "invalidate");
|
||
});
|
||
|
||
test("truncate keeps both pieces with original status and family-style split ids, replaced in place", () => {
|
||
// before/after 刻意不贴旧边界(避免卷入贴边跟随,本测只钉跨界原位替换)。
|
||
const before = { id: "p0", label: "前置", description: "前置动作", start: 170, end: 179, status: "described" };
|
||
const after = { id: "p9", label: "后置", description: "后置动作", start: 190, end: 200, status: "described" };
|
||
const done = resolveSliceEditConflicts({
|
||
baseSlices: cutBaseSlices,
|
||
pendingSlices: cutPendingSlices,
|
||
actions: [before, straddledAction, after],
|
||
choices: { q1: "truncate" },
|
||
});
|
||
assert.equal(done.effective, true);
|
||
assert.deepEqual(
|
||
done.actions.map((piece) => piece.id),
|
||
["p0", "q1:split:185.000000:a", "q1:split:185.000000:b", "p9"],
|
||
);
|
||
assert.deepEqual(
|
||
done.actions.map((piece) => [piece.start, piece.end, piece.status]),
|
||
[
|
||
[170, 179, "described"],
|
||
[183, 185, "described"],
|
||
[185, 190, "described"],
|
||
[190, 200, "described"],
|
||
],
|
||
);
|
||
// 未受影响动作原引用保留(零拷贝),受影响动作原位替换。
|
||
assert.equal(done.actions[0], before);
|
||
assert.equal(done.actions[3], after);
|
||
});
|
||
|
||
test("move keeps the piece in the other slice (bare id) and materializes the vacated home span as an invalid segment", () => {
|
||
// Q[183,190] 原归属右片 s2(旧边界 180);边界右移到 185 → 挪片 = 动作迁入长大的
|
||
// 左片:保留落进 s1 的 [183,185],让出的原片空当 [185,190] 自动生成无效段(R2-Q1)。
|
||
const done = resolveSliceEditConflicts({
|
||
baseSlices: cutBaseSlices,
|
||
pendingSlices: cutPendingSlices,
|
||
actions: [straddledAction],
|
||
choices: { q1: "move" },
|
||
});
|
||
assert.equal(done.effective, true);
|
||
assert.deepEqual(
|
||
done.actions.map((piece) => [piece.id, piece.start, piece.end, piece.status]),
|
||
[
|
||
["q1", 183, 185, "described"],
|
||
["q1:gap:185.000000", 185, 190, "invalid"],
|
||
],
|
||
);
|
||
assert.equal(done.actions[0].isInvalid, undefined); // 迁入段仍是有效动作(未携带无效标记)
|
||
assert.equal(done.actions[1].isInvalid, true);
|
||
// 空当无效段与手工无效动作完全同形(R2-Q1:可再编辑/撤销,R3-Q1:无系统标记)。
|
||
const gap = done.actions[1];
|
||
assert.equal(gap.description, "无效片段");
|
||
assert.equal(gap.label, "无效片段");
|
||
assert.equal(gap.labelId, "");
|
||
});
|
||
|
||
test("clean scan: boundary move with no affected actions resolves immediately and changes nothing", () => {
|
||
const idle = { id: "w0", label: "闲", description: "闲动作", start: 188, end: 192, status: "described" };
|
||
const scan = scanSliceEditConflicts({ baseSlices: cutBaseSlices, pendingSlices: cutPendingSlices, actions: [idle] });
|
||
assert.equal(scan.clean, true);
|
||
assert.deepEqual(scan.entries, []);
|
||
const done = resolveSliceEditConflicts({
|
||
baseSlices: cutBaseSlices,
|
||
pendingSlices: cutPendingSlices,
|
||
actions: [idle],
|
||
});
|
||
assert.equal(done.effective, true);
|
||
assert.equal(done.actions[0], idle);
|
||
assert.equal(done.applied.length, 0);
|
||
// 结构照预览原样返回(同引用)——04/05 直接落库。
|
||
assert.equal(done.slices, cutPendingSlices);
|
||
});
|
||
|
||
// —— 贴边(只贴不穿)与 T2 钉死 ——
|
||
//
|
||
// 基础夹具:边界 5 → 7;v 贴在旧边界 5 上(end=5),w 从 5 铺满右片(跨界)。
|
||
|
||
const glueBaseSlices = [
|
||
{ id: "g1", name: "左片", start: 0, end: 5 },
|
||
{ id: "g2", name: "右片", start: 5, end: 10 },
|
||
];
|
||
const gluePendingSlices = [
|
||
{ id: "g1", name: "左片", start: 0, end: 7 },
|
||
{ id: "g2", name: "右片", start: 7, end: 10 },
|
||
];
|
||
const gluedInvalid = {
|
||
id: "v1",
|
||
label: "无效片段",
|
||
description: "无效片段",
|
||
start: 0,
|
||
end: 5,
|
||
status: "invalid",
|
||
isInvalid: true,
|
||
};
|
||
const gluedValid = { id: "v1", label: "拿起", description: "拿起商品", start: 0, end: 5, status: "described" };
|
||
const tiledRight = { id: "w1", label: "放回", description: "放回商品", start: 5, end: 10, status: "described" };
|
||
const farAction = { id: "f1", label: "远处", description: "远处动作", start: 8, end: 10, status: "described" };
|
||
|
||
test("glued invalid action auto-follows the stretch without becoming an entry", () => {
|
||
const scan = scanSliceEditConflicts({
|
||
baseSlices: glueBaseSlices,
|
||
pendingSlices: gluePendingSlices,
|
||
actions: [gluedInvalid, farAction],
|
||
});
|
||
// 区间语义:无效动作自动跟随伸缩,不进清单(零拍板成本)。
|
||
assert.equal(scan.clean, true);
|
||
assert.deepEqual(scan.entries, []);
|
||
const done = resolveSliceEditConflicts({
|
||
baseSlices: glueBaseSlices,
|
||
pendingSlices: gluePendingSlices,
|
||
actions: [gluedInvalid, farAction],
|
||
});
|
||
assert.equal(done.effective, true);
|
||
assert.deepEqual(
|
||
done.actions.map((piece) => [piece.id, piece.start, piece.end, piece.status]),
|
||
[
|
||
["v1", 0, 7, "invalid"],
|
||
["f1", 8, 10, "described"],
|
||
],
|
||
);
|
||
// 自动跟随仍留处置审计(choice=follow, auto=true),供撤销与摘要横幅追溯。
|
||
assert.equal(done.applied.length, 1);
|
||
assert.deepEqual(
|
||
{ ...done.applied[0], products: undefined },
|
||
{ actionId: "v1", kind: "edge-glued", choice: "follow", auto: true, defaulted: false, products: undefined },
|
||
);
|
||
});
|
||
|
||
test("glued valid action becomes a two-choice entry: follow is the default, keep preserves the boundary", () => {
|
||
const scan = scanSliceEditConflicts({
|
||
baseSlices: glueBaseSlices,
|
||
pendingSlices: gluePendingSlices,
|
||
actions: [gluedValid, farAction],
|
||
});
|
||
assert.equal(scan.clean, false);
|
||
assert.equal(scan.entries.length, 1);
|
||
const entry = scan.entries[0];
|
||
assert.equal(entry.kind, "edge-glued");
|
||
assert.deepEqual(entry.relation, { start: 0, end: 5, edge: "end", from: 5, to: 7 });
|
||
assert.deepEqual(entry.choices, ["follow", "keep"]);
|
||
assert.equal(entry.defaultChoice, "follow");
|
||
|
||
const kept = resolveSliceEditConflicts({
|
||
baseSlices: glueBaseSlices,
|
||
pendingSlices: gluePendingSlices,
|
||
actions: [gluedValid, farAction],
|
||
choices: { v1: "keep" },
|
||
});
|
||
assert.deepEqual(
|
||
kept.actions.map((piece) => [piece.start, piece.end]),
|
||
[
|
||
[0, 5],
|
||
[8, 10],
|
||
],
|
||
);
|
||
|
||
const followed = resolveSliceEditConflicts({
|
||
baseSlices: glueBaseSlices,
|
||
pendingSlices: gluePendingSlices,
|
||
actions: [gluedValid, farAction],
|
||
choices: { v1: "follow" },
|
||
});
|
||
assert.deepEqual(
|
||
followed.actions.map((piece) => [piece.start, piece.end, piece.status]),
|
||
[
|
||
[0, 7, "described"],
|
||
[8, 10, "described"],
|
||
],
|
||
);
|
||
});
|
||
|
||
test("T2 pin: glue stretch is clamped by the straddle pieces — products never overlap", () => {
|
||
// 旧引擎在此场景产出 [0,7](贴边无效跟随)+ [5,7](跨界截断段)——轨道重叠、上下
|
||
// 操作失灵(T2)。新引擎:跨界产物先占位,贴边跟随被 [5,7] 段夹回 5。
|
||
for (const glued of [gluedInvalid, gluedValid]) {
|
||
const done = resolveSliceEditConflicts({
|
||
baseSlices: glueBaseSlices,
|
||
pendingSlices: gluePendingSlices,
|
||
actions: [glued, tiledRight],
|
||
choices: { w1: "truncate" },
|
||
});
|
||
assert.equal(done.effective, true);
|
||
assert.deepEqual(
|
||
done.actions.map((piece) => [piece.start, piece.end]),
|
||
[
|
||
[0, 5],
|
||
[5, 7],
|
||
[7, 10],
|
||
],
|
||
);
|
||
// 产物两两无重叠(含跨轨道),时间轴无缺口:动作/无效动作各归其轨的几何前提。
|
||
for (let i = 1; i < done.actions.length; i += 1) {
|
||
assert.ok(done.actions[i].start >= done.actions[i - 1].end - 1e-6, "products must tile without overlap");
|
||
}
|
||
}
|
||
});
|
||
|
||
test("Enter semantics: undecided entries resolve by default (truncate for straddled, follow for glued)", () => {
|
||
// 场景:边界 180→185;g 无效贴边 [175,180] 自动跟随、q 跨界 [183,190] 默认截断。
|
||
const tiled = { id: "t0", label: "铺垫", description: "铺垫动作", start: 170, end: 175, status: "described" };
|
||
const gluedLeft = {
|
||
id: "g0",
|
||
label: "无效片段",
|
||
description: "无效片段",
|
||
start: 175,
|
||
end: 180,
|
||
status: "invalid",
|
||
isInvalid: true,
|
||
};
|
||
const done = resolveSliceEditConflicts({
|
||
baseSlices: cutBaseSlices,
|
||
pendingSlices: cutPendingSlices,
|
||
actions: [tiled, gluedLeft, straddledAction],
|
||
});
|
||
assert.equal(done.effective, true);
|
||
// g0 跟随被 q1 的截断段 [183,185] 夹到 183;q1 按默认截断成两段。
|
||
assert.deepEqual(
|
||
done.actions.map((piece) => [piece.id, piece.start, piece.end, piece.status]),
|
||
[
|
||
["t0", 170, 175, "described"],
|
||
["g0", 175, 183, "invalid"],
|
||
["q1:split:185.000000:a", 183, 185, "described"],
|
||
["q1:split:185.000000:b", 185, 190, "described"],
|
||
],
|
||
);
|
||
const straddledAudit = done.applied.find((record) => record.actionId === "q1");
|
||
assert.equal(straddledAudit.choice, "truncate");
|
||
assert.equal(straddledAudit.defaulted, true);
|
||
const glueAudit = done.applied.find((record) => record.actionId === "g0");
|
||
assert.equal(glueAudit.auto, true);
|
||
assert.equal(glueAudit.defaulted, false);
|
||
});
|
||
|
||
// —— 快照回退 / 产物断言 / 轨道推导(票 03 第 3–6 项)——
|
||
|
||
import {
|
||
assertActionsCoveredByExactlyOneSlice,
|
||
assertSliceCoverageTiling,
|
||
deriveActionTrackState,
|
||
restoreSliceEditWorkspace,
|
||
snapshotSliceEditWorkspace,
|
||
validateActionStatuses,
|
||
} from "../../src/lib/slice-edit-conflict.js";
|
||
|
||
test("snapshot and rollback restore the panel-open state exactly, idempotently (Esc semantics)", () => {
|
||
const workspace = {
|
||
slices: [
|
||
{ id: "g1", name: "左片", start: 0, end: 5 },
|
||
{ id: "g2", name: "右片", start: 5, end: 10 },
|
||
],
|
||
actions: [gluedInvalid, tiledRight],
|
||
};
|
||
const snapshot = snapshotSliceEditWorkspace(workspace);
|
||
// 面板期间的最坏情况:原对象被就地污染 + 数组被增删。
|
||
workspace.slices[0].end = 7;
|
||
workspace.actions.push({ id: "junk", start: 1, end: 2, status: "described" });
|
||
const restored = restoreSliceEditWorkspace(snapshot);
|
||
assert.deepEqual(restored.slices, [
|
||
{ id: "g1", name: "左片", start: 0, end: 5 },
|
||
{ id: "g2", name: "右片", start: 5, end: 10 },
|
||
]);
|
||
assert.deepEqual(restored.actions, [gluedInvalid, tiledRight]);
|
||
// 回退幂等:二次回退结果一致;恢复不污染快照本体。
|
||
assert.deepEqual(restoreSliceEditWorkspace(snapshot), restored);
|
||
// 回退产物与快照本体隔离:改 restored 不影响再次回退。
|
||
restored.slices[0].end = 99;
|
||
assert.equal(restoreSliceEditWorkspace(snapshot).slices[0].end, 5);
|
||
});
|
||
|
||
test("status whitelist mirrors the Go guard: every disposition product passes, crafted bad states are flagged", () => {
|
||
for (const choice of ["truncate", "move", "invalidate"]) {
|
||
const done = resolveSliceEditConflicts({
|
||
baseSlices: cutBaseSlices,
|
||
pendingSlices: cutPendingSlices,
|
||
actions: [straddledAction],
|
||
choices: { q1: choice },
|
||
});
|
||
assert.deepEqual(validateActionStatuses(done.actions), [], `${choice} products must pass the whitelist`);
|
||
}
|
||
const glueDone = resolveSliceEditConflicts({
|
||
baseSlices: glueBaseSlices,
|
||
pendingSlices: gluePendingSlices,
|
||
actions: [gluedValid, tiledRight],
|
||
choices: { w1: "invalidate" },
|
||
});
|
||
assert.deepEqual(validateActionStatuses(glueDone.actions), []);
|
||
|
||
const bad = [
|
||
{ id: "x1", start: 0, end: 1, status: "pending", isInvalid: true }, // 待标注不能标无效
|
||
{ id: "x2", start: 0, end: 1, status: "described", description: "" }, // 已描述必须有描述
|
||
{ id: "x3", start: 0, end: 1, status: "described", isInvalid: true, description: "x" }, // 已描述不能无效
|
||
{ id: "x4", start: 0, end: 1, status: "invalid" }, // 无效必须与 isInvalid 一致
|
||
{ id: "x5", start: 0, end: 1, status: "待核对" }, // 白名单外状态永不落库
|
||
];
|
||
const issues = validateActionStatuses(bad);
|
||
assert.equal(issues.length, bad.length);
|
||
assert.ok(issues.every((issue) => issue.code === "action_annotation_incomplete"));
|
||
assert.ok(issues.some((issue) => issue.actionId === "x5" && issue.message.includes("未知动作状态")));
|
||
});
|
||
|
||
test("assertActionsCoveredByExactlyOneSlice mirrors the Go submit guard", () => {
|
||
// 恰好一片包含:通过。
|
||
assert.deepEqual(assertActionsCoveredByExactlyOneSlice([farAction], gluePendingSlices), []);
|
||
// 跨片(T3 的守卫对象):拒。
|
||
const straddling = [{ id: "z1", description: "跨界", start: 183, end: 190, status: "described" }];
|
||
const issues = assertActionsCoveredByExactlyOneSlice(straddling, cutPendingSlices);
|
||
assert.equal(issues.length, 1);
|
||
assert.equal(issues[0].actionId, "z1");
|
||
assert.equal(issues[0].message, "semantic segment must be fully contained in exactly one submitted final slice");
|
||
// 重叠切片(脏结构)双重包含:同样拒。
|
||
const dirtySlices = [
|
||
{ id: "d1", start: 0, end: 10 },
|
||
{ id: "d2", start: 5, end: 15 },
|
||
];
|
||
assert.equal(
|
||
assertActionsCoveredByExactlyOneSlice([{ id: "z2", start: 6, end: 8, status: "described" }], dirtySlices).length,
|
||
1,
|
||
);
|
||
// 有效动作落在弃用片:拒(镜像"舍弃片段不能包含当前有效标注");无效动作可留。
|
||
const discardPending = [
|
||
{ id: "g1", start: 0, end: 7, deliveryDisposition: "discard" },
|
||
{ id: "g2", start: 7, end: 10 },
|
||
];
|
||
const inDiscard = [
|
||
{ id: "v-keep", start: 0, end: 5, status: "invalid", isInvalid: true },
|
||
{ id: "v-bad", start: 5, end: 7, status: "described", description: "有效" },
|
||
];
|
||
const discardIssues = assertActionsCoveredByExactlyOneSlice(inDiscard, discardPending);
|
||
assert.equal(discardIssues.length, 1);
|
||
assert.equal(discardIssues[0].actionId, "v-bad");
|
||
});
|
||
|
||
test("T3 pin: every choice tiles the pending structure gap-free — the coverage guard never trips", () => {
|
||
// 铺满基线:v 无效铺左片 [0,5],w 已描述铺右片 [5,10];边界 5→7。
|
||
for (const choice of ["truncate", "move", "invalidate"]) {
|
||
const done = resolveSliceEditConflicts({
|
||
baseSlices: glueBaseSlices,
|
||
pendingSlices: gluePendingSlices,
|
||
actions: [gluedInvalid, tiledRight],
|
||
choices: { w1: choice },
|
||
});
|
||
assert.deepEqual(assertSliceCoverageTiling(done.actions, gluePendingSlices), [], `${choice} must tile gap-free`);
|
||
assert.deepEqual(
|
||
assertActionsCoveredByExactlyOneSlice(done.actions, gluePendingSlices),
|
||
[],
|
||
`${choice} must contain exactly one slice each`,
|
||
);
|
||
}
|
||
// 反例(T3 原始病灶):残段丢弃留下缺口,守卫必须报 annotation_coverage_gap——
|
||
// 旧"挪片只留对面段"产物 [7,10] + 未跟随的 v [0,5] 缺 [5,7]。
|
||
const droppedMove = [
|
||
{ ...gluedInvalid },
|
||
{ id: "w1", start: 7, end: 10, status: "described", description: "放回商品" },
|
||
];
|
||
const gapIssues = assertSliceCoverageTiling(droppedMove, gluePendingSlices);
|
||
assert.ok(gapIssues.some((issue) => issue.code === "annotation_coverage_gap"));
|
||
// 旧"判无效只留原侧段"产物 [5,7] 缺 [7,10]:同样报缺口。
|
||
const droppedInvalidate = [{ ...gluedInvalid }, { id: "w1", start: 5, end: 7, status: "invalid", isInvalid: true }];
|
||
assert.ok(
|
||
assertSliceCoverageTiling(droppedInvalidate, gluePendingSlices).some(
|
||
(issue) => issue.code === "annotation_coverage_gap",
|
||
),
|
||
);
|
||
});
|
||
|
||
test("deriveActionTrackState partitions tracks by effective status, keeps time order, and flags overlap", () => {
|
||
const actions = [
|
||
{ id: "a", description: "推导为已描述", start: 0, end: 5 },
|
||
{ id: "b", status: "pending", start: 6, end: 8 },
|
||
{ id: "c", status: "invalid", start: 9, end: 10 },
|
||
{ id: "d", isInvalid: true, start: 11, end: 12 },
|
||
{ id: "e", status: "described", description: "y", start: 13, end: 14 },
|
||
];
|
||
const tracks = deriveActionTrackState(actions);
|
||
assert.deepEqual(
|
||
tracks.validActions.map((action) => action.id),
|
||
["a", "b", "e"],
|
||
);
|
||
assert.deepEqual(
|
||
tracks.invalidActions.map((action) => action.id),
|
||
["c", "d"],
|
||
);
|
||
// 上下操作按时间序遍历全轨道(动作/无效动作同一条导航序)。
|
||
assert.deepEqual(
|
||
tracks.sequence.map((action) => action.id),
|
||
["a", "b", "c", "d", "e"],
|
||
);
|
||
assert.deepEqual(tracks.overlapIssues, []);
|
||
// T2 的轨道症状:任何两段几何重叠都会被点名。
|
||
const overlapped = deriveActionTrackState([
|
||
{ id: "x", start: 0, end: 5, status: "described" },
|
||
{ id: "y", start: 3, end: 8, status: "invalid", isInvalid: true },
|
||
]);
|
||
assert.equal(overlapped.overlapIssues.length, 1);
|
||
assert.deepEqual(overlapped.overlapIssues[0].actionIds.sort(), ["x", "y"]);
|
||
});
|
||
|
||
test("multi-cut generalization: two new boundaries through one action yield three coherent pieces", () => {
|
||
// 基线 m2=[30,100];边界 30→50 右移 + 在 70 新拆分 → 预览 [0,50],[50,70],[70,100]。
|
||
const base = [
|
||
{ id: "m1", start: 0, end: 30 },
|
||
{ id: "m2", start: 30, end: 100 },
|
||
];
|
||
const pending = [
|
||
{ id: "m1", start: 0, end: 50 },
|
||
{ id: "m2", start: 50, end: 70 },
|
||
{ id: "m3", start: 70, end: 100 },
|
||
];
|
||
const act = { id: "k1", label: "跨两刀", description: "跨两刀动作", start: 40, end: 90, status: "described" };
|
||
const scan = scanSliceEditConflicts({ baseSlices: base, pendingSlices: pending, actions: [act] });
|
||
assert.equal(scan.entries.length, 1);
|
||
assert.deepEqual(scan.entries[0].relation.cuts, [50, 70]);
|
||
|
||
const truncated = resolveSliceEditConflicts({
|
||
baseSlices: base,
|
||
pendingSlices: pending,
|
||
actions: [act],
|
||
choices: { k1: "truncate" },
|
||
});
|
||
assert.deepEqual(
|
||
truncated.actions.map((piece) => [piece.id, piece.start, piece.end, piece.status]),
|
||
[
|
||
["k1:split:50.000000-70.000000:a", 40, 50, "described"],
|
||
["k1:split:50.000000-70.000000:b", 50, 70, "described"],
|
||
["k1:split:50.000000-70.000000:c", 70, 90, "described"],
|
||
],
|
||
);
|
||
|
||
// 挪片(消失旧边界 30 → 最近刀口原片侧=右侧):迁入段 [40,50]+[50,70] 保留原状态,
|
||
// 原片空当 [70,90] 生成无效段。
|
||
const moved = resolveSliceEditConflicts({
|
||
baseSlices: base,
|
||
pendingSlices: pending,
|
||
actions: [act],
|
||
choices: { k1: "move" },
|
||
});
|
||
assert.deepEqual(
|
||
moved.actions.map((piece) => [piece.id, piece.start, piece.end, piece.status, piece.isInvalid === true]),
|
||
[
|
||
["k1:split:50.000000-70.000000:a", 40, 50, "described", false],
|
||
["k1:split:50.000000-70.000000:b", 50, 70, "described", false],
|
||
["k1:gap:50.000000-70.000000", 70, 90, "invalid", true],
|
||
],
|
||
);
|
||
|
||
const invalidated = resolveSliceEditConflicts({
|
||
baseSlices: base,
|
||
pendingSlices: pending,
|
||
actions: [act],
|
||
choices: { k1: "invalidate" },
|
||
});
|
||
assert.ok(invalidated.actions.every((piece) => piece.status === "invalid" && piece.isInvalid === true));
|
||
assert.deepEqual(
|
||
invalidated.actions.map((piece) => [piece.start, piece.end]),
|
||
[
|
||
[40, 50],
|
||
[50, 70],
|
||
[70, 90],
|
||
],
|
||
);
|
||
});
|
||
|
||
// —— 工单 02(rework-ux-adjust,D2/D3):零宽产物守卫 + 贴边跟随提示行 ——
|
||
//
|
||
// 退化结构可达性:相邻刀口距离 ≤EPS 经 API 直写/历史数据进入(帧吸附与毫秒吸附的
|
||
// UI 最小间距都大于 EPS,鼠标路径不可达);引擎作为公共接缝必须兜住——宽度 ≤EPS
|
||
// 的段显式并入同动作相邻段(优先同状态邻段、同为同状态取左),覆盖不变、绝不静默。
|
||
|
||
const degenerateBaseSlices = [
|
||
{ id: "s1", name: "拿取", start: 170, end: 180 },
|
||
{ id: "s2", name: "放回", start: 180, end: 200 },
|
||
];
|
||
const degeneratePendingSlices = [
|
||
{ id: "s1", name: "拿取", start: 170, end: 184 },
|
||
{ id: "s2", name: "放回", start: 184, end: 184.0000005 },
|
||
{ id: "s3", name: "整理", start: 184.0000005, end: 200 },
|
||
];
|
||
const degenerateInvalid = {
|
||
id: "iv1",
|
||
label: "无效片段",
|
||
description: "无效片段",
|
||
labelId: "",
|
||
start: 183,
|
||
end: 190,
|
||
status: "invalid",
|
||
isInvalid: true,
|
||
};
|
||
|
||
test("zero-width guard (02): degenerate middle piece merges into an adjacent piece for every disposition", () => {
|
||
for (const choice of ["truncate", "move", "invalidate"]) {
|
||
const done = resolveSliceEditConflicts({
|
||
baseSlices: degenerateBaseSlices,
|
||
pendingSlices: degeneratePendingSlices,
|
||
actions: [degenerateInvalid],
|
||
choices: { iv1: choice },
|
||
});
|
||
assert.ok(
|
||
done.actions.every((piece) => piece.end - piece.start > 1e-6),
|
||
`${choice}: no ≤EPS-width product may survive`,
|
||
);
|
||
const covered = done.actions.reduce((sum, piece) => sum + (piece.end - piece.start), 0);
|
||
assert.ok(Math.abs(covered - 7) <= 1e-6, `${choice}: total coverage must stay 7s (183→190)`);
|
||
}
|
||
});
|
||
|
||
test("zero-width guard (02): invalidate keeps merged pieces invalid; move merges the degenerate sliver into the same-status neighbour", () => {
|
||
const validStraddled = {
|
||
id: "q9",
|
||
label: "取放",
|
||
labelId: "L1",
|
||
description: "取放商品",
|
||
start: 183,
|
||
end: 190,
|
||
status: "described",
|
||
};
|
||
const invalidated = resolveSliceEditConflicts({
|
||
baseSlices: degenerateBaseSlices,
|
||
pendingSlices: degeneratePendingSlices,
|
||
actions: [validStraddled],
|
||
choices: { q9: "invalidate" },
|
||
});
|
||
assert.equal(invalidated.actions.length, 2, "three-piece geometry collapses to two (sliver absorbed)");
|
||
assert.ok(invalidated.actions.every((piece) => piece.status === "invalid" && piece.isInvalid === true));
|
||
|
||
const moved = resolveSliceEditConflicts({
|
||
baseSlices: degenerateBaseSlices,
|
||
pendingSlices: degeneratePendingSlices,
|
||
actions: [validStraddled],
|
||
choices: { q9: "move" },
|
||
});
|
||
assert.ok(moved.actions.every((piece) => piece.end - piece.start > 1e-6));
|
||
// 消失旧边界 180 → 原片侧=右:迁入段 q9 几何 [183, 184.0000005](含并入的退化中段,
|
||
// 保留 described),原片空当 [184.0000005, 190] 转无效。
|
||
const migrated = moved.actions.find((piece) => piece.status === "described");
|
||
const gap = moved.actions.find((piece) => piece.status === "invalid");
|
||
assert.deepEqual([migrated.start, migrated.end], [183, 184.0000005]);
|
||
assert.deepEqual([gap.start, gap.end], [184.0000005, 190]);
|
||
});
|
||
|
||
test("zero-width guard (02): exactly duplicated boundaries yield two clean pieces instead of an invisible zero-width one", () => {
|
||
const pendingExact = [
|
||
{ id: "s1", name: "拿取", start: 170, end: 184 },
|
||
{ id: "s2", name: "放回", start: 184, end: 184 },
|
||
{ id: "s3", name: "整理", start: 184, end: 200 },
|
||
];
|
||
const done = resolveSliceEditConflicts({
|
||
baseSlices: degenerateBaseSlices,
|
||
pendingSlices: pendingExact,
|
||
actions: [degenerateInvalid],
|
||
choices: { iv1: "invalidate" },
|
||
});
|
||
assert.deepEqual(
|
||
done.actions.map((piece) => [piece.start, piece.end]),
|
||
[
|
||
[183, 184],
|
||
[184, 190],
|
||
],
|
||
);
|
||
assert.ok(done.actions.every((piece) => piece.status === "invalid" && piece.isInvalid === true));
|
||
});
|
||
|
||
test("autoFollows (02): silently-following glued invalid actions are exposed for the conflict-list hint row", () => {
|
||
const scan = scanSliceEditConflicts({
|
||
baseSlices: glueBaseSlices,
|
||
pendingSlices: gluePendingSlices,
|
||
actions: [gluedInvalid, farAction],
|
||
});
|
||
assert.deepEqual(scan.entries, []);
|
||
assert.equal(scan.autoFollows.length, 1);
|
||
assert.deepEqual(scan.autoFollows[0], { actionId: "v1", start: 0, end: 5, edge: "end", from: 5, to: 7 });
|
||
// 有效贴边动作是两选条目(人来拍板),不进 autoFollows。
|
||
const withValid = scanSliceEditConflicts({
|
||
baseSlices: glueBaseSlices,
|
||
pendingSlices: gluePendingSlices,
|
||
actions: [gluedValid, farAction],
|
||
});
|
||
assert.equal(withValid.autoFollows.length, 0);
|
||
assert.equal(withValid.entries.length, 1);
|
||
});
|
||
|
||
test("auto-follow hint (02): collapsed hint-row text derives from the auto-follow set", () => {
|
||
assert.equal(conflictAutoFollowHint([]), null);
|
||
assert.equal(conflictAutoFollowHint(undefined), null);
|
||
assert.equal(conflictAutoFollowHint([{ actionId: "v1" }]), "1 个贴边无效动作自动跟随");
|
||
assert.equal(conflictAutoFollowHint([{ actionId: "v1" }, { actionId: "v2" }]), "2 个贴边无效动作自动跟随");
|
||
});
|