Skip to content

[NA] [SDK] test: add streaming coverage for Groq integration#7387

Open
petrotiurin wants to merge 9 commits into
mainfrom
petrot/NA-groq-streaming-tests
Open

[NA] [SDK] test: add streaming coverage for Groq integration#7387
petrotiurin wants to merge 9 commits into
mainfrom
petrot/NA-groq-streaming-tests

Conversation

@petrotiurin

@petrotiurin petrotiurin commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Details

Follow-up from reviewing #7341 (Groq SDK integration): the merged PR shipped with no test coverage for the stream=True path, left an unused RESPONSE_KEYS_TO_LOG_AS_OUTPUT constant in groq_chat_completions_decorator.py, and (per review feedback) its streaming tests should exercise the SDK's public http_client testing hook rather than monkeypatching a private method. This PR:

  • Adds sync/async offline tests for the stream=True path (chunk aggregation, including the Groq-specific x_groq.usage fallback), built via httpx.MockTransport plugged into http_client= — not by monkeypatching client.chat.completions._post or constructing groq.Stream/AsyncStream directly.
  • Adds sync/async e2e tests that hit the real Groq API (gated behind the pre-existing, previously-unused ensure_groq_configured fixture) to validate the streaming path against real response shapes rather than only our hand-built SSE fixtures.
  • Removes the dead RESPONSE_KEYS_TO_LOG_AS_OUTPUT constant.
  • Un-skips test_langchain__openai_llm_is_used__token_usage_is_logged__happy_flow in test_langchain_groq.py, skipped since 2026-04-14 due to a Groq credentials/billing issue in CI that is now resolved (confirmed via the e2e tests above passing against the live API).

Change checklist

  • User facing
  • Documentation update

Issues

  • Resolves #
  • OPIK-

AI-WATERMARK

AI-WATERMARK: yes

  • Tools: Claude Code
  • Model(s): Claude Sonnet 5
  • Scope: Full diff generated by the agent, directed by and iterated against reviewer feedback (code review of feat: add Groq integration to the Python SDK #7341, then inline suggestions on this PR's own diff).
  • Human verification: Author ran the full test suite, pre-commit, and dispatched CI (including the real-API e2e tests) locally/via gh before requesting merge; diff review pending before merging out of draft.

Testing

  • pytest tests/library_integration/groq/ -vv — 6 offline tests pass (4 pre-existing + 2 new streaming tests); the 2 e2e tests fail loudly via ensure_groq_configured when run locally without GROQ_API_KEY (expected, matches the openai/anthropic convention in this suite).
  • pre-commit on all changed files — ruff, ruff-format, mypy all pass.
  • Dispatched SDK Library Integration Tests Runner (libs=groq) against this branch in CI (which has the real secret): all 5 Python versions (3.10–3.14) pass, including both e2e tests against the live Groq API — confirms the x_groq.usage fallback and response-shape assumptions hold for real.
  • Dispatched the same runner (libs=langchain) to validate the un-skipped langchain test against the real API.

Not covered here: the stream-error/exception path, and the cross-client concurrency issue tracked separately in OPIK_7261 — a single-stream test can't exercise that race.

No video evidence included (non-UI, internal contribution, low complexity).

Documentation

No documentation changes required.

…ad constant

Adds sync/async tests exercising track_groq's stream=True path (chunk
aggregation, x_groq usage parsing) which had no coverage after #7341
merged, and removes RESPONSE_KEYS_TO_LOG_AS_OUTPUT, an unused constant
in groq_chat_completions_decorator.py.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions github-actions Bot added python Pull requests that update Python code tests Including test files, or tests related like configuration. Python SDK labels Jul 7, 2026
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

⏱️ pre-commit per-hook timing

Hook Description Result Duration
🐍 mypy — python sdk Static type check 0.95s
🐍 fix end of files — python sdk Ensure files end in a newline 0.03s
🐍 trim trailing whitespace — python sdk Strip trailing whitespace 0.02s
🐍 ruff-format — python sdk Format Python code (ruff) 0.01s
🐍 ruff — python sdk Lint + autofix Python (ruff) 0.01s
Total (5 ran) 1.02s
⏭️ 35 skipped (no matching files changed)
Hook Description Result
🤖 trim trailing whitespace — optimizer Strip trailing whitespace ⏭️
🤖 fix end of files — optimizer Ensure files end in a newline ⏭️
🤖 check yaml — optimizer Validate YAML syntax ⏭️
🤖 check json — optimizer Validate JSON syntax ⏭️
🤖 check toml — optimizer Validate TOML syntax ⏭️
🤖 check for added large files — optimizer Block large files (>1MB) ⏭️
🔐 detect private key — optimizer Block committed private keys ⏭️
🤖 check for merge conflicts — optimizer Block merge-conflict markers ⏭️
🤖 check for case conflicts — optimizer Block case-only name clashes ⏭️
🤖 pyupgrade — optimizer Modernize Python syntax ⏭️
🤖 ruff — optimizer Lint + autofix Python (ruff) ⏭️
🤖 ruff-format — optimizer Format Python code (ruff) ⏭️
🤖 mypy — optimizer Static type check ⏭️
📓 nbstripout — optimizer notebooks Strip notebook output ⏭️
📝 markdownlint — optimizer Lint Markdown ⏭️
🔤 codespell — optimizer Fix common misspellings ⏭️
📊 radon cc — optimizer Cyclomatic-complexity gate ⏭️
📊 radon raw — optimizer Raw size metrics gate ⏭️
📊 xenon — optimizer Fail on complexity thresholds ⏭️
📊 lizard — optimizer Cyclomatic-complexity gate ⏭️
🧹 vulture — optimizer Find dead code ⏭️
🛡️ trim trailing whitespace — guardrails Strip trailing whitespace ⏭️
🛡️ fix end of files — guardrails Ensure files end in a newline ⏭️
🛡️ ruff — guardrails Lint + autofix Python (ruff) ⏭️
🛡️ ruff-format — guardrails Format Python code (ruff) ⏭️
🛡️ mypy — guardrails Static type check ⏭️
⚓ helm-docs Regenerate Helm chart README ⏭️
block non-public FE plugins Block non-public FE plugins ⏭️
☕ spotless — java backend Format Java code ⏭️
🧪 pre-commit wrapper smoke tests Self-test the wrapper scripts ⏭️
🌐 eslint — frontend Lint + autofix JS/TS ⏭️
🌐 typecheck — frontend Whole-project tsc type check ⏭️
📘 eslint — typescript sdk Lint + autofix JS/TS ⏭️
📘 typecheck — typescript sdk Whole-project tsc type check ⏭️
⚙️ actionlint — github workflows Lint GitHub Actions workflows ⏭️

Comment thread sdks/python/tests/library_integration/groq/test_groq.py
usage=ANY_DICT didn't verify the x_groq.usage fallback in
chat_completion_chunks_aggregator actually propagates the real token
counts. Use ANY_DICT.containing() rather than an exact dict match,
since try_build_opik_usage_or_log_error duplicates fields under
original_usage.* — verified empirically that an exact-dict assertion
would have failed against real output.
Comment thread sdks/python/tests/library_integration/groq/test_groq.py Outdated
…private _post

Replaces monkeypatching client.chat.completions._post (private) and
manually constructing groq.Stream/AsyncStream with the SDK's
documented http_client override plus httpx.MockTransport. The mock
now only fakes the wire response; _post, header/request construction,
and Stream/AsyncStream construction all run for real.
Adds sync/async tests that hit the actual Groq API (gated behind the
existing ensure_groq_configured fixture, previously unused) to
validate the streaming path against real response shapes rather than
only our hand-built SSE fixtures — in particular whether x_groq.usage
is really present on the terminal chunk as assumed.

Mirrors the existing openai/anthropic real-API test pattern in this
suite; local runs without GROQ_API_KEY fail loudly via the fixture,
same as those providers. CI already injects the secret in
lib-groq-tests.yml.
@petrotiurin petrotiurin marked this pull request as ready for review July 7, 2026 14:38
@petrotiurin petrotiurin requested a review from a team as a code owner July 7, 2026 14:38
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Python SDK E2E Tests Results (Python 3.13)

285 tests   282 ✅  5m 23s ⏱️
  1 suites    3 💤
  1 files      0 ❌

Results for commit 89d9f3f.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Python SDK E2E Tests Results (Python 3.14)

285 tests  ±0   282 ✅ ±0   5m 12s ⏱️ +16s
  1 suites ±0     3 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 89d9f3f. ± Comparison against base commit 8428b81.

♻️ This comment has been updated with latest results.

The Groq credentials/billing issue blocking this test in CI since
April is now resolved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

baz: pending Python SDK python Pull requests that update Python code tests Including test files, or tests related like configuration.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant