Add second batch master agent fast paths
This commit is contained in:
@@ -10,6 +10,7 @@ let POST: (typeof import("../src/app/api/v1/projects/[projectId]/messages/route"
|
||||
let saveAiAccount: (typeof import("../src/lib/boss-data"))["saveAiAccount"];
|
||||
let getProjectAgentControls: (typeof import("../src/lib/boss-data"))["getProjectAgentControls"];
|
||||
let updateProjectAgentControls: (typeof import("../src/lib/boss-data"))["updateProjectAgentControls"];
|
||||
let updateDevice: (typeof import("../src/lib/boss-data"))["updateDevice"];
|
||||
let readState: (typeof import("../src/lib/boss-data"))["readState"];
|
||||
let createAuthSession: (typeof import("../src/lib/boss-data"))["createAuthSession"];
|
||||
let AUTH_SESSION_COOKIE = "";
|
||||
@@ -33,6 +34,7 @@ async function setup() {
|
||||
saveAiAccount = data.saveAiAccount;
|
||||
getProjectAgentControls = data.getProjectAgentControls;
|
||||
updateProjectAgentControls = data.updateProjectAgentControls;
|
||||
updateDevice = data.updateDevice;
|
||||
readState = data.readState;
|
||||
createAuthSession = data.createAuthSession;
|
||||
AUTH_SESSION_COOKIE = auth.AUTH_SESSION_COOKIE;
|
||||
@@ -357,6 +359,252 @@ test("master-agent 查询当前后端时直接走 fast path 返回后端摘要",
|
||||
assert.equal(reply?.senderLabel ?? "", "主Agent·gpt-5.4");
|
||||
});
|
||||
|
||||
test("master-agent 查询全局接管状态时直接走 fast path 返回当前状态", async () => {
|
||||
await saveAiAccount({
|
||||
accountId: "openai-takeover-status",
|
||||
label: "OpenAI 主模型",
|
||||
role: "primary",
|
||||
provider: "openai_api",
|
||||
displayName: "OpenAI 主模型",
|
||||
model: "gpt-5.4-mini",
|
||||
apiKey: "sk-openai-takeover-status",
|
||||
enabled: true,
|
||||
setActive: true,
|
||||
loginStatusNote: "用于全局接管状态查询测试。",
|
||||
});
|
||||
await updateProjectAgentControls(
|
||||
"master-agent",
|
||||
{
|
||||
globalTakeoverEnabled: true,
|
||||
},
|
||||
"17600003315",
|
||||
);
|
||||
|
||||
const response = await POST(
|
||||
await createAuthedRequest("master-agent", {
|
||||
body: "当前有没有开启主agent接管",
|
||||
}),
|
||||
{ params: Promise.resolve({ projectId: "master-agent" }) },
|
||||
);
|
||||
|
||||
assert.equal(response.status, 200);
|
||||
const payload = (await response.json()) as {
|
||||
ok: boolean;
|
||||
task?: { taskId: string } | null;
|
||||
masterReplyState?: "queued" | "running" | "completed" | null;
|
||||
};
|
||||
assert.equal(payload.ok, true);
|
||||
assert.equal(payload.task ?? null, null);
|
||||
assert.equal(payload.masterReplyState, "completed");
|
||||
|
||||
const state = await readState();
|
||||
const masterProject = state.projects.find((project) => project.id === "master-agent");
|
||||
const reply = masterProject?.messages.at(-1);
|
||||
assert.ok(reply);
|
||||
assert.match(reply?.body ?? "", /全局接管:开启/);
|
||||
assert.equal(reply?.senderLabel ?? "", "主Agent·gpt-5.4-mini");
|
||||
});
|
||||
|
||||
test("master-agent 可以直接通过 fast path 开启全局接管", async () => {
|
||||
await saveAiAccount({
|
||||
accountId: "openai-takeover-switch",
|
||||
label: "OpenAI 主模型",
|
||||
role: "primary",
|
||||
provider: "openai_api",
|
||||
displayName: "OpenAI 主模型",
|
||||
model: "gpt-5.4-mini",
|
||||
apiKey: "sk-openai-takeover-switch",
|
||||
enabled: true,
|
||||
setActive: true,
|
||||
loginStatusNote: "用于全局接管切换测试。",
|
||||
});
|
||||
|
||||
const response = await POST(
|
||||
await createAuthedRequest("master-agent", {
|
||||
body: "帮我开启全局接管",
|
||||
}),
|
||||
{ params: Promise.resolve({ projectId: "master-agent" }) },
|
||||
);
|
||||
|
||||
assert.equal(response.status, 200);
|
||||
const payload = (await response.json()) as {
|
||||
ok: boolean;
|
||||
task?: { taskId: string } | null;
|
||||
masterReplyState?: "queued" | "running" | "completed" | null;
|
||||
};
|
||||
assert.equal(payload.ok, true);
|
||||
assert.equal(payload.task ?? null, null);
|
||||
assert.equal(payload.masterReplyState, "completed");
|
||||
|
||||
const controls = await getProjectAgentControls("master-agent", "17600003315");
|
||||
assert.equal(controls?.globalTakeoverEnabled ?? null, true);
|
||||
|
||||
const state = await readState();
|
||||
const masterProject = state.projects.find((project) => project.id === "master-agent");
|
||||
const reply = masterProject?.messages.at(-1);
|
||||
assert.ok(reply);
|
||||
assert.match(reply?.body ?? "", /已开启全局接管/);
|
||||
});
|
||||
|
||||
test("master-agent 可以直接通过 fast path 切换默认后端到 Hermes", async () => {
|
||||
const previousEnv = {
|
||||
BOSS_HERMES_ENABLED: process.env.BOSS_HERMES_ENABLED,
|
||||
BOSS_HERMES_COMMAND: process.env.BOSS_HERMES_COMMAND,
|
||||
};
|
||||
process.env.BOSS_HERMES_ENABLED = "true";
|
||||
process.env.BOSS_HERMES_COMMAND = process.execPath;
|
||||
|
||||
await saveAiAccount({
|
||||
accountId: "openai-backend-switch",
|
||||
label: "OpenAI 主模型",
|
||||
role: "primary",
|
||||
provider: "openai_api",
|
||||
displayName: "OpenAI 主模型",
|
||||
model: "gpt-5.4",
|
||||
apiKey: "sk-openai-backend-switch",
|
||||
enabled: true,
|
||||
setActive: true,
|
||||
loginStatusNote: "用于后端切换测试。",
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await POST(
|
||||
await createAuthedRequest("master-agent", {
|
||||
body: "把默认后端切到 Hermes",
|
||||
}),
|
||||
{ params: Promise.resolve({ projectId: "master-agent" }) },
|
||||
);
|
||||
|
||||
assert.equal(response.status, 200);
|
||||
const payload = (await response.json()) as {
|
||||
ok: boolean;
|
||||
task?: { taskId: string } | null;
|
||||
masterReplyState?: "queued" | "running" | "completed" | null;
|
||||
};
|
||||
assert.equal(payload.ok, true);
|
||||
assert.equal(payload.task ?? null, null);
|
||||
assert.equal(payload.masterReplyState, "completed");
|
||||
|
||||
const controls = await getProjectAgentControls("master-agent", "17600003315");
|
||||
assert.equal(controls?.backendOverride ?? null, "hermes-runtime");
|
||||
|
||||
const state = await readState();
|
||||
const masterProject = state.projects.find((project) => project.id === "master-agent");
|
||||
const reply = masterProject?.messages.at(-1);
|
||||
assert.ok(reply);
|
||||
assert.match(reply?.body ?? "", /已把默认后端切到 hermes-runtime/i);
|
||||
} finally {
|
||||
process.env.BOSS_HERMES_ENABLED = previousEnv.BOSS_HERMES_ENABLED;
|
||||
process.env.BOSS_HERMES_COMMAND = previousEnv.BOSS_HERMES_COMMAND;
|
||||
}
|
||||
});
|
||||
|
||||
test("master-agent 查询默认执行模式时直接返回 GUI CLI 状态", async () => {
|
||||
await saveAiAccount({
|
||||
accountId: "master-codex-execution-mode",
|
||||
label: "主 GPT",
|
||||
role: "primary",
|
||||
provider: "master_codex_node",
|
||||
displayName: "Mac 上的 Master Codex Node",
|
||||
nodeId: "mac-studio",
|
||||
nodeLabel: "Mac Studio",
|
||||
model: "gpt-5.4",
|
||||
enabled: true,
|
||||
setActive: true,
|
||||
loginStatusNote: "用于执行模式查询测试。",
|
||||
});
|
||||
await updateDevice("mac-studio", {
|
||||
status: "online",
|
||||
preferredExecutionMode: "gui",
|
||||
capabilities: {
|
||||
gui: {
|
||||
connected: true,
|
||||
},
|
||||
cli: {
|
||||
connected: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const response = await POST(
|
||||
await createAuthedRequest("master-agent", {
|
||||
body: "现在默认走 GUI 还是 CLI",
|
||||
}),
|
||||
{ params: Promise.resolve({ projectId: "master-agent" }) },
|
||||
);
|
||||
|
||||
assert.equal(response.status, 200);
|
||||
const payload = (await response.json()) as {
|
||||
ok: boolean;
|
||||
task?: { taskId: string } | null;
|
||||
masterReplyState?: "queued" | "running" | "completed" | null;
|
||||
};
|
||||
assert.equal(payload.ok, true);
|
||||
assert.equal(payload.task ?? null, null);
|
||||
assert.equal(payload.masterReplyState, "completed");
|
||||
|
||||
const state = await readState();
|
||||
const masterProject = state.projects.find((project) => project.id === "master-agent");
|
||||
const reply = masterProject?.messages.at(-1);
|
||||
assert.ok(reply);
|
||||
assert.match(reply?.body ?? "", /默认执行模式:gui/i);
|
||||
assert.match(reply?.body ?? "", /GUI:在线/);
|
||||
assert.match(reply?.body ?? "", /CLI:在线/);
|
||||
});
|
||||
|
||||
test("master-agent 查询当前主节点设备状态时直接返回绑定设备在线信息", async () => {
|
||||
await saveAiAccount({
|
||||
accountId: "master-codex-device-status",
|
||||
label: "主 GPT",
|
||||
role: "primary",
|
||||
provider: "master_codex_node",
|
||||
displayName: "Mac 上的 Master Codex Node",
|
||||
nodeId: "mac-studio",
|
||||
nodeLabel: "Mac Studio",
|
||||
model: "gpt-5.4",
|
||||
enabled: true,
|
||||
setActive: true,
|
||||
loginStatusNote: "用于绑定设备状态查询测试。",
|
||||
});
|
||||
await updateDevice("mac-studio", {
|
||||
status: "online",
|
||||
capabilities: {
|
||||
gui: {
|
||||
connected: true,
|
||||
},
|
||||
cli: {
|
||||
connected: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const response = await POST(
|
||||
await createAuthedRequest("master-agent", {
|
||||
body: "当前主节点在线吗",
|
||||
}),
|
||||
{ params: Promise.resolve({ projectId: "master-agent" }) },
|
||||
);
|
||||
|
||||
assert.equal(response.status, 200);
|
||||
const payload = (await response.json()) as {
|
||||
ok: boolean;
|
||||
task?: { taskId: string } | null;
|
||||
masterReplyState?: "queued" | "running" | "completed" | null;
|
||||
};
|
||||
assert.equal(payload.ok, true);
|
||||
assert.equal(payload.task ?? null, null);
|
||||
assert.equal(payload.masterReplyState, "completed");
|
||||
|
||||
const state = await readState();
|
||||
const masterProject = state.projects.find((project) => project.id === "master-agent");
|
||||
const reply = masterProject?.messages.at(-1);
|
||||
assert.ok(reply);
|
||||
assert.match(reply?.body ?? "", /当前主节点设备:/);
|
||||
assert.match(reply?.body ?? "", /设备状态:online/);
|
||||
assert.match(reply?.body ?? "", /GUI:在线/);
|
||||
assert.match(reply?.body ?? "", /CLI:离线/);
|
||||
});
|
||||
|
||||
test("POST /api/v1/projects/master-agent/messages 快速返回队列态并在异步实际回复时继承当前会话覆盖", async () => {
|
||||
await saveAiAccount({
|
||||
accountId: "openai-master-agent-queue",
|
||||
|
||||
Reference in New Issue
Block a user