mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 14:40:43 +00:00
test: share claude cli error fixture
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
|||||||
parseCliJson,
|
parseCliJson,
|
||||||
parseCliJsonl,
|
parseCliJsonl,
|
||||||
} from "./cli-output.js";
|
} from "./cli-output.js";
|
||||||
|
import { createClaudeApiErrorFixture } from "./test-helpers/claude-api-error-fixture.js";
|
||||||
|
|
||||||
describe("parseCliJson", () => {
|
describe("parseCliJson", () => {
|
||||||
it("recovers mixed-output Claude session metadata from embedded JSON objects", () => {
|
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", () => {
|
it("extracts nested Claude API errors from failed stream-json output", () => {
|
||||||
const message =
|
const { message, jsonl } = createClaudeApiErrorFixture();
|
||||||
"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 result = extractCliErrorMessage(jsonl);
|
||||||
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"),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result).toBe(message);
|
expect(result).toBe(message);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import { buildCliEnvAuthLog, executePreparedCliRun } from "./cli-runner/execute.
|
|||||||
import { buildSystemPrompt } from "./cli-runner/helpers.js";
|
import { buildSystemPrompt } from "./cli-runner/helpers.js";
|
||||||
import { setCliRunnerPrepareTestDeps } from "./cli-runner/prepare.js";
|
import { setCliRunnerPrepareTestDeps } from "./cli-runner/prepare.js";
|
||||||
import type { PreparedCliRunContext } from "./cli-runner/types.js";
|
import type { PreparedCliRunContext } from "./cli-runner/types.js";
|
||||||
|
import { createClaudeApiErrorFixture } from "./test-helpers/claude-api-error-fixture.js";
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
resetAgentEventsForTest();
|
resetAgentEventsForTest();
|
||||||
@@ -619,16 +620,7 @@ describe("runCliAgent spawn path", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("surfaces nested Claude stream-json API errors instead of raw event output", async () => {
|
it("surfaces nested Claude stream-json API errors instead of raw event output", async () => {
|
||||||
const message =
|
const { message, jsonl } = createClaudeApiErrorFixture();
|
||||||
"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",
|
|
||||||
})}`;
|
|
||||||
|
|
||||||
supervisorSpawnMock.mockResolvedValueOnce(
|
supervisorSpawnMock.mockResolvedValueOnce(
|
||||||
createManagedRun({
|
createManagedRun({
|
||||||
@@ -636,26 +628,7 @@ describe("runCliAgent spawn path", () => {
|
|||||||
exitCode: 1,
|
exitCode: 1,
|
||||||
exitSignal: null,
|
exitSignal: null,
|
||||||
durationMs: 50,
|
durationMs: 50,
|
||||||
stdout: [
|
stdout: 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"),
|
|
||||||
stderr: "",
|
stderr: "",
|
||||||
timedOut: false,
|
timedOut: false,
|
||||||
noOutputTimedOut: 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