Files
boss/tests/device-import-draft-manager.test.ts
2026-03-31 22:38:57 +08:00

130 lines
4.2 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { describeDeviceImportDraft } from "../src/components/device-import-draft-manager.tsx";
test("device import draft copy explains selection and recommendation state", () => {
const view = describeDeviceImportDraft(
{
draftId: "draft-1",
deviceId: "device-1",
status: "pending_selection",
candidates: [
{
candidateId: "candidate-1",
deviceId: "device-1",
folderName: "北区试产线",
folderRef: "north-line",
threadId: "thread-1",
threadDisplayName: "北区试产线回归",
codexFolderRef: "north-line",
codexThreadRef: "thread-1",
lastActiveAt: "2026-03-30T10:18:00+08:00",
suggestedImport: true,
},
{
candidateId: "candidate-2",
deviceId: "device-1",
folderName: "北区试产线",
folderRef: "north-line",
threadId: "thread-2",
threadDisplayName: "北区试产线审计",
codexFolderRef: "north-line",
codexThreadRef: "thread-2",
lastActiveAt: "2026-03-30T10:20:00+08:00",
suggestedImport: false,
},
],
selectedCandidateIds: ["candidate-1"],
appliedProjectNames: [],
createdAt: "2026-03-30T10:00:00+08:00",
updatedAt: "2026-03-30T10:20:00+08:00",
},
null,
);
assert.equal(view.statusTitle, "等待勾选");
assert.match(view.statusBody, /先勾选想导入的线程/);
assert.match(view.recommendationHint, /推荐 1 项/);
assert.equal(view.resultTitle, "导入建议");
assert.match(view.resultBody, /应用导入前/);
assert.equal(view.selectedCount, 1);
assert.equal(view.recommendedCount, 1);
});
test("device import draft copy shows pending agent review when task is queued", () => {
const view = describeDeviceImportDraft(
{
draftId: "draft-1",
deviceId: "device-1",
status: "pending_resolution",
candidates: [
{
candidateId: "candidate-1",
deviceId: "device-1",
folderName: "北区试产线",
folderRef: "north-line",
threadId: "thread-1",
threadDisplayName: "北区试产线回归",
codexFolderRef: "north-line",
codexThreadRef: "thread-1",
lastActiveAt: "2026-03-30T10:18:00+08:00",
suggestedImport: true,
},
],
selectedCandidateIds: ["candidate-1"],
appliedProjectNames: [],
createdAt: "2026-03-30T10:00:00+08:00",
updatedAt: "2026-03-30T10:20:00+08:00",
},
null,
{
taskId: "mastertask-1",
projectId: "master-agent",
taskType: "device_import_resolution",
requestMessageId: "draft-1",
requestText: "请审核设备导入",
executionPrompt: "prompt",
requestedBy: "17600003315",
requestedByAccount: "17600003315",
deviceId: "mac-studio",
deviceImportDraftId: "draft-1",
status: "queued",
requestedAt: "2026-03-30T10:20:10+08:00",
},
);
assert.equal(view.statusTitle, "主 Agent 审核中");
assert.match(view.statusBody, /页面会自动刷新/);
});
test("device import draft copy shows applied project names after import", () => {
const view = describeDeviceImportDraft(
{
draftId: "draft-1",
deviceId: "device-1",
status: "applied",
candidates: [],
selectedCandidateIds: [],
appliedProjectNames: ["北区试产线回归", "北区试产线审计"],
createdAt: "2026-03-30T10:00:00+08:00",
updatedAt: "2026-03-30T10:20:00+08:00",
},
{
resolutionId: "resolution-1",
draftId: "draft-1",
deviceId: "device-1",
status: "applied",
summary: "MacBook Pro 导入建议:新建 2 个会话,关联 0 个现有会话。",
items: [],
createdAt: "2026-03-30T10:21:00+08:00",
appliedAt: "2026-03-30T10:22:00+08:00",
},
);
assert.equal(view.statusTitle, "已导入");
assert.match(view.statusBody, /已导入 2 个线程/);
assert.equal(view.resultTitle, "应用结果");
assert.match(view.resultBody, /已把 2 个线程导入到会话首页/);
assert.deepEqual(view.appliedProjectNames, ["北区试产线回归", "北区试产线审计"]);
});