Skip to content

refactor(ai): test-only model request hooks leave src - #3768

Merged
dan-petty merged 2 commits into
mainfrom
refactor/1330-remove-test-model-hooks
Nov 6, 2026
Merged

dan-petty merged 2 commits into
mainfrom
refactor/1330-remove-test-model-hooks

Conversation

@dan-petty

@dan-petty dan-petty commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Product code in src held switches that only tests used (#3759, child A of #1330). Tests double only edges, and src must hold no test switch (ADR 0007).

  • ALLOW_MODEL_REQUESTS was a flag in ai/agents/agent.py and in ai/agents/testing.py. PydanticAgent.run read both and raised ModelNotAllowedError for a client that was not a home-made TestModel or FunctionModel.
  • _is_testing_mode_active in ai/pydantic_ai_bridge.py read the same flags, and resolve_pydantic_ai_model returned a pydantic-ai TestModel when it was true.
  • _RUN_MESSAGES_CAPTURE was a ContextVar that PydanticAgent filled at the end of a run, for the home-made capture_run_messages.

Nothing outside tests set a flag or read a capture. This change removes all of them. Tests use the ModelFake instead.

Closes #3759

Change: openspec/changes/archive/2026-11-06-3759-remove-test-model-hooks/

ALLOW_MODEL_REQUESTS, ModelNotAllowedError, _RUN_MESSAGES_CAPTURE, _is_testing_mode_active and ai/agents/testing.py had no caller outside tests. The tests now answer from the model_fake fixture.
@dan-petty dan-petty added type/refactor Type refactor: a new structure, same behavior scope/ai AI review pipeline, personas, prompts, LLM client, or RAG labels Nov 6, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Test and check results:

  • Rebased onto origin/main (release 0.67.0).
  • Focused pytest: 137 passed (agent capabilities, gateway caller headers, MCP, Ollama, profiles and providers, architectural invariants).
  • Pre-push fast static checks: passed.
  • The independent review gave no findings.
  • Full devops ci runs in GitHub CI.

@dan-petty
dan-petty marked this pull request as ready for review November 6, 2026 07:30
@dan-petty
dan-petty merged commit 9b01821 into main Nov 6, 2026
30 checks passed
@dan-petty
dan-petty deleted the refactor/1330-remove-test-model-hooks branch November 6, 2026 07:58
dan-petty pushed a commit that referenced this pull request Nov 6, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.67.2](v0.67.1...v0.67.2)
(2026-11-06)


### Code Refactoring

* **ai:** test-only model request hooks leave src
([#3768](#3768))
([9b01821](9b01821))
* **tests:** one DNS seam with a shared fake and contract suite
([#3773](#3773))
([10c7896](10c7896)),
closes [#3752](#3752)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/ai AI review pipeline, personas, prompts, LLM client, or RAG type/refactor Type refactor: a new structure, same behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(ai): test-only model request hooks leave src

1 participant