From 2ad9820c51edb651aa3f52670f2e2f8ff107c877 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 17 Aug 2026 10:12:07 +0000 Subject: [PATCH 1/2] Expose connector ID in `wp connectors list` and `wp connectors get` Neither command surfaced the connector identifier, so there was no way to discover the value that `wp connectors get ` expects as its positional argument. Add an `id` field to the connector item and include it as the first default field for both subcommands. Fixes #24 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01FG8X9hSsPjFYsHD3KyDwkJ --- README.md | 15 +++++------ features/connectors.feature | 50 +++++++++++++++++++++++++++++++++++-- src/Connectors_Command.php | 21 +++++++++------- 3 files changed, 68 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 79e2043..2df28c8 100644 --- a/README.md +++ b/README.md @@ -276,6 +276,7 @@ wp connectors get [--fields=] [--format=] +-----------------+-----------------------------------------------+ | Field | Value | +-----------------+-----------------------------------------------+ + | id | openai | | name | OpenAI | | description | Text and image generation with GPT and Dall-E | | status | connected | @@ -323,13 +324,13 @@ wp connectors list [--status=] [--fields=] [--format=] # List all connectors $ wp connectors list - +-----------+-----------------------------------------------+---------------+ - | name | description | status | - +-----------+-----------------------------------------------+---------------+ - | Anthropic | Text generation with Claude. | not installed | - | Google | Text and image generation with Gemini... | not installed | - | OpenAI | Text and image generation with GPT and Dall-E | connected | - +-----------+-----------------------------------------------+---------------+ + +-----------+-----------+-----------------------------------------------+---------------+ + | id | name | description | status | + +-----------+-----------+-----------------------------------------------+---------------+ + | anthropic | Anthropic | Text generation with Claude. | not installed | + | google | Google | Text and image generation with Gemini... | not installed | + | openai | OpenAI | Text and image generation with GPT and Dall-E | connected | + +-----------+-----------+-----------------------------------------------+---------------+ # List only connected connectors $ wp connectors list --status=connected diff --git a/features/connectors.feature b/features/connectors.feature index b18e489..667952f 100644 --- a/features/connectors.feature +++ b/features/connectors.feature @@ -16,6 +16,10 @@ Feature: List and get AI connectors Scenario: List connectors returns built-in providers with descriptions When I run `wp connectors list --format=json` Then STDOUT should contain: + """ + "id":"openai" + """ + And STDOUT should contain: """ "name":"OpenAI" """ @@ -49,9 +53,13 @@ Feature: List and get AI connectors """ @require-wp-7.0 - Scenario: List connectors in table format shows name, description and status columns + Scenario: List connectors in table format shows id, name, description and status columns When I run `wp connectors list` Then STDOUT should contain: + """ + | id + """ + And STDOUT should contain: """ name """ @@ -63,14 +71,26 @@ Feature: List and get AI connectors """ status """ + And STDOUT should contain: + """ + | openai + """ And STDOUT should contain: """ OpenAI """ + And STDOUT should contain: + """ + | anthropic + """ And STDOUT should contain: """ Anthropic """ + And STDOUT should contain: + """ + | google + """ And STDOUT should contain: """ Google @@ -92,6 +112,10 @@ Feature: List and get AI connectors Scenario: Get a specific connector shows key-value layout When I run `wp connectors get openai` Then STDOUT should contain: + """ + | id + """ + And STDOUT should contain: """ name """ @@ -109,7 +133,7 @@ Feature: List and get AI connectors When I run `wp connectors get openai --format=json` Then STDOUT should be JSON containing: """ - {"name":"OpenAI","description":"Text and image generation with GPT and Dall-E.","status":"not installed","credentials_url":"https://platform.openai.com/api-keys","api_key":""} + {"id":"openai","name":"OpenAI","description":"Text and image generation with GPT and Dall-E.","status":"not installed","credentials_url":"https://platform.openai.com/api-keys","api_key":""} """ # TODO: Depends on https://core.trac.wordpress.org/ticket/64819. @@ -143,6 +167,28 @@ Feature: List and get AI connectors {"name":"OpenAI","auth_method":"api_key","type":"ai_provider","plugin_file":"ai-provider-for-openai/plugin.php"} """ + @require-wp-7.0 + Scenario: Connector ID from list can be passed to get + When I run `wp connectors list --fields=id --format=json` + Then STDOUT should contain: + """ + {"id":"openai"} + """ + And STDOUT should contain: + """ + {"id":"anthropic"} + """ + And STDOUT should contain: + """ + {"id":"google"} + """ + + When I run `wp connectors get openai --fields=id --format=json` + Then STDOUT should be JSON containing: + """ + {"id":"openai"} + """ + @require-wp-7.0 Scenario: Error on non-existent connector When I try `wp connectors get nonexistent` diff --git a/src/Connectors_Command.php b/src/Connectors_Command.php index 2a3e33c..4889626 100644 --- a/src/Connectors_Command.php +++ b/src/Connectors_Command.php @@ -23,6 +23,7 @@ class Connectors_Command extends WP_CLI_Command { * @var string[] */ protected $default_fields = [ + 'id', 'name', 'description', 'status', @@ -61,13 +62,13 @@ class Connectors_Command extends WP_CLI_Command { * * # List all connectors * $ wp connectors list - * +-----------+-----------------------------------------------+---------------+ - * | name | description | status | - * +-----------+-----------------------------------------------+---------------+ - * | Anthropic | Text generation with Claude. | not installed | - * | Google | Text and image generation with Gemini... | not installed | - * | OpenAI | Text and image generation with GPT and Dall-E | connected | - * +-----------+-----------------------------------------------+---------------+ + * +-----------+-----------+-----------------------------------------------+---------------+ + * | id | name | description | status | + * +-----------+-----------+-----------------------------------------------+---------------+ + * | anthropic | Anthropic | Text generation with Claude. | not installed | + * | google | Google | Text and image generation with Gemini... | not installed | + * | openai | OpenAI | Text and image generation with GPT and Dall-E | connected | + * +-----------+-----------+-----------------------------------------------+---------------+ * * # List only connected connectors * $ wp connectors list --status=connected @@ -141,6 +142,7 @@ static function ( array $item ) use ( $status_filter ) { * +-----------------+-----------------------------------------------+ * | Field | Value | * +-----------------+-----------------------------------------------+ + * | id | openai | * | name | OpenAI | * | description | Text and image generation with GPT and Dall-E | * | status | connected | @@ -180,7 +182,7 @@ public function get( $args, $assoc_args ) { $item['api_key'] = $api_key; - $default_fields = array( 'name', 'description', 'status', 'credentials_url', 'api_key' ); + $default_fields = array( 'id', 'name', 'description', 'status', 'credentials_url', 'api_key' ); $formatter = new \WP_CLI\Formatter( $assoc_args, $default_fields ); $formatter->display_item( $item ); } @@ -190,7 +192,7 @@ public function get( $args, $assoc_args ) { * * @param string $connector_id The connector ID. * @param mixed[] $connector Connector settings from wp_get_connectors(). - * @return array{name: string, description: string, status: string, type: string, auth_method: string, credentials_url: string, plugin_file: string} + * @return array{id: string, name: string, description: string, status: string, type: string, auth_method: string, credentials_url: string, plugin_file: string} */ private function build_connector_item( string $connector_id, array $connector ): array { $auth = is_array( $connector['authentication'] ) ? $connector['authentication'] : array(); @@ -198,6 +200,7 @@ private function build_connector_item( string $connector_id, array $connector ): $plugin_file = isset( $plugin['file'] ) && is_string( $plugin['file'] ) ? $plugin['file'] : ''; return array( + 'id' => $connector_id, 'name' => $this->scalar_to_string( $connector['name'] ?? '' ), 'description' => $this->scalar_to_string( $connector['description'] ?? '' ), 'status' => $this->get_connector_status( $connector_id, $connector ), From afa36c72c7bcb6a1245f2359806afb04e2ee490d Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 17 Aug 2026 10:18:57 +0000 Subject: [PATCH 2/2] Fix connector table assertions and capture ID for round-trip test Behat renders WP-CLI's table format as tab-separated values without box borders, so the `| id` assertions could never match. Assert against the actual tab-separated layout instead, which also pins the column order. Also capture a connector ID from `wp connectors list` and pass it to `wp connectors get`, so the scenario exercises the round trip rather than testing both commands against a hard-coded ID. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01FG8X9hSsPjFYsHD3KyDwkJ --- features/connectors.feature | 69 ++++++------------------------------- 1 file changed, 11 insertions(+), 58 deletions(-) diff --git a/features/connectors.feature b/features/connectors.feature index 667952f..e65f985 100644 --- a/features/connectors.feature +++ b/features/connectors.feature @@ -55,46 +55,10 @@ Feature: List and get AI connectors @require-wp-7.0 Scenario: List connectors in table format shows id, name, description and status columns When I run `wp connectors list` - Then STDOUT should contain: - """ - | id - """ - And STDOUT should contain: - """ - name - """ - And STDOUT should contain: - """ - description - """ - And STDOUT should contain: - """ - status - """ - And STDOUT should contain: - """ - | openai - """ - And STDOUT should contain: - """ - OpenAI - """ - And STDOUT should contain: - """ - | anthropic - """ - And STDOUT should contain: - """ - Anthropic - """ - And STDOUT should contain: - """ - | google - """ - And STDOUT should contain: - """ - Google - """ + Then STDOUT should match /^id\tname\tdescription\tstatus$/m + And STDOUT should match /^anthropic\tAnthropic\t/m + And STDOUT should match /^google\tGoogle\t/m + And STDOUT should match /^openai\tOpenAI\t/m @require-wp-7.0 Scenario: List connectors supports --status filter @@ -111,22 +75,10 @@ Feature: List and get AI connectors @require-wp-7.0 Scenario: Get a specific connector shows key-value layout When I run `wp connectors get openai` - Then STDOUT should contain: - """ - | id - """ - And STDOUT should contain: - """ - name - """ - And STDOUT should contain: - """ - OpenAI - """ - And STDOUT should contain: - """ - status - """ + Then STDOUT should match /^Field\tValue$/m + And STDOUT should match /^id\topenai$/m + And STDOUT should match /^name\tOpenAI$/m + And STDOUT should match /^status\t/m @require-wp-7.0 Scenario: Get a specific connector in JSON format @@ -182,11 +134,12 @@ Feature: List and get AI connectors """ {"id":"google"} """ + And save STDOUT '"id":"([a-z0-9_-]+)"' as {CONNECTOR_ID} - When I run `wp connectors get openai --fields=id --format=json` + When I run `wp connectors get {CONNECTOR_ID} --fields=id --format=json` Then STDOUT should be JSON containing: """ - {"id":"openai"} + {"id":"{CONNECTOR_ID}"} """ @require-wp-7.0