@@ -81,6 +81,24 @@ def test_pick_workspace_falls_back_to_first(monkeypatch: pytest.MonkeyPatch):
8181 assert pick_workspace ("k" , "https://api.hotdata.dev" , None ) == "ws_1"
8282
8383
84+ def test_resolve_workspace_selection_source_first (monkeypatch : pytest .MonkeyPatch ):
85+ monkeypatch .delenv ("HOTDATA_WORKSPACE" , raising = False )
86+ monkeypatch .delenv ("HOTDATA_WORKSPACE_ID" , raising = False )
87+ items = [
88+ SimpleNamespace (public_id = "ws_1" , active = False ),
89+ SimpleNamespace (public_id = "ws_2" , active = False ),
90+ ]
91+ listing = SimpleNamespace (workspaces = items )
92+ with patch ("hotdata_runtime.env.WorkspacesApi" ) as Api :
93+ Api .return_value .list_workspaces .return_value = listing
94+ resolved = resolve_workspace_selection (
95+ "k" , "https://api.hotdata.dev" , None
96+ )
97+ assert resolved .workspace_id == "ws_1"
98+ assert resolved .source == "first"
99+ assert resolved .workspaces == items
100+
101+
84102def test_resolve_workspace_selection_returns_workspaces_and_source (
85103 monkeypatch : pytest .MonkeyPatch ,
86104):
@@ -121,3 +139,48 @@ def get_result(self, result_id: str):
121139 with patch .object (client , "_results_api" , return_value = FakeResultsApi ()):
122140 with pytest .raises (RuntimeError , match = "cancelled" ):
123141 client ._wait_result_ready ("res_1" , timeout_s = 0.1 , interval_s = 0 )
142+
143+
144+ def test_connection_id_by_name_raises_on_duplicate_names ():
145+ client = HotdataClient ("k" , "ws" , host = "https://api.hotdata.dev" )
146+ listing = SimpleNamespace (
147+ connections = [
148+ SimpleNamespace (name = "warehouse" , id = "conn_1" ),
149+ SimpleNamespace (name = "warehouse" , id = "conn_2" ),
150+ ]
151+ )
152+
153+ class FakeConnectionsApi :
154+ def list_connections (self ):
155+ return listing
156+
157+ with patch .object (client , "connections" , return_value = FakeConnectionsApi ()):
158+ with pytest .raises (RuntimeError , match = "Duplicate connection names" ):
159+ client .connection_id_by_name ()
160+
161+
162+ def test_columns_for_qualified_prefers_explicit_connection_id ():
163+ client = HotdataClient ("k" , "ws" , host = "https://api.hotdata.dev" )
164+ col = SimpleNamespace (name = "a" , data_type = "INTEGER" , nullable = True )
165+ table = SimpleNamespace (columns = [col ])
166+ response = SimpleNamespace (tables = [table ])
167+
168+ class FakeInformationSchemaApi :
169+ def __init__ (self ):
170+ self .kwargs = None
171+
172+ def information_schema (self , ** kwargs ):
173+ self .kwargs = kwargs
174+ return response
175+
176+ fake_api = FakeInformationSchemaApi ()
177+ with patch .object (client , "_information_schema" , return_value = fake_api ), patch .object (
178+ client , "connection_id_by_name"
179+ ) as id_map :
180+ cols = client .columns_for_qualified (
181+ "warehouse.public.orders" ,
182+ connection_id = "conn_explicit" ,
183+ )
184+ id_map .assert_not_called ()
185+ assert cols == [col ]
186+ assert fake_api .kwargs ["connection_id" ] == "conn_explicit"
0 commit comments