Audit tests that hand-mimic pydantic-ai state instead of exercising it (compat-CI blind spots)

Author: DouweMCreated Jul 31, 2026Updated Oct 1, 2026
Labelsharness

Transferred from pydantic/pydantic-ai-harness#526 after harness moved into this repo. Harness paths map to src/pydantic_ai_harness/pydantic_ai_harness/, tests/harness/ and docs/harness/.

What happened

pydantic-ai#6770 changed ToolSearchToolset to stop flipping ToolDefinition.defer_loading to False on reveal (the flag now records the author's intent for the whole run; visibility moved to ModelRequestParameters.revealed_tool_names). That broke CodeModeToolset in production — a tool revealed via search_tools or load_capability never folded into run_code (pydantic/pydantic-ai-harness#517 fixes it).

pydantic-ai's harness-compat job ran on pydantic/pydantic-ai-harness#6770's exact head SHA and passed (https://github.com/pydantic/pydantic-ai/actions/runs/30559290352/job/90927825121). The job did its job; the harness suite was the blind spot.

Why the suite missed it

The fold-in tests simulated pydantic-ai's side of the contract instead of exercising it:

  • tests/code_mode/test_code_mode.py:942-949 — """Once a deferred tool is discovered (defer_loading=False) it folds into run_code.""" with the comment # defer_loading=False mimics the post-discovery state ToolSearchToolset hands back. The test constructs the post-discovery state by hand, so when pydantic/pydantic-ai-harness#6770 changed what ToolSearchToolset actually hands back, the mimic stayed faithful to the old world and kept passing.
  • Same pattern at the old test_code_mode.py:2284 comment ("Post-discovery the deferred tool comes back with defer_loading=False").

A hand-built fixture that encodes an assumption about another repo's output is invisible to compat CI by construction: the compat job runs our tests against their code, but a test that never calls their code can't notice their code changed.

pydantic/pydantic-ai-harness#517 already fixes this instance the right way — its new test_loaded_capability_tool_folds_into_run_code drives a real Capability, a real load_capability call, and a FunctionModel, no mimicry.

Task

Audit the harness test suite for other places where a test hand-constructs state that pydantic-ai is supposed to produce, and convert them to exercise the real integration:

  • grep candidates: comments containing "mimics", "simulates", "mirrors pydantic-ai", hand-set defer_loading=..., hand-built ModelRequestParameters, hand-built RunContext fields that the framework normally populates (discovered_tool_names, loaded_capability_ids, revealed_tool_names)
  • for each: either drive the real pydantic-ai flow (preferred), or — where the real flow is genuinely impractical — add a companion contract test that asserts pydantic-ai still produces the state the fixture encodes, so drift turns the suite red.

Unit-style tests of harness-internal logic are fine; the audit is specifically about fixtures that stand in for pydantic-ai's behavior at the repo boundary, because those are exactly what the compat job cannot see through.