// Route: POST /agent/optimize/evaluate (managed evaluateInstances) #include #include "support/GoogleRig.hpp" using namespace molo::example::test; int main() { setenv("GOOGLE_CLOUD_PROJECT", "test-proj", 1); const char* json = "application/json"; GoogleRig keyed; Fixture f(keyed.client); check(f.client->post("/agent/optimize/evaluate", "{\"kind\":\"voodoo\"}", json).status == 422, "unknown kind is 422"); check(f.client->post("/agent/optimize/evaluate", "{\"kind\":\"safety\"}", json).status == 422, "missing prediction is 422"); check(f.client->post("/agent/optimize/evaluate", "not json", json).status == 422, "non-JSON body is 422"); check(f.client->post("/agent/optimize/evaluate", "{\"kind\":\"safety\",\"prediction\":\"" + std::string(20001, 'x') + "\"}", json) .status == 422, "prediction over the 20000 character cap is 422"); check(f.client->post("/agent/optimize/evaluate", "{\"kind\":\"trajectory\",\"predicted\":\"a\"}", json) .status == 422, "trajectory without reference is 422"); check(keyed.mock->send_count() == 0, "rejected input never reached Google"); check(f.client->get("/agent/optimize/evaluate").status == 405, "get is 405"); // Credential present but the project id is malformed: loud 503, no traffic. setenv("GOOGLE_CLOUD_PROJECT", "Not A Project!", 1); auto bad = f.client->post("/agent/optimize/evaluate", "{\"kind\":\"safety\",\"prediction\":\"hi\"}", json); check(bad.status == 503 && contains(bad.body, "google_not_configured"), "malformed project is a 503"); check(keyed.mock->send_count() == 0, "side effect: no traffic without a valid project"); setenv("GOOGLE_CLOUD_PROJECT", "test-proj", 1); GoogleRig none(false); Fixture g(none.client); auto res = g.client->post("/agent/optimize/evaluate", "{\"kind\":\"safety\",\"prediction\":\"hi\"}", json); check(res.status == 503 && contains(res.body, "google_not_configured"), "no credential is a loud 503"); check(none.mock->send_count() == 0, "no network without a credential"); return finish("agent/optimize/evaluate"); }