mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-17 20:52:15 +03:00
* fix(db): default debugMode to false in getSettings() defaults Fresh installs (or installs missing the persisted debugMode key) ran in debug mode, contradicting the documented opt-in toggle and flooding new production installs with debug-level logs. Flip the default to false; installs that persisted debugMode=true keep it — only the missing-key path changes, no migration needed. Fixes #10312 * changelog: fragment for #10372
51 lines
1.6 KiB
TypeScript
51 lines
1.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-settings-debug-"));
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
|
|
const core = await import("../../src/lib/db/core.ts");
|
|
const settings = await import("../../src/lib/db/settings.ts");
|
|
|
|
async function resetStorage() {
|
|
const globalDb = (globalThis as { __omnirouteDb?: { open: boolean; close(): void } })
|
|
.__omnirouteDb;
|
|
try {
|
|
if (globalDb?.open) {
|
|
globalDb.close();
|
|
}
|
|
} catch {}
|
|
delete (globalThis as { __omnirouteDb?: unknown }).__omnirouteDb;
|
|
core.resetDbInstance();
|
|
if (fs.existsSync(TEST_DATA_DIR)) {
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
|
|
}
|
|
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
|
|
core.getDbInstance();
|
|
}
|
|
|
|
await resetStorage();
|
|
|
|
test("#10312: empty store defaults debugMode to false (fresh install is not in debug)", async () => {
|
|
await resetStorage();
|
|
const result = await settings.getSettings();
|
|
assert.equal(result.debugMode, false);
|
|
});
|
|
|
|
test("#10312: persisted debugMode=true is preserved after the default flip", async () => {
|
|
await resetStorage();
|
|
await settings.updateSettings({ debugMode: true });
|
|
const result = await settings.getSettings();
|
|
assert.equal(result.debugMode, true);
|
|
});
|
|
|
|
test("#10312: persisted debugMode=false stays false after the default flip", async () => {
|
|
await resetStorage();
|
|
await settings.updateSettings({ debugMode: false });
|
|
const result = await settings.getSettings();
|
|
assert.equal(result.debugMode, false);
|
|
});
|