Scripts: harden record_writers CLI argument handling and validation #2049

Open
github-bot wants to merge 1 commit from github-bot/gh-2049 into main AGit
Owner

@⁠heditrigui on GitHub · 2026-11-25 02:00 UTC · original
heditrigui:scripts/record-writers-cli-hardening → main · +246 −62 · 2 files · 1 commits · open

Summary

Hardens CLI argument handling and validation in scripts/re/record_writers.py and expands unit test coverage in scripts/test_record_writers.py:

  • Adds -h and --help CLI option support with usage docstrings and clean exit code 0.
  • Rejects missing arguments with usage instructions and exit code 2.
  • Handles missing or unreadable files cleanly (reports error: file not found: '<asm_path>' on stderr and exits code 1) instead of crashing with unhandled Python exceptions.
  • Modularizes record writer extraction into reusable find_record_writers(lines), dump_record_writers(lines, file=None), and main(argv=None, out=None) functions so the module can be cleanly imported without executing top-level logic or crashing.
  • Expands scripts/test_record_writers.py from 1 to 9 tests covering branch targets with/without hex prefix, list-field header extraction, lea length calculation, empty listings, help flags, missing argument exit codes, nonexistent files, direct Python API usage, and programmatic main invocation.

Tested

  • python scripts/test_record_writers.py (9 tests passed in 0.92s).
  • python -m pytest scripts/ (33 passed in 1.31s).
  • Validated with scripts/pr_check.py --local.

Not tested

  • Retail game smoke execution (scripts/ tools are non-runtime code).

AI use

  • Antigravity (Gemini 3.8 Flash (High))
**@⁠heditrigui** on GitHub · 2026-11-25 02:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/2049) `heditrigui:scripts/record-writers-cli-hardening` → `main` · +246 −62 · 2 files · 1 commits · open ### Summary Hardens CLI argument handling and validation in `scripts/re/record_writers.py` and expands unit test coverage in `scripts/test_record_writers.py`: - Adds `-h` and `--help` CLI option support with usage docstrings and clean exit code 0. - Rejects missing arguments with usage instructions and exit code 2. - Handles missing or unreadable files cleanly (reports `error: file not found: '<asm_path>'` on stderr and exits code 1) instead of crashing with unhandled Python exceptions. - Modularizes record writer extraction into reusable `find_record_writers(lines)`, `dump_record_writers(lines, file=None)`, and `main(argv=None, out=None)` functions so the module can be cleanly imported without executing top-level logic or crashing. - Expands `scripts/test_record_writers.py` from 1 to 9 tests covering branch targets with/without hex prefix, list-field header extraction, lea length calculation, empty listings, help flags, missing argument exit codes, nonexistent files, direct Python API usage, and programmatic `main` invocation. **Tested** - `python scripts/test_record_writers.py` (9 tests passed in 0.92s). - `python -m pytest scripts/` (33 passed in 1.31s). - Validated with `scripts/pr_check.py --local`. **Not tested** - Retail game smoke execution (`scripts/` tools are non-runtime code). **AI use** - Antigravity (Gemini 3.8 Flash (High))
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:16:43 +00:00
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 02:04 UTC · original

Code review on 48c08bc:

  • Extracting find_record_writers / dump_record_writers / main in scripts/re/record_writers.py cleanly adds -h/--help (rc=0), missing-arg usage (rc=2), missing-file handling (rc=1), and comprehensive CLI + unit tests in scripts/test_record_writers.py.
  • Diff audited and CI workflow approved (running).

Remaining before merge: Build and test finishing green plus independent verification on 48c08bc.

**@⁠raylitebull** on GitHub · 2026-11-25 02:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/2049#issuecomment-7150279319) Code review on `48c08bc`: - Extracting `find_record_writers` / `dump_record_writers` / `main` in `scripts/re/record_writers.py` cleanly adds `-h`/`--help` (`rc=0`), missing-arg usage (`rc=2`), missing-file handling (`rc=1`), and comprehensive CLI + unit tests in `scripts/test_record_writers.py`. - Diff audited and `CI` workflow approved (running). **Remaining before merge:** `Build and test` finishing green plus independent verification on `48c08bc`.
Author
Owner

@⁠JJAutoCompare on GitHub · 2026-11-25 02:12 UTC · original

Independent Windows compatibility run for 48c08bc26023dcbbece3e1bd3906b083d6917a3e. The reused checkout was clean before and after the run, and the open PR still pointed to this commit after testing.

Tested

  • AMD Ryzen 7 3800X, Windows 11 Enterprise Evaluation x64 (build 26200.9974), portable CPython 3.13.7 x64. The captured CLI streams used the host’s default Windows code page (CP1252).
  • Checked-in unittest suite: 9 passed, 0 failed, 0 ignored, 0 skipped. This covers help and missing arguments, missing files, direct API and programmatic main calls, branch targets with and without 0x, immediate and list-field headers, add and lea lengths, and a listing with zero matching sites.
  • Two additional CLI checks: 2 passed, 0 failed, 0 ignored, 0 skipped. Both paths contained spaces and accented characters in the directory and filename. The valid synthetic listing exited 0, wrote one site to stdout (imm beef, 40 bytes, bound +0x30, fallback slot 7), and left stderr empty. The missing path exited 1, left stdout empty, and wrote exactly one file-not-found message to stderr with the original path.

Commands executed from the repository root (TMP and TEMP were on L:):

