Skip to content

Commit 11085bf

Browse files
authored
Merge branch 'main' into patch-1
2 parents 9d07ac1 + 4f28bcf commit 11085bf

14 files changed

Lines changed: 278 additions & 138 deletions

‎.github/actionlint.yml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Configuration for actionlint, run by the `actionlint` job in
2+
# `.github/workflows/reusable-code-quality.yml`.
3+
paths:
4+
.github/workflows/**/*.{yml,yaml}:
5+
ignore:
6+
# `copilot-requests` is a real permission scope - it is what lets a
7+
# workflow authenticate the Copilot CLI with the built-in `GITHUB_TOKEN`
8+
# instead of a personal access token - but actionlint's hard-coded scope
9+
# list has not caught up with it yet, so it reports every use as unknown.
10+
# Drop this entry once actionlint ships the scope, and it will go back to
11+
# catching genuine typos in permission names.
12+
# See https://docs.github.com/en/copilot/how-tos/copilot-cli/use-copilot-cli-in-actions
13+
- 'unknown permission scope "copilot-requests"'
14+
# Steps can run in parallel through the `background`, `wait`, `wait-all`,
15+
# `cancel` and `parallel` keywords, but actionlint does not know them yet:
16+
# it rejects `background` as an unexpected key, and a `wait-all` or
17+
# `parallel` step as one that has neither `run` nor `uses`. Drop these
18+
# entries once actionlint supports the keywords. Until then, a step that is
19+
# genuinely missing both `run` and `uses` is no longer reported.
20+
# See https://docs.github.com/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsparallel
21+
- 'unexpected key "background" for step'
22+
- 'step must run script with "run" section or run action with "uses" section'

‎.github/dependabot.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
version: 2
22
updates:
33
- package-ecosystem: composer
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
open-pull-requests-limit: 10
8+
labels:
9+
- scope:distribution
10+
cooldown:
11+
default-days: 7
12+
# Packages from our own org are trusted, so they are updated immediately.
13+
exclude:
14+
- "wp-cli/*"
15+
# Only wp-cli-tests carries a package.json, holding the pinned version of the
16+
# Gherkin linter. This is a no-op in every other repository.
17+
- package-ecosystem: npm
418
directory: "/"
519
schedule:
620
interval: daily

‎.github/workflows/copilot-setup-steps.yml‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ jobs:
1919
permissions:
2020
contents: read
2121

22+
env:
23+
MYSQL_HOST: 127.0.0.1
24+
MYSQL_TCP_PORT: 3306
25+
WP_CLI_TEST_DBROOTUSER: root
26+
WP_CLI_TEST_DBROOTPASS: root
27+
WP_CLI_TEST_DBNAME: wp_cli_test
28+
WP_CLI_TEST_DBUSER: wp_cli_test
29+
WP_CLI_TEST_DBPASS: password1
30+
WP_CLI_TEST_DBHOST: 127.0.0.1:3306
31+
2232
steps:
2333
- name: Checkout code
2434
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -29,6 +39,27 @@ jobs:
2939
id: check_composer_file
3040
run: echo "files_exists=$(test -f composer.json && echo true || echo false)" >> "$GITHUB_OUTPUT"
3141

42+
# Without a database the Behat runner silently falls back to SQLite, so the
43+
# agent's test runs are not the ones CI will do. Mirrors the setup in
44+
# reusable-functional.yml.
45+
- name: Check existence of behat.yml file
46+
id: check_behat_file
47+
run: echo "files_exists=$(test -f behat.yml && echo true || echo false)" >> "$GITHUB_OUTPUT"
48+
49+
# Downloading and starting the database server is the slowest part of the
50+
# setup and it is independent of PHP and Composer, so it runs in the
51+
# background and is waited for right before the test database is prepared.
52+
- name: Setup MySQL Server
53+
if: steps.check_behat_file.outputs.files_exists == 'true'
54+
background: true
55+
uses: shogo82148/actions-setup-mysql@1d4ebc60ba1227dd13fc7e6ba845bd3997928d75 # v1
56+
with:
57+
mysql-version: '8.0' # Standard MySQL version for these tests
58+
auto-start: true
59+
root-password: ${{ env.WP_CLI_TEST_DBROOTPASS }}
60+
user: ${{ env.WP_CLI_TEST_DBUSER }}
61+
password: ${{ env.WP_CLI_TEST_DBPASS }}
62+
3263
- name: Set up PHP environment
3364
if: steps.check_composer_file.outputs.files_exists == 'true'
3465
uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2
@@ -45,3 +76,14 @@ jobs:
4576
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
4677
env:
4778
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
79+
80+
- name: Wait for the MySQL server
81+
wait-all:
82+
83+
- name: Remove system MySQL binary
84+
if: steps.check_behat_file.outputs.files_exists == 'true'
85+
run: sudo rm -f /usr/bin/mysql /usr/bin/mysqldump
86+
87+
- name: Prepare test database
88+
if: steps.check_behat_file.outputs.files_exists == 'true'
89+
run: composer prepare-tests

‎.github/workflows/issue-triage.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ permissions:
1717
issues: write
1818
pull-requests: write
1919
contents: read
20-
models: read
20+
# A caller can only cap a reusable workflow's permissions, so the scope the
21+
# Copilot CLI needs has to be granted here too. `models: read` was for the
22+
# GitHub Models provider, which `actions/ai-inference` v3 removed.
23+
copilot-requests: write
2124
# A caller can only cap a reusable workflow's permissions, never raise them,
2225
# so `actions: write` has to be granted here for the dispatch job downstream
2326
# to work at all. The reusable workflow narrows it to that single job, so the

‎AGENTS.md‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,27 @@ When contributing to this package, please adhere to the following guidelines:
1313

1414
### Building and running
1515

16-
Before submitting any changes, it is crucial to validate them by running the full suite of static code analysis and tests. To run the full suite of checks, execute the following command: `composer test`.
16+
Run the narrowest check that covers your change:
1717

18-
This single command ensures that your changes meet all the quality gates of the project. While you can run the individual steps separately, it is highly recommended to use this single command to ensure a comprehensive validation.
18+
| You changed | Run |
19+
| --- | --- |
20+
| Any PHP file | `composer phpcs -- <file>` and `composer phpstan` |
21+
| Logic with unit test coverage | `composer phpunit -- --filter <TestName>` |
22+
| One feature file | `composer behat -- features/<name>.feature` |
23+
| One scenario | `composer behat -- features/<name>.feature:<line>` |
24+
25+
After a failure, `composer behat-rerun` re-runs only the scenarios that failed, and `composer behat -- --stop-on-failure` bails out at the first one instead of working through the rest.
26+
27+
`composer test` runs every suite, the whole Behat suite included. In most packages that means installing WordPress from scratch once per scenario, which takes tens of minutes and needs `jq`, a MySQL or MariaDB client with a prepared test database, and network access to WordPress.org. Run it before opening a pull request when you have touched something cross-cutting. Do not run it to check a two-line change.
28+
29+
Set these first, so the tools report problems compactly instead of drawing progress bars and ANSI color into output you are going to read back:
30+
31+
```bash
32+
export NO_COLOR=1
33+
export WP_CLI_TEST_QUIET=1
34+
```
35+
36+
Note that a green `composer test` is not the same as a green CI. `actionlint` and `typos` also run on every pull request and are not part of it.
1937

2038
### Useful Composer Commands
2139

@@ -24,6 +42,7 @@ The project uses Composer to manage dependencies and run scripts. The following
2442
* `composer install`: Install dependencies.
2543
* `composer test`: Run the full test suite, including linting, code style checks, static analysis, and unit/behavior tests.
2644
* `composer lint`: Check for syntax errors.
45+
* `composer lint-gherkin`: Check the Behat feature files for style violations.
2746
* `composer phpcs`: Check for code style violations.
2847
* `composer phpcbf`: Automatically fix code style violations.
2948
* `composer phpstan`: Run static analysis.

‎composer.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@
6767
"behat": "run-behat-tests",
6868
"behat-rerun": "rerun-behat-tests",
6969
"lint": "run-linter-tests",
70+
"lint-gherkin": "run-gherkin-lint-tests",
7071
"phpcs": "run-phpcs-tests",
7172
"phpstan": "run-phpstan-tests",
7273
"phpcbf": "run-phpcbf-cleanup",
7374
"phpunit": "run-php-unit-tests",
7475
"prepare-tests": "install-package-tests",
7576
"test": [
7677
"@lint",
78+
"@lint-gherkin",
7779
"@phpcs",
7880
"@phpunit",
7981
"@behat"

‎features/db-columns.feature‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ Feature: Display information about a given table.
4141
Couldn't find any tables matching: wp_foobar
4242
"""
4343

44-
@require-mysql-or-mariadb
4544
Scenario: Display information about a non default WordPress table
4645
Given a WP install
4746
And I run `wp db query "CREATE TABLE not_wp ( date DATE NOT NULL, awesome_stuff TEXT, PRIMARY KEY (date) );;"`
@@ -51,14 +50,3 @@ Feature: Display information about a given table.
5150
| Field | Type | Null | Key | Default | Extra |
5251
| date | date | NO | PRI | | |
5352
| awesome_stuff | text | YES | | | |
54-
55-
@require-sqlite
56-
Scenario: Display information about a non default WordPress table
57-
Given a WP install
58-
And I run `wp db query "CREATE TABLE not_wp ( date DATE NOT NULL, awesome_stuff TEXT, PRIMARY KEY (date) );;"`
59-
60-
When I try `wp db columns not_wp`
61-
Then STDOUT should be a table containing rows:
62-
| Field | Type | Null | Key | Default |
63-
| date | TEXT | NO | PRI | '' |
64-
| awesome_stuff | TEXT | YES | | |

‎features/db-import.feature‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,16 @@ Feature: Import a WordPress database
256256
CREATE TABLE wp_cli_sqlite_meta (id int NOT NULL);
257257
.shell touch side_effect_sqlite.txt
258258
"""
259+
And a malicious_sqlite_space.sql file:
260+
"""
261+
CREATE TABLE wp_cli_sqlite_meta (id int NOT NULL);
262+
. shell touch side_effect_sqlite_space.txt
263+
"""
264+
And a malicious_sqlite_quotes.sql file:
265+
"""
266+
CREATE TABLE wp_cli_sqlite_meta (id int NOT NULL);
267+
."shell" touch side_effect_sqlite_quotes.txt
268+
"""
259269

260270
When I try `wp db import malicious_sqlite.sql`
261271
Then STDERR should contain:
@@ -264,6 +274,43 @@ Feature: Import a WordPress database
264274
"""
265275
And the side_effect_sqlite.txt file should not exist
266276

277+
When I try `wp db import malicious_sqlite_space.sql`
278+
Then STDERR should contain:
279+
"""
280+
SQLite dot-commands are not allowed in import files.
281+
"""
282+
And the side_effect_sqlite_space.txt file should not exist
283+
284+
When I try `wp db import malicious_sqlite_quotes.sql`
285+
Then STDERR should contain:
286+
"""
287+
SQLite dot-commands are not allowed in import files.
288+
"""
289+
And the side_effect_sqlite_quotes.txt file should not exist
290+
291+
@require-sqlite
292+
Scenario: `wp db import` allows multiline SQL containing numeric literals starting with a dot
293+
Given a WP install
294+
And a numeric_literal.sql file:
295+
"""
296+
CREATE TABLE wp_cli_prices (value REAL);
297+
INSERT INTO wp_cli_prices (value) VALUES (
298+
.5
299+
);
300+
"""
301+
302+
When I run `wp db import numeric_literal.sql`
303+
Then STDOUT should contain:
304+
"""
305+
Success: Imported from 'numeric_literal.sql'.
306+
"""
307+
308+
When I run `wp db query 'SELECT value FROM wp_cli_prices;' --skip-column-names`
309+
Then STDOUT should be:
310+
"""
311+
0.5
312+
"""
313+
267314
# SQLite does not use the MySQL client and has no concept of SQL modes.
268315
@require-mysql-or-mariadb
269316
Scenario: `wp db import` adapts the SQL mode via --init-command by default

‎features/db-query.feature‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Feature: Query the database with WordPress' MySQL config
55
And a wp-content/mu-plugins/error.php file:
66
"""
77
<?php
8-
WP_CLI::error( "Plugin loaded." );
8+
WP_CLI::error( 'Plugin loaded.' );
99
"""
1010

1111
When I try `wp option get home`

‎features/db-sqlite-path.feature‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
@require-sqlite
2+
Feature: Select the configured SQLite database for file operations
3+
4+
Scenario Outline: Use the effective database path without changing another database
5+
Given a WP install
6+
When I run `wp eval 'copy( defined( "DB_PATH" ) ? DB_PATH : FQDB, "selected.sqlite" ); copy( "selected.sqlite", "other.sqlite" );'`
7+
And I run `sqlite3 selected.sqlite "CREATE TABLE path_marker (value TEXT); INSERT INTO path_marker VALUES ('selected');"`
8+
And I run `sqlite3 other.sqlite "CREATE TABLE path_marker (value TEXT); INSERT INTO path_marker VALUES ('other');"`
9+
10+
Given a paths.php file:
11+
"""
12+
<?php
13+
if ( '' !== '<db_path>' ) {
14+
define( 'DB_PATH', __DIR__ . '/<db_path>' );
15+
}
16+
if ( '' !== '<fqdb>' ) {
17+
define( 'FQDB', __DIR__ . '/<fqdb>' );
18+
}
19+
if ( '' !== '<db_dir>' ) {
20+
define( 'DB_DIR', __DIR__ . '/<db_dir>' );
21+
}
22+
if ( '' !== '<db_file>' ) {
23+
define( 'DB_FILE', '<db_file>' );
24+
}
25+
if ( '' !== '<fqdbdir>' ) {
26+
define( 'FQDBDIR', __DIR__ . '/<fqdbdir>' );
27+
}
28+
"""
29+
When I run `wp config set path_constants "require __DIR__ . '/paths.php'" --type=variable --raw`
30+
And I try `wp eval 'echo "ready";'`
31+
Then the return code should be 0
32+
33+
When I run `wp eval 'echo md5_file( "other.sqlite" );' --skip-wordpress`
34+
Then save STDOUT as {OTHER_HASH}
35+
36+
When I try `wp db export selected.sql`
37+
Then the return code should be 0
38+
And the selected.sql file should contain:
39+
"""
40+
INSERT INTO path_marker VALUES('selected');
41+
"""
42+
And the selected.sql file should not contain:
43+
"""
44+
INSERT INTO path_marker VALUES('other');
45+
"""
46+
47+
When I try `wp db drop --yes`
48+
Then the return code should be 0
49+
And the selected.sqlite file should not exist
50+
51+
When I run `wp eval 'echo md5_file( "other.sqlite" );' --skip-wordpress`
52+
Then STDOUT should be:
53+
"""
54+
{OTHER_HASH}
55+
"""
56+
57+
Examples:
58+
| db_path | fqdb | db_dir | db_file | fqdbdir |
59+
| selected.sqlite | other.sqlite | other | other.sqlite | other/ |
60+
| selected.sqlite | selected.sqlite | / | selected.sqlite | / |
61+
| | selected.sqlite | | | |
62+
| | | | selected.sqlite | / |
63+
64+
Scenario Outline: Reject file operations on an in-memory SQLite database
65+
Given a WP install
66+
And an input.sql file:
67+
"""
68+
SELECT 1;
69+
"""
70+
When I run `wp config set <constant> :memory:`
71+
And I run `wp db query "SELECT 1 AS value" --skip-column-names`
72+
Then STDOUT should be:
73+
"""
74+
1
75+
"""
76+
77+
When I try `wp db <command>`
78+
Then the return code should be 1
79+
And STDERR should be:
80+
"""
81+
Error: This command does not support in-memory SQLite databases.
82+
"""
83+
And STDOUT should be empty
84+
85+
Examples:
86+
| constant | command |
87+
| DB_PATH | create |
88+
| DB_PATH | drop --yes |
89+
| DB_PATH | reset --yes |
90+
| DB_PATH | export output.sql |
91+
| DB_PATH | import input.sql |
92+
| FQDB | create |
93+
| FQDB | drop --yes |
94+
| FQDB | reset --yes |
95+
| FQDB | export output.sql |
96+
| FQDB | import input.sql |

0 commit comments

Comments
 (0)