Skip to content

Block step 1 Continue without a valid MIDI device - #12

Merged
yottanami merged 1 commit into
mainfrom
agent/163-step1-midi-gate
Aug 19, 2026
Merged

yottanami merged 1 commit into
mainfrom
agent/163-step1-midi-gate

Conversation

@yottanami

Copy link
Copy Markdown
Owner

Closes Men-in-Black-5/ideas#163.

Bug

setupStep1NextButton was wired through the generic menuButtonTargets map exactly like every other nav button — it called showScreen('setupStep2Screen') unconditionally. isValidMidiInput(midi?.options) already existed and was used correctly, but only inside startGame() (step 3) — so a player could click through all 3 steps with no keyboard connected and only find out on the final Start Game button, several steps removed from where they'd actually go plug something in.

Fix

  • Pulled setupStep1NextButton out of the generic menuButtonTargets loop into its own click handler that checks isValidMidiInput(midi?.options) before calling showScreen('setupStep2Screen').
  • On failure, shows an inline message via a new showStep1Error()/#setupStep1Error pair — same pattern as showSetupError/#setupError, added because #setupError lives inside #setupStep3Screen's DOM and isn't present (or visible) on step 1.
  • Extracted the message text into a shared NO_MIDI_SELECTED_MESSAGE constant, used by both step 1's new gate and startGame()'s existing check, so the two can't drift apart. startGame()'s own check is untouched — this is a second, earlier gate, not a replacement.

Testing

  • npx tsc --noEmit — clean.
  • npx vitest run — 172 passed (15 files), including a new showStep1Error test mirroring the existing showSetupError one.
  • npm run build — clean, dist/app.js included.
  • Manually exercised in headless Chromium (nix chromium + puppeteer-core) against a local static server:
    • Clicked Continue on step 1 with no MIDI device selected (the "No MIDI keyboard found" placeholder): stayed on step 1, showed the exact expected message, did not advance.
    • Injected a fake real MIDI <option> and selected it, clicked Continue again: advanced to step 2 normally, and the step 1 error was cleared.
    • Screenshot of the blocked state confirms it renders cleanly alongside the pre-existing "MIDI access was blocked" browser-support notice, no layout overlap.

setupStep1NextButton was wired through the generic menuButtonTargets
map exactly like every other nav button, advancing unconditionally.
isValidMidiInput() already existed and was used correctly in
startGame() (step 3) -- so a player could click through all 3 steps
with no keyboard connected and only find out several steps removed
from where they'd actually go plug one in.

Pulls setupStep1NextButton out of the generic map into its own
handler that checks isValidMidiInput() first. On failure it shows an
inline message via a new showStep1Error()/#setupStep1Error pair
(same pattern as showSetupError/#setupError, which lives inside
#setupStep3Screen's DOM and isn't present on step 1). The message
text is now a shared NO_MIDI_SELECTED_MESSAGE constant so step 1's
gate and startGame()'s own check can't drift apart. startGame()'s
check is untouched -- this is a second, earlier gate, not a
replacement.

Closes Men-in-Black-5/ideas#163
@yottanami

Copy link
Copy Markdown
Owner Author

reviewer: approved. Confirmed midi in the new step 1 handler resolves the same #midiSelect element via the same .options access pattern startGame() already uses, so isValidMidiInput behaves identically at both call sites. Extracting NO_MIDI_SELECTED_MESSAGE only deduplicates the string -- startGame()'s condition/control-flow is byte-for-byte unchanged, so this is genuinely a second earlier gate, not a replacement, matching the acceptance criterion. showStep1Error mirrors showSetupError's toggle pattern exactly, correctly solving the "no #setupError on step 1" DOM-scoping problem called out in the issue. Real click-through verification in headless Chromium plus the new unit test for showStep1Error in isolation is adequate coverage for the new wiring, consistent with how #11's wizard-navigation plumbing was verified. CI green. Merging (squash).

@yottanami
yottanami merged commit 7d22930 into main Aug 19, 2026
3 checks passed
@yottanami
yottanami deleted the agent/163-step1-midi-gate branch August 19, 2026 08:42
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