01 / Reproduce
Try one token against three parsers
Download the practice ZIP, extract it and open PowerShell in the extracted folder. Use Python 3.13 to reproduce the recorded run. The exercise works offline once extracted, with no packages to install or account to configure.
python .\compare_flags.py
Look at the first three rows in the JSON output. Each parser receives the identical argument list, ["--pub"].
- Original, default abbreviation behavior. With only
--publishavailable,--pubselects the simulated publish mode. Exit 0. - Expanded, default abbreviation behavior. Add
--public-previewand both long options match. The parser reports an ambiguous option. Exit 2. - Expanded, full spelling required. With
allow_abbrev=False, the parser reports an unrecognized argument. Exit 2.
The matrix calls the parser on explicit argument lists and records its selected mode or exit and error text. The kit includes the observed JSON for comparison. Try the strict CLI directly to see where the parse gates the simulated action.
python .\report_tool.py --publish
python .\report_tool.py --pub
$LASTEXITCODE
python .\report_tool.py --public-preview
python .\report_tool.py
Expect simulated mode: publish, usage with exit code 2, simulated mode: public-preview, then simulated mode: draft. Read $LASTEXITCODE immediately after the rejected command so it refers to that invocation.
02 / Understand
Set the rule where arguments enter
Here is the smallest version of the rule. Save it as full_flag.py, then run python .\full_flag.py --publish and python .\full_flag.py --pub. The first command prints True. The second exits with an unrecognized-argument error before it can print anything.
import argparse
parser = argparse.ArgumentParser(allow_abbrev=False)
parser.add_argument("--publish", action="store_true")
args = parser.parse_args()
print(args.publish)
By default, a unique prefix can stand in for a long option. allow_abbrev=False turns off that matching. In the full lab, parse_args() rejects unknown tokens and the mutually exclusive group also rejects a request containing both action flags. Those rules cover two different inputs. See Python’s abbreviation setting and mutually exclusive groups.
03 / Inspect the edges
Keep the cases that matter to the operator
The complete lab checks that both full spellings work and that an empty argument list stays in draft mode. It also checks a typo, both action flags together, an unexpected value (--publish=yes), and a trailing token (notes.txt). Each of those four inputs exits with a parser error.
Test the exact spelling and the unwanted spelling together. A check for the valid command alone would pass with either configuration. A check for rejection alone could also pass if the valid flag were accidentally removed.
04 / Make it your own
Give the command a testable contract
- Pick a CLI you maintain and start with an offline fixture. Write down its full flags, any explicit aliases, and the behavior when no action flag is supplied.
- Choose a real prefix or typo you want rejected. Add it to your test alongside the full flag and verify that a parse failure stops before the action handler. If you add a new option later, keep those cases.
- Before tightening an existing tool, check scripts and scheduled jobs for abbreviations they rely on. Update those callers or explicitly register an alias you intend to keep.
- For an AI-assisted workflow, show the operator the exact proposed arguments. Check the requested action and permissions before any write or send. The practice README includes an optional prompt for reviewing proposed arguments without running the command.
If you only use the tool, compare the suggested flag with the current --help output and confirm the action before running it. For unfamiliar tools, try the proposal against disposable data first.
Boundaries
A valid flag can still request the wrong action
This exercise covers long-option spelling in this argparse parser. The full --publish flag remains valid, so spelling checks cannot establish operator intent or authorize an action. Real tools need separate permission checks and side-effect controls. The supplied code prints a simulated mode and never publishes a report.
We did not test a real agent, production CLI, shell-quoting or injection behavior, or the optional review prompt. The tested outcomes describe the ten supplied cases on the stated Python runtime.
Primary sources / Checked November 7, 2026
Read the parser contract
Downloads / Practice files

