Repository navigation
Build/Test Tools: Add live AI provider tests for the core abilities - #16029
jorgefilipecosta wants to merge 16 commits into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
lancewillett
left a comment
There was a problem hiding this comment.
The live provider boundary is useful: mocked tests cannot catch a provider rejecting a function schema or returning an unusable function call. Before landing, could you explain what the six individual ability calls catch beyond the combined call for each provider? That will help us choose the smallest useful matrix, or justify keeping all 21 cases.
I read this as an opt-in diagnostic, since network, rate-limit and server failures skip. Please confirm that contract. I have not exercised the live requests, so green CI is not evidence that this boundary works.
AI review · gpt-6
86c5907 to
0fd3252
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The live-provider tests can pass despite ability errors and incorrectly skip installed providers when the checkout’s Composer autoloader is not loaded.
2 open issues
What changed in this PR
Adds opt-in live integration tests to verify that Anthropic, Google, and OpenAI can call WordPress core abilities through the AI Client.
Changes:
- Adds 21 test cases covering six abilities individually and together for each provider.
- Adds provider packages as Composer development dependencies.
- Documents test-only credentials and model overrides, and passes them into the local PHP container.
| File | Description |
|---|---|
wp-tests-config-sample.php |
Documents optional test credentials and model constants. |
tests/phpunit/tests/ai-client/wpAiClientLiveProviders.php |
Adds live provider tests, fixtures, ability execution, and response checks. |
docker-compose.yml |
Passes test credentials and model overrides to PHP. |
composer.json |
Adds three AI provider development dependencies. |
.env.example |
Documents live-test configuration and execution. |
Review effort: Balanced
|
Hi @lancewillett, thank you for the review.
When a provider rejects a schema it stops at the first one and says nothing about the others. I ran the tests today and the new OpenAI default model rejects uniqueItems, the combined test only reported tools[3] while the individual tests showed settings-get, users-query and content-query were all failing. They also make it easier to tell if the problem is the schema or the model not calling one of the six abilities. I think it is worth keeping them, a full run takes less than a minute and a single provider can be run with --filter. The OpenAI fix is at WordPress/ai-provider-for-openai#61.
Yes, without a key the tests are skipped, so on CI all of them skip. Rate limits, server errors and network errors also skip. A rejected key, a model that does not exist, a request the provider rejects, an ability that is not called or a wrong answer make the test fail. |
lancewillett
left a comment
There was a problem hiding this comment.
@jorgefilipecosta thanks, that answers my question. The combined case stops at the first rejected schema, and the per-ability cases showed three abilities failing on OpenAI. Let's keep all 21.
One change before this lands: please move these tests out of external-http into their own group.
- Why: CI runs
external-httpon every PR (reusable-phpunit-tests-v3.yml), and this PR passes theWP_TESTS_AI_*variables into Docker. Today every case skips because CI has no keys. If keys are ever added to the workflow, every PR run makes paid calls. A separate group keeps paid calls opt-in by design, not by a missing secret. - How: exclude the new group in
phpunit.xml.distandtests/phpunit/multisite.xml, the wayhtml-api-web-platform-testsis, but don't add a PR job for it. Run it locally with--group, or later from a manual or scheduled workflow on this repo once someone owns the keys and the budget. Fork PRs can't read secrets anyway. - Also:
external-httptests are free to run. Mixing paid tests into that group changes what it means for everyone who runs it.
I'll update the ticket to match once the group is in.
|
@jorgefilipecosta your OpenAI example answers my question. Please keep the 21 cases. Reporting the three rejected abilities separately gives us something the combined call cannot. One correction to my earlier suggestion: keep
That would keep routine CI free of paid calls without changing the shared workflow. Please update the run instructions to match. The two inline threads about provider discovery and a failed ability followed by a successful retry are also still open. AI review · |
Adds `Tests_AI_Client_LiveProviders`, which asks the Anthropic, Google and OpenAI providers questions they can only answer by calling the core abilities through the AI Client. Every provider is tested with each core ability on its own and with all of them together.
The tests send real requests, so they are in the `external-http` group, and the tests of a provider are skipped unless its API key is in the `ANTHROPIC_API_KEY`, `GOOGLE_API_KEY` or `OPENAI_API_KEY` environment variable. A `WP_TESTS_AI_{PROVIDER}_MODEL` variable selects a model other than the default one of the provider.
The provider packages become Composer development dependencies, and the local Docker environment passes the variables to the PHP container when they are set.
…der is unavailable. The tests are now skipped only on a rate limit, a server error of the provider or a network error. Any other error fails them, including a response the provider changed and a disabled AI Client. See #66707.
…tests. The tests now read the API keys from `WP_TESTS_AI_ANTHROPIC_API_KEY`, `WP_TESTS_AI_GOOGLE_API_KEY` and `WP_TESTS_AI_OPENAI_API_KEY`. A key set for a provider tool or for the Connectors does not start them, and the local site does not use a key set for the tests. A model name the provider does not list now fails the test, and an ability only counts as called when it ran without an error. The provider packages are pinned to the versions the tests ran with. See #66707.
…er of the live AI provider tests. The number of requests a model may take now follows the number of abilities, so a model that calls one ability per response can still answer when it is given all six. The model of each result is compared with the requested one, which also catches a listed model that cannot be used for the prompt. Every text part of the answer is read, not only the first one. See #66707.
…settings from constants too. An ability now counts as called when the `wp_after_execute_ability` action fires, which only happens after it ran without an error. A model named in `WP_TESTS_AI_*_MODEL` is used directly instead of as a preference, so no request goes to another model, and a model the provider does not list still fails the test. The API keys and models can also be set as constants, for example in `wp-tests-config.php`. The timezone option is set once for the class, and the super admin status is no longer revoked by hand, since the options are restored after each class. See #66707.
…constants. Removes the unregister loops that ran before the core abilities are registered, resolves a named model once instead of on every request, and catches client errors apart from network and server errors. Documents the key and model constants in `wp-tests-config-sample.php` and `.env.example`, and says that the keys reach the PHP container that serves the local site. See #66707.
0fd3252 to
f94fd86
Compare
…tes. The tests now live in `tests/phpunit/manual`, which no test suite includes, so a run of the `external-http` group, such as the one on CI, does not select them. They only run when that directory is named. See #66707.
There was a problem hiding this comment.
The move to tests/phpunit/manual works. I found zero cases in ordinary external-http discovery and 21 credential skips when I selected the manual directory, on both single-site and multisite. PHPCS passed. The 21 cases retain the per-ability diagnostics from your OpenAI example.
Two issues remain in 4703a4b:
- With the provider packages installed, PHPUnit 9.6.39 from its PHAR still skips the OpenAI case as “packages are not installed.” A bootstrap probe found the class only after requiring the checkout’s
vendor/autoload.php. Please load that autoloader after the credential check so a configured diagnostic reaches the provider. - The resolver’s error response can disappear from the final result. I passed invalid arguments and then valid arguments to
core/get-site-info. The first call returned an error, the second recorded a successful call and returned UTF-8. Those final values can satisfy both assertions if the model retries and quotes UTF-8. Please fail on the resolver’s error response as the PR describes.
I used a placeholder for the PHAR skip check and made no live provider requests.
AI review · gpt-6.2-sol
…m a PHAR. A PHPUnit PHAR does not load the Composer autoloader of the checkout, so the live AI provider tests skipped as if the provider packages were not installed. The tests now load that autoloader when a provider class is missing. See #66707.
…urns an error. An ability error was sent back to the model without failing the test, so a model that retried and then answered could still pass it. The test now fails on the first error response of the resolver. See #66707.
… provider tests. The users-query ability returns the display name as `name`. When the question asked for the display name, a model given every ability could request a `display_name` field, which only the get-user-info ability has. See #66707.
…s from a PHAR. The Composer autoloader of the checkout goes in front of the autoloader of the PHAR and also maps the PHPUnit classes of the checkout, so a run could mix two PHPUnit versions. The tests now load the classes of the provider package from its own directory. See #66707.
…AI provider tests to 1.3.0. See #66707.
…settings from the environment first. Since an ability error fails the test, the abilities that ran are recorded from the responses of the resolver instead of an action. An error now also shows its data, and the setup pops the simulated actions in finally blocks. An environment variable now takes precedence over the constant, as in the AI Client, so an empty constant in wp-tests-config.php no longer hides a key in the environment. The sample config lists the model constants too. See #66707.
…n one place. The provider packages get their autoloaders once, before the tests run, and an autoloader returns early for classes outside its namespace. The settings helper is shorter, and two docblocks are corrected. The test file now documents the Docker run command, so `.env.example` points to it instead of repeating the instructions. See #66707.
…I provider tests. Handle the failed model list in one catch block, keep the namespace of each provider package next to its class, register the core abilities and their categories in one simulated action context, and document the model IDs and the precedence of a non-empty environment variable. See #66707.
lancewillett
left a comment
There was a problem hiding this comment.
I verified both earlier findings against 79e1f52. Under the same PHPUnit PHAR, the installed OpenAI class remained undiscoverable after the old fixture setup and was discoverable after the revised setup. With the real site-info resolver, the old success hook accepted a valid retry after an invalid call. The new response guard failed on the invalid call and accepted the valid one.
On both single-site and multisite, seed 66707 gave 325 tests and 828 assertions in the existing AI Client suite. Routine external-HTTP discovery selected zero manual provider cases. Explicit discovery selected 21 and skipped all 21 without credentials. PHPCS passed. I made no live provider requests.
AI review · gpt-6.2-sol
Exercise each core ability separately and together across the three providers. Keep the suite outside ordinary PHPUnit discovery so contributors can run it explicitly with their own credentials. Surface rejected schemas and failed ability calls. Developed in: #16029 Props jorgefilipecosta. Fixes #66707. git-svn-id: https://develop.svn.wordpress.org/trunk@65819 602fd350-edb4-49c9-b593-d223f7449a82
Exercise each core ability separately and together across the three providers. Keep the suite outside ordinary PHPUnit discovery so contributors can run it explicitly with their own credentials. Surface rejected schemas and failed ability calls. Developed in: WordPress/wordpress-develop#16029 Props jorgefilipecosta. Fixes #66707. Built from https://develop.svn.wordpress.org/trunk@65819 git-svn-id: http://core.svn.wordpress.org/trunk@64848 1a063a9b-81f0-0310-95a4-ce76da25c4cd
|
PR #16029 landed in https://core.trac.wordpress.org/changeset/65819 |

