Skip to content

readline: do not read history options from the input stream - #67665

Open
yohannesjoya wants to merge 1 commit into
nodejs:mainfrom
yohannesjoya:readline-stream-history-options
Open

yohannesjoya wants to merge 1 commit into
nodejs:mainfrom
yohannesjoya:readline-stream-history-options

Conversation

@yohannesjoya

Copy link
Copy Markdown
Contributor

When readline.createInterface() is given a stream rather than an options object, the stream itself is passed to setupHistoryManager() as the REPL history options. A stream with an onHistoryFileLoaded property, such as a mocked stream, starts REPL history loading before this.input is set and throws Cannot read properties of undefined (reading 'pause'), and a stream with a history or size property is validated as history options. Both work on v22 and fail since v24.2.0; reproduced on main.

This passes empty history options when only a stream is given, which matches the behaviour before v24.2.0. History passed in an options object is unchanged, and the REPL sets its history separately through setupHistory(). @thisalihassan noted on #61538 that the root cause is readline passing the input to the REPL history setup; this addresses that directly. The new test fails on main with the TypeError from the issue and passes with this change; the readline and REPL tests pass locally.

Fixes: #61526
Refs: #61538

AI disclosure: I used a coding agent to help find the issue and draft the test. I reproduced the crash on v25 and main, reviewed the change line by line, and ran the readline and REPL tests locally.

When createInterface() is given a stream instead of an options object,
the stream itself was passed to setupHistoryManager() as the history
options. A stream with an onHistoryFileLoaded property, such as a mock,
started REPL history loading before this.input was set and threw
"Cannot read properties of undefined (reading 'pause')". Properties
named history or size on the stream were validated as history options
too.

Pass empty history options in that case, as before v24.2.0. History
given in an options object is unchanged.

Fixes: nodejs#61526
Refs: nodejs#61538
Signed-off-by: Yohannes Desta <yohannesdestagebru10@gmail.com>
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. readline Issues and PRs related to the built-in readline module. labels Nov 20, 2026
@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.59%. Comparing base (c99ebf2) to head (c489acf).
⚠️ Report is 287 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67665      +/-   ##
==========================================
- Coverage   92.99%   90.59%   -2.41%     
==========================================
  Files         428      801     +373     
  Lines      195633   280968   +85335     
  Branches    30281    54234   +23953     
==========================================
+ Hits       181937   254537   +72600     
- Misses      13369    16621    +3252     
- Partials      327     9810    +9483     
Files with missing lines Coverage Δ
lib/internal/readline/interface.js 93.26% <100.00%> (+<0.01%) ⬆️

... and 577 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. readline Issues and PRs related to the built-in readline module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

readline Regression since v24.2.0 Cannot read properties of undefined (reading 'pause')

2 participants