Skip to content

test(rekognition): green up PR #1205 — make off-loop read test robust to sys.modules eviction - #1207

Closed
groupthinking wants to merge 1 commit into
perf/rekognition-offloopfrom
claude/determined-maxwell-2frkmc
Closed

test(rekognition): green up PR #1205 — make off-loop read test robust to sys.modules eviction#1207
groupthinking wants to merge 1 commit into
perf/rekognition-offloopfrom
claude/determined-maxwell-2frkmc

Conversation

@groupthinking

Copy link
Copy Markdown
Owner

Canonical issue

Remediates the failing test check on #1205 (perf/rekognition-offloop). This PR targets perf/rekognition-offloop directly, 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_thread fails 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.py deletes every youtube_extension.*cloud_ai* key from sys.modules at collection time. The aws_rekognition module key matches, so after that eviction the failing 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.object landed 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 empty observed.

Scope

  • Included: patch the method's own __globals__ via patch.dict (the exact namespace _prepare_image_input resolves names from) instead of a re-imported module attribute; drop the now-unused late import.
  • Explicitly excluded: no production code change; no other test touched; the sibling test_cloud_ai_integrator.py eviction pattern is left as-is (its del sys.modules[...] is intentional for its own stubbing).

Risk

  • Risk level: low
  • Failure mode: test-only; __globals__ is a stable CPython attribute of the bound function, immune to sys.modules churn.
  • Rollback: revert commit c375307.

Verification

Tied to head c375307:

  • Focused test passes in isolation and under the real polluting order (test_cloud_ai_integrator.py first, then the target, one session) — before this change that ordering reproduces the exact CI failure (1 failed); after, 62 passed.
  • Full file: 95 passed.
  • ruff check on the file: parity with base (the one pre-existing F841 at line 820 is unrelated and unchanged; zero added).
  • Required CI — will run on this PR's head.
  • Review threads resolved.

Reproduction (local):

# old test, real ordering
pytest tests/unit/test_cloud_ai_integrator.py \
       tests/unit/test_aws_rekognition_provider.py::TestRekognitionDoesNotBlockEventLoop::test_local_image_read_runs_off_the_event_loop_thread
# -> 1 failed: AssertionError: _read_file_bytes was never called
# with this change -> 62 passed

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


Generated by Claude Code

…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.
@vercel

vercel Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
v0-uvai Ready Ready Preview, v0 Aug 1, 2026 11:19pm

@github-actions github-actions Bot added the python label Aug 1, 2026
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (1)
  • [‘architecture-gap’, ‘bug’, ‘ci-cd’, ‘ci/cd’, ‘copilot-rabbit’, ‘documentation’, ‘duplicate’, ‘enhancement’, ‘frontend’, ‘github_actions’, ‘good first issue’, ‘help wanted’, ‘high-priority’, ‘invalid’, ‘javascript’, ‘ml-model’, ‘needs-triage’, ‘pipeline-critical’, ‘placeholder-code’, ‘priority:high’, ‘python’, ‘python:uv’, ‘question’, ‘styling’, ‘tests’, ‘v0’]

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository YAML (base), Repository UI (inherited), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: afa7e452-8a02-4f3d-ad11-b1d50b434017

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown

Agent Completion Truth Gate: BLOCKED

Reasons: invalid_payload

Machine-readable verdict
{
  "details": {
    "invalid_fields": [
      "issue.number",
      "policy.agent_login",
      "policy.run_id"
    ]
  },
  "reasons": [
    "invalid_payload"
  ],
  "verdict": "blocked"
}

Workflow evidence

Copy link
Copy Markdown
Owner Author

CI triage for this PR

The substantive change here (c375307, test-only) is verified: under the real polluting order — test_cloud_ai_integrator.py then the target test in one session — the previous test reproduces the exact CI failure (AssertionError: _read_file_bytes was never called), and with this change that ordering passes (62 passed); full file 95 passed; ruff at parity with base.

The remaining red checks on this head are all pre-existing, repo-wide gates that are red on the base branch (perf/rekognition-offloop) and on #1205 itself — none is caused by this one-file test diff, and I am deliberately not forcing them green:

What this PR does deliver: the Python test job is not in this PR's scoped check set (base is perf/rekognition-offloop, diff is test-only), but merging this — or cherry-picking c375307 onto perf/rekognition-offloop — is what turns #1205's test job green. The infra/policy gates above then remain, identically to #1205, and need their own fixes (#1197/#1142 for gitleaks, #1151/#1154 for the agent gate) rather than anything in this change.

Human decision requested: merge this into perf/rekognition-offloop (or cherry-pick the commit), then take #1205 through its own merge approval to main.


Generated by Claude Code

Copy link
Copy Markdown
Owner Author

Contained as a duplicate repair. The verified __globals__-based test fix was transferred onto canonical branch perf/rekognition-offloop / PR #1205 at exact head af04aedb59d5b46871c46ab945536faa58c97d91. This PR is being closed unmerged; its branch and commit c3753073ca0bf6951340edc8f3416487177c2041 are preserved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants