Skip to content

Build/Test Tools: Add live AI provider tests for the core abilities - #16029

Closed
jorgefilipecosta wants to merge 16 commits into
WordPress:trunkfrom
jorgefilipecosta:add/ai-client-live-provider-tests
Closed

jorgefilipecosta wants to merge 16 commits into
WordPress:trunkfrom
jorgefilipecosta:add/ai-client-live-provider-tests

Conversation

@jorgefilipecosta

@jorgefilipecosta jorgefilipecosta commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

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_LiveProviders asks 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.
  • The tests send real requests to paid APIs, so they live in tests/phpunit/manual, which no test suite includes: a run of the external-http group, such as the one on CI, does not select them. They are in the external-http group, 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 a WP_TESTS_AI_*_API_KEY environment variable or constant.
  • Only the tests read these names. A key set for a provider tool or for the Connectors, such as ANTHROPIC_API_KEY, does not start them, and the local site does not use a key set for the tests.
  • The provider packages become Composer development dependencies: wordpress/ai-provider-for-anthropic, wordpress/ai-provider-for-google and wordpress/ai-provider-for-openai.
  • The local Docker environment passes the key variables to the PHP container when they are set. .env.example documents the variables and wp-tests-config-sample.php the constants.

Trac ticket: https://core.trac.wordpress.org/ticket/66707

Testing

1. Install the provider packages

npm run env:start installs them. With the environment already running:

npm run env:composer -- update

Without Docker:

composer update

2. Set the API key of each provider to test

Provider Variable
Anthropic WP_TESTS_AI_ANTHROPIC_API_KEY
Google WP_TESTS_AI_GOOGLE_API_KEY
OpenAI WP_TESTS_AI_OPENAI_API_KEY

A provider without a key is skipped, so one key is enough to start.

With the Docker environment, add the keys to the .env file, which Git ignores:

WP_TESTS_AI_ANTHROPIC_API_KEY=your-key
WP_TESTS_AI_GOOGLE_API_KEY=your-key
WP_TESTS_AI_OPENAI_API_KEY=your-key

Without Docker, export them in the shell:

export WP_TESTS_AI_ANTHROPIC_API_KEY=your-key

or define them as constants in wp-tests-config.php.

3. Run the tests

npm run test:php -- --group external-http --test-suffix .php tests/phpunit/manual

Without Docker:

vendor/bin/phpunit --group external-http --test-suffix .php tests/phpunit/manual

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:

  • One provider: --filter '@openai.*'
  • One test: --filter '@google, core/users-query'
  • Multisite: add -c tests/phpunit/multisite.xml
  • The reason for each skipped test: add --verbose
  • Another model: set WP_TESTS_AI_ANTHROPIC_MODEL, WP_TESTS_AI_GOOGLE_MODEL or WP_TESTS_AI_OPENAI_MODEL next to the key, for example WP_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

  • Skipped: the key is not set, or the provider is unavailable (rate limit, server error or timeout).
  • Failed: the provider rejected the key, the request failed for any other reason (for example a response the provider changed, or an AI Client that is turned off), the model did not call the ability, the ability returned an error, or the answer does not contain the expected value.

AI disclosure: the change and tests were drafted with AI assistance (Claude Code) and reviewed by me.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

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:

Props jorgefilipecosta, lancewillett.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

@jorgefilipecosta

Copy link
Copy Markdown
Member Author

Hi @lancewillett, thank you for the review.

could you explain what the six individual ability calls catch beyond the combined call for each provider?

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.

Please confirm that contract.

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 lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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-http on every PR (reusable-phpunit-tests-v3.yml), and this PR passes the WP_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.dist and tests/phpunit/multisite.xml, the way html-api-web-platform-tests is, 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-http tests 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.

@lancewillett

Copy link
Copy Markdown
Member

@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 @group external-http. Core checks that group before allowing a real HTTP request. I tried moving just the test file outside the default suite into tests/phpunit/manual/. The ordinary external-HTTP run then selected zero provider cases. This explicit run found all 21 and skipped them without credentials:

vendor/bin/phpunit --group external-http --filter Tests_AI_Client_LiveProviders --test-suffix .php tests/phpunit/manual

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 · gpt-6

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.
@jorgefilipecosta
jorgefilipecosta force-pushed the add/ai-client-live-provider-tests branch from 0fd3252 to f94fd86 Compare November 26, 2026 15:54
…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.

@lancewillett lancewillett left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
…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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the opt-in live-provider test changes.

2 open issues

Review effort: Balanced

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

wporg-sync pushed a commit that referenced this pull request Nov 28, 2026
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
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 65819
GitHub commit: 43413fc

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Nov 28, 2026
@github-project-automation github-project-automation Bot moved this from Neeeds review to Done in Core abibilities Nov 28, 2026
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 28, 2026
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
@lancewillett

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Core abilities Core abilities related tasks

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants