feat(agent): improve investigation contracts and runtime readiness
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { streamPromptResponse } from "../../src/routes/chatStream.js";
|
||||
import type { OpencodeRuntimeAdapter } from "../../src/runtime/opencode.js";
|
||||
import { McpPreparationError, type OpencodeRuntimeAdapter } from "../../src/runtime/opencode.js";
|
||||
|
||||
type Output = { event: string; data: Record<string, unknown> };
|
||||
const textStart = { type: "message.part.updated", properties: { sessionID: "s", part: { id: "text", type: "text", text: "" } } };
|
||||
@@ -143,3 +143,21 @@ describe("stream stage boundaries", () => {
|
||||
expect(output.some((item) => item.event === "progress" && item.data.id === "query")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it("propagates MCP_NOT_READY without completing an artifact-free investigation", async () => {
|
||||
const output: Output[] = [];
|
||||
const failure = new McpPreparationError("等待业务工具目录就绪超时");
|
||||
let completionChecks = 0;
|
||||
const runtime = createRuntime({ [Symbol.asyncIterator]: () => ({
|
||||
next: () => new Promise<IteratorResult<unknown>>(() => {}),
|
||||
return: async () => ({ done: true as const, value: undefined }),
|
||||
}) }, { prompt: async () => { throw failure; } });
|
||||
let caught: unknown;
|
||||
try { await run(runtime, output, { beforeIdle: async () => { completionChecks++; return true; } }); }
|
||||
catch (error) { caught = error; }
|
||||
expect(caught).toBe(failure);
|
||||
expect(caught).toMatchObject({ code: "MCP_NOT_READY" });
|
||||
expect(completionChecks).toBe(0);
|
||||
expect(output.some((item) => ["tool_call", "final_answer", "done"].includes(item.event))).toBe(false);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user