PR checks: an empty file or a pure rename is not a binary #513

Open
github-bot wants to merge 2 commits from github-bot/gh-513 into main AGit
Owner

@⁠hmodymac8-droid on GitHub · 2026-11-24 01:08 UTC · original
hmodymac8-droid:scripts/pr-check-binary-by-content → main · +72 −3 · 2 files · 2 commits · open

pr-check.yml marks a file as binary when GitHub's files API shows no patch and 0 changed lines ((.patch == null) and (.changes == 0)). That is also what the API returns for an empty file, a pure rename and a mode-only change, so pr_check.py refuses such a PR with "<file> is a binary file outside tests/data/ or over 1 MB", although nothing binary was added. Moving a script or adding a .gitkeep is enough to hit it.

Reproduced on a throwaway PR in my fork (since closed): a pure rename of scripts/re/pe_exports.py, an empty scripts/re/.gitkeep and a real PNG header in docs/picture.png. The files API returned binary = true for all three:

  • main's pr_check.py refuses all three files
  • with this PR, only docs/picture.png is refused

What is in it

  • scripts/pr_check.py: when the workflow marks a file binary, blob_is_binary() reads the blob (git/blobs API, or git cat-file -p with --local) and keeps the mark only if the content is binary by git's own test (looks_binary(): a NUL byte in the first 8000 bytes; an empty file is not binary). If the blob can't be read, the workflow's answer stands. check() and pr-check.yml are unchanged.
  • scripts/test_pr_check.py (from #507): a BinaryContentTests class with looks_binary(), plus end-to-end --local runs. An empty file and a renamed text file pass; a new PNG and a renamed binary are still refused.

Tested

  • Windows 11 Pro 26200, Python 3.13, AMD Radeon RX 7700 XT (driver 32.0.32029.2010), Rust 1.100.0
  • python test_pr_check.py (in scripts/): OK, together with #507's tests. Against main's pr_check.py the empty file and the rename are refused (and looks_binary does not exist)
  • the API path (no --local) on the real files list of the probe PR above: results as listed
  • python scripts/pr_check.py --local on this description: description ok
  • cargo test --workspace -- --test-threads=4 at 2997c9a: 676 passed, 0 failed, 41 ignored, no SKIPPED (results in #42)

Regression run

  • not needed: no file under crates/xcl/src changes

Not tested

  • a run of pr-check.yml itself (it uses main's pr_check.py, so this takes effect after merge)

AI use

  • Claude Code (Claude Opus 5.5) found the problem, reproduced it through the API, wrote the fix and the tests.

🤖 Generated with Claude Code

**@⁠hmodymac8-droid** on GitHub · 2026-11-24 01:08 UTC · [original](https://github.com/xcl-dev/xcl/pull/513) `hmodymac8-droid:scripts/pr-check-binary-by-content` → `main` · +72 −3 · 2 files · 2 commits · open `pr-check.yml` marks a file as binary when GitHub's files API shows no patch and 0 changed lines (`(.patch == null) and (.changes == 0)`). That is also what the API returns for **an empty file, a pure rename and a mode-only change**, so `pr_check.py` refuses such a PR with "`<file>` is a binary file outside tests/data/ or over 1 MB", although nothing binary was added. Moving a script or adding a `.gitkeep` is enough to hit it. Reproduced on a throwaway PR in my fork (since closed): a pure rename of `scripts/re/pe_exports.py`, an empty `scripts/re/.gitkeep` and a real PNG header in `docs/picture.png`. The files API returned `binary = true` for all three: - `main`'s `pr_check.py` refuses all three files - with this PR, only `docs/picture.png` is refused **What is in it** - `scripts/pr_check.py`: when the workflow marks a file binary, `blob_is_binary()` reads the blob (`git/blobs` API, or `git cat-file -p` with `--local`) and keeps the mark only if the content is binary by git's own test (`looks_binary()`: a NUL byte in the first 8000 bytes; an empty file is not binary). If the blob can't be read, the workflow's answer stands. `check()` and `pr-check.yml` are unchanged. - `scripts/test_pr_check.py` (from #507): a `BinaryContentTests` class with `looks_binary()`, plus end-to-end `--local` runs. An empty file and a renamed text file pass; a new PNG and a renamed binary are still refused. **Tested** - Windows 11 Pro 26200, Python 3.13, AMD Radeon RX 7700 XT (driver 32.0.32029.2010), Rust 1.100.0 - `python test_pr_check.py` (in `scripts/`): OK, together with #507's tests. Against `main`'s `pr_check.py` the empty file and the rename are refused (and `looks_binary` does not exist) - the API path (no `--local`) on the real files list of the probe PR above: results as listed - `python scripts/pr_check.py --local` on this description: `description ok` - `cargo test --workspace -- --test-threads=4` at `2997c9a`: 676 passed, 0 failed, 41 ignored, no `SKIPPED` (results in #42) **Regression run** - not needed: no file under `crates/xcl/src` changes **Not tested** - a run of `pr-check.yml` itself (it uses `main`'s `pr_check.py`, so this takes effect after merge) **AI use** - Claude Code (Claude Opus 5.5) found the problem, reproduced it through the API, wrote the fix and the tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The workflow marks a file binary when GitHub shows no patch and 0 changed lines,
which is also true of an empty file (.gitkeep), a pure rename and a mode change,
so such a PR was refused as adding a binary. pr_check.py now confirms the flag
with the blob's content, as git does (a NUL in the first 8000 bytes). Adds
scripts/pr_check_binary_tests.py.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:24:02 +00:00
Author
Owner

@⁠wadzwigidy on GitHub · 2026-11-24 01:32 UTC · original

Independent check of PR #513 at 15e3d8800a5b918066e9480072a4c2802276cfb7.

Tested

  • Windows 11 build 26300, AMD Ryzen 9 5900X, NVIDIA RTX 4080 SUPER (driver 32.0.16.2135; GPU not used), Python 3.14.9.
  • py -3.14 scripts/pr_check_binary_tests.py -v: 4 passed, 0 failed. The tests accept an empty file and a text rename, and still reject a PNG and a renamed binary.
  • git diff --check on the PR commit: clean; worktree clean. Tests used synthetic files only. Temporary files and the checkout were kept on the VS Projects share.

Not tested

  • The live GitHub API path, pr-check.yml after merge, or the Rust/GPU suite.

AI use

  • Codex (GPT-6; exact model identifier not exposed to this session) assisted with the local check and this report. No game files were used.
**@⁠wadzwigidy** on GitHub · 2026-11-24 01:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/513#issuecomment-7119194340) Independent check of PR #513 at `15e3d8800a5b918066e9480072a4c2802276cfb7`. **Tested** - Windows 11 build 26300, AMD Ryzen 9 5900X, NVIDIA RTX 4080 SUPER (driver 32.0.16.2135; GPU not used), Python 3.14.9. - `py -3.14 scripts/pr_check_binary_tests.py -v`: 4 passed, 0 failed. The tests accept an empty file and a text rename, and still reject a PNG and a renamed binary. - `git diff --check` on the PR commit: clean; worktree clean. Tests used synthetic files only. Temporary files and the checkout were kept on the VS Projects share. **Not tested** - The live GitHub API path, `pr-check.yml` after merge, or the Rust/GPU suite. **AI use** - Codex (GPT-6; exact model identifier not exposed to this session) assisted with the local check and this report. No game files were used.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 13:53 UTC · original

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

**@⁠DavidM1911** on GitHub · 2026-11-25 13:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/513#issuecomment-7164446621) Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
This pull request has changes conflicting with the target branch.
  • scripts/test_pr_check.py
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/513/head:github-bot/gh-513'
git switch 'github-bot/gh-513'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-513'
git switch 'github-bot/gh-513'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-513'
git switch 'github-bot/gh-513'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-513'
git switch 'main'
git merge --squash 'github-bot/gh-513'
git switch 'main'
git merge --ff-only 'github-bot/gh-513'
git switch 'main'
git merge 'github-bot/gh-513'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.