refactor(virtualmodels): unify batch-rewrite paths and drop dead rewrite mode#424
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughTwo files in ChangesRewrite Helper Simplification and Batch Extraction
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Confidence Score: 5/5This looks safe to merge.
Reviews (2): Last reviewed commit: "test(virtualmodels): cover the unified b..." | Re-trigger Greptile |
|
Thanks @greptile-apps — added behavior tests for the unified batch path in
I also brought this branch up to date with its base (#423), which resolved the overlap with the scoped-redirect fix landed there —
|
|
Tests look great — solid coverage of all the key paths:
One small note: Otherwise the implementation is clean and the tests are thorough. LGTM. |
2a568b2 to
e6b66d7
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/virtualmodels/batch_preparer.go`:
- Around line 88-119: The function `requestedSelectorForDecodedRequest`
duplicates the logic already provided by
`core.DecodedBatchItemRequest.RequestedModelSelector()` method, which properly
handles selector extraction for all three supported request types using the
`semanticSelectorCarrier` interface. Replace the call to
`requestedSelectorForDecodedRequest(decoded.Request)` with a direct call to
`decoded.RequestedModelSelector()` to eliminate the redundant type switch and
error reconstruction at line 90. After making this change, remove the entire
`requestedSelectorForDecodedRequest` function since it will no longer be needed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: e1f360a5-96da-40cb-8672-d77495c20977
📒 Files selected for processing (3)
internal/virtualmodels/batch_preparer.gointernal/virtualmodels/batch_preparer_test.gointernal/virtualmodels/provider.go
e6b66d7 to
b9d304a
Compare
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/virtualmodels/batch_preparer_test.go`:
- Around line 87-102: The TestBatchPreparerValidateAccess test function
currently only validates the failure cases (disabled model and nil service) but
lacks coverage for the success path. Add a test case within this function that
verifies validateAccess succeeds when called with a non-nil BatchPreparer
service and an enabled model. This should mirror the existing test structure by
first upserting an enabled VirtualModel with the same provider and model
selector, then calling validateAccess on a properly initialized BatchPreparer
instance and asserting that no error is returned, thereby completing the
validation behavior matrix.
- Around line 78-83: The TestRewriteBatchItem_RejectsCrossProviderBatch test
currently only verifies that an error is returned but does not check the error
message content. Modify the test to assert that the returned error message
contains relevant keywords like "single-provider" or "cross-provider" to verify
the correct rejection reason is being enforced. This can be done by checking
that the error message string contains the expected substring after confirming
err is not nil, making the test more self-documenting and better at catching
regressions where the wrong error type is returned.
- Around line 96-98: The test for NewBatchPreparer's validateAccess method when
called with a disabled model only verifies that an error is returned, but does
not verify the error type and code. To ensure compliance with the
ValidateModelAccess contract, enhance the test to assert that the returned error
is specifically an InvalidRequestError with a "model_access_denied" code. This
can be done by type-asserting the error and checking its code field to match the
expected denial response.
- Around line 68-74: In the TestRewriteBatchItem_UnsupportedItem test function,
the current error check only verifies that an error is returned when
rewriteBatchItem is called with an unsupported endpoint. To improve regression
detection, extend the test to also verify the error type matches the expected
invalid request error. Replace the simple nil check with a type assertion or
error comparison that confirms the returned error is the correct invalid request
error type expected for unsupported batch items.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 8effaae7-f4ee-41a9-ab4e-0a72813d55e7
📒 Files selected for processing (3)
internal/virtualmodels/batch_preparer.gointernal/virtualmodels/batch_preparer_test.gointernal/virtualmodels/provider.go
d45d072 to
ad7efab
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/virtualmodels/batch_preparer_test.go`:
- Around line 83-90: The test TestRewriteBatchItem_ValidateRejectsUnauthorized
only verifies that the validator hook error is surfaced, but does not verify
that the validator receives the correct resolved selector. Strengthen the test
by capturing the core.ModelSelector argument passed to the validator function
and asserting it matches the expected resolved target (openai/gpt-4o) rather
than the requested alias (fast). This ensures validation is operating on the
correctly translated model reference, not just that errors propagate.
In `@internal/virtualmodels/provider.go`:
- Around line 528-572: Add focused unit tests for the three rewrite functions:
rewriteChatRequest, rewriteResponsesRequest, and rewriteEmbeddingRequest. Each
test should cover three aspects: successful redirect resolution where the
selector model and provider are correctly rewritten into the returned forward
request, error propagation when resolveRedirectRoutableSelector fails, and nil
request handling. These tests will ensure the provider preservation behavior for
routing and prevent regression against the batch-clearing behavior documented in
the comments.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 63950b4c-379c-4603-951b-e0d22bd5af0e
📒 Files selected for processing (3)
internal/virtualmodels/batch_preparer.gointernal/virtualmodels/batch_preparer_test.gointernal/virtualmodels/provider.go
ad7efab to
0f472f0
Compare
Summary
DRY follow-up to #423 (review item #3). Now that #423 has merged, this PR is rebased onto
mainand keeps only the batch-rewrite cleanup.rewriteBatchSource/rewriteBatchItem.BatchPreparerpassesValidateModelAccess; the provider wrapper passesnil, preserving existing wrapper behavior.requestRewriteMode/rewriteForUpstreammachinery from translated request rewriting.Verification
go test ./internal/virtualmodelsgo test ./...make test-race,make lint,go mod tidy🤖 Generated with Claude Code
Summary by CodeRabbit