Skip to content

🧪 add tests for request_context.py - #19738

Merged
undivisible merged 2 commits into
mainfrom
test-coverage-llm-gateway-request-context-12321582620649684028
Oct 19, 2026
Merged

undivisible merged 2 commits into
mainfrom
test-coverage-llm-gateway-request-context-12321582620649684028

Conversation

@undivisible

@undivisible undivisible commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

🎯 What: The testing gap addressed: created unit tests for llm_gateway/gateway/request_context.py
📊 Coverage: Covered all utility methods such as jit_budget_forward_headers, jit_budget_headers_for, request_id_for, resolve_request_id, and validated_jit_budget_values. Also verified mock Request headers parsing.
✨ Result: Improved overall backend test coverage and caught edge cases related to empty and unparsable states in FastAPI requests.
Failure-Class: none


PR created automatically by Jules for task 12321582620649684028 started by @undivisible

Review in cubic

Add missing unit tests to cover utility methods and valid/invalid
JIT budget headers resolution for FastAPI requests.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-29T09:00:32.851888Z 93c1a1c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 93c1a1c468

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@@ -0,0 +1,157 @@
import uuid

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Put the gateway test under the selector's matching path

When a later PR changes only backend/llm_gateway/gateway/request_context.py, the changed-file selector maps backend/llm_gateway/ exclusively to tests/unit/test_llm_gateway_*.py, so this nested test is omitted from the selected PR/pre-push suite and runs only during an --all build. Move it to the matching root-level naming convention or extend AREA_TESTS to include nested gateway tests so the new regression coverage actually guards future changes.

AGENTS.md reference: backend/AGENTS.md:L205-L205

Useful? React with 👍 / 👎.

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test-only addition covering llm_gateway/gateway/request_context.py — reviewed assertion-by-assertion against the source and executed locally.

  • backend/tests/unit/llm_gateway/gateway/test_request_context.py: all 14 tests pass. The assertions match the production branches exactly: env-gated unavailability when JIT_BUDGET_CONTRACT_ENV mismatches, contract/run-id grammar (JIT_RUN_ID_PATTERN rejecting both 'invalid run id!' and ''), non-integer and non-positive budget headers, and the qualification ceilings — max_attempts=4 is correctly rejected against the ceiling tuple (3, 2048, 32768, 50000) in request_context.py. jit_budget_forward_headers asserts the canonical X-Omi-Jit-* relay names, and resolve_request_id covers UUID case-normalization plus opaque-ID regeneration for non-UUID/oversized inputs. The mock ASGI scope in build_mock_request also exercises the request.state.request_id fallbacks behind request_id_for, including the empty-string and missing-attr paths.
  • No overlap with existing coverage: tests/unit/test_llm_gateway_openai_compatible.py touches jit_budget_headers_for only at the router level, so this file fills a real gap.
  • One non-blocking nit: from dataclasses import dataclass at the top of the new test file is unused.

Coverage is consistent with the wire contract in backend/docs/runbooks/jit-qa-cloud-run.md. Thanks @undivisible!


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test-only PR (request_context.py coverage), not a bug fix - approve-only. CI clean.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-confirmed: test/perf/refactor addition, not a bug fix — backend confidence gate requires a bug/issue fix to merge, so this stays approve-only per policy.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undivisible test-only PR (test_request_context.py) — zero production risk

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test-only PR — adds backend/tests/unit/llm_gateway/gateway/test_request_context.py only; zero production risk, CI green.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test-only coverage addition (undivisible), verified real test content, CI clean/non-blocking, no abuse signal. Approve-only per confidence gate (not a bug fix).

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undivisible test-only PR (request_context tests) -- approve, test-only

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undivisible test-only addition, zero production risk (per standing memory on the 09-24 flood) — approve only, not a bug fix

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test-only addition for request_context.py - approve-only. CI green.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test-only coverage addition, not a bug fix — approve only per policy, not merged.

@undivisible
undivisible merged commit 56a988b into main Oct 19, 2026
57 checks passed
@undivisible
undivisible deleted the test-coverage-llm-gateway-request-context-12321582620649684028 branch October 19, 2026 15:07
Git-on-my-level added a commit that referenced this pull request Oct 19, 2026
Five unit files fail on current main. Each one passed on its own PR's base
and broke when main moved underneath it; none is a product regression.

- test_request_context.py (#19738): tested the JIT budget surface that
  #22209 removed from llm_gateway/gateway/request_context.py. Keep the
  request-id tests; drop the tests for removed code.
- test_users_joan_followup_tombstone_guard.py (#19867): called
  delete_person_endpoint, but the joan followup route is
  delete_followup_question_endpoint.
- test_developer_from_segments_idempotency.py (#21265): process fakes
  rejected the trigger=CLIENT_FINALIZE kwarg the router passes since #19788.
- test_external_tools_sanitization.py (#19406): the stubbed utils package
  lacked utils.generated_compute (#21488) and utils.model_text. Stub the
  default-off gate as disabled and load the stdlib-only model_text for real.
- test_batch_upload_storage.py: the database.vector_db stub lacked
  delete_action_item_vectors_batch, which merge_conversations imports since
  #15953.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Git-on-my-level added a commit that referenced this pull request Oct 19, 2026
)

* fix(backend): restore pyright-clean main after #22207 and #22326

Main's backend unit shards fail the enforced pyright lane:

- database/desktop_previews.py (#22207): 16 reportUnnecessaryIsInstance
  errors. The runtime guards stay; they move into validators that take
  `object` (_payload, _string, _expected_generation, _datetime), so the
  checks are meaningful to pyright. Public signatures, error messages and
  check order are unchanged.
- utils/sync/pipeline.py:process_segment (#22326 on top of #22452):
  "code is too complex to analyze". Behaviour-neutral split: the two
  identical cap-hold defer blocks become one hold_for_cap closure, and the
  final-pass / speaker-identification block moves to
  _assign_segment_speakers with the same exception handling.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(backend): repair unit tests that drifted from main across merges

Five unit files fail on current main. Each one passed on its own PR's base
and broke when main moved underneath it; none is a product regression.

- test_request_context.py (#19738): tested the JIT budget surface that
  #22209 removed from llm_gateway/gateway/request_context.py. Keep the
  request-id tests; drop the tests for removed code.
- test_users_joan_followup_tombstone_guard.py (#19867): called
  delete_person_endpoint, but the joan followup route is
  delete_followup_question_endpoint.
- test_developer_from_segments_idempotency.py (#21265): process fakes
  rejected the trigger=CLIENT_FINALIZE kwarg the router passes since #19788.
- test_external_tools_sanitization.py (#19406): the stubbed utils package
  lacked utils.generated_compute (#21488) and utils.model_text. Stub the
  default-off gate as disabled and load the stdlib-only model_text for real.
- test_batch_upload_storage.py: the database.vector_db stub lacked
  delete_action_item_vectors_batch, which merge_conversations imports since
  #15953.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

3 participants