|
@@ -214,3 +214,67 @@ TEST(HostRegistry, SizeCountsEveryRegisteredName) {
|
|
|
EXPECT_EQ(r.size(), 5u) << "admin + global + 3 project hostnames";
|
|
EXPECT_EQ(r.size(), 5u) << "admin + global + 3 project hostnames";
|
|
|
EXPECT_FALSE(r.empty());
|
|
EXPECT_FALSE(r.empty());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+// --- serialisation: a hostname has to survive the document round trip -------
|
|
|
|
|
+//
|
|
|
|
|
+// These live here rather than in test_stores.cpp because they are pure: the
|
|
|
|
|
+// store's job is tested there, and what a STORED document means is tested here.
|
|
|
|
|
+
|
|
|
|
|
+#include "project_settings.hpp"
|
|
|
|
|
+
|
|
|
|
|
+using svapi::ProjectSettings;
|
|
|
|
|
+
|
|
|
|
|
+TEST(ProjectSettingsHostnames, RoundTripsHostAndStyle) {
|
|
|
|
|
+ ProjectSettings p;
|
|
|
|
|
+ p.project = "novitax";
|
|
|
|
|
+ p.hostnames = {{"nt.kb.smartbotics.ai", PathStyle::Short},
|
|
|
|
|
+ {"portal.novitax.example", PathStyle::Full}};
|
|
|
|
|
+ const ProjectSettings back = ProjectSettings::fromJson(p.toJson());
|
|
|
|
|
+ ASSERT_EQ(back.hostnames.size(), 2u);
|
|
|
|
|
+ EXPECT_EQ(back.hostnames[0].host, "nt.kb.smartbotics.ai");
|
|
|
|
|
+ EXPECT_EQ(back.hostnames[0].pathStyle, PathStyle::Short);
|
|
|
|
|
+ EXPECT_EQ(back.hostnames[1].host, "portal.novitax.example");
|
|
|
|
|
+ EXPECT_EQ(back.hostnames[1].pathStyle, PathStyle::Full)
|
|
|
|
|
+ << "the per-hostname style must survive storage, or every hostname silently "
|
|
|
|
|
+ "becomes the default shape after a restart";
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+TEST(ProjectSettingsHostnames, EmittedAsAnArrayEvenWhenEmpty) {
|
|
|
|
|
+ // "No hostnames" and "a server that does not know about hostnames" must not
|
|
|
|
|
+ // look the same to a reader - this file's most repeated trap.
|
|
|
|
|
+ const nlohmann::json j = ProjectSettings{}.toJson();
|
|
|
|
|
+ ASSERT_TRUE(j.contains("hostnames"));
|
|
|
|
|
+ EXPECT_TRUE(j.at("hostnames").is_array());
|
|
|
|
|
+ EXPECT_TRUE(j.at("hostnames").empty());
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+TEST(ProjectSettingsHostnames, AcceptsTheBareStringSpellingAndDefaultsToShort) {
|
|
|
|
|
+ // So a hand-written document stays readable.
|
|
|
|
|
+ const nlohmann::json j = {{"project", "p"}, {"hostnames", {"a.example.com"}}};
|
|
|
|
|
+ const ProjectSettings p = ProjectSettings::fromJson(j);
|
|
|
|
|
+ ASSERT_EQ(p.hostnames.size(), 1u);
|
|
|
|
|
+ EXPECT_EQ(p.hostnames[0].host, "a.example.com");
|
|
|
|
|
+ EXPECT_EQ(p.hostnames[0].pathStyle, PathStyle::Short);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+TEST(ProjectSettingsHostnames, AnUnknownStyleIsShortRatherThanAnError) {
|
|
|
|
|
+ // A document written by a NEWER server must not take a project offline -
|
|
|
|
|
+ // the same forward-compatibility rule the function descriptor follows for
|
|
|
|
|
+ // an unknown key.
|
|
|
|
|
+ const nlohmann::json j = {{"project", "p"},
|
|
|
|
|
+ {"hostnames", {{{"host", "a.example.com"}, {"path_style", "sideways"}}}}};
|
|
|
|
|
+ const ProjectSettings p = ProjectSettings::fromJson(j);
|
|
|
|
|
+ ASSERT_EQ(p.hostnames.size(), 1u);
|
|
|
|
|
+ EXPECT_EQ(p.hostnames[0].pathStyle, PathStyle::Short);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+TEST(ProjectSettingsHostnames, AMalformedEntryIsSkippedWithoutLosingTheRest) {
|
|
|
|
|
+ // A typo in one hostname must not cost the project its embedding overrides.
|
|
|
|
|
+ const nlohmann::json j = {{"project", "p"},
|
|
|
|
|
+ {"default_embedding_model", "m"},
|
|
|
|
|
+ {"hostnames", {7, nlohmann::json::object(), "ok.example.com"}}};
|
|
|
|
|
+ const ProjectSettings p = ProjectSettings::fromJson(j);
|
|
|
|
|
+ EXPECT_EQ(p.defaultEmbeddingModel, "m") << "the rest of the document survived";
|
|
|
|
|
+ ASSERT_EQ(p.hostnames.size(), 1u);
|
|
|
|
|
+ EXPECT_EQ(p.hostnames[0].host, "ok.example.com");
|
|
|
|
|
+}
|