51 lines
2.6 KiB
C++
51 lines
2.6 KiB
C++
// Routes: GET /ai/compat (page), /status, /providers, /calls (no credential needed)
|
|||
|
|
#include <cstdlib>
|
||
|
|
|
||
|
|
#include "support/Assert.hpp"
|
||
|
|
#include "vendors/compat/registry.h"
|
||
|
|
|
||
|
|
using namespace molo::example::test;
|
||
|
|
namespace cp = molo::compat;
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
setenv("MOLO_ENV_FILES", "off", 1);
|
||
|
|
for (std::size_t i = 0; i < cp::Registry::count(); ++i) {
|
||
|
|
const cp::ProviderRow& r = cp::Registry::at(i);
|
||
|
|
unsetenv(r.key_env);
|
||
|
|
if (r.base_env[0]) unsetenv(r.base_env);
|
||
|
|
if (r.extra_env[0]) unsetenv(r.extra_env);
|
||
|
|
}
|
||
|
|
Fixture f;
|
||
|
|
auto page = f.client->get("/ai/compat");
|
||
|
|
check(page.status == 200, "page 200");
|
||
|
|
check(contains(page.headers.get("Content-Type"), "text/html"), "html");
|
||
|
|
check(contains(page.body, "OpenAI-compatible providers") && contains(page.body, "viewport"), "title and mobile viewport");
|
||
|
|
check(contains(page.body, "/embedded/ai_compat.js"), "script wired");
|
||
|
|
check(f.client->post("/ai/compat", "{}", "application/json").status == 405, "post page is 405");
|
||
|
|
|
||
|
|
auto st = f.client->get("/ai/compat/status");
|
||
|
|
check(st.status == 200 && contains(st.body, "\"configured\":false"), "status without a key");
|
||
|
|
check(contains(st.body, "GROQ_API_KEY") && contains(st.body, "CLOUDFLARE_API_TOKEN"), "status names credential envs");
|
||
|
|
check(contains(st.body, "\"configured_providers\":0"), "no provider configured");
|
||
|
|
check(f.client->post("/ai/compat/status", "{}", "application/json").status == 405, "post status is 405");
|
||
|
|
|
||
|
|
auto prov = f.client->get("/ai/compat/providers");
|
||
|
|
check(prov.status == 200, "providers 200");
|
||
|
|
for (std::size_t i = 0; i < cp::Registry::count(); ++i) {
|
||
|
|
const cp::ProviderRow& r = cp::Registry::at(i);
|
||
|
|
check(contains(prov.body, std::string("\"id\":\"") + r.id + "\""), std::string("providers lists ") + r.id);
|
||
|
|
}
|
||
|
|
check(contains(prov.body, "https://api.groq.com/openai/v1") && contains(prov.body, "docs+probe") &&
|
||
|
|
contains(prov.body, "needs GROQ_API_KEY") == false && contains(prov.body, "\"missing_env\":\"GROQ_API_KEY\""),
|
||
|
|
"provider rows carry base url, evidence and missing env");
|
||
|
|
check(contains(prov.body, "\"missing_env\":\"OLLAMA_BASE_URL\""), "local row names its switch");
|
||
|
|
check(contains(prov.body, "\"missing_env\":\"CLOUDFLARE_ACCOUNT_ID\"") || contains(prov.body, "\"missing_env\":\"CLOUDFLARE_API_TOKEN\""),
|
||
|
|
"cloudflare names a missing env");
|
||
|
|
|
||
|
|
auto calls = f.client->get("/ai/compat/calls");
|
||
|
|
check(calls.status == 200 && contains(calls.body, "/chat/completions") && contains(calls.body, "createEmbedding") &&
|
||
|
|
contains(calls.body, "/audio/speech"),
|
||
|
|
"call table listed");
|
||
|
|
return finish("ai/compat/page");
|
||
|
|
}
|