فهرست منبع

fix: the new settings are WRITABLE, not only readable (0.18.1)

The four settings added earlier in 0.18.1 went into Settings, into
fromJson/toJson and into the GET, and NOT into the PUT handler, which is an
explicit allow-list. So PUT /api/v1/settings answered 200 and silently
discarded them, and a GET afterwards returned the default - the
accepted-and-ignored defect this file documents three times over, committed
in the same release that added the fields.

A setting that cannot be written is worse than no setting: it reads back
plausibly however many times you write it, so an operator would conclude the
value was in force. For embedding_connect_cap_sec specifically the cost would
have been that the 2 s default could not be moved without another release,
which is the one escape hatch the behaviour change needed.

ALL 1361 UNIT TESTS PASSED WITH THE DEFECT PRESENT, and that is the part
worth keeping. They exercise fromJson/toJson, which was never the layer that
dropped the field. It was caught by round-tripping a write against the BUILT
DEB in a container - PUT 200, GET still 2 - which is the only check that
could have seen it. A consumer put the shape better than I did: both suites
were aimed one layer away from the failure.

So the test added here is an INTEGRATION test that drives the route, and it
asserts three things rather than one: that each of the four survives the PUT,
that a neighbour nobody mentioned is unchanged (a PUT rebuilds from the
current snapshot, so resetting a sibling is the likelier damage), and that 0
round-trips as 0 rather than being coerced to the default - because 0 means
"no absolute cap" and is how an operator restores the pre-0.18.1 arithmetic.
Remove any one of the four handler lines and exactly this test goes red.

THE CLASS IS STILL OPEN AND IS NOT FIXED HERE. A consumer pointed out, with
our own precedents attached, that adding four fields to an allow-list leaves
the next four in the same hole, and that 422 on an unknown key is what closes
it - the same argument that settled manualTrigger() dropping keys outside its
six, and PUT ?ttl_seconds= answering 201 while ignoring the one parameter the
request existed for. They are right, and it is deliberately not in this
commit: the GET returns openai_api_key_set and captcha_secret_set, which are
NOT settable keys, so a blanket refusal would 422 any caller that reads the
document and sends it back. The webui sends a partial patch today and would
survive, but SettingsView omits only openai_api_key_set from the patch type,
so captcha_secret_set can legitimately reach the route. Closing the class
needs that mirror-key question answered and a sweep of the settings pages,
which is a change to a public refusal and belongs with the owner rather than
inside a hotfix.

1365/1365 tests pass.
fszontagh 3 هفته پیش
والد
کامیت
71d9f006fe
2فایلهای تغییر یافته به همراه60 افزوده شده و 0 حذف شده
  1. 15 0
      src/handlers/settings.cpp
  2. 45 0
      tests/test_api_integration.cpp

+ 15 - 0
src/handlers/settings.cpp

@@ -45,6 +45,21 @@ void registerSettingsRoutes(ApiServer& s) {
             updated.embeddingConnectTimeoutSec = body["embedding_connect_timeout_sec"].get<uint32_t>();
         if (body.contains("embedding_read_timeout_sec"))
             updated.embeddingReadTimeoutSec = body["embedding_read_timeout_sec"].get<uint32_t>();
+        // 0.18.1. These four were added to Settings and to the GET in the same
+        // commit and NOT here, so the route answered 200 and discarded them -
+        // a setting that reads back its default however many times you write it
+        // is the accepted-and-ignored defect this codebase keeps meeting, and
+        // it was caught by a round-trip check against the built deb rather than
+        // by any test. The handler is an explicit allow-list, so adding a field
+        // to Settings is never enough on its own.
+        if (body.contains("embedding_connect_cap_sec"))
+            updated.embeddingConnectCapSec = body["embedding_connect_cap_sec"].get<uint32_t>();
+        if (body.contains("vector_filter_scan_cap"))
+            updated.vectorFilterScanCap = body["vector_filter_scan_cap"].get<uint32_t>();
+        if (body.contains("captcha_connect_timeout_sec"))
+            updated.captchaConnectTimeoutSec = body["captcha_connect_timeout_sec"].get<uint32_t>();
+        if (body.contains("captcha_read_timeout_sec"))
+            updated.captchaReadTimeoutSec = body["captcha_read_timeout_sec"].get<uint32_t>();
         if (body.contains("embedding_cache_size"))
             updated.embeddingCacheSize = body["embedding_cache_size"].get<uint32_t>();
         if (body.contains("embedding_cache_ttl_sec"))

+ 45 - 0
tests/test_api_integration.cpp

@@ -320,6 +320,51 @@ TEST_F(ApiFixture, SettingsGetMasksSecretForAdmin) {
     EXPECT_TRUE(body.contains("default_embedding_model"));
 }
 
+// 0.18.1: EVERY operational setting must survive the ROUTE, not only
+// Settings::fromJson. All four of these were added to the struct and to the GET
+// and NOT to the PUT handler, which is an explicit allow-list - so the route
+// answered 200 and silently discarded them, and a GET afterwards showed the
+// default. Nothing in the unit tests could see it, because they exercise
+// fromJson/toJson and never the handler; it was caught by a round-trip against
+// the built deb. This test exists so "a setting is not done until a test drives
+// its ROUTE" is enforced rather than remembered.
+//
+// It is also the falsifiable pairing: remove any one of the four lines from
+// handlers/settings.cpp and exactly this test goes red.
+TEST_F(ApiFixture, EveryOperationalSettingSurvivesThePutRoute) {
+    const nlohmann::json body{{"embedding_connect_cap_sec", 1},
+                              {"vector_filter_scan_cap", 20000},
+                              {"captcha_connect_timeout_sec", 3},
+                              {"captcha_read_timeout_sec", 7}};
+    auto put = admin().Put("/api/v1/settings", body.dump(), "application/json");
+    ASSERT_TRUE(put);
+    ASSERT_EQ(put->status, 200);
+
+    auto get = admin().Get("/api/v1/settings");
+    ASSERT_TRUE(get);
+    ASSERT_EQ(get->status, 200);
+    auto g = nlohmann::json::parse(get->body);
+    EXPECT_EQ(g["embedding_connect_cap_sec"].get<uint32_t>(), 1u);
+    EXPECT_EQ(g["vector_filter_scan_cap"].get<uint32_t>(), 20000u);
+    EXPECT_EQ(g["captcha_connect_timeout_sec"].get<uint32_t>(), 3u);
+    EXPECT_EQ(g["captcha_read_timeout_sec"].get<uint32_t>(), 7u);
+
+    // A PUT REPLACES the document from the current snapshot, so the real risk
+    // is a neighbouring field being reset rather than the named one failing to
+    // move. Assert one that was never mentioned in the body.
+    EXPECT_EQ(g["embedding_read_timeout_sec"].get<uint32_t>(), 60u);
+
+    // 0 is "no absolute cap", not "no connect time", and it must round-trip as
+    // 0 rather than being coerced back to the default - otherwise an operator
+    // could not restore the pre-0.18.1 arithmetic at all.
+    auto zero = admin().Put("/api/v1/settings",
+        nlohmann::json{{"embedding_connect_cap_sec", 0}}.dump(), "application/json");
+    ASSERT_TRUE(zero);
+    ASSERT_EQ(zero->status, 200);
+    auto g2 = nlohmann::json::parse(admin().Get("/api/v1/settings")->body);
+    EXPECT_EQ(g2["embedding_connect_cap_sec"].get<uint32_t>(), 0u);
+}
+
 // W9 Step 1a: PUT /api/v1/settings changes a field; non-admin gets 403
 TEST_F(ApiFixture, SettingsPutChangesField) {
     // Change default_embedding_model