|
|
@@ -2389,10 +2389,18 @@ TEST_F(ApiFixture, ARecycledCollectionNameInheritsNoConstraint) {
|
|
|
// it. On data that cost money to produce.
|
|
|
TEST_F(ApiFixture, InsertingAVectorlessDocumentIntoAVectorCollectionIsRefused) {
|
|
|
// The sibling of the PUT refusal below, through a different door. Reported
|
|
|
- // from production: a 12448-document collection whose three indexed facets
|
|
|
- // each summed to 12447, the extra row being a query body posted to the
|
|
|
- // documents route by mistake. It read back perfectly and could never be
|
|
|
- // found by a search, which is why the arithmetic was the only symptom.
|
|
|
+ // from production with the only symptom it has: a 12448-document collection
|
|
|
+ // whose three indexed facets each summed to 12447, the extra row being a
|
|
|
+ // query body posted to the documents route by mistake. It read back
|
|
|
+ // perfectly and could never be found by a search.
|
|
|
+ //
|
|
|
+ // THE FIRST VERSION OF THIS TEST WAS TOO WEAK AND LET A HOLE THROUGH. It
|
|
|
+ // asserted that a `text`-carrying POST did not return `vector_missing` -
|
|
|
+ // that is, that the refusal did not fire - and called that a pass. But this
|
|
|
+ // route DOES NOT EMBED; only `.../vectors` does. So the row it accepted was
|
|
|
+ // stored with no vector and was exactly the invisible document the guard
|
|
|
+ // exists to refuse. Asserting "the refusal did not fire" is not the same as
|
|
|
+ // asserting the outcome is good, and only the latter is worth testing.
|
|
|
auto c = admin();
|
|
|
const std::string base = "/api/v1/projects/" + project_ + "/collections";
|
|
|
const std::string ct = "application/json";
|
|
|
@@ -2405,9 +2413,15 @@ TEST_F(ApiFixture, InsertingAVectorlessDocumentIntoAVectorCollectionIsRefused) {
|
|
|
if (!r || r->status != 200) return std::size_t{0};
|
|
|
return nlohmann::json::parse(r->body)["documents"].size();
|
|
|
};
|
|
|
+ auto searchable = [&]() {
|
|
|
+ auto r = c.Post((base + "/vins/search").c_str(),
|
|
|
+ nlohmann::json{{"query_vector",{1.0,0.0,0.0,0.5}},{"top_k",10}}.dump(), ct);
|
|
|
+ if (!r || r->status != 200) return std::size_t{0};
|
|
|
+ return nlohmann::json::parse(r->body)["results"].size();
|
|
|
+ };
|
|
|
ASSERT_EQ(count(), 0u);
|
|
|
|
|
|
- // Exactly the shape that was reported: a body with no vector and no text.
|
|
|
+ // 1. Exactly the shape that was reported: no vector, no text.
|
|
|
auto bad = c.Post((base + "/vins/documents").c_str(),
|
|
|
nlohmann::json{{"filter",{{"sourceType","email"}}},{"limit",60}}.dump(), ct);
|
|
|
ASSERT_TRUE(bad);
|
|
|
@@ -2415,23 +2429,47 @@ TEST_F(ApiFixture, InsertingAVectorlessDocumentIntoAVectorCollectionIsRefused) {
|
|
|
EXPECT_NE(bad->body.find("vector_missing"), std::string::npos) << bad->body;
|
|
|
EXPECT_EQ(count(), 0u) << "the refused insert must not have stored anything";
|
|
|
|
|
|
- // An explicit vector is accepted - the refusal must not block the real
|
|
|
- // write path, or it would be a far worse bug than the one it fixes.
|
|
|
+ // 2. TEXT ALONE IS ALSO REFUSED, and this is the case that caught me. This
|
|
|
+ // route does not embed, so a text-only row would be stored without a vector
|
|
|
+ // and be unfindable forever. The message must point at the route that DOES
|
|
|
+ // embed rather than just saying no.
|
|
|
+ auto textOnly = c.Post((base + "/vins/documents").c_str(),
|
|
|
+ nlohmann::json{{"text","hello"},{"tag","b"}}.dump(), ct);
|
|
|
+ ASSERT_TRUE(textOnly);
|
|
|
+ EXPECT_EQ(textOnly->status, 422) << textOnly->body;
|
|
|
+ EXPECT_NE(textOnly->body.find("vector_missing"), std::string::npos) << textOnly->body;
|
|
|
+ EXPECT_NE(textOnly->body.find("vectors"), std::string::npos)
|
|
|
+ << "the refusal must name the route that embeds: " << textOnly->body;
|
|
|
+ EXPECT_EQ(count(), 0u);
|
|
|
+
|
|
|
+ // 3. An EMPTY text is refused too - the question that exposed all of this.
|
|
|
+ // It needs no special case now: text does not satisfy the guard at all, so
|
|
|
+ // "" and "hello" and absent are one rule rather than three.
|
|
|
+ auto emptyText = c.Post((base + "/vins/documents").c_str(),
|
|
|
+ nlohmann::json{{"text",""}}.dump(), ct);
|
|
|
+ ASSERT_TRUE(emptyText);
|
|
|
+ EXPECT_EQ(emptyText->status, 422) << emptyText->body;
|
|
|
+ EXPECT_EQ(count(), 0u);
|
|
|
+
|
|
|
+ // 4. An explicit vector is accepted AND IS SEARCHABLE. The second half is
|
|
|
+ // the assertion that matters: a guard that let a write through while
|
|
|
+ // leaving it unfindable is the defect, so the test has to look for the row
|
|
|
+ // through a SEARCH rather than through a read.
|
|
|
auto withVec = c.Post((base + "/vins/documents").c_str(),
|
|
|
nlohmann::json{{"_vector",{1.0,0.0,0.0,0.5}},{"tag","a"}}.dump(), ct);
|
|
|
ASSERT_TRUE(withVec);
|
|
|
- EXPECT_EQ(withVec->status, 201) << withVec->body;
|
|
|
-
|
|
|
- // And `text` satisfies it too, because a row with text gets embedded and IS
|
|
|
- // searchable. Refusing it would have broken ordinary ingest, which is the
|
|
|
- // common case - so this asserts the guard is not over-broad. The insert may
|
|
|
- // fail for want of an embedding provider in this environment; what must NOT
|
|
|
- // happen is a 422 naming vector_missing.
|
|
|
- auto withText = c.Post((base + "/vins/documents").c_str(),
|
|
|
- nlohmann::json{{"text","hello"},{"tag","b"}}.dump(), ct);
|
|
|
- ASSERT_TRUE(withText);
|
|
|
- EXPECT_EQ(withText->body.find("vector_missing"), std::string::npos)
|
|
|
- << "text must satisfy the guard: " << withText->body;
|
|
|
+ ASSERT_EQ(withVec->status, 201) << withVec->body;
|
|
|
+ EXPECT_EQ(count(), 1u);
|
|
|
+ EXPECT_EQ(searchable(), 1u) << "an accepted row must be findable, which is the entire point";
|
|
|
+
|
|
|
+ // 5. And the vectors route, which embeds, still accepts a bare vector -
|
|
|
+ // proof the refusal has not blocked the path it tells callers to use.
|
|
|
+ auto viaVectors = c.Post((base + "/vins/vectors").c_str(),
|
|
|
+ nlohmann::json{{"vector",{0.0,1.0,0.0,0.0}},
|
|
|
+ {"metadata",{{"tag","c"}}}}.dump(), ct);
|
|
|
+ ASSERT_TRUE(viaVectors);
|
|
|
+ EXPECT_EQ(viaVectors->status, 201) << viaVectors->body;
|
|
|
+ EXPECT_EQ(searchable(), 2u);
|
|
|
|
|
|
auto del = c.Delete((base + "/vins").c_str());
|
|
|
ASSERT_TRUE(del);
|