test(rekognition): green up PR #1205 — make off-loop read test robust to sys.modules eviction - #1207
Conversation
…tion
`test_local_image_read_runs_off_the_event_loop_thread` failed in the full
CI suite ("_read_file_bytes was never called") while passing in isolation.
Root cause is cross-module test pollution, not the production change:
`tests/unit/test_cloud_ai_integrator.py` deletes every
`youtube_extension.*cloud_ai*` entry from `sys.modules` at collection time.
The aws_rekognition module key matches, so after that eviction the test's
late `import ... as _rek_mod` binds a *fresh* module object, while the
provider instance's `_prepare_image_input` still resolves `_read_file_bytes`
from the original module's globals. The patch landed on the stale module and
the read ran unintercepted — correct bytes returned, but the recording
wrapper never fired.
Patch the method's own `__globals__` via `patch.dict` instead of a
re-imported module attribute. That namespace is exactly what
`_prepare_image_input` resolves names from and cannot drift regardless of
sys.modules churn. Verified: old test fails / new test passes when
test_cloud_ai_integrator runs first in the same session; full file 95 passed.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one) (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository YAML (base), Repository UI (inherited), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Agent Completion Truth Gate: BLOCKEDReasons: Machine-readable verdict{
"details": {
"invalid_fields": [
"issue.number",
"policy.agent_login",
"policy.run_id"
]
},
"reasons": [
"invalid_payload"
],
"verdict": "blocked"
} |
CI triage for this PRThe substantive change here ( The remaining red checks on this head are all pre-existing, repo-wide gates that are red on the base branch (
What this PR does deliver: the Python Human decision requested: merge this into Generated by Claude Code |
|
Contained as a duplicate repair. The verified |
Canonical issue
Remediates the failing
testcheck on #1205 (perf/rekognition-offloop). This PR targetsperf/rekognition-offloopdirectly, so merging it lands the fix on #1205's head and turns its CI green. It carries a single commit (c375307) — no duplication of #1205's perf changes.Outcome
tests/unit/test_aws_rekognition_provider.py::TestRekognitionDoesNotBlockEventLoop::test_local_image_read_runs_off_the_event_loop_threadfails in the full CI suite (AssertionError: _read_file_bytes was never called) while passing in isolation. This makes the failure deterministic-green by fixing the test's module resolution. The production change in #1205 is correct and untouched.Root cause — cross-module test pollution, not the diff.
tests/unit/test_cloud_ai_integrator.pydeletes everyyoutube_extension.*cloud_ai*key fromsys.modulesat collection time. Theaws_rekognitionmodule key matches, so after that eviction the failing test's lateimport ... as _rek_modbinds a fresh module object, while the provider instance's_prepare_image_inputstill resolves_read_file_bytesfrom the original module's globals. Thepatch.objectlanded on the stale module and the read ran unintercepted — correct bytes were returned, but the recording wrapper never fired, so the thread-identity assertion saw an emptyobserved.Scope
__globals__viapatch.dict(the exact namespace_prepare_image_inputresolves names from) instead of a re-imported module attribute; drop the now-unused late import.test_cloud_ai_integrator.pyeviction pattern is left as-is (itsdel sys.modules[...]is intentional for its own stubbing).Risk
__globals__is a stable CPython attribute of the bound function, immune tosys.moduleschurn.c375307.Verification
Tied to head
c375307:test_cloud_ai_integrator.pyfirst, then the target, one session) — before this change that ordering reproduces the exact CI failure (1 failed); after,62 passed.95 passed.ruff checkon the file: parity with base (the one pre-existingF841at line 820 is unrelated and unchanged; zero added).Reproduction (local):
Production evidence
Not applicable — test-only change. The production behaviour (all 14 Rekognition calls off the event loop) is #1205's and is unchanged here.
Agent handoff
test) reproduced red and driven green locallyperf/rekognition-offloop(or cherry-pickingc375307onto it) is left to you — I did not push to perf(cloud-ai): run AWS Rekognition boto3 calls off the event loop #1205's branch directly. perf(cloud-ai): run AWS Rekognition boto3 calls off the event loop #1205 still needs your merge approval tomainafter CI re-runs green.Generated by Claude Code