41 lines
2.0 KiB
C++
41 lines
2.0 KiB
C++
// Routes: GET /ai/huggingface (page), /status, /calls, /tasks (no credential needed)
|
|||
|
|
#include <cstdlib>
|
||
|
|
|
||
|
|
#include "support/Assert.hpp"
|
||
|
|
|
||
|
|
using namespace molo::example::test;
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
setenv("MOLO_ENV_FILES", "off", 1);
|
||
|
|
unsetenv("HF_TOKEN");
|
||
|
|
unsetenv("HUGGING_FACE_HUB_TOKEN");
|
||
|
|
Fixture f;
|
||
|
|
auto page = f.client->get("/ai/huggingface");
|
||
|
|
check(page.status == 200, "page 200");
|
||
|
|
check(contains(page.headers.get("Content-Type"), "text/html"), "html");
|
||
|
|
check(contains(page.body, "Hugging Face") && contains(page.body, "viewport"), "title and mobile viewport");
|
||
|
|
check(contains(page.body, "/embedded/ai_huggingface.js"), "script wired");
|
||
|
|
check(f.client->post("/ai/huggingface", "{}", "application/json").status == 405, "post page is 405");
|
||
|
|
|
||
|
|
auto st = f.client->get("/ai/huggingface/status");
|
||
|
|
check(st.status == 200 && contains(st.body, "\"configured\":false"), "status without a token");
|
||
|
|
check(contains(st.body, "HF_TOKEN") && contains(st.body, "router.huggingface.co") &&
|
||
|
|
contains(st.body, "api.endpoints.huggingface.cloud"),
|
||
|
|
"status names credential env and hosts");
|
||
|
|
check(contains(st.body, "\"calls\":132") && contains(st.body, "\"tasks\":25"), "status counts calls and tasks");
|
||
|
|
check(f.client->post("/ai/huggingface/status", "{}", "application/json").status == 405, "post status is 405");
|
||
|
|
|
||
|
|
auto calls = f.client->get("/ai/huggingface/calls");
|
||
|
|
check(calls.status == 200 && contains(calls.body, "/v1/chat/completions") &&
|
||
|
|
contains(calls.body, "/v2/endpoint/{namespace}/{name}/pause") && contains(calls.body, "/embed") &&
|
||
|
|
contains(calls.body, "/api/whoami-v2"),
|
||
|
|
"call table listed across surfaces");
|
||
|
|
check(f.client->post("/ai/huggingface/calls", "{}", "application/json").status == 405, "post calls is 405");
|
||
|
|
|
||
|
|
auto tasks = f.client->get("/ai/huggingface/tasks");
|
||
|
|
check(tasks.status == 200 && contains(tasks.body, "feature-extraction") &&
|
||
|
|
contains(tasks.body, "\"binary_input\":true"),
|
||
|
|
"task catalog listed");
|
||
|
|
return finish("ai/huggingface/page");
|
||
|
|
}
|