Skip to content

Commit 8afb662

Browse files
committed
Diff the corpus exports without prep-diff.php
Both sides share the corpus, the PHP binary, and the exporter, so the export is already deterministic. prep-diff.php reconciles exports from different environments: it zeroes line numbers, strips global-namespace prefixes, and sorts collections. Measured against three open PRs, the raw diff was equal or smaller in every case and kept each change at its source location, while the collection sort relocated changed records and the erasures hid classes of real change. Diff the exports as emitted.
1 parent 2df6c27 commit 8afb662

2 files changed

Lines changed: 16 additions & 18 deletions

File tree

‎.github/workflows/corpus-diff.yml‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
# Parses a pinned corpus of WordPress core source with the parser at the base
2-
# branch and with the PR merged into it, normalizes both JSON outputs with
3-
# prep-diff.php, and diffs them. Anything in the diff is a behavior change this
4-
# PR makes: every hunk must be either intended (and explained in the PR) or a
5-
# regression.
2+
# branch and with the PR merged into it, and diffs the two JSON exports.
3+
# Anything in the diff is a behavior change this PR makes: every hunk must be
4+
# either intended (and explained in the PR) or a regression.
65
#
76
# Policy decisions, deliberate:
87
# - The corpus is pinned to one WordPress tag so diffs are reproducible.
9-
# - The head checkout's tools/export-corpus.php and prep-diff.php drive both
10-
# sides, so tooling changes never masquerade as parser changes. When
11-
# prep-diff.php itself changes, its effect on normalization shows up in the
12-
# diff and is reviewed like any other change.
8+
# - The head checkout's tools/export-corpus.php drives both sides, so tooling
9+
# changes never masquerade as parser changes.
10+
# - The exports are diffed as emitted, without prep-diff.php. Both sides share
11+
# the corpus, the PHP binary, and the exporter, so the export is already
12+
# deterministic; prep-diff.php exists to reconcile exports from different
13+
# environments, and its erasures (line numbers, global-namespace prefixes)
14+
# and collection sorting would hide or scatter real changes here.
1315
# - Non-blocking: the job succeeds even when the diff is non-empty. The diff
1416
# is published as an artifact and summarized. Make it blocking only after
1517
# the signal has proven trustworthy.
@@ -100,12 +102,10 @@ jobs:
100102
ls -l head.json
101103
[ "$(wc -c < head.json)" -ge 1000000 ]
102104
103-
- name: Normalize and diff
105+
- name: Diff
104106
run: |
105-
php -d memory_limit=4G prep-diff.php < base.json > base.norm.json
106-
php -d memory_limit=4G prep-diff.php < head.json > head.norm.json
107107
# diff exits 1 on differences (expected) and 2 on trouble (fail).
108-
diff -u --label base --label head base.norm.json head.norm.json > corpus.diff || [ $? -eq 1 ]
108+
diff -u --label base --label head base.json head.json > corpus.diff || [ $? -eq 1 ]
109109
if [ -s corpus.diff ]; then
110110
hunks=$(grep -c '^@@' corpus.diff)
111111
lines=$(wc -l < corpus.diff)

‎README.md‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ wp parser create /path/to/source/code --user=<id|login>
5353

5454
## Corpus diff
5555

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 base branch and the pull request merged into it — 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.
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 base branch and the pull request merged into it, and the two JSON exports 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.
5757

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.
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` drives both sides, so tooling changes never masquerade as parser changes. The exports are diffed as emitted: both sides share the corpus, the PHP binary, and the exporter, so the output is already deterministic. `prep-diff.php` is for comparing exports from different environments; its line-number and namespace-prefix erasure and its collection sorting would hide or scatter real changes here.
5959

6060
To run it locally, get the pinned corpus:
6161

@@ -74,15 +74,13 @@ composer install
7474

7575
On a branch this compares against the commit the branch left `master` at. CI runs on the pull request merged into `master`, so it compares against the `master` tip; merge `master` into the branch first to get the same comparison.
7676

77-
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:
77+
Export both sides over the same corpus and diff. `export-corpus.php` takes the parser root and the corpus directory, and writes JSON to stdout:
7878

7979
```bash
8080
export LC_ALL=C
8181
php -d memory_limit=4G tools/export-corpus.php base WordPress-7.0.4/wp-includes > base.json
8282
php -d memory_limit=4G tools/export-corpus.php . WordPress-7.0.4/wp-includes > head.json
83-
php -d memory_limit=4G prep-diff.php < base.json > base.norm.json
84-
php -d memory_limit=4G prep-diff.php < head.json > head.norm.json
85-
diff -u base.norm.json head.norm.json > corpus.diff
83+
diff -u base.json head.json > corpus.diff
8684
```
8785

8886
An empty `corpus.diff` means the change has no effect on parser output.

0 commit comments

Comments
 (0)