[in progress] Add provider credentials verification - #299
jorgefilipecosta wants to merge 1 commit into
Conversation
ListModelsApiBasedProviderAvailability::isConfigured() reports every failure as false and relies on the cached model list, so it cannot tell rejected credentials apart from a network error, and it keeps reporting success for other credentials while the list is cached. Add VerifiesCredentialsInterface and ProviderRegistry::verifyProviderCredentials(). The list models availability check implements the interface: it invalidates the cached model list, returns false only when the provider rejects the request, and throws for network errors, server errors, timeouts and rate limits.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #299 +/- ##
============================================
+ Coverage 86.58% 86.62% +0.04%
- Complexity 1383 1389 +6
============================================
Files 69 69
Lines 4449 4464 +15
============================================
+ Hits 3852 3867 +15
Misses 597 597
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…rification. Stand-in for bundling a php-ai-client release that includes WordPress/php-ai-client#299. Generated with tools/php-ai-client/installer.sh from 1.3.1 plus that change.
What?
Adds a way to verify a provider's credentials that tells credentials the provider rejected apart from failures that say nothing about them.
VerifiesCredentialsInterfacewithverifyCredentials(): bool.ListModelsApiBasedProviderAvailabilityimplements it.ProviderRegistry::verifyProviderCredentials(), which falls back toisConfigured()for availability checks that don't implement the interface.Why?
isConfigured()reports every failure asfalseand uses the cached model list. WordPress validates connector API keys with it, so a provider outage during a settings save wipes a valid key, and a wrong key passes while the model list is cached: https://core.trac.wordpress.org/ticket/65551How?
verifyCredentials()invalidates the cached model list, lists models, and returnsfalseonly for a 4xx response other than 408 or 429 (Google answers a bad key with 400). Network errors, 5xx, 408 and 429 are rethrown.GenerateTextApiBasedProviderAvailabilityis unchanged, as no official provider uses it. Happy to add it here too.Testing
Verify unit tests are passing:
Issue found via AI-assisted code review; fix and tests drafted with AI assistance (Claude Code) and reviewed by me.