Skip to content

test(messages): add live Claude Agent SDK smoke test against /v1/messages - #6010

Merged
cdoern merged 8 commits into
ogx-ai:mainfrom
cdoern:messages-claude-agent-sdk-smoke
Jun 5, 2026
Merged

test(messages): add live Claude Agent SDK smoke test against /v1/messages#6010
cdoern merged 8 commits into
ogx-ai:mainfrom
cdoern:messages-claude-agent-sdk-smoke

Conversation

@cdoern

@cdoern cdoern commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

What

Adds a live smoke test that drives the upstream claude-agent-sdk Python package against a local OGX server, exercising the Anthropic Messages (/v1/messages) path end to end through a real client. This is the SDK companion to the Claude Code CLI smoke test merged in #5986 (RHAIENG-5377).

The SDK does not speak HTTP itself — it spawns the Claude Code CLI as a subprocess and parses its streamed session output. So this covers a distinct client surface (the SDK's session machinery: message streaming, ResultMessage parsing) on top of the same path: full system prompt, tool definitions, and an inline system-role message that the server must accept and dispatch to the backing provider.

Why live, not record/replay

The SDK drives the real CLI, which bakes the working directory, date, and platform into every request body. The recording system keys on SHA256 of the request body, so those hashes are not reproducible across runs or machines — record/replay is not viable. The test runs live against Ollama and self-skips unless both the claude-agent-sdk package and the claude binary are available.

What it asserts

Integration health, not answer quality — a small local model driving the Claude Code harness cannot be relied on to produce specific text. The test checks the parsed ResultMessage:

  • subtype == "success" and is_error is False
  • the backing model present in model_usage

A regression like a rejected inline system-role message would surface as a session error and be caught here.

Changes

  • New test: tests/integration/messages/test_claude_agent_sdk.py
  • New CI workflow: .github/workflows/integration-tests-messages-sdk.yml (provisions Ollama, installs the pinned CLI, runs the test live)
  • claude-agent-sdk>=0.2.0 added to the test dependency group (locked to 0.2.87)

Test plan

Ran live against local Ollama using the same CI command:

./scripts/integration-tests.sh \
  --stack-config server:ci-tests --setup ollama --suite messages \
  --inference-mode live --pattern test_claude_agent_sdk_smoke

Result:

tests/integration/messages/test_claude_agent_sdk.py::test_claude_agent_sdk_smoke[txt=ollama/llama3.2:3b-instruct-fp16] PASSED
1 passed, 20 deselected in 36.45s

🤖 Generated with Claude Code

…ages

Drive the upstream claude-agent-sdk Python package against a local OGX
server so the SDK's session machinery exercises the Anthropic Messages
path end to end. The SDK does not speak HTTP itself; it spawns the Claude
Code CLI as a subprocess, so the test asserts on the parsed ResultMessage
(successful subtype, no error, and the backing model present in
model_usage) rather than on model text, which a small local model driving
the Claude Code harness cannot be relied on to produce.

The SDK drives the real CLI, which bakes the working directory, date, and
platform into every request body, so request-body hashes are not
reproducible and record/replay is not viable. The test therefore runs
live against Ollama and self-skips unless both the claude-agent-sdk
package and the claude binary are available.

Add claude-agent-sdk to the test dependency group and a sibling CI
workflow that provisions Ollama, installs the CLI, and runs the smoke
test live.

Signed-off-by: Charlie Doern <cdoern@redhat.com>
@cdoern
cdoern marked this pull request as ready for review June 3, 2026 13:13

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@cdoern
cdoern enabled auto-merge June 3, 2026 15:35

@leseb leseb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this "The SDK does not speak HTTP itself — it spawns the Claude Code CLI as a subprocess and parses its streamed session output. " is true, can't we have a single test that uses just the SDK so this will validate both CLI and SDK at the same time? like reverting #5986?

@skamenan7 skamenan7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM apart from two comments.

"""Run a single Agent SDK query() to completion and return all messages."""
from claude_agent_sdk import ClaudeAgentOptions, query

options = ClaudeAgentOptions(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be missing a reason this differs from the CLI smoke, but should the SDK path also run from tmp_path? ClaudeAgentOptions has a cwd field, and using it would avoid the spawned CLI picking up repo-local context while bypassPermissions is enabled.

Comment thread pyproject.toml Outdated
{include-group = "test-common"},
"autoevals",
"chromadb>=1.0.15",
"claude-agent-sdk>=0.2.0", # Drives the real Claude Code CLI in the Messages API SDK smoke test

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dependency wiring works, but it may be broader than needed. Since only this new live SDK smoke uses claude-agent-sdk, could we install it in this workflow or a narrower group instead of the shared test group?

cdoern added 2 commits June 3, 2026 12:42
Address review feedback on the Claude Agent SDK smoke test:

Rename the merged integration-tests-messages-cli.yml to
integration-tests-messages-clients.yml and run both the CLI and Agent SDK
smoke tests from it. Both clients ultimately drive the same Claude Code
CLI, so a single job shares the Ollama provisioning and CLI install and
then runs both tests, rather than paying that setup twice across two
workflows.

Install claude-agent-sdk at workflow time instead of adding it to the
shared test dependency group. Since CI syncs all groups, a group
dependency would be installed for every integration-test job even though
only this one live smoke test imports it; a workflow-scoped install keeps
it narrow, mirroring how the CLI binary itself is installed. The test
already self-skips when the package is absent.

Run the Agent SDK session from an isolated tmp directory via
ClaudeAgentOptions.cwd so the spawned CLI does not pick up repo-local
context while permissions are bypassed.

Signed-off-by: Charlie Doern <cdoern@redhat.com>
@cdoern

cdoern commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator Author

@leseb

▎ can't we have a single test that uses just the SDK... like reverting #5986?

Combined instead of collapsed: both tests now run from one workflow (renamed to integration-tests-messages-clients.yml) — shared Ollama + CLI setup, run via -k '(test_claude_code_cli_smoke or test_claude_agent_sdk_smoke)'. No more duplicate setup or two workflows.

Kept both because they assert different contracts: the CLI test checks claude -p --output-format json (no Python dep), the SDK test checks streamed message parsing (ResultMessage). They fail independently — if the claude-agent-sdk ↔ CLI version pairing breaks, the CLI canary still tells us whether OGX itself regressed. Extra cost is ~30s now that setup is shared.

run-and-record-tests passes --pattern unquoted, so the parenthesized
'(... or ...)' expression was word-split and the script rejected the bare
'or' token. Use the single shell word 'test_claude', which selects both
test_claude_code_cli_smoke and test_claude_agent_sdk_smoke and survives
the unquoted expansion.

Signed-off-by: Charlie Doern <cdoern@redhat.com>
@cdoern
cdoern added this pull request to the merge queue Jun 3, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 3, 2026
@cdoern
cdoern added this pull request to the merge queue Jun 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 4, 2026
@cdoern
cdoern enabled auto-merge June 4, 2026 13:46
@cdoern
cdoern added this pull request to the merge queue Jun 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 4, 2026
@cdoern
cdoern merged commit b8efa4d into ogx-ai:main Jun 5, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants