Files
moloapp/tests/example/agent/models/post_routes_test.cpp
T
retoorandClaude Sonnet 5.5 6b731643bf feat(clients): models: Gemini on Vertex, Model Garden, Claude, endpoint models, media, VertexModel
One call table verified against Discovery (29 calls), live-verified read-only
with an express key and a service account token, /agent/models example routes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 04:40:00 +02:00

58 lines
2.5 KiB
C++

// Routes: POST /agent/models/{generate,count,embed,claude,list,endpoint,image,music,video,video/status}
// Without a credential every one is 503 google_not_configured and sends
// nothing; with one, bad input is 422 before any network traffic; GET is 405.
#include <cstdlib>
#include "support/GoogleRig.hpp"
using namespace molo::example::test;
namespace {
struct Route {
const char* path;
const char* valid; // well formed body
const char* bad; // rejected locally
};
const Route kRoutes[] = {
{"/agent/models/generate", "{\"prompt\":\"hi\"}", "{\"prompt\":\"\"}"},
{"/agent/models/count", "{\"prompt\":\"hi\"}", "{\"prompt\":\"\"}"},
{"/agent/models/embed", "{\"text\":\"hi\"}", "{\"text\":\"\"}"},
{"/agent/models/claude", "{\"prompt\":\"hi\"}", "{\"prompt\":\"\"}"},
{"/agent/models/list", "{\"publisher\":\"google\"}", "{\"publisher\":\"a/b\"}"},
{"/agent/models/endpoint", "{\"endpoint\":\"77\",\"prompt\":\"hi\"}",
"{\"endpoint\":\"7/7\",\"prompt\":\"hi\"}"},
{"/agent/models/image", "{\"prompt\":\"a cat\"}", "{\"prompt\":\"a cat\",\"count\":\"9\"}"},
{"/agent/models/music", "{\"prompt\":\"calm\"}", "{\"prompt\":\"\"}"},
{"/agent/models/video", "{\"prompt\":\"waves\"}", "{\"prompt\":\"waves\",\"duration_seconds\":\"99\"}"},
{"/agent/models/video/status", "{\"operation\":\"projects/p/locations/l/operations/1\"}",
"{\"operation\":\"../x\"}"},
};
} // namespace
int main() {
setenv("GOOGLE_CLOUD_PROJECT", "demo-proj", 1);
{
GoogleRig none(false);
Fixture f(none.client);
for (const Route& r : kRoutes) {
auto res = f.client->post(r.path, r.valid, "application/json");
check(res.status == 503 && contains(res.body, "google_not_configured"),
std::string(r.path) + ": 503 google_not_configured without a credential");
check(f.client->get(r.path).status == 405, std::string(r.path) + ": GET is 405");
}
check(none.mock->send_count() == 0, "side effect: nothing sent without a credential");
}
{
GoogleRig rig;
Fixture f(rig.client);
for (const Route& r : kRoutes) {
auto res = f.client->post(r.path, r.bad, "application/json");
check(res.status == 422 && contains(res.body, "validation_error"),
std::string(r.path) + ": bad input is 422 (got " + std::to_string(res.status) + ")");
check(!contains(res.body, kTestKey), std::string(r.path) + ": credential never in a response");
}
check(rig.mock->send_count() == 0, "side effect: rejected input never reached Google");
}
return finish("agent/models/post");
}