Merge models and runtime gaps

This commit is contained in:
2026-10-24 05:47:50 +02:00
38 changed files with 4437 additions and 72 deletions
+106
View File
@@ -0,0 +1,106 @@
// Routes: POST /agent/models/{endpoints,endpoint/call,endpoint/operations,publisher}
// Without a credential every one is 503 google_not_configured and sends
// nothing; with one, bad input is 422 before any network traffic; gated
// actions are dry runs unless confirm:true; GET is 405.
#include <cstdlib>
#include "support/GoogleRig.hpp"
using namespace molo::example::test;
namespace {
struct Route {
const char* path;
const char* valid;
const char* bad;
};
const Route kRoutes[] = {
{"/agent/models/endpoints", "{\"action\":\"list_beta\"}",
"{\"action\":\"patch\",\"endpoint\":\"7/7\",\"body\":{},\"updateMask\":\"displayName\"}"},
{"/agent/models/endpoint/call",
"{\"kind\":\"compute_tokens\",\"endpoint\":\"7\",\"contents\":[{\"role\":\"user\",\"parts\":[{\"text\":\"x\"}]}]}",
"{\"kind\":\"compute_tokens\",\"endpoint\":\"7\",\"contents\":[]}"},
{"/agent/models/endpoint/operations", "{\"action\":\"list\",\"endpoint\":\"7\"}",
"{\"action\":\"get\",\"endpoint\":\"7\"}"},
{"/agent/models/publisher", "{\"action\":\"beta_get\",\"model\":\"gemini-2.5-flash\"}",
"{\"action\":\"beta_get\",\"model\":\"a/b\"}"},
};
// More rejected bodies, one per kind of rule.
const Route kMore[] = {
{"/agent/models/endpoints", "", "{\"action\":\"explode\"}"},
{"/agent/models/endpoints", "", "{\"action\":\"create\"}"},
{"/agent/models/endpoints", "", "{\"action\":\"create\",\"body\":{\"notAField\":1}}"},
{"/agent/models/endpoints", "", "{\"action\":\"patch\",\"endpoint\":\"7\",\"body\":{},\"updateMask\":\"bad mask!\"}"},
{"/agent/models/endpoints", "", "{\"action\":\"get_iam\",\"endpoint\":\"7\",\"policyVersion\":9}"},
{"/agent/models/endpoints", "", "{\"action\":\"test_iam\",\"endpoint\":\"7\",\"permissions\":[]}"},
{"/agent/models/endpoints", "", "{\"action\":\"delete\",\"endpoint\":\"7\",\"confirm\":\"yes\"}"},
{"/agent/models/endpoint/call", "", "{\"kind\":\"openapi\",\"openapiKind\":\"images\",\"body\":{}}"},
{"/agent/models/endpoint/call", "", "{\"kind\":\"direct_raw_predict\",\"endpoint\":\"7\",\"methodName\":\"bad method\",\"input\":\"AAAA\"}"},
{"/agent/models/endpoint/call", "", "{\"kind\":\"invoke\",\"endpoint\":\"7\",\"invokeId\":\"../x\",\"body\":{}}"},
{"/agent/models/endpoint/operations", "", "{\"action\":\"wait\",\"endpoint\":\"7\",\"operation\":\"9\",\"timeoutSeconds\":9999}"},
{"/agent/models/publisher", "", "{\"action\":\"responses_get\",\"publisher\":\"a/b\",\"responseId\":\"r1\"}"},
{"/agent/models/publisher", "", "{\"action\":\"beta_post\",\"model\":\"m\",\"callId\":\"beta.generate\",\"body\":{}}"},
{"/agent/models/publisher", "", "{\"action\":\"stream_predict\",\"model\":\"m\",\"inputs\":[]}"},
{"/agent/models/publisher", "", "{\"action\":\"beta_generate\",\"model\":\"m\",\"prompt\":\"\"}"},
};
// Gated actions: a dry run without confirm.
const Route kGated[] = {
{"/agent/models/endpoints", "{\"action\":\"delete\",\"endpoint\":\"7\"}", ""},
{"/agent/models/endpoints", "{\"action\":\"deploy\",\"endpoint\":\"7\",\"deployedModel\":{\"model\":\"m\"}}", ""},
{"/agent/models/endpoints", "{\"action\":\"undeploy\",\"endpoint\":\"7\",\"deployedModelId\":\"3\"}", ""},
{"/agent/models/endpoints", "{\"action\":\"mutate\",\"endpoint\":\"7\",\"deployedModel\":{},\"updateMask\":\"x\"}", ""},
{"/agent/models/endpoints", "{\"action\":\"set_iam\",\"endpoint\":\"7\",\"policy\":{}}", ""},
{"/agent/models/endpoint/call", "{\"kind\":\"response_delete\",\"endpoint\":\"7\",\"responseId\":\"r1\"}", ""},
{"/agent/models/endpoint/operations", "{\"action\":\"delete\",\"endpoint\":\"7\",\"operation\":\"9\"}", ""},
{"/agent/models/publisher", "{\"action\":\"export\",\"model\":\"gemma3\",\"destination\":\"gs://b/x\"}", ""},
{"/agent/models/publisher", "{\"action\":\"set_config\",\"model\":\"gemma3\",\"publisherModelConfig\":{},\"updateMask\":\"x\"}", ""},
{"/agent/models/publisher", "{\"action\":\"enable\",\"model\":\"gemma3\"}", ""},
{"/agent/models/publisher", "{\"action\":\"responses_delete\",\"responseId\":\"r1\"}", ""},
};
} // 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");
}
for (const Route& r : kGated) {
auto res = f.client->post(r.path, r.valid, "application/json");
check(res.status == 503, std::string(r.path) + ": gated action is 503 without a credential");
}
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");
}
for (const Route& r : kMore) {
auto res = f.client->post(r.path, r.bad, "application/json");
check(res.status == 422, std::string(r.path) + ": rejected " + r.bad + " (got " +
std::to_string(res.status) + ")");
}
for (const Route& r : kGated) {
auto res = f.client->post(r.path, r.valid, "application/json");
check(res.status == 200 && contains(res.body, "\"dry_run\":true"),
std::string(r.path) + ": " + r.valid + " is a dry run (got " + std::to_string(res.status) + ")");
}
std::string huge = "{\"action\":\"create\",\"body\":{\"displayName\":\"" + std::string(300 * 1024, 'x') + "\"}}";
check(f.client->post("/agent/models/endpoints", huge, "application/json").status == 413,
"oversize body is 413");
check(f.client->post("/agent/models/endpoints", "not json", "application/json").status == 422,
"non JSON body is 422");
check(rig.mock->send_count() == 0, "side effect: rejected input and dry runs never reached Google");
}
return finish("agent/models/admin");
}
@@ -0,0 +1,147 @@
// Routes: POST /agent/runtime/{operations,revisions,update,iam,code,async/cancel,
// feedback,a2a,a2a/tasks,a2a/records}
// Without a credential a well formed request is 503 google_not_configured;
// bad input is 422 (with or without a credential) and never reaches Google;
// destructive actions are dry runs unless confirm:true; GET is 405.
#include <cstdlib>
#include "support/GoogleRig.hpp"
using namespace molo::example::test;
namespace {
struct Route {
const char* path;
const char* valid;
const char* bad;
};
const char* kOp = "projects/p/locations/us-central1/reasoningEngines/1/operations/2";
const Route kRoutes[] = {
{"/agent/runtime/operations",
"{\"action\":\"get\",\"name\":\"projects/p/locations/us-central1/reasoningEngines/1/operations/2\"}",
"{\"action\":\"get\",\"name\":\"projects/p/operations/2\"}"},
{"/agent/runtime/revisions", "{\"action\":\"get\",\"id\":\"1\",\"revision\":\"r1\"}",
"{\"action\":\"get\",\"id\":\"1\"}"},
{"/agent/runtime/update", "{\"id\":\"1\",\"displayName\":\"new name\"}", "{\"id\":\"1\"}"},
{"/agent/runtime/iam", "{\"action\":\"get\",\"id\":\"1\"}",
"{\"action\":\"get\",\"id\":\"1\",\"policyVersion\":9}"},
{"/agent/runtime/code", "{\"id\":\"1\",\"inputs\":[{\"code\":\"x\"}]}",
"{\"id\":\"1\",\"inputs\":[]}"},
{"/agent/runtime/async/cancel",
"{\"id\":\"1\",\"operation\":\"projects/p/locations/us-central1/operations/9\"}",
"{\"id\":\"1\",\"operation\":\"nope\"}"},
{"/agent/runtime/feedback", "{\"action\":\"list\",\"id\":\"1\"}",
"{\"action\":\"get\",\"id\":\"1\"}"},
{"/agent/runtime/a2a", "{\"target\":\"engine\",\"protocol\":\"v1\",\"op\":\"card\",\"id\":\"1\"}",
"{\"target\":\"engine\",\"protocol\":\"v1\",\"op\":\"task\",\"id\":\"1\"}"},
{"/agent/runtime/a2a/tasks", "{\"action\":\"list\",\"id\":\"1\"}",
"{\"action\":\"create\",\"id\":\"1\",\"task\":\"Bad_ID\"}"},
{"/agent/runtime/a2a/records", "{\"action\":\"list\",\"store\":\"s1\"}",
"{\"action\":\"get\",\"store\":\"s1\"}"},
};
// Further rejected bodies per route family.
const Route kMore[] = {
{"/agent/runtime/operations", "", "{\"action\":\"explode\",\"name\":\"x\"}"},
{"/agent/runtime/operations", "", "{\"action\":\"wait\",\"name\":\"projects/p/locations/l/reasoningEngines/1/operations/2\",\"timeoutSeconds\":9999}"},
{"/agent/runtime/operations", "", "{\"action\":\"list\",\"parent\":\"projects/p/locations/l/reasoningEngines/1/examples/x\"}"},
{"/agent/runtime/revisions", "", "{\"action\":\"query\",\"id\":\"1\",\"revision\":\"r\",\"input\":\"text\"}"},
{"/agent/runtime/iam", "", "{\"action\":\"test\",\"id\":\"1\",\"permissions\":\"x\"}"},
{"/agent/runtime/iam", "", "{\"action\":\"set\",\"id\":\"1\",\"confirm\":true}"},
{"/agent/runtime/feedback", "", "{\"action\":\"create\",\"id\":\"1\",\"feedbackLabels\":[1]}"},
{"/agent/runtime/feedback", "", "{\"action\":\"create\",\"id\":\"1\",\"feedbackText\":\"x\",\"customMetadata\":5}"},
{"/agent/runtime/a2a", "", "{\"target\":\"engine\",\"protocol\":\"v2\",\"op\":\"card\",\"id\":\"1\"}"},
{"/agent/runtime/a2a", "", "{\"target\":\"revision\",\"protocol\":\"plain\",\"op\":\"card\",\"id\":\"1\"}"},
{"/agent/runtime/a2a", "", "{\"target\":\"engine\",\"protocol\":\"plain\",\"op\":\"send\",\"id\":\"1\"}"},
{"/agent/runtime/a2a", "", "{\"target\":\"engine\",\"protocol\":\"plain\",\"op\":\"card\",\"id\":\"1\",\"historyLength\":99999}"},
{"/agent/runtime/a2a/tasks", "", "{\"action\":\"append\",\"id\":\"1\",\"task\":\"t1\",\"events\":[]}"},
{"/agent/runtime/a2a/records", "", "{\"action\":\"create\",\"store\":\"s1\",\"record\":\"a/b\"}"},
};
// Destructive actions: dry run without confirm, then 503 with it.
struct Destructive {
const char* path;
const char* body;
const char* confirmed;
};
const Destructive kDestructive[] = {
{"/agent/runtime/operations",
"{\"action\":\"delete\",\"name\":\"projects/p/locations/us-central1/reasoningEngines/1/operations/2\"}",
"{\"action\":\"delete\",\"confirm\":true,\"name\":\"projects/p/locations/us-central1/reasoningEngines/1/operations/2\"}"},
{"/agent/runtime/revisions", "{\"action\":\"delete\",\"id\":\"1\",\"revision\":\"r1\"}",
"{\"action\":\"delete\",\"id\":\"1\",\"revision\":\"r1\",\"confirm\":true}"},
{"/agent/runtime/iam", "{\"action\":\"set\",\"id\":\"1\",\"policy\":{}}",
"{\"action\":\"set\",\"id\":\"1\",\"policy\":{},\"confirm\":true}"},
{"/agent/runtime/feedback", "{\"action\":\"delete\",\"id\":\"1\",\"entry\":\"f1\"}",
"{\"action\":\"delete\",\"id\":\"1\",\"entry\":\"f1\",\"confirm\":true}"},
{"/agent/runtime/a2a/tasks", "{\"action\":\"delete\",\"id\":\"1\",\"task\":\"t1\"}",
"{\"action\":\"delete\",\"id\":\"1\",\"task\":\"t1\",\"confirm\":true}"},
{"/agent/runtime/a2a/records", "{\"action\":\"delete\",\"store\":\"s1\",\"record\":\"r1\"}",
"{\"action\":\"delete\",\"store\":\"s1\",\"record\":\"r1\",\"confirm\":true}"},
};
} // namespace
int main() {
setenv("GOOGLE_CLOUD_PROJECT", "test-project", 1);
(void)kOp;
{
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 (got " +
std::to_string(res.status) + ")");
auto bad = f.client->post(r.path, r.bad, "application/json");
check(bad.status == 422 && contains(bad.body, "validation_error"),
std::string(r.path) + ": bad input is 422 even without a credential (got " +
std::to_string(bad.status) + ")");
check(f.client->get(r.path).status == 405, std::string(r.path) + ": GET is 405");
check(f.client->post(r.path, "not json", "application/json").status == 422,
std::string(r.path) + ": non JSON body is 422");
}
for (const Route& r : kMore) {
auto bad = f.client->post(r.path, r.bad, "application/json");
check(bad.status == 422, std::string(r.path) + ": rejected: " + r.bad + " (got " +
std::to_string(bad.status) + ")");
}
for (const Destructive& d : kDestructive) {
auto dry = f.client->post(d.path, d.body, "application/json");
check(dry.status == 200 && contains(dry.body, "\"dry_run\":true"),
std::string(d.path) + ": no confirm is a dry run (got " + std::to_string(dry.status) + ")");
auto real = f.client->post(d.path, d.confirmed, "application/json");
check(real.status == 503 && contains(real.body, "google_not_configured"),
std::string(d.path) + ": confirmed without a credential is 503 (got " +
std::to_string(real.status) + ")");
auto wrong = f.client->post(d.path, "{\"action\":\"delete\",\"confirm\":\"yes\"}", "application/json");
check(wrong.status == 422, std::string(d.path) + ": non boolean confirm is 422");
}
std::string huge = "{\"id\":\"1\",\"inputs\":[{\"code\":\"" + std::string(300 * 1024, 'x') + "\"}]}";
check(f.client->post("/agent/runtime/code", huge, "application/json").status == 413,
"oversize body is 413");
check(none.mock->send_count() == 0, "side effect: nothing sent without a credential");
}
{
GoogleRig rig; // dummy credential: validation must still stop first
Fixture f(rig.client);
for (const Route& r : kRoutes) {
auto bad = f.client->post(r.path, r.bad, "application/json");
check(bad.status == 422, std::string(r.path) + ": bad input is 422 with a credential (got " +
std::to_string(bad.status) + ")");
check(!contains(bad.body, kTestKey), std::string(r.path) + ": credential never in a response");
}
for (const Route& r : kMore) {
auto bad = f.client->post(r.path, r.bad, "application/json");
check(bad.status == 422, std::string(r.path) + ": rejected with a credential: " + r.bad);
}
for (const Destructive& d : kDestructive) {
auto dry = f.client->post(d.path, d.body, "application/json");
check(dry.status == 200 && contains(dry.body, "dry_run"),
std::string(d.path) + ": dry run with a credential");
}
check(rig.mock->send_count() == 0, "side effect: rejected input and dry runs never reached Google");
}
return finish("agent/runtime/extended");
}