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

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

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


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.

<!-- greyfinch-sync:ivall/xcl:issue:5473583341 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1267). Originally posted by [heditrigui](https://github.com/heditrigui) on 2026-11-24T13:59:52Z. --- 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.
DavidM1911 commented 2026-11-24 14:06:52 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T14:05:31Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7133825822 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1267#issuecomment-7133825822). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T14:05:31Z. --- 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!
RavenCurseBurg commented 2026-11-25 15:07:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by RavenCurseBurg on 2026-11-25T14:35:44Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7165518803 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1267#issuecomment-7165518803). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T14:35:44Z. --- 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.
luckyteagirl commented 2026-11-26 05:15:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T05:15:16Z.

Review: COMMENTED


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).

<!-- greyfinch-sync:ivall/xcl:review:6068893182 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1267#pullrequestreview-6068893182). Originally posted by [luckyteagirl](https://github.com/luckyteagirl) on 2026-11-26T05:15:16Z. **Review:** COMMENTED --- 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).
github-actions[bot] commented 2026-11-30 08:43:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-30T08:43:36Z.


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:7273266169 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1267#issuecomment-7273266169). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-30T08:43:36Z. --- 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:17:15 +00:00 (Migrated from github.com)

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


Triage (#1607) – head 4859ec4

No other open PR changes scripts/gen_gdk_table.py; the other "harden ... CLI" PRs touch different generators. The default output is byte-for-byte the same as before (same header, row order and trailing newline).
Minor: DEFAULT_OUT is imported in the test but not used.
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:7301612287 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1267#issuecomment-7301612287). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:17:15Z. --- **Triage (#1607)** – head 4859ec4 No other open PR changes scripts/gen_gdk_table.py; the other "harden ... CLI" PRs touch different generators. The default output is byte-for-byte the same as before (same header, row order and trailing newline). Minor: `DEFAULT_OUT` is imported in the test but not used. 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/1267:upstream-pr/1267'
git switch 'upstream-pr/1267'

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/1267'
git switch 'upstream-pr/1267'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1267'
git switch 'upstream-pr/1267'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1267'
git switch 'main'
git merge --squash 'upstream-pr/1267'
git switch 'main'
git merge --ff-only 'upstream-pr/1267'
git switch 'main'
git merge 'upstream-pr/1267'
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!1257
No description provided.