test(providers): adopt providertest and testify in core provider tests - #981
Conversation
|
Warning Review limit reachedNext included review available in 30 seconds. View limit detailsLimit details: You’ve used all 4 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (66)
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 |
|
| @@ -348,16 +313,11 @@ func TestApplyConfigMetadataOverrides_NonNilEmptyReplacementsDoesNotPanic(t *tes | |||
| } | |||
| replacements := make(map[*ModelInfo]*ModelInfo) // non-nil, empty | |||
| applied := applyConfigMetadataOverrides(overrides, modelsByProvider, replacements) | |||
| if applied != 1 { | |||
| t.Errorf("applied = %d, want 1", applied) | |||
| } | |||
| assert.Equal(t, 1, applied) | |||
|
|
|||
| next := modelsByProvider["p"]["m"] | |||
| if next == existing { | |||
| t.Error("expected a replacement ModelInfo pointer, got original") | |||
| } | |||
| if replacements[existing] != next { | |||
| t.Errorf("replacements[existing] = %p, want %p", replacements[existing], next) | |||
| } | |||
| assert.NotSame(t, existing, next) | |||
| assert.Equal(t, next, replacements[existing]) | |||
There was a problem hiding this comment.
These assertions document identity guarantees: a no-op override must retain the captured ModelInfo pointer, and the replacement map must contain the exact installed replacement. assert.Equal accepts distinct pointers with equal contents, so a regression that replaces either pointer would still pass. Use assert.Same for both checks. This is non-blocking, but it leaves the documented concurrency-safety contract unprotected.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Artifacts
- The executable creates distinct but equal ModelInfo pointers and compares them with both assertion forms, demonstrating that deep equality does not enforce identity.
- The output shows distinct pointers where assert.Equal succeeds and assert.Same fails, confirming that the current checks cannot detect replacement.
- The focused registry tests pass with the current deep-equality assertions, showing that the gap is not caught by the existing test suite.
|
Both identity checks in registry_metadata_override_test.go now use |
b56823b to
6efe85d
Compare
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Rewrites the tests of the
providersroot package and theanthropic,gemini, andopenaiadapters on top of the sharedprovidertestservers and testify.httptest.NewServerrequest-capture setups in the three adapter packages becomeprovidertest.JSONServer/SSEServer/RouteServerpluscapture.Last(t); hand-written handlers stay only where they implement multi-step behaviour (cached content reuse, key rotation, batch upload, breaker isolation).require/assert; pointer identity checks useSame/NotSame, JSON comparisons useJSONEq.TestProviderFactory_HooksPassedToBuilder(subset ofTestProviderFactory_SetHooks), the five per-typeTestApplyProviderEnvVars_Discovers*FromAPIKeytests folded into one table, and the openai reasoning/GPT-5 token-parameter and tool-configuration tests folded into tables with identical per-case assertions.The root package tests keep hand-rolled servers because
providertestimportsproviders. Test-only change, about 6,600 net lines removed. Stacked on #976 (helper packages).