Skip to content

fix(prompt): execute on Enter, validate required fields, show field help (issue #31) - #33

Merged
tyrsson merged 2 commits into
1.0.xfrom
feat/31-prompt-submit-validation
Sep 26, 2026
Merged

tyrsson merged 2 commits into
1.0.xfrom
feat/31-prompt-submit-validation

Conversation

@tyrsson

@tyrsson tyrsson commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

What

Fixes the three defects that stop a wrapped command being driven to completion from the menu. 10 files, +406/−53.

The three findings

Defect Fix
F1 PromptKeyAction::enter() only submitted when the active field was the last one, because Enter doubled as "next field". dev:mode declares enable, disable, status in that order — Space on disable then Enter advanced to status and ran nothing. This is the reported failure. Enter executes from any field. Tab/Down/Up remain the only navigation; the active index already wraps, so nothing becomes unreachable.
F2 A blank required argument was passed as '', which Symfony accepts as a supplied value, so the command ran and failed deep inside instead of the form naming what was missing. Submission is refused while any required field is blank: the blank fields are named, focus moves to the first of them, and everything already entered is left intact.
F3 The description was handed to TextInput::placeholder(), which draws only when the field is empty — so it vanished exactly where it was needed, since a declared default pre-fills the field. Flag fields showed no description at all, because render() returned before reaching the widget. The description renders on the row between the last field and the key hints, which was already free. A refusal report takes precedence there.

F1 also affects generate-template-map, servicemanager:generate-deps-for-config-factory and every mezzio-tooling command with more than one field; F2 affects every command with a required argument.

The asterisk, and what "required" means

Required fields are marked *, read from the command's own definition. Only an argument can carry requiredness — InputOption has no required concept — so a command needing a mandatory value must declare it as a required argument. user:init-db declares its four mandatory values as optional options and asks for them in execute(), so the console cannot see them; that fix lands separately in webware-usermanager.

Also in this PR

  • PromptState::$refused + missingIndexes(); the report is computed from the current values, so it shrinks as fields are filled in instead of showing a stale Required: configFile after that field is filled.
  • render()'s field-kind branch is now a match expression over FieldKind rather than an if/continue, per the stated match-over-if convention.
  • infection.json5.dist: ignores re-keyed to the shifted line numbers (render::83 → 86, confirm::158/165/172 → 196/203/210). No new ignores, no mutator disabled.
  • docs/v1/command-input.md documents the key contract, the marker and the requiredness rule; linked from the README.

Also fixed here — dev:mode left the config cache in place (issue #34)

disable and enable returned early when the requested state was already in
force, before reaching clearConfigCache(), so a stale cache outlived the toggle
meant to end it. That matters more than it looks: ConfigAggregator serves an
existing cache without consulting a single provider, so a cache disagreeing with
config/development.config.php is authoritative and nothing else can correct it.

The cache is now dropped on every enable and disable, including the
already-in-state branches. execute() became a single match over the three
flags, and the dist copy moved into copyDistFile(), which reports its own
failure — that also brought the class back under the kan-defect threshold with
no suppression.

Gates

Gate Result
mago fmt --check clean
mago lint no issues
mago analyze no issues
mago guard no issues
PHPUnit unit 131 tests, 251 assertions
PHPUnit integration 2 tests, 6 assertions
Line coverage 100% (489/489 statements, 57/57 methods)
Infection MSI 100%, 0 escaped (343 mutants)

Two notes on verification:

  • The first full mutation run reported 13 timeouts in MenuCommand.php and one escaped mutant. The escape was real — I had dropped the up keystroke from the scripted loop test, leaving PromptKeyAction::Up unasserted; a dedicated testOnKeyUpMovesBack (3 fields at index 1, where ++ and -- cannot both wrap to the same value) kills it. The timeouts did not reproduce on a re-run, and MenuCommand.php alone scores 47/47 killed — they were cold-start contention, not a real gap.
  • PromptKeyAction::enter()'s two-way guard stays an if/early-return. A match over a boolean obscures the intent rather than clarifying it; the convention is applied where there is a discrete set of cases.

Docs

Artifacts for this work are in #32 (FR-009–FR-012, SC-006/SC-007, Phase 8 tasks T029–T043).

Closes #31
Closes #34

Fixes the three defects in issue #31 that stop a wrapped command being
driven to completion from the menu.

Enter is positional (F1) — `PromptKeyAction::enter()` only submitted when
the active field happened to be the last one, because Enter doubled as
"next field". `dev:mode` declares `enable`, `disable`, `status` in that
order, so Space on `disable` followed by Enter advanced to `status` and ran
nothing. Enter now executes from any field; Tab/Down/Up remain the only
navigation, and the active index already wraps so nothing becomes
unreachable.

Required input is not validated (F2) — a blank required argument was passed
as `''`, which Symfony accepts as a supplied value, so the command ran and
failed deep inside instead of the form naming what was missing. Submission
is now refused while any required field is blank: the blank fields are
named, focus moves to the first of them, and everything already entered is
left intact.

Help text disappears behind defaults (F3) — the description was handed to
`TextInput::placeholder()`, which draws only when the field is empty, so it
vanished exactly where it was needed: a declared default pre-fills the
field. Flag fields showed no description at all, since `render()` returned
before reaching the widget. The description now renders on the row between
the last field and the key hints, which was already free, and a refusal
report takes precedence there. Blank optional fields are still omitted so
the command's own default applies.

Required fields are marked with `*`, and requiredness is read from the
command's own definition. Only an argument can carry it — `InputOption` has
no required concept — so a command needing a mandatory value has to declare
it as a required argument; `user:init-db` is being fixed accordingly in
webware-usermanager.

Also:
- `PromptState::$refused` plus `missingIndexes()`; the report is computed
  from the current values so it shrinks as fields are filled in rather than
  going stale.
- render()'s field-kind branch is a match expression over FieldKind instead
  of an if/continue, per the stated `match`-over-`if` convention.
- infection.json5.dist ignores re-keyed to the shifted line numbers
  (render::83 -> 86, confirm::158/165/172 -> 196/203/210). No new ignores,
  and no mutator was disabled.
- docs/v1/command-input.md documents the key contract, the marker and the
  requiredness rule.

Gates: mago format/lint/analyze/guard clean; 131 unit + 2 integration
tests; 100% line coverage (487/487); MSI 100%, 0 escaped.
@codecov

codecov Bot commented Sep 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

The already-disabled and already-enabled branches returned before
clearing the cache, so a cache outlived the toggle meant to end it.
The aggregator serves an existing cache without consulting a single
provider, so nothing else could correct it.

Signed-off-by: Joey Smith <jsmith@webinertia.net>
@tyrsson
tyrsson merged commit 45dd90a into 1.0.x Sep 26, 2026
12 checks passed
@tyrsson
tyrsson deleted the feat/31-prompt-submit-validation branch September 26, 2026 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant