Skip to content

ref(integrations): collapse auto_test_scripts to a nox-level smoke - #738

Open
starfolkai[bot] wants to merge 3 commits into
mainfrom
refactor/auto-instrument-shared-runner
Open

ref(integrations): collapse auto_test_scripts to a nox-level smoke#738
starfolkai[bot] wants to merge 3 commits into
mainfrom
refactor/auto-instrument-shared-runner

Conversation

@starfolkai

@starfolkai starfolkai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Replace 26 per-provider test_auto_*.py scripts, plus the 26 TestAutoInstrument* classes in every provider test file, with:

  • _run_smoke.py — one runner + inline SMOKES registry (kwargs per integration; only litellm needs openai=False).
  • _maybe_run_autoinstrument_smoke() in noxfile.py — hoisted into _run_tests. Each session's _run_tests(session, test_path, ...) extracts the integration name from test_path (.../integrations/<name>/test_<name>.py<name>) and invokes python -m braintrust.integrations.auto_test_scripts._run_smoke <name> once per (session, integration) before pytest starts.

The reasoning

The scripts + TestAutoInstrument* classes were doing far more than a subprocess sanity check requires. The only bug class a fresh subprocess uniquely proves is:

from a cold Python process, auto_instrument() successfully sets up this integration.

Span shape, provider metadata, patching topology, and real API calls all live (and belong) in the in-process test_*.py files for each integration. The new runner asserts exactly the minimum:

first = auto_instrument(**kwargs)
assert first.get(name) is True
second = auto_instrument(**kwargs)
assert second.get(name) is True  # idempotent

auto_instrument internally returns True only if integration.setup() returned True (ImportError is swallowed to False, other exceptions logged), so a two-call True/True is already a strong signal that setup succeeded and is idempotent.

Cost

The smoke no longer runs under raw pytest test_foo.py — only under nox -s "test_foo(latest)". CI runs everything through nox so CI coverage is unchanged; devs running pytest directly lose the local sanity check, which is a fair trade for the ~1300 net LOC deleted and a "new integrations get smoke for free" story (add the name to SMOKES in _run_smoke.py — that's the only place).

Bonus: llamaindex and strands are added to the registry — they had no smoke scripts before but do have auto_instrument entries, so they get free coverage now.

Diff shape

Cumulative across the branch: 78 files changed, −1357 net lines (~+117 / −1474). One commit per logical step (initial shared helper → collapse to registry → hoist into nox).

What stays put

  • test_patch_litellm_responses.py, test_patch_litellm_aresponses.py: exercise patch_litellm() directly, not auto_instrument().

Test plan

  • cd py && nox -s pylint — clean
  • cd py && nox -s "test_litellm(latest)" -- -k "test_patch_litellm" — 2 passed; nox output shows python -m ..._run_smoke litellmSUCCESS before pytest starts
  • cd py && nox -s test_core — clean
  • pre-commit hooks (ruff, codespell, EOF, trailing whitespace) on all changed files — clean
  • CI: the sharded nox matrix will exercise the smoke for every integration session (nox calls the runner once per session before pytest).

🤖 Generated with Claude Code

Created by Abhijeet Prasad (@AbhiPrasad)

Slack thread

…ipts

Add `run_auto_smoke()` to `braintrust.integrations.test_utils` and rewrite 23
of the 29 `auto_test_scripts/` to use it. The helper encodes the standard
contract for `auto_instrument()` smoke tests: optional pre/post `is_patched`
check, first call returns `{name: True, ...}`, second call is idempotent, and
an optional memory-logger + VCR context that delegates to a per-script `run()`
callback for the API call and span-shape asserts.

Net -58 lines across the auto_test_scripts, but the real win is a single
authoritative definition of "auto_instrument works" that every simple
provider script now shares. Complex scripts that are mostly provider-specific
setup rather than boilerplate (agentscope, pipecat, agno) are left alone, as
are the `test_patch_litellm_*` scripts which exercise `patch_litellm()`
directly rather than `auto_instrument()`.

Verified: `nox -s pylint`, `nox -s test_core`, `nox -s test_litellm(latest)`
covering both the refactored `test_auto_litellm` and the untouched
`test_patch_litellm_*` scripts, plus pre-commit hooks on all changed files.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 04be476fca

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment on lines +176 to +177
second = auto_instrument(**kwargs)
assert second.get(name) is True, f"auto_instrument (2nd call) returned {second!r}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Verify patch state after the second instrumentation call

When a repeated auto_instrument() call reports success but accidentally removes, replaces, or duplicates installed instrumentation, this helper still passes because is_patched() is only evaluated after the first call. Several converted scripts previously verified post-second-call state—including object identity for the CrewAI listener and LangChain handler—so the shared runner now allows idempotence regressions to escape; re-run an appropriate state verifier after the second call or retain the provider-specific identity assertions.

Useful? React with 👍 / 👎.

…ry-driven smoke

Replace 26 near-identical per-provider `test_auto_*.py` scripts with one
runner (`_run_smoke.py`) driven by an inline SMOKES registry, invoked from
each `TestAutoInstrument*` via a new `verify_autoinstrument_smoke(name)`
helper.

The scripts were doing far more than a subprocess sanity check requires.
The only bug class a fresh subprocess uniquely proves is "from a cold Python
process, `auto_instrument()` successfully sets up this integration"; span
shape, provider metadata, patching topology, and real API calls all live in
the in-process `test_*.py` files for each integration. The runner asserts
exactly that minimum: `auto_instrument(**kwargs).get(name) is True`, twice
(idempotent).

Net: −1222 LOC. The `test_patch_litellm_*` scripts stay put — they exercise
`patch_litellm()` directly rather than `auto_instrument()`.

The `run_auto_smoke` helper added in the previous commit is removed along
with the scripts that used it.

Verified: `nox -s pylint`, `nox -s "test_litellm(latest)" -- -k
"test_auto_instrument_litellm or test_patch_litellm"` (3 passed), and
pre-commit hooks on all changed files.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@starfolkai starfolkai Bot changed the title refactor(integrations): share auto_instrument smoke runner across scripts refactor(integrations): collapse auto_test_scripts to a single registry-driven smoke Sep 4, 2026
@AbhiPrasad Abhijeet Prasad (AbhiPrasad) changed the title refactor(integrations): collapse auto_test_scripts to a single registry-driven smoke ref(integrations): collapse auto_test_scripts to a single registry-driven smoke Sep 4, 2026
…-provider tests

Follow-up to the previous commit: instead of every provider test file carrying
a tiny `TestAutoInstrument*` class that spawns the same subprocess, hoist the
smoke into `_run_tests` in the noxfile. Each integration session already knows
which provider it's testing (via the test path), so it invokes

    python -m braintrust.integrations.auto_test_scripts._run_smoke <name>

once before pytest starts. This works uniformly in src and wheel modes.

Deletes:
- 26 `TestAutoInstrument*` classes/functions and their imports across every
  provider test file
- `verify_autoinstrument_smoke` from `test_utils` (no callers left)
- The `args` parameter I added to `verify_autoinstrument_script` in the last
  commit (only `verify_autoinstrument_smoke` used it; reverted to the original
  signature)

Adds:
- `_maybe_run_autoinstrument_smoke(session, test_path)` in noxfile.py — infers
  the integration name from the test path, dedupes per (session, integration),
  skips paths that aren't per-provider (e.g. test_core, test_versioning).
- `llamaindex` and `strands` to the SMOKES registry — they had no smoke scripts
  before but do have `auto_instrument` entries, so they get free coverage now.

Cost: the smoke no longer runs under raw `pytest test_foo.py` — only under
`nox -s "test_foo(latest)"`. CI runs everything through nox so CI coverage is
unchanged; devs running pytest directly lose the local sanity check, which is
a fair trade for the −135 net LOC and one-line "add a new integration" story.

Verified: `nox -s "test_litellm(latest)" -- -k test_patch_litellm` prints
"python -m ..._run_smoke litellm\nSUCCESS" before pytest runs (2 passed),
`nox -s pylint` clean, `nox -s test_core` clean.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@starfolkai starfolkai Bot changed the title ref(integrations): collapse auto_test_scripts to a single registry-driven smoke ref(integrations): collapse auto_test_scripts to a nox-level smoke Sep 4, 2026
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.

1 participant