mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 10:52: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.
110 lines
4.4 KiB
TypeScript
110 lines
4.4 KiB
TypeScript
// ENVIRONMENT NOTE (sandbox better-sqlite3 / glibc limitation, not a code defect):
|
|
// This test constructs or exercises a real better-sqlite3-backed SQLite database.
|
|
// better-sqlite3 is a native addon; production and CI load it normally, but some
|
|
// sandboxes/dev boxes ship a system glibc older than the prebuilt binary requires
|
|
// ("GLIBC_2.29 not found"), so the native module fails to dlopen and any test that
|
|
// reaches better-sqlite3 directly (or asserts stdout that the load-failure warning
|
|
// would pollute) fails HERE while passing in CI. This is a known environment
|
|
// limitation, not a defect in the code under test: the OmniRoute runtime itself
|
|
// cascades to node:sqlite/sql.js when better-sqlite3 is unavailable. See
|
|
// tests/unit/_helpers/betterSqlite3Availability.ts for a guard helper.
|
|
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 ORIGINAL_DATA_DIR = process.env.DATA_DIR;
|
|
|
|
function createTempDataDir() {
|
|
return fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-cli-backup-"));
|
|
}
|
|
|
|
async function withBackupEnv(fn: (dataDir: string) => Promise<void>) {
|
|
const dataDir = createTempDataDir();
|
|
process.env.DATA_DIR = dataDir;
|
|
|
|
const originalLog = console.log;
|
|
console.log = () => {};
|
|
|
|
try {
|
|
await fn(dataDir);
|
|
} finally {
|
|
console.log = originalLog;
|
|
fs.rmSync(dataDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
if (ORIGINAL_DATA_DIR === undefined) delete process.env.DATA_DIR;
|
|
else process.env.DATA_DIR = ORIGINAL_DATA_DIR;
|
|
}
|
|
}
|
|
|
|
test("backup returns 0 with no files (empty data dir)", async () => {
|
|
await withBackupEnv(async () => {
|
|
const { runBackupCommand } = await import("../../bin/cli/commands/backup.mjs");
|
|
const result = await runBackupCommand({});
|
|
assert.equal(result, 0);
|
|
});
|
|
});
|
|
|
|
test("backup creates backup-info.json when storage.sqlite exists", async () => {
|
|
await withBackupEnv(async (dataDir) => {
|
|
const dbPath = path.join(dataDir, "storage.sqlite");
|
|
const Database = (await import("better-sqlite3")).default;
|
|
new Database(dbPath).close();
|
|
|
|
const { runBackupCommand } = await import("../../bin/cli/commands/backup.mjs");
|
|
const result = await runBackupCommand({});
|
|
assert.equal(result, 0);
|
|
|
|
const backupDir = path.join(dataDir, "backups");
|
|
assert.ok(fs.existsSync(backupDir));
|
|
const entries = fs.readdirSync(backupDir).filter((d) => d.startsWith("omniroute-backup-"));
|
|
assert.ok(entries.length > 0);
|
|
const infoPath = path.join(backupDir, entries[0], "backup-info.json");
|
|
assert.ok(fs.existsSync(infoPath));
|
|
const info = JSON.parse(fs.readFileSync(infoPath, "utf8"));
|
|
assert.ok(info.timestamp);
|
|
assert.ok(Array.isArray(info.files));
|
|
});
|
|
});
|
|
|
|
test("encrypted backup removes temporary ciphertext files", async () => {
|
|
await withBackupEnv(async (dataDir) => {
|
|
fs.writeFileSync(path.join(dataDir, "settings.json"), JSON.stringify({ ok: true }), "utf8");
|
|
const keyFile = path.join(dataDir, "backup.key");
|
|
fs.writeFileSync(keyFile, "test-passphrase", "utf8");
|
|
|
|
const { runBackupCommand } = await import("../../bin/cli/commands/backup.mjs");
|
|
const result = await runBackupCommand({ encrypt: true, keyFile });
|
|
assert.equal(result, 0);
|
|
|
|
const backupDir = path.join(dataDir, "backups");
|
|
const entries = fs.readdirSync(backupDir).filter((d) => d.startsWith("omniroute-backup-"));
|
|
assert.ok(entries.length > 0);
|
|
const backupPath = path.join(backupDir, entries[0]);
|
|
assert.deepEqual(
|
|
fs.readdirSync(backupPath).filter((name) => name.endsWith(".ciphertext")),
|
|
[]
|
|
);
|
|
assert.ok(fs.existsSync(path.join(backupPath, "settings.json.enc")));
|
|
});
|
|
});
|
|
|
|
test("restore --list returns 0 with no backups", async () => {
|
|
await withBackupEnv(async () => {
|
|
const { runRestoreCommand } = await import("../../bin/cli/commands/backup.mjs");
|
|
const result = await runRestoreCommand(undefined, { list: true });
|
|
assert.equal(result, 0);
|
|
});
|
|
});
|
|
|
|
test("restore returns 1 when backup id not found", async () => {
|
|
await withBackupEnv(async () => {
|
|
const { runRestoreCommand } = await import("../../bin/cli/commands/backup.mjs");
|
|
const originalError = console.error;
|
|
console.error = () => {};
|
|
const result = await runRestoreCommand("nonexistent-id", { yes: true });
|
|
console.error = originalError;
|
|
assert.equal(result, 1);
|
|
});
|
|
});
|