mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-08-22 03:18:54 +08:00
fix(sdk): fail step when result has is_error:true despite success subtype (#1496)
Treat subtype success with is_error:true as a failed run so CI does not show a misleading green check when the review never actually ran. Fixes #1495 Co-authored-by: syf2211 <syf2211@users.noreply.github.com>
This commit is contained in:
@@ -63,4 +63,69 @@ describe("runClaudeWithSdk", () => {
|
||||
consoleLogSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
test("fails when result subtype is success but is_error is true", async () => {
|
||||
const consoleErrorSpy = spyOn(console, "error").mockImplementation(
|
||||
() => {},
|
||||
);
|
||||
const consoleLogSpy = spyOn(console, "log").mockImplementation(() => {});
|
||||
const coreErrorSpy = spyOn(
|
||||
await import("@actions/core"),
|
||||
"error",
|
||||
).mockImplementation(() => {});
|
||||
|
||||
tempDir = await mkdtemp(join(tmpdir(), "claude-sdk-"));
|
||||
process.env.RUNNER_TEMP = tempDir;
|
||||
|
||||
const promptPath = join(tempDir, "prompt.txt");
|
||||
await writeFile(promptPath, "test prompt");
|
||||
|
||||
const initMessage = {
|
||||
type: "system",
|
||||
subtype: "init",
|
||||
session_id: "session-123",
|
||||
model: "claude-sonnet-5",
|
||||
};
|
||||
|
||||
const errorResultMessage = {
|
||||
type: "result",
|
||||
subtype: "success",
|
||||
is_error: true,
|
||||
duration_ms: 434,
|
||||
num_turns: 1,
|
||||
total_cost_usd: 0,
|
||||
permission_denials: [],
|
||||
};
|
||||
|
||||
mock.module("@anthropic-ai/claude-agent-sdk", () => ({
|
||||
query: async function* () {
|
||||
yield initMessage;
|
||||
yield errorResultMessage;
|
||||
},
|
||||
}));
|
||||
|
||||
try {
|
||||
const { runClaudeWithSdk } = await import("../src/run-claude-sdk");
|
||||
|
||||
await expect(
|
||||
runClaudeWithSdk(promptPath, {
|
||||
sdkOptions: {},
|
||||
showFullOutput: false,
|
||||
hasJsonSchema: false,
|
||||
}),
|
||||
).rejects.toThrow("result is_error:true");
|
||||
|
||||
const executionFile = join(tempDir, "claude-execution-output.json");
|
||||
await expect(readFile(executionFile, "utf-8")).resolves.toBe(
|
||||
JSON.stringify([initMessage, errorResultMessage], null, 2),
|
||||
);
|
||||
expect(coreErrorSpy).toHaveBeenCalledWith(
|
||||
"Claude result reported subtype success with is_error:true (run did not complete successfully)",
|
||||
);
|
||||
} finally {
|
||||
consoleErrorSpy.mockRestore();
|
||||
consoleLogSpy.mockRestore();
|
||||
coreErrorSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user