L:\XclTooling\pr1999-coverage-52a120f7\portable\python.exe -B scripts/test_record_writers.py -v
L:\XclTooling\pr1999-coverage-52a120f7\portable\python.exe -B scripts/re/record_writers.py "L:\XclTooling\pr2049\run-20261125-031024-136\Entrée café\listing été.asm"
L:\XclTooling\pr1999-coverage-52a120f7\portable\python.exe -B scripts/re/record_writers.py "L:\XclTooling\pr2049\run-20261125-031024-136\Entrée café\absent été.asm"

Not tested

  • Other Windows code pages, characters outside CP1252, other Python versions, other platforms, third-party listings, and large inputs.
  • Full workspace suite, GPU and driver behavior, Rust/DXC, and retail smoke testing.

AI use

  • T3 Code / Codex (gpt-6.2-sol) prepared the synthetic fixture and ran, checked, and reported the commands above.
**@⁠JJAutoCompare** on GitHub · 2026-11-25 02:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/2049#issuecomment-7150448390) Independent Windows compatibility run for `48c08bc26023dcbbece3e1bd3906b083d6917a3e`. The reused checkout was clean before and after the run, and the open PR still pointed to this commit after testing. **Tested** - AMD Ryzen 7 3800X, Windows 11 Enterprise Evaluation x64 (build 26200.9974), portable CPython 3.13.7 x64. The captured CLI streams used the host’s default Windows code page (CP1252). - Checked-in unittest suite: 9 passed, 0 failed, 0 ignored, 0 skipped. This covers help and missing arguments, missing files, direct API and programmatic `main` calls, branch targets with and without `0x`, immediate and list-field headers, `add` and `lea` lengths, and a listing with zero matching sites. - Two additional CLI checks: 2 passed, 0 failed, 0 ignored, 0 skipped. Both paths contained spaces and accented characters in the directory and filename. The valid synthetic listing exited 0, wrote one site to stdout (`imm beef`, 40 bytes, bound `+0x30`, fallback slot 7), and left stderr empty. The missing path exited 1, left stdout empty, and wrote exactly one file-not-found message to stderr with the original path. Commands executed from the repository root (`TMP` and `TEMP` were on `L:`): ```text L:\XclTooling\pr1999-coverage-52a120f7\portable\python.exe -B scripts/test_record_writers.py -v L:\XclTooling\pr1999-coverage-52a120f7\portable\python.exe -B scripts/re/record_writers.py "L:\XclTooling\pr2049\run-20261125-031024-136\Entrée café\listing été.asm" L:\XclTooling\pr1999-coverage-52a120f7\portable\python.exe -B scripts/re/record_writers.py "L:\XclTooling\pr2049\run-20261125-031024-136\Entrée café\absent été.asm" ``` **Not tested** - Other Windows code pages, characters outside CP1252, other Python versions, other platforms, third-party listings, and large inputs. - Full workspace suite, GPU and driver behavior, Rust/DXC, and retail smoke testing. **AI use** - T3 Code / Codex (gpt-6.2-sol) prepared the synthetic fixture and ran, checked, and reported the commands above.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 04:41 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 04:41 UTC · [original](https://github.com/xcl-dev/xcl/pull/2049#issuecomment-7153080126) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
Author
Owner

@⁠RavenCurseBurg on GitHub · 2026-11-25 21:38 UTC · original · edited 2026-11-25 21:45 UTC

On 48c08bc26023dcbbece3e1bd3906b083d6917a3e I redirected the same seven-line synthetic listing with cmd /d /c type source.txt > sample.asm from each shell, then ran python -B scripts/re/record_writers.py sample.asm. Windows PowerShell 5.1 wrote UTF-16LE (first bytes FF FE 20 00), and the CLI exited 0 reporting 0 sites. PowerShell 7.6.9 wrote the original bytes and the CLI reported the expected single site.

Fix and regression test. Both redirected files now produce the same header, 32-byte record and fallback slot 8. I also passed both files in one invocation with a missing filename between them. Both valid files were processed, stderr identified the missing file, and the CLI exited 1.

python -B -m unittest discover -s scripts -p "test_*.py" passed all 33 tests on Windows 11 26100.9711, i7-13700, Python 3.14.3. The focused suite passed all 9 tests. The new encoding checks failed on the original code for UTF-8 with BOM and both UTF-16 byte orders when the first line contained the matching instruction. Synthetic text only. OpenAI Codex (GPT-6) prepared the patch, ran the checks and wrote this report.

**@⁠RavenCurseBurg** on GitHub · 2026-11-25 21:38 UTC · [original](https://github.com/xcl-dev/xcl/pull/2049#issuecomment-7175350024) · edited 2026-11-25 21:45 UTC On `48c08bc26023dcbbece3e1bd3906b083d6917a3e` I redirected the same seven-line synthetic listing with `cmd /d /c type source.txt > sample.asm` from each shell, then ran `python -B scripts/re/record_writers.py sample.asm`. Windows PowerShell 5.1 wrote UTF-16LE (first bytes `FF FE 20 00`), and the CLI exited 0 reporting **0 sites**. PowerShell 7.6.9 wrote the original bytes and the CLI reported the expected single site. [Fix and regression test](https://github.com/RavenCurseBurg/xcl/commit/9e91a1f8b8c7f65b9c83231590d5c6f84088204d). Both redirected files now produce the same header, 32-byte record and fallback slot 8. I also passed both files in one invocation with a missing filename between them. Both valid files were processed, stderr identified the missing file, and the CLI exited 1. `python -B -m unittest discover -s scripts -p "test_*.py"` passed all 33 tests on Windows 11 26100.9711, i7-13700, Python 3.14.3. The focused suite passed all 9 tests. The new encoding checks failed on the original code for UTF-8 with BOM and both UTF-16 byte orders when the first line contained the matching instruction. Synthetic text only. OpenAI Codex (GPT-6) prepared the patch, ran the checks and wrote this report.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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