mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-10 09:52:54 +00:00
Merged via squash.
Prepared head SHA: 06a3a82816
Co-authored-by: stainlu <109842185+stainlu@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
73 lines
2.5 KiB
TypeScript
73 lines
2.5 KiB
TypeScript
import { beforeAll, beforeEach, describe, expect, it } from "vitest";
|
|
import { makeAssistantMessageFixture } from "../test-helpers/assistant-message-fixtures.js";
|
|
import { makeModelFallbackCfg } from "../test-helpers/model-fallback-config-fixture.js";
|
|
import { makeAttemptResult } from "./run.overflow-compaction.fixture.js";
|
|
import {
|
|
loadRunOverflowCompactionHarness,
|
|
MockedFailoverError,
|
|
mockedClassifyFailoverReason,
|
|
mockedFormatAssistantErrorText,
|
|
mockedGlobalHookRunner,
|
|
mockedIsFailoverAssistantError,
|
|
mockedRunEmbeddedAttempt,
|
|
overflowBaseRunParams,
|
|
resetRunOverflowCompactionHarnessMocks,
|
|
} from "./run.overflow-compaction.harness.js";
|
|
|
|
let runEmbeddedPiAgent: typeof import("./run.js").runEmbeddedPiAgent;
|
|
|
|
describe("runEmbeddedPiAgent Codex server_error fallback handoff", () => {
|
|
beforeAll(async () => {
|
|
({ runEmbeddedPiAgent } = await loadRunOverflowCompactionHarness());
|
|
});
|
|
|
|
beforeEach(() => {
|
|
resetRunOverflowCompactionHarnessMocks();
|
|
mockedGlobalHookRunner.hasHooks.mockImplementation(() => false);
|
|
});
|
|
|
|
it("throws FailoverError for Codex server_error when model fallbacks are configured", async () => {
|
|
const rawCodexError =
|
|
'Codex error: {"type":"error","error":{"type":"server_error","code":"server_error","message":"An error occurred while processing your request."},"sequence_number":2}';
|
|
|
|
mockedClassifyFailoverReason.mockReturnValue("timeout");
|
|
mockedIsFailoverAssistantError.mockReturnValue(true);
|
|
mockedFormatAssistantErrorText.mockReturnValue(
|
|
"LLM error server_error: An error occurred while processing your request.",
|
|
);
|
|
const currentAttemptAssistant = makeAssistantMessageFixture({
|
|
stopReason: "error",
|
|
errorMessage: rawCodexError,
|
|
provider: "openai-codex",
|
|
model: "gpt-5.4",
|
|
});
|
|
mockedRunEmbeddedAttempt.mockResolvedValueOnce(
|
|
makeAttemptResult({
|
|
assistantTexts: [],
|
|
lastAssistant: currentAttemptAssistant,
|
|
currentAttemptAssistant,
|
|
}),
|
|
);
|
|
|
|
const promise = runEmbeddedPiAgent({
|
|
...overflowBaseRunParams,
|
|
runId: "run-codex-server-error-fallback",
|
|
config: makeModelFallbackCfg({
|
|
agents: {
|
|
defaults: {
|
|
model: {
|
|
primary: "openai-codex/gpt-5.4",
|
|
fallbacks: ["anthropic/claude-opus-4-6"],
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
});
|
|
|
|
await expect(promise).rejects.toBeInstanceOf(MockedFailoverError);
|
|
await expect(promise).rejects.toThrow(
|
|
"LLM error server_error: An error occurred while processing your request.",
|
|
);
|
|
});
|
|
});
|