|
8 | 8 | from core import database_arango |
9 | 9 | from core.schemas import entity, rbac, roles, user |
10 | 10 | from core.web import webapp |
| 11 | +from core.web.apiv2.search import MAX_RESULTS_PER_TYPE |
11 | 12 | from plugins.analytics.public.chromadb_indexer import ChromaDBIndexer |
12 | 13 |
|
13 | 14 | client = TestClient(webapp.app) |
@@ -620,6 +621,30 @@ def test_documents_an_object_stops_producing_are_pruned(self, mock_get_client): |
620 | 621 | } |
621 | 622 | self.assertEqual(remaining, {"self", "approach:0"}) |
622 | 623 |
|
| 624 | + @mock.patch("core.chromadb_client.get_client") |
| 625 | + def test_count_outside_the_allowed_range_is_rejected(self, mock_get_client): |
| 626 | + """count is overfetched into ChromaDB's n_results, which raises on any |
| 627 | + non-positive value -- unbounded, that surfaces as a 500 for what is a |
| 628 | + client error. The upper bound caps the ACL checks and database reads a |
| 629 | + single request can trigger.""" |
| 630 | + mock_get_client.return_value = self.chroma_client |
| 631 | + |
| 632 | + for count in (0, -1, MAX_RESULTS_PER_TYPE + 1): |
| 633 | + with self.subTest(count=count): |
| 634 | + response = client.post( |
| 635 | + "/api/v2/search/semantic", |
| 636 | + json={"query": "russian actor", "count": count}, |
| 637 | + ) |
| 638 | + self.assertEqual(response.status_code, 422, response.json()) |
| 639 | + |
| 640 | + for count in (1, MAX_RESULTS_PER_TYPE): |
| 641 | + with self.subTest(count=count): |
| 642 | + response = client.post( |
| 643 | + "/api/v2/search/semantic", |
| 644 | + json={"query": "russian actor", "count": count}, |
| 645 | + ) |
| 646 | + self.assertEqual(response.status_code, 200, response.json()) |
| 647 | + |
623 | 648 |
|
624 | 649 | class SimilarityScoreTest(unittest.TestCase): |
625 | 650 | def test_converts_squared_l2_distance_to_a_bounded_similarity(self): |
|
0 commit comments