Option C Tools
Loading...
Searching...
No Matches
test_command_flags_introspection Namespace Reference

Functions

list[str] _click_option_names (click.Command cmd)
list[tuple[str, click.Command]] _walk_commands (click.Group group, str prefix="")
str _rendered_for (str qname)
 test_every_click_option_appears_in_command_flags ()
 test_every_group_subcommand_appears_in_group_flags ()
 test_command_flags_entries_only_reference_known_commands ()

Variables

dict _ARGPARSE_ROUTED = {"lint", "format", "typecheck"}
dict _ROLLED_INTO_PARENT

Detailed Description

Purpose
-------
OI-523 drift-prevention regression — :data:`oct.cli._COMMAND_FLAGS` is a
hand-maintained table of ``(flag, description)`` rows rendered by
:meth:`OctGroup.format_help`. It is easy for a contributor to add a new
``@click.option`` on a command and forget to append the matching row to
``_COMMAND_FLAGS``, leaving ``oct --help`` silently out of date.

This test walks every non-hidden Click command / subcommand in the ``oct``
CLI and asserts that each declared :class:`click.Option` appears
somewhere in the command's ``_COMMAND_FLAGS`` entry. Running this test in
CI turns a silent doc drift into a loud unit-test failure.

Responsibilities
----------------
- Every top-level Click option on every ``oct`` subcommand is mentioned
  in the ``_COMMAND_FLAGS`` rows.
- Every Click group (``git``, ``diag``) exposes its subcommands in the
  group's ``_COMMAND_FLAGS`` rows.
- Argparse-routed commands (``lint``, ``format``, ``typecheck``) are
  skipped because their flags live in ``argparse``, not Click.

Diagnostics
-----------
Domain: CLI-TESTS
Levels:
    L2 — test lifecycle
    L3 — assertion details
    L4 — deep tracing

Contracts
---------
- Tests introspect the Click command tree in-process; no subprocess or
  filesystem writes.
- Argparse-routed commands are excluded from the check.

Function Documentation

◆ _click_option_names()

list[str] test_command_flags_introspection._click_option_names ( click.Command cmd)
protected
Return the canonical long-option name for each :class:`Option`.

Definition at line 58 of file test_command_flags_introspection.py.

Here is the caller graph for this function:

◆ _rendered_for()

str test_command_flags_introspection._rendered_for ( str qname)
protected
Join the flag rows for ``qname``, falling back to the parent group.

``_COMMAND_FLAGS`` keys subgroup subcommands under two conventions:
``git`` and ``diag`` either get per-subcommand keys (``git status``)
or roll the subcommands into the parent key (``diag``). Either
convention satisfies the drift guard.

Definition at line 89 of file test_command_flags_introspection.py.

Here is the caller graph for this function:

◆ _walk_commands()

list[tuple[str, click.Command]] test_command_flags_introspection._walk_commands ( click.Group group,
str prefix = "" )
protected
Yield ``(qualified_name, command)`` for every non-hidden command.

Definition at line 72 of file test_command_flags_introspection.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_command_flags_entries_only_reference_known_commands()

test_command_flags_introspection.test_command_flags_entries_only_reference_known_commands ( )

Definition at line 167 of file test_command_flags_introspection.py.

◆ test_every_click_option_appears_in_command_flags()

test_command_flags_introspection.test_every_click_option_appears_in_command_flags ( )

Definition at line 117 of file test_command_flags_introspection.py.

Here is the call graph for this function:

◆ test_every_group_subcommand_appears_in_group_flags()

test_command_flags_introspection.test_every_group_subcommand_appears_in_group_flags ( )

Definition at line 140 of file test_command_flags_introspection.py.

Variable Documentation

◆ _ARGPARSE_ROUTED

dict test_command_flags_introspection._ARGPARSE_ROUTED = {"lint", "format", "typecheck"}
protected

Definition at line 55 of file test_command_flags_introspection.py.

◆ _ROLLED_INTO_PARENT

dict test_command_flags_introspection._ROLLED_INTO_PARENT
protected
Initial value:
1= {
2 "diag validate-config",
3 "diag list-domains",
4 "diag set-level",
5 "diag migrate-config",
6 "diag restore",
7}

Definition at line 108 of file test_command_flags_introspection.py.