Files
OmniRoute/tests/unit/plugins-scanner.test.ts
Diego Rodrigues de Sa e Souza 93265eede3 test(infra): retry recursive temp-dir removal on main (main twin of #11968) (#12246)
* test(infra): retry recursive temp-dir removal on main (main twin of #11968)

`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.

* chore(scripts): carry the rm-maxretries codemod onto main alongside its output

The codemod that generated the previous commit lives in the repo on
release/v3.8.51 (added by #11968) but was never on main. Bringing it over keeps
the tool next to the change it produced, so the transformation stays
reproducible and auditable from either branch.
2026-09-01 01:48:00 -03:00

84 lines
3.1 KiB
TypeScript

import { describe, it } from "node:test";
import assert from "node:assert/strict";
import { mkdtempSync, writeFileSync, mkdirSync, rmSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
const mod = await import("../../src/lib/plugins/scanner.ts");
function makePluginDir(tmpDir: string, name: string, manifest: Record<string, unknown>) {
const pluginDir = join(tmpDir, name);
mkdirSync(pluginDir, { recursive: true });
writeFileSync(join(pluginDir, "plugin.json"), JSON.stringify(manifest, null, 2));
writeFileSync(join(pluginDir, "index.js"), "module.exports = {};");
return pluginDir;
}
const validManifest = { name: "scan-test", version: "1.0.0" };
describe("plugin scanner", () => {
describe("getDefaultPluginDir", () => {
it("returns a string path", () => {
const dir = mod.getDefaultPluginDir();
assert.equal(typeof dir, "string");
assert.ok(dir.includes("plugins") || dir.includes("omniroute"));
});
});
describe("scanPluginDir", () => {
it("discovers valid plugins", async () => {
const tmp = mkdtempSync(join(tmpdir(), "scan-test-"));
try {
makePluginDir(tmp, "my-plugin", validManifest);
const result = await mod.scanPluginDir(tmp);
assert.equal(result.plugins.length, 1);
assert.equal(result.plugins[0].name, "scan-test");
assert.ok(result.plugins[0].manifest);
assert.ok(result.plugins[0].pluginDir);
} finally {
rmSync(tmp, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
}
});
it("skips directories without plugin.json", async () => {
const tmp = mkdtempSync(join(tmpdir(), "scan-test-"));
try {
mkdirSync(join(tmp, "not-a-plugin"));
writeFileSync(join(tmp, "not-a-plugin", "index.js"), "");
const result = await mod.scanPluginDir(tmp);
assert.equal(result.plugins.length, 0);
} finally {
rmSync(tmp, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
}
});
it("skips plugins with invalid manifest", async () => {
const tmp = mkdtempSync(join(tmpdir(), "scan-test-"));
try {
makePluginDir(tmp, "bad-plugin", { name: "INVALID NAME!", version: "nope" });
const result = await mod.scanPluginDir(tmp);
assert.equal(result.plugins.length, 0);
} finally {
rmSync(tmp, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
}
});
it("handles non-existent directory", async () => {
const result = await mod.scanPluginDir("/nonexistent/path");
assert.equal(result.plugins.length, 0);
});
it("discovers multiple plugins", async () => {
const tmp = mkdtempSync(join(tmpdir(), "scan-test-"));
try {
makePluginDir(tmp, "plugin-a", { name: "plugin-a", version: "1.0.0" });
makePluginDir(tmp, "plugin-b", { name: "plugin-b", version: "2.0.0" });
const result = await mod.scanPluginDir(tmp);
assert.equal(result.plugins.length, 2);
} finally {
rmSync(tmp, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
}
});
});
});