fix(prompt): preserve buffered input between prompts#118
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
WalkthroughThe readLine input handling in src/lib/prompt.ts is refactored to buffer unread stream data in a WeakMap keyed by stream, allowing sequential prompts sharing a stream to reuse previously read input. Listener cleanup is made conditional, and tests were added covering buffered reuse for promptText and promptSecret. ChangesSequential prompt input buffering
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant readLine
participant pendingPromptInput
participant Stream
Caller->>readLine: prompt for answer
readLine->>pendingPromptInput: check pending text for stream
alt pending text exists
readLine->>readLine: process pending text, isInputEnded check
readLine->>Caller: finish() with buffered answer
else no pending text
readLine->>Stream: attach data/end/error listeners
Stream->>readLine: emit data chunk
readLine->>readLine: processText loop, detect newline
readLine->>pendingPromptInput: save remainder after newline
readLine->>Caller: finish() with answer
readLine->>Stream: cleanup() detaches listeners
end
Related Issues: None referenced in the provided changes. Related PRs: None referenced in the provided changes. Suggested labels: bug, enhancement Suggested reviewers: None determinable from the provided changes. 🐰 A prompt once lost its trailing bytes, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
zeshi-du
left a comment
There was a problem hiding this comment.
Reviewed and verified — merging. Thanks for the contribution!
Summary
Fixes prompt input handling so answers already buffered after the first newline are preserved for later prompts on the same input stream.
Why
When input arrives as one buffered chunk, such as
first\nsecond\n, the prompt reader returnedfirstand discarded the remaining text. A second prompt on the same stream would then wait for input that had already been read.Changes
Testing
npx vitest run src/lib/prompt.test.ts --reporter=dotnpm run typechecknpm run buildSummary by CodeRabbit