Repository navigation
Conversation
Avoid panicking when http.DefaultTransport is replaced by a custom RoundTripper by falling back to a safe transport, and add regression coverage for the custom-transport case. Co-authored-by: Cursor <[email protected]>
📝 WalkthroughWalkthrough
ChangesHTTP Transport Robustness
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/entity/models/modelscope_test.go (1)
88-100: ⚡ Quick winStrengthen the assertion to verify internal fields.
The test only checks if the model is non-nil, but should also verify that
model.httpClientandmodel.httpClient.Transportare non-nil to confirm the fallback path constructs a complete model.🧪 Proposed fix to strengthen the test assertion
- if model := NewModelScopeModel(map[string]string{"default": "http://unused"}, URLSuffix{}); model == nil { - t.Fatal("NewModelScopeModel returned nil") + model := NewModelScopeModel(map[string]string{"default": "http://unused"}, URLSuffix{}) + if model == nil || model.httpClient == nil || model.httpClient.Transport == nil { + t.Fatalf("NewModelScopeModel returned incomplete model: %#v", model) }Based on learnings: The groq_test.go test for the same scenario verifies
model.httpClientandmodel.httpClient.Transportare non-nil (internal/entity/models/groq_test.go:62-79).🤖 Prompt for 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. In `@internal/entity/models/modelscope_test.go` around lines 88 - 100, Update the test TestModelScopeNewModelWithCustomDefaultTransport to assert not only that NewModelScopeModel(...) returns non-nil but also that the returned model's httpClient and httpClient.Transport are non-nil; locate the model created by calling NewModelScopeModel and add assertions checking model.httpClient != nil and model.httpClient.Transport != nil (mirroring the checks in groq_test.go) to ensure the fallback path builds a fully initialized HTTP client.
🤖 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.
Nitpick comments:
In `@internal/entity/models/modelscope_test.go`:
- Around line 88-100: Update the test
TestModelScopeNewModelWithCustomDefaultTransport to assert not only that
NewModelScopeModel(...) returns non-nil but also that the returned model's
httpClient and httpClient.Transport are non-nil; locate the model created by
calling NewModelScopeModel and add assertions checking model.httpClient != nil
and model.httpClient.Transport != nil (mirroring the checks in groq_test.go) to
ensure the fallback path builds a fully initialized HTTP client.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 87bef510-70c1-4f2a-860d-c98b2d0af703
📒 Files selected for processing (2)
internal/entity/models/modelscope.gointernal/entity/models/modelscope_test.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15339 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
NewModelScopeModelto avoid panics whenhttp.DefaultTransportis a custom non-*http.TransportRoundTripper.ProxyFromEnvironment) while preserving existing pooling/timeout settings.TestModelScopeNewModelWithCustomDefaultTransportregression coverage.Test plan
go test ./internal/entity/models/ -run TestModelScope -count=1(cannot run locally:gois unavailable in this environment)