sessions: operations get/list/cancel/delete/wait for engine, session, memory and serving profile; servingProfiles CRUD. registry: ListResult with truncated flag, v1alpha twins, gateway/policy operations, authz IAM, deny policy update, boundary patch/bindings. optimize: make_gemini_model over models::VertexModel (DirectModel removed), generateSyntheticData, online evaluator operations, trace/log writers. armor: SecurityAdmin for all SCC v2 methods (attack exposure excluded), documented agent threat categories, floor settings fixed to location global after live run. check_discovery.py of all four enforce coverage. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
176 lines
9.0 KiB
C++
176 lines
9.0 KiB
C++
// Routes: every POST/DELETE under /agent/sessions. Without a credential they
|
|
// answer 503 google_not_configured; bad input is 422 before any traffic; a
|
|
// wrong verb is 405. No Google reply is scripted: the mock has no
|
|
// expectations, so any request that reached it would fail loudly.
|
|
#include <cstdlib>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "fw/Http.hpp"
|
|
#include "support/GoogleRig.hpp"
|
|
|
|
using namespace molo::example::test;
|
|
|
|
namespace {
|
|
const std::string kEngine = "projects/p1/locations/us-central1/reasoningEngines/1";
|
|
const std::string kJson = "application/json";
|
|
|
|
std::string body(const std::string& extra) {
|
|
return "{\"engine\":\"" + kEngine + "\"," + extra + "}";
|
|
}
|
|
|
|
struct Route {
|
|
std::string path;
|
|
std::string valid; // valid input (no credential: expect 503)
|
|
std::string invalid; // bad input (expect 422)
|
|
};
|
|
} // namespace
|
|
|
|
int main() {
|
|
setenv("GOOGLE_CLOUD_PROJECT", "p1", 1);
|
|
const std::vector<Route> posts = {
|
|
{"/agent/sessions/create", body("\"user_id\":\"u1\",\"session_id\":\"chat-1\""),
|
|
body("\"user_id\":\"u1\",\"session_id\":\"Bad_Id\"")},
|
|
{"/agent/sessions/get", body("\"session_id\":\"chat-1\""), body("\"session_id\":\"\"")},
|
|
{"/agent/sessions/list", body("\"filter\":\"userId=\\\"u1\\\"\""), "{\"engine\":\"a/b\"}"},
|
|
{"/agent/sessions/events/append",
|
|
body("\"session_id\":\"chat-1\",\"author\":\"user\",\"invocation_id\":\"i1\","
|
|
"\"timestamp\":\"2025-01-31T11:30:00Z\",\"text\":\"hi\""),
|
|
body("\"session_id\":\"chat-1\",\"author\":\"user\",\"invocation_id\":\"i1\","
|
|
"\"timestamp\":\"yesterday\"")},
|
|
{"/agent/sessions/events/list", body("\"session_id\":\"chat-1\""),
|
|
body("\"session_id\":\"a/b\"")},
|
|
{"/agent/sessions/memories/generate",
|
|
body("\"scope_key\":\"user_id\",\"scope_value\":\"1\",\"text\":\"I like tea\""),
|
|
body("\"scope_key\":\"user_id\",\"scope_value\":\"*\",\"text\":\"x\"")},
|
|
{"/agent/sessions/memories/retrieve",
|
|
body("\"scope_key\":\"user_id\",\"scope_value\":\"1\",\"query\":\"tea\",\"top_k\":\"3\""),
|
|
body("\"scope_key\":\"user_id\",\"scope_value\":\"1\",\"query\":\"tea\",\"top_k\":\"51\"")},
|
|
{"/agent/sessions/memories/create",
|
|
body("\"scope_key\":\"user_id\",\"scope_value\":\"1\",\"fact\":\"likes tea\""),
|
|
body("\"scope_key\":\"user_id\",\"scope_value\":\"1\",\"fact\":\"\"")},
|
|
{"/agent/sessions/memories/get", body("\"memory_id\":\"mem-1\""),
|
|
body("\"memory_id\":\"1bad\"")},
|
|
{"/agent/sessions/memories/list", body("\"filter\":\"topics=\\\"x\\\"\""),
|
|
"{\"engine\":\"\"}"},
|
|
{"/agent/sessions/memories/profiles",
|
|
body("\"scope_key\":\"user_id\",\"scope_value\":\"1\""), body("\"scope_key\":\"\"")},
|
|
{"/agent/sessions/memories/purge", body("\"filter\":\"scope.user_id=\\\"1\\\"\""),
|
|
body("\"filter\":\"\"")},
|
|
{"/agent/sessions/operations/list", body("\"parent\":\"" + kEngine + "/sessions/chat-1\""),
|
|
body("\"parent\":\"" + kEngine + "/other/x\"")},
|
|
{"/agent/sessions/operations/get", body("\"name\":\"" + kEngine + "/operations/7\""),
|
|
body("\"name\":\"" + kEngine + "/operations/..\"")},
|
|
{"/agent/sessions/operations/wait",
|
|
body("\"name\":\"" + kEngine + "/operations/7\",\"timeout_seconds\":\"60\""),
|
|
body("\"name\":\"" + kEngine + "/operations/7\",\"timeout_seconds\":\"61\"")},
|
|
{"/agent/sessions/operations/cancel",
|
|
body("\"name\":\"" + kEngine + "/memories/mem-1/operations/7\""),
|
|
body("\"name\":\"operations/7\"")},
|
|
{"/agent/sessions/serving-profiles/list", "{\"location\":\"us-central1\"}",
|
|
"{\"location\":\"Bad Place\"}"},
|
|
{"/agent/sessions/serving-profiles/get",
|
|
"{\"location\":\"us-central1\",\"profile_id\":\"sp-1\"}",
|
|
"{\"location\":\"us-central1\",\"profile_id\":\"Bad_Id\"}"},
|
|
{"/agent/sessions/serving-profiles/create",
|
|
"{\"location\":\"us-central1\",\"profile_id\":\"sp-1\",\"display_name\":\"Live\","
|
|
"\"scope\":\"GEMINI_LIVE\"}",
|
|
"{\"location\":\"us-central1\",\"profile_id\":\"sp-1\",\"display_name\":\"Live\","
|
|
"\"scope\":\"EVERYTHING\"}"},
|
|
};
|
|
|
|
GoogleRig rig(false);
|
|
Fixture f(rig.client);
|
|
for (const Route& r : posts) {
|
|
auto none = f.client->post(r.path, r.valid, kJson);
|
|
check(none.status == 503 && contains(none.body, "google_not_configured"),
|
|
r.path + ": no credential is a loud 503");
|
|
auto bad = f.client->post(r.path, r.invalid, kJson);
|
|
check(bad.status == 422 && contains(bad.body, "validation_error"),
|
|
r.path + ": bad input is 422");
|
|
check(f.client->get(r.path).status == 405, r.path + ": get is 405");
|
|
}
|
|
|
|
// Bare engine id resolves through GOOGLE_CLOUD_PROJECT.
|
|
auto bare = f.client->post("/agent/sessions/get",
|
|
"{\"engine\":\"1\",\"session_id\":\"chat-1\"}", kJson);
|
|
check(bare.status == 503, "bare engine id with a project env reaches the client");
|
|
unsetenv("GOOGLE_CLOUD_PROJECT");
|
|
auto no_project = f.client->post("/agent/sessions/get",
|
|
"{\"engine\":\"1\",\"session_id\":\"chat-1\"}", kJson);
|
|
check(no_project.status == 422, "bare engine id without a project is 422");
|
|
setenv("GOOGLE_CLOUD_PROJECT", "p1", 1);
|
|
|
|
// Limits: id cap (63), purge guard, dry run default.
|
|
check(f.client->post("/agent/sessions/get",
|
|
body("\"session_id\":\"" + std::string(64, 'a') + "\""), kJson)
|
|
.status == 422,
|
|
"session id over 63 characters is 422");
|
|
check(f.client->post("/agent/sessions/get",
|
|
body("\"session_id\":\"" + std::string(63, 'a') + "\""), kJson)
|
|
.status == 503,
|
|
"session id of exactly 63 characters passes validation");
|
|
auto forced = f.client->post(
|
|
"/agent/sessions/memories/purge",
|
|
body("\"filter\":\"scope.user_id=\\\"1\\\"\",\"force\":\"true\""), kJson);
|
|
check(forced.status == 422 && contains(forced.body, "confirm"),
|
|
"forced purge without confirm is 422");
|
|
auto confirmed = f.client->post(
|
|
"/agent/sessions/memories/purge",
|
|
body("\"filter\":\"scope.user_id=\\\"1\\\"\",\"force\":\"true\",\"confirm\":\"1\""),
|
|
kJson);
|
|
check(confirmed.status == 503, "forced purge with the engine id as confirm reaches the client");
|
|
|
|
// DELETE routes.
|
|
using molo::example::fw::Method;
|
|
auto del_session = f.client->request(
|
|
Method::Delete, "/agent/sessions/session?engine=" + kEngine + "&id=chat-1");
|
|
check(del_session.status == 503 && contains(del_session.body, "google_not_configured"),
|
|
"delete session: no credential is 503");
|
|
check(f.client->request(Method::Delete,
|
|
"/agent/sessions/session?engine=" + kEngine + "&id=BAD").status == 422,
|
|
"delete session: bad id is 422");
|
|
check(f.client->post("/agent/sessions/session").status == 405, "delete route: post is 405");
|
|
auto del_memory = f.client->request(
|
|
Method::Delete, "/agent/sessions/memories/memory?engine=" + kEngine + "&id=mem-1");
|
|
check(del_memory.status == 503, "delete memory: no credential is 503");
|
|
check(f.client->request(Method::Delete,
|
|
"/agent/sessions/memories/memory?engine=" + kEngine + "&id=1x").status ==
|
|
422,
|
|
"delete memory: bad id is 422");
|
|
|
|
auto del_op = f.client->request(
|
|
Method::Delete, "/agent/sessions/operations/operation?engine=" + kEngine +
|
|
"&name=" + kEngine + "/operations/7");
|
|
check(del_op.status == 503 && contains(del_op.body, "google_not_configured"),
|
|
"delete operation: no credential is 503");
|
|
check(f.client->request(Method::Delete,
|
|
"/agent/sessions/operations/operation?engine=" + kEngine +
|
|
"&name=" + kEngine + "/sessions").status == 422,
|
|
"delete operation: a name that is no operation is 422");
|
|
check(f.client->post("/agent/sessions/operations/operation").status == 405,
|
|
"delete operation route: post is 405");
|
|
auto del_profile = f.client->request(
|
|
Method::Delete, "/agent/sessions/serving-profiles/profile?location=us-central1&id=sp-1");
|
|
check(del_profile.status == 503 && contains(del_profile.body, "google_not_configured"),
|
|
"delete serving profile: no credential is 503");
|
|
check(f.client->request(Method::Delete,
|
|
"/agent/sessions/serving-profiles/profile?location=us-central1&id=A_B")
|
|
.status == 422,
|
|
"delete serving profile: bad id is 422");
|
|
check(f.client->post("/agent/sessions/operations/wait",
|
|
body("\"name\":\"" + kEngine + "/operations/7\",\"timeout_seconds\":\"0\""),
|
|
kJson).status == 422,
|
|
"server-side wait of 0 seconds is 422");
|
|
|
|
check(rig.mock->send_count() == 0, "side effect: nothing reached the network");
|
|
|
|
// With a credential, validation still runs first and still stops traffic.
|
|
GoogleRig keyed;
|
|
Fixture g(keyed.client);
|
|
check(g.client->post("/agent/sessions/get", body("\"session_id\":\"BAD\""), kJson).status == 422,
|
|
"credentialed bad input is 422");
|
|
check(keyed.mock->send_count() == 0, "rejected input never reached Google");
|
|
return finish("agent/sessions calls");
|
|
}
|