Scripts: harden gen_bcpack_victory_tables CLI argument handling and output option #1430

Open
heditrigui wants to merge 1 commit from upstream-pr/1440 into main
heditrigui commented 2026-11-24 15:59:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by heditrigui on 2026-11-24T15:59:17Z.


Harden scripts/gen_bcpack_victory_tables.py argument parsing and output configuration:

  • Support -h and --help flags, printing the script's docstring usage and exiting with code 0.
  • Print usage and exit with code 2 when invoked without arguments, avoiding an unhandled IndexError.
  • Validate input file existence and report diagnostic errors to sys.stderr when <bcpack-tables.bin> is missing or has an unexpected size (exit code 1) instead of crashing with unhandled tracebacks.
  • Accept an optional second argument [out.rs] to write output to a custom destination, defaulting to crates/xcl/src/hle/bcpack/tables.rs.
  • Add scripts/test_gen_bcpack_victory_tables.py covering CLI help, missing argument handling, invalid file reporting, custom output path writing, and synthetic table binary parsing.

Tested

  • python -B -m unittest discover -s scripts -p "test_*.py" -v: 23 passed, 0 failed.
  • Tested scripts/gen_bcpack_victory_tables.py --help (exits 0 with usage docstring).
  • Tested scripts/gen_bcpack_victory_tables.py with no args (exits 2 with usage docstring).
  • Tested scripts/gen_bcpack_victory_tables.py nonexistent.bin (exits 1 with clear diagnostic).
  • Validated PR description and changed files with scripts/pr_check.py --local.

Not tested

  • Retail game smoke tests: this PR modifies only offline code generator tooling in scripts/ and does not touch runtime code or dependencies.

AI use
Antigravity (Gemini 3.8 Flash (High)) designed the CLI argument handling and optional output destination, implemented unit tests in scripts/test_gen_bcpack_victory_tables.py, ran the test suite, and verified PR conventions.

<!-- greyfinch-sync:ivall/xcl:issue:5475697985 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1440). Originally posted by [heditrigui](https://github.com/heditrigui) on 2026-11-24T15:59:17Z. --- Harden `scripts/gen_bcpack_victory_tables.py` argument parsing and output configuration: - Support `-h` and `--help` flags, printing the script's docstring usage and exiting with code 0. - Print usage and exit with code 2 when invoked without arguments, avoiding an unhandled `IndexError`. - Validate input file existence and report diagnostic errors to `sys.stderr` when `<bcpack-tables.bin>` is missing or has an unexpected size (exit code 1) instead of crashing with unhandled tracebacks. - Accept an optional second argument `[out.rs]` to write output to a custom destination, defaulting to `crates/xcl/src/hle/bcpack/tables.rs`. - Add `scripts/test_gen_bcpack_victory_tables.py` covering CLI help, missing argument handling, invalid file reporting, custom output path writing, and synthetic table binary parsing. **Tested** - `python -B -m unittest discover -s scripts -p "test_*.py" -v`: 23 passed, 0 failed. - Tested `scripts/gen_bcpack_victory_tables.py --help` (exits 0 with usage docstring). - Tested `scripts/gen_bcpack_victory_tables.py` with no args (exits 2 with usage docstring). - Tested `scripts/gen_bcpack_victory_tables.py nonexistent.bin` (exits 1 with clear diagnostic). - Validated PR description and changed files with `scripts/pr_check.py --local`. **Not tested** - Retail game smoke tests: this PR modifies only offline code generator tooling in `scripts/` and does not touch runtime code or dependencies. **AI use** Antigravity (Gemini 3.8 Flash (High)) designed the CLI argument handling and optional output destination, implemented unit tests in `scripts/test_gen_bcpack_victory_tables.py`, ran the test suite, and verified PR conventions.
nnonno91 commented 2026-11-24 17:06:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by nnonno91 on 2026-11-24T16:08:11Z.


Windows CLI test report for ab7a400

Tested

  • Windows 11 25H2 (build 26200), Python 3.14.5 x64. python -B -m unittest discover -s scripts -p "test_*.py" -v passed 23 tests on clean head ab7a400c70bb334fac520c8bcc50573c19d4ddb4.
  • I ran the CLI from a separate working directory using python -I. For two 77,982-byte synthetic inputs (zero-filled and seeded), the explicit output from the parent commit 037aecd57e8a2ae55154d5e0dfb7119e75430f5b, the PR’s explicit output, and the PR’s default output were byte-for-byte identical. The explicit PR path included spaces and a new subdirectory. I tested the default destination in a temporary copy.
  • With no arguments, the parent raised IndexError; the PR printed usage and exited 2. Both -h and --help printed usage and exited 0 on the PR.
  • The PR reported exit 1 without a traceback for a missing file and for 0-, 77,981-, and 77,983-byte inputs. Those cases left an existing default output byte-for-byte intact and created no file at a new explicit destination.

Not tested

  • Real table data and retail-title smoke testing. The checks above used synthetic data and the Python tooling suite.

AI use

  • OpenAI Codex (GPT-6, exact model variant unavailable) ran the tests and prepared this report.
<!-- greyfinch-sync:ivall/xcl:comment:7137175735 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1440#issuecomment-7137175735). Originally posted by [nnonno91](https://github.com/nnonno91) on 2026-11-24T16:08:11Z. --- ### Windows CLI test report for `ab7a400` **Tested** - Windows 11 25H2 (build 26200), Python 3.14.5 x64. `python -B -m unittest discover -s scripts -p "test_*.py" -v` passed **23 tests** on clean head `ab7a400c70bb334fac520c8bcc50573c19d4ddb4`. - I ran the CLI from a separate working directory using `python -I`. For two 77,982-byte synthetic inputs (zero-filled and seeded), the explicit output from the parent commit `037aecd57e8a2ae55154d5e0dfb7119e75430f5b`, the PR’s explicit output, and the PR’s default output were byte-for-byte identical. The explicit PR path included spaces and a new subdirectory. I tested the default destination in a temporary copy. - With no arguments, the parent raised `IndexError`; the PR printed usage and exited `2`. Both `-h` and `--help` printed usage and exited `0` on the PR. - The PR reported exit `1` without a traceback for a missing file and for 0-, 77,981-, and 77,983-byte inputs. Those cases left an existing default output byte-for-byte intact and created no file at a new explicit destination. **Not tested** - Real table data and retail-title smoke testing. The checks above used synthetic data and the Python tooling suite. **AI use** - OpenAI Codex (GPT-6, exact model variant unavailable) ran the tests and prepared this report.
gut0to commented 2026-11-24 17:06:21 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-11-24T17:06:21Z.

Review: COMMENTED


AI-assisted review; I checked the CLI argument flow against the documented usage.

<!-- greyfinch-sync:ivall/xcl:review:6043845297 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1440#pullrequestreview-6043845297). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-24T17:06:21Z. **Review:** COMMENTED --- AI-assisted review; I checked the CLI argument flow against the documented usage.
gut0to commented 2026-11-24 17:06:50 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-11-24T17:06:21Z.

Code review location: scripts/gen_bcpack_victory_tables.py; line 162

@@ -144,9 +155,35 @@ def plain_entries(items):
                 ctrl, rows_3, bits[0], bits[1],
                 ", ".join(map(str, ix[:16])), ", ".join(map(str, ix[16:]))))
     src_lines += ["];", ""]
-    open(dst, "w", encoding="utf-8", newline="\n").write("\n".join(src_lines))
-    print("wrote", dst, "entries", len(bc1), len(bc3), len(bc4), len(bc5), len(bc6), len(bc7))
+    return "\n".join(src_lines), (len(bc1), len(bc3), len(bc4), len(bc5), len(bc6), len(bc7))
+
+
+def main(argv=None):
+    args = argv if argv is not None else sys.argv[1:]

The documented usage accepts an input file and at most one optional output path, but main never rejects arguments after args[1]. A command with an extra positional argument silently ignores it and exits successfully, which can hide a typo. Please reject unexpected arguments and add a CLI test. AI-assisted review; I checked the documented usage against the argument handling.

<!-- greyfinch-sync:ivall/xcl:review-comment:4683658652 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1440#discussion_r4683658652). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-24T17:06:21Z. **Code review location:** `scripts/gen_bcpack_victory_tables.py`; line 162 ~~~~diff @@ -144,9 +155,35 @@ def plain_entries(items): ctrl, rows_3, bits[0], bits[1], ", ".join(map(str, ix[:16])), ", ".join(map(str, ix[16:])))) src_lines += ["];", ""] - open(dst, "w", encoding="utf-8", newline="\n").write("\n".join(src_lines)) - print("wrote", dst, "entries", len(bc1), len(bc3), len(bc4), len(bc5), len(bc6), len(bc7)) + return "\n".join(src_lines), (len(bc1), len(bc3), len(bc4), len(bc5), len(bc6), len(bc7)) + + +def main(argv=None): + args = argv if argv is not None else sys.argv[1:] ~~~~ --- The documented usage accepts an input file and at most one optional output path, but `main` never rejects arguments after `args[1]`. A command with an extra positional argument silently ignores it and exits successfully, which can hide a typo. Please reject unexpected arguments and add a CLI test. AI-assisted review; I checked the documented usage against the argument handling.
DavidM1911 commented 2026-11-24 19:07:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T18:52:34Z.


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

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7141274782 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1440#issuecomment-7141274782). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T18:52:34Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
RavenCurseBurg commented 2026-11-25 17:07:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by RavenCurseBurg on 2026-11-25T16:12:43Z.


I reproduced the extra-argument issue reported above on ab7a400c70bb334fac520c8bcc50573c19d4ddb4. With a 77,982-byte synthetic table, python -I scripts/gen_bcpack_victory_tables.py input.bin output.rs extra returned 0 and replaced an existing 15-byte output with 258,080 bytes.

Fix and CLI regression test. The generator now rejects the extra positional argument before opening the destination, writes the diagnostic to stderr and exits 2. The test starts with a sentinel output and checks its exact bytes. It failed before the fix (exit 0) and passed after. All 24 Python script tests passed with python -B -m unittest discover -s scripts -p "test_*.py"; git diff --check also passed.

Windows 11 26100.9711, i7-13700, RTX 4060, Python 3.14.3. Synthetic table data only; no game, Rust or GPU run. OpenAI Codex (GPT-6) wrote the patch and ran the checks.

<!-- greyfinch-sync:ivall/xcl:comment:7167690327 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1440#issuecomment-7167690327). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T16:12:43Z. --- I reproduced the extra-argument issue reported above on `ab7a400c70bb334fac520c8bcc50573c19d4ddb4`. With a 77,982-byte synthetic table, `python -I scripts/gen_bcpack_victory_tables.py input.bin output.rs extra` returned 0 and replaced an existing 15-byte output with 258,080 bytes. [Fix and CLI regression test](https://github.com/RavenCurseBurg/xcl/commit/fe18c0b10c260af6506846d5c15f6c4a3a25d92b). The generator now rejects the extra positional argument before opening the destination, writes the diagnostic to stderr and exits 2. The test starts with a sentinel output and checks its exact bytes. It failed before the fix (exit 0) and passed after. All 24 Python script tests passed with `python -B -m unittest discover -s scripts -p "test_*.py"`; `git diff --check` also passed. Windows 11 26100.9711, i7-13700, RTX 4060, Python 3.14.3. Synthetic table data only; no game, Rust or GPU run. OpenAI Codex (GPT-6) wrote the patch and ran the checks.
github-actions[bot] commented 2026-11-28 20:17:38 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-28T20:17:38Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7245179760 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1440#issuecomment-7245179760). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-28T20:17:38Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 05:45:35 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:45:35Z.


Triage (#1607) – head ab7a400

No open PR changes gen_bcpack_victory_tables.py; the lines shared with #1336 are the same CLI pattern (help text, default output, error exit codes) applied to a different script, gen_d3d12_layout.py.
No problems found in the diff: TABLES_BIN_SIZE (77982) matches what generate() consumes, and the default output path is the existing crates/xcl/src/hle/bcpack/tables.rs. main has since changed the BC7 loop in this script (7881dbc, entry 0 keeps 32 indices); the size is unchanged, but the synthetic test blob should be rechecked against it after a rebase.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7302107798 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1440#issuecomment-7302107798). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:45:35Z. --- **Triage (#1607)** – head ab7a400 No open PR changes gen_bcpack_victory_tables.py; the lines shared with #1336 are the same CLI pattern (help text, default output, error exit codes) applied to a different script, gen_d3d12_layout.py. No problems found in the diff: TABLES_BIN_SIZE (77982) matches what generate() consumes, and the default output path is the existing crates/xcl/src/hle/bcpack/tables.rs. main has since changed the BC7 loop in this script (7881dbc, entry 0 keeps 32 indices); the size is unchanged, but the synthetic test blob should be rechecked against it after a rebase. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1440:upstream-pr/1440'
git switch 'upstream-pr/1440'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1440'
git switch 'upstream-pr/1440'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1440'
git switch 'upstream-pr/1440'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1440'
git switch 'main'
git merge --squash 'upstream-pr/1440'
git switch 'main'
git merge --ff-only 'upstream-pr/1440'
git switch 'main'
git merge 'upstream-pr/1440'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1430
No description provided.