mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 08:20:43 +00:00
test: share claude cli error fixture
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
parseCliJson,
|
||||
parseCliJsonl,
|
||||
} from "./cli-output.js";
|
||||
import { createClaudeApiErrorFixture } from "./test-helpers/claude-api-error-fixture.js";
|
||||
|
||||
describe("parseCliJson", () => {
|
||||
it("recovers mixed-output Claude session metadata from embedded JSON objects", () => {
|
||||
@@ -313,38 +314,8 @@ describe("parseCliJsonl", () => {
|
||||
});
|
||||
|
||||
it("extracts nested Claude API errors from failed stream-json output", () => {
|
||||
const message =
|
||||
"Third-party apps now draw from your extra usage, not your plan limits. We've added a $200 credit to get you started. Claim it at claude.ai/settings/usage and keep going.";
|
||||
const apiError = `API Error: 400 ${JSON.stringify({
|
||||
type: "error",
|
||||
error: {
|
||||
type: "invalid_request_error",
|
||||
message,
|
||||
},
|
||||
request_id: "req_011CZqHuXhFetYCnr8325DQc",
|
||||
})}`;
|
||||
const result = extractCliErrorMessage(
|
||||
[
|
||||
JSON.stringify({ type: "system", subtype: "init", session_id: "session-api-error" }),
|
||||
JSON.stringify({
|
||||
type: "assistant",
|
||||
message: {
|
||||
model: "<synthetic>",
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: apiError }],
|
||||
},
|
||||
session_id: "session-api-error",
|
||||
error: "unknown",
|
||||
}),
|
||||
JSON.stringify({
|
||||
type: "result",
|
||||
subtype: "success",
|
||||
is_error: true,
|
||||
result: apiError,
|
||||
session_id: "session-api-error",
|
||||
}),
|
||||
].join("\n"),
|
||||
);
|
||||
const { message, jsonl } = createClaudeApiErrorFixture();
|
||||
const result = extractCliErrorMessage(jsonl);
|
||||
|
||||
expect(result).toBe(message);
|
||||
});
|
||||
|
||||
@@ -18,6 +18,7 @@ import { buildCliEnvAuthLog, executePreparedCliRun } from "./cli-runner/execute.
|
||||
import { buildSystemPrompt } from "./cli-runner/helpers.js";
|
||||
import { setCliRunnerPrepareTestDeps } from "./cli-runner/prepare.js";
|
||||
import type { PreparedCliRunContext } from "./cli-runner/types.js";
|
||||
import { createClaudeApiErrorFixture } from "./test-helpers/claude-api-error-fixture.js";
|
||||
|
||||
beforeEach(() => {
|
||||
resetAgentEventsForTest();
|
||||
@@ -619,16 +620,7 @@ describe("runCliAgent spawn path", () => {
|
||||
});
|
||||
|
||||
it("surfaces nested Claude stream-json API errors instead of raw event output", async () => {
|
||||
const message =
|
||||
"Third-party apps now draw from your extra usage, not your plan limits. We've added a $200 credit to get you started. Claim it at claude.ai/settings/usage and keep going.";
|
||||
const apiError = `API Error: 400 ${JSON.stringify({
|
||||
type: "error",
|
||||
error: {
|
||||
type: "invalid_request_error",
|
||||
message,
|
||||
},
|
||||
request_id: "req_011CZqHuXhFetYCnr8325DQc",
|
||||
})}`;
|
||||
const { message, jsonl } = createClaudeApiErrorFixture();
|
||||
|
||||
supervisorSpawnMock.mockResolvedValueOnce(
|
||||
createManagedRun({
|
||||
@@ -636,26 +628,7 @@ describe("runCliAgent spawn path", () => {
|
||||
exitCode: 1,
|
||||
exitSignal: null,
|
||||
durationMs: 50,
|
||||
stdout: [
|
||||
JSON.stringify({ type: "system", subtype: "init", session_id: "session-api-error" }),
|
||||
JSON.stringify({
|
||||
type: "assistant",
|
||||
message: {
|
||||
model: "<synthetic>",
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: apiError }],
|
||||
},
|
||||
session_id: "session-api-error",
|
||||
error: "unknown",
|
||||
}),
|
||||
JSON.stringify({
|
||||
type: "result",
|
||||
subtype: "success",
|
||||
is_error: true,
|
||||
result: apiError,
|
||||
session_id: "session-api-error",
|
||||
}),
|
||||
].join("\n"),
|
||||
stdout: jsonl,
|
||||
stderr: "",
|
||||
timedOut: false,
|
||||
noOutputTimedOut: false,
|
||||
|
||||
38
src/agents/test-helpers/claude-api-error-fixture.ts
Normal file
38
src/agents/test-helpers/claude-api-error-fixture.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
export const CLAUDE_API_ERROR_MESSAGE =
|
||||
"Third-party apps now draw from your extra usage, not your plan limits. We've added a $200 credit to get you started. Claim it at claude.ai/settings/usage and keep going.";
|
||||
|
||||
export function createClaudeApiErrorFixture() {
|
||||
const apiError = `API Error: 400 ${JSON.stringify({
|
||||
type: "error",
|
||||
error: {
|
||||
type: "invalid_request_error",
|
||||
message: CLAUDE_API_ERROR_MESSAGE,
|
||||
},
|
||||
request_id: "req_011CZqHuXhFetYCnr8325DQc",
|
||||
})}`;
|
||||
|
||||
return {
|
||||
message: CLAUDE_API_ERROR_MESSAGE,
|
||||
apiError,
|
||||
jsonl: [
|
||||
JSON.stringify({ type: "system", subtype: "init", session_id: "session-api-error" }),
|
||||
JSON.stringify({
|
||||
type: "assistant",
|
||||
message: {
|
||||
model: "<synthetic>",
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: apiError }],
|
||||
},
|
||||
session_id: "session-api-error",
|
||||
error: "unknown",
|
||||
}),
|
||||
JSON.stringify({
|
||||
type: "result",
|
||||
subtype: "success",
|
||||
is_error: true,
|
||||
result: apiError,
|
||||
session_id: "session-api-error",
|
||||
}),
|
||||
].join("\n"),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user