Skip to content

Comments

fix: clean optimizer tests — proper patch() + Azure Entra ID integration#10

Merged
sbroenne merged 4 commits intomainfrom
fix/optimizer-test-patching
Feb 19, 2026
Merged

fix: clean optimizer tests — proper patch() + Azure Entra ID integration#10
sbroenne merged 4 commits intomainfrom
fix/optimizer-test-patching

Conversation

@sbroenne
Copy link
Owner

What

  • Replaced fragile \sys.modules\ hacks in \ est_optimizer.py\ with clean \patch('pytest_codingagents.copilot.optimizer.PydanticAgent', ...)\
  • Added \TestAzureEntraModel\ class (3 tests: returns Model, defaults to \gpt-5.2-chat, accepts custom deployment)
  • Updated \ est_optimizer_integration.py\ to use \�zure_entra_model()\ (gpt-5.2-chat via Azure Entra ID) — no more OPENAI_API_KEY skip

Why

The old \sys.modules\ patching mutated live modules with no cleanup, polluting other tests. The correct target is now \patch('...optimizer.PydanticAgent', ...)\ since pydantic-ai is a top-level import.

Verified

  • Full test → optimize → test loop run end-to-end: 3/3 integration tests passed in 64s against real \gpt-5.2-chat\
  • 131 unit tests all passing

- Rewrite test_optimizer.py using patch('...PydanticAgent', ...) cleanly
- Add TestAzureEntraModel class (3 tests covering default gpt-5.2-chat deployment)
- Update test_optimizer_integration.py to use azure_entra_model() (gpt-5.2-chat)
  instead of OPENAI_API_KEY skip guard -- all 3 now pass against real Azure
- Verified full test->optimize->test loop end-to-end: 3/3 passed in 64s

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link

github-actions bot commented Feb 19, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Stefan Broenner and others added 3 commits February 19, 2026 12:06
…nstead

pytest-aitest already provides build_model_from_string() which handles Azure
Entra ID auth automatically from 'azure/gpt-5.2-chat' style strings.

- Delete azure_entra_model() from optimizer.py and __init__.py (duplication)
- optimize_instruction() now uses build_model_from_string() internally
- Default model changed to 'azure/gpt-5.2-chat'
- Model strings use provider/model format (same as pytest-aitest Provider)
- Remove TestAzureEntraModel unit tests (testing dead code)
- Update integration tests: no extra import needed
- 3/3 integration tests pass against azure/gpt-5.2-chat via Entra ID

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds test_full_optimize_loop which validates the hero use case end-to-end:

1. Run Copilot with weak instruction ('no comments or documentation needed')
   -> code produced has no docstrings (verified)
2. Call optimize_instruction() with failing criterion
   -> optimizer identifies the conflict, suggests explicit docstring mandate
3. Run Copilot again with improved instruction
   -> code now contains Google-style docstrings (verified)

Result: Docstrings round 1: False, round 2: True (passed in 36s)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…equirement

Unit tests were failing in CI with 'AZURE_API_BASE or AZURE_OPENAI_ENDPOINT
required' because build_model_from_string('azure/gpt-5.2-chat') runs before
PydanticAgent is mocked. Now both are patched together.

Also strengthens test_uses_default_model: verifies the exact model string
passed to build_model_from_string, and that the resolved model is forwarded.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sbroenne sbroenne merged commit 1365a0e into main Feb 19, 2026
15 checks passed
@sbroenne sbroenne deleted the fix/optimizer-test-patching branch February 19, 2026 11:37
sbroenne pushed a commit that referenced this pull request Feb 19, 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