Files
moloapp/tests/example/ai/openrouter/inference_test.cpp
T

25 lines
1.8 KiB
C++
Raw Normal View History

// Routes: POST /ai/openrouter/responses, /messages, /model-ref
#include "support/Assert.hpp"
using namespace molo::example::test;
int main() {
Fixture f;
auto post = [&](const std::string& path, const std::string& body) { return f.client->post(path, body, "application/json"); };
auto dry = post("/ai/openrouter/responses", "{\"body\":{\"model\":\"openai/gpt-5.2\",\"input\":\"hi\"}}");
check(dry.status == 200 && contains(dry.body, "createResponses"), "responses dry run");
check(post("/ai/openrouter/responses", "{\"body\":{\"model\":\"m/x\",\"input\":\"hi\"},\"confirm\":true}").status == 503, "responses without key 503");
check(post("/ai/openrouter/responses", "{\"body\":{\"bogus\":1}}").status == 422, "responses undeclared field 422");
auto msg = post("/ai/openrouter/messages", "{\"body\":{\"model\":\"anthropic/claude-sonnet\",\"max_tokens\":8,\"messages\":[]}}");
check(msg.status == 200 && contains(msg.body, "createMessages"), "messages dry run");
check(post("/ai/openrouter/messages", "{\"body\":{\"model\":\"a/b\",\"messages\":[]},\"confirm\":true}").status == 503, "messages without key 503");
check(post("/ai/openrouter/messages", "{\"body\":{\"zzz\":1}}").status == 422, "messages undeclared field 422");
auto ref = post("/ai/openrouter/model-ref", "{\"model\":\"poolside/laguna-s-2.1:free:nitro\"}");
check(ref.status == 200 && contains(ref.body, "\"catalog_id\":\"poolside/laguna-s-2.1:free\""), "model ref resolves the catalog id");
check(contains(ref.body, "\"nitro\""), "routing variants listed");
check(post("/ai/openrouter/model-ref", "{\"model\":\"x:y:z\"}").status == 422, "bad model ref 422");
check(f.client->get("/ai/openrouter/responses").status == 405, "get is 405");
check(f.client->get("/ai/openrouter/messages").status == 405, "messages get is 405");
return finish("ai/openrouter/inference");
}