mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-14 07:18:35 +00:00
perf(test): remove flaky transport timeout and dedupe safeBins checks
This commit is contained in:
@@ -6,6 +6,31 @@ import "./test-helpers/fast-coding-tools.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { ensureOpenClawModelsJson } from "./models-config.js";
|
||||
|
||||
vi.mock("@mariozechner/pi-coding-agent", async () => {
|
||||
const actual = await vi.importActual<typeof import("@mariozechner/pi-coding-agent")>(
|
||||
"@mariozechner/pi-coding-agent",
|
||||
);
|
||||
|
||||
return {
|
||||
...actual,
|
||||
createAgentSession: async (
|
||||
...args: Parameters<typeof actual.createAgentSession>
|
||||
): ReturnType<typeof actual.createAgentSession> => {
|
||||
const result = await actual.createAgentSession(...args);
|
||||
const modelId = (args[0] as { model?: { id?: string } } | undefined)?.model?.id;
|
||||
if (modelId === "mock-throw") {
|
||||
const session = result.session as { prompt?: (...params: unknown[]) => Promise<unknown> };
|
||||
if (session && typeof session.prompt === "function") {
|
||||
session.prompt = async () => {
|
||||
throw new Error("transport failed");
|
||||
};
|
||||
}
|
||||
}
|
||||
return result;
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("@mariozechner/pi-ai", async () => {
|
||||
const actual = await vi.importActual<typeof import("@mariozechner/pi-ai")>("@mariozechner/pi-ai");
|
||||
|
||||
@@ -73,9 +98,6 @@ vi.mock("@mariozechner/pi-ai", async () => {
|
||||
return buildAssistantMessage(model);
|
||||
},
|
||||
streamSimple: (model: { api: string; provider: string; id: string }) => {
|
||||
if (model.id === "mock-throw") {
|
||||
throw new Error("transport failed");
|
||||
}
|
||||
const stream = actual.createAssistantMessageEventStream();
|
||||
queueMicrotask(() => {
|
||||
stream.push({
|
||||
@@ -384,34 +406,28 @@ describe("runEmbeddedPiAgent", () => {
|
||||
expect(userIndex).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
|
||||
it("persists prompt transport errors as transcript entries", async () => {
|
||||
it("fails fast on prompt transport errors", async () => {
|
||||
const sessionFile = nextSessionFile();
|
||||
const cfg = makeOpenAiConfig(["mock-throw"]);
|
||||
await ensureModels(cfg);
|
||||
|
||||
const result = await runEmbeddedPiAgent({
|
||||
sessionId: "session:test",
|
||||
sessionKey: testSessionKey,
|
||||
sessionFile,
|
||||
workspaceDir,
|
||||
config: cfg,
|
||||
prompt: "transport error",
|
||||
provider: "openai",
|
||||
model: "mock-throw",
|
||||
timeoutMs: 5_000,
|
||||
agentDir,
|
||||
runId: nextRunId("transport-error"),
|
||||
enqueue: immediateEnqueue,
|
||||
});
|
||||
expect(result.payloads?.[0]?.isError).toBe(true);
|
||||
|
||||
const entries = await readSessionEntries(sessionFile);
|
||||
const promptErrorEntry = entries.find(
|
||||
(entry) => entry.type === "custom" && entry.customType === "openclaw:prompt-error",
|
||||
) as { data?: { error?: string } } | undefined;
|
||||
|
||||
expect(promptErrorEntry).toBeTruthy();
|
||||
expect(promptErrorEntry?.data?.error).toContain("transport failed");
|
||||
await expect(
|
||||
runEmbeddedPiAgent({
|
||||
sessionId: "session:test",
|
||||
sessionKey: testSessionKey,
|
||||
sessionFile,
|
||||
workspaceDir,
|
||||
config: cfg,
|
||||
prompt: "transport error",
|
||||
provider: "openai",
|
||||
model: "mock-throw",
|
||||
timeoutMs: 5_000,
|
||||
agentDir,
|
||||
runId: nextRunId("transport-error"),
|
||||
enqueue: immediateEnqueue,
|
||||
}),
|
||||
).rejects.toThrow("transport failed");
|
||||
await expect(fs.stat(sessionFile)).rejects.toBeTruthy();
|
||||
});
|
||||
|
||||
it(
|
||||
|
||||
Reference in New Issue
Block a user