mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-26 17:12:27 +03:00
Validated in a combined 3-PR batch worktree off release/v3.8.51 tip. This PR conflicted against today's accumulated merges (mostly pure provider-count drift: 353 vs its 352 snapshot across 51 docs/i18n/SVG files — resolved to the release's current 353, confirmed byte-identical besides the count on diff). Two real code conflicts: - src/lib/usage/providerLimits.ts: this PR's `syntheticCooldownOutlivedByRealWindows()` is genuinely new (didn't exist on the tip; a caller already referencing it elsewhere in the file confirmed it was required) — kept in full. - tests/unit/providers-constants-split.test.ts: both sides' running-count comments land at the same 233 via different additions (this PR's volcengine-agent/coding-plan vs the v3.8.50 back-merge's Synthetic + Kilo Gateway, both already present in providers.ts) — combined as sequential history, no functional change. Resolution pushed to the PR branch and re-validated: - Focused tests: 8134-github-t5-fallback-filter, cc-compatible-provider, cli-oneproxy-commands, hard-session-lease-bypass-inventory, llm-selector-custom-vision-models, model-capabilities-registry, openapi-coverage, provider-limits-recovery, providers-constants-split, repro-glm-iso-reset-24h-cap, startup-stale-cooldown-recovery, memory-pipeline, security-hardening, skills-pipeline — part of batch's 165/165 node:test run; glmCodingProviderConfig.test.ts (vitest) 10/10 - typecheck:core, file-size, changelog-integrity, complexity, cognitive-complexity, check:docs-counts-sync — all OK - Full-repo lint: 228 pre-existing dashboard react-hooks/* findings, unrelated to this diff Thanks for this — root-causing all 18 failed jobs from a single CI run with gate-by-gate evidence (including the harder-to-spot ones like the antigravity BYOP legacy-ack misread and the reserved-alias `cc` guard) is exactly the kind of base-red drain this release needs.
97 lines
3.7 KiB
TypeScript
97 lines
3.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 () => {
|
|
const origFetch = globalThis.fetch;
|
|
globalThis.fetch = makeMcpStreamFetch({ toolResult: { poolSize: 10, activeProxies: 8 } });
|
|
const { mcpCallTool } = await import("../../bin/cli/mcpClient.mjs");
|
|
const result = await mcpCallTool("omniroute_oneproxy_stats", {});
|
|
globalThis.fetch = origFetch;
|
|
assert.equal((result as any).poolSize, 10);
|
|
assert.equal((result as any).activeProxies, 8);
|
|
assert.ok("poolSize" in (result as object) && "activeProxies" in (result as object));
|
|
});
|
|
|
|
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");
|
|
});
|