Files
OmniRoute/tests/unit/puter-provider-removed.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

78 lines
3.2 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-puter-removed-"));
process.env.DATA_DIR = TEST_DATA_DIR;
const { REGISTRY } = await import("../../open-sse/config/providerRegistry.ts");
const { APIKEY_PROVIDERS } = await import("../../src/shared/constants/providers.ts");
const { FREE_MODEL_BUDGETS } = await import("../../open-sse/config/freeModelCatalog.data.ts");
const { hasSpecializedExecutor } = await import("../../open-sse/executors/index.ts");
const core = await import("../../src/lib/db/core.ts");
// Regression guard: the Puter provider (id `puter`, alias `pu`,
// https://puter.com) was removed at the request of Puter's owner
// (Nariman Jelveh). It must stay out of every provider catalog, the
// executor map, and the free model catalog, and migration 152 must clean
// up any locally stored Puter configuration.
test.after(() => {
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
});
test("puter provider is removed from the chat registry (id and alias)", () => {
assert.equal(REGISTRY["puter"], undefined);
assert.equal(REGISTRY["pu"], undefined);
});
test("puter provider is removed from the API-key provider presets", () => {
assert.equal((APIKEY_PROVIDERS as Record<string, unknown>)["puter"], undefined);
});
test("puter has no entries in the free model catalog", () => {
const offenders = FREE_MODEL_BUDGETS.filter((b) => b.provider === "puter");
assert.deepEqual(offenders, []);
});
test("puter executor is removed from the executor map (id and alias)", () => {
assert.equal(hasSpecializedExecutor("puter"), false);
assert.equal(hasSpecializedExecutor("pu"), false);
});
test("migration 152 deletes stored puter configuration and is idempotent", () => {
const db = core.getDbInstance();
const applied = db
.prepare("SELECT version FROM _omniroute_migrations WHERE version = 152")
.get() as { version: number } | undefined;
assert.ok(applied, "migration 152 must be recorded as applied");
// Simulate a pre-removal install that still has Puter configuration, then
// re-apply the migration SQL and assert every row is cleaned up.
db.prepare(
"INSERT INTO provider_connections (id, provider, auth_type, name, is_active, created_at, updated_at) VALUES (?, ?, ?, ?, 1, datetime('now'), datetime('now'))"
).run("puter-conn-test", "puter", "apikey", "puter-main");
db.prepare(
"INSERT INTO key_value (namespace, key, value) VALUES ('customModels', 'puter', '[]')"
).run();
const sql = fs.readFileSync(
path.join(process.cwd(), "src/lib/db/migrations/152_remove_puter_provider.sql"),
"utf8"
);
db.exec(sql);
db.exec(sql); // idempotent — a second run must not throw
const conn = db.prepare("SELECT id FROM provider_connections WHERE provider = 'puter'").get();
assert.equal(conn, undefined, "puter provider_connections rows must be deleted");
const custom = db
.prepare("SELECT key FROM key_value WHERE namespace = 'customModels' AND key = 'puter'")
.get();
assert.equal(custom, undefined, "puter custom models must be deleted");
});