-
Notifications
You must be signed in to change notification settings - Fork 2
Add wp ai is-supported command
#13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |
| "ai", | ||
| "ai check", | ||
| "ai generate", | ||
| "ai is-supported", | ||
| "ai status", | ||
| "connectors", | ||
| "connectors get", | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,25 @@ | ||||||||||||||
| Feature: Check if AI features are supported | ||||||||||||||
|
|
||||||||||||||
| Background: | ||||||||||||||
| Given a WP install | ||||||||||||||
|
|
||||||||||||||
| @less-than-wp-7.0 | ||||||||||||||
| Scenario: Command not available on WP < 7.0 | ||||||||||||||
|
||||||||||||||
| Scenario: Command not available on WP < 7.0 | |
| Scenario: Errors on WP < 7.0 |
Copilot
AI
Mar 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The “AI is supported by default” scenario only asserts the exit code. Since this PR is introducing a user-facing command, it would be good to also assert the expected success output (to prevent regressions where the command stays silent).
| Then the return code should be 0 | |
| Then the return code should be 0 | |
| And STDOUT should contain: | |
| """ | |
| AI is supported | |
| """ |
Copilot
AI
Mar 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The “AI is not supported when disabled via filter” scenario only checks the exit code. To validate the new behavior end-to-end, add an assertion for the expected error message on STDERR (per the PR description/example).
| Then the return code should be 1 | |
| Then the return code should be 1 | |
| And STDERR should contain: | |
| """ | |
| Error: AI is not supported when disabled via filter. | |
| """ |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |||||||||||||
| namespace WP_CLI\AI; | ||||||||||||||
|
|
||||||||||||||
| use WP_CLI; | ||||||||||||||
| use WP_CLI\Utils; | ||||||||||||||
| use WP_CLI_Command; | ||||||||||||||
| use WordPress\AiClient\Results\DTO\TokenUsage; | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -118,10 +119,19 @@ class AI_Command extends WP_CLI_Command { | |||||||||||||
| public function generate( $args, $assoc_args ) { | ||||||||||||||
| list( $type, $prompt ) = $args; | ||||||||||||||
|
|
||||||||||||||
| // @phpstan-ignore function.notFound | ||||||||||||||
| if ( ! wp_supports_ai() ) { | ||||||||||||||
| WP_CLI::error( 'AI features are not supported in this environment.' ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| try { | ||||||||||||||
| // @phpstan-ignore function.notFound | ||||||||||||||
| $builder = wp_ai_client_prompt( $prompt ); | ||||||||||||||
|
|
||||||||||||||
| if ( is_wp_error( $builder ) ) { | ||||||||||||||
| WP_CLI::error( $builder->get_error_message() ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if ( isset( $assoc_args['provider'] ) ) { | ||||||||||||||
| $builder = $builder->using_provider( $assoc_args['provider'] ); | ||||||||||||||
| } | ||||||||||||||
|
|
@@ -185,6 +195,32 @@ public function generate( $args, $assoc_args ) { | |||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Checks whether AI features are supported in the current environment. | ||||||||||||||
| * | ||||||||||||||
| * Exits with code 0 if AI features are supported, or code 1 if they are not. | ||||||||||||||
| * | ||||||||||||||
| * ## EXAMPLES | ||||||||||||||
| * | ||||||||||||||
| * # Check if AI is supported | ||||||||||||||
| * $ wp ai is-supported | ||||||||||||||
| * Success: AI features are supported. | ||||||||||||||
| * | ||||||||||||||
| * @subcommand is-supported | ||||||||||||||
| * | ||||||||||||||
| * @param string[] $args Positional arguments. Unused. | ||||||||||||||
| * @param string[] $assoc_args Associative arguments. Unused. | ||||||||||||||
| * @return void | ||||||||||||||
| */ | ||||||||||||||
| public function is_supported( $args, $assoc_args ) { | ||||||||||||||
| // @phpstan-ignore function.notFound | ||||||||||||||
| if ( wp_supports_ai() ) { | ||||||||||||||
| WP_CLI::halt( 0 ); | ||||||||||||||
| } else { | ||||||||||||||
| WP_CLI::halt( 1 ); | ||||||||||||||
|
Comment on lines
+218
to
+220
|
||||||||||||||
| WP_CLI::halt( 0 ); | |
| } else { | |
| WP_CLI::halt( 1 ); | |
| WP_CLI::success( 'AI features are supported.' ); | |
| } else { | |
| WP_CLI::error( 'AI features are not supported in this environment.' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two scenarios named “Generates text using mock provider”, but they test different behavior (
wp ai statusvswp ai generate text). Renaming one of them would make failures easier to interpret and keep the feature file clearer.