mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 19:02:17 +03:00
`main` has been red since b342c1a361 on the vitest and integration gates:
✖ tests/unit/autoCombo/provider-family-combos.test.ts > auto/<family>
✖ chat pipeline applies Codex OAuth fingerprint and priority tier inside combos
Both call resetStorage() from beforeEach, which does an fs.rmSync(TEST_DATA_DIR,
{recursive: true, force: true}) with no retry, and intermittently loses the race
with a not-yet-released SQLite handle (ENOTEMPTY).
release/v3.8.51 fixed this in #11968 with a mechanical codemod adding
maxRetries/retryDelay to every recursive rm/rmSync/rmdirSync under tests/, but
that PR landed only on the release branch. Because main only receives work at
the release squash, it stayed broken for the whole cycle — and repo-wide gates
then turn every open PR into main red on checks unrelated to their diff.
This is the --base main twin: re-runs the same codemod that already shipped on
the release branch (scripts/ad-hoc/codemod-rm-maxretries.mjs), so the two
branches converge on identical test-teardown semantics. Test-only; no product
logic is touched.
The remaining three failures reported on #12133 (unit full suite exceeding its
4800s ceiling, package-artifact exceeding 1200s, and the boot-smoke that is
skipped as a consequence) are runner-contention timeouts, not code defects —
validate-release-green.mjs runs those heavy gates concurrently on one shared
hosted runner. There is no fix to port for those.
196 lines
7.4 KiB
TypeScript
196 lines
7.4 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { existsSync, readFileSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
|
|
import { join, dirname } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { tmpdir, homedir } from "node:os";
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const ROOT = join(__dirname, "..", "..");
|
|
|
|
test("bin/cli/plugins.mjs exporta discoverPlugins, loadPlugins, buildPluginContext", async () => {
|
|
const mod = await import("../../bin/cli/plugins.mjs");
|
|
assert.equal(typeof mod.discoverPlugins, "function");
|
|
assert.equal(typeof mod.loadPlugins, "function");
|
|
assert.equal(typeof mod.buildPluginContext, "function");
|
|
});
|
|
|
|
test("discoverPlugins retorna array vazio se nenhum plugin instalado (diretório não existe)", async () => {
|
|
const { discoverPlugins } = await import("../../bin/cli/plugins.mjs");
|
|
const orig = process.env.OMNIROUTE_PLUGIN_PATH;
|
|
process.env.OMNIROUTE_PLUGIN_PATH = join(tmpdir(), `no-such-dir-${Date.now()}`);
|
|
try {
|
|
const plugins = await discoverPlugins();
|
|
assert.ok(Array.isArray(plugins));
|
|
} finally {
|
|
if (orig === undefined) delete process.env.OMNIROUTE_PLUGIN_PATH;
|
|
else process.env.OMNIROUTE_PLUGIN_PATH = orig;
|
|
}
|
|
});
|
|
|
|
test("discoverPlugins descobre plugin com package.json válido", async () => {
|
|
const { discoverPlugins } = await import("../../bin/cli/plugins.mjs");
|
|
const pluginDir = join(tmpdir(), `omniroute-plugins-test-${Date.now()}`);
|
|
const pkgDir = join(pluginDir, "omniroute-cmd-test-hello");
|
|
mkdirSync(pkgDir, { recursive: true });
|
|
writeFileSync(
|
|
join(pkgDir, "package.json"),
|
|
JSON.stringify({
|
|
name: "omniroute-cmd-test-hello",
|
|
version: "1.0.0",
|
|
type: "module",
|
|
main: "index.mjs",
|
|
})
|
|
);
|
|
writeFileSync(join(pkgDir, "index.mjs"), `export function register() {}`);
|
|
|
|
const orig = process.env.OMNIROUTE_PLUGIN_PATH;
|
|
process.env.OMNIROUTE_PLUGIN_PATH = pluginDir;
|
|
try {
|
|
const plugins = await discoverPlugins();
|
|
assert.ok(
|
|
plugins.some((p) => p.name === "omniroute-cmd-test-hello"),
|
|
"deve encontrar o plugin"
|
|
);
|
|
} finally {
|
|
if (orig === undefined) delete process.env.OMNIROUTE_PLUGIN_PATH;
|
|
else process.env.OMNIROUTE_PLUGIN_PATH = orig;
|
|
try {
|
|
rmSync(pluginDir, { recursive: true, maxRetries: 5, retryDelay: 100 });
|
|
} catch {}
|
|
}
|
|
});
|
|
|
|
test("discoverPlugins ignora pacotes sem prefixo omniroute-cmd-", async () => {
|
|
const { discoverPlugins } = await import("../../bin/cli/plugins.mjs");
|
|
const pluginDir = join(tmpdir(), `omniroute-plugins-test-${Date.now()}`);
|
|
const pkgDir = join(pluginDir, "some-unrelated-package");
|
|
mkdirSync(pkgDir, { recursive: true });
|
|
writeFileSync(
|
|
join(pkgDir, "package.json"),
|
|
JSON.stringify({ name: "some-unrelated-package", version: "1.0.0" })
|
|
);
|
|
|
|
const orig = process.env.OMNIROUTE_PLUGIN_PATH;
|
|
process.env.OMNIROUTE_PLUGIN_PATH = pluginDir;
|
|
try {
|
|
const plugins = await discoverPlugins();
|
|
assert.ok(
|
|
!plugins.some((p) => p.name === "some-unrelated-package"),
|
|
"não deve descobrir pacotes sem prefixo"
|
|
);
|
|
} finally {
|
|
if (orig === undefined) delete process.env.OMNIROUTE_PLUGIN_PATH;
|
|
else process.env.OMNIROUTE_PLUGIN_PATH = orig;
|
|
try {
|
|
rmSync(pluginDir, { recursive: true, maxRetries: 5, retryDelay: 100 });
|
|
} catch {}
|
|
}
|
|
});
|
|
|
|
test("loadPlugins não quebra CLI quando plugin tem erro de load (try/catch)", async () => {
|
|
const { loadPlugins } = await import("../../bin/cli/plugins.mjs");
|
|
const pluginDir = join(tmpdir(), `omniroute-plugins-test-${Date.now()}`);
|
|
const pkgDir = join(pluginDir, "omniroute-cmd-broken");
|
|
mkdirSync(pkgDir, { recursive: true });
|
|
writeFileSync(
|
|
join(pkgDir, "package.json"),
|
|
JSON.stringify({
|
|
name: "omniroute-cmd-broken",
|
|
version: "1.0.0",
|
|
type: "module",
|
|
main: "broken.mjs",
|
|
})
|
|
);
|
|
writeFileSync(join(pkgDir, "broken.mjs"), "throw new Error('intentional load error');");
|
|
|
|
const orig = process.env.OMNIROUTE_PLUGIN_PATH;
|
|
process.env.OMNIROUTE_PLUGIN_PATH = pluginDir;
|
|
const { Command } = await import("commander");
|
|
const prog = new Command();
|
|
try {
|
|
// Deve não lançar exceção
|
|
await assert.doesNotReject(async () => loadPlugins(prog));
|
|
} finally {
|
|
if (orig === undefined) delete process.env.OMNIROUTE_PLUGIN_PATH;
|
|
else process.env.OMNIROUTE_PLUGIN_PATH = orig;
|
|
try {
|
|
rmSync(pluginDir, { recursive: true, maxRetries: 5, retryDelay: 100 });
|
|
} catch {}
|
|
}
|
|
});
|
|
|
|
test("loadPlugins carrega plugin válido e chama register()", async () => {
|
|
const { loadPlugins } = await import("../../bin/cli/plugins.mjs");
|
|
const pluginDir = join(tmpdir(), `omniroute-plugins-test-${Date.now()}`);
|
|
const pkgDir = join(pluginDir, "omniroute-cmd-valid");
|
|
mkdirSync(pkgDir, { recursive: true });
|
|
writeFileSync(
|
|
join(pkgDir, "package.json"),
|
|
JSON.stringify({
|
|
name: "omniroute-cmd-valid",
|
|
version: "1.0.0",
|
|
type: "module",
|
|
main: "index.mjs",
|
|
})
|
|
);
|
|
// Plugin que adiciona um comando 'testcmd'
|
|
writeFileSync(
|
|
join(pkgDir, "index.mjs"),
|
|
`export function register(program) { program.command('testcmd-from-plugin'); }`
|
|
);
|
|
|
|
const orig = process.env.OMNIROUTE_PLUGIN_PATH;
|
|
process.env.OMNIROUTE_PLUGIN_PATH = pluginDir;
|
|
const { Command } = await import("commander");
|
|
const prog = new Command();
|
|
try {
|
|
const count = await loadPlugins(prog);
|
|
assert.ok(count >= 1, "deve ter carregado pelo menos 1 plugin");
|
|
assert.ok(
|
|
prog.commands.some((c) => c.name() === "testcmd-from-plugin"),
|
|
"comando do plugin deve estar registrado"
|
|
);
|
|
} finally {
|
|
if (orig === undefined) delete process.env.OMNIROUTE_PLUGIN_PATH;
|
|
else process.env.OMNIROUTE_PLUGIN_PATH = orig;
|
|
try {
|
|
rmSync(pluginDir, { recursive: true, maxRetries: 5, retryDelay: 100 });
|
|
} catch {}
|
|
}
|
|
});
|
|
|
|
test("commands/plugin.mjs exporta registerPlugin", async () => {
|
|
const mod = await import("../../bin/cli/commands/plugin.mjs");
|
|
assert.equal(typeof mod.registerPlugin, "function");
|
|
});
|
|
|
|
test("registerPlugin registra subcomandos: list, install, remove, info, search, update, scaffold", async () => {
|
|
const { registerPlugin } = await import("../../bin/cli/commands/plugin.mjs");
|
|
const { Command } = await import("commander");
|
|
const prog = new Command().exitOverride();
|
|
registerPlugin(prog);
|
|
const pluginCmd = prog.commands.find((c) => c.name() === "plugin");
|
|
assert.ok(pluginCmd, "plugin command deve existir");
|
|
const names = pluginCmd.commands.map((c) => c.name());
|
|
for (const sub of ["list", "install", "remove", "info", "search", "update", "scaffold"]) {
|
|
assert.ok(names.includes(sub), `plugin ${sub} deve existir`);
|
|
}
|
|
});
|
|
|
|
test("exemplo omniroute-cmd-hello existe e tem register()", () => {
|
|
const examplePath = join(ROOT, "examples", "omniroute-cmd-hello", "index.mjs");
|
|
assert.ok(existsSync(examplePath), "exemplo index.mjs deve existir");
|
|
const src = readFileSync(examplePath, "utf8");
|
|
assert.ok(src.includes("export function register"), "deve exportar register");
|
|
assert.ok(src.includes("export const meta"), "deve exportar meta");
|
|
});
|
|
|
|
test("docs/frameworks/PLUGINS.md existe", () => {
|
|
const docPath = join(ROOT, "docs", "frameworks", "PLUGINS.md");
|
|
assert.ok(existsSync(docPath), "docs/frameworks/PLUGINS.md deve existir");
|
|
const src = readFileSync(docPath, "utf8");
|
|
assert.ok(src.includes("omniroute-cmd"), "deve mencionar omniroute-cmd");
|
|
assert.ok(src.includes("register(program, ctx)"), "deve documentar a API register");
|
|
});
|