F22.5 — CLI invocation state with a clear lifetime
| State | Closed |
| Parent | E22 |
| Iteration | Release 9 |
| Start Date | 2026-11-14 |
| Closed Date | 2026-11-16 |
| Predecessors | F22.3 |
Stories: 2 Closed
| Story | State | Depends on |
|---|---|---|
| S22.5.1 — Specify and restore console lifetime | Closed (2026-11-14) | — |
| S22.5.2 — Keep one option and error path | Closed (2026-11-15) | S22.3.2 |
Keep the small CLI layer, and make repeated invocation predictable.
Context
options.py:125-142 sets the process console mode for JSON/quiet but does not
reset it for a plain invocation. Same-process command tests and embedded CLIs
can inherit the previous mode. app.py:162-168 also calls idempotent logger
initialization, which can ignore later invocation log-level/file options. An
autouse fixture manually resets globals and hides that lifecycle. The package
has only four source modules and 574 lines; a new command framework would add
complexity.
S22.5.1 — Specify and restore console lifetime
State: Closed (2026-11-14)
Add consecutive same-process invocation cases. Set the effective mode for every root invocation and restore prior process state at the appropriate invocation boundary, including exceptions. Keep subcommand inheritance.
Acceptance:
- JSON → plain, quiet → plain, failed → plain and nested root/subcommand invocations produce the expected output and exit codes.
- Conflicting quiet/JSON options fail without leaking state into the next invocation; INFO → DEBUG and two successive log-file paths honor each invocation.
- CommonOptions remains a value contract; console mode is still owned by commons.
rn_forge.cli.app.runrestores the console mode it found on entry, in afinallyafter the error report, so nested calls unwind last-in-first-out. A root invocation reconfigures logging only when--log-levelor--log-fileis passed explicitly; logging is not restored on exit.
Outcome: JSON or quiet mode no longer leaks into the next same-process invocation, and explicit log options take effect on every invocation.
S22.5.2 — Keep one option and error path
State: Closed (2026-11-15) · Depends on: S22.3.2
Review CliApp and declarative surfaces for repeated option application and exception translation. Consolidate only where two paths promise identical behavior.
Acceptance:
- Generated and hand-registered commands exercise the same inherited-option/error matrix.
- Help output, standard options, declared surface and exception exit codes remain covered; scalar/list surface tables report key-specific configuration errors.
- Cold invocation measurements justify any import deferral; no blanket file split.
Settled contract: CliSurface.load rejects a commands value that is not an
array of tables ([cli] commands must be an array of tables, not str) and a
non-table entry by index ([cli] commands[1] must be a table, not int); unknown
[cli] keys stay tolerated; no import is deferred.
Outcome: tests/test_command_paths.py pins one exit-code, option and
failure-output path for hand-registered and declared commands; rn_forge.cli
imports in about 105 ms cumulative, none of it deferrable.
Acceptance
- S22.5.1: JSON → plain, quiet → plain, failed → plain and nested root/subcommand invocations produce the expected output and exit codes.
- S22.5.2: Generated and hand-registered commands exercise the same inherited-option/error matrix.