134 lines
4.4 KiB
TypeScript
134 lines
4.4 KiB
TypeScript
import test from "node:test";
|
||
import assert from "node:assert/strict";
|
||
import {
|
||
extractApprovedTargetProjectIds,
|
||
latestRejectedDispatchPlan,
|
||
latestPendingDispatchPlan,
|
||
resolveDispatchPlanComposerState,
|
||
summarizeDispatchPlan,
|
||
} from "@/lib/dispatch-plan-ui";
|
||
|
||
test("summarizeDispatchPlan combines summary and recommended target titles", () => {
|
||
const summary = summarizeDispatchPlan({
|
||
planId: "dispatch-plan-0",
|
||
summary: "主 Agent 建议先同步 UI 和设备线程",
|
||
targets: [
|
||
{ projectId: "p1", threadDisplayName: "Boss UI 主线程" },
|
||
{ projectId: "p2", threadDisplayName: "设备接入线程" },
|
||
],
|
||
});
|
||
|
||
assert.equal(summary, "主 Agent 建议先同步 UI 和设备线程\n推荐线程:Boss UI 主线程、设备接入线程");
|
||
});
|
||
|
||
test("extractApprovedTargetProjectIds keeps target order and drops blanks", () => {
|
||
const ids = extractApprovedTargetProjectIds({
|
||
planId: "dispatch-plan-0",
|
||
targets: [
|
||
{ projectId: "p2", threadDisplayName: "设备接入线程" },
|
||
{ projectId: "p1", threadDisplayName: "Boss UI 主线程" },
|
||
],
|
||
});
|
||
|
||
assert.deepEqual(ids, ["p2", "p1"]);
|
||
});
|
||
|
||
test("latestPendingDispatchPlan returns the latest waiting confirmation item", () => {
|
||
const plan = latestPendingDispatchPlan([
|
||
{
|
||
planId: "dispatch-plan-1",
|
||
status: "dispatched",
|
||
summary: "已完成的推荐",
|
||
targets: [{ projectId: "p1", threadDisplayName: "Boss UI 主线程" }],
|
||
},
|
||
{
|
||
planId: "dispatch-plan-2",
|
||
status: "pending_user_confirmation",
|
||
summary: "等待确认的推荐",
|
||
targets: [{ projectId: "p2", threadDisplayName: "设备接入线程" }],
|
||
},
|
||
]);
|
||
|
||
assert.deepEqual(plan, {
|
||
planId: "dispatch-plan-2",
|
||
status: "pending_user_confirmation",
|
||
summary: "等待确认的推荐",
|
||
targets: [{ projectId: "p2", threadDisplayName: "设备接入线程" }],
|
||
});
|
||
});
|
||
|
||
test("latestRejectedDispatchPlan returns the latest rejected item", () => {
|
||
const plan = latestRejectedDispatchPlan([
|
||
{
|
||
planId: "dispatch-plan-1",
|
||
status: "dispatched",
|
||
summary: "已完成的推荐",
|
||
targets: [{ projectId: "p1", threadDisplayName: "Boss UI 主线程" }],
|
||
},
|
||
{
|
||
planId: "dispatch-plan-3",
|
||
status: "rejected",
|
||
summary: "已拒绝的推荐",
|
||
targets: [{ projectId: "p3", threadDisplayName: "调度修复线程" }],
|
||
},
|
||
]);
|
||
|
||
assert.deepEqual(plan, {
|
||
planId: "dispatch-plan-3",
|
||
status: "rejected",
|
||
summary: "已拒绝的推荐",
|
||
targets: [{ projectId: "p3", threadDisplayName: "调度修复线程" }],
|
||
});
|
||
});
|
||
|
||
test("resolveDispatchPlanComposerState folds older rejected plans once a newer pending plan exists", () => {
|
||
const state = resolveDispatchPlanComposerState([
|
||
{
|
||
planId: "dispatch-plan-1",
|
||
status: "rejected",
|
||
summary: "已拒绝的推荐",
|
||
targets: [{ projectId: "p3", threadDisplayName: "调度修复线程" }],
|
||
},
|
||
{
|
||
planId: "dispatch-plan-2",
|
||
status: "pending_user_confirmation",
|
||
summary: "重新生成的推荐",
|
||
targets: [{ projectId: "p2", threadDisplayName: "设备接入线程" }],
|
||
},
|
||
]);
|
||
|
||
assert.deepEqual(state.pendingDispatchPlan, {
|
||
planId: "dispatch-plan-2",
|
||
status: "pending_user_confirmation",
|
||
summary: "重新生成的推荐",
|
||
targets: [{ projectId: "p2", threadDisplayName: "设备接入线程" }],
|
||
});
|
||
assert.equal(state.rejectedDispatchPlan, null);
|
||
assert.equal(state.recoveryHint, "当前有待确认推荐,已折叠旧的拒绝状态。");
|
||
assert.equal(state.recoveryActionLabel, null);
|
||
});
|
||
|
||
test("resolveDispatchPlanComposerState exposes a retry action for a rejected plan", () => {
|
||
const state = resolveDispatchPlanComposerState([
|
||
{
|
||
planId: "dispatch-plan-3",
|
||
status: "rejected",
|
||
summary: "已拒绝的推荐",
|
||
targets: [{ projectId: "p3", threadDisplayName: "调度修复线程" }],
|
||
},
|
||
]);
|
||
|
||
assert.equal(state.pendingDispatchPlan, null);
|
||
assert.deepEqual(state.rejectedDispatchPlan, {
|
||
planId: "dispatch-plan-3",
|
||
status: "rejected",
|
||
summary: "已拒绝的推荐",
|
||
targets: [{ projectId: "p3", threadDisplayName: "调度修复线程" }],
|
||
});
|
||
assert.equal(state.recoveryActionLabel, "重新生成新的推荐");
|
||
assert.equal(
|
||
state.recoveryHint,
|
||
"上次推荐已拒绝。直接点击“重新生成新的推荐”即可继续协作,不用重新发送整条消息。",
|
||
);
|
||
});
|