mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-11 09:42:15 +03:00
* test(integration): add general live-test tool for the real "default" combo Temporary WIP commit on this deferred branch — lands in its own separate PR once the bug-fix extraction batch is done (never bundled into a bug-fix PR). Unlike liveGeminiShared.ts (provisions its own narrow 2-model Gemini-only combo), this reads the REAL "default" combo currently configured on the target instance directly from the DB and exercises every provider/model step in it directly, bypassing combo routing, so live-test coverage always matches whatever is actually configured instead of a hardcoded snapshot. Live-verified against omniroute-beta (seeded with the real 18-model, 5-provider default combo): 14/18 models pass consistently across non-streaming + streaming Chat Completions and streaming Responses API. The 4 consistent failures are real external state (cerebras credits_exhausted, one deprecated openrouter free-tier model), not code regressions. (cherry picked from commit c40b13a48fd897259c56f5122e9e57a3dc7654ba) * test(integration): add rootless wire-capture correlation to the live-test tool Temporary WIP commit on this deferred branch — lands in the same final live-test-tool PR as the general default-combo suite, never bundled into a bug-fix PR. liveContainerHarness.ts spins up a dedicated, throwaway podman container (same runner-base image target as the operator's local dev/beta containers) so wire-capture tests are fully self-contained: builds the image if missing, starts the container with a persistent data dir, waits for health, seeds the real "default" combo + provider connections from the operator's local omniroute-dev instance (idempotent — only runs once per data dir), and provisions API keys via the running instance's own auth flow. wireCapture.ts captures the container's actual network traffic via `podman unshare nsenter --net=<container netns> -- tcpdump` — no root needed, verified working live (this generalizes the root-requiring `sudo nsenter -t $PID` command scripts/sre/tcp-close-analyzer.py already documented for the same rootless-Podman netns problem; that script's docstring now documents both). Capture and analysis needed two real fixes found only by running the pipeline live: `-U` (unbuffered tcpdump writes) plus a `pkill -f <pcap path>` fallback, since `podman unshare -> nsenter -> tcpdump` is a 3-level subprocess chain and SIGTERM to the top-level process doesn't reach the tcpdump grandchild, leaving an orphaned process and a truncated/unreadable pcap; and filtering on the container's internal listening port (20128) rather than the dynamically-assigned host port, since capture happens inside the container's own network namespace where only the internal port is meaningful. live-default-combo-wire-capture.test.ts (gated on RUN_LIVE_WIRE_CAPTURE=1) ties it together: sends a small representative sample of requests through the real default combo, then cross-checks each one's app-level JSON status against the actual HTTP status line observed on the wire via scripts/sre/tcp-close-analyzer.py's stream reassembly — catching bugs where the app layer claims success but the wire shows a truncated/reset stream, not just what liveDefaultComboShared.ts's existing breadth suite already covers. Live-verified end-to-end: 4/4 sampled requests correlated correctly across 8 captured TCP streams, container + capture process fully torn down afterward (verified no orphaned podman container or tcpdump process left running). sendModelRequest/filterActiveModelTargets (liveDefaultComboShared.ts) gain optional baseUrl/apiKey overrides, defaulting to the existing module-level omniroute-beta target, so the wire-capture suite can point the same request-sending logic at its own dedicated container instead. (cherry picked from commit 914a7e42cbe914f257db9f72eedc902ee1532083) --------- Co-authored-by: Markus Hartung <mail@hartmark.se>
267 lines
10 KiB
TypeScript
267 lines
10 KiB
TypeScript
/**
|
|
* tests/integration/liveDefaultComboShared.ts
|
|
*
|
|
* Shared utilities for the general "default combo" live workload test.
|
|
* Unlike liveGeminiShared.ts (which provisions its own narrow 2-model
|
|
* Gemini-only combo when "default" doesn't already exist), this reads the
|
|
* REAL "default" combo currently configured on the target instance directly
|
|
* from its own DB (src/lib/db/combos.ts — never raw SQL, per AGENTS.md) and
|
|
* exercises every provider/model step in it directly, bypassing combo
|
|
* routing, so live-test coverage always matches whatever the operator
|
|
* actually has configured instead of a hardcoded snapshot that goes stale
|
|
* the moment the combo changes.
|
|
*/
|
|
import {
|
|
API_KEY,
|
|
BASE_URL,
|
|
readSSEStream,
|
|
readResponsesSSEStream,
|
|
genSystemMessage,
|
|
genUserMessage,
|
|
type Message,
|
|
} from "./liveGeminiShared.ts";
|
|
|
|
export { API_KEY, BASE_URL };
|
|
|
|
export const skip = !API_KEY ? "OMNIROUTE_API_KEY not set — skipping live test" : undefined;
|
|
|
|
export interface ComboModelTarget {
|
|
model: string;
|
|
providerId: string | null;
|
|
}
|
|
|
|
async function apiFetch(path: string, options: RequestInit = {}): Promise<Response> {
|
|
return fetch(`${BASE_URL}${path}`, {
|
|
...options,
|
|
headers: {
|
|
Authorization: `Bearer ${API_KEY}`,
|
|
"Content-Type": "application/json",
|
|
...options.headers,
|
|
},
|
|
});
|
|
}
|
|
|
|
// Bootstrap seed used ONLY when the target instance has no "default" combo
|
|
// at all — mirrors liveGeminiShared.ts's own DEFAULT_COMBO_CONFIG fallback,
|
|
// generalized to the real multi-provider spread confirmed live against this
|
|
// operator's own production "default" combo (5 providers, 18 models) rather
|
|
// than Gemini alone. This is a creation fallback only: whenever a "default"
|
|
// combo already exists on the target instance, its actual live config is
|
|
// always what gets read and tested — this list never overrides it.
|
|
const FALLBACK_COMBO_MODELS: { model: string; providerId: string }[] = [
|
|
{ model: "opencode/big-pickle", providerId: "opencode" },
|
|
{ model: "opencode/mimo-v2.5-free", providerId: "opencode" },
|
|
{ model: "opencode/laguna-s-2.1-free", providerId: "opencode" },
|
|
{ model: "openrouter/cohere/north-mini-code:free", providerId: "openrouter" },
|
|
{ model: "openrouter/poolside/laguna-m.1:free", providerId: "openrouter" },
|
|
{ model: "openrouter/nvidia/nemotron-3-ultra-550b-a55b:free", providerId: "openrouter" },
|
|
{ model: "openrouter/nvidia/nemotron-3-super-120b-a12b:free", providerId: "openrouter" },
|
|
{ model: "openrouter/nvidia/nemotron-3-nano-30b-a3b:free", providerId: "openrouter" },
|
|
{ model: "openrouter/google/gemma-4-26b-a4b-it:free", providerId: "openrouter" },
|
|
{ model: "openrouter/google/gemma-4-31b-it:free", providerId: "openrouter" },
|
|
{ model: "openrouter/poolside/laguna-s-2.1:free", providerId: "openrouter" },
|
|
{ model: "gemini/gemini-3.1-flash-lite", providerId: "gemini" },
|
|
{ model: "gemini/gemma-4-31b-it", providerId: "gemini" },
|
|
{ model: "gemini/gemma-4-26b-a4b-it", providerId: "gemini" },
|
|
{ model: "mistral/mistral-large-latest", providerId: "mistral" },
|
|
{ model: "cerebras/gemma-4-31b", providerId: "cerebras" },
|
|
{ model: "cerebras/zai-glm-4.7", providerId: "cerebras" },
|
|
{ model: "cerebras/gpt-oss-120b", providerId: "cerebras" },
|
|
];
|
|
|
|
async function ensureDefaultComboExists(
|
|
getComboByName: (name: string) => Promise<Record<string, unknown> | null>
|
|
): Promise<void> {
|
|
const existing = await getComboByName("default");
|
|
if (existing) return;
|
|
|
|
console.log(` [setup] no "default" combo on this instance — creating fallback seed combo`);
|
|
const { createCombo } = await import("../../src/lib/db/combos.ts");
|
|
await createCombo({
|
|
name: "default",
|
|
strategy: "priority",
|
|
models: FALLBACK_COMBO_MODELS.map((m, i) => ({
|
|
kind: "model" as const,
|
|
model: m.model,
|
|
providerId: m.providerId,
|
|
weight: 1,
|
|
id: `fallback-${i}`,
|
|
})),
|
|
});
|
|
}
|
|
|
|
// Read the live "default" combo's model steps straight from the DB module —
|
|
// intentionally not hardcoded, so this always reflects whatever the operator
|
|
// currently has configured on the target instance. Creates a fallback seed
|
|
// combo first if none exists at all (see ensureDefaultComboExists above).
|
|
export async function getDefaultComboModelTargets(): Promise<ComboModelTarget[]> {
|
|
const { getComboByName } = await import("../../src/lib/db/combos.ts");
|
|
await ensureDefaultComboExists(getComboByName);
|
|
const combo = (await getComboByName("default")) as Record<string, unknown> | null;
|
|
const models =
|
|
combo && Array.isArray(combo.models) ? (combo.models as Record<string, unknown>[]) : [];
|
|
|
|
const targets: ComboModelTarget[] = [];
|
|
for (const step of models) {
|
|
if (step.kind !== "model" || typeof step.model !== "string") continue;
|
|
targets.push({
|
|
model: step.model,
|
|
providerId: typeof step.providerId === "string" ? step.providerId : null,
|
|
});
|
|
}
|
|
return targets;
|
|
}
|
|
|
|
// Skip (never fail) any model whose provider connection isn't currently
|
|
// active — this suite's job is breadth across the real combo, not blocking
|
|
// the whole run on one unrelated provider outage. baseUrl/apiKey default to
|
|
// the module-level omniroute-beta target but can be overridden (see
|
|
// sendModelRequest — same rationale, used by the wire-capture suite's
|
|
// dedicated container).
|
|
export async function filterActiveModelTargets(
|
|
targets: ComboModelTarget[],
|
|
options: SendModelRequestOptions = {}
|
|
): Promise<{ active: ComboModelTarget[]; skipped: string[] }> {
|
|
const baseUrl = options.baseUrl ?? BASE_URL;
|
|
const apiKey = options.apiKey ?? API_KEY;
|
|
const res = await fetch(`${baseUrl}/api/providers`, {
|
|
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
});
|
|
if (!res.ok) return { active: targets, skipped: [] };
|
|
|
|
const data = await res.json();
|
|
const connections = (data.connections || data) as Record<string, unknown>[];
|
|
// Terminal states (never self-heal — see AGENTS.md "Resilience Runtime
|
|
// State" → Connection Cooldown) plus "unavailable" (active cooldown) are
|
|
// the only statuses worth pre-filtering; everything else (including
|
|
// transient/lazily-recovered cooldowns that have already expired) is left
|
|
// for the request itself to prove out.
|
|
const DEAD_STATUSES = new Set(["expired", "unavailable", "banned", "credits_exhausted"]);
|
|
const activeProviders = new Set(
|
|
connections
|
|
.filter((c) => c.isActive && !DEAD_STATUSES.has(c.testStatus as string))
|
|
.map((c) => c.provider as string)
|
|
);
|
|
|
|
const active: ComboModelTarget[] = [];
|
|
const skipped: string[] = [];
|
|
for (const t of targets) {
|
|
if (!t.providerId || activeProviders.has(t.providerId)) {
|
|
active.push(t);
|
|
} else {
|
|
skipped.push(`${t.model} (provider "${t.providerId}" not active)`);
|
|
}
|
|
}
|
|
return { active, skipped };
|
|
}
|
|
|
|
function ts(): string {
|
|
return new Date().toISOString().slice(11, 23); // HH:MM:SS.mmm
|
|
}
|
|
|
|
export interface ModelRequestResult {
|
|
model: string;
|
|
status: number;
|
|
duration: number;
|
|
tokens: number;
|
|
contentLength: number;
|
|
correlationId: string;
|
|
error?: string;
|
|
}
|
|
|
|
export interface SendModelRequestOptions {
|
|
baseUrl?: string;
|
|
apiKey?: string;
|
|
}
|
|
|
|
// Deliberately lighter than liveGeminiShared's sendAndValidate (no retry
|
|
// loop, one fixed prompt pair): this suite's job is breadth across every
|
|
// model in the real combo, not depth on any single provider. baseUrl/apiKey
|
|
// default to the module-level omniroute-beta target but can be overridden —
|
|
// e.g. by the wire-capture suite, which points requests at its own
|
|
// dedicated throwaway container instead (see liveContainerHarness.ts).
|
|
export async function sendModelRequest(
|
|
model: string,
|
|
stream: boolean,
|
|
apiFormat: "chat" | "responses" = "chat",
|
|
options: SendModelRequestOptions = {}
|
|
): Promise<ModelRequestResult> {
|
|
const baseUrl = options.baseUrl ?? BASE_URL;
|
|
const apiKey = options.apiKey ?? API_KEY;
|
|
const endpoint = apiFormat === "responses" ? "/v1/responses" : "/v1/chat/completions";
|
|
const messages: Message[] = [genSystemMessage(), genUserMessage()];
|
|
const body =
|
|
apiFormat === "responses"
|
|
? { model, input: messages, stream, max_output_tokens: 1024, temperature: 0.3 }
|
|
: { model, messages, stream, max_tokens: 1024, temperature: 0.3 };
|
|
|
|
const controller = new AbortController();
|
|
const timeoutMs = Number(process.env.TEST_REQUEST_TIMEOUT_MS) || 120_000;
|
|
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
const start = performance.now();
|
|
|
|
try {
|
|
const response = await fetch(`${baseUrl}${endpoint}`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}` },
|
|
body: JSON.stringify(body),
|
|
signal: controller.signal,
|
|
});
|
|
const duration = performance.now() - start;
|
|
clearTimeout(timeout);
|
|
const correlationId = response.headers.get("x-correlation-id") || "?";
|
|
|
|
let content = "";
|
|
let totalTokens = 0;
|
|
|
|
if (response.status === 200) {
|
|
if (stream) {
|
|
const streamResult =
|
|
apiFormat === "responses"
|
|
? await readResponsesSSEStream(response)
|
|
: await readSSEStream(response);
|
|
content = streamResult.fullContent;
|
|
totalTokens = streamResult.totalTokens;
|
|
} else if (apiFormat === "responses") {
|
|
const json = await response.json().catch(() => ({}));
|
|
const textItem = json?.output?.find((o: Record<string, unknown>) => o.type === "message");
|
|
content = textItem?.content?.[0]?.text || "";
|
|
totalTokens = json?.usage?.total_tokens || 0;
|
|
} else {
|
|
const json = await response.json().catch(() => ({}));
|
|
content = json?.choices?.[0]?.message?.content || "";
|
|
totalTokens = json?.usage?.total_tokens || 0;
|
|
}
|
|
}
|
|
|
|
console.log(
|
|
`${ts()} ${model.padEnd(40)} HTTP ${response.status} | ` +
|
|
`${Math.round(duration).toString().padStart(6)}ms | ` +
|
|
`${String(totalTokens).padStart(5)} tok | ` +
|
|
`${content.length} chars | cid: ${correlationId}`
|
|
);
|
|
|
|
return {
|
|
model,
|
|
status: response.status,
|
|
duration,
|
|
tokens: totalTokens,
|
|
contentLength: content.length,
|
|
correlationId,
|
|
};
|
|
} catch (err) {
|
|
clearTimeout(timeout);
|
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
console.log(`${ts()} ${model.padEnd(40)} FAILED: ${errorMessage}`);
|
|
return {
|
|
model,
|
|
status: 0,
|
|
duration: performance.now() - start,
|
|
tokens: 0,
|
|
contentLength: 0,
|
|
correlationId: "?",
|
|
error: errorMessage,
|
|
};
|
|
}
|
|
}
|