Scripts: harden gen_gdk_table CLI argument handling and output option #1267

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

@⁠heditrigui on GitHub · 2026-11-24 13:59 UTC · original
heditrigui:scripts/gen-gdk-table-cli-hardening → main · +172 −16 · 2 files · 1 commits · open

Harden scripts/gen_gdk_table.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 the file is missing or contains no matching GDK API table rows (exit code 1) instead of crashing with unhandled tracebacks.
  • Accept an optional second argument [out_rs] to write output to a custom destination instead of strictly hardcoding crates/xcl/src/hle/xgameruntime/gdk_table.rs.
  • Add scripts/test_gen_gdk_table.py covering CLI help, missing argument handling, invalid file reporting, custom output path writing, and table sorting/hex formatting.

Tested

  • python -B -m unittest discover -s scripts -p "test_*.py" -v: 17 passed, 0 failed.
  • Tested scripts/gen_gdk_table.py --help (exits 0 with usage docstring).
  • Tested scripts/gen_gdk_table.py with no args (exits 2 with usage docstring).
  • Tested scripts/gen_gdk_table.py nonexistent.txt (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_gdk_table.py, ran the test suite, and verified PR conventions.

**@⁠heditrigui** on GitHub · 2026-11-24 13:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/1267) `heditrigui:scripts/gen-gdk-table-cli-hardening` → `main` · +172 −16 · 2 files · 1 commits · open Harden `scripts/gen_gdk_table.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 the file is missing or contains no matching GDK API table rows (exit code 1) instead of crashing with unhandled tracebacks. - Accept an optional second argument `[out_rs]` to write output to a custom destination instead of strictly hardcoding `crates/xcl/src/hle/xgameruntime/gdk_table.rs`. - Add `scripts/test_gen_gdk_table.py` covering CLI help, missing argument handling, invalid file reporting, custom output path writing, and table sorting/hex formatting. **Tested** - `python -B -m unittest discover -s scripts -p "test_*.py" -v`: 17 passed, 0 failed. - Tested `scripts/gen_gdk_table.py --help` (exits 0 with usage docstring). - Tested `scripts/gen_gdk_table.py` with no args (exits 2 with usage docstring). - Tested `scripts/gen_gdk_table.py nonexistent.txt` (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_gdk_table.py`, ran the test suite, and verified PR conventions.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:48:59 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 14:05 UTC · original

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

  • cargo test -p xcl scripts/test_gen_gdk_table.py: 8 tests OK, 0 failed.

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 14:05 UTC · [original](https://github.com/xcl-dev/xcl/pull/1267#issuecomment-7133825822) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - cargo test -p xcl scripts/test_gen_gdk_table.py: 8 tests OK, 0 failed. Thanks!
Author
Owner

@⁠RavenCurseBurg on GitHub · 2026-11-25 14:35 UTC · original · edited 2026-11-26 06:44 UTC

Tested 4859ec4bb5cb819eb477ee46e332235380e4ca00 with python -B scripts/gen_gdk_table.py <input> <output> from a different working directory. With the three-row synthetic table, a Unicode directory and a spaced output name worked. Two runs produced byte-identical LF output with the slots in numeric order. The default repository table remained unchanged. The fixture used UTF-8 subprocess I/O.

The eight original generator tests passed. Three additional CLI cases exited 1 with a Python traceback: invalid UTF-8 input, an existing directory used as the output filename, and a regular file used as the output’s parent. A text input with no rows already gave a concise error.

Fix and regression tests. The three new failure cases reproduced on the PR head. After the change all three gave path-specific stderr diagnostics and exit 1, and invalid input preserved the previous output bytes. python -B -m unittest discover -s scripts -p "test_*.py" passed all 19 tests.

Windows 11 26100.9711, i7-13700, RTX 4060, Python 3.14.3. No proprietary GDK input, Rust build, retail title or GPU workload. OpenAI Codex (GPT-6) ran the checks, prepared the patch and wrote this report.

Follow-up on the latest review

I reproduced review 6068893182 on the PR head. With a valid one-row synthetic input and an existing output file, adding one extra argument returned 0 and overwrote the file.

The candidate checks arity before opening either path. The same command now exits 2 and preserves every byte. Both supported invocations (explicit and default output) still generated identical Rust tables in an isolated directory. The full Python script discovery run passed all 18 tests, including the new regression.

Candidate commit 2cf7b91f is based directly on 4859ec4bb5cb. Reproduce with python -B -m unittest discover -s scripts -p test_*.py. OpenAI Codex (GPT-6) prepared the fix and ran these Windows CPU fixtures. No game, GPU benchmark or workspace build.

**@⁠RavenCurseBurg** on GitHub · 2026-11-25 14:35 UTC · [original](https://github.com/xcl-dev/xcl/pull/1267#issuecomment-7165518803) · edited 2026-11-26 06:44 UTC Tested `4859ec4bb5cb819eb477ee46e332235380e4ca00` with `python -B scripts/gen_gdk_table.py <input> <output>` from a different working directory. With the three-row synthetic table, a Unicode directory and a spaced output name worked. Two runs produced byte-identical LF output with the slots in numeric order. The default repository table remained unchanged. The fixture used UTF-8 subprocess I/O. The eight original generator tests passed. Three additional CLI cases exited 1 with a Python traceback: invalid UTF-8 input, an existing directory used as the output filename, and a regular file used as the output’s parent. A text input with no rows already gave a concise error. [Fix and regression tests](https://github.com/RavenCurseBurg/xcl/commit/d643895cc3a814adcb14e91882066a88eb0e6c19). The three new failure cases reproduced on the PR head. After the change all three gave path-specific stderr diagnostics and exit 1, and invalid input preserved the previous output bytes. `python -B -m unittest discover -s scripts -p "test_*.py"` passed all 19 tests. Windows 11 26100.9711, i7-13700, RTX 4060, Python 3.14.3. No proprietary GDK input, Rust build, retail title or GPU workload. OpenAI Codex (GPT-6) ran the checks, prepared the patch and wrote this report. **Follow-up on the latest review** I reproduced review 6068893182 on the PR head. With a valid one-row synthetic input and an existing output file, adding one extra argument returned 0 and overwrote the file. The candidate checks arity before opening either path. The same command now exits 2 and preserves every byte. Both supported invocations (explicit and default output) still generated identical Rust tables in an isolated directory. The full Python script discovery run passed all 18 tests, including the new regression. [Candidate commit 2cf7b91f](https://github.com/RavenCurseBurg/xcl/commit/2cf7b91f6403afe747a29149de3bfeeb4382b473) is based directly on `4859ec4bb5cb`. Reproduce with `python -B -m unittest discover -s scripts -p test_*.py`. OpenAI Codex (GPT-6) prepared the fix and ran these Windows CPU fixtures. No game, GPU benchmark or workspace build.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-26 05:15 UTC · original · reviewed

Could main reject surplus positional arguments before opening the output? The new usage lists one required input and one optional output, but gen_gdk_table.py table.txt existing.rs unexpected takes args[1], ignores args[2], and overwrites existing.rs as if the invocation were valid. A CLI fixture with a sentinel output could check for a usage error and unchanged bytes. Source review only at head 4859ec4b; I did not run the script. AI-assisted with Codex (GPT-6.2 Sol).

**@⁠luckyteagirl** on GitHub · 2026-11-26 05:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/1267#pullrequestreview-6068893182) · **reviewed** Could `main` reject surplus positional arguments before opening the output? The new usage lists one required input and one optional output, but `gen_gdk_table.py table.txt existing.rs unexpected` takes `args[1]`, ignores `args[2]`, and overwrites `existing.rs` as if the invocation were valid. A CLI fixture with a sentinel output could check for a usage error and unchanged bytes. Source review only at head `4859ec4b`; I did not run the script. AI-assisted with Codex (GPT-6.2 Sol).
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/1267/head:github-bot/gh-1267'
git switch 'github-bot/gh-1267'

Merge

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