Skip to content

Commit

Permalink
[rb] Add full RBS support (#13234)
Browse files Browse the repository at this point in the history
  • Loading branch information
aguspe committed Mar 18, 2024
1 parent f54b068 commit 5b7c95b
Show file tree
Hide file tree
Showing 182 changed files with 3,603 additions and 90 deletions.
84 changes: 82 additions & 2 deletions rb/Steepfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,88 @@
# frozen_string_literal: true

# rubocop:disable Metrics/BlockLength -- Disable due to the steep configuration not matching rubocop expectations
target :lib do
signature 'sig' # Signature directory
signature 'sig', '.gem_rbs_collection/rubyzip' # Signature directory
check 'lib' # Directory name
# Total amount of errors ignore 66 in 31 files
ignore(
# Ignore line 166 due to UDP RBS issue
'lib/selenium/webdriver/common/platform.rb',
# Ignore due to webmock gem not having RBS signatures
'lib/selenium/webdriver/remote/http/curb.rb',
# Ignore due to line 71, there is one last error where RBS thinks backtrace is nil
'lib/selenium/webdriver/remote/response.rb',
# Ignore due to Errno::EACCES error
'lib/selenium/webdriver/support/color.rb',
'lib/selenium/webdriver/common/port_prober.rb',
# Ignore due to error overloading
'lib/selenium/webdriver/common/socket_poller.rb',
# Ignore due to Parser on line 611
'lib/selenium/webdriver/remote/bridge.rb',
# Ignore due to error on line 101 with block
'lib/selenium/webdriver/devtools/network_interceptor.rb',
# Ignore due to error on line 21 with overloading issues
'lib/selenium/webdriver/common/virtual_authenticator/credential.rb',
# Ignore due to error with the Zipper RBS
'lib/selenium/webdriver/common/zipper.rb',
# Ignore due to error on line 117 with the debug? method
'lib/selenium/webdriver/common/selenium_manager.rb',
# Ignore due to line 230 with the overloading issues
'lib/selenium/webdriver/common/action_builder.rb',
# Ignore due to CAPABILITIES not able to be found on line 55
'lib/selenium/webdriver/common/options.rb',
# Ignore due to strftime error in RBS on line 188
'lib/selenium/webdriver/common/logger.rb',
# Ignore due to error with Process
'lib/selenium/webdriver/common/child_process.rb',
# Ignore due to Net::HTTP not being found on line 49
'lib/selenium/webdriver/chromium/driver.rb',
# Ignore due to error on line 37 with include?
'lib/selenium/webdriver/support/guards/guard_condition.rb',
# Ignore due to positional argument error on line 69
'lib/selenium/webdriver/common/socket_lock.rb',
# Ignore due to is_a? bot error on line 70
'lib/selenium/webdriver/remote/driver.rb',
# Ignore due to line 118 causing an error with URI & Net::HTTP
'lib/selenium/server.rb',
# Ignore due to overloading issue on line 84
'lib/selenium/webdriver/chromium/features.rb',
# Ignore due to line 59 with the same URI & Net::HTTP issue
'lib/selenium/webdriver/firefox/driver.rb',
# Ignore due to line 27 with overloading issue
'lib/selenium/webdriver/bidi/log/console_log_entry.rb',
# Ignore due to line 89 with overloading issue
'lib/selenium/webdriver.rb',
# Ignore due to line 37 with overloading issue
'lib/selenium/webdriver/common/interactions/wheel_input.rb',
# Cannot override last error on line 71
'lib/selenium/webdriver/common/wait.rb',
# Cannot override params on line 83
'lib/selenium/webdriver/bidi/log_inspector.rb',
# Kwargs issue on line 74
'lib/selenium/webdriver/common/driver.rb',
# issue with the Zipper RBS library on line 54
'lib/selenium/webdriver/firefox/extension.rb',
# Ignored due to return of last match in line 57 and 59
'lib/selenium/webdriver/firefox/profiles_ini.rb',
# Ignored due to error on line 100 of response being nillable
'lib/selenium/webdriver/remote/http/default.rb'
)

library 'forwardable' # Standard libraries
# Standard libraries used in the project
library(
'base64',
'date',
'erb',
'find',
'forwardable',
'ipaddr',
'net-http',
'openssl',
'tmpdir',
'securerandom',
'uri',
'zlib'
)
end
# rubocop:enable Metrics/BlockLength
11 changes: 6 additions & 5 deletions rb/lib/selenium/devtools/support/cdp_client_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ module DevTools
module Support
class CDPClientGenerator
# Input JSON files are generated from PDL tasks.
DOMAIN_TEMPLATE_PATH = File.expand_path('cdp/domain.rb.erb', __dir__)
LOADER_TEMPLATE_PATH = File.expand_path('cdp/loader.rb.erb', __dir__)
DIR = __dir__ || ''
DOMAIN_TEMPLATE_PATH = File.expand_path('cdp/domain.rb.erb', DIR)
LOADER_TEMPLATE_PATH = File.expand_path('cdp/loader.rb.erb', DIR)

RESERVED_KEYWORDS = %w[end].freeze

Expand All @@ -39,9 +40,9 @@ def call(output_dir:, version:, **opts)
@version = version

browser_protocol_path = opts.delete(:browser_protocol_path) do
File.expand_path('cdp/browser_protocol.json', __dir__)
File.expand_path('cdp/browser_protocol.json', DIR)
end
js_protocol_path = opts.delete(:js_protocol_path) { File.expand_path('cdp/js_protocol.json', __dir__) }
js_protocol_path = opts.delete(:js_protocol_path) { File.expand_path('cdp/js_protocol.json', DIR) }

raise ArgumentError, "Invalid arguments: #{opts.keys}" unless opts.empty?

Expand Down Expand Up @@ -103,7 +104,7 @@ def process_loader(domains)
Selenium::DevTools::Support::CDPClientGenerator.new.call(
browser_protocol_path: browser_protocol_path,
js_protocol_path: js_protocol_path,
output_dir: loader_path.sub(/\.rb$/, ''),
output_dir: loader_path&.sub(/\.rb$/, ''),
loader_path: loader_path,
version: version
)
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module WebDriver
# @api private

def self.root
@root ||= File.expand_path('..', __dir__)
@root ||= File.expand_path('..', __dir__.to_s)
end

#
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/common/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def [](sel)
end

def browser
bridge&.browser
bridge.browser
end

def capabilities
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/common/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def add_cookie(opts = {})
opts[:httpOnly] = http_only if http_only

obj = opts.delete(:expires)
opts[:expiry] = seconds_from(obj).to_i if obj
opts[:expiry] = seconds_from(obj).to_int if obj

@bridge.add_cookie opts
end
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/common/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def convert_json_key(key, camelize: true)
end

def camel_case(str)
str.gsub(/_([a-z])/) { Regexp.last_match(1).upcase }
str.gsub(/_([a-z])/) { Regexp.last_match(1)&.upcase }
end
end # Options
end # WebDriver
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/common/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def initialize(path: nil, port: nil, log: nil, args: nil)

def launch
@executable_path ||= begin
default_options = WebDriver.const_get("#{self.class.name.split('::')[2]}::Options").new
default_options = WebDriver.const_get("#{self.class.name&.split('::')&.[](2)}::Options").new
DriverFinder.path(default_options, self.class)
end
ServiceManager.new(self).tap(&:start)
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/common/socket_poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def listening?
def listening?
addr = Socket.getaddrinfo(@host, @port, Socket::AF_INET, Socket::SOCK_STREAM)
sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
sockaddr = Socket.pack_sockaddr_in(@port, addr[0][3])
sockaddr = Socket.pack_sockaddr_in(@port, addr[0][3].to_s)

begin
sock.connect_nonblock sockaddr
Expand Down
16 changes: 11 additions & 5 deletions rb/lib/selenium/webdriver/firefox/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class Profile
include ProfileHelper

VALID_PREFERENCE_TYPES = [TrueClass, FalseClass, Integer, Float, String].freeze
WEBDRIVER_PREFS = {
port: 'webdriver_firefox_port',
log_file: 'webdriver.log.file'
}.freeze

DEFAULT_PREFERENCES = {
'browser.newtabpage.enabled' => false,
Expand All @@ -35,8 +39,8 @@ class Profile

LOCK_FILES = %w[.parentlock parent.lock lock].freeze

attr_reader :name, :log_file
attr_writer :secure_ssl, :load_no_focus_lib
attr_reader :name, :log_file
attr_writer :secure_ssl, :load_no_focus_lib

class << self
def ini
Expand Down Expand Up @@ -206,8 +210,8 @@ def read_user_prefs(path)
File.read(path).split("\n").each do |line|
next unless line =~ /user_pref\("([^"]+)"\s*,\s*(.+?)\);/

key = Regexp.last_match(1).strip
value = Regexp.last_match(2).strip
key = Regexp.last_match(1)&.strip
value = Regexp.last_match(2)&.strip

# wrap the value in an array to make it a valid JSON string.
prefs[key] = JSON.parse("[#{value}]").first
Expand All @@ -223,7 +227,9 @@ def write_prefs(prefs, path)
end
end
end
end # Profile
end

# Profile
end # Firefox
end # WebDriver
end # Selenium
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/firefox/profiles_ini.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def parse
when /^\[Profile/
name, path = nil if path_for(name, is_relative, path)
when /^Name=(.+)$/
name = Regexp.last_match(1).strip
name = Regexp.last_match(1)&.strip
when /^IsRelative=(.+)$/
is_relative = Regexp.last_match(1).strip == '1'
when /^Path=(.+)$/
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/remote/capabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def json_create(data)
end

def camel_case(str_or_sym)
str_or_sym.to_s.gsub(/_([a-z])/) { Regexp.last_match(1).upcase }
str_or_sym.to_s.gsub(/_([a-z])/) { Regexp.last_match(1)&.upcase }
end

private
Expand Down
82 changes: 70 additions & 12 deletions rb/rbs_collection.lock.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
---
sources:
- type: git
name: ruby/gem_rbs_collection
revision: 8149bc3fc0f720d935dc0592dc8886e03052f65f
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
path: ".gem_rbs_collection"
gems:
- name: addressable
version: '2.8'
source:
type: git
name: ruby/gem_rbs_collection
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: ast
version: '2.4'
source:
type: git
name: ruby/gem_rbs_collection
revision: 8149bc3fc0f720d935dc0592dc8886e03052f65f
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: base64
- name: bigdecimal
version: '0'
source:
type: stdlib
- name: cgi
version: '0'
source:
type: stdlib
- name: fileutils
version: '0'
source:
type: stdlib
- name: hashdiff
version: '1.1'
source:
type: git
name: ruby/gem_rbs_collection
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: json
version: '0'
source:
Expand All @@ -44,23 +58,67 @@ gems:
source:
type: git
name: ruby/gem_rbs_collection
revision: 8149bc3fc0f720d935dc0592dc8886e03052f65f
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: parser
version: '3.2'
source:
type: git
name: ruby/gem_rbs_collection
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: rack
version: '2.2'
source:
type: git
name: ruby/gem_rbs_collection
revision: 8149bc3fc0f720d935dc0592dc8886e03052f65f
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: rainbow
version: '3.0'
source:
type: git
name: ruby/gem_rbs_collection
revision: 8149bc3fc0f720d935dc0592dc8886e03052f65f
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: rake
version: '13.0'
source:
type: git
name: ruby/gem_rbs_collection
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: regexp_parser
version: '2.8'
source:
type: git
name: ruby/gem_rbs_collection
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: ripper
version: '0'
source:
type: stdlib
- name: rubocop
version: '1.57'
source:
type: git
name: ruby/gem_rbs_collection
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: rubocop-ast
version: '1.30'
source:
type: git
name: ruby/gem_rbs_collection
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: tempfile
Expand All @@ -76,7 +134,7 @@ gems:
source:
type: git
name: ruby/gem_rbs_collection
revision: 8149bc3fc0f720d935dc0592dc8886e03052f65f
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
gemfile_lock_path: Gemfile.lock
3 changes: 3 additions & 0 deletions rb/sig/gems/open3/open3.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Open3
def self.capture3: (*untyped) -> untyped
end
7 changes: 7 additions & 0 deletions rb/sig/gems/rexml/document.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module REXML
class Document
def initialize: (untyped element) -> void

def root: () -> untyped
end
end
5 changes: 5 additions & 0 deletions rb/sig/gems/rexml/xpath.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module REXML
class XPath
def self.first: (untyped element, untyped path) -> untyped
end
end
7 changes: 7 additions & 0 deletions rb/sig/gems/websocket/handshake.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module WebSocket
module Handshake
class Client
def initialize: (untyped) -> void
end
end
end

0 comments on commit 5b7c95b

Please sign in to comment.