Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/cli-live-smoke.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: CLI Live Smoke

on:
pull_request:
paths:
- "tools/cli/**"
- ".github/workflows/cli-live-smoke.yml"
push:
branches:
- main
paths:
- "tools/cli/**"
- ".github/workflows/cli-live-smoke.yml"
workflow_dispatch:

permissions:
contents: read

concurrency:
group: cli-live-smoke-${{ github.ref }}
cancel-in-progress: true

jobs:
live-smoke:
name: Harness live smoke (vitest)
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
working-directory: tools/cli
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: tools/cli/package-lock.json

- name: Install dependencies
run: npm ci

- name: Build CLI
run: npm run build

- name: Run harness live smoke
run: npm run test:live
24 changes: 15 additions & 9 deletions tools/cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion tools/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"build": "npm run clean && tsc -p tsconfig.build.json",
"typecheck": "tsc -p tsconfig.json --noEmit",
"test": "vitest --run",
"test:live": "vitest --run --config vitest.live.config.ts",
"smoke:harness": "node scripts/smoke-harness.mjs",
"dev": "tsx src/index.ts",
"clean": "rm -rf dist",
Expand All @@ -68,7 +69,7 @@
"node": ">=18.14.1"
},
"dependencies": {
"@anthropic-ai/claude-agent-sdk": "^0.2.90",
"@anthropic-ai/claude-agent-sdk": "0.2.107",
"@hono/node-server": "^1.19.14",
"@oclif/core": "^4.10.6",
"@openai/codex-sdk": "^0.125.0",
Expand All @@ -79,5 +80,8 @@
"tsx": "^4.19.2",
"typescript": "^5.7.3",
"vitest": "^3.2.4"
},
"overrides": {
"@anthropic-ai/sdk": "^0.92.0"
}
}
3 changes: 3 additions & 0 deletions tools/cli/src/harnesses/claude-sdk.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CLAUDE_SDK_DEFAULTS, resolveClaudeModel } from "./defaults.js";
import { writeLine } from "./streams.js";
import type { Harness, HarnessRunOptions } from "./types.js";

