Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test rails console with reline #48369

Merged
merged 2 commits into from
Jun 1, 2023

Conversation

st0012
Copy link
Contributor

@st0012 st0012 commented Jun 1, 2023

Motivation / Background

Rails has been testing Rails console with readline for a while. And recently due to the removal of readline from default gems, it even needs to install readline-ext separately (#48183).

However, given reline has become IRB's default for a while and now receives frequent updates from a group of maintainers (myself included), I think it's worth running those tests without readline instead.

Detail

In addition to removing the readline-ext gem, this PR also has 2 changes:

  1. By removing the --singleline flag, IRB will use Reline by default.
  2. By assigning TERM=dumb, which is a convention in terminal programs to indicate reduced/minimum feature set, Reline will skip east-asian width detection, which was what caused the test to hang.

I need to stress that the east-asian width detection is not a bug but an
improvement in Reline to help rendering east-asian characters correctly.
Readline actually can't do this well. Please see @tompng's great explanation
in ruby/irb#582 (comment)

However, this detection should not happen when the terminal is running in
PTY (usually used in test environment). The problem is that in Ruby we
don't have a way to detect if the terminal is running in TTY or PTY.

But by passing TERM=dumb, Reline will assume that the terminal is not
capable of several advanced features, including this east-asian width
detection.

Additional information

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@rails-bot rails-bot bot added the railties label Jun 1, 2023
@st0012
Copy link
Contributor Author

st0012 commented Jun 1, 2023

I just noticed that I accidentally dropped the --singleline change. Will update it soon. Done.

1. By removing the `--singleline` flag, IRB will use Reline by default.
2. By assigning `TERM=dumb`, Reline will skip east-asian width detection,
   which was what caused the test to hang.

I need to stress that the east-asian width detection is not a bug but an
improvement in Reline to help rendering east-asian characters correctly.
Readline actually can't do this well. Please see @tompng's great explanation
in ruby/irb#582 (comment)

However, this detection should not happen when the terminal is running in
PTY (usually used in test environment). The problem is that in Ruby we
don't have a way to detect if the terminal is running in TTY or PTY.

But by passing `TERM=dumb`, Reline will assume that the terminal is not
capable of several advanced features, including this east-asian width
detection.
@st0012 st0012 force-pushed the test-rails-console-with-reline branch from 9c1ba7a to cf45394 Compare June 1, 2023 17:54
@eileencodes eileencodes merged commit 866df97 into rails:main Jun 1, 2023
@eileencodes eileencodes deleted the test-rails-console-with-reline branch June 1, 2023 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants