Skip to content

Commit d2fdf16

Browse files
committed
Require WordPress 7.0+
1 parent 5fa97e2 commit d2fdf16

6 files changed

Lines changed: 49 additions & 14 deletions

File tree

ai-command.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace WP_CLI\AI;
44

55
use WP_CLI;
6+
use WP_CLI\Utils;
67

78
if ( ! class_exists( '\WP_CLI' ) ) {
89
return;
@@ -14,5 +15,11 @@
1415
require_once $wpcli_ai_autoloader;
1516
}
1617

17-
WP_CLI::add_command( 'ai', AI_Command::class );
18-
WP_CLI::add_command( 'ai credentials', Credentials_Command::class );
18+
$wpcli_ai_before_invoke = static function () {
19+
if ( Utils\wp_version_compare( '7.0-beta1', '<' ) ) {
20+
WP_CLI::error( 'Requires WordPress 7.0 or greater.' );
21+
}
22+
};
23+
24+
WP_CLI::add_command( 'ai', AI_Command::class, [ 'before_invoke' => $wpcli_ai_before_invoke ] );
25+
WP_CLI::add_command( 'ai credentials', Credentials_Command::class, [ 'before_invoke' => $wpcli_ai_before_invoke ] );

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"license": "MIT",
77
"authors": [],
88
"require": {
9-
"wordpress/wp-ai-client": "^0.3.0",
10-
"wp-cli/wp-cli": "^2.12"
9+
"wp-cli/wp-cli": "^2.13"
1110
},
1211
"require-dev": {
12+
"wordpress/wp-ai-client": "^0.3.0",
1313
"wp-cli/wp-cli-tests": "^5"
1414
},
1515
"config": {

features/ai.feature

Lines changed: 0 additions & 10 deletions
This file was deleted.

features/credentials.feature

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,26 @@ Feature: Manage AI provider credentials
33
Background:
44
Given a WP install
55

6+
@less-than-wp-7.0
7+
Scenario: Command not available on WP < 7.0
8+
Given a WP install
9+
10+
When I try `wp ai credentials list`
11+
Then STDERR should contain:
12+
"""
13+
Requires WordPress 7.0 or greater.
14+
"""
15+
And the return code should be 1
16+
17+
@require-wp-7.0
618
Scenario: List credentials when none exist
719
When I run `wp ai credentials list`
820
Then STDOUT should contain:
921
"""
1022
No credentials found.
1123
"""
1224

25+
@require-wp-7.0
1326
Scenario: Set and list credentials
1427
When I run `wp ai credentials set openai --api-key=sk-test123456789`
1528
Then STDOUT should contain:
@@ -23,6 +36,7 @@ Feature: Manage AI provider credentials
2336
[{"provider":"openai","api_key":"sk-*********6789"}]
2437
"""
2538

39+
@require-wp-7.0
2640
Scenario: Get specific provider credentials
2741
When I run `wp ai credentials set anthropic --api-key=sk-ant-api-key-123`
2842
Then STDOUT should contain:
@@ -40,6 +54,7 @@ Feature: Manage AI provider credentials
4054
"api_key":"sk-**********-123"
4155
"""
4256

57+
@require-wp-7.0
4358
Scenario: Delete provider credentials
4459
When I run `wp ai credentials set google --api-key=test-google-key`
4560
Then STDOUT should contain:
@@ -60,6 +75,7 @@ Feature: Manage AI provider credentials
6075
"""
6176
And the return code should be 1
6277

78+
@require-wp-7.0
6379
Scenario: Error when getting non-existent credentials
6480
When I try `wp ai credentials get nonexistent`
6581
Then STDERR should contain:
@@ -68,6 +84,7 @@ Feature: Manage AI provider credentials
6884
"""
6985
And the return code should be 1
7086

87+
@require-wp-7.0
7188
Scenario: Error when setting credentials without api-key
7289
When I try `wp ai credentials set openai`
7390
Then STDERR should contain:
@@ -76,6 +93,7 @@ Feature: Manage AI provider credentials
7693
"""
7794
And the return code should be 1
7895

96+
@require-wp-7.0
7997
Scenario: List multiple credentials in table format
8098
When I run `wp ai credentials set openai --api-key=sk-openai123`
8199
And I run `wp ai credentials set anthropic --api-key=sk-ant-api-456`
@@ -85,6 +103,7 @@ Feature: Manage AI provider credentials
85103
| openai | sk-*****i123 |
86104
| anthropic | sk-*******-456 |
87105

106+
@require-wp-7.0
88107
Scenario: Update existing credentials
89108
When I run `wp ai credentials set openai --api-key=old-key-123`
90109
Then STDOUT should contain:

features/generate.feature

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,23 @@ Feature: Generate AI content
150150
);
151151
"""
152152

153+
@less-than-wp-7.0
154+
Scenario: Command not available on WP < 7.0
155+
Given a WP install
156+
157+
When I try `wp ai generate text "Test prompt" --model=invalidformat`
158+
Then STDERR should contain:
159+
"""
160+
Requires WordPress 7.0 or greater.
161+
"""
162+
And the return code should be 1
163+
164+
@require-wp-7.0
153165
Scenario: Generate command validates model format
154166
When I try `wp ai generate text "Test prompt" --model=invalidformat`
155167
Then the return code should be 1
156168

169+
@require-wp-7.0
157170
Scenario: Generate command validates max-tokens
158171
When I try `wp ai generate text "Test prompt" --max-tokens=-5`
159172
Then the return code should be 1
@@ -162,6 +175,7 @@ Feature: Generate AI content
162175
Max tokens must be a positive integer
163176
"""
164177

178+
@require-wp-7.0
165179
Scenario: Generate command validates top-p range
166180
When I try `wp ai generate text "Test prompt" --top-p=1.5`
167181
Then the return code should be 1
@@ -170,6 +184,7 @@ Feature: Generate AI content
170184
Top-p must be between 0.0 and 1.0
171185
"""
172186

187+
@require-wp-7.0
173188
Scenario: Generate command validates top-k positive
174189
When I try `wp ai generate text "Test prompt" --top-k=-10`
175190
Then the return code should be 1

src/Credentials_Command.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ private function get_all_credentials() {
220220
return array();
221221
}
222222

223+
/**
224+
* @var array<string, string> $credentials
225+
*/
226+
223227
return $credentials;
224228
}
225229

0 commit comments

Comments
 (0)