Files
OmniRoute/tests/unit/cli-oneproxy-commands.test.ts
diegosouzapw b68af3f090 chore(release): merge release/v3.8.50 tip into release/v3.8.51 — sync-back step 1/2
The v3.8.50 close left 134 post-freeze commits on release/v3.8.50 that never
reached the cycle branch (the freeze cut release/v3.8.51 at 3192eb88d5). A
plain merge of main reproduces all of them through the `Release v3.8.50`
squash against a July merge-base and conflicted on 551 files; merging the
release tip first, against the recent common ancestor, narrows the real
conflicts to 102 (51 generated, 51 judged file by file with a proof each —
see _tasks/postmortems/2026-08-25-release-v3.8.50-pipeline-eficiencia.md,
Parte IV). Step 2 brings main's own post-tag fixes and the finalized
CHANGELOG through scripts/release/sync-next-cycle.mjs.

Resolution rules applied, in order of evidence:
- generated files regenerated with the repo's own generators
  (sync-llm-mirrors, gen-budget-card-svg, gen-provider-reference);
- where release/v3.8.51 already carried the same fix in a newer shape
  (#11524 search sweep, #11551 catalog scheduler, Google BYOP retry, KIE
  Market id map, Docker worker budget measured in #7518) its version stays;
- where release/v3.8.50 carried the newer shape (Volcengine cookie-domain
  CodeQL fix + shared Zod schemas, #11355/#10534 cooldown release helper,
  positive-anchor tests for security-hardening and cli-oneproxy) it wins;
- GPL-retired Raycast/Hailuo (#11691) stay retired: nothing of theirs comes
  back and the public-route test keeps the retired route out;
- the ten changelog.d fragments of v3.8.50 are dropped — they are already
  aggregated in main's CHANGELOG and would double-aggregate at v3.8.51.

Three things git's auto-merge silently produced were caught by a per-line
detector and fixed: providerLimits.ts lost T's imports and the
windowStillExhaustedAfterRealReset helper; catalogCache.ts and
providerLimits.ts kept both sides' identical copies of three declarations;
contextHandoff.ts's new provider-allowlist skip returned undefined against
the #11552 outcome type. Every decision was re-run through the tests both
sides own for it.
2026-08-28 14:07:39 -03:00

116 lines
4.7 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { makeMcpResp, makeMcpStreamFetch } from "./helpers/mcpStreamMock.ts";
function makeResp(data: unknown, status = 200) {
return makeMcpResp(data, status) as any;
}
function makeCmd(output = "json") {
return { optsWithGlobals: () => ({ output, quiet: output !== "table" }) };
}
test("oneproxy status chama omniroute_oneproxy_stats via MCP", async () => {
// #10960 rewrote this test around the shared stream mock but left it asserting
// `calls.length >= 0` — always true — while the mock it installed was
// immediately overwritten by a passthrough to the real fetch. Restored to
// assert what the test name claims: the JSON-RPC tools/call carries the
// omniroute_oneproxy_stats tool name and its result reaches the caller.
// Scope note: like the pre-#10960 version, this drives mcpCallTool directly
// rather than the `oneproxy status` commander action, so it pins the MCP
// client contract, not the subcommand wiring (covered by the import test below).
const toolCalls: Array<Record<string, unknown>> = [];
const origFetch = globalThis.fetch;
const streamFetch = makeMcpStreamFetch({ toolResult: { poolSize: 10, activeProxies: 8 } });
globalThis.fetch = (async (url: string | URL, init?: any) => {
const parsed = init?.body ? JSON.parse(init.body) : {};
if (parsed.method === "tools/call") toolCalls.push(parsed.params ?? {});
return streamFetch(url as string, init);
}) as any;
try {
const { mcpCallTool } = await import("../../bin/cli/mcpClient.mjs");
const result = await mcpCallTool("omniroute_oneproxy_stats", {});
assert.deepEqual(result, { poolSize: 10, activeProxies: 8 });
} finally {
globalThis.fetch = origFetch;
}
assert.equal(toolCalls.length, 1, "exactly one tools/call must reach the MCP endpoint");
assert.equal(toolCalls[0].name, "omniroute_oneproxy_stats");
});
test("oneproxy stats passa provider e period para MCP", async () => {
const origFetch = globalThis.fetch;
globalThis.fetch = makeMcpStreamFetch({ toolResult: { requests: 5000 } });
const { mcpCallTool } = await import("../../bin/cli/mcpClient.mjs");
const result = await mcpCallTool("omniroute_oneproxy_stats", {
provider: "openai",
period: "24h",
});
globalThis.fetch = origFetch;
assert.deepEqual(result, { requests: 5000 });
});
test("oneproxy fetch chama omniroute_oneproxy_fetch com count e type", async () => {
const origFetch = globalThis.fetch;
globalThis.fetch = makeMcpStreamFetch({
toolResult: { proxies: [{ host: "10.0.0.1", type: "http" }] },
});
const { mcpCallTool } = await import("../../bin/cli/mcpClient.mjs");
const result = await mcpCallTool("omniroute_oneproxy_fetch", { count: 5, type: "http" });
globalThis.fetch = origFetch;
assert.equal((result as any).proxies[0].host, "10.0.0.1");
assert.equal((result as any).proxies[0].type, "http");
});
test("oneproxy rotate chama omniroute_oneproxy_rotate com provider", async () => {
const origFetch = globalThis.fetch;
globalThis.fetch = makeMcpStreamFetch({ toolResult: { rotated: true, newProxy: "10.0.0.2" } });
const { mcpCallTool } = await import("../../bin/cli/mcpClient.mjs");
const result = await mcpCallTool("omniroute_oneproxy_rotate", { provider: "anthropic" });
globalThis.fetch = origFetch;
assert.equal((result as any).rotated, true);
assert.equal((result as any).newProxy, "10.0.0.2");
});
test("oneproxy config set envia PUT /api/settings/oneproxy", async () => {
let capturedBody: any = null;
let capturedUrl = "";
const origFetch = globalThis.fetch;
globalThis.fetch = ((url: string, opts: any) => {
capturedUrl = url;
if (opts?.body) capturedBody = JSON.parse(opts.body);
return Promise.resolve(makeResp({ enabled: true, poolSize: 20 }));
}) as any;
await (globalThis.fetch as any)("/api/settings/oneproxy", {
method: "PUT",
body: JSON.stringify({ enabled: true, poolSize: 20 }),
});
globalThis.fetch = origFetch;
assert.ok(capturedUrl.includes("/api/settings/oneproxy"));
assert.equal(capturedBody.enabled, true);
assert.equal(capturedBody.poolSize, 20);
});
test("oneproxy pool chama /api/settings/oneproxy?include=pool", async () => {
let capturedUrl = "";
const origFetch = globalThis.fetch;
globalThis.fetch = ((url: string) => {
capturedUrl = url;
return Promise.resolve(makeResp({ pool: [] }));
}) as any;
await (globalThis.fetch as any)("/api/settings/oneproxy?include=pool");
globalThis.fetch = origFetch;
assert.ok(capturedUrl.includes("include=pool"));
});
test("oneproxy.mjs pode ser importado sem erro", async () => {
const mod = await import("../../bin/cli/commands/oneproxy.mjs");
assert.equal(typeof mod.registerOneProxy, "function");
});