Expand Down Expand Up @@ -27,6 +28,8 @@ export function createClaudeSdkHarness(options: ClaudeSdkHarnessOptions = {}): H
prompt,
options: {
abortController,
model: resolveClaudeModel(runOptions.env),
thinking: CLAUDE_SDK_DEFAULTS.thinking,
...(runOptions.additionalDirectories === undefined
? {}
: { additionalDirectories: runOptions.additionalDirectories }),
Expand Down
10 changes: 6 additions & 4 deletions tools/cli/src/harnesses/codex-sdk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { codexClientConfig, codexThreadRuntimeOptions } from "./codex-options.js";
import { resolveCodexModel } from "./defaults.js";
import { writeLine } from "./streams.js";
import type { CodexSdkClientOptions, CodexSdkFactory, CodexThreadEvent, CodexThreadItem, Harness } from "./types.js";

Expand All @@ -19,9 +20,10 @@ export function createCodexSdkHarness(options: CodexSdkHarnessOptions = {}): Har
async run(prompt, runOptions) {
try {
const env = definedEnv(runOptions.env);
const model = resolveCodexModel(runOptions.env);
const codex = await factory(codexClientOptions(env, runOptions.systemPromptAppend));
const thread = codex.startThread(
codexThreadOptions(runOptions.cwd, env, runOptions.additionalDirectories),
codexThreadOptions(runOptions.cwd, env, runOptions.additionalDirectories, model),
);
const { events } = await thread.runStreamed(
prompt,
Expand All @@ -48,14 +50,14 @@ function codexThreadOptions(
cwd: string | undefined,
env: Record<string, string> | undefined,
additionalDirectories: readonly string[] | undefined,
model: string,
) {
const runtimeOptions = codexThreadRuntimeOptions(env, additionalDirectories);
const options = {
return {
model,
...(cwd === undefined ? {} : { workingDirectory: cwd }),
...runtimeOptions,
};

return Object.keys(options).length === 0 ? undefined : options;
}

function codexClientOptions(env: Record<string, string> | undefined, systemPromptAppend: string | undefined) {
Expand Down
16 changes: 16 additions & 0 deletions tools/cli/src/harnesses/defaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const CLAUDE_SDK_DEFAULTS = {
model: "claude-sonnet-4-6",
thinking: { type: "adaptive" as const },
} as const;

export const CODEX_SDK_DEFAULTS = {
model: "gpt-5-codex",
} as const;

export function resolveClaudeModel(env: Record<string, string | undefined> | undefined): string {
return env?.ANTHROPIC_MODEL ?? process.env.ANTHROPIC_MODEL ?? CLAUDE_SDK_DEFAULTS.model;
}

export function resolveCodexModel(env: Record<string, string | undefined> | undefined): string {
return env?.OPENAI_MODEL ?? env?.CODEX_MODEL ?? process.env.OPENAI_MODEL ?? process.env.CODEX_MODEL ?? CODEX_SDK_DEFAULTS.model;
}
40 changes: 38 additions & 2 deletions tools/cli/tests/harnesses/harnesses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe("codex-sdk harness", () => {

expect(exitCode).toBe(0);
expect(io.stdout).toBe("sdk output\n");
expect(starts).toEqual([{ skipGitRepoCheck: true, workingDirectory: "/repo" }]);
expect(starts).toEqual([{ model: "gpt-5-codex", skipGitRepoCheck: true, workingDirectory: "/repo" }]);
expect(factoryOptions).toEqual([{ apiKey: "test", env: { OPENAI_API_KEY: "test" } }]);
});

Expand Down Expand Up @@ -127,6 +127,7 @@ describe("codex-sdk harness", () => {
expect(starts).toEqual([
{
additionalDirectories: ["/skills/open-prose"],
model: "gpt-5-codex",
skipGitRepoCheck: true,
},
]);
Expand Down Expand Up @@ -166,7 +167,9 @@ describe("codex-sdk harness", () => {
});

expect(exitCode).toBe(0);
expect(starts).toEqual([{ approvalPolicy: "never", sandboxMode: "danger-full-access", skipGitRepoCheck: true }]);
expect(starts).toEqual([
{ approvalPolicy: "never", model: "gpt-5-codex", sandboxMode: "danger-full-access", skipGitRepoCheck: true },
]);
});

test("maps failed turns to stderr and nonzero exit", async () => {
Expand Down Expand Up @@ -219,6 +222,8 @@ describe("claude-sdk harness", () => {
additionalDirectories: ["/skills/open-prose"],
cwd: "/repo",
env: { A: "B" },
model: "claude-sonnet-4-6",
thinking: { type: "adaptive" },
systemPrompt: {
type: "preset",
preset: "claude_code",
Expand All @@ -229,6 +234,37 @@ describe("claude-sdk harness", () => {
]);
});

test("honors ANTHROPIC_MODEL override from runOptions.env", async () => {
const io = memoryStreams();
const calls: unknown[] = [];
const harness = createClaudeSdkHarness({
query: async (args) => {
calls.push(args);
return {
async *[Symbol.asyncIterator]() {
yield { type: "result", subtype: "success", result: "ok", is_error: false };
},
close() {},
} as never;
},
});

await harness.run("prose status", {
...io.options,
env: { ANTHROPIC_MODEL: "claude-opus-4-7" },
});

expect(calls).toEqual([
{
prompt: "prose status",
options: expect.objectContaining({
model: "claude-opus-4-7",
thinking: { type: "adaptive" },
}),
},
]);
});

test("streams text deltas without duplicating final result", async () => {
const io = memoryStreams();
const abortControllers: AbortController[] = [];
Expand Down
77 changes: 77 additions & 0 deletions tools/cli/tests/live/smoke.live.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { describe, expect, test } from "vitest";

import { createClaudeSdkHarness, createCodexSdkHarness } from "../../src/harnesses/index.js";

const MARKER = "PROSE_LIVE_SMOKE_OK";
const PROMPT = `Reply with exactly the literal string ${MARKER} and nothing else. Do not use any tools.`;
const TIMEOUT_MS = 90_000;

function memoryStreams() {
let stdout = "";
let stderr = "";
return {
options: {
stdout: { write: (chunk: string) => void (stdout += chunk) },
stderr: { write: (chunk: string) => void (stderr += chunk) },
},
get stdout() {
return stdout;
},
get stderr() {
return stderr;
},
};
}

const claudeKey = process.env.ANTHROPIC_API_KEY;
const codexKey = process.env.CODEX_API_KEY ?? process.env.OPENAI_API_KEY;

describe("live smoke", () => {
test.runIf(claudeKey !== undefined)(
"claude-sdk reaches Anthropic and produces text",
async () => {
const io = memoryStreams();
const exitCode = await createClaudeSdkHarness().run(PROMPT, {
...io.options,
env: { ANTHROPIC_API_KEY: claudeKey, ...processEnvWhitelist(["HOME", "PATH"]) },
});
expect(exitCode).toBe(0);
expect(io.stderr).not.toMatch(/API Error|invalid_request_error/);
expect(io.stdout).toContain(MARKER);
},
TIMEOUT_MS,
);

test.runIf(codexKey !== undefined)(
"codex-sdk reaches OpenAI and produces text",
async () => {
const io = memoryStreams();
const exitCode = await createCodexSdkHarness().run(PROMPT, {
...io.options,
env: { OPENAI_API_KEY: codexKey, ...processEnvWhitelist(["HOME", "PATH"]) },
});
expect(exitCode).toBe(0);
expect(io.stderr).not.toMatch(/error|failed/i);
expect(io.stdout).toContain(MARKER);
},
TIMEOUT_MS,
);

test.skipIf(claudeKey !== undefined || codexKey !== undefined)(
"skipped: no live keys present",
() => {
expect(true).toBe(true);
},
);
});

function processEnvWhitelist(keys: readonly string[]): Record<string, string> {
const out: Record<string, string> = {};
for (const key of keys) {
const value = process.env[key];
if (value !== undefined) {
out[key] = value;
}
}
return out;
}
3 changes: 2 additions & 1 deletion tools/cli/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
environment: "node",
include: ["tests/**/*.test.ts"]
include: ["tests/**/*.test.ts"],
exclude: ["**/node_modules/**", "**/dist/**", "tests/live/**"]
}
});
Loading
Loading