198 lines
8.1 KiB
TypeScript
198 lines
8.1 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { mkdtemp, rm } from "node:fs/promises";
|
|
|
|
let runtimeRoot = "";
|
|
let readState: (typeof import("../src/lib/boss-data"))["readState"];
|
|
let writeState: (typeof import("../src/lib/boss-data"))["writeState"];
|
|
let saveAiAccount: (typeof import("../src/lib/boss-data"))["saveAiAccount"];
|
|
let updateMasterAgentPromptPolicy: (typeof import("../src/lib/boss-data"))["updateMasterAgentPromptPolicy"];
|
|
let updateUserMasterPrompt: (typeof import("../src/lib/boss-data"))["updateUserMasterPrompt"];
|
|
let createUserMasterMemory: (typeof import("../src/lib/boss-data"))["createUserMasterMemory"];
|
|
let updateProjectAgentControls: (typeof import("../src/lib/boss-data"))["updateProjectAgentControls"];
|
|
let resolveMasterAgentExecutionConfig: (typeof import("../src/lib/boss-master-agent"))["resolveMasterAgentExecutionConfig"];
|
|
let replyToMasterAgentUserMessage: (typeof import("../src/lib/boss-master-agent"))["replyToMasterAgentUserMessage"];
|
|
|
|
async function setup() {
|
|
if (runtimeRoot) return;
|
|
|
|
runtimeRoot = await mkdtemp(path.join(os.tmpdir(), "boss-master-agent-thread-status-"));
|
|
process.env.BOSS_RUNTIME_ROOT = runtimeRoot;
|
|
process.env.BOSS_STATE_FILE = path.join(runtimeRoot, "boss-state.json");
|
|
|
|
const [data, masterAgent] = await Promise.all([
|
|
import("../src/lib/boss-data.ts"),
|
|
import("../src/lib/boss-master-agent.ts"),
|
|
]);
|
|
|
|
readState = data.readState;
|
|
writeState = data.writeState;
|
|
saveAiAccount = data.saveAiAccount;
|
|
updateMasterAgentPromptPolicy = data.updateMasterAgentPromptPolicy;
|
|
updateUserMasterPrompt = data.updateUserMasterPrompt;
|
|
createUserMasterMemory = data.createUserMasterMemory;
|
|
updateProjectAgentControls = data.updateProjectAgentControls;
|
|
resolveMasterAgentExecutionConfig = masterAgent.resolveMasterAgentExecutionConfig;
|
|
replyToMasterAgentUserMessage = masterAgent.replyToMasterAgentUserMessage;
|
|
}
|
|
|
|
test.after(async () => {
|
|
if (runtimeRoot) {
|
|
await rm(runtimeRoot, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("主 Agent 执行 prompt 默认读取线程状态文档、最近进展事件和项目记忆,并保留深拉兜底", async () => {
|
|
await setup();
|
|
|
|
await saveAiAccount({
|
|
accountId: "master-codex-primary",
|
|
label: "主 GPT",
|
|
role: "primary",
|
|
provider: "master_codex_node",
|
|
displayName: "17600003315 · Master Codex Node",
|
|
nodeId: "mac-studio",
|
|
nodeLabel: "Mac Studio",
|
|
enabled: true,
|
|
setActive: true,
|
|
status: "ready",
|
|
loginStatusNote: "主节点可用。",
|
|
});
|
|
await updateMasterAgentPromptPolicy({
|
|
globalPrompt: "管理员全局主提示词",
|
|
updatedBy: "17600003315",
|
|
});
|
|
await updateUserMasterPrompt("17600003315", "用户私有主提示词");
|
|
await updateProjectAgentControls("master-agent", {
|
|
promptOverride: "当前对话提示词",
|
|
});
|
|
await createUserMasterMemory({
|
|
account: "17600003315",
|
|
scope: "project",
|
|
projectId: "master-agent",
|
|
title: "项目记忆",
|
|
content: "项目记忆正文",
|
|
memoryType: "project_progress",
|
|
tags: ["线程状态"],
|
|
});
|
|
await createUserMasterMemory({
|
|
account: "master-codex-primary",
|
|
scope: "project",
|
|
projectId: "master-agent",
|
|
title: "项目记忆",
|
|
content: "项目记忆正文",
|
|
memoryType: "project_progress",
|
|
tags: ["线程状态"],
|
|
});
|
|
|
|
const state = await readState();
|
|
const auditProject = state.projects.find((project) => project.id === "audit-collab");
|
|
assert.ok(auditProject, "expected seeded audit-collab project");
|
|
auditProject!.projectUnderstanding = {
|
|
projectGoal: "深拉兜底目标",
|
|
currentProgress: "深拉兜底进度",
|
|
technicalArchitecture: "深拉兜底架构",
|
|
currentBlockers: "深拉兜底阻塞",
|
|
recommendedNextStep: "深拉兜底下一步",
|
|
sourceTaskId: "task-deep-pull",
|
|
updatedAt: "2026-04-04T18:00:00+08:00",
|
|
sourceKind: "thread_sync",
|
|
};
|
|
state.threadStatusDocuments = [
|
|
{
|
|
documentId: "thread-status-doc-1",
|
|
projectId: "audit-collab",
|
|
threadId: "thread-audit-chief",
|
|
threadDisplayName: "审计对话",
|
|
folderName: "审计群聊",
|
|
deviceId: "mac-studio",
|
|
projectGoal: "线程状态目标",
|
|
currentPhase: "线程状态阶段",
|
|
currentProgress: "线程状态进度",
|
|
technicalArchitecture: "线程状态架构",
|
|
currentBlockers: "线程状态阻塞",
|
|
recommendedNextStep: "线程状态下一步",
|
|
keyFiles: ["src/lib/boss-master-agent.ts"],
|
|
keyCommands: ["npm run build"],
|
|
updatedAt: "2026-04-04T18:01:00+08:00",
|
|
sourceTaskId: "task-thread-status",
|
|
sourceKind: "incremental_sync",
|
|
},
|
|
];
|
|
state.threadProgressEvents = [
|
|
{
|
|
eventId: "thread-progress-event-1",
|
|
projectId: "audit-collab",
|
|
threadId: "thread-audit-chief",
|
|
threadDisplayName: "审计对话",
|
|
deviceId: "mac-studio",
|
|
eventType: "progress_updated",
|
|
summary: "最近进展事件摘要",
|
|
phase: "线程状态阶段",
|
|
blockerDelta: "线程状态阻塞",
|
|
nextStepDelta: "线程状态下一步",
|
|
createdAt: "2026-04-04T18:02:00+08:00",
|
|
sourceTaskId: "task-thread-progress",
|
|
},
|
|
];
|
|
await writeState(state);
|
|
|
|
const resolved = await resolveMasterAgentExecutionConfig(
|
|
"master-agent",
|
|
"17600003315",
|
|
"继续推进线程状态同步",
|
|
);
|
|
assert.ok(resolved.projectMemories.length > 0);
|
|
assert.equal(resolved.projectMemories[0]?.content, "项目记忆正文");
|
|
assert.ok(resolved.executionPrompt.includes("当前对话提示词"));
|
|
assert.ok(
|
|
resolved.executionPrompt.indexOf("管理员全局主提示词:") <
|
|
resolved.executionPrompt.indexOf("用户私有主提示词:") &&
|
|
resolved.executionPrompt.indexOf("用户私有主提示词:") <
|
|
resolved.executionPrompt.indexOf("当前对话附加提示词:") &&
|
|
resolved.executionPrompt.indexOf("当前对话附加提示词:") <
|
|
resolved.executionPrompt.indexOf("当前消息:"),
|
|
);
|
|
|
|
const reply = await replyToMasterAgentUserMessage({
|
|
requestText: "继续推进线程状态同步",
|
|
requestedBy: "Boss 超级管理员",
|
|
requestedByAccount: "17600003315",
|
|
mode: "enqueue",
|
|
});
|
|
assert.equal(reply.ok, true);
|
|
assert.equal(reply.masterReplyState, "queued");
|
|
|
|
const queuedTask = (await readState()).masterAgentTasks.find(
|
|
(task) => task.projectId === "master-agent" && task.requestText === "继续推进线程状态同步",
|
|
);
|
|
assert.ok(queuedTask, "expected master-agent task to be queued");
|
|
assert.ok(queuedTask?.executionPrompt.includes("线程状态文档:"));
|
|
assert.ok(queuedTask?.executionPrompt.includes("线程状态目标"));
|
|
assert.ok(queuedTask?.executionPrompt.includes("最近进展事件:"));
|
|
assert.ok(queuedTask?.executionPrompt.includes("最近进展事件摘要"));
|
|
assert.ok(queuedTask?.executionPrompt.includes("关键时刻深拉线程兜底:"));
|
|
assert.ok(queuedTask?.executionPrompt.includes("深拉兜底目标"));
|
|
|
|
assert.ok(
|
|
queuedTask?.executionPrompt.indexOf("管理员全局主提示词:") <
|
|
queuedTask.executionPrompt.indexOf("用户私有主提示词:") &&
|
|
queuedTask.executionPrompt.indexOf("用户私有主提示词:") <
|
|
queuedTask.executionPrompt.indexOf("当前对话附加提示词:") &&
|
|
queuedTask.executionPrompt.indexOf("当前对话附加提示词:") <
|
|
queuedTask.executionPrompt.indexOf("项目记忆:") &&
|
|
queuedTask.executionPrompt.indexOf("项目记忆:") <
|
|
queuedTask.executionPrompt.indexOf("当前消息:") &&
|
|
queuedTask.executionPrompt.indexOf("当前消息:") <
|
|
queuedTask.executionPrompt.indexOf("当前对话覆盖:") &&
|
|
queuedTask.executionPrompt.indexOf("当前对话覆盖:") <
|
|
queuedTask.executionPrompt.indexOf("线程状态文档:") &&
|
|
queuedTask.executionPrompt.indexOf("线程状态文档:") <
|
|
queuedTask.executionPrompt.indexOf("最近进展事件:") &&
|
|
queuedTask.executionPrompt.indexOf("最近进展事件:") <
|
|
queuedTask.executionPrompt.indexOf("关键时刻深拉线程兜底:"),
|
|
);
|
|
});
|