Files
moloapp/tests/example/agent/runtime/extended_test.cpp
T
retoorandClaude Sonnet 5.5 8e807945a2 feat(clients): models+runtime: close gaps (all Discovery methods wrapped, live re-verification)
models: EndpointAdmin and PublisherAdmin wrap every remaining method of the
owned resources (84 call table rows, 132 Discovery methods covered, v1beta1
twins, IAM, operations, responses, export, config, enableModel); planner
rejects undeclared body keys; VertexModel::TurnBuilder replays model turns
with every thoughtSignature; Lyria WAV mime from bytes; veo-3.1 default.
runtime: v1beta1 feedbackEntries, A2A gateway (40 rpcs), a2aTasks, task store
records, scoped operations, beta twin flag (103 rows, 214 methods covered);
checker verifies twins, a2aEndpoint patterns and coverage.
example: admin routes for both parts. SPECs: live results moved from
Unverified to Verified live (Veo, Lyria, thought signatures, v1beta1 routes).

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

148 lines
8.3 KiB
C++

// 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");
}