Closed titusfortner closed 4 weeks ago
โฑ๏ธ Estimated effort to review [1-5] | 4, because the PR introduces significant changes across multiple files, including new classes and methods, deprecations, and modifications to existing functionalities. The complexity of the changes, especially around the new logging API and handling of callbacks, requires careful consideration to ensure compatibility and correctness. |
๐งช Relevant tests | Yes |
โก Possible issues | Possible Bug: The `remove_message_handler` method in `LogHandler` class might not properly handle the case where the `id` does not exist in the `@callbacks` hash, potentially leading to errors when trying to delete a non-existent entry. |
๐ Security concerns | No |
relevant file | rb/lib/selenium/webdriver/bidi/log_handler.rb |
suggestion | Consider adding error handling in `remove_message_handler` to gracefully handle cases where the `id` provided does not exist in the `@callbacks` hash. This can prevent potential errors and improve the robustness of the method. [important] |
relevant line | @bidi.remove_callback('log.entryAdded', id) |
Category | Suggestion | Score |
Possible bug |
Fix the
___
**The | 10 |
Consistency |
Ensure
___
**The | 8 |
Enhancement |
Simplify the
___
**The | 6 |
Maintainability |
Correct the typo in the test method name for better readability___ **There is a typo in the test method namelogs removes console message hander . It should be corrected to logs removes console message handler .**
[rb/spec/integration/selenium/webdriver/bidi/script_spec.rb [67]](https://github.com/SeleniumHQ/selenium/pull/14073/files#diff-511fb8dd07c92b6e7a8767aafc8f3008f7fb18799fd027b9ee9b4e45d9cbea33R67-R67)
```diff
-it 'logs removes console message hander' do
+it 'logs removes console message handler' do
```
Suggestion importance[1-10]: 4Why: Correcting typos improves code maintainability and readability, but it's a relatively minor issue. | 4 |
**Action:** Ruby / Local Tests (firefox, windows) / Local Tests (firefox, windows) |
**Failed stage:** [Run Bazel](https://github.com/SeleniumHQ/selenium/actions/runs/9386108330/job/25846231393) [โ] |
**Failed test name:** //rb/spec/integration/selenium/webdriver:devtools-firefox |
**Failure summary:**
The action failed due to the following reasons:protoc.exe command failed to execute successfully, causing a critical build step to fail.proto_library for the target @@io_bazel_rules_closure//java/io/bazel/rules/closure:build_info_proto .//rb/spec/integration/selenium/webdriver:devtools-firefox failed to build, leading to the failure of the action. |
Relevant error logs:```yaml 1: ##[group]Operating System 2: Microsoft Windows Server 2022 ... 353: ##[group]Restore cache for external-protobuf~ 354: Cache Size: ~7 MB (6846456 B) 355: [command]"C:\Program Files\Git\usr\bin\tar.exe" -xf D:/a/_temp/0fb72dd8-d190-43e5-b123-7d8f3e791412/cache.tzst -P -C D:/a/selenium/selenium --force-local --use-compress-program "zstd -d" 356: Received 5073488 of 5073488 (100.0%), 4.8 MBs/sec 357: Cache restored successfully 358: Successfully restored cache from setup-bazel-2-win32-external-protobuf~-9914fdedced4b237d23a421264c215c7ce93f92c099c523923a35f2748b6e88d 359: ##[endgroup] 360: ##[group]Restore cache for external-rules_buf~~ext~rules_buf_toolchains 361: Failed to restore external-rules_buf~~ext~rules_buf_toolchains cache ... 664: [32m[1,066 / 1,864][0m Compiling src/google/protobuf/compiler/command_line_interface.cc [for tool]; 5s local, disk-cache ... (4 actions, 3 running) 665: [32m[1,074 / 1,864][0m Compiling src/google/protobuf/compiler/command_line_interface.cc [for tool]; 6s local, disk-cache ... (2 actions, 1 running) 666: [32m[1,076 / 1,864][0m [Prepa] RunBinary rb/lib/selenium/devtools/v124.rb ... (4 actions, 1 running) 667: [32mINFO: [0mFrom Installing external/rules_ruby~~ruby~bundle/rb/vendor/cache/bundler-2.5.10.gem (@@rules_ruby~~ruby~bundle//:bundler-2.5.10): 668: Successfully installed bundler-2.5.10 669: 1 gem installed 670: [32m[1,077 / 1,864][0m Linking external/protobuf~/protoc.exe [for tool]; 1s local, disk-cache ... (4 actions, 1 running) 671: [32m[1,078 / 1,864][0m RunBinary rb/lib/selenium/devtools/v85.rb; 1s disk-cache ... (4 actions, 2 running) 672: [31m[1mERROR: [0mD:/_bazel/external/io_bazel_rules_closure/java/io/bazel/rules/closure/BUILD:64:14: Generating proto_library @@io_bazel_rules_closure//java/io/bazel/rules/closure:build_info_proto [for tool] failed: (Exit -1073741819): protoc.exe failed: error executing GenProto command (from target @@io_bazel_rules_closure//java/io/bazel/rules/closure:build_info_proto) 673: cd /d D:/_bazel/execroot/_main 674: SET PATH=C:\Program Files\Git\bin;C:\Program Files\Git\usr\bin;C:\Windows;C:\Windows\System32;C:\Windows\System32\WindowsPowerShell\v1.0 675: bazel-out\x64_windows-opt-exec-ST-13d3ddad9198\bin\external\protobuf~\protoc.exe --java_out=bazel-out/x64_windows-opt-exec-ST-13d3ddad9198/bin/external/io_bazel_rules_closure/java/io/bazel/rules/closure/build_info_proto-speed-src.jar -Iexternal/io_bazel_rules_closure -I. external/io_bazel_rules_closure/java/io/bazel/rules/closure/build_info.proto 676: # Configuration: 3f62d58e1724b33c4c5a838ec5dd37be29e6f58351fe7900d780cb5e8258345c 677: # Execution platform: @@local_config_platform//:host 678: [32m[1,082 / 1,864][0m 1 / 27 tests, [31m[1m1 failed[0m;[0m checking cached actions 679: [32mINFO: [0mElapsed time: 266.804s, Critical Path: 16.05s 680: [32mINFO: [0m1082 processes: 33 disk cache hit, 872 internal, 177 local. 681: [31m[1mERROR: [0mBuild did NOT complete successfully 682: //rb/spec/integration/selenium/webdriver:action_builder-firefox [0m[31m[1mNO STATUS[0m 683: //rb/spec/integration/selenium/webdriver:bidi-firefox [0m[31m[1mNO STATUS[0m 684: //rb/spec/integration/selenium/webdriver:driver-firefox [0m[31m[1mNO STATUS[0m 685: //rb/spec/integration/selenium/webdriver:element-firefox [0m[31m[1mNO STATUS[0m 686: //rb/spec/integration/selenium/webdriver:error-firefox [0m[31m[1mNO STATUS[0m ... 700: //rb/spec/integration/selenium/webdriver/bidi:browsing_context-firefox [0m[31m[1mNO STATUS[0m 701: //rb/spec/integration/selenium/webdriver/bidi:log_inspector-firefox [0m[31m[1mNO STATUS[0m 702: //rb/spec/integration/selenium/webdriver/bidi:script-firefox [0m[31m[1mNO STATUS[0m 703: //rb/spec/integration/selenium/webdriver/firefox:driver-firefox [0m[31m[1mNO STATUS[0m 704: //rb/spec/integration/selenium/webdriver/firefox:profile-firefox [0m[31m[1mNO STATUS[0m 705: //rb/spec/integration/selenium/webdriver/firefox:service-firefox [0m[31m[1mNO STATUS[0m 706: //rb/spec/integration/selenium/webdriver/remote:driver-firefox [0m[31m[1mNO STATUS[0m 707: //rb/spec/integration/selenium/webdriver/remote:element-firefox [0m[31m[1mNO STATUS[0m 708: //rb/spec/integration/selenium/webdriver:devtools-firefox [0m[31m[1mFAILED TO BUILD[0m 709: Executed 0 out of 27 tests: [0m[31m[1m1 fails to build[0m and [0m[35m26 were skipped[0m. 710: [0m 711: ##[error]Process completed with exit code 1. ``` |
/help
Welcome to the PR Agent, an AI-powered tool for automated pull request analysis, feedback, suggestions and more.
Here is a list of tools you can use to interact with the PR Agent:
Tool | Description | Trigger Interactively :gem: |
---|---|---|
[DESCRIBE](https://pr-agent-docs.codium.ai/tools/describe/) | Generates PR description - title, type, summary, code walkthrough and labels | - [ ] Run |
[REVIEW](https://pr-agent-docs.codium.ai/tools/review/) | Adjustable feedback about the PR, possible issues, security concerns, review effort and more | - [ ] Run |
[IMPROVE](https://pr-agent-docs.codium.ai/tools/improve/) | Code suggestions for improving the PR | - [x] Run |
[UPDATE CHANGELOG](https://pr-agent-docs.codium.ai/tools/update_changelog/) | Automatically updates the changelog | - [ ] Run |
[ADD DOCS](https://pr-agent-docs.codium.ai/tools/documentation/) ๐ | Generates documentation to methods/functions/classes that changed in the PR | - [ ] Run |
[TEST](https://pr-agent-docs.codium.ai/tools/test/) ๐ | Generates unit tests for a specific component, based on the PR code change | - [ ] Run |
[IMPROVE COMPONENT](https://pr-agent-docs.codium.ai/tools/improve_component/) ๐ | Code suggestions for a specific component that changed in the PR | - [ ] Run |
[ANALYZE](https://pr-agent-docs.codium.ai/tools/analyze/) ๐ | Identifies code components that changed in the PR, and enables to interactively generate tests, docs, and code suggestions for each component | - [ ] Run |
[ASK](https://pr-agent-docs.codium.ai/tools/ask/) | Answering free-text questions about the PR | [*] |
[GENERATE CUSTOM LABELS](https://pr-agent-docs.codium.ai/tools/custom_labels/) ๐ | Generates custom labels for the PR, based on specific guidelines defined by the user | [*] |
[CI FEEDBACK](https://pr-agent-docs.codium.ai/tools/ci_feedback/) ๐ | Generates feedback and analysis for a failed CI job | [*] |
[CUSTOM PROMPT](https://pr-agent-docs.codium.ai/tools/custom_prompt/) ๐ | Generates custom suggestions for improving the PR code, derived only from a specific guidelines prompt defined by the user | [*] |
[SIMILAR ISSUE](https://pr-agent-docs.codium.ai/tools/similar_issues/) | Automatically retrieves and presents similar issues | [*] |
(1) Note that each tool be triggered automatically when a new PR is opened, or called manually by commenting on a PR.
(2) Tools marked with [*] require additional parameters to be passed. For example, to invoke the /ask
tool, you need to comment on a PR: /ask "<question content>"
. See the relevant documentation for each tool for more details.
Persistent review updated to latest commit https://github.com/SeleniumHQ/selenium/commit/aeb7b85395982c4d2251f8be1caaa132fa2cdaf6
PR Description updated to latest commit (https://github.com/SeleniumHQ/selenium/commit/aeb7b85395982c4d2251f8be1caaa132fa2cdaf6)
Category | Suggestion | Score |
Enhancement |
Ensure
___
**The | 10 |
Possible issue |
Add a check to ensure the handler ID exists before attempting to remove it___ **Add a check in theremove_message_handler method to ensure the handler ID exists before attempting to remove it. This will prevent potential errors if an invalid ID is passed.** [rb/lib/selenium/webdriver/bidi/log_handler.rb [44-47]](https://github.com/SeleniumHQ/selenium/pull/14073/files#diff-255281b194a6769984ac959abce6e066d00fbfc11e43f8b21363695d0dd652b8R44-R47) ```diff def remove_message_handler(id) - @bidi.remove_callback('log.entryAdded', id) - unsubscribe_log_entry if @bidi.callbacks['log.entryAdded'].empty? + if @bidi.callbacks['log.entryAdded'].any? { |callback| callback.object_id == id } + @bidi.remove_callback('log.entryAdded', id) + unsubscribe_log_entry if @bidi.callbacks['log.entryAdded'].empty? + else + raise ArgumentError, "Handler ID not found" + end end ``` Suggestion importance[1-10]: 8Why: Adding a check for the existence of a handler ID before removal is crucial to prevent runtime errors and ensures robustness in method execution. | 8 |
Best practice |
Convert
___
**The | 7 |
Maintainability |
Extract deprecation warning logic into a separate private method for better readability___ **To improve readability and maintainability, consider extracting the deprecation warninglogic in the callbacks method into a separate private method.**
[rb/lib/selenium/webdriver/bidi.rb [39-40]](https://github.com/SeleniumHQ/selenium/pull/14073/files#diff-b7660c7b53fec20ce95452b2afdbf306e9c36363e5bf8812863375b7bc96e42eR39-R40)
```diff
-WebDriver.logger.deprecate('`BiDi#callbacks << event` to add a callback to the list of callbacks',
- 'BiDi#add_callback(event, &block)', id: :callbacks)
+log_deprecation_warning
+private
+
+def log_deprecation_warning
+ WebDriver.logger.deprecate('`BiDi#callbacks << event` to add a callback to the list of callbacks',
+ 'BiDi#add_callback(event, &block)', id: :callbacks)
+end
+
```
Suggestion importance[1-10]: 6Why: Extracting the deprecation logic into a separate method improves the readability and maintainability of the code, although it's not a critical change. | 6 |
I have some more tweaks for this, but does it look good enough for now?
Category | Suggestion | Score |
Enhancement |
Return the handler ID from the
___
**The | 8 |
Return a boolean indicating whether the callback was successfully removed in the
___
**The | 7 | |
Possible bug |
Handle the case where the event does not exist in the callbacks hash in the
___
**The | 7 |
Best practice |
Define
___
**The | 6 |
User description
Description
Motivation and Context
Partial Ruby implementation of #13992
13964
Updates
Based on feedback:
#object_id
of the proc to return the id instead of tracking it separatelyScript
class is going to implement things from both script and log domains. It makes sense to implement the domain specific functionality in separate, lower level classes and keepScript
for the high level API, so I createdLogHandler
class for this.Driver#script
alias ofDriver#exectue_script
LogInspector
- this should provide all of the required functionality of LogInspectorPR Type
Enhancement, Tests, Documentation
Description
LogHandler
class for managing console and JavaScript log entries.BiDi#callbacks
andLogInspector
class.add_callback
andremove_callback
methods toWebSocketConnection
.Script
class to handle log entries and manage handlers.subscribe
andunsubscribe
methods inSession
class to use keyword arguments.Script
class and BiDi error handling.Driver
andScript
classes.Changes walkthrough ๐
9 files
bidi.rb
Enhance BiDi with logging handlers and callback management
rb/lib/selenium/webdriver/bidi.rb
LogHandler
andStruct
autoloads.BiDi#callbacks
method.add_callback
andremove_callback
methods.log_handler.rb
Introduce LogHandler class for managing log entries
rb/lib/selenium/webdriver/bidi/log_handler.rb
LogHandler
class for managing log entries.log_inspector.rb
Deprecate LogInspector and update callback handling
rb/lib/selenium/webdriver/bidi/log_inspector.rb
LogInspector
class.add_callback
instead of direct callbackmanipulation.
session.rb
Refactor session subscription methods with keyword arguments
rb/lib/selenium/webdriver/bidi/session.rb
subscribe
andunsubscribe
methods to use keyword arguments.struct.rb
Add Struct class for camel to snake case conversion
rb/lib/selenium/webdriver/bidi/struct.rb
Struct
class to convert camel case JSON keys to snake casemethods.
common.rb
Require Script class in common module
rb/lib/selenium/webdriver/common.rb - Added `require 'selenium/webdriver/common/script'`.
driver.rb
Deprecate Driver#script alias and add Script instance method
rb/lib/selenium/webdriver/common/driver.rb
Driver#script
alias for#execute_script
.Driver#script
method for accessingScript
instance.script.rb
Add Script class for handling log entries
rb/lib/selenium/webdriver/common/script.rb
Script
class to handle console and JavaScript log entries.websocket_connection.rb
Add callback management methods to WebSocketConnection
rb/lib/selenium/webdriver/common/websocket_connection.rb
add_callback
andremove_callback
methods for managing WebSocketcallbacks.
3 files
script_spec.rb
Add integration tests for Script class
rb/spec/integration/selenium/webdriver/bidi/script_spec.rb
Script
class.bidi_spec.rb
Add BiDi error handling and deprecation tests
rb/spec/integration/selenium/webdriver/bidi_spec.rb
BiDi#callbacks
.driver_spec.rb
Add test for Driver#script method with deprecation warning
rb/spec/integration/selenium/webdriver/driver_spec.rb - Added test for `Driver#script` method with deprecation warning.
2 files
driver.rbs
Update type signature for Driver class
rb/sig/lib/selenium/webdriver/common/driver.rbs - Added `@script` instance variable to type signature.
script.rbs
Add type signatures for Script class
rb/sig/selenium/web_driver/script.rbs - Added type signatures for `Script` class methods.