Skip to content

Commit 7896e5a

Browse files
committed
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RcafAC2UeQTVKoy8wVxJzB
1 parent b02c72d commit 7896e5a

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ chmod +x ~/wp-cli/wp
147147
WP_CLI_BIN_DIR=~/wp-cli composer behat
148148
```
149149

150+
#### Project configuration trust
151+
152+
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.
153+
154+
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:
155+
```
156+
When I try `WP_CLI_TRUST_PROJECT_CONFIG=false wp cli version`
157+
```
158+
150159
### Setting up the tests in Travis CI
151160

152161
Basic rules for setting up the test framework with Travis CI:

‎src/Context/FeatureContext.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,14 @@ private static function get_process_env_variables(): array {
489489
$env['WP_CLI_REQUIRE'] = $updated;
490490
}
491491

492+
// Test fixtures routinely create project-level `wp-cli.yml` files that contain
493+
// `require`, `exec`, `env` or `ssh-args` directives. WP-CLI gates those behind a
494+
// trust confirmation, which cannot be answered in a non-interactive test run, so
495+
// trust them by default. Scenarios that specifically test the trust mechanism can
496+
// still override this by prefixing their command with their own value.
497+
$trust_project_config = getenv( 'WP_CLI_TRUST_PROJECT_CONFIG' );
498+
$env['WP_CLI_TRUST_PROJECT_CONFIG'] = false !== $trust_project_config ? $trust_project_config : '1';
499+
492500
$config_path = getenv( 'WP_CLI_CONFIG_PATH' );
493501
if ( false !== $config_path ) {
494502
$env['WP_CLI_CONFIG_PATH'] = $config_path;

0 commit comments

Comments
 (0)