Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

test: fix 4 failing unit tests (copilot-usage, request-log-migration)

William Finger7928bede1e6e
diff --git a/tests/unit/copilot-usage.test.mjs b/tests/unit/copilot-usage.test.mjs
index 0e1ad62464..ca635a28bf 100644
--- a/tests/unit/copilot-usage.test.mjs
+++ b/tests/unit/copilot-usage.test.mjs
@@ -2,9 +2,8 @@ import test from "node:test";
import assert from "node:assert/strict";
const usageService = await import("../../open-sse/services/usage.ts");
-const providerLimitUtils = await import(
- "../../src/app/(dashboard)/dashboard/usage/components/ProviderLimits/utils.tsx"
-);
+const providerLimitUtils =
+ await import("../../src/app/(dashboard)/dashboard/usage/components/ProviderLimits/utils.tsx");
test("github copilot business seats infer business plan and hide unlimited buckets", async () => {
const originalFetch = globalThis.fetch;
@@ -13,7 +12,7 @@ test("github copilot business seats infer business plan and hide unlimited bucke
new Response(
JSON.stringify({
access_type_sku: "copilot_business_seat",
- quota_reset_date: "2026-04-01T00:00:00Z",
+ quota_reset_date: "2026-12-31T00:00:00Z",
quota_snapshots: {
chat: { unlimited: true },
completions: { unlimited: true },
@@ -61,7 +60,7 @@ test("github copilot individual paid plans no longer normalize as free", async (
new Response(
JSON.stringify({
copilot_plan: "individual",
- quota_reset_date: "2026-04-01T00:00:00Z",
+ quota_reset_date: "2026-12-31T00:00:00Z",
quota_snapshots: {
premium_interactions: {
entitlement: 300,
diff --git a/tests/unit/request-log-migration.test.mjs b/tests/unit/request-log-migration.test.mjs
index 95a4c4bce6..c35be628a1 100644
--- a/tests/unit/request-log-migration.test.mjs
+++ b/tests/unit/request-log-migration.test.mjs
@@ -8,17 +8,13 @@ const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-log-migra
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 resetDataDir() {
- fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
- fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
-}
-
function seedLegacyLayout() {
fs.mkdirSync(path.join(LEGACY_LOGS_DIR, "session-a"), { recursive: true });
fs.writeFileSync(
@@ -35,12 +31,28 @@ function seedLegacyLayout() {
fs.writeFileSync(LEGACY_SUMMARY_FILE, "legacy summary\n");
}
-test.beforeEach(() => {
- resetDataDir();
-});
+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 });
+ return;
+ } catch {
+ /* retry */
+ }
+ }
+}
test.after(() => {
- resetDataDir();
+ cleanup();
});
test("archives legacy request log layout into a zip and removes old files", async () => {
@@ -60,7 +72,13 @@ test("archives legacy request log layout into a zip and removes old files", asyn
});
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 });
fs.writeFileSync(migrations.LOG_ARCHIVES_DIR, "not-a-directory");
await assert.rejects(() => migrations.archiveLegacyRequestLogs());