runtime: add main(argv), bounds validation, and error guards in awc_metadata with CLI suite #2407

Merged
Ammmae0x merged 1 commit from upstream-pr/2415 into main 2026-11-25 18:42:20 +00:00
Ammmae0x commented 2026-11-25 16:04:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T16:04:09Z.


Change

Add a testable main(argv=None) -> int entrypoint, upfront bounds and path validation, and structured error handling to tools/awc_metadata.py, together with a standalone pure-Python CLI test suite registered in CMakeLists.txt (audio_awc_metadata_cli_check).

  • tools/awc_metadata.py: accept argv: Optional[list[str]] = None in main, forward argv to parser.parse_args(argv), return 0 on success, and invoke raise SystemExit(main()) under __main__.
  • Validate --offset >= 0, --size > 0, and reject directory paths (args.archive.is_dir()) before opening/reading the archive.
  • Catch (OSError, ValueError, struct.error) cleanly via parser.exit(1, f"{type(exc).__name__}: {exc}\n") without raw tracebacks while preserving the exact JSON output schema for SFX and music AWC banks.
  • tests/awc_metadata_cli_check.py: standalone unittest suite covering decimal and 0x... hex --offset/--size, SFX & music ADAT/TADA JSON schema fidelity, main(None) / __main__ entrypoint forwarding, and negative/mutation controls (missing archive, directory path, negative --offset, zero/negative --size, truncated banks, struct.error, and corrupt ADAT/TADA headers).
  • CMakeLists.txt: register audio_awc_metadata_cli_check immediately after audio_awc_metadata (tests/awc_metadata_check.py left untouched).

Verification

Verified on commit 4fe3f74b (based on upstream/main 7092683a) using out/pe-env/Scripts/python.exe -B:

  • out/pe-env/Scripts/python.exe -B tests/awc_metadata_cli_check.py -v -> Ran 8 tests in 3.870s, OK (exit 0).
  • out/pe-env/Scripts/python.exe -B tests/awc_metadata_check.py -v -> Ran 14 tests in 0.700s, OK (exit 0).
  • out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py -> form coverage checks passed (exit 0).
  • out/pe-env/Scripts/python.exe -B tests/docs_links_check.py -> Self-test passed. Checked 19 Markdown files and 464 links. (exit 0).
  • out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> Self-test passed. Checked 1724 tracked source, script and build/CI files: no bidirectional controls. (exit 0).
  • Spot mutation audit on tools/awc_metadata.py: 8/8 mutations killed (argv forwarding, --offset < 0, --size <= 0, is_dir(), struct.error guard, OSError guard, exit code 1, integer 0 return).

Evidence and follow-up

All fixtures in tests/awc_metadata_cli_check.py are synthetic source-built ADAT/TADA byte arrays generated in-memory under the repository MIT license; no external or game files are used. Contributors can run the new suite directly with out/pe-env/Scripts/python.exe -B tests/awc_metadata_cli_check.py or via CTest (audio_awc_metadata_cli_check).

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6608525259 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2415). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T16:04:09Z. --- ## Change Add a testable `main(argv=None) -> int` entrypoint, upfront bounds and path validation, and structured error handling to `tools/awc_metadata.py`, together with a standalone pure-Python CLI test suite registered in `CMakeLists.txt` (`audio_awc_metadata_cli_check`). - `tools/awc_metadata.py`: accept `argv: Optional[list[str]] = None` in `main`, forward `argv` to `parser.parse_args(argv)`, return `0` on success, and invoke `raise SystemExit(main())` under `__main__`. - Validate `--offset >= 0`, `--size > 0`, and reject directory paths (`args.archive.is_dir()`) before opening/reading the archive. - Catch `(OSError, ValueError, struct.error)` cleanly via `parser.exit(1, f"{type(exc).__name__}: {exc}\n")` without raw tracebacks while preserving the exact JSON output schema for SFX and music AWC banks. - `tests/awc_metadata_cli_check.py`: standalone unittest suite covering decimal and `0x...` hex `--offset`/`--size`, SFX & music ADAT/TADA JSON schema fidelity, `main(None)` / `__main__` entrypoint forwarding, and negative/mutation controls (missing archive, directory path, negative `--offset`, zero/negative `--size`, truncated banks, `struct.error`, and corrupt ADAT/TADA headers). - `CMakeLists.txt`: register `audio_awc_metadata_cli_check` immediately after `audio_awc_metadata` (`tests/awc_metadata_check.py` left untouched). ## Verification Verified on commit `4fe3f74b` (based on `upstream/main` `7092683a`) using `out/pe-env/Scripts/python.exe -B`: - `out/pe-env/Scripts/python.exe -B tests/awc_metadata_cli_check.py -v` -> `Ran 8 tests in 3.870s`, `OK` (exit 0). - `out/pe-env/Scripts/python.exe -B tests/awc_metadata_check.py -v` -> `Ran 14 tests in 0.700s`, `OK` (exit 0). - `out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py` -> `form coverage checks passed` (exit 0). - `out/pe-env/Scripts/python.exe -B tests/docs_links_check.py` -> `Self-test passed. Checked 19 Markdown files and 464 links.` (exit 0). - `out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py` -> `Self-test passed. Checked 1724 tracked source, script and build/CI files: no bidirectional controls.` (exit 0). - Spot mutation audit on `tools/awc_metadata.py`: 8/8 mutations killed (`argv` forwarding, `--offset < 0`, `--size <= 0`, `is_dir()`, `struct.error` guard, `OSError` guard, exit code `1`, integer `0` return). ## Evidence and follow-up All fixtures in `tests/awc_metadata_cli_check.py` are synthetic source-built ADAT/TADA byte arrays generated in-memory under the repository MIT license; no external or game files are used. Contributors can run the new suite directly with `out/pe-env/Scripts/python.exe -B tests/awc_metadata_cli_check.py` or via CTest (`audio_awc_metadata_cli_check`). ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
KelboLive commented 2026-11-25 17:01:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-25T16:05:53Z.


APPROVED: main(argv), bounds validation, and error guards in awc_metadata with CLI suite. Good runtime addition.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7167591059 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2415#issuecomment-7167591059). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-25T16:05:53Z. --- APPROVED: main(argv), bounds validation, and error guards in awc_metadata with CLI suite. Good runtime addition.
upstream-sync closed this pull request 2026-11-25 19:03:38 +00:00
tedin7 commented 2026-11-25 19:03:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T18:22:11Z.

Review: COMMENTED


Review of head 4fe3f74b (Linux checks only; no Windows run by me, and I found no author-posted Windows results for this SHA).

What I checked

  • Scope: 3 files (tools/awc_metadata.py, new tests/awc_metadata_cli_check.py, one CTest line in CMakeLists.txt). Small and additive. No other open or merged PR touches awc_metadata (searched awc_metadata).
  • main(argv) now returns an int and the entry point uses raise SystemExit(main()). The new guards (negative offset, non-positive size, directory path, struct.error) all exit 1 through parser.exit.
  • The new CTest entry sits next to audio_awc_metadata in the same INTAKE_PYTHON block.

Commands run in a clean worktree of the PR head

  • python3 -B tests/awc_metadata_check.py -> 14 tests OK
  • python3 -B tests/awc_metadata_cli_check.py -> 8 tests OK
  • python3 tests/docs_links_check.py -> OK
  • python3 tests/bidi_controls_check.py -> OK
  • git diff --check origin/main...HEAD -> clean
  • Mutation 1: args.size <= 0 changed to < 0 -> the CLI suite fails (1 failure, 1 error)
  • Mutation 2: directory guard disabled -> the CLI suite fails (1 failure)
    Both mutations were reverted.

Minor notes (not blocking)

  • tools/awc_metadata.py:~192: the error line used to be <archive>: <error>. It is now <ExceptionType>: <error> and no longer names the archive file. Keeping the path in the message would help when this runs in batch scripts.
  • The args.size <= 0 guard also rejects --size 0. That is reasonable, since read_bank cannot parse a zero-byte bank anyway.

No bugs found. Windows results for the final head are still needed before a merge.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6062807322 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2415#pullrequestreview-6062807322). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T18:22:11Z. **Review:** COMMENTED --- Review of head 4fe3f74b (Linux checks only; no Windows run by me, and I found no author-posted Windows results for this SHA). What I checked - Scope: 3 files (tools/awc_metadata.py, new tests/awc_metadata_cli_check.py, one CTest line in CMakeLists.txt). Small and additive. No other open or merged PR touches awc_metadata (searched `awc_metadata`). - `main(argv)` now returns an int and the entry point uses `raise SystemExit(main())`. The new guards (negative offset, non-positive size, directory path, `struct.error`) all exit 1 through `parser.exit`. - The new CTest entry sits next to `audio_awc_metadata` in the same INTAKE_PYTHON block. Commands run in a clean worktree of the PR head - `python3 -B tests/awc_metadata_check.py` -> 14 tests OK - `python3 -B tests/awc_metadata_cli_check.py` -> 8 tests OK - `python3 tests/docs_links_check.py` -> OK - `python3 tests/bidi_controls_check.py` -> OK - `git diff --check origin/main...HEAD` -> clean - Mutation 1: `args.size <= 0` changed to `< 0` -> the CLI suite fails (1 failure, 1 error) - Mutation 2: directory guard disabled -> the CLI suite fails (1 failure) Both mutations were reverted. Minor notes (not blocking) - tools/awc_metadata.py:~192: the error line used to be `<archive>: <error>`. It is now `<ExceptionType>: <error>` and no longer names the archive file. Keeping the path in the message would help when this runs in batch scripts. - The `args.size <= 0` guard also rejects `--size 0`. That is reasonable, since `read_bank` cannot parse a zero-byte bank anyway. No bugs found. Windows results for the final head are still needed before a merge. AI-assisted; commands listed were executed locally.
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
R0Y00/Xbox2Windows!2407
No description provided.