mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-20 13:52:28 +03:00
* test(infra): retry recursive temp-dir removal instead of failing a shard on ENOTEMPTY (#11966) Two shards on release/v3.8.51 went red in one day with the same signature — "ENOTEMPTY, Directory not empty: /tmp/omniroute-<test>-XXXXXX" — from combo-same-provider-cascade (Unit Tests fast-path 4/4, on a PR that touches only .github/) and auth-policy-embeddings-webfetch-7785 (the 20k-test TIA step). Both pass alone and on re-run: the cleanup races something still writing into the directory (SQLite WAL/-shm checkpoint, a worker, the backup) and under a loaded hosted runner the window opens. 1154 test files do their own cleanup with fs.rmSync(dir, { recursive: true, force: true }); 57 already asked for retries. One-shot codemod (scripts/ad-hoc/codemod-rm-maxretries.mjs, kept for the record): every rm / rmSync / rmdirSync option object with `recursive: true` and no `maxRetries` gains `maxRetries: 5, retryDelay: 100` — Node itself then retries ENOTEMPTY/EBUSY/EPERM for up to ~0.5 s before giving up. 2243 call sites in 1292 files under tests/, the shared tests/_setup/isolateDataDir.ts exit hook included. Only the option object changes: no call site, assertion or import is touched. Validation: prettier and ESLint (with the frozen suppressions) clean on all 1292 files; a random 20-file sample runs green (quota-redis-store hangs identically on the untouched tree — it needs a Redis on localhost, an environment matter). The four unit shards on this PR are the full run. * fix(quality): let check-forgotten-sibling-tests read a 1,000-file diff The gate shells out to `git diff` through execFileSync with Node's default 1 MB maxBuffer; the 1,292-file codemod in this PR is the first diff large enough to overflow it, and the gate died with `spawnSync git ENOBUFS` before comparing anything. 64 MB is far above any real PR and costs nothing when unused.
530 lines
13 KiB
TypeScript
530 lines
13 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { makeManagementSessionRequest } from "../helpers/managementSession.ts";
|
|
|
|
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-providers-managed-"));
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
process.env.JWT_SECRET = "test-jwt-secret-for-managed-providers";
|
|
process.env.INITIAL_PASSWORD = "admin-secret";
|
|
|
|
const core = await import("../../src/lib/db/core.ts");
|
|
const providersRoute = await import("../../src/app/api/providers/route.ts");
|
|
const modelsDb = await import("../../src/lib/db/models.ts");
|
|
|
|
function resetDb() {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
|
|
}
|
|
|
|
test.beforeEach(() => {
|
|
resetDb();
|
|
});
|
|
|
|
test.after(() => {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
});
|
|
|
|
test("providers route accepts managed local, audio, web-cookie and search providers", async () => {
|
|
const cases = [
|
|
{
|
|
provider: "synthetic",
|
|
body: {
|
|
provider: "synthetic",
|
|
apiKey: "synthetic-key",
|
|
name: "Synthetic",
|
|
},
|
|
},
|
|
{
|
|
provider: "gitlab",
|
|
body: {
|
|
provider: "gitlab",
|
|
apiKey: "glpat-test",
|
|
name: "GitLab Duo PAT",
|
|
},
|
|
},
|
|
{
|
|
provider: "thebai",
|
|
body: {
|
|
provider: "thebai",
|
|
apiKey: "theb-key",
|
|
name: "TheB.AI Primary",
|
|
},
|
|
},
|
|
{
|
|
provider: "fenayai",
|
|
body: {
|
|
provider: "fenayai",
|
|
apiKey: "fenay-key",
|
|
name: "FenayAI Primary",
|
|
},
|
|
},
|
|
{
|
|
provider: "chutes",
|
|
body: {
|
|
provider: "chutes",
|
|
apiKey: "chutes-key",
|
|
name: "Chutes Primary",
|
|
},
|
|
},
|
|
{
|
|
provider: "datarobot",
|
|
body: {
|
|
provider: "datarobot",
|
|
apiKey: "datarobot-key",
|
|
name: "DataRobot Primary",
|
|
},
|
|
},
|
|
{
|
|
provider: "clarifai",
|
|
body: {
|
|
provider: "clarifai",
|
|
apiKey: "clarifai-pat",
|
|
name: "Clarifai Primary",
|
|
},
|
|
},
|
|
{
|
|
provider: "empower",
|
|
body: {
|
|
provider: "empower",
|
|
apiKey: "empower-key",
|
|
name: "Empower Primary",
|
|
},
|
|
},
|
|
{
|
|
provider: "nous-research",
|
|
body: {
|
|
provider: "nous-research",
|
|
apiKey: "nous-key",
|
|
name: "Nous Research Primary",
|
|
},
|
|
},
|
|
{
|
|
provider: "poe",
|
|
body: {
|
|
provider: "poe",
|
|
apiKey: "poe-key",
|
|
name: "Poe Primary",
|
|
},
|
|
},
|
|
{
|
|
provider: "azure-ai",
|
|
body: {
|
|
provider: "azure-ai",
|
|
apiKey: "azure-ai-key",
|
|
name: "Azure AI Foundry Primary",
|
|
},
|
|
},
|
|
{
|
|
provider: "azure-openai",
|
|
body: {
|
|
provider: "azure-openai",
|
|
apiKey: "azure-openai-key",
|
|
name: "Azure OpenAI Primary",
|
|
providerSpecificData: {
|
|
baseUrl: "https://my-resource.openai.azure.com",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
provider: "bedrock",
|
|
body: {
|
|
provider: "bedrock",
|
|
apiKey: "bedrock-key",
|
|
name: "Bedrock Mantle Primary",
|
|
},
|
|
},
|
|
{
|
|
provider: "watsonx",
|
|
body: {
|
|
provider: "watsonx",
|
|
apiKey: "watsonx-key",
|
|
name: "watsonx Gateway Primary",
|
|
},
|
|
},
|
|
{
|
|
provider: "oci",
|
|
body: {
|
|
provider: "oci",
|
|
apiKey: "oci-key",
|
|
name: "OCI GenAI Primary",
|
|
},
|
|
},
|
|
{
|
|
provider: "sap",
|
|
body: {
|
|
provider: "sap",
|
|
apiKey: "sap-key",
|
|
name: "SAP GenAI Primary",
|
|
},
|
|
},
|
|
{
|
|
provider: "modal",
|
|
body: {
|
|
provider: "modal",
|
|
apiKey: "modal-key",
|
|
name: "Modal Primary",
|
|
providerSpecificData: {
|
|
baseUrl: "https://alice--demo.modal.run/v1",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
provider: "reka",
|
|
body: {
|
|
provider: "reka",
|
|
apiKey: "reka-key",
|
|
name: "Reka Primary",
|
|
providerSpecificData: {
|
|
baseUrl: "https://api.reka.ai/v1",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
provider: "nlpcloud",
|
|
body: {
|
|
provider: "nlpcloud",
|
|
apiKey: "nlpc-key",
|
|
name: "NLP Cloud Primary",
|
|
},
|
|
},
|
|
{
|
|
provider: "runwayml",
|
|
body: {
|
|
provider: "runwayml",
|
|
apiKey: "runway-key",
|
|
name: "Runway Primary",
|
|
},
|
|
},
|
|
{
|
|
provider: "voyage-ai",
|
|
body: {
|
|
provider: "voyage-ai",
|
|
apiKey: "voyage-key",
|
|
name: "Voyage AI Primary",
|
|
},
|
|
},
|
|
{
|
|
provider: "jina-ai",
|
|
body: {
|
|
provider: "jina-ai",
|
|
apiKey: "jina-key",
|
|
name: "Jina AI Primary",
|
|
},
|
|
},
|
|
{
|
|
provider: "sdwebui",
|
|
body: {
|
|
provider: "sdwebui",
|
|
name: "SD WebUI Local",
|
|
providerSpecificData: {
|
|
baseUrl: "http://localhost:7860",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
provider: "lm-studio",
|
|
body: {
|
|
provider: "lm-studio",
|
|
name: "LM Studio Local",
|
|
providerSpecificData: {
|
|
baseUrl: "http://localhost:1234/v1",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
provider: "vllm",
|
|
body: {
|
|
provider: "vllm",
|
|
name: "vLLM Local",
|
|
providerSpecificData: {
|
|
baseUrl: "http://localhost:8000/v1",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
provider: "lemonade",
|
|
body: {
|
|
provider: "lemonade",
|
|
name: "Lemonade Local",
|
|
providerSpecificData: {
|
|
baseUrl: "http://localhost:13305/api/v1",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
provider: "llamafile",
|
|
body: {
|
|
provider: "llamafile",
|
|
name: "Llamafile Local",
|
|
providerSpecificData: {
|
|
baseUrl: "http://127.0.0.1:8080/v1",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
provider: "llama-cpp",
|
|
body: {
|
|
provider: "llama-cpp",
|
|
name: "llama.cpp Local",
|
|
providerSpecificData: {
|
|
baseUrl: "http://127.0.0.1:8080/v1",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
provider: "triton",
|
|
body: {
|
|
provider: "triton",
|
|
name: "Triton Local",
|
|
providerSpecificData: {
|
|
baseUrl: "http://localhost:8000/v1",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
provider: "docker-model-runner",
|
|
body: {
|
|
provider: "docker-model-runner",
|
|
name: "Docker Model Runner Local",
|
|
providerSpecificData: {
|
|
baseUrl: "http://localhost:12434/v1",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
provider: "xinference",
|
|
body: {
|
|
provider: "xinference",
|
|
name: "XInference Local",
|
|
providerSpecificData: {
|
|
baseUrl: "http://localhost:9997/v1",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
provider: "oobabooga",
|
|
body: {
|
|
provider: "oobabooga",
|
|
name: "oobabooga Local",
|
|
providerSpecificData: {
|
|
baseUrl: "http://localhost:5000/v1",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
provider: "assemblyai",
|
|
body: {
|
|
provider: "assemblyai",
|
|
apiKey: "aa-key",
|
|
name: "AssemblyAI Primary",
|
|
},
|
|
},
|
|
{
|
|
provider: "aws-polly",
|
|
body: {
|
|
provider: "aws-polly",
|
|
apiKey: "aws-secret-key",
|
|
name: "AWS Polly Primary",
|
|
providerSpecificData: {
|
|
accessKeyId: "AKIA_TEST",
|
|
region: "us-east-1",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
provider: "grok-web",
|
|
body: {
|
|
provider: "grok-web",
|
|
apiKey: "sso=grok-cookie",
|
|
name: "Grok Web Session",
|
|
},
|
|
},
|
|
{
|
|
provider: "perplexity-web",
|
|
body: {
|
|
provider: "perplexity-web",
|
|
apiKey: "__Secure-next-auth.session-token=pplx-cookie",
|
|
name: "Perplexity Web Session",
|
|
},
|
|
},
|
|
{
|
|
provider: "blackbox-web",
|
|
body: {
|
|
provider: "blackbox-web",
|
|
apiKey: "__Secure-authjs.session-token=bb-cookie",
|
|
name: "Blackbox Web Session",
|
|
},
|
|
},
|
|
{
|
|
provider: "muse-spark-web",
|
|
body: {
|
|
provider: "muse-spark-web",
|
|
apiKey: "abra_sess=meta-cookie",
|
|
name: "Muse Spark Web Session",
|
|
},
|
|
},
|
|
{
|
|
provider: "google-pse-search",
|
|
body: {
|
|
provider: "google-pse-search",
|
|
apiKey: "google-key",
|
|
name: "Google PSE",
|
|
providerSpecificData: {
|
|
cx: "engine-id-123",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
provider: "youcom-search",
|
|
body: {
|
|
provider: "youcom-search",
|
|
apiKey: "you-key",
|
|
name: "You.com Search",
|
|
},
|
|
},
|
|
{
|
|
provider: "searxng-search",
|
|
body: {
|
|
provider: "searxng-search",
|
|
name: "Local SearXNG",
|
|
providerSpecificData: {
|
|
baseUrl: "http://localhost:8888/search",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
provider: "jules",
|
|
body: {
|
|
provider: "jules",
|
|
apiKey: "jules-test-key",
|
|
name: "Jules API",
|
|
},
|
|
},
|
|
];
|
|
|
|
for (const entry of cases) {
|
|
const response = await providersRoute.POST(
|
|
await makeManagementSessionRequest("http://localhost/api/providers", {
|
|
method: "POST",
|
|
body: entry.body,
|
|
})
|
|
);
|
|
|
|
assert.equal(
|
|
response.status,
|
|
201,
|
|
`${entry.provider} should be accepted by POST /api/providers`
|
|
);
|
|
const payload = (await response.json()) as any;
|
|
assert.equal(payload.connection.provider, entry.provider);
|
|
}
|
|
});
|
|
|
|
test("providers route rejects upstream proxy tools as direct provider connections", async () => {
|
|
const response = await providersRoute.POST(
|
|
await makeManagementSessionRequest("http://localhost/api/providers", {
|
|
method: "POST",
|
|
body: {
|
|
provider: "cliproxyapi",
|
|
apiKey: "cpa-key",
|
|
name: "CLIProxyAPI",
|
|
},
|
|
})
|
|
);
|
|
|
|
assert.equal(response.status, 400);
|
|
assert.deepEqual(await response.json(), { error: "Invalid provider" });
|
|
});
|
|
|
|
test("DELETE /api/providers batch deletes connections", async () => {
|
|
const createReq = async (provider, name, apiKey) =>
|
|
providersRoute.POST(
|
|
await makeManagementSessionRequest("http://localhost/api/providers", {
|
|
method: "POST",
|
|
body: { provider, name, apiKey },
|
|
})
|
|
);
|
|
|
|
const r1 = await createReq("synthetic", "Conn 1", "key-1");
|
|
const r2 = await createReq("synthetic", "Conn 2", "key-2");
|
|
const r3 = await createReq("synthetic", "Conn 3", "key-3");
|
|
const id1 = (await r1.json()).connection.id;
|
|
const id2 = (await r2.json()).connection.id;
|
|
const id3 = (await r3.json()).connection.id;
|
|
await modelsDb.addCustomModel("synthetic", "manual-model", "Manual", "manual");
|
|
await modelsDb.addCustomModel("synthetic", "imported-model", "Imported", "imported");
|
|
|
|
const deleteRes = await providersRoute.DELETE(
|
|
await makeManagementSessionRequest("http://localhost/api/providers", {
|
|
method: "DELETE",
|
|
body: { ids: [id1, id3] },
|
|
})
|
|
);
|
|
|
|
assert.equal(deleteRes.status, 200);
|
|
const deletePayload = (await deleteRes.json()) as any;
|
|
assert.equal(deletePayload.deleted, 2);
|
|
|
|
const listRes = await providersRoute.GET(
|
|
await makeManagementSessionRequest("http://localhost/api/providers")
|
|
);
|
|
const listPayload = (await listRes.json()) as any;
|
|
const remainingIds = listPayload.connections.map((c) => c.id);
|
|
assert.equal(remainingIds.includes(id1), false);
|
|
assert.equal(remainingIds.includes(id3), false);
|
|
assert.equal(remainingIds.includes(id2), true);
|
|
assert.deepEqual(
|
|
(await modelsDb.getCustomModels("synthetic")).map((model: { id: string }) => model.id),
|
|
["manual-model", "imported-model"]
|
|
);
|
|
|
|
const deleteLastRes = await providersRoute.DELETE(
|
|
await makeManagementSessionRequest("http://localhost/api/providers", {
|
|
method: "DELETE",
|
|
body: { ids: [id2] },
|
|
})
|
|
);
|
|
assert.equal(deleteLastRes.status, 200);
|
|
assert.deepEqual(
|
|
(await modelsDb.getCustomModels("synthetic")).map((model: { id: string }) => model.id),
|
|
["manual-model"]
|
|
);
|
|
});
|
|
|
|
test("DELETE /api/providers rejects empty ids array", async () => {
|
|
const res = await providersRoute.DELETE(
|
|
await makeManagementSessionRequest("http://localhost/api/providers", {
|
|
method: "DELETE",
|
|
body: { ids: [] },
|
|
})
|
|
);
|
|
assert.equal(res.status, 400);
|
|
});
|
|
|
|
test("DELETE /api/providers rejects ids over 100 limit", async () => {
|
|
const res = await providersRoute.DELETE(
|
|
await makeManagementSessionRequest("http://localhost/api/providers", {
|
|
method: "DELETE",
|
|
body: { ids: Array.from({ length: 101 }, (_, i) => `id-${i}`) },
|
|
})
|
|
);
|
|
assert.equal(res.status, 400);
|
|
const payload = (await res.json()) as any;
|
|
assert.equal(payload.error, "Cannot delete more than 100 connections at once");
|
|
});
|
|
|
|
test("DELETE /api/providers rejects non-array ids", async () => {
|
|
const res = await providersRoute.DELETE(
|
|
await makeManagementSessionRequest("http://localhost/api/providers", {
|
|
method: "DELETE",
|
|
body: { ids: "not-an-array" },
|
|
})
|
|
);
|
|
assert.equal(res.status, 400);
|
|
});
|