Files
OmniRoute/tests/unit/executor-adapta-web.test.ts
Diego Rodrigues de Sa e Souza a721fc7295 fix(adapta): redact streamed upstream errors (#12438)
Validado em lote numa worktree combinada com os 14 PRs desta campanha de error-boundary sobre o tip de `release/v3.8.51`: `typecheck:core` limpo e **120/120** nos 23 arquivos de teste que os PRs trazem.

Um ponto que só apareceu no tree combinado: **#12465 e #12466 criam o mesmo arquivo novo** `open-sse/utils/streamReadiness.ts` (que não existe no tip) com desenhos divergentes de cancelamento — `cancelled` + `releaseLock` imediato num, `readInFlight`/`cancelRequested` com `cancelReader` fire-and-forget no outro. Adotei a versão do #12466, que difere e defere o release do lock para quando a leitura em voo termina, e validei a escolha rodando as suítes dos **dois** PRs contra ela: 21/21 no readiness compartilhado e 22/22 incluindo o boundary do Perplexity.
2026-09-03 20:57:02 -03:00

66 lines
2.2 KiB
TypeScript

import { describe, it } from "node:test";
import assert from "node:assert/strict";
const mod = await import("../../open-sse/executors/adapta-web.ts");
describe("AdaptaWebExecutor", () => {
it("can be instantiated", () => {
const executor = new mod.AdaptaWebExecutor();
assert.ok(executor);
});
it("returns 401 when credentials are missing", async () => {
const executor = new mod.AdaptaWebExecutor();
const result = await executor.execute({
model: "adapta-one",
body: { messages: [{ role: "user", content: "hi" }] },
stream: false,
credentials: {},
signal: null,
});
assert.equal(result.response.status, 401);
const json = await result.response.json();
assert.ok(json.error.message.includes("Missing Adapta credentials"));
});
it("returns 401 when apiKey is empty", async () => {
const executor = new mod.AdaptaWebExecutor();
const result = await executor.execute({
model: "adapta-one",
body: { messages: [{ role: "user", content: "test" }] },
stream: false,
credentials: { apiKey: "" },
signal: null,
});
assert.equal(result.response.status, 401);
});
it("execute returns proper result shape on auth failure", async () => {
const originalFetch = globalThis.fetch;
globalThis.fetch = (async () => new Response(null, { status: 401 })) as typeof fetch;
try {
const executor = new mod.AdaptaWebExecutor();
const result = await executor.execute({
model: "adapta-one",
body: { messages: [{ role: "user", content: "hi" }] },
stream: false,
credentials: { apiKey: "invalid-jwt" },
signal: null,
});
assert.ok(result.response instanceof Response);
assert.ok(typeof result.url === "string");
assert.ok(typeof result.headers === "object");
assert.ok(result.transformedBody !== undefined);
} finally {
globalThis.fetch = originalFetch;
}
});
it("testConnection returns false for invalid credentials", async () => {
const executor = new mod.AdaptaWebExecutor();
const connected = await executor.testConnection({ apiKey: "" });
assert.equal(connected, false);
});
});