Skip to content

refactor: make the source and tests consistent - #80

Merged
edornd merged 2 commits into
v2from
79-coherence-pass
Oct 31, 2026
Merged

edornd merged 2 commits into
v2from
79-coherence-pass

Conversation

@edornd

@edornd edornd commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Summary

This PR is stacked on #78 and is a cleanup only. CLI output, exit codes and the public API stay the same.

 errors.py
-EXIT_OK, EXIT_FAILED, EXIT_REJECTED
+class ExitCode(IntEnum)
-rejected_input(model, leftovers, flags, error)
+InputRejected.from_parse(model, leftovers, flags, error)
-InputRejected.report = ErrorReport(...)   # set in __init__
+InputRejected.report                     # property, like CommandError.report

 app.py
-class Command(BaseSettings)
+class InputModel(BaseSettings)
-set_defaults(_command_spec=..., _cli_source=..., _leaf_parser=...)
+set_defaults(_leaf=_Leaf(spec, source, flags))   # flags computed once, at build time

Every comment in src/ is now one line that says why.

 tests/
+├── conftest.py              # run, run_raising, notes_app fixtures
+├── test_command.py          # registration, flags, help, result output
+├── test_rejected_input.py   # validation, unknown flags, stray tokens, malformed JSON, secrets
+├── test_command_errors.py   # CommandError, UNKNOWN, ARGD_DEBUG
+├── test_string_errors.py    # the private bench switch
-├── test_flat_command.py
-├── test_errors.py
 └── test_package.py

The example apps are now a generic notes and calc CLI instead of a Slurm training tool.

Evidence

  • Before: 60 passed, 33 test functions.
    After: 61 passed, 34 test functions. The new one checks that registering a functools.partial raises TypeError. The safety-hints test now checks the hints stored on the spec.
  • The old test suite passes on the refactor commit alone, before the tests move.
  • ruff, ruff format and ty pass.

Merge Danger

Door: two-way

Only internal names change. App and CommandError keep their signatures.

Blast Radius: none

Nothing outside argdantic imports Command, rejected_input or the EXIT_* constants.

Closes #79

@edornd
edornd added this pull request to stack #81 October 31, 2026 19:48
Base automatically changed from 66-structured-errors to v2 October 31, 2026 19:48
Rename the internal input model base to InputModel, so "command" only
means the registered function. Replace the exit code constants with an
ExitCode enum. InputRejected and CommandError both expose report as a
property, and InputRejected.from_parse replaces the rejected_input
function. Each subparser stores one leaf record with the spec, the CLI
source and the valid flags, computed when the parser is built.

Cut each comment to one line that says why, and drop the module
docstrings.

Refs #79
conftest.py holds the run fixture and the shared notes app. The tests
split into commands, rejected input, command errors and string errors.
The example apps are now a generic notes and calc CLI. New tests cover
registering a nameless callable and storing safety hints.

Closes #79
@edornd
edornd force-pushed the 79-coherence-pass branch from 312e112 to b6804ab Compare October 31, 2026 19:48
@edornd
edornd merged commit 79aa16d into v2 Oct 31, 2026
5 checks passed
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