|
|
@@ -718,3 +718,96 @@ TEST(HostPrelude, AMailSendRefusesAnUnsendableMessageBeforeConnecting) {
|
|
|
" attachments: [{ filename: 'x', base64: 'AAEC', text: 'y' }] });",
|
|
|
"ambiguous_body");
|
|
|
}
|
|
|
+
|
|
|
+// --- unknown options on the VECTOR calls ----------------------------------
|
|
|
+//
|
|
|
+// These matter more than the HTTP equivalent, because the prelude builds the
|
|
|
+// payload from an explicit key list: an unrecognised option is DISCARDED here
|
|
|
+// before the host can see it, so the host cannot refuse what never arrives.
|
|
|
+// That is how embedTimeoutMs came to be honoured host-side and never sent by
|
|
|
+// the prelude, while a consumer believed a bound was in force.
|
|
|
+//
|
|
|
+// Measured over HTTP, where the same hole was open: `topK` returned the
|
|
|
+// DEFAULT top_k, and a singular `filter` returned the rows the caller meant to
|
|
|
+// EXCLUDE - both under a 200.
|
|
|
+
|
|
|
+TEST(HostPrelude, SearchRefusesAMisspelledOptionBeforeReachingTheHost) {
|
|
|
+ // expectRefused also asserts the host was never called, which is the
|
|
|
+ // property that matters: a refusal arriving after the search ran would be
|
|
|
+ // no protection at all.
|
|
|
+ expectRefused("ctx.collections('c').search({ query_text: 'x', topK: 3 });", "validation");
|
|
|
+ expectRefused("ctx.collections('c').search({ query_text: 'x', minScore: 0.9 });", "validation");
|
|
|
+}
|
|
|
+
|
|
|
+TEST(HostPrelude, SearchRefusesTheSingularFilterThatSilentlyWIDENEDTheResult) {
|
|
|
+ // The dangerous spelling: `filter` instead of `filters` dropped the filter
|
|
|
+ // and handed back the rows it existed to withhold.
|
|
|
+ expectRefused("ctx.collections('c').search({ query_text: 'x', filter: ['a:eq:b'] });",
|
|
|
+ "validation");
|
|
|
+}
|
|
|
+
|
|
|
+TEST(HostPrelude, TheRefusalNamesTheOffendingKeyAndWhatIsAccepted) {
|
|
|
+ const nlohmann::json out =
|
|
|
+ runPrelude("ctx.collections('c').search({ query_text: 'x', topK: 3 });");
|
|
|
+ ASSERT_FALSE(out.at("threw").is_null()) << out.dump();
|
|
|
+ const std::string msg = out.at("threw").at("message").get<std::string>();
|
|
|
+ EXPECT_NE(msg.find("topK"), std::string::npos) << msg;
|
|
|
+ // The accepted set, because the usual cause is a plausible spelling of a
|
|
|
+ // real option rather than an invented one.
|
|
|
+ EXPECT_NE(msg.find("top_k"), std::string::npos) << msg;
|
|
|
+ EXPECT_NE(msg.find("min_score"), std::string::npos) << msg;
|
|
|
+}
|
|
|
+
|
|
|
+TEST(HostPrelude, StoreRefusesAnUnknownOptionToo) {
|
|
|
+ expectRefused("ctx.collections('c').store({ text: 'x', ttlSeconds: 60 });", "validation");
|
|
|
+}
|
|
|
+
|
|
|
+// --- and the falsifying half: everything documented must still pass --------
|
|
|
+
|
|
|
+TEST(HostPrelude, SearchStillAcceptsEveryDocumentedOption) {
|
|
|
+ // A refusal that refused everything would satisfy every test above while
|
|
|
+ // breaking every caller, so this is the one that makes them mean anything.
|
|
|
+ const nlohmann::json out = runPrelude(
|
|
|
+ "ctx.collections('c').search({ query_text: 'x', top_k: 3, min_score: 0.5,"
|
|
|
+ " filters: ['a:eq:b'], embedTimeoutMs: 2000 });");
|
|
|
+ EXPECT_TRUE(out.at("threw").is_null()) << out.at("threw").dump();
|
|
|
+ EXPECT_EQ(out.at("calls").size(), 1u) << out.dump();
|
|
|
+}
|
|
|
+
|
|
|
+TEST(HostPrelude, SearchStillAcceptsAQueryVector) {
|
|
|
+ const nlohmann::json out =
|
|
|
+ runPrelude("ctx.collections('c').search({ query_vector: [0.1, 0.2], top_k: 1 });");
|
|
|
+ EXPECT_TRUE(out.at("threw").is_null()) << out.at("threw").dump();
|
|
|
+}
|
|
|
+
|
|
|
+TEST(HostPrelude, StoreStillAcceptsEveryDocumentedOption) {
|
|
|
+ const nlohmann::json out = runPrelude(
|
|
|
+ "ctx.collections('c').store({ text: 'x', metadata: { a: 1 }, id: 'i',"
|
|
|
+ " ttl_seconds: 60, embedTimeoutMs: 2000 });");
|
|
|
+ EXPECT_TRUE(out.at("threw").is_null()) << out.at("threw").dump();
|
|
|
+}
|
|
|
+
|
|
|
+TEST(HostPrelude, AnEXPLICITLYUndefinedOptionIsNotAMisspelling) {
|
|
|
+ // `{ ...partial, top_k: undefined }` is ordinary JS for "not set", and
|
|
|
+ // must not read as a typo.
|
|
|
+ const nlohmann::json out = runPrelude(
|
|
|
+ "ctx.collections('c').search({ query_text: 'x', top_k: undefined,"
|
|
|
+ " min_score: undefined });");
|
|
|
+ EXPECT_TRUE(out.at("threw").is_null()) << out.at("threw").dump();
|
|
|
+}
|
|
|
+
|
|
|
+TEST(HostPrelude, TheChainedFilterStillMergesWithAnExplicitFiltersArray) {
|
|
|
+ // The refusal must not have broken the merge: `.filter()` on the chain and
|
|
|
+ // `filters:` in the call are APPENDED, never one replacing the other.
|
|
|
+ const nlohmann::json out = runPrelude(
|
|
|
+ "ctx.collections('c').filter('x:eq:1').search({ query_text: 'q',"
|
|
|
+ " filters: ['y:eq:2'] });");
|
|
|
+ EXPECT_TRUE(out.at("threw").is_null()) << out.at("threw").dump();
|
|
|
+ // onlyCall returns the recorded ARGS: (collection, op, payload).
|
|
|
+ const nlohmann::json args = onlyCall(out, "db");
|
|
|
+ ASSERT_GE(args.size(), 3u) << args.dump();
|
|
|
+ const nlohmann::json& sent = args.at(2).at("filters");
|
|
|
+ EXPECT_EQ(sent.size(), 2u) << sent.dump();
|
|
|
+ EXPECT_EQ(sent.at(0), "x:eq:1") << sent.dump();
|
|
|
+ EXPECT_EQ(sent.at(1), "y:eq:2") << sent.dump();
|
|
|
+}
|