Update ocr/tests/test_gemini_engine.py to match new SDK internals:
Replace engine._model / engine._generation_config mocks with engine._client / engine._model_name
Mock engine._client.models.generate_content instead of mock_model.generate_content
Update sys.modules patches: replace vertexai/google.cloud.aiplatform with google.genai
Update test_missing_sdk_raises_unavailable to test google.genai import failure
Acceptance Criteria
All tests pass with new mock patterns
No references to old SDK module names in test patches
test_vin_decode.py and test_manual_extractor.py confirmed unchanged (they mock at router/engine-instance level)
File
ocr/tests/test_gemini_engine.py
Relates to #231
Update `ocr/tests/test_gemini_engine.py` to match new SDK internals:
- Replace `engine._model` / `engine._generation_config` mocks with `engine._client` / `engine._model_name`
- Mock `engine._client.models.generate_content` instead of `mock_model.generate_content`
- Update `sys.modules` patches: replace `vertexai`/`google.cloud.aiplatform` with `google.genai`
- Update `test_missing_sdk_raises_unavailable` to test `google.genai` import failure
## Acceptance Criteria
- [ ] All tests pass with new mock patterns
- [ ] No references to old SDK module names in test patches
- [ ] `test_vin_decode.py` and `test_manual_extractor.py` confirmed unchanged (they mock at router/engine-instance level)
## File
`ocr/tests/test_gemini_engine.py`
The test file ocr/tests/test_gemini_engine.py mocks the old vertexai.generative_models SDK internals. After M2 (#233) and M3 (#234) change the production code, these mocks must be updated to match the new google.genai SDK patterns.
Codebase Analysis
File
SDK References
Action
ocr/tests/test_gemini_engine.py
2 tests use sys.modules patches with old module names; others set engine._model directly
Update mock patterns
ocr/tests/test_vin_decode.py
None (mocks at router level)
No changes
ocr/tests/test_manual_extractor.py
None (mocks at engine instance level)
No changes
ocr/tests/test_resolve_vin_year.py
Imports resolve_vin_year only (pure function, no SDK)
No changes -- file is currently untracked; commit before beginning M1 to avoid loss during branch operations
Internal State Changes (old -> new mock targets)
Tests that set engine._model and engine._generation_config must change to:
engine._client=MagicMock()# with .models.generate_content return valueengine._model_name="gemini-2.5-flash"
Implementation
File: ocr/tests/test_gemini_engine.py
Update module docstring (L5): replace "All Vertex AI SDK calls are mocked" with "All google-genai SDK calls are mocked"
All tests that set engine._model and engine._generation_config -> set engine._client (MagicMock with .models.generate_content return value) and engine._model_name = "gemini-2.5-flash"
test_valid_pdf_returns_structured_schedules: update BOTH the sys.modules patch (replace vertexai/google.cloud.aiplatform entries with google.genai entries) AND the engine._model -> engine._client / engine._model_name field reassignments. Clean up dead if False branch (L162).
test_missing_sdk_raises_unavailable: change patch to patch.dict("sys.modules", {"google.genai": None}) to simulate missing new SDK
Verify test_vin_decode.py, test_manual_extractor.py, and test_resolve_vin_year.py pass unchanged
PRECISION: test_valid_pdf_returns_structured_schedules needs BOTH sys.modules patch update AND engine._model -> engine._client field reassignments -- clarified
[RULE 2] SHOULD_FIX: Dead code if False branch at L162 -- clean up during this milestone
QR plan-docs:
[RULE 2] SHOULD_FIX: Test module docstring (L5) -- included in implementation
Verdict: APPROVED | Next: Execute (depends on M2 #233 and M3 #234)
## Plan: M4 -- Update tests (#235)
**Phase**: Planning | **Agent**: Planner | **Status**: APPROVED
**Parent**: #231 | **Revision**: v4
---
### Context
The test file `ocr/tests/test_gemini_engine.py` mocks the old `vertexai.generative_models` SDK internals. After M2 (#233) and M3 (#234) change the production code, these mocks must be updated to match the new `google.genai` SDK patterns.
### Codebase Analysis
| File | SDK References | Action |
|------|---------------|--------|
| `ocr/tests/test_gemini_engine.py` | 2 tests use `sys.modules` patches with old module names; others set `engine._model` directly | Update mock patterns |
| `ocr/tests/test_vin_decode.py` | None (mocks at router level) | No changes |
| `ocr/tests/test_manual_extractor.py` | None (mocks at engine instance level) | No changes |
| `ocr/tests/test_resolve_vin_year.py` | Imports `resolve_vin_year` only (pure function, no SDK) | No changes -- file is currently untracked; commit before beginning M1 to avoid loss during branch operations |
### Internal State Changes (old -> new mock targets)
Tests that set `engine._model` and `engine._generation_config` must change to:
```python
engine._client = MagicMock() # with .models.generate_content return value
engine._model_name = "gemini-2.5-flash"
```
### Implementation
- File: `ocr/tests/test_gemini_engine.py`
- Update module docstring (L5): replace "All Vertex AI SDK calls are mocked" with "All google-genai SDK calls are mocked"
- All tests that set `engine._model` and `engine._generation_config` -> set `engine._client` (MagicMock with `.models.generate_content` return value) and `engine._model_name = "gemini-2.5-flash"`
- `test_valid_pdf_returns_structured_schedules`: update BOTH the `sys.modules` patch (replace `vertexai`/`google.cloud.aiplatform` entries with `google.genai` entries) AND the `engine._model` -> `engine._client` / `engine._model_name` field reassignments. Clean up dead `if False` branch (L162).
- `test_missing_sdk_raises_unavailable`: change patch to `patch.dict("sys.modules", {"google.genai": None})` to simulate missing new SDK
- Verify `test_vin_decode.py`, `test_manual_extractor.py`, and `test_resolve_vin_year.py` pass unchanged
### Review Findings
**QR plan-completeness:**
- [RULE 1] HIGH: Untracked `test_resolve_vin_year.py` acknowledged -- commit before M1 branch operations
**TW plan-scrub:**
- PRECISION: `test_valid_pdf_returns_structured_schedules` needs BOTH `sys.modules` patch update AND `engine._model` -> `engine._client` field reassignments -- clarified
- PRECISION: `test_missing_sdk_raises_unavailable` exact patch: `patch.dict("sys.modules", {"google.genai": None})` -- specified
**QR plan-code:**
- [RULE 2] SHOULD_FIX: Dead code `if False` branch at L162 -- clean up during this milestone
**QR plan-docs:**
- [RULE 2] SHOULD_FIX: Test module docstring (L5) -- included in implementation
---
*Verdict*: APPROVED | *Next*: Execute (depends on M2 #233 and M3 #234)
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Relates to #231
Update
ocr/tests/test_gemini_engine.pyto match new SDK internals:engine._model/engine._generation_configmocks withengine._client/engine._model_nameengine._client.models.generate_contentinstead ofmock_model.generate_contentsys.modulespatches: replacevertexai/google.cloud.aiplatformwithgoogle.genaitest_missing_sdk_raises_unavailableto testgoogle.genaiimport failureAcceptance Criteria
test_vin_decode.pyandtest_manual_extractor.pyconfirmed unchanged (they mock at router/engine-instance level)File
ocr/tests/test_gemini_engine.pyPlan: M4 -- Update tests (#235)
Phase: Planning | Agent: Planner | Status: APPROVED
Parent: #231 | Revision: v4
Context
The test file
ocr/tests/test_gemini_engine.pymocks the oldvertexai.generative_modelsSDK internals. After M2 (#233) and M3 (#234) change the production code, these mocks must be updated to match the newgoogle.genaiSDK patterns.Codebase Analysis
ocr/tests/test_gemini_engine.pysys.modulespatches with old module names; others setengine._modeldirectlyocr/tests/test_vin_decode.pyocr/tests/test_manual_extractor.pyocr/tests/test_resolve_vin_year.pyresolve_vin_yearonly (pure function, no SDK)Internal State Changes (old -> new mock targets)
Tests that set
engine._modelandengine._generation_configmust change to:Implementation
ocr/tests/test_gemini_engine.pyengine._modelandengine._generation_config-> setengine._client(MagicMock with.models.generate_contentreturn value) andengine._model_name = "gemini-2.5-flash"test_valid_pdf_returns_structured_schedules: update BOTH thesys.modulespatch (replacevertexai/google.cloud.aiplatformentries withgoogle.genaientries) AND theengine._model->engine._client/engine._model_namefield reassignments. Clean up deadif Falsebranch (L162).test_missing_sdk_raises_unavailable: change patch topatch.dict("sys.modules", {"google.genai": None})to simulate missing new SDKtest_vin_decode.py,test_manual_extractor.py, andtest_resolve_vin_year.pypass unchangedReview Findings
QR plan-completeness:
test_resolve_vin_year.pyacknowledged -- commit before M1 branch operationsTW plan-scrub:
test_valid_pdf_returns_structured_schedulesneeds BOTHsys.modulespatch update ANDengine._model->engine._clientfield reassignments -- clarifiedtest_missing_sdk_raises_unavailableexact patch:patch.dict("sys.modules", {"google.genai": None})-- specifiedQR plan-code:
if Falsebranch at L162 -- clean up during this milestoneQR plan-docs:
Verdict: APPROVED | Next: Execute (depends on M2 #233 and M3 #234)
Milestone: M4 Complete -- Update test mocks
Phase: Execution | Agent: Developer | Status: PASS
Changes
ocr/tests/test_gemini_engine.py: Updated all mock patterns for new SDKengine._model->engine._client(MagicMock with.models.generate_content)engine._generation_config->engine._model_name = "gemini-2.5-flash"test_valid_pdf_returns_structured_schedules: Replaced old sys.modules patch withgoogle.genaientries, removed deadif Falsebranchtest_missing_sdk_raises_unavailable: Patchesgoogleandgoogle.genaias Nonetest_model_is_none_after_construction->test_client_is_none_after_constructiontest_model_reused_on_second_call->test_client_reused_on_second_callPropertyMockimportTest Results
All 18 gemini engine tests pass. All VIN decode and manual extractor tests pass unchanged (they mock at router/engine-instance level).
Acceptance Criteria
test_vin_decode.pyandtest_manual_extractor.pyconfirmed unchangedVerdict: PASS | Next: M5 -- Doc-sync