Trust project configuration files in Behat runs - #348
Conversation
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
📝 WalkthroughWalkthroughChangesProject configuration trust
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 PHPStan (2.2.7)PHPStan was skipped because the config uses disallowed Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR updates the WP-CLI Behat test harness to default to trusting project-level wp-cli.yml configuration during non-interactive runs, preventing widespread failures introduced by the new trust confirmation gate in wp-cli/wp-cli#6365.
Changes:
- Default
WP_CLI_TRUST_PROJECT_CONFIGto1for all Behat-invoked WP-CLI commands, while still honoring an explicitly-set outer environment value. - Document the default trust behavior and how to override it globally or per-command in the README.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Context/FeatureContext.php | Adds a default WP_CLI_TRUST_PROJECT_CONFIG=1 process environment value for commands executed by the Behat context (with passthrough override support). |
| README.md | Documents the default trust behavior in Behat runs and shows how to override it for the full run or per command. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@README.md`:
- Around line 150-157: Update the “Project configuration trust” heading in
README.md to use the repository’s configured setext heading style, and add a
gherkin language identifier to the command example’s fenced code block.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 47ae8d2e-65d6-4ffa-a607-d2c37a5e68b8
📒 Files selected for processing (2)
README.mdsrc/Context/FeatureContext.php
| #### 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` | ||
| ``` |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Fix the Markdown lint issues in the new section.
Line 150 must use the configured setext heading style. Line 155 must specify a fence language, such as gherkin.
Proposed fix
-#### Project configuration trust
+Project configuration trust
+---------------------------
...
-```
+```gherkin📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| #### 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` | |
| ``` | |
| 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: |
🧰 Tools
🪛 markdownlint-cli2 (0.23.2)
[warning] 150-150: Heading style
Expected: setext; Actual: atx
(MD003, heading-style)
[warning] 155-155: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@README.md` around lines 150 - 157, Update the “Project configuration trust”
heading in README.md to use the repository’s configured setext heading style,
and add a gherkin language identifier to the command example’s fenced code
block.
Source: Linters/SAST tools
Companion to wp-cli/wp-cli#6365.
That PR gates
require,exec,envandssh-argsdirectives found in a project-levelwp-cli.ymlbehind a trust confirmation, controlled by--trust-project-config/WP_CLI_TRUST_PROJECT_CONFIG.Test fixtures create such files all the time —
Given a wp-cli.yml file:with arequire:entry is one of the most common steps across the WP-CLI package suites, andgiven_a_request_to_a_url_respond_with_file()writes one itself. A Behat run is non-interactive, so without this change every one of those scenarios fails with:Changes
FeatureContext::get_process_env_variables()now passesWP_CLI_TRUST_PROJECT_CONFIG=1to every command it runs. An explicit value in the outer environment still wins, following the same pass-through pattern already used forWP_CLI_CONFIG_PATH,WP_CLI_ALLOW_ROOTand friends.When I try \WP_CLI_TRUST_PROJECT_CONFIG=false wp cli version``), which is how the trust mechanism's own acceptance tests in Add project configuration trust verification (trust-project-config) wp-cli#6365 exercise the denial paths.Testing
Ran the affected wp-cli/wp-cli feature scenarios against a checkout of wp-cli/wp-cli#6365 with this context patched in: the 28 scenarios that build a project
wp-cli.ymlcontainingrequire/exec/env/ssh-argsand do not need a WordPress install (acrosscommand,config,flags,prompt,runcommandandrunnerfeatures) fail without this change and pass with it. The nine new trust scenarios infeatures/config.featurestill pass, confirming that the per-command override keeps working.Note this needs to be released before wp-cli/wp-cli#6365's CI can go green, since that repo installs
wp-cli/wp-cli-testsfrom a version constraint.Generated by Claude Code
Summary by CodeRabbit
New Features
Documentation