Skip to content

test(cli): cover global user context - #329

Closed
chubes4 wants to merge 5 commits into
WordPress:trunkfrom
chubes4:fix/wp-cli-user-option-collision
Closed

chubes4 wants to merge 5 commits into
WordPress:trunkfrom
chubes4:fix/wp-cli-user-option-collision

Conversation

@chubes4

@chubes4 chubes4 commented Sep 14, 2026 •

Copy link
Copy Markdown

Summary

  • add a real WP-CLI regression test for command registration and global user context
  • document that --user remains a WP-CLI global option, not a serve option
  • correct the generated command examples to use mcp-adapter

Fixes #328.

Testing

  • composer run-script lint
  • composer run-script phpstan
  • wp --skip-wordpress --require=/tmp/register-command.php help mcp-adapter serve
  • npm run test:cli is ready for CI; local execution is blocked because Docker is unavailable.

AI Assistance Disclosure

OpenCode using openai/gpt-5.6-terra authored this change under Chris Huber's authorization. The regression fixture uses only synthetic user-context assertions.

Open WordPress Playground Preview

Copilot AI lite review requested due to automatic review settings September 14, 2026 15:58
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: chubes4 <extrachill@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The CLI regression test is not run in CI, and its guard may miss the --user conflict warning.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds WP-CLI regression coverage for global --user handling and updates CLI documentation and examples.

Changes:

  • Adds shell and PHP fixtures for registration and user-context checks.
  • Adds the npm run test:cli command.
  • Corrects generated examples and documents --user as a global option.
File summaries
File Description Review notes
tests/cli/test-serve-user-context.sh Runs registration and user-context checks. Moderate: assert that the global/local --user conflict warning is absent.
tests/cli/assert-serve-user-context.php Validates the active WordPress user. No final comments.
package.json Defines the CLI test command. Moderate: add npm run test:cli to CI after the WP environment starts.
includes/Cli/McpCommand.php Corrects generated command examples. No final comments.
docs/guides/cli-usage.md Documents global --user usage. No final comments.
Review details

Suppressed comments (1)

tests/cli/test-serve-user-context.sh:12

  • This guard does not actually cover the regression described in #328: it only rejects output containing already registered, while WP-CLI's global/local --user collision can be reported as a conflict warning. Because the later assertion only requires The STDIO transport is disabled., a collision warning could be emitted and this test would still pass. Assert the collision-warning text (or otherwise verify it is absent) in the help output so reintroducing the conflicting option fails the test.
case "$help_output" in
	*"already registered"*)
		printf '%s\n' "$help_output" >&2
		exit 1
		;;
esac
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread package.json
"lint:php:fix": "wp-env run cli --env-cwd=wp-content/plugins/$(basename \"$(pwd)\")/ composer run-script format",
"lint:php:stan": "wp-env run cli --env-cwd=wp-content/plugins/$(basename \"$(pwd)\")/ composer run-script phpstan",
"plugin-zip": "wp-scripts plugin-zip",
"test:cli": "npm run wp-env:test -- run cli --env-cwd=wp-content/plugins/$(basename \"$(pwd)\")/ sh tests/cli/test-serve-user-context.sh",
@codecov

codecov Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.78%. Comparing base (d6eaa92) to head (1058139).

Additional details and impacted files
@@            Coverage Diff            @@
##              trunk     #329   +/-   ##
=========================================
  Coverage     88.78%   88.78%           
  Complexity     1264     1264           
=========================================
  Files            54       54           
  Lines          4164     4164           
=========================================
  Hits           3697     3697           
  Misses          467      467           
Flag Coverage Δ
unit 88.78% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chubes4 chubes4 closed this Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: avoid redeclaring WP-CLI global --user in mcp serve

2 participants