@@ -139,3 +139,97 @@ def test_list_resources(self, temp_file: Path):
139139 resources = manager .list_resources ()
140140 assert len (resources ) == 2
141141 assert resources == [resource1 , resource2 ]
142+
143+ def test_list_resources_with_prefix (self , temp_file : Path ):
144+ """Test listing resources with prefix filtering."""
145+ manager = ResourceManager ()
146+
147+ # Add resources with different URIs
148+ resource1 = FileResource (
149+ uri = FileUrl ("file:///data/images/test.jpg" ),
150+ name = "test_image" ,
151+ path = temp_file ,
152+ )
153+ resource2 = FileResource (
154+ uri = FileUrl ("file:///data/docs/test.txt" ),
155+ name = "test_doc" ,
156+ path = temp_file ,
157+ )
158+ resource3 = FileResource (
159+ uri = FileUrl ("file:///other/test.txt" ),
160+ name = "other_test" ,
161+ path = temp_file ,
162+ )
163+
164+ manager .add_resource (resource1 )
165+ manager .add_resource (resource2 )
166+ manager .add_resource (resource3 )
167+
168+ # Test prefix filtering
169+ data_resources = manager .list_resources (prefix = "file:///data/" )
170+ assert len (data_resources ) == 2
171+ assert resource1 in data_resources
172+ assert resource2 in data_resources
173+
174+ # More specific prefix
175+ image_resources = manager .list_resources (prefix = "file:///data/images/" )
176+ assert len (image_resources ) == 1
177+ assert resource1 in image_resources
178+
179+ # No matches
180+ no_matches = manager .list_resources (prefix = "file:///nonexistent/" )
181+ assert len (no_matches ) == 0
182+
183+ def test_list_templates_with_prefix (self ):
184+ """Test listing templates with prefix filtering."""
185+ manager = ResourceManager ()
186+
187+ # Add templates with different URI patterns
188+ def user_func (user_id : str ) -> str :
189+ return f"User { user_id } "
190+
191+ def post_func (user_id : str , post_id : str ) -> str :
192+ return f"User { user_id } Post { post_id } "
193+
194+ def product_func (product_id : str ) -> str :
195+ return f"Product { product_id } "
196+
197+ template1 = manager .add_template (user_func , uri_template = "http://api.com/users/{user_id}" , name = "user_template" )
198+ template2 = manager .add_template (
199+ post_func , uri_template = "http://api.com/users/{user_id}/posts/{post_id}" , name = "post_template"
200+ )
201+ template3 = manager .add_template (
202+ product_func , uri_template = "http://api.com/products/{product_id}" , name = "product_template"
203+ )
204+
205+ # Test listing all templates
206+ all_templates = manager .list_templates ()
207+ assert len (all_templates ) == 3
208+
209+ # Test prefix filtering - matches both user templates
210+ user_templates = manager .list_templates (prefix = "http://api.com/users/" )
211+ assert len (user_templates ) == 2
212+ assert template1 in user_templates
213+ assert template2 in user_templates
214+
215+ # Test partial materialization - only matches post template
216+ # The template users/{user_id} generates "users/123" not "users/123/"
217+ # But users/{user_id}/posts/{post_id} can generate "users/123/posts/456"
218+ user_123_templates = manager .list_templates (prefix = "http://api.com/users/123/" )
219+ assert len (user_123_templates ) == 1
220+ assert template2 in user_123_templates # users/{user_id}/posts/{post_id} matches
221+
222+ # Without trailing slash, both match
223+ user_123_no_slash = manager .list_templates (prefix = "http://api.com/users/123" )
224+ assert len (user_123_no_slash ) == 2
225+ assert template1 in user_123_no_slash
226+ assert template2 in user_123_no_slash
227+
228+ # Test product prefix
229+ product_templates = manager .list_templates (prefix = "http://api.com/products/" )
230+ assert len (product_templates ) == 1
231+ assert template3 in product_templates
232+
233+ # No matches
234+ no_matches = manager .list_templates (prefix = "http://api.com/orders/" )
235+ assert len (no_matches ) == 0
0 commit comments