@@ -165,3 +165,114 @@ async def test_get_spec_not_loaded(self, spec_manager_integration: ApiSpecManage
165
165
166
166
assert result == SAMPLE_SPEC
167
167
mock_fetch .assert_called_once ()
168
+
169
+ @pytest .mark .asyncio
170
+ async def test_comprehensive_spec_retrieval (self , spec_manager_integration : ApiSpecManager ):
171
+ """
172
+ Comprehensive test of API spec retrieval and functionality.
173
+ This test exactly mirrors the main() function to ensure all aspects work correctly.
174
+ """
175
+ # Create a fresh instance to avoid any cached data from other tests
176
+ from supabase_mcp .services .api .spec_manager import LOCAL_SPEC_PATH , ApiSpecManager
177
+
178
+ spec_manager = ApiSpecManager ()
179
+
180
+ # Print the path being used (for debugging)
181
+ print (f"\n Test is looking for spec at: { LOCAL_SPEC_PATH } " )
182
+
183
+ # Load the spec
184
+ spec = await spec_manager .get_spec ()
185
+ assert spec is not None , "Spec should be loaded successfully"
186
+
187
+ # 1. Test get_all_domains
188
+ all_domains = spec_manager .get_all_domains ()
189
+ print (f"\n All domains: { all_domains } " )
190
+ assert len (all_domains ) > 0 , "Should have at least one domain"
191
+
192
+ # Verify all expected domains are present
193
+ expected_domains = [
194
+ "Analytics" ,
195
+ "Auth" ,
196
+ "Database" ,
197
+ "Domains" ,
198
+ "Edge Functions" ,
199
+ "Environments" ,
200
+ "OAuth" ,
201
+ "Organizations" ,
202
+ "Projects" ,
203
+ "Rest" ,
204
+ "Secrets" ,
205
+ "Storage" ,
206
+ ]
207
+ for domain in expected_domains :
208
+ assert domain in all_domains , f"Domain '{ domain } ' should be in the list of domains"
209
+
210
+ # 2. Test get_all_paths_and_methods
211
+ all_paths = spec_manager .get_all_paths_and_methods ()
212
+ assert len (all_paths ) > 0 , "Should have at least one path"
213
+
214
+ # Sample a few paths to verify
215
+ sample_paths = list (all_paths .keys ())[:5 ]
216
+ print ("\n Sample paths:" )
217
+ for path in sample_paths :
218
+ print (f" { path } :" )
219
+ assert path .startswith ("/v1/" ), f"Path { path } should start with /v1/"
220
+ assert len (all_paths [path ]) > 0 , f"Path { path } should have at least one method"
221
+ for method , operation_id in all_paths [path ].items ():
222
+ print (f" { method } : { operation_id } " )
223
+ assert method .lower () in ["get" , "post" , "put" , "patch" , "delete" ], f"Method { method } should be valid"
224
+ assert operation_id .startswith ("v1-" ), f"Operation ID { operation_id } should start with v1-"
225
+
226
+ # 3. Test get_paths_and_methods_by_domain for each domain
227
+ for domain in expected_domains :
228
+ domain_paths = spec_manager .get_paths_and_methods_by_domain (domain )
229
+ assert len (domain_paths ) > 0 , f"Domain { domain } should have at least one path"
230
+ print (f"\n { domain } domain has { len (domain_paths )} paths" )
231
+
232
+ # 4. Test Edge Functions domain specifically
233
+ edge_paths = spec_manager .get_paths_and_methods_by_domain ("Edge Functions" )
234
+ print ("\n Edge Functions Paths and Methods:" )
235
+ for path in edge_paths :
236
+ print (f" { path } " )
237
+ for method , operation_id in edge_paths [path ].items ():
238
+ print (f" { method } : { operation_id } " )
239
+
240
+ # Verify specific Edge Functions paths exist
241
+ expected_edge_paths = [
242
+ "/v1/projects/{ref}/functions" ,
243
+ "/v1/projects/{ref}/functions/{function_slug}" ,
244
+ "/v1/projects/{ref}/functions/deploy" ,
245
+ ]
246
+ for path in expected_edge_paths :
247
+ assert path in edge_paths , f"Expected path { path } should be in Edge Functions domain"
248
+
249
+ # 5. Test get_spec_for_path_and_method
250
+ # Test for Edge Functions
251
+ path = "/v1/projects/{ref}/functions"
252
+ method = "GET"
253
+ full_spec = spec_manager .get_spec_for_path_and_method (path , method )
254
+ assert full_spec is not None , f"Should find spec for { method } { path } "
255
+ assert "operationId" in full_spec , "Spec should include operationId"
256
+ assert full_spec ["operationId" ] == "v1-list-all-functions" , "Should have correct operationId"
257
+
258
+ # Test for another domain (Auth)
259
+ auth_path = "/v1/projects/{ref}/config/auth"
260
+ auth_method = "GET"
261
+ auth_spec = spec_manager .get_spec_for_path_and_method (auth_path , auth_method )
262
+ assert auth_spec is not None , f"Should find spec for { auth_method } { auth_path } "
263
+ assert "operationId" in auth_spec , "Auth spec should include operationId"
264
+
265
+ # 6. Test get_spec_part
266
+ # Get a specific schema
267
+ schema = spec_manager .get_spec_part ("components" , "schemas" , "FunctionResponse" )
268
+ assert schema is not None , "Should find FunctionResponse schema"
269
+ assert "properties" in schema , "Schema should have properties"
270
+
271
+ # 7. Test caching behavior
272
+ # Call get_spec again - should use cached version
273
+ import time
274
+
275
+ start_time = time .time ()
276
+ await spec_manager .get_spec ()
277
+ end_time = time .time ()
278
+ assert (end_time - start_time ) < 0.1 , "Cached spec retrieval should be fast"
0 commit comments