Skip to content

fix: guard after_session hook and avoid duplicate newCommandTimeout capability - #270

Open
hoanle0126 wants to merge 2 commits into
appium:masterfrom
hoanle0126:fix/safe-console-hook-and-command-timeout
Open

hoanle0126 wants to merge 2 commits into
appium:masterfrom
hoanle0126:fix/safe-console-hook-and-command-timeout

Conversation

@hoanle0126

Copy link
Copy Markdown

Proposed changes

  • Remove existing pry_load_appium_txt and reload singleton methods on Pry before redefining them in Appium::Console.setup to avoid method redefined warnings.
  • Replace any existing 'Release session hook' :after_session hook before registering it in Appium::Console.start, and guard x with respond_to?(:x, true) so the :after_session hook does not raise NameError if a session failed to start or promote driver methods.
  • Check for both :newCommandTimeout and :'appium:newCommandTimeout' in lib/start.rb before injecting the default newCommandTimeout: 999_999 capability.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

@hoanle0126
hoanle0126 requested a review from KazuCocoa as a code owner October 26, 2026 08:43
Comment thread test/console_test.rb
end
output = StringIO.new
Pry.hooks.exec_hook(:after_session, output, binding, Pry.new)
assert_includes output.string, 'Closing appium session...'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] Assert that the release hook completes without an error

Pry.hooks.exec_hook catches hook exceptions and stores them in Pry.hooks.errors, so this assertion still passes if the new respond_to?(:x, true) guard is removed: the closing message is printed before x raises NameError. I reproduced this behavior with Pry 0.14.2's hook implementation. Please invoke the registered hook directly with Pry.hooks.get_hook(:after_session, 'Release session hook').call(output, binding, Pry.new), or assert that executing it adds no hook errors, so the test detects the missing-driver regression.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated test_after_session_hook_handles_missing_driver_and_repeated_start to invoke Pry.hooks.get_hook(:after_session, 'Release session hook').call(output, binding, Pry.new) directly and assert Pry.hooks.errors is empty. Thanks @KazuCocoa!

This branch has not been deployed

No deployments
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.

2 participants