mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-08 00:02:20 +03:00
* feat(ci): G0 — quality rail (PR→release/**) ganha ratchets+segurança do trilho A O refactor de god-files do trilho 3.8.50→3.9.0 acontece em PRs→release/**, e esse trilho pulava o motor de ratchet, o CodeQL ratchet e todos os scanners de segurança — exatamente onde a rede era necessária (5 das 13 causas da reconciliação de 07-24 eram regressões reais shipadas por CI verde por-PR). Modo enxuto, jobs EXISTENTES (a .51 consolida lanes; nenhum job novo): - lint-guard: quality:collect + ratchet --allow-missing + require-tighten + check:codeql-ratchet. O job já escreve .artifacts/eslint-results.json, então o motor entra a custo ZERO de ESLint (um inventário, dois consumidores). Coverage ausente degrada gracioso (--allow-missing); autoridade de coverage segue no trilho A. + permissions security-events:read para o CodeQL ratchet. - fast-gates: check:cycles, check:lockfile, duplication, dead-code, type-coverage, compression-budget + install endurecido dos scanners (gh release download, zizmor PINADO 1.25.2 = mesmo auditor do ci.yml) + secrets/vuln/workflows/ openapi-breaking com --ratchet (self-skip sem binário; só regressão medida bloqueia). - Fora de propósito: bundle-size (self-skip sem build → configuração morta) e o run de coverage (fast-unit já roda a suíte cheia). Runners intocados: guard tests/unit/vps-runner-variable-scope.test.ts verde; teste novo tests/unit/quality-rail-gate-membership.test.ts pina a MEMBERSHIP dos gates no trilho B (red antes da edição, green depois). Validação no tip puro (nenhum base-red fabricado para a fila de PRs abertos): cycles OK · lockfile OK · duplication 4.26% (base 5.72%) · dead-code 226 (base 227) · type-coverage 94.13% (base 92.17%) · compression OK · secrets 0 (base 0) · vuln 5 (base 10) · codeql 0 (base 0) · oasdiff 0 (base 0) · zizmor 178 (base 190) · actionlint exit 0 no arquivo editado · quality-ratchet 56 métricas OK + require-tighten OK com --allow-missing. Refs #8084 * feat(.50): G13 golden-set, G14 import boundaries, gap34 deterministic, docs sync, R0.2 dead hooks Integra os itens restantes da 3.8.50: - G13: golden-set determinístico para combo.ts e chatCore.ts via seams públicas - G14: no-restricted-imports para localDb barrel fora de src/lib/db/ e executors em src/app/ - Gap34: teste determinístico de timeout DuckDuckGo sem rede real - Docs: golden path de contribuição + sincronização de números canônicos - R0.2: remoção dos 7 hooks mortos do BUILTIN_EVENTS + UI marketplace ajustada * fix(r0.2): remove marketplace tab remnants from plugins page — fixes dashboard typecheck regression * chore(r0.2): remove pluginWorker.ts, signing.ts, sandbox.ts — zero importers confirmed * fix(docs): remove OMNIROUTE_PLUGINS_ALLOW_EXEC reference — env var removed with pluginWorker.ts in R0.2 * fix(env): remove dead OMNIROUTE_PLUGINS_ALLOW_EXEC from .env.example — consumer removed in R0.2 * fix(test): update sidebar-visibility assertion for R0.2 marketplace removal --------- Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com>
238 lines
8.0 KiB
TypeScript
238 lines
8.0 KiB
TypeScript
import { describe, it } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { FETCH_TIMEOUT_MS } from "../../open-sse/config/constants.ts";
|
|
import {
|
|
DuckDuckGoWebExecutor,
|
|
DUCKDUCKGO_BASE,
|
|
STATUS_URL,
|
|
} from "../../open-sse/executors/duckduckgo-web.ts";
|
|
|
|
describe("DuckDuckGoWebExecutor", () => {
|
|
describe("class instantiation", () => {
|
|
it("should instantiate executor", () => {
|
|
const executor = new DuckDuckGoWebExecutor();
|
|
assert.ok(executor, "Executor should be created");
|
|
});
|
|
|
|
it("should have execute method", () => {
|
|
const executor = new DuckDuckGoWebExecutor();
|
|
assert.equal(typeof executor.execute, "function", "execute should be a function");
|
|
});
|
|
|
|
it("should have testConnection method", () => {
|
|
const executor = new DuckDuckGoWebExecutor();
|
|
assert.equal(
|
|
typeof executor.testConnection,
|
|
"function",
|
|
"testConnection should be a function"
|
|
);
|
|
});
|
|
|
|
it("should export DUCKDUCKGO_BASE constant", () => {
|
|
assert.equal(
|
|
DUCKDUCKGO_BASE,
|
|
"https://duckduckgo.com",
|
|
"DUCKDUCKGO_BASE should be correct URL"
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("execute method validation", () => {
|
|
it("should reject empty messages array", async () => {
|
|
const executor = new DuckDuckGoWebExecutor();
|
|
|
|
const response = await executor.execute({
|
|
model: "gpt-4o-mini",
|
|
messages: [],
|
|
stream: false,
|
|
} as any);
|
|
|
|
assert.ok(response instanceof Response, "should return Response");
|
|
assert.equal(response.status, 400, "should return 400 for empty messages");
|
|
|
|
const body = await response.json();
|
|
assert.ok(body.error, "error response should have error field");
|
|
});
|
|
|
|
it("should accept non-empty messages array", async () => {
|
|
const executor = new DuckDuckGoWebExecutor();
|
|
|
|
// This will fail due to network, but should pass input validation
|
|
try {
|
|
const response = await executor.execute({
|
|
model: "gpt-4o-mini",
|
|
messages: [{ role: "user", content: "test" }],
|
|
stream: false,
|
|
} as any);
|
|
|
|
// Should either succeed with real response or fail with network error (status 5xx, not 400)
|
|
assert.notEqual(response.status, 400, "should not return 400 for valid messages");
|
|
} catch (error) {
|
|
// Network error is expected since we're not running against real DuckDuckGo
|
|
assert.ok(error instanceof Error, "should throw Error for network issues");
|
|
}
|
|
});
|
|
|
|
it("should handle missing model parameter", async () => {
|
|
const executor = new DuckDuckGoWebExecutor();
|
|
|
|
try {
|
|
await executor.execute({
|
|
model: undefined,
|
|
messages: [{ role: "user", content: "test" }],
|
|
stream: false,
|
|
} as any);
|
|
} catch (error) {
|
|
assert.ok(
|
|
error instanceof Error || error instanceof Response,
|
|
"should handle missing model"
|
|
);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("testConnection method", () => {
|
|
it("should return boolean", async () => {
|
|
const executor = new DuckDuckGoWebExecutor();
|
|
|
|
try {
|
|
const result = await executor.testConnection({});
|
|
assert.equal(typeof result, "boolean", "testConnection should return boolean");
|
|
} catch (error) {
|
|
// Network error is acceptable - just verify method exists and is callable
|
|
assert.ok(true, "testConnection is callable");
|
|
}
|
|
});
|
|
|
|
it("should abort the status request when its timeout expires", async (t) => {
|
|
t.mock.timers.enable({ apis: ["setTimeout"] });
|
|
let requestSignal: AbortSignal | null = null;
|
|
|
|
t.mock.method(globalThis, "fetch", async (input, init) => {
|
|
assert.equal(String(input), STATUS_URL);
|
|
assert.equal(init?.method, "GET");
|
|
requestSignal = init?.signal ?? null;
|
|
|
|
return new Promise<Response>((_resolve, reject) => {
|
|
requestSignal?.addEventListener("abort", () => reject(requestSignal?.reason), {
|
|
once: true,
|
|
});
|
|
});
|
|
});
|
|
|
|
const resultPromise = new DuckDuckGoWebExecutor().testConnection({});
|
|
assert.ok(requestSignal, "status fetch should receive an AbortSignal");
|
|
assert.equal(requestSignal.aborted, false);
|
|
|
|
t.mock.timers.tick(FETCH_TIMEOUT_MS);
|
|
|
|
assert.equal(requestSignal.aborted, true);
|
|
assert.equal(requestSignal.reason?.name, "TimeoutError");
|
|
assert.equal(await resultPromise, false);
|
|
});
|
|
});
|
|
|
|
describe("response handling", () => {
|
|
it("should handle AbortSignal", async () => {
|
|
const executor = new DuckDuckGoWebExecutor();
|
|
const controller = new AbortController();
|
|
|
|
// Abort immediately
|
|
controller.abort();
|
|
|
|
const response = await executor.execute({
|
|
model: "gpt-4o-mini",
|
|
body: { messages: [{ role: "user", content: "test" }] },
|
|
stream: false,
|
|
signal: controller.signal,
|
|
} as any);
|
|
|
|
assert.ok(response instanceof Response, "should return Response");
|
|
assert.equal(response.status, 499, "should return 499 for aborted request");
|
|
});
|
|
|
|
it("should support streaming parameter", async () => {
|
|
const executor = new DuckDuckGoWebExecutor();
|
|
|
|
try {
|
|
// Test with stream: true
|
|
const response1 = await executor.execute({
|
|
model: "gpt-4o-mini",
|
|
messages: [{ role: "user", content: "test" }],
|
|
stream: true,
|
|
} as any);
|
|
assert.ok(response1 instanceof Response, "streaming mode should return Response");
|
|
|
|
// Test with stream: false
|
|
const response2 = await executor.execute({
|
|
model: "gpt-4o-mini",
|
|
messages: [{ role: "user", content: "test" }],
|
|
stream: false,
|
|
} as any);
|
|
assert.ok(response2 instanceof Response, "non-streaming mode should return Response");
|
|
} catch (error) {
|
|
// Network errors are expected
|
|
assert.ok(error instanceof Error || error instanceof Response);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("error handling", () => {
|
|
it("should handle network timeouts gracefully", async () => {
|
|
const executor = new DuckDuckGoWebExecutor();
|
|
|
|
try {
|
|
const response = await executor.execute({
|
|
model: "gpt-4o-mini",
|
|
messages: [{ role: "user", content: "test" }],
|
|
stream: false,
|
|
} as any);
|
|
|
|
// Should get a response, not throw
|
|
assert.ok(response instanceof Response, "should return Response even on timeout");
|
|
} catch (error) {
|
|
// Timeout or network error is acceptable
|
|
assert.ok(error instanceof Error, "should handle errors gracefully");
|
|
}
|
|
});
|
|
|
|
it("should return valid error responses with JSON", async () => {
|
|
const executor = new DuckDuckGoWebExecutor();
|
|
|
|
const response = await executor.execute({
|
|
model: "gpt-4o-mini",
|
|
messages: [],
|
|
stream: false,
|
|
} as any);
|
|
|
|
assert.equal(response.status, 400);
|
|
const contentType = response.headers.get("content-type");
|
|
assert.ok(contentType?.includes("application/json"), "error response should be JSON");
|
|
|
|
const body = await response.json();
|
|
assert.ok(body.error, "error response should have error object");
|
|
assert.ok(body.error.message, "error should have message");
|
|
});
|
|
});
|
|
|
|
describe("integration checks", () => {
|
|
it("should be properly exported from executor module", async () => {
|
|
// Import the singleton as well
|
|
const { duckduckgoWebExecutor } = await import("../../open-sse/executors/duckduckgo-web.ts");
|
|
assert.ok(duckduckgoWebExecutor, "singleton executor should be exported");
|
|
assert.ok(duckduckgoWebExecutor.execute, "singleton should have execute method");
|
|
});
|
|
|
|
it("should be registered in executor index", async () => {
|
|
const { getExecutor } = await import("../../open-sse/executors/index.ts");
|
|
const executor = getExecutor("duckduckgo-web");
|
|
assert.ok(executor, "executor should be registered in index");
|
|
assert.equal(
|
|
typeof executor.execute,
|
|
"function",
|
|
"registered executor should have execute method"
|
|
);
|
|
});
|
|
});
|
|
});
|