test: share claude cli error fixture

This commit is contained in:
Peter Steinberger
2026-04-18 22:15:01 +01:00
parent 966a3ea27c
commit d2c1b743c0
3 changed files with 44 additions and 62 deletions

View File

@@ -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);
});

View File

@@ -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,

View 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"),
};
}