Files
OmniRoute/@omniroute/opencode-plugin/tests/models-fetcher.test.ts
Ravi Tharuma b0557543b8 fix(opencode-plugin): lengthen /v1/models timeout and attach HTTP status (#12607)
Validado em lote numa worktree combinada com os 10 PRs desta leva sobre o tip de `release/v3.8.51`: `typecheck:core` limpo, `check-file-size` OK e **241/242** nos 29 arquivos de teste que os PRs tocam.

A única "falha" não é falha: `tests/unit/autoCombo/strict-zero-cost-filter.test.ts` é um teste em estilo Vitest que eu incluí por engano na invocação do runner nativo do Node — ele quebra no import (`@vitest/runner`), não numa asserção. Ao investigar, descobri que esse arquivo não roda em nenhum dos dois runners hoje (o glob do `test:unit` não lista `autoCombo` e o `include` do Vitest só pega `.tsx` nessa pasta); é um problema pré-existente do repositório, sem relação com esta leva, e vou registrá-lo separadamente.

O #12636 conflitava apenas na lista de testes do `@omniroute/opencode-plugin/package.json`, de forma aditiva: o tip já tinha `models-fetcher.test.ts` (do #12607, irmão desta mesma leva) e o #12636 acrescenta `telemetry.test.ts`. Fiz a união dos dois lados (25 arquivos contra 24 de cada) em vez de escolher um, o que teria removido um arquivo da suíte do plugin em silêncio.

Obrigado, @RaviTharuma.
2026-09-03 23:38:04 -03:00

46 lines
1.5 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { defaultOmniRouteModelsFetcher } from "../src/index.js";
test("defaultOmniRouteModelsFetcher attaches statusCode on HTTP 401", async () => {
const original = globalThis.fetch;
globalThis.fetch = (async () =>
new Response(JSON.stringify({ error: "authentication expired" }), {
status: 401,
statusText: "Unauthorized",
})) as typeof fetch;
try {
await assert.rejects(
() => defaultOmniRouteModelsFetcher("https://gateway.example/v1", "test-key"),
(err: unknown) => {
assert.ok(err instanceof Error);
const rec = err as Error & { statusCode?: number; status?: number };
assert.equal(rec.statusCode, 401);
assert.equal(rec.status, 401);
assert.match(rec.message, /401/);
return true;
},
);
} finally {
globalThis.fetch = original;
}
});
test("defaultOmniRouteModelsFetcher default timeout is 30s", async () => {
const original = globalThis.fetch;
let signal: AbortSignal | undefined;
globalThis.fetch = (async (_input, init) => {
signal = init?.signal ?? undefined;
return new Response(JSON.stringify({ object: "list", data: [] }), {
status: 200,
headers: { "Content-Type": "application/json" },
});
}) as typeof fetch;
try {
await defaultOmniRouteModelsFetcher("https://gateway.example/v1", "test-key");
assert.equal(signal instanceof AbortSignal, true);
} finally {
globalThis.fetch = original;
}
});