|
|
@@ -306,3 +306,70 @@ TEST(Embeddings, BaseEndingInV1DuplicatesTheVersionSegment) {
|
|
|
auto right = splitEmbeddingBase("https://openrouter.ai/api");
|
|
|
EXPECT_EQ(right.path + "/v1/embeddings", "/api/v1/embeddings");
|
|
|
}
|
|
|
+
|
|
|
+// THE DEFECT: an unreachable provider and a provider that never answers used to
|
|
|
+// produce the IDENTICAL message, "could not reach embedding endpoint", because
|
|
|
+// httplib hands back an empty Result for both and nothing read `res.error()`.
|
|
|
+// The operator warning one layer up prints the windows we ALLOWED, so neither
|
|
|
+// the message nor the log could say which phase expired, and a live diagnosis
|
|
|
+// had to be recovered from the gap between two journal timestamps.
|
|
|
+//
|
|
|
+// These two tests are a PAIR and are only worth anything together: the first
|
|
|
+// alone would pass against a message that named "read" unconditionally, and the
|
|
|
+// second alone would pass against one that named "connect" unconditionally.
|
|
|
+// What has to hold is that the two DIFFER and each names its own phase.
|
|
|
+TEST(Embeddings, AReadThatNeverAnswersSaysSOandCarriesTheElapsedTime) {
|
|
|
+ httplib::Server mock;
|
|
|
+ // Accepts the connection, then outlives the client's read timeout. So
|
|
|
+ // connect succeeded and the READ is what ran out - the shape measured on
|
|
|
+ // prod, where the second rung's failures landed within 70 ms of their 3 s
|
|
|
+ // read window while the connect cap was 2 s.
|
|
|
+ mock.Post("/v1/embeddings", [](const httplib::Request&, httplib::Response& res) {
|
|
|
+ std::this_thread::sleep_for(std::chrono::seconds(3));
|
|
|
+ res.set_content(R"({"data":[{"embedding":[1]}]})", "application/json");
|
|
|
+ });
|
|
|
+ int port = mock.bind_to_any_port("127.0.0.1");
|
|
|
+ std::thread t([&]{ mock.listen_after_bind(); });
|
|
|
+ EmbeddingClient cli("http://127.0.0.1:" + std::to_string(port), "k", 2 /*connect*/, 1 /*read*/);
|
|
|
+ std::string msg;
|
|
|
+ try {
|
|
|
+ cli.embed("m", "hello");
|
|
|
+ FAIL() << "a server that never answers inside the read window must throw";
|
|
|
+ } catch (const ApiError& e) {
|
|
|
+ msg = e.what();
|
|
|
+ // The code is deliberately UNCHANGED: a consumer branches on it.
|
|
|
+ EXPECT_EQ(e.slug, "embedding_unreachable");
|
|
|
+ }
|
|
|
+ // httplib's own wording: Error::Read is "Failed to read connection",
|
|
|
+ // Error::Connection is "Could not establish connection". Matching on
|
|
|
+ // "connection" would match BOTH, which is how a pair like this quietly
|
|
|
+ // stops discriminating - so each arm matches the word only its own kind has.
|
|
|
+ EXPECT_NE(msg.find("read"), std::string::npos) << msg;
|
|
|
+ EXPECT_EQ(msg.find("establish"), std::string::npos) << msg;
|
|
|
+ // The elapsed time is the half that makes the phase checkable rather than
|
|
|
+ // merely asserted: a read window of 1 s cannot expire in 50 ms.
|
|
|
+ EXPECT_NE(msg.find("ms"), std::string::npos) << msg;
|
|
|
+ mock.stop(); t.join();
|
|
|
+}
|
|
|
+
|
|
|
+TEST(Embeddings, ARefusedConnectionNamesTheCONNECTphaseInstead) {
|
|
|
+ // Port 1 on loopback: the kernel answers RST immediately, so connect FAILS
|
|
|
+ // rather than hanging. The first version of this test bound a port with
|
|
|
+ // bind_to_any_port and let the Server go out of scope, assuming that closed
|
|
|
+ // the listener - it does not, so connect SUCCEEDED, nothing accepted, and
|
|
|
+ // the call died at the 1 s READ timeout reporting "Failed to read
|
|
|
+ // connection". It was indistinguishable from the test above, which is
|
|
|
+ // exactly the conflation this pair exists to rule out, and it was only
|
|
|
+ // visible because the OTHER arm asserts the absence of this one's wording.
|
|
|
+ EmbeddingClient cli("http://127.0.0.1:1", "k", 2, 1);
|
|
|
+ std::string msg;
|
|
|
+ try {
|
|
|
+ cli.embed("m", "hello");
|
|
|
+ FAIL() << "a refused connection must throw";
|
|
|
+ } catch (const ApiError& e) {
|
|
|
+ msg = e.what();
|
|
|
+ EXPECT_EQ(e.slug, "embedding_unreachable");
|
|
|
+ }
|
|
|
+ EXPECT_NE(msg.find("establish"), std::string::npos) << msg;
|
|
|
+ EXPECT_EQ(msg.find("read"), std::string::npos) << msg;
|
|
|
+}
|