// Routes: POST /agent/adk/export, /agent/adk/import, /agent/adk/ap2/validate #include "support/GoogleRig.hpp" using namespace molo::example::test; int main() { GoogleRig none(false); Fixture f(none.client); auto post = [&](const std::string& path, const std::string& body) { return f.client->post(path, body, "application/json"); }; auto ex = post("/agent/adk/export", "{\"template\":\"invoice_processing\"}"); check(ex.status == 200 && contains(ex.body, "\"agent_class\":\"LlmAgent\"") && contains(ex.body, "invoice_processing"), "export returns the definition"); check(contains(ex.body, "\"yaml\":"), "export includes yaml"); check(post("/agent/adk/export", "{\"template\":\"nope\"}").status == 422, "unknown template is 422"); std::string def = "{\"agent_class\":\"SequentialAgent\",\"name\":\"flow\",\"sub_agents\":[" "{\"name\":\"a\",\"model\":\"m\",\"instruction\":\"x\",\"tools\":[{\"name\":\"word_count\"}]}]}"; auto im = post("/agent/adk/import", def); check(im.status == 200 && contains(im.body, "\"word_count\""), "import round-trips a known tool"); auto yi = post("/agent/adk/import", "name: root\nmodel: m\ninstruction: |\n Be brief.\ntools:\n - name: word_count\n"); check(yi.status == 200 && contains(yi.body, "\"word_count\"") && contains(yi.body, "Be brief."), "import accepts ADK Agent Config YAML"); check(post("/agent/adk/import", "name: root\ninstruction: &a x\n").status == 422, "yaml anchors are 422"); check(post("/agent/adk/import", "name: a\ninstruction: x\nbefore_model_callbacks:\n - name: cb\n").status == 422, "unsupported ADK field is 422"); check(post("/agent/adk/import", "{\"name\":\"a\",\"tools\":[{\"name\":\"ghost\"}]}").status == 422, "unknown tool is 422"); check(post("/agent/adk/import", "{\"name\":\"a\",\"agent_class\":\"Evil\"}").status == 422, "bad class is 422"); check(post("/agent/adk/import", "oops").status == 422, "bad json is 422"); // AP2 v0.2: the checkout_hash is base64url(sha256(checkout_jwt)); for the // jwt "abc" that is ungWv48Bz-pBQUDeXa4iI7ADYaOWF3qctBD_YfIAFa0. std::string hash = "ungWv48Bz-pBQUDeXa4iI7ADYaOWF3qctBD_YfIAFa0"; std::string checkout = "{\"vct\":\"mandate.checkout.1\",\"checkout_jwt\":\"abc\",\"checkout_hash\":\"" + hash + "\"}"; std::string payment = "{\"vct\":\"mandate.payment.1\",\"transaction_id\":\"" + hash + "\",\"payee\":{\"id\":\"m1\",\"name\":\"Shop\"}," "\"payment_amount\":{\"amount\":27999,\"currency\":\"USD\"}," "\"payment_instrument\":{\"id\":\"pi1\",\"type\":\"card\"}}"; check(post("/agent/adk/ap2/validate", "{\"checkout\":" + checkout + ",\"payment\":" + payment + "}").status == 200, "valid checkout + payment mandate is 200"); std::string bad = checkout.substr(0, checkout.find(hash)) + "AAAA" + checkout.substr(checkout.find(hash) + 4); check(post("/agent/adk/ap2/validate", "{\"checkout\":" + bad + "}").status == 422, "hash mismatch is 422"); check(post("/agent/adk/ap2/validate", "{\"checkout\":" + checkout + ",\"payment\":" + payment.replace(payment.find(hash), hash.size(), "other") + "}").status == 422, "payment for another checkout is 422"); check(post("/agent/adk/ap2/validate", "{}").status == 422, "empty body is 422"); check(f.client->get("/agent/adk/export").status == 405, "get export is 405"); check(none.mock->send_count() == 0, "none of these routes call Google"); return finish("agent/adk studio"); }