mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 19:02:17 +03:00
* 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.
95 lines
3.6 KiB
TypeScript
95 lines
3.6 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-log-migration-"));
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
|
|
const migrations = await import("../../src/lib/usage/migrations.ts");
|
|
const { getDbInstance } = await import("../../src/lib/db/core.ts");
|
|
|
|
const LEGACY_LOGS_DIR = path.join(TEST_DATA_DIR, "logs");
|
|
const LEGACY_CALL_LOGS_DIR = path.join(TEST_DATA_DIR, "call_logs");
|
|
const LEGACY_SUMMARY_FILE = path.join(TEST_DATA_DIR, "log.txt");
|
|
const MARKER_PATH = path.join(migrations.LOG_ARCHIVES_DIR, "legacy-request-logs.json");
|
|
|
|
function seedLegacyLayout() {
|
|
fs.mkdirSync(path.join(LEGACY_LOGS_DIR, "session-a"), { recursive: true });
|
|
fs.writeFileSync(
|
|
path.join(LEGACY_LOGS_DIR, "session-a", "1_req_client.json"),
|
|
JSON.stringify({ ok: true }, null, 2)
|
|
);
|
|
|
|
fs.mkdirSync(path.join(LEGACY_CALL_LOGS_DIR, "2026-03-30"), { recursive: true });
|
|
fs.writeFileSync(
|
|
path.join(LEGACY_CALL_LOGS_DIR, "2026-03-30", "123000_model_200.json"),
|
|
JSON.stringify({ ok: true }, null, 2)
|
|
);
|
|
|
|
fs.writeFileSync(LEGACY_SUMMARY_FILE, "legacy summary\n");
|
|
}
|
|
|
|
function cleanup() {
|
|
// Close the SQLite connection that holds a lock on files inside TEST_DATA_DIR
|
|
try {
|
|
const db = getDbInstance();
|
|
if (db && db.open) db.close();
|
|
} catch {
|
|
// DB may already be closed
|
|
}
|
|
// On Windows, rmSync can fail if file handles are still held.
|
|
// Retry with a short delay to let the OS release locks.
|
|
for (let attempt = 0; attempt < 5; attempt++) {
|
|
try {
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
return;
|
|
} catch {
|
|
/* retry */
|
|
}
|
|
}
|
|
}
|
|
|
|
test.after(() => {
|
|
cleanup();
|
|
});
|
|
|
|
test("archives legacy request log layout into a zip and removes old files", async () => {
|
|
seedLegacyLayout();
|
|
|
|
const archiveFilename = await migrations.archiveLegacyRequestLogs();
|
|
|
|
assert.match(archiveFilename || "", /_legacy-request-logs\.zip$/);
|
|
// DATA_DIR/logs itself is preserved (not recursively removed) because it is shared
|
|
// with the live app logger's own logs/application subdirectory since #6234 — only the
|
|
// individual legacy entries inside it are archived-then-deleted (#6799).
|
|
assert.equal(fs.existsSync(LEGACY_LOGS_DIR), true);
|
|
assert.equal(fs.existsSync(path.join(LEGACY_LOGS_DIR, "session-a")), false);
|
|
assert.equal(fs.existsSync(LEGACY_CALL_LOGS_DIR), false);
|
|
assert.equal(fs.existsSync(LEGACY_SUMMARY_FILE), false);
|
|
assert.equal(fs.existsSync(MARKER_PATH), true);
|
|
|
|
const archivePath = path.join(migrations.LOG_ARCHIVES_DIR, archiveFilename);
|
|
assert.equal(fs.existsSync(archivePath), true);
|
|
assert.ok(fs.statSync(archivePath).size > 0);
|
|
});
|
|
|
|
test("keeps legacy files in place when zip creation fails", async () => {
|
|
// Re-seed legacy layout (first test archived and removed them)
|
|
seedLegacyLayout();
|
|
|
|
// Remove the archive dir created by the first test, then write a file
|
|
// at that path so mkdirSync throws EEXIST. This simulates a zip
|
|
// creation failure. The migration should leave legacy files intact.
|
|
fs.rmSync(migrations.LOG_ARCHIVES_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
fs.writeFileSync(migrations.LOG_ARCHIVES_DIR, "not-a-directory");
|
|
|
|
await assert.rejects(() => migrations.archiveLegacyRequestLogs());
|
|
|
|
assert.equal(fs.existsSync(LEGACY_LOGS_DIR), true);
|
|
assert.equal(fs.existsSync(LEGACY_CALL_LOGS_DIR), true);
|
|
assert.equal(fs.existsSync(LEGACY_SUMMARY_FILE), true);
|
|
assert.equal(fs.existsSync(MARKER_PATH), false);
|
|
});
|