Skip to content

fix(cli): support non-interactive help and gated hardware test#434

Open
melxusgid wants to merge 2 commits into
RfidResearchGroup:mainfrom
melxusgid:fix/cli-nontty-and-hardware-tests
Open

fix(cli): support non-interactive help and gated hardware test#434
melxusgid wants to merge 2 commits into
RfidResearchGroup:mainfrom
melxusgid:fix/cli-nontty-and-hardware-tests

Conversation

@melxusgid

Copy link
Copy Markdown

Summary

This PR makes two small CLI/test hygiene improvements:

  • Adds a real argparse entrypoint for chameleon_cli_main.py, so --help works without starting the interactive prompt_toolkit prompt.
  • Makes the hardnested hardware acquisition test opt-in via CHAMELEON_PORT instead of hardcoding com19 and /dev/ttyACM0.

It also adds a small one-shot command mode:

python script/chameleon_cli_main.py --command "rem hello"

Why

Before this change, running CLI help from a non-interactive environment could enter the interactive prompt path instead of printing help cleanly. This is inconvenient for scripts, CI, and automation.

The hardnested acquisition test also failed on machines where the device is not available at com19 or /dev/ttyACM0. On macOS, for example, Chameleon Ultra commonly appears as a /dev/cu.usbmodem... device.

With this change, hardware tests only run when a port is explicitly provided:

CHAMELEON_PORT=/dev/cu.usbmodem0000000000001 pytest script/tests/test_hard_acquire.py

If CHAMELEON_PORT is not set, the test is skipped instead of failing due to a missing hardcoded port.

Test plan

Ran from software/ against a plugged-in Chameleon Ultra on macOS:

test_help_exits_without_starting_interactive_prompt        PASSED
test_non_interactive_without_command_fails_cleanly         PASSED
test_hardnested_acquire                                    FAILED (expected — no HF tag placed on reader)
test_crypto1::test_key_getter_setter                       PASSED
test_crypto1::test_mfkey32_is_reader_has_key_false         PASSED
test_crypto1::test_mfkey32_is_reader_has_key_true          PASSED
test_crypto1::test_prng_next                               PASSED
test_crypto1::test_reader_three_pass_auth                  PASSED
test_crypto1::test_tag_three_pass_auth                     PASSED

8 passed, 1 failed

The hardware test failure is expected — HF tag no found or lost means the device connected and tried to scan, but no Mifare Classic tag was physically present on the reader.

Also verified manually:

PYTHONPATH=script python script/chameleon_cli_main.py --help
PYTHONPATH=script python script/chameleon_cli_main.py --command "rem hello from automation"
PYTHONPATH=script python script/chameleon_cli_main.py </dev/null

Expected behavior:

  • --help prints usage and exits 0.
  • --command executes a one-shot CLI command and exits 0.
  • no args in a non-interactive terminal exits with a clear argparse error instead of entering prompt_toolkit.

Notes

This PR intentionally avoids changing RFID behavior. It only improves automation ergonomics and test portability.

@github-actions

Copy link
Copy Markdown

You are welcome to add an entry to the CHANGELOG.md as well

@github-actions

github-actions Bot commented May 26, 2026

Copy link
Copy Markdown

Built artifacts for commit e6f06c9

Firmware

Client

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.

1 participant