@@ -7,14 +7,14 @@ class Stagehand::LocalBinaryTest < Minitest::Test
77
88 @mutex = Mutex . new
99
10- def self . mutex
11- @ mutex
10+ class << self
11+ attr_reader : mutex
1212 end
1313
1414 def setup
1515 super
1616 @tmp_home = Dir . mktmpdir
17- @old_home = ENV [ "HOME" ]
17+ @old_home = Dir . home if ENV . key? ( "HOME" )
1818 @old_xdg = ENV [ "XDG_CACHE_HOME" ]
1919 @old_local = ENV [ "LOCALAPPDATA" ]
2020 ENV [ "HOME" ] = @tmp_home
@@ -26,7 +26,11 @@ def setup
2626 end
2727
2828 def teardown
29- ENV [ "HOME" ] = @old_home
29+ if @old_home
30+ ENV [ "HOME" ] = @old_home
31+ else
32+ ENV . delete ( "HOME" )
33+ end
3034 ENV [ "XDG_CACHE_HOME" ] = @old_xdg
3135 ENV [ "LOCALAPPDATA" ] = @old_local
3236 FileUtils . remove_entry ( @tmp_home ) if @tmp_home && File . directory? ( @tmp_home )
@@ -47,35 +51,35 @@ def test_uses_cache_without_network
4751 File . binwrite ( cache_path , "cached" )
4852
4953 path = Stagehand ::Local ::Binary . resolve_binary_path
50- assert_equal cache_path , path
54+ assert_equal ( cache_path , path )
5155 end
5256
5357 def test_downloads_latest_tag_when_missing
5458 filename = Stagehand ::Local ::Binary . binary_filename
5559
5660 stub_request ( :get , "https://api.github.com/repos/browserbase/stagehand/releases?per_page=15" )
57- . to_return ( status : 200 , body : [ { tag_name : "stagehand-server/v9.9.9" } ] . to_json )
61+ . to_return ( status : 200 , body : [ { tag_name : "stagehand-server/v9.9.9" } ] . to_json )
5862
5963 stub_request ( :get , "https://github.com/browserbase/stagehand/releases/download/stagehand-server/v9.9.9/#{ filename } " )
6064 . to_return ( status : 200 , body : "binary" )
6165
6266 path = Stagehand ::Local ::Binary . resolve_binary_path
6367
64- assert File . exist? ( path )
65- assert_equal "binary" , File . binread ( path )
68+ assert ( File . exist? ( path ) )
69+ assert_equal ( "binary" , File . binread ( path ) )
6670 end
6771
6872 def test_download_error_includes_manual_hint
6973 filename = Stagehand ::Local ::Binary . binary_filename
7074
7175 stub_request ( :get , "https://api.github.com/repos/browserbase/stagehand/releases?per_page=15" )
72- . to_return ( status : 200 , body : [ { tag_name : "stagehand-server/v1.2.3" } ] . to_json )
76+ . to_return ( status : 200 , body : [ { tag_name : "stagehand-server/v1.2.3" } ] . to_json )
7377
7478 stub_request ( :get , "https://github.com/browserbase/stagehand/releases/download/stagehand-server/v1.2.3/#{ filename } " )
7579 . to_return ( status : 404 , body : "not found" )
7680
7781 err = assert_raises ( RuntimeError ) { Stagehand ::Local ::Binary . resolve_binary_path }
78- assert_includes err . message , "Failed to download Stagehand driver binary"
79- assert_includes err . message , filename
82+ assert_includes ( err . message , "Failed to download Stagehand driver binary" )
83+ assert_includes ( err . message , filename )
8084 end
8185end
0 commit comments