fix: preserve investigation execution history by round
This commit is contained in:
@@ -138,6 +138,76 @@ describe("Agent API client sessions", () => {
|
||||
await expect(createAgentApiClient("http://agent.local").loadSession("missing")).resolves.toBeNull();
|
||||
});
|
||||
|
||||
it("loads a task execution history through its exact task and run binding", async () => {
|
||||
const fetchMock = vi.fn(async (..._args: Parameters<typeof fetch>) => Response.json({
|
||||
id: "execution-session",
|
||||
session_id: "execution-session",
|
||||
title: "南桥管道爆管调查 · 执行记录",
|
||||
purpose: "task_execution",
|
||||
task_id: "50000000-0000-4000-8000-000000000001",
|
||||
created_at: "2026-10-30T01:00:00Z",
|
||||
updated_at: "2026-10-30T01:05:00Z",
|
||||
messages: [{ id: "assistant", role: "assistant", parts: [{ type: "text", text: "调查完成" }] }],
|
||||
is_streaming: false,
|
||||
run_status: "completed"
|
||||
}));
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
const client = createAgentApiClient("http://agent.local", {
|
||||
getAccessToken: async () => "token",
|
||||
getProjectId: async () => "project"
|
||||
});
|
||||
|
||||
const loaded = await client.loadTaskExecutionSession(
|
||||
"50000000-0000-4000-8000-000000000001",
|
||||
"70000000-0000-4000-8000-000000000001",
|
||||
"execution-session"
|
||||
);
|
||||
|
||||
expect(loaded).toMatchObject({
|
||||
sessionId: "execution-session",
|
||||
title: "南桥管道爆管调查 · 执行记录",
|
||||
purpose: "task_execution",
|
||||
taskId: "50000000-0000-4000-8000-000000000001",
|
||||
runStatus: "completed"
|
||||
});
|
||||
const url = new URL(String(fetchMock.mock.calls[0]?.[0]));
|
||||
expect(url.pathname).toBe("/api/v1/task/50000000-0000-4000-8000-000000000001/execution-session");
|
||||
expect(url.searchParams.get("run_id")).toBe("70000000-0000-4000-8000-000000000001");
|
||||
expect(url.searchParams.get("session_id")).toBe("execution-session");
|
||||
const headers = new Headers(fetchMock.mock.calls[0]?.[1]?.headers);
|
||||
expect(headers.get("Authorization")).toBe("Bearer token");
|
||||
expect(headers.get("X-Project-Id")).toBe("project");
|
||||
});
|
||||
|
||||
it("creates a debug branch bound to an exact task execution history", async () => {
|
||||
const fetchMock = vi.fn(async (..._args: Parameters<typeof fetch>) => Response.json({
|
||||
session_id: "debug-session",
|
||||
title: "南桥管道爆管调查 · 调试",
|
||||
purpose: "task_collaboration",
|
||||
task_id: "50000000-0000-4000-8000-000000000001",
|
||||
parent_session_id: "execution-session",
|
||||
created: true
|
||||
}, { status: 201 }));
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
const client = createAgentApiClient("http://agent.local", {
|
||||
getAccessToken: async () => "token",
|
||||
getProjectId: async () => "project"
|
||||
});
|
||||
|
||||
await expect(client.createTaskExecutionDebugSession(
|
||||
"50000000-0000-4000-8000-000000000001",
|
||||
"70000000-0000-4000-8000-000000000001",
|
||||
"execution-session"
|
||||
)).resolves.toMatchObject({ session_id: "debug-session", purpose: "task_collaboration" });
|
||||
|
||||
const [url, init] = fetchMock.mock.calls[0] ?? [];
|
||||
expect(new URL(String(url)).pathname).toBe("/api/v1/task/50000000-0000-4000-8000-000000000001/execution-session/debug");
|
||||
expect(JSON.parse(String(init?.body))).toEqual({
|
||||
run_id: "70000000-0000-4000-8000-000000000001",
|
||||
session_id: "execution-session"
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back when a candidate is not the agent service", async () => {
|
||||
const fetchMock = vi
|
||||
.fn()
|
||||
|
||||
Reference in New Issue
Block a user