Files
OmniRoute/scripts/dev/run-ecosystem-tests.mjs
Arnav Rastogi 397ec88751 fix(ci): repair and wire the two live-server E2E suites (#10050)
tests/e2e/ecosystem.test.ts and tests/e2e/protocol-clients.test.ts appear in the
AGENTS.md test matrix but ran in no workflow, and could not run at all: both are
listed in vitest.config.ts include AND exclude, and their runners invoked Vitest
without --config, so the default config's exclusion discarded the very file each
passed as a positional filter.

  No test files found, exiting with code 1
  filter: tests/e2e/ecosystem.test.ts

Add vitest.e2e-live.config.ts covering only these two suites, point both runners
at it, and drop the contradictory include entries. The exclusions stay: these
drive a real server and must never run in the jsdom UI job.

Wire both into CI. test-ecosystem is blocking (20/20 green). test-protocols-e2e
is advisory pending #10049 — restoring it surfaced a pre-existing discrepancy
where GET /api/mcp/audit answers 403 over loopback against an expected 200|401.
2026-08-13 07:52:22 -03:00

117 lines
3.2 KiB
JavaScript

#!/usr/bin/env node
import { spawn } from "node:child_process";
import { join } from "node:path";
import { setTimeout as delay } from "node:timers/promises";
import { sanitizeColorEnv } from "../build/runtime-env.mjs";
function parsePort(value, fallback) {
const parsed = Number.parseInt(String(value), 10);
return Number.isFinite(parsed) && parsed > 0 && parsed <= 65535 ? parsed : fallback;
}
const explicitBaseUrl = process.env.OMNIROUTE_BASE_URL || "";
const isolatedPort = parsePort(
process.env.DASHBOARD_PORT || process.env.PORT,
22000 + (process.pid % 1000)
);
const isolatedDataDir =
process.env.DATA_DIR || join(process.cwd(), ".tmp", "ecosystem-data", String(process.pid));
const port = explicitBaseUrl ? null : isolatedPort;
const baseUrl = explicitBaseUrl || `http://127.0.0.1:${isolatedPort}`;
const healthUrl = `${baseUrl}/api/monitoring/health`;
const maxWaitMs = Number(process.env.ECOSYSTEM_SERVER_WAIT_MS || 180000);
const pollMs = 2000;
async function isServerReady() {
const timeout = AbortSignal.timeout(2000);
try {
const res = await fetch(healthUrl, { signal: timeout });
return res.ok;
} catch {
return false;
}
}
async function waitForServerReady() {
const maxAttempts = Math.ceil(maxWaitMs / pollMs);
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
if (await isServerReady()) {
return;
}
await delay(pollMs);
}
throw new Error(`Timed out waiting for ${healthUrl} after ${maxWaitMs}ms`);
}
async function main() {
let serverProcess = null;
let startedHere = false;
const testEnv = {
...sanitizeColorEnv(process.env),
DATA_DIR: isolatedDataDir,
...(explicitBaseUrl
? {}
: {
PORT: String(port),
DASHBOARD_PORT: String(port),
API_PORT: String(port),
OMNIROUTE_BASE_URL: baseUrl,
}),
OMNIROUTE_E2E_BOOTSTRAP_MODE: process.env.OMNIROUTE_E2E_BOOTSTRAP_MODE || "open",
REQUIRE_API_KEY: explicitBaseUrl ? process.env.REQUIRE_API_KEY : "false",
ENABLE_CLI_TOOLS: "true",
};
if (!(await isServerReady())) {
serverProcess = spawn(process.execPath, ["scripts/dev/run-next-playwright.mjs", "dev"], {
stdio: "inherit",
env: testEnv,
});
startedHere = true;
await waitForServerReady();
}
const vitestProcess = spawn(
process.execPath,
[
"./node_modules/vitest/vitest.mjs",
"run",
// Without --config, Vitest loads vitest.config.ts, whose exclude list drops
// this file — the run then dies with "No test files found".
"--config",
"vitest.e2e-live.config.ts",
"tests/e2e/ecosystem.test.ts",
],
{
stdio: "inherit",
env: testEnv,
}
);
const exitCode = await new Promise((resolve) => {
vitestProcess.on("exit", (code, signal) => {
if (signal) {
resolve(1);
return;
}
resolve(code ?? 1);
});
});
if (startedHere && serverProcess) {
serverProcess.kill("SIGTERM");
await delay(1000);
if (!serverProcess.killed) {
serverProcess.kill("SIGKILL");
}
}
process.exit(exitCode);
}
main().catch((error) => {
console.error("[test:ecosystem] Failed:", error?.message || error);
process.exit(1);
});