Skip to content

Prompt generally signals that the shell is ready #1900

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

jablko
Copy link
Contributor

@jablko jablko commented Mar 2, 2020

What do you think of this (hopefully) simplified tmux.prepare? (relying on the prompt to signal that the shell is ready)

@junegunn
Copy link
Owner

junegunn commented Mar 2, 2020

I don't think repeating tmux.until { |lines| lines[-1] == '$' } instead of tmux.prepare is an improvement. We can change the implementation of tmux.prepare method to rely on $ prompt (which is probably a more robust way to check) but removing the layer of abstraction is not something we should do.

And it looks like you did a bunch of additional refactorings here, which is nice, but it's a different concern, so it should be in a separate commit (or in a separate pull request).

@jablko jablko force-pushed the patch-9 branch 5 times, most recently from cbc277d to dcefbb0 Compare March 2, 2020 19:33
@jablko
Copy link
Contributor Author

jablko commented Mar 2, 2020

👍 Will do: I've replaced tmux.until { |lines| lines[-1] == '$' } with tmux.prepare and split apart changes that stand on their own.

test/test_go.rb Outdated
tmux.send_keys '3d'
tmux.until { |lines| lines[-3].end_with? 'echo 3rd' }
tmux.until { |lines| lines[-3].end_with? 'echo 3d' }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you removed the additional CTRL-R for toggling sort and changed the assertions accordingly. Can you add checks for the toggling functionality? i.e. match_count should be 2 and lines[-3] should toggle between echo 3rd and echo 3d on CTRL-R.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️ Will do! But for the time being I've undone the changes.

test/test_go.rb Outdated
# Keys are possibly echoed before the (fish) shell is ready for
# C-r? In this case there's no other feedback to check for so add
# an arbitrary delay.
sleep 0.5 if shell == :fish
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to avoid this arbitrary delay. This seems to the case where the old Left, Right hack should work well. What do you think?

tmux.send_keys(query, :Left, :Right)
# $ foo^[[D^[[C (not ready)
# $ foo (ready)
tmux.until { |lines| lines[-1] == "$ #{query}" }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! But I tried it out and the intermittent failure returned: https://travis-ci.org/jablko/fzf/jobs/657850503#L534

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the link correct?

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the backtrace shows that it errored at test/test_go.rb:1842:in `block in test_ctrl_r_abort', which is: https://github.com/jablko/fzf/blob/28a39ddbc5a8761f151d8b05e3da4b92f98ad812/test/test_go.rb#L1842

So it sends query (in this case a double quote) followed by :Left and :Right. It finds $ #{query} (in this case $ ") so determines that the shell should be ready! It sends C-r but fish still stumbles and doesn't launch fzf 🙍‍♂️

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's strange. Let me see.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use the equality condition (lines[-1] == "$ #{query}") instead of start_with? which should return true before fish processes left and right arrow keys.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this left-right dance turns out to work well, we probably should put it in tmux.prepare.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️ Sorry I missed .start_with?. Thanks for your patience! However there are still intermittent failures:

I used lines[-1] != "$ #{query}^[[D^[[C" or !lines[-1].start_with?("$ #{query}^") instead of lines[-1] == "$ #{query}" because fish sometimes offers an autocompletion: https://travis-ci.org/jablko/fzf/jobs/658726395#L628

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because fish sometimes offers an autocompletion

Hmm, this is painful. One thing I noticed on my machine is that I append a space after double-quote, the suggestion text disappears. So,

tmux.send_keys(query, :Space, :Left, :Right)

might simplify the check. But anyway, this trick doesn't seem to completely prevent fish from not responding on CTRL-R.

There are other test cases for CTRL-R, should we apply the same hack on those cases as well?

We used to wrap these key bindings with retries method,

  • fzf/test/test_go.rb

    Lines 1758 to 1762 in d9c6a03

    retries do
    tmux.prepare
    tmux.send_keys 'C-t'
    tmux.until { |lines| lines.item_count == 100 }
    end
  • fzf/test/test_go.rb

    Lines 1839 to 1843 in d9c6a03

    retries do
    tmux.prepare
    tmux.send_keys 'C-r'
    tmux.until { |lines| lines.match_count.positive? }
    end
  • fzf/test/test_go.rb

    Lines 1820 to 1824 in d9c6a03

    retries do
    tmux.prepare
    tmux.send_keys :Escape, :c
    tmux.until { |lines| lines.item_count == 1 }
    end

but you removed them all in this pull request. Maybe we should keep them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in those cases there's a prompt we can rely on instead?

test/test_go.rb Outdated
tmux.send_keys 'sleep12345'
tmux.until { |lines| lines.any_include? 'sleep 12345' }
tmux.until { |lines| lines.match_count == 1 }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about changing this to lines.match_count >= 1? We can't be 100% sure if our process is the only match on the system.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's more than one match can we be sure we'll the right one?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but it will avoid false negatives. Any reason you decided to remove any_include? which should be more robust in that regard? If we would really like to avoid false positives, we could generate a large random integer instead of 12345 and search for that number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but it will avoid false negatives.

Sorry, I didn't think carefully enough! You're right: I've changed it to lines.match_count >= 1 👍

Any reason you decided to remove any_include? which should be more robust in that regard?

Is it more robust? It checks that the process is among the matches but another match might still be selected?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not perfect, but I'm sure we can agree that it is better than not checking at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point, how about lines[5].end_with?(' sleep 12345')?

@jablko jablko force-pushed the patch-9 branch 22 times, most recently from 0ac07b3 to 5cdaf38 Compare March 5, 2020 16:40
@jablko jablko force-pushed the patch-9 branch 6 times, most recently from 0e11d73 to f3d6a30 Compare April 2, 2020 18:28
@jablko
Copy link
Contributor Author

jablko commented Apr 2, 2020

I'm not convinced that the change proposed here reduces the probability of intermittent failures.

I think I've fixed it: The loop below now runs for 50 minutes without failing (it exhausts the Travis CI job time limit): https://travis-ci.org/github/jablko/fzf/builds/670342136

Would you consider giving it another look?

while ruby test/test_go.rb --verbose; do :; done

@jablko
Copy link
Contributor Author

jablko commented Apr 3, 2020

I've rebased this change and confirmed that an indefinite loop still exhausts the job time limit without failing: https://travis-ci.org/github/jablko/fzf/builds/670732268

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