Skip to content

bug: make base_cli_declare transactional when a late row is invalid #347

Description

@codeforester

Related roadmap: #214

Problem

base_cli_declare says it parses every row before mutating the model, but the first pass validates only row structure and required columns. It calls base_cli_model_init before applying commands, options, and positionals. A semantic error in a later row therefore destroys a previously valid model and publishes a partially built replacement.

This makes generated/declarative CLI reloads non-atomic and leaves callers with state that does not match either the old or requested declaration.

Evidence

Reviewed on main at 63753047312cd5c189600ed71597faceae0f5d8e.

Focused reproduction:

  1. Initialize a model named demo with name original and an old command.
  2. Call base_cli_declare demo with a new model row, a new command, and a late option row using an invalid type.
  3. The call returns status 2.

Actual state after failure: the model name is the replacement value, the old command is gone, and the new command is present.

The mutation begins at lib/bash/cli/lib_cli.sh:465; late semantic validation occurs while rows are applied at lines 466-504.

Acceptance criteria

  • A failed base_cli_declare leaves every registry entry for an existing model byte-for-byte unchanged.
  • A failed declaration for a new model leaves no partial model behind.
  • Validate the complete table in staging state, or snapshot and reliably roll back before publishing.
  • Cover late failures from command, option, positional, alias, enum, boolean, validator-name, and model-validation rules.
  • Preserve the documented order-independent command-row behavior and Bash 4.2 support.
  • Add tests that assert both absence of partial new state and preservation of a prior valid model.

Metadata

Metadata

Assignees

Labels

bugSomething is not working

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions