Merge anthropic core package
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
// Route: POST /ai/anthropic/build (offline: validates, never calls the vendor)
|
||||
#include "support/Assert.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
unsetenv("ANTHROPIC_API_KEY");
|
||||
Fixture f;
|
||||
auto ok = f.client->post("/ai/anthropic/build",
|
||||
R"({"model":"claude-opus-5-5","max_tokens":4096,"prompt":"hi","tools":[{"type":"advisor_20260301","model":"claude-opus-5-5"}],"thinking":{"type":"enabled","budget_tokens":2048}})",
|
||||
"application/json");
|
||||
check(ok.status == 200, "build 200 without a credential");
|
||||
check(contains(ok.body, "advisor-tool-2026-03-01"), "derived beta reported");
|
||||
check(contains(ok.body, "\"anthropic_version\":\"2023-06-01\""), "default version");
|
||||
check(contains(ok.body, "\"budget_tokens\":2048"), "thinking in the body");
|
||||
auto v26 = f.client->post("/ai/anthropic/build",
|
||||
R"({"model":"m","prompt":"hi","version":"2026-10-21","temperature":0.5})", "application/json");
|
||||
check(v26.status == 422, "temperature rejected under 2026-10-21");
|
||||
auto v23 = f.client->post("/ai/anthropic/build",
|
||||
R"({"model":"m","prompt":"hi","temperature":0.5})", "application/json");
|
||||
check(v23.status == 200 && contains(v23.body, "\"temperature\":0.5"), "temperature kept under 2023-06-01");
|
||||
auto mcp = f.client->post("/ai/anthropic/build",
|
||||
R"({"model":"m","prompt":"hi","tools":[{"type":"mcp_toolset","mcp_server_name":"x"}]})", "application/json");
|
||||
check(mcp.status == 422, "toolset without a server is rejected");
|
||||
return finish("ai/anthropic/core/build");
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// 503 anthropic_not_configured on every route that would call the vendor;
|
||||
// paid and destructive routes are dry runs (200) until confirm:true.
|
||||
#include "support/Assert.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
unsetenv("ANTHROPIC_API_KEY");
|
||||
Fixture f;
|
||||
auto post = [&](const std::string& path, const std::string& body) {
|
||||
return f.client->post("/ai/anthropic/" + path, body, "application/json");
|
||||
};
|
||||
auto r = post("models", R"({"limit":3})");
|
||||
check(r.status == 503 && contains(r.body, "anthropic_not_configured"), "models: 503 without a key");
|
||||
check(post("count", R"({"model":"m","prompt":"x"})").status == 503, "count: 503");
|
||||
check(post("batches", R"({"action":"list"})").status == 503, "batches list: 503");
|
||||
check(post("batches", R"({"action":"get","id":"msgbatch_1"})").status == 503, "batches get: 503");
|
||||
check(post("batches", R"({"action":"results","id":"msgbatch_1"})").status == 503, "batches results: 503");
|
||||
check(post("files", R"({"action":"list"})").status == 503, "files list: 503");
|
||||
check(post("skills", R"({"action":"list"})").status == 503, "skills list: 503");
|
||||
check(post("profiles", R"({"action":"list"})").status == 503, "profiles list: 503");
|
||||
|
||||
auto dry = post("messages", R"({"model":"claude-opus-5-5","prompt":"hi"})");
|
||||
check(dry.status == 200 && contains(dry.body, "\"dry_run\":true"), "messages: dry run without confirm");
|
||||
check(post("messages", R"({"model":"claude-opus-5-5","prompt":"hi","confirm":true})").status == 503, "messages confirmed: 503");
|
||||
check(contains(post("stream", R"({"model":"m","prompt":"hi"})").body, "\"dry_run\":true"), "stream: dry run");
|
||||
check(post("stream", R"({"model":"m","prompt":"hi","confirm":true})").status == 503, "stream confirmed: 503");
|
||||
check(contains(post("batches", R"({"action":"cancel","id":"msgbatch_1"})").body, "\"dry_run\":true"), "batch cancel: dry run");
|
||||
check(contains(post("batches", R"({"action":"delete","id":"msgbatch_1"})").body, "\"dry_run\":true"), "batch delete: dry run");
|
||||
check(post("batches", R"({"action":"delete","id":"msgbatch_1","confirm":true})").status == 503, "batch delete confirmed: 503");
|
||||
check(contains(post("batches", R"({"action":"create","requests":[{"custom_id":"a","params":{"model":"m","prompt":"x"}}]})").body, "\"dry_run\":true"), "batch create: dry run");
|
||||
check(contains(post("files", R"({"action":"delete","id":"file_1"})").body, "\"dry_run\":true"), "file delete: dry run");
|
||||
check(contains(post("files", R"({"action":"upload","filename":"a.txt","text":"hello"})").body, "\"dry_run\":true"), "file upload: dry run");
|
||||
check(contains(post("skills", R"({"action":"delete","id":"skill_1"})").body, "\"dry_run\":true"), "skill delete: dry run");
|
||||
check(contains(post("profiles", R"({"action":"delete","id":"uprof_1"})").body, "\"dry_run\":true"), "profile delete: dry run");
|
||||
return finish("ai/anthropic/core/credential");
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// Routes: GET /ai/anthropic (page), /status, /calls, /betas, /tools
|
||||
#include "support/Assert.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
unsetenv("ANTHROPIC_API_KEY");
|
||||
Fixture f;
|
||||
auto page = f.client->get("/ai/anthropic");
|
||||
check(page.status == 200, "page 200");
|
||||
check(contains(page.body, "Anthropic Claude"), "page has its heading");
|
||||
check(contains(page.body, "ai_anthropic_core.js"), "page loads its script");
|
||||
auto st = f.client->get("/ai/anthropic/status");
|
||||
check(st.status == 200, "status 200");
|
||||
check(contains(st.body, "\"configured\":false"), "no credential reported");
|
||||
check(contains(st.body, "\"key_env\":\"ANTHROPIC_API_KEY\""), "names the key variable");
|
||||
check(contains(st.body, "\"calls\":32"), "reports 32 calls");
|
||||
check(contains(st.body, "\"betas\":55"), "reports 55 betas");
|
||||
auto calls = f.client->get("/ai/anthropic/calls");
|
||||
check(calls.status == 200 && contains(calls.body, "messages.batches.results"), "call table listed");
|
||||
check(contains(calls.body, "/v1/skills/{skill_id}/versions/{version}/content"), "download row listed");
|
||||
auto betas = f.client->get("/ai/anthropic/betas");
|
||||
check(betas.status == 200 && contains(betas.body, "interleaved-thinking-2025-05-14"), "betas listed");
|
||||
check(contains(betas.body, "admin_package"), "other-package betas are labelled");
|
||||
auto tools = f.client->get("/ai/anthropic/tools");
|
||||
check(tools.status == 200 && contains(tools.body, "web_fetch_20260318"), "tools listed");
|
||||
check(f.client->post("/ai/anthropic/status", "{}", "application/json").status == 405, "post status is 405");
|
||||
check(f.client->get("/ai/anthropic/messages").status == 405, "get messages is 405");
|
||||
return finish("ai/anthropic/core/status");
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// 422 on bad input, 413 on oversize, before any credential check
|
||||
#include "support/Assert.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
unsetenv("ANTHROPIC_API_KEY");
|
||||
Fixture f;
|
||||
auto post = [&](const std::string& path, const std::string& body) {
|
||||
return f.client->post("/ai/anthropic/" + path, body, "application/json").status;
|
||||
};
|
||||
check(post("messages", "not json") == 422, "messages: invalid JSON is 422");
|
||||
check(post("messages", "[]") == 422, "messages: array body is 422");
|
||||
check(post("messages", "{}") == 422, "messages: model required");
|
||||
check(post("messages", R"({"model":"m"})") == 422, "messages: prompt or messages required");
|
||||
check(post("messages", R"({"model":"m","prompt":"x","max_tokens":-5})") == 422, "messages: negative max_tokens");
|
||||
check(post("messages", R"({"model":"m","prompt":"x","speed":"turbo"})") == 422, "messages: bad speed");
|
||||
check(post("stream", R"({"model":"m","prompt":"x","confirm":"yes"})") == 422, "stream: confirm must be a bool");
|
||||
check(post("count", "{}") == 422, "count: model required");
|
||||
check(post("batches", "{}") == 422, "batches: action required");
|
||||
check(post("batches", R"({"action":"explode"})") == 422, "batches: unknown action");
|
||||
check(post("batches", R"({"action":"get"})") == 422, "batches: id required");
|
||||
check(post("batches", R"({"action":"get","id":"../x"})") == 422, "batches: bad id");
|
||||
check(post("batches", R"({"action":"create","requests":"x"})") == 422, "batches: requests must be an array");
|
||||
check(post("files", R"({"action":"delete","id":"a/b"})") == 422, "files: bad id");
|
||||
check(post("files", R"({"action":"upload","filename":"x.txt"})") == 422, "files: upload needs text");
|
||||
check(post("skills", R"({"action":"get"})") == 422, "skills: id required");
|
||||
check(post("profiles", R"({"action":"nope"})") == 422, "profiles: unknown action");
|
||||
check(post("models", R"({"id":"../x"})") == 422, "models: bad id");
|
||||
std::string big(600 * 1024, 'x');
|
||||
check(post("messages", R"({"model":"m","prompt":")" + big + R"("})") == 413, "oversize body is 413");
|
||||
return finish("ai/anthropic/core/validation");
|
||||
}
|
||||
Reference in New Issue
Block a user