From 7896e5a18e8c7e8eced57287dedfdddd3618ddf9 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 4 Aug 2026 22:23:57 +0000 Subject: [PATCH 1/5] Trust project configuration files in Behat runs WP-CLI gates `require`, `exec`, `env` and `ssh-args` directives found in a project-level wp-cli.yml behind a trust confirmation. Test fixtures create such files routinely and a non-interactive test run cannot answer the prompt, so pass WP_CLI_TRUST_PROJECT_CONFIG=1 to every command the Behat context runs. An explicit WP_CLI_TRUST_PROJECT_CONFIG in the outer environment still wins, and scenarios exercising the trust mechanism itself can keep overriding it per command. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01RcafAC2UeQTVKoy8wVxJzB --- README.md | 9 +++++++++ src/Context/FeatureContext.php | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/README.md b/README.md index ceb0c9804..485e0b0d0 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,15 @@ chmod +x ~/wp-cli/wp WP_CLI_BIN_DIR=~/wp-cli composer behat ``` +#### Project configuration trust + +WP-CLI asks for confirmation before acting on `require`, `exec`, `env` or `ssh-args` directives found in a project-level `wp-cli.yml` file. Test fixtures create such files all the time and a test run cannot answer an interactive prompt, so the Behat context passes `WP_CLI_TRUST_PROJECT_CONFIG=1` to every command it runs. + +Set the `WP_CLI_TRUST_PROJECT_CONFIG` environment variable yourself to override that default for the whole run. Individual scenarios can override it per command: +``` +When I try `WP_CLI_TRUST_PROJECT_CONFIG=false wp cli version` +``` + ### Setting up the tests in Travis CI Basic rules for setting up the test framework with Travis CI: diff --git a/src/Context/FeatureContext.php b/src/Context/FeatureContext.php index 867f535ce..c4055ad7c 100644 --- a/src/Context/FeatureContext.php +++ b/src/Context/FeatureContext.php @@ -489,6 +489,14 @@ private static function get_process_env_variables(): array { $env['WP_CLI_REQUIRE'] = $updated; } + // Test fixtures routinely create project-level `wp-cli.yml` files that contain + // `require`, `exec`, `env` or `ssh-args` directives. WP-CLI gates those behind a + // trust confirmation, which cannot be answered in a non-interactive test run, so + // trust them by default. Scenarios that specifically test the trust mechanism can + // still override this by prefixing their command with their own value. + $trust_project_config = getenv( 'WP_CLI_TRUST_PROJECT_CONFIG' ); + $env['WP_CLI_TRUST_PROJECT_CONFIG'] = false !== $trust_project_config ? $trust_project_config : '1'; + $config_path = getenv( 'WP_CLI_CONFIG_PATH' ); if ( false !== $config_path ) { $env['WP_CLI_CONFIG_PATH'] = $config_path; From 789af954aa8d63d9d9bc919a805c0bb07f0367b3 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 3 Sep 2026 17:15:07 +0200 Subject: [PATCH 2/5] Apply suggestion from @swissspidy --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 485e0b0d0..8ef22efe1 100644 --- a/README.md +++ b/README.md @@ -152,9 +152,9 @@ WP_CLI_BIN_DIR=~/wp-cli composer behat WP-CLI asks for confirmation before acting on `require`, `exec`, `env` or `ssh-args` directives found in a project-level `wp-cli.yml` file. Test fixtures create such files all the time and a test run cannot answer an interactive prompt, so the Behat context passes `WP_CLI_TRUST_PROJECT_CONFIG=1` to every command it runs. Set the `WP_CLI_TRUST_PROJECT_CONFIG` environment variable yourself to override that default for the whole run. Individual scenarios can override it per command: -``` + +```gherkin When I try `WP_CLI_TRUST_PROJECT_CONFIG=false wp cli version` -``` ### Setting up the tests in Travis CI From 633d433354d7f8b966f8670fa670010461ea0a3b Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 24 Nov 2026 10:15:24 +0000 Subject: [PATCH 3/5] Close the code fence in the project configuration trust docs Also describe which directives are gated in line with the framework change. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UWTd5pwpi2xQfDA6mUYkkx --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 882e5f657..c46e2fabb 100644 --- a/README.md +++ b/README.md @@ -439,12 +439,13 @@ WP_CLI_BIN_DIR=~/wp-cli composer behat #### Project configuration trust -WP-CLI asks for confirmation before acting on `require`, `exec`, `env` or `ssh-args` directives found in a project-level `wp-cli.yml` file. Test fixtures create such files all the time and a test run cannot answer an interactive prompt, so the Behat context passes `WP_CLI_TRUST_PROJECT_CONFIG=1` to every command it runs. +WP-CLI asks for confirmation before acting on directives that can run code or redirect a command, such as `require`, `exec`, `env`, `ssh-args` or SSH aliases, when they come from a project-level `wp-cli.yml` file. Test fixtures create such files all the time and a test run cannot answer an interactive prompt, so the Behat context passes `WP_CLI_TRUST_PROJECT_CONFIG=1` to every command it runs. Set the `WP_CLI_TRUST_PROJECT_CONFIG` environment variable yourself to override that default for the whole run. Individual scenarios can override it per command: ```gherkin When I try `WP_CLI_TRUST_PROJECT_CONFIG=false wp cli version` +``` ### Setting up the tests in Travis CI From 5b9767705c8788bfaf4f9f99fe3f7b62f9668d09 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 25 Nov 2026 10:58:55 +0000 Subject: [PATCH 4/5] Add the project configuration trust docs to the README partial README.md is generated from .readme-partials/USING.md, so the section would be lost the next time the README is regenerated. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UWTd5pwpi2xQfDA6mUYkkx --- .readme-partials/USING.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.readme-partials/USING.md b/.readme-partials/USING.md index 40e84b4f8..ff473cb1a 100644 --- a/.readme-partials/USING.md +++ b/.readme-partials/USING.md @@ -460,6 +460,16 @@ chmod +x ~/wp-cli/wp WP_CLI_BIN_DIR=~/wp-cli composer behat ``` +#### Project configuration trust + +WP-CLI asks for confirmation before acting on directives that can run code or redirect a command, such as `require`, `exec`, `env`, `ssh-args` or SSH aliases, when they come from a project-level `wp-cli.yml` file. Test fixtures create such files all the time and a test run cannot answer an interactive prompt, so the Behat context passes `WP_CLI_TRUST_PROJECT_CONFIG=1` to every command it runs. + +Set the `WP_CLI_TRUST_PROJECT_CONFIG` environment variable yourself to override that default for the whole run. Individual scenarios can override it per command: + +```gherkin +When I try `WP_CLI_TRUST_PROJECT_CONFIG=false wp cli version` +``` + #### Xdebug Step Debugging Set `WP_CLI_TEST_XDEBUG` to step debug the WP-CLI and WordPress code that the scenarios run, with Xdebug 3: From 4486a8cb871b9a1e23a8c571e4a45b71d51eec2f Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 25 Nov 2026 10:58:55 +0000 Subject: [PATCH 5/5] Pass WP_CLI_TRUST_PROJECT_CONFIG through to Docker test containers With WP_CLI_TEST_DOCKER, the scenarios run in containers that only get an allowlisted set of environment variables, so an outer WP_CLI_TRUST_PROJECT_CONFIG override as documented in the README never reached the Behat context. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UWTd5pwpi2xQfDA6mUYkkx --- utils/behat-parallel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/behat-parallel.php b/utils/behat-parallel.php index e1e0d5fd6..ba33b5298 100644 --- a/utils/behat-parallel.php +++ b/utils/behat-parallel.php @@ -633,7 +633,7 @@ function wp_cli_tests_docker_worker_command( $name, $php_image, $db_image, array } foreach ( getenv() as $key => $value ) { - if ( preg_match( '/^(WP_VERSION|NO_COLOR|CI|GITHUB_TOKEN|WP_CLI_TEST_(DBTYPE|OBJECT_CACHE|CORE_ZIP|QUIET|LOG_RUN_TIMES|PHP_TUNING|WP_VERSION_CACHE_TTL))$/', $key ) ) { + if ( preg_match( '/^(WP_VERSION|NO_COLOR|CI|GITHUB_TOKEN|WP_CLI_TEST_(DBTYPE|OBJECT_CACHE|CORE_ZIP|QUIET|LOG_RUN_TIMES|PHP_TUNING|WP_VERSION_CACHE_TTL)|WP_CLI_TRUST_PROJECT_CONFIG)$/', $key ) ) { $env[ $key ] = $value; } }