This PR adds live tests that check the Anthropic, Google and OpenAI providers can call the core abilities through the AI Client:
Tests_AI_Client_LiveProvidersasks each provider questions it can only answer by calling an ability. Every provider gets each core ability on its own (core/get-site-info,core/get-user-info,core/get-environment-info,core/settings-get,core/users-query,core/content-query) and all six together: 21 tests.tests/phpunit/manual, which no test suite includes: a run of theexternal-httpgroup, such as the one on CI, does not select them. They are in theexternal-httpgroup, which Core requires for real requests, and only run when that directory is named. The tests of a provider are also skipped unless its API key is in aWP_TESTS_AI_*_API_KEYenvironment variable or constant.ANTHROPIC_API_KEY, does not start them, and the local site does not use a key set for the tests.wordpress/ai-provider-for-anthropic,wordpress/ai-provider-for-googleandwordpress/ai-provider-for-openai..env.exampledocuments the variables andwp-tests-config-sample.phpthe constants.Trac ticket: https://core.trac.wordpress.org/ticket/66707
Testing
1. Install the provider packages
npm run env:startinstalls them. With the environment already running:Without Docker:
2. Set the API key of each provider to test
WP_TESTS_AI_ANTHROPIC_API_KEYWP_TESTS_AI_GOOGLE_API_KEYWP_TESTS_AI_OPENAI_API_KEYA provider without a key is skipped, so one key is enough to start.
With the Docker environment, add the keys to the
.envfile, which Git ignores:Without Docker, export them in the shell:
or define them as constants in
wp-tests-config.php.3. Run the tests
Without Docker:
With the three keys set, the result is
OK (21 tests, 84 assertions)after about 70 seconds and 63 requests: a model list and two prompts for each test, and one more prompt for each round a model calls another ability.Options
These work with both commands:
--filter '@openai.*'--filter '@google, core/users-query'-c tests/phpunit/multisite.xml--verboseWP_TESTS_AI_ANTHROPIC_MODEL,WP_TESTS_AI_GOOGLE_MODELorWP_TESTS_AI_OPENAI_MODELnext to the key, for exampleWP_TESTS_AI_GOOGLE_MODEL=gemini-3.5-flash-lite. A free-tier Google key may have no quota for the default Gemini model, so it needs one. A model the provider cannot use for these prompts, such as a mistyped name or an image model, fails the test.Reading the result
AI disclosure: the change and tests were drafted with AI assistance (Claude Code) and reviewed by me.