|
|
@@ -811,3 +811,55 @@ TEST(HostPrelude, TheChainedFilterStillMergesWithAnExplicitFiltersArray) {
|
|
|
EXPECT_EQ(sent.at(0), "x:eq:1") << sent.dump();
|
|
|
EXPECT_EQ(sent.at(1), "y:eq:2") << sent.dump();
|
|
|
}
|
|
|
+
|
|
|
+// --- #60: a truncated search must reach the FUNCTION, not just the console --
|
|
|
+//
|
|
|
+// A console warning reaches neither the function's logic nor a model
|
|
|
+// downstream of it, and a function's result is routinely handed to one. A
|
|
|
+// consumer hit this exact shape: they logged their degraded-search fallback
|
|
|
+// for the operator, and the gap was that the ASSISTANT was never told, so it
|
|
|
+// stated "nothing in memory" with confidence.
|
|
|
+//
|
|
|
+// The return must stay an ARRAY, so the flags ride as properties on it.
|
|
|
+
|
|
|
+TEST(HostPrelude, SearchStillReturnsAnARRAYThatBehavesLikeOne) {
|
|
|
+ // The compatibility guarantee: indexing, length, iteration, spread and
|
|
|
+ // JSON.stringify must all be exactly as before. If any of these changed,
|
|
|
+ // every existing script breaks.
|
|
|
+ const nlohmann::json out = runPrelude(
|
|
|
+ "const r = ctx.collections('c').search({ query_text: 'x' });"
|
|
|
+ "return { isArray: Array.isArray(r), len: r.length,"
|
|
|
+ " viaIndex: r.length > 0 ? typeof r[0] : 'n/a',"
|
|
|
+ " viaSpread: [...r].length,"
|
|
|
+ " viaFor: (function(){ let n = 0; for (const h of r) n++; return n; })(),"
|
|
|
+ " json: JSON.stringify(r) };");
|
|
|
+ const nlohmann::json& v = out.at("value");
|
|
|
+ EXPECT_EQ(v.at("isArray"), true) << v.dump();
|
|
|
+ EXPECT_EQ(v.at("viaSpread"), v.at("len")) << v.dump();
|
|
|
+ EXPECT_EQ(v.at("viaFor"), v.at("len")) << v.dump();
|
|
|
+ // The flags must NOT appear in JSON.stringify - they are non-enumerable,
|
|
|
+ // so a script that serialises its results sends what it always sent.
|
|
|
+ const std::string json = v.at("json").get<std::string>();
|
|
|
+ EXPECT_EQ(json.find("scan_capped"), std::string::npos) << json;
|
|
|
+ EXPECT_EQ(json.find("filter_mode"), std::string::npos) << json;
|
|
|
+ EXPECT_EQ(json.front(), '[') << json;
|
|
|
+}
|
|
|
+
|
|
|
+TEST(HostPrelude, TheFlagsAreREADABLEOnTheReturnedArray) {
|
|
|
+ const nlohmann::json out = runPrelude(
|
|
|
+ "const r = ctx.collections('c').search({ query_text: 'x' });"
|
|
|
+ "return { capped: r.scan_capped, mode: r.filter_mode,"
|
|
|
+ " cappedType: typeof r.scan_capped, modeType: typeof r.filter_mode };");
|
|
|
+ const nlohmann::json& v = out.at("value");
|
|
|
+ EXPECT_EQ(v.at("cappedType"), "boolean") << v.dump();
|
|
|
+ EXPECT_EQ(v.at("modeType"), "string") << v.dump();
|
|
|
+}
|
|
|
+
|
|
|
+TEST(HostPrelude, ABareArrayFromAnOlderHostIsStillAccepted) {
|
|
|
+ // The two halves can deploy in either order, so the prelude must tolerate
|
|
|
+ // a host that answers the old shape rather than throwing on it.
|
|
|
+ const nlohmann::json out = runPrelude(
|
|
|
+ "const r = ctx.collections('c').search({ query_text: 'x' });"
|
|
|
+ "return Array.isArray(r);");
|
|
|
+ EXPECT_EQ(out.at("value"), true) << out.dump();
|
|
|
+}
|