Fix[Image Generation]: Detect support for connectors that authenticate without an API key (e.g. OAuth)#748
Conversation
|
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. |
has_image_generation_support() skipped connectors that authenticate without an API key (e.g. OAuth) because it only checked for API-key credentials. Also honor connectors the registry reports as configured, consistent with text generation credential detection. Add integration tests covering the API-key path, the non-API-key (configured) path, the missing-capability case, and the unauthenticated/unconfigured skip path.
fc4e693 to
73b28bf
Compare
dkotter
left a comment
There was a problem hiding this comment.
I've left a concern on the use of is_connector_configured but I'd also like more information on where you're encountering this, what AI Provider are you using? My understanding is the Connectors API in WordPress Core doesn't yet support OAuth and only supports API key authentication so trying to understand the real world use case here.
| // covers connectors that authenticate without an API key (e.g. OAuth), | ||
| // consistent with how text generation honors connectors that do not | ||
| // rely on API key settings. | ||
| if ( ! has_connector_authentication( $connector_id ) && ! is_connector_configured( $connector_id ) ) { |
There was a problem hiding this comment.
So the problem with using is_connector_configured is it uses isProviderConfigured which makes actual API requests to verify the connection. We try and stay away from using this as we don't want to make unnecessary API requests and right now, has_image_generation_support is run on basically every admin page load
There was a problem hiding this comment.
Argh. Good catch. I'll see if there is a better way to accomplish this...
Yes, you are correct. This is for an internal AI Gateway which uses oAuth. We handle the auth in our AI connector plugin so from the WordPress connector side it looks like a connector with |
So an easy approach would be to add a filter within the |
…nfigured Addresses review feedback: is_connector_configured() calls isProviderConfigured(), which issues a live API request, and has_image_generation_support() runs on nearly every admin page load. Replace it with a request-free wpai_has_image_generation_support filter so connectors that authenticate without an API key (e.g. OAuth) can advertise support, mirroring the existing wpai_has_ai_credentials pattern. Update tests to cover advertising and suppressing support through the filter.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #748 +/- ##
=============================================
+ Coverage 76.41% 76.71% +0.29%
Complexity 1828 1828
=============================================
Files 87 87
Lines 7764 7764
=============================================
+ Hits 5933 5956 +23
+ Misses 1831 1808 -23
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:
|
…support tests Adds tests for the two patch lines Codecov flagged as uncovered: the memoized cache-hit return path, and the catch/continue guard when a connector's provider throws while listing model metadata.
| * connectors that do not rely on API key settings (e.g. OAuth), without | ||
| * triggering a live API request. | ||
| * | ||
| * @since 1.0.3 |
There was a problem hiding this comment.
All @since statements, both here and in the test file, should be set to x.x.x
What?
Follow up to #679.
has_image_generation_support()skipped connectors that authenticate without an API key (e.g. OAuth) because it only checked for API-key credentials. It now exposes awpai_has_image_generation_supportfilter so those connectors can advertise support — without making any live API requests.Why?
#679 gates the image generation UI on
has_image_generation_support(). That check relied solely onhas_connector_authentication(), which by design only detects API-key credentials (environment variable, constant, or stored option).As a result, a provider that is fully configured but authenticates via OAuth was never counted as supporting image generation, and the image generation UI stayed hidden even though the provider exposes an image-generation-capable model.
This mirrors how AI credential detection already lets connectors that do not rely on API key settings advertise availability through a filter (
wpai_has_ai_credentials).How?
The connector loop still only inspects connectors that have API-key credentials, which is a request-free check. Connectors that authenticate without an API key now advertise support through a new
wpai_has_image_generation_supportfilter, applied to the computed result:This deliberately avoids
is_connector_configured()/isProviderConfigured(), which issues a live API request to verify the connection.has_image_generation_support()runs on nearly every admin page load, so it must stay request-free.A
$reset_cacheparameter allows the per-request memoization to be recomputed (used by the tests, and useful when connector configuration changes within a single request).Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.8
Used for: Investigating the regression, drafting the filter-based fix, and writing the integration tests; reviewed and edited by me.
Testing Instructions
Automated:
tests/Integration/Includes/HelpersTest.phpcovershas_image_generation_support()for the API-key path, the filter path (advertising and suppressing support), the missing-capability case, and the skip path for connectors without credentials.Manual:
wpai_has_image_generation_supportto advertise support (e.g. returntrue).Changelog Entry