Skip to content

AI-180: Disable LangSmith network calls in samples tests via mock client#304

Open
xumaple wants to merge 1 commit intomainfrom
maplexu/AI-180-disable-langsmith-tracing-in-tests
Open

AI-180: Disable LangSmith network calls in samples tests via mock client#304
xumaple wants to merge 1 commit intomainfrom
maplexu/AI-180-disable-langsmith-tracing-in-tests

Conversation

@xumaple
Copy link
Copy Markdown
Contributor

@xumaple xumaple commented May 6, 2026

Summary

  • tests/langsmith_tracing/test_basic.py and test_chatbot.py previously instantiated LangSmithPlugin() with no client. Internally that constructs a real langsmith.Client which authenticates against api.smith.langchain.com using whatever LANGSMITH_API_KEY is in env, producing 401/403 warnings on every test run when a stale key was present.
  • Added a mock_ls_client pytest fixture (in a new tests/langsmith_tracing/conftest.py) and wired it into both tests via LangSmithPlugin(client=mock_ls_client). The mock is a MagicMock with explicit .session and .tracing_queue stubs that the langsmith library accesses internally.
  • Verified empirically with pytest-socket --disable-socket --allow-hosts=127.0.0.1,::1,localhost and LANGSMITH_API_KEY set: zero non-localhost connections attempted, even with the env var present.
  • Drive-by: corrected a pre-existing docstring on test_chatbot_read_note that didn't mention the save-first phase of the test.

Related

  • AI-183 tracks the underlying SDK bug — LangSmithInterceptor force-sets tracing_context(enabled=True), which overrides LANGSMITH_TRACING=false. That's why the env-var disable mechanism couldn't be used here and a mock client is the correct fix in the samples.

Test plan

  • uv run --group langsmith-tracing pytest tests/langsmith_tracing/ -v — 3/3 pass
  • uv run ruff check tests/langsmith_tracing/ — clean
  • uv run ruff format --check tests/langsmith_tracing/ — clean
  • No network I/O verified via pytest-socket --disable-socket --allow-hosts=127.0.0.1,::1,localhost with LANGSMITH_API_KEY set

The langsmith_tracing tests previously instantiated `LangSmithPlugin()`
with no client. Internally that constructs a real `langsmith.Client`
which authenticates against `api.smith.langchain.com` using whatever
`LANGSMITH_API_KEY` is in env, producing 401/403 warnings on every
test run when a stale or invalid key was present.

The samples tests don't assert on trace output, so the right fix is
to bypass the network entirely. Added a `mock_ls_client` pytest
fixture in `tests/langsmith_tracing/conftest.py` and wired it into
`test_basic.py` and `test_chatbot.py` via `LangSmithPlugin(client=mock_ls_client)`.

Verified empirically with `pytest-socket --disable-socket
--allow-hosts=127.0.0.1,::1,localhost` and `LANGSMITH_API_KEY` set:
zero non-localhost connections attempted during the test run.

Drive-by: corrected a pre-existing inaccurate docstring on
`test_chatbot_read_note` (the test saves a note first, then reads
it back; the original elided the save phase).

The underlying SDK behavior — `LangSmithInterceptor` force-sets
`tracing_context(enabled=True)`, which overrides the standard
`LANGSMITH_TRACING=false` disable mechanism — is filed separately
as AI-183.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@xumaple xumaple requested a review from a team as a code owner May 6, 2026 17:30
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