Skip to content

fix(fake-scenarios): preserve endsWithPrompt through flattenScenario - #362

Open
dormouse-bot wants to merge 1 commit into
mainfrom
fix/fake-scenarios-endswithprompt
Open

fix(fake-scenarios): preserve endsWithPrompt through flattenScenario#362
dormouse-bot wants to merge 1 commit into
mainfrom
fix/fake-scenarios-endswithprompt

Conversation

@dormouse-bot

Copy link
Copy Markdown
Collaborator

Problem

flattenScenario (lib/src/lib/platform/fake-scenarios.ts) collapses a FakeScenario into a single instant chunk for Chromatic/regression stories. It explicitly copies name, chunks, and exitCode — but silently omits the endsWithPrompt flag. A flattened prompt-ending scenario therefore reports FakePtyAdapter.scenarioEndsWithPrompt() === false.

This is latent today: flattenScenario is only consumed by Storybook stories, which never read endsWithPrompt, and the website playground registers non-flattened scenarios (with the flag intact). But it is a genuine fidelity gap — exitCode is deliberately preserved through the flatten, so dropping the sibling semantic field endsWithPrompt is an oversight that would surface as a duplicate-prompt bug the moment a flattened scenario is registered in the playground shell registry.

Separately, SCENARIO_FAST_OUTPUT ends with a shell prompt (instant(PROMPT, 200)) just like SCENARIO_SHELL_PROMPT, SCENARIO_LS_OUTPUT, SCENARIO_ANSI_COLORS, and SCENARIO_LONG_RUNNING, but was the only one of them not declaring endsWithPrompt: true.

Solution

  • flattenScenario now carries endsWithPrompt through, alongside exitCode.
  • Add the missing endsWithPrompt: true to SCENARIO_FAST_OUTPUT.

Testing

Added two cases to fake-scenarios.test.ts alongside the existing exitCode tests: one asserting flattenScenario preserves endsWithPrompt: true, one asserting it stays undefined when the source scenario has no prompt. The first would have failed before this change (the flattened scenario returned endsWithPrompt === undefined). Full fake-scenarios.test.ts suite passes (15 tests).

Surfaced by the nightly code-quality survey.

flattenScenario copied name/chunks/exitCode but silently dropped the
endsWithPrompt flag, so a flattened prompt-ending scenario reported
scenarioEndsWithPrompt() === false. This is latent today (flattenScenario
is only consumed by Storybook stories, which don't read the flag; the
playground uses non-flattened scenarios), but it is a genuine fidelity
gap given exitCode is deliberately preserved.

Also add the missing endsWithPrompt: true to SCENARIO_FAST_OUTPUT, which
ends with a prompt like its siblings but did not declare it.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying mouseterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: b89c619
Status: ✅  Deploy successful!
Preview URL: https://161ba952.mouseterm.pages.dev
Branch Preview URL: https://fix-fake-scenarios-endswithp.mouseterm.pages.dev

View logs

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