mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
* feat: add structured output support Add support for Agent SDK structured outputs. New input: json_schema Output: structured_output (JSON string) Access: fromJSON(steps.id.outputs.structured_output).field Docs: https://docs.claude.com/en/docs/agent-sdk/structured-outputs * rm unused * refactor: simplify structured outputs to use claude_args Remove json_schema input in favor of passing --json-schema flag directly in claude_args. This simplifies the interface by treating structured outputs like other CLI flags (--model, --max-turns, etc.) instead of as a special input that gets injected. Users now specify: claude_args: '--json-schema {...}' Instead of separate: json_schema: {...} 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * chore: remove unused json-schema util and revert version - Remove src/utils/json-schema.ts (no longer used after refactor) - Revert Claude Code version from 2.0.45 back to 2.0.42 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
97 lines
2.8 KiB
TypeScript
97 lines
2.8 KiB
TypeScript
#!/usr/bin/env bun
|
|
|
|
import { describe, test, expect } from "bun:test";
|
|
import { prepareRunConfig, type ClaudeOptions } from "../src/run-claude";
|
|
|
|
describe("prepareRunConfig", () => {
|
|
test("should prepare config with basic arguments", () => {
|
|
const options: ClaudeOptions = {};
|
|
const prepared = prepareRunConfig("/tmp/test-prompt.txt", options);
|
|
|
|
expect(prepared.claudeArgs).toEqual([
|
|
"-p",
|
|
"--verbose",
|
|
"--output-format",
|
|
"stream-json",
|
|
]);
|
|
});
|
|
|
|
test("should include promptPath", () => {
|
|
const options: ClaudeOptions = {};
|
|
const prepared = prepareRunConfig("/tmp/test-prompt.txt", options);
|
|
|
|
expect(prepared.promptPath).toBe("/tmp/test-prompt.txt");
|
|
});
|
|
|
|
test("should use provided prompt path", () => {
|
|
const options: ClaudeOptions = {};
|
|
const prepared = prepareRunConfig("/custom/prompt/path.txt", options);
|
|
|
|
expect(prepared.promptPath).toBe("/custom/prompt/path.txt");
|
|
});
|
|
|
|
describe("claudeArgs handling", () => {
|
|
test("should parse and include custom claude arguments", () => {
|
|
const options: ClaudeOptions = {
|
|
claudeArgs: "--max-turns 10 --model claude-3-opus-20240229",
|
|
};
|
|
const prepared = prepareRunConfig("/tmp/test-prompt.txt", options);
|
|
|
|
expect(prepared.claudeArgs).toEqual([
|
|
"-p",
|
|
"--max-turns",
|
|
"10",
|
|
"--model",
|
|
"claude-3-opus-20240229",
|
|
"--verbose",
|
|
"--output-format",
|
|
"stream-json",
|
|
]);
|
|
});
|
|
|
|
test("should handle empty claudeArgs", () => {
|
|
const options: ClaudeOptions = {
|
|
claudeArgs: "",
|
|
};
|
|
const prepared = prepareRunConfig("/tmp/test-prompt.txt", options);
|
|
|
|
expect(prepared.claudeArgs).toEqual([
|
|
"-p",
|
|
"--verbose",
|
|
"--output-format",
|
|
"stream-json",
|
|
]);
|
|
});
|
|
|
|
test("should handle claudeArgs with quoted strings", () => {
|
|
const options: ClaudeOptions = {
|
|
claudeArgs: '--system-prompt "You are a helpful assistant"',
|
|
};
|
|
const prepared = prepareRunConfig("/tmp/test-prompt.txt", options);
|
|
|
|
expect(prepared.claudeArgs).toEqual([
|
|
"-p",
|
|
"--system-prompt",
|
|
"You are a helpful assistant",
|
|
"--verbose",
|
|
"--output-format",
|
|
"stream-json",
|
|
]);
|
|
});
|
|
|
|
test("should include json-schema flag when provided", () => {
|
|
const options: ClaudeOptions = {
|
|
claudeArgs:
|
|
'--json-schema \'{"type":"object","properties":{"result":{"type":"boolean"}}}\'',
|
|
};
|
|
|
|
const prepared = prepareRunConfig("/tmp/test-prompt.txt", options);
|
|
|
|
expect(prepared.claudeArgs).toContain("--json-schema");
|
|
expect(prepared.claudeArgs).toContain(
|
|
'{"type":"object","properties":{"result":{"type":"boolean"}}}',
|
|
);
|
|
});
|
|
});
|
|
});
|