Skip to content

check_apt_key: -h/--help print the usage and description instead of a usage error (EGEN-APTKEY-CLI) - #7657

Closed
Vonsek wants to merge 3 commits into
ProjectLeonida:mainfrom
Vonsek:deepseek/2-aptkey-help
Closed

Vonsek wants to merge 3 commits into
ProjectLeonida:mainfrom
Vonsek:deepseek/2-aptkey-help

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Item: EGEN-APTKEY-CLI (found and claimed in #7496)

scripts/check_apt_key.py parsed argv by hand: len(argv) != 2 printed usage: check_apt_key.py KEYFILE FINGERPRINT
on stderr and returned 2. -h and --help therefore landed in that branch, so the tool answered a help request with the
exit code it uses for a usage error and never showed its description or its two arguments. Every other script in
scripts/ answers --help and exits 0, and AGENTS.md asks contributors and agents to quote a tool's --help usage line;
this is the one script where that does not work. Two CI workflows call it (.github/workflows/ci.yml:138,
.github/workflows/runtime.yml:329), with two arguments.

What changed

  • main() builds an argparse.ArgumentParser (prog="check_apt_key.py", description = the module docstring's first
    line) and takes the two positionals as KEYFILE/FINGERPRINT, so the printed usage stays the line the docstring
    documents. -h/--help print the usage, both arguments and the description on stdout and exit 0.
  • A missing argument, an unknown option and a bad fingerprint keep exit 2. The docstring's exit-code sentence says so and
    now also says that -h/--help exits 0.
  • Nothing the workflows do changes: both pass a key file and a 40-digit fingerprint.

Test

python -I tests/test_check_apt_key.py

Before (main, with the same test file and scripts/check_apt_key.py reverted to main's):

FAIL: test_help_names_the_arguments_and_exits_zero
AssertionError: 2 != 0 : usage: check_apt_key.py KEYFILE FINGERPRINT
Ran 15 tests in 10.812s
FAILED (failures=1)

After:

Ran 15 tests in 1.503s
OK

The new cases run the script: -h and --help must exit 0 with the usage, KEYFILE, FINGERPRINT and the docstring's
first line on stdout and nothing on stderr; --commits must exit 2 with the usage; the no-argument case must keep
exiting 2 and naming the usage.

python -m compileall -q scripts tests passes, and
python -I scripts/check_no_game_data.py scripts/check_apt_key.py tests/test_check_apt_key.py reports nothing, so nothing
here reads or adds game data.

No GPU needed. Windows 11, Python 3.12.

Notes

AI-assisted.

main() parsed argv by hand, so -h and --help fell through to the 'wrong argument count' branch: the bare usage line on stderr and exit 2, the same code as a usage error. argparse prints the usage, the arguments and the module docstring's first line as the description, and exits 0; a missing argument, an unknown option and a bad fingerprint still exit 2.
The exit-code sentence is what a CI author reads before wiring this into a workflow; it now says that -h/--help exits 0, so 0 no longer means only 'the key matched'.
The new cases run the script: -h and --help must print the usage, both arguments and the docstring's description on stdout and exit 0 (on main they exit 2 with the bare usage line on stderr), an unknown option must exit 2, and the no-argument usage error must keep naming the usage. Red on main, green with the argparse change.

@devnull34 devnull34 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified via Claude Code (Opus 5.5): Swapping the hand-rolled argument check for argparse makes -h/--help print the usage, both arguments and description on stdout and exit 0. Unknown options and missing arguments still exit 2 with usage error. All 15 tests in tests/test_check_apt_key.py pass cleanly.

@morodirule

Copy link
Copy Markdown

Tested b68bd2a on Arch Linux, Python 3.14.10, CPU only: pass — first Linux check. tests/test_check_apt_key.py 15/15 OK. Negative control: base script → exactly the targeted test fails (exit 2 instead of 0 on -h); restored, green again. No game files. AI-assisted.

@hcampbell98

Copy link
Copy Markdown

Tested b68bd2ab6 merged with main db9fef883 on Linux (WSL2, CPython 3.14.4 and 3.12.13, CPU only, no game files): Pass.

Checks

  • Merge, git diff --check db9fef883...HEAD, python3 -I scripts/check_no_game_data.py scripts/check_apt_key.py tests/test_check_apt_key.py, and python3 -m compileall -q scripts tests: clean / exit 0.
  • tests/test_check_apt_key.py:
    • CPython 3.14.4 (-I): 15/15 OK (0.275s).
    • CPython 3.12.13 (-I): 15/15 OK (0.183s).
    • Venv pytest -q: 15 passed, 2 subtests passed (0.27s).
  • Repo-wide gates: tests/test_ci_registration.py 14/14 OK; tests/test_runner_calls_all_tests.py 3/3 OK.
  • Direct CLI probes (python3 -I scripts/check_apt_key.py ...):
    • -h and --help exit 0 with empty stderr and usage: check_apt_key.py [-h] KEYFILE FINGERPRINT, KEYFILE, FINGERPRINT, and the docstring description on stdout.
    • --commits, --bad-opt, no args ([]), and [<file>, "bad"] exit 2 with diagnostic output on stderr and empty stdout.
  • Negative control (scripts/check_apt_key.py restored from db9fef883): tests/test_check_apt_key.py fails 1/15 at test_help_names_the_arguments_and_exits_zero (AssertionError: 2 != 0 : usage: check_apt_key.py KEYFILE FINGERPRINT).
  • Unrelated baseline failures matching db9fef883 identically: tests/test_tool_stdout_encoding.py (11 pre-existing files; scripts/check_apt_key.py is not flagged), tests/test_docs_cli_flags.py (docs/embedded_shaders.md + docs/dev-tools.md), and tests/test_text_write_line_endings.py (tools/leonida_tui.py:753, tools/wave_diff.py:373).

AI-assisted.

@sds-228 sds-228 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at the current head. The hand-rolled argument check is now argparse: -h/--help print the usage, both arguments and the description on stdout with exit 0, while missing arguments, unknown options and bad fingerprints keep exit 2.

CPU-only verification: the focused help test passes here and fails on the parent. Two workflow assertions are red in my checkout on the parent as well. Compile and no-game-data checks are clean.

AI-assisted (OpenCode).

@garuspl

garuspl commented Nov 23, 2026

Copy link
Copy Markdown

Tested b68bd2a on Windows 11 (CPU only, no GPU needed): pass

Windows 11 Pro, Python 3.14.7, no GPU or game files involved; pytest/numpy/Pillow pinned from tests/requirements.txt in a fresh venv. Method: PR head merged onto main bf85ff7, the PR's test files run with python -m pytest before and after the merge, plus python -m compileall -q on the changed files (clean).

  • tests/test_check_apt_key.py: main 13 passed; with the PR 15 passed (2 subtests).

AI-assisted (Claude Code, Claude Opus 5.5).

@airp1ane

Copy link
Copy Markdown
Contributor

Tested b68bd2a on Windows 11, Python 3.15.2, NVIDIA RTX 4060 Ti (driver 621.24; CPU-only checks, no game files, no GPU/llvm-mc/MSVC used): pass.

Ran the test files this PR adds or changes, from a clean checkout of the PR head: test_check_apt_key.py - all exit 0.

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants