@@ -54,6 +54,8 @@ def test_catalog_attach_returns_attach_id(self, example_worker: str) -> None:
5454 assert len (attach_result ["attach_id" ]) > 0
5555 assert attach_result ["supports_transactions" ] is False
5656 assert attach_result ["catalog_version_frozen" ] is True
57+ # ReadOnlyCatalogInterface returns attach_id_required=False
58+ assert attach_result ["attach_id_required" ] is False
5759
5860
5961class TestCLISchemaContents :
@@ -72,15 +74,47 @@ def test_schema_contents_lists_functions(self, example_worker: str) -> None:
7274 attach_data = json .loads (attach_result .output )
7375 attach_id = attach_data ["attach_id" ]
7476
75- # List schema contents (now nested under catalog)
77+ # List schema contents using --attach-id option
7678 contents_result = runner .invoke (
7779 cli ,
7880 [
7981 "catalog" ,
8082 "schema" ,
8183 "contents" ,
84+ "main" ,
85+ "--attach-id" ,
8286 attach_id ,
87+ "--server" ,
88+ example_worker ,
89+ ],
90+ )
91+ assert contents_result .exit_code == 0
92+
93+ # Parse all output lines as JSON
94+ lines = contents_result .output .strip ().split ("\n " )
95+ items = [json .loads (line ) for line in lines if line .strip ()]
96+
97+ # Should have items
98+ assert len (items ) > 0
99+
100+ # All items should be functions
101+ for item in items :
102+ assert item ["type" ] == "function"
103+
104+ def test_schema_contents_with_catalog_option (self , example_worker : str ) -> None :
105+ """Schema contents works with --catalog option for auto-attach."""
106+ runner = CliRunner ()
107+
108+ # List schema contents using --catalog option (auto-attach)
109+ contents_result = runner .invoke (
110+ cli ,
111+ [
112+ "catalog" ,
113+ "schema" ,
114+ "contents" ,
83115 "main" ,
116+ "--catalog" ,
117+ "example" ,
84118 "--server" ,
85119 example_worker ,
86120 ],
@@ -110,15 +144,16 @@ def test_all_example_functions_present(self, example_worker: str) -> None:
110144 assert attach_result .exit_code == 0
111145 attach_id = json .loads (attach_result .output )["attach_id" ]
112146
113- # Get schema contents (now nested under catalog)
147+ # Get schema contents using --attach-id option
114148 contents_result = runner .invoke (
115149 cli ,
116150 [
117151 "catalog" ,
118152 "schema" ,
119153 "contents" ,
120- attach_id ,
121154 "main" ,
155+ "--attach-id" ,
156+ attach_id ,
122157 "--server" ,
123158 example_worker ,
124159 ],
@@ -158,8 +193,9 @@ def test_function_info_has_correct_structure(self, example_worker: str) -> None:
158193 "catalog" ,
159194 "schema" ,
160195 "contents" ,
161- attach_id ,
162196 "main" ,
197+ "--attach-id" ,
198+ attach_id ,
163199 "--server" ,
164200 example_worker ,
165201 ],
@@ -195,8 +231,9 @@ def test_scalar_functions_have_correct_type(self, example_worker: str) -> None:
195231 "catalog" ,
196232 "schema" ,
197233 "contents" ,
198- attach_id ,
199234 "main" ,
235+ "--attach-id" ,
236+ attach_id ,
200237 "--server" ,
201238 example_worker ,
202239 ],
@@ -229,8 +266,9 @@ def test_table_functions_have_correct_type(self, example_worker: str) -> None:
229266 "catalog" ,
230267 "schema" ,
231268 "contents" ,
232- attach_id ,
233269 "main" ,
270+ "--attach-id" ,
271+ attach_id ,
234272 "--server" ,
235273 example_worker ,
236274 ],
@@ -262,14 +300,96 @@ def test_schema_list_shows_main(self, example_worker: str) -> None:
262300 )
263301 attach_id = json .loads (attach_result .output )["attach_id" ]
264302
265- # List schemas (now nested under catalog)
303+ # List schemas using --attach-id option
304+ list_result = runner .invoke (
305+ cli ,
306+ [
307+ "catalog" ,
308+ "schema" ,
309+ "list" ,
310+ "--attach-id" ,
311+ attach_id ,
312+ "--server" ,
313+ example_worker ,
314+ ],
315+ )
316+ assert list_result .exit_code == 0
317+
318+ # Parse schema info
319+ schema_info = json .loads (list_result .output )
320+ assert schema_info ["name" ] == "main"
321+ assert schema_info ["is_default" ] is True
322+
323+ def test_schema_list_with_catalog_option (self , example_worker : str ) -> None :
324+ """Schema list works with --catalog option."""
325+ runner = CliRunner ()
326+
327+ # List schemas using --catalog option (auto-attach)
266328 list_result = runner .invoke (
267329 cli ,
268- ["catalog" , "schema" , "list" , attach_id , "--server" , example_worker ],
330+ [
331+ "catalog" ,
332+ "schema" ,
333+ "list" ,
334+ "--catalog" ,
335+ "example" ,
336+ "--server" ,
337+ example_worker ,
338+ ],
269339 )
270340 assert list_result .exit_code == 0
271341
272342 # Parse schema info
273343 schema_info = json .loads (list_result .output )
274344 assert schema_info ["name" ] == "main"
275345 assert schema_info ["is_default" ] is True
346+
347+
348+ class TestCLIAttachIdCatalogOptions :
349+ """Tests for --attach-id and --catalog option validation."""
350+
351+ def test_mutual_exclusivity (self , example_worker : str ) -> None :
352+ """Error when both --attach-id and --catalog are specified."""
353+ runner = CliRunner ()
354+
355+ # First get an attach_id
356+ attach_result = runner .invoke (
357+ cli ,
358+ ["catalog" , "attach" , "example" , "--server" , example_worker ],
359+ )
360+ attach_id = json .loads (attach_result .output )["attach_id" ]
361+
362+ # Try to use both options
363+ result = runner .invoke (
364+ cli ,
365+ [
366+ "catalog" ,
367+ "schema" ,
368+ "list" ,
369+ "--attach-id" ,
370+ attach_id ,
371+ "--catalog" ,
372+ "example" ,
373+ "--server" ,
374+ example_worker ,
375+ ],
376+ )
377+ assert result .exit_code != 0
378+ assert "Cannot specify both" in result .output
379+
380+ def test_requires_attach_id_or_catalog (self , example_worker : str ) -> None :
381+ """Error when neither --attach-id nor --catalog is specified."""
382+ runner = CliRunner ()
383+
384+ result = runner .invoke (
385+ cli ,
386+ [
387+ "catalog" ,
388+ "schema" ,
389+ "list" ,
390+ "--server" ,
391+ example_worker ,
392+ ],
393+ )
394+ assert result .exit_code != 0
395+ assert "Must specify either" in result .output
0 commit comments