runtime: add main(argv), bounds validation, and error guards in awc_metadata with CLI suite #2407
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2415"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T16:04:09Z.
Change
Add a testable
main(argv=None) -> intentrypoint, upfront bounds and path validation, and structured error handling totools/awc_metadata.py, together with a standalone pure-Python CLI test suite registered inCMakeLists.txt(audio_awc_metadata_cli_check).tools/awc_metadata.py: acceptargv: Optional[list[str]] = Noneinmain, forwardargvtoparser.parse_args(argv), return0on success, and invokeraise SystemExit(main())under__main__.--offset >= 0,--size > 0, and reject directory paths (args.archive.is_dir()) before opening/reading the archive.(OSError, ValueError, struct.error)cleanly viaparser.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 and0x...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: registeraudio_awc_metadata_cli_checkimmediately afteraudio_awc_metadata(tests/awc_metadata_check.pyleft untouched).Verification
Verified on commit
4fe3f74b(based onupstream/main7092683a) usingout/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).tools/awc_metadata.py: 8/8 mutations killed (argvforwarding,--offset < 0,--size <= 0,is_dir(),struct.errorguard,OSErrorguard, exit code1, integer0return).Evidence and follow-up
All fixtures in
tests/awc_metadata_cli_check.pyare 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 without/pe-env/Scripts/python.exe -B tests/awc_metadata_cli_check.pyor via CTest (audio_awc_metadata_cli_check).Checklist
AI-assisted.
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.
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
awc_metadata).main(argv)now returns an int and the entry point usesraise SystemExit(main()). The new guards (negative offset, non-positive size, directory path,struct.error) all exit 1 throughparser.exit.audio_awc_metadatain the same INTAKE_PYTHON block.Commands run in a clean worktree of the PR head
python3 -B tests/awc_metadata_check.py-> 14 tests OKpython3 -B tests/awc_metadata_cli_check.py-> 8 tests OKpython3 tests/docs_links_check.py-> OKpython3 tests/bidi_controls_check.py-> OKgit diff --check origin/main...HEAD-> cleanargs.size <= 0changed to< 0-> the CLI suite fails (1 failure, 1 error)Both mutations were reverted.
Minor notes (not blocking)
<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.args.size <= 0guard also rejects--size 0. That is reasonable, sinceread_bankcannot 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.