@@ -76,3 +76,33 @@ def test_run_end_exception_finalizes_stored_invocation_not_current_global(monkey
7676 assert build .call_args .args [0 ] == "inv-1"
7777 coord .set_post_run .assert_called_once_with ("inv-1" , "log" )
7878 coord .close .assert_called_once_with ("inv-1" )
79+
80+
81+ def test_connection_open_uses_opened_path_workspace_id (monkeypatch ):
82+ coord = Mock ()
83+ monkeypatch .setattr (hooks , "coordinator" , lambda : coord )
84+ monkeypatch .setattr (hooks , "_current_invocation_id" , lambda : "inv-1" )
85+ monkeypatch .setattr (hooks , "is_enabled_for_invocation" , lambda _ : True )
86+ monkeypatch .setattr (hooks , "has_reusable_transport" , lambda _ : True )
87+ manager = SimpleNamespace (host = "https://h" , header_factory = lambda : {}, workspace_id = None )
88+
89+ hooks .on_connection_open (
90+ SimpleNamespace (), manager , "/sql/1.0/warehouses/named?o=42"
91+ )
92+
93+ transport = coord .set_transport .call_args .args [1 ]
94+ assert transport .workspace_id == "42"
95+
96+
97+ def test_connection_open_falls_back_to_manager_workspace_id (monkeypatch ):
98+ coord = Mock ()
99+ monkeypatch .setattr (hooks , "coordinator" , lambda : coord )
100+ monkeypatch .setattr (hooks , "_current_invocation_id" , lambda : "inv-1" )
101+ monkeypatch .setattr (hooks , "is_enabled_for_invocation" , lambda _ : True )
102+ monkeypatch .setattr (hooks , "has_reusable_transport" , lambda _ : True )
103+ manager = SimpleNamespace (host = "https://h" , header_factory = lambda : {}, workspace_id = "7" )
104+
105+ hooks .on_connection_open (SimpleNamespace (), manager , "/sql/1.0/warehouses/default" )
106+
107+ transport = coord .set_transport .call_args .args [1 ]
108+ assert transport .workspace_id == "7"
0 commit comments