Skip to content

Commit aba9891

Browse files
committed
fix steep type checks
1 parent 3504fad commit aba9891

File tree

4 files changed

+123
-22
lines changed

4 files changed

+123
-22
lines changed

temporalio/lib/temporalio/envconfig.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,10 @@ def to_hash
245245
hash[:address] = @address if @address
246246
hash[:namespace] = @namespace if @namespace
247247
hash[:api_key] = @api_key if @api_key
248-
hash[:tls] = @tls.to_hash if @tls && !@tls.to_hash.empty?
248+
if @tls
249+
tls_hash = @tls.to_hash # steep:ignore
250+
hash[:tls] = tls_hash unless tls_hash.empty?
251+
end
249252
hash[:grpc_meta] = @grpc_meta if @grpc_meta && !@grpc_meta.empty?
250253
hash
251254
end
@@ -257,7 +260,7 @@ def to_client_connect_config
257260
config[:target_host] = @address if @address
258261
config[:namespace] = @namespace if @namespace
259262
config[:api_key] = @api_key if @api_key
260-
config[:tls] = @tls.to_connect_tls_config if @tls
263+
config[:tls] = @tls.to_connect_tls_config if @tls # steep:ignore
261264
config[:rpc_metadata] = @grpc_meta if @grpc_meta && !@grpc_meta.empty?
262265
config
263266
end
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
module Temporalio
2+
module EnvConfig
3+
def self.source_to_path_and_data: (untyped source) -> [String?, Array[Integer]?]
4+
5+
class ClientConfigTLS
6+
attr_reader disabled: bool
7+
attr_reader server_name: String?
8+
attr_reader server_root_ca_cert: (Pathname | String)?
9+
attr_reader client_cert: (Pathname | String)?
10+
attr_reader client_private_key: (Pathname | String)?
11+
12+
def self.from_hash: (Hash[untyped, untyped]? hash) -> ClientConfigTLS?
13+
def self.hash_to_source: (Hash[untyped, untyped]? hash) -> (Pathname | String)?
14+
15+
def initialize: (
16+
?disabled: bool,
17+
?server_name: String?,
18+
?server_root_ca_cert: (Pathname | String)?,
19+
?client_cert: (Pathname | String)?,
20+
?client_private_key: (Pathname | String)?
21+
) -> void
22+
23+
def to_hash: -> Hash[Symbol, untyped]
24+
def to_connect_tls_config: -> (Hash[Symbol, untyped] | false)
25+
26+
private
27+
28+
def source_to_hash: (untyped source) -> Hash[Symbol, String]?
29+
def read_source: (untyped source) -> String?
30+
end
31+
32+
class ClientConfigProfile
33+
attr_reader address: String?
34+
attr_reader namespace: String?
35+
attr_reader api_key: String?
36+
attr_reader tls: ClientConfigTLS?
37+
attr_reader grpc_meta: Hash[untyped, untyped]
38+
39+
def self.from_hash: (Hash[untyped, untyped] hash) -> ClientConfigProfile
40+
41+
def self.load: (
42+
?profile: String?,
43+
?config_source: (Pathname | String)?,
44+
?disable_file: bool,
45+
?disable_env: bool,
46+
?config_file_strict: bool,
47+
?override_env_vars: Hash[String, String]?
48+
) -> ClientConfigProfile
49+
50+
def initialize: (
51+
?address: String?,
52+
?namespace: String?,
53+
?api_key: String?,
54+
?tls: ClientConfigTLS?,
55+
?grpc_meta: Hash[untyped, untyped]
56+
) -> void
57+
58+
def to_hash: -> Hash[Symbol, untyped]
59+
def to_client_connect_config: -> Hash[Symbol, untyped]
60+
end
61+
62+
class ClientConfig
63+
attr_reader profiles: Hash[String, ClientConfigProfile]
64+
65+
def self.from_hash: (Hash[untyped, untyped] hash) -> ClientConfig
66+
67+
def self.load: (
68+
?config_source: (Pathname | String)?,
69+
?disable_file: bool,
70+
?config_file_strict: bool,
71+
?override_env_vars: Hash[String, String]?
72+
) -> ClientConfig
73+
74+
def self.load_client_connect_config: (
75+
?profile: String?,
76+
?config_source: (Pathname | String)?,
77+
?disable_file: bool,
78+
?disable_env: bool,
79+
?config_file_strict: bool,
80+
?override_env_vars: Hash[String, String]?
81+
) -> Hash[Symbol, untyped]
82+
83+
def initialize: (Hash[String, ClientConfigProfile] profiles) -> void
84+
def to_hash: -> Hash[String, Hash[Symbol, untyped]]
85+
end
86+
end
87+
end

temporalio/test/envconfig_test.rb

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require 'fileutils'
44
require 'pathname'
5+
require 'tmpdir'
56
require 'temporalio/client'
67
require 'temporalio/envconfig'
78
require_relative 'test'
@@ -93,7 +94,7 @@ def test_load_profile_from_file_custom
9394
assert_equal 'custom-address', profile.address
9495
assert_equal 'custom-namespace', profile.namespace
9596
refute_nil profile.tls
96-
assert_equal 'custom-server-name', profile.tls.server_name
97+
assert_equal 'custom-server-name', profile.tls.server_name # steep:ignore
9798
assert_equal 'custom-value', profile.grpc_meta['custom-header']
9899

99100
config = profile.to_client_connect_config
@@ -123,7 +124,7 @@ def test_load_profile_from_data_custom
123124
assert_equal 'custom-address', profile.address
124125
assert_equal 'custom-namespace', profile.namespace
125126
refute_nil profile.tls
126-
assert_equal 'custom-server-name', profile.tls.server_name
127+
assert_equal 'custom-server-name', profile.tls.server_name # steep:ignore
127128
assert_equal 'custom-value', profile.grpc_meta['custom-header']
128129

129130
config = profile.to_client_connect_config
@@ -166,7 +167,7 @@ def test_load_profile_env_overrides
166167
assert_equal 'env-namespace', profile.namespace
167168
assert_equal 'env-api-key', profile.api_key
168169
refute_nil profile.tls
169-
assert_equal 'env-server-name', profile.tls.server_name
170+
assert_equal 'env-server-name', profile.tls.server_name # steep:ignore
170171

171172
config = profile.to_client_connect_config
172173
assert_equal 'env-address', config[:target_host]
@@ -369,7 +370,7 @@ def test_load_profile_tls_options
369370
config_source: TOML_CONFIG_TLS_DETAILED, profile: 'tls_disabled'
370371
)
371372
refute_nil profile_disabled.tls
372-
assert profile_disabled.tls.disabled
373+
assert profile_disabled.tls.disabled # steep:ignore
373374

374375
config_disabled = profile_disabled.to_client_connect_config
375376
assert_equal false, config_disabled[:tls]
@@ -379,13 +380,13 @@ def test_load_profile_tls_options
379380
config_source: TOML_CONFIG_TLS_DETAILED, profile: 'tls_with_certs'
380381
)
381382
refute_nil profile_certs.tls
382-
assert_equal 'custom-server', profile_certs.tls.server_name
383-
refute_nil profile_certs.tls.server_root_ca_cert
384-
assert_equal 'ca-pem-data', profile_certs.tls.server_root_ca_cert
385-
refute_nil profile_certs.tls.client_cert
386-
assert_equal 'client-crt-data', profile_certs.tls.client_cert
387-
refute_nil profile_certs.tls.client_private_key
388-
assert_equal 'client-key-data', profile_certs.tls.client_private_key
383+
assert_equal 'custom-server', profile_certs.tls.server_name # steep:ignore
384+
refute_nil profile_certs.tls.server_root_ca_cert # steep:ignore
385+
assert_equal 'ca-pem-data', profile_certs.tls.server_root_ca_cert # steep:ignore
386+
refute_nil profile_certs.tls.client_cert # steep:ignore
387+
assert_equal 'client-crt-data', profile_certs.tls.client_cert # steep:ignore
388+
refute_nil profile_certs.tls.client_private_key # steep:ignore
389+
assert_equal 'client-key-data', profile_certs.tls.client_private_key # steep:ignore
389390

390391
config_certs = profile_certs.to_client_connect_config
391392
tls_config_certs = config_certs[:tls]
@@ -397,7 +398,7 @@ def test_load_profile_tls_options
397398
end
398399

399400
def test_load_profile_tls_from_paths
400-
Dir.mktmpdir do |tmpdir|
401+
Dir.mktmpdir do |tmpdir| # steep:ignore
401402
# Create dummy cert files
402403
ca_pem_path = File.join(tmpdir, 'ca.pem')
403404
client_crt_path = File.join(tmpdir, 'client.crt')
@@ -419,13 +420,13 @@ def test_load_profile_tls_from_paths
419420

420421
profile = Temporalio::EnvConfig::ClientConfigProfile.load(config_source: toml_config)
421422
refute_nil profile.tls
422-
assert_equal 'custom-server', profile.tls.server_name
423-
refute_nil profile.tls.server_root_ca_cert
424-
assert_equal ca_pem_path, profile.tls.server_root_ca_cert
425-
refute_nil profile.tls.client_cert
426-
assert_equal client_crt_path, profile.tls.client_cert
427-
refute_nil profile.tls.client_private_key
428-
assert_equal client_key_path, profile.tls.client_private_key
423+
assert_equal 'custom-server', profile.tls.server_name # steep:ignore
424+
refute_nil profile.tls.server_root_ca_cert # steep:ignore
425+
assert_equal ca_pem_path, profile.tls.server_root_ca_cert # steep:ignore
426+
refute_nil profile.tls.client_cert # steep:ignore
427+
assert_equal client_crt_path, profile.tls.client_cert # steep:ignore
428+
refute_nil profile.tls.client_private_key # steep:ignore
429+
assert_equal client_key_path, profile.tls.client_private_key # steep:ignore
429430

430431
config = profile.to_client_connect_config
431432
tls_config = config[:tls]
@@ -895,7 +896,7 @@ def test_e2e_multi_profile_different_client_connections
895896
private
896897

897898
def with_temp_config_file(content)
898-
Dir.mktmpdir do |tmpdir|
899+
Dir.mktmpdir do |tmpdir| # steep:ignore
899900
config_file = File.join(tmpdir, 'config.toml')
900901
File.write(config_file, content)
901902
yield config_file
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class EnvConfigTest < Test
2+
TOML_CONFIG_BASE: String
3+
TOML_CONFIG_STRICT_FAIL: String
4+
TOML_CONFIG_MALFORMED: String
5+
TOML_CONFIG_TLS_DETAILED: String
6+
7+
private
8+
9+
def with_temp_config_file: [T] (String content) { (String config_file) -> T } -> T
10+
end

0 commit comments

Comments
 (0)