Skip to content

Commit 1c23bb7

Browse files
committed
Document the corpus diff procedure
Records what the corpus-diff check is, how to run it by hand with the repo's own tools/export-corpus.php and prep-diff.php, and the policy the workflow already states: the head checkout's tooling drives both sides.
1 parent 66ca1eb commit 1c23bb7

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,37 @@ In your site's directory:
5050
```bash
5151
wp parser create /path/to/source/code --user=<id|login>
5252
```
53+
54+
## Corpus diff
55+
56+
Unit tests do not cover every shape of real-world documentation, so changes to the parser are also checked against a corpus of WordPress core source. The same corpus is parsed with the parser at two refs — the merge base of a pull request and its head — both JSON outputs are normalized with `prep-diff.php`, and the two are diffed. Everything in that diff is a behavior change the pull request makes: every hunk must be either intended and explained, or it is a regression.
57+
58+
`.github/workflows/corpus-diff.yml` runs this on every pull request. The corpus is `wp-includes` from a pinned WordPress tag (`WP_CORPUS_TAG` in the workflow), so diffs are reproducible. The job is non-blocking: it uploads the diff as a `corpus.diff` artifact and reports the hunk count in the job summary. The head checkout's `tools/export-corpus.php` and `prep-diff.php` drive both sides, so tooling changes never masquerade as parser changes; when `prep-diff.php` itself changes, its effect on normalization shows up in the diff and is reviewed like any other change.
59+
60+
To run it locally, get the pinned corpus:
61+
62+
```bash
63+
curl -sSfL -o wordpress.zip https://github.com/WordPress/WordPress/archive/refs/tags/7.0.4.zip
64+
unzip -q wordpress.zip 'WordPress-7.0.4/wp-includes/*'
65+
```
66+
67+
Check out the other side of the comparison and install its dependencies. The exporter runs under plain PHP — it does not load WordPress — but it needs a Composer autoloader in each parser root:
68+
69+
```bash
70+
git worktree add base "$(git merge-base origin/master HEAD)"
71+
composer --working-dir=base install
72+
composer install
73+
```
74+
75+
Export both sides over the same corpus, normalize, and diff. `export-corpus.php` takes the parser root and the corpus directory, and writes JSON to stdout:
76+
77+
```bash
78+
export LC_ALL=C
79+
php -d memory_limit=4G tools/export-corpus.php base WordPress-7.0.4/wp-includes > base.json
80+
php -d memory_limit=4G tools/export-corpus.php . WordPress-7.0.4/wp-includes > head.json
81+
php -d memory_limit=4G prep-diff.php < base.json > base.norm.json
82+
php -d memory_limit=4G prep-diff.php < head.json > head.norm.json
83+
diff -u base.norm.json head.norm.json > corpus.diff
84+
```
85+
86+
An empty `corpus.diff` means the change has no effect on parser output.

0 commit comments

Comments
 (0)