Skip to content

The open-source app everyone uses to manage agents at work

test(cli): cover board prompt handoff (#9137)

馨冉99a1b5c83b02
diff --git a/cli/src/__tests__/prompt.test.ts b/cli/src/__tests__/prompt.test.ts
index 21f3a78b14..d7e1cbbfe2 100644
--- a/cli/src/__tests__/prompt.test.ts
+++ b/cli/src/__tests__/prompt.test.ts
@@ -3,7 +3,7 @@ import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { writeContext } from "../client/context.js";
-import { runAgentPrompt } from "../commands/client/prompt.js";
+import { runAgentPrompt, runBoardPrompt } from "../commands/client/prompt.js";
const ORIGINAL_ENV = { ...process.env };
@@ -99,4 +99,99 @@ describe("prompt handoff", () => {
});
expect(fetchMock.mock.calls[2]?.[0]).toBe("http://localhost:3100/api/agents/11111111-1111-4111-8111-111111111111/wakeup");
});
+
+ it("fails when a board prompt uses an agent persona profile", async () => {
+ const contextPath = createTempContextPath();
+ writeContext(
+ {
+ version: 2,
+ currentProfile: "agent",
+ profiles: {
+ agent: {
+ apiBase: "http://localhost:3100",
+ companyId: "22222222-2222-4222-8222-222222222222",
+ persona: "agent",
+ agentId: "11111111-1111-4111-8111-111111111111",
+ },
+ },
+ },
+ contextPath,
+ );
+
+ await expect(runBoardPrompt("worker", "Do the work", {
+ context: contextPath,
+ apiKey: "board-token",
+ })).rejects.toThrow(/persona=agent/);
+ });
+
+ it("creates an assigned issue and wakes the target agent with board auth", async () => {
+ const fetchMock = vi
+ .fn()
+ .mockResolvedValueOnce(new Response(JSON.stringify(agent()), { status: 200 }))
+ .mockResolvedValueOnce(new Response(JSON.stringify({
+ id: "issue-1",
+ companyId: "22222222-2222-4222-8222-222222222222",
+ title: "Investigate queue lag",
+ status: "todo",
+ priority: "medium",
+ assigneeAgentId: "11111111-1111-4111-8111-111111111111",
+ }), { status: 201 }))
+ .mockResolvedValueOnce(new Response(JSON.stringify({ id: "run-1", status: "queued" }), { status: 202 }));
+ vi.stubGlobal("fetch", fetchMock);
+
+ const result = await runBoardPrompt("worker", "Investigate queue lag", {
+ apiBase: "http://localhost:3100",
+ apiKey: "board-token",
+ companyId: "22222222-2222-4222-8222-222222222222",
+ });
+
+ expect(result.actor).toBe("board");
+ expect(result.mode).toBe("issue");
+ expect(result.agent.id).toBe("11111111-1111-4111-8111-111111111111");
+ expect(fetchMock).toHaveBeenCalledTimes(3);
+ expect(fetchMock.mock.calls[0]?.[0]).toBe(
+ "http://localhost:3100/api/agents/worker?companyId=22222222-2222-4222-8222-222222222222",
+ );
+ expect(fetchMock.mock.calls[1]?.[0]).toBe(
+ "http://localhost:3100/api/companies/22222222-2222-4222-8222-222222222222/issues",
+ );
+ expect(JSON.parse(String(fetchMock.mock.calls[1]?.[1]?.body))).toMatchObject({
+ assigneeAgentId: "11111111-1111-4111-8111-111111111111",
+ description: "Investigate queue lag",
+ title: "Investigate queue lag",
+ });
+ expect(fetchMock.mock.calls[2]?.[0]).toBe(
+ "http://localhost:3100/api/agents/11111111-1111-4111-8111-111111111111/wakeup",
+ );
+ });
+
+ it("adds a board-authored prompt comment without waking when disabled", async () => {
+ const fetchMock = vi
+ .fn()
+ .mockResolvedValueOnce(new Response(JSON.stringify(agent()), { status: 200 }))
+ .mockResolvedValueOnce(new Response(JSON.stringify({
+ id: "comment-1",
+ issueId: "issue-1",
+ body: "Follow up on queue lag",
+ }), { status: 201 }));
+ vi.stubGlobal("fetch", fetchMock);
+
+ const result = await runBoardPrompt("worker", "Follow up on queue lag", {
+ apiBase: "http://localhost:3100",
+ apiKey: "board-token",
+ companyId: "22222222-2222-4222-8222-222222222222",
+ issue: "issue-1",
+ wake: false,
+ });
+
+ expect(result.actor).toBe("board");
+ expect(result.mode).toBe("comment");
+ expect(result.wakeup).toBeNull();
+ expect(fetchMock).toHaveBeenCalledTimes(2);
+ expect(fetchMock.mock.calls[1]?.[0]).toBe("http://localhost:3100/api/issues/issue-1/comments");
+ expect(JSON.parse(String(fetchMock.mock.calls[1]?.[1]?.body))).toMatchObject({
+ body: "Follow up on queue lag",
+ resume: false,
+ });
+ });
});