Files
OmniRoute/tests/unit/settings-api.test.ts
Diego Rodrigues de Sa e Souza 0cd388efb8 Release v3.7.4 (#1730)
* chore(release): v3.7.4 — version bump, openapi and changelog sync

* fix: preserve previous_response_id and conversation_id fields on empty input array (#1729)

* fix: bypass UI validation block for optional API keys and fix string fallback typing (#1721)

* fix(proxy): disable HTTP keep-alive and pipelining in Undici proxy dispatcher to prevent socket hang up

* feat(proxy): implement bulk proxy import via pipe-delimited parser with update-or-create logic

* docs: update changelog for v3.7.4 fixes and proxy features

* test: update responses store expectations for empty input arrays

* feat(pwa): add fullscreen installable PWA with manifest, service worker, and cross-platform app icons. (#1728)

Integrated into release/v3.7.4

* Fix image provider validation and Stability image requests (#1726)

Integrated into release/v3.7.4

* docs: add PR 1726 and PR 1728 to v3.7.4 changelog

* fix(security): replace insecure Math.random with crypto.getRandomValues for fallback UUID generation

* fix(migrations): intercept 007 migration to use IF NOT EXISTS logic on fresh installs

Fixes #1733

* test: fix typescript compilation errors in unit tests

* fix(db): reconcile legacy reasoning cache migration

* chore(release): bump to v3.7.4 — changelog, docs, version sync

* fix(cc-compatible): preserve Claude Code system skeleton (#1740)

Integrated into release/v3.7.4

* docs(changelog): update for PR #1740 merge

* docs(changelog): include workflow updates

* fix(db): reconcile legacy reasoning cache migration (#1734)

Integrated into release/v3.7.4

* Add endpoint tunnel visibility settings (#1743)

Integrated into release/v3.7.4

* Normalize max reasoning effort for Codex routing (#1744)

Integrated into release/v3.7.4

* Fix Claude Code gateway config helper (#1745)

Integrated into release/v3.7.4

* Refresh CLI fingerprint provider profiles (#1746)

Integrated into release/v3.7.4

* Integrated into release/v3.7.4 (PR #1742)

* docs(changelog): update for PRs 1742-1746

---------

Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com>
Co-authored-by: Yash Ghule <y.ghule77@gmail.com>
Co-authored-by: backryun <bakryun0718@proton.me>
Co-authored-by: dhaern <manker_lol@hotmail.com>
Co-authored-by: Randi <55005611+rdself@users.noreply.github.com>
Co-authored-by: Duncan L <leungd@gmail.com>
2026-04-28 20:46:25 -03:00

172 lines
5.7 KiB
TypeScript

import { describe, test, beforeEach, afterEach, after } from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
// --- Create harness function (similar to _chatPipelineHarness pattern) ---
async function createSettingsApiHarness() {
const testDataDir = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-settings-api-"));
process.env.DATA_DIR = testDataDir;
process.env.REQUIRE_API_KEY = "false";
if (!process.env.API_KEY_SECRET) {
process.env.API_KEY_SECRET = "test-settings-api-secret-" + Date.now();
}
// --- Dynamic imports AFTER env setup ---
const core = await import("../../src/lib/db/core.ts");
const { getSettings, updateSettings } = await import("../../src/lib/db/settings.ts");
const settingsRoute = await import("../../src/app/api/settings/route.ts");
async function resetStorage() {
core.resetDbInstance();
fs.rmSync(testDataDir, { recursive: true, force: true });
fs.mkdirSync(testDataDir, { recursive: true });
}
function cleanup() {
core.resetDbInstance();
fs.rmSync(testDataDir, { recursive: true, force: true });
}
return {
testDataDir,
core,
getSettings,
updateSettings,
settingsRoute,
resetStorage,
cleanup,
};
}
// --- Initialize harness ---
const harness = await createSettingsApiHarness();
// --- Static import for helper (doesn't depend on DB) ---
import { makeManagementSessionRequest } from "../helpers/managementSession.ts";
beforeEach(async () => {
await harness.resetStorage();
});
afterEach(async () => {
await harness.resetStorage();
});
after(() => {
harness.cleanup();
});
describe("Settings API - persisted preferences", () => {
describe("debugMode", () => {
test("updateSettings with debugMode=true succeeds", async () => {
const result = await harness.updateSettings({ debugMode: true });
assert.ok(result, "updateSettings should return truthy result");
const settings = await harness.getSettings();
assert.strictEqual(settings.debugMode, true, "debugMode should be true");
});
test("updateSettings with debugMode=false succeeds", async () => {
const result = await harness.updateSettings({ debugMode: false });
assert.ok(result, "updateSettings should return truthy result");
const settings = await harness.getSettings();
assert.strictEqual(settings.debugMode, false, "debugMode should be false");
});
});
describe("hiddenSidebarItems", () => {
test("updateSettings with hiddenSidebarItems=['translator'] succeeds", async () => {
const result = await harness.updateSettings({ hiddenSidebarItems: ["translator"] });
assert.ok(result, "updateSettings should return truthy result");
const settings = await harness.getSettings();
assert.deepStrictEqual(
settings.hiddenSidebarItems,
["translator"],
"hiddenSidebarItems should contain translator"
);
});
test("updateSettings with empty hiddenSidebarItems succeeds", async () => {
const result = await harness.updateSettings({ hiddenSidebarItems: [] });
assert.ok(result, "updateSettings should return truthy result");
const settings = await harness.getSettings();
assert.deepStrictEqual(
settings.hiddenSidebarItems,
[],
"hiddenSidebarItems should be empty array"
);
});
});
describe("combined updates", () => {
test("updateSettings with both debugMode and hiddenSidebarItems succeeds", async () => {
const result = await harness.updateSettings({
debugMode: true,
hiddenSidebarItems: ["translator"],
});
assert.ok(result, "updateSettings should return truthy result");
const settings = await harness.getSettings();
assert.strictEqual(settings.debugMode, true, "debugMode should be true");
assert.deepStrictEqual(
settings.hiddenSidebarItems,
["translator"],
"hiddenSidebarItems should be updated"
);
});
test("updateSettings persists antigravitySignatureCacheMode", async () => {
const result = await harness.updateSettings({
antigravitySignatureCacheMode: "bypass-strict",
});
assert.ok(result, "updateSettings should return truthy result");
const settings = await harness.getSettings();
assert.strictEqual(
settings.antigravitySignatureCacheMode,
"bypass-strict",
"antigravitySignatureCacheMode should be updated"
);
});
test("PATCH /api/settings persists endpoint tunnel visibility", async () => {
const response = await harness.settingsRoute.PATCH(
await makeManagementSessionRequest("http://localhost/api/settings", {
method: "PATCH",
body: {
hideEndpointCloudflaredTunnel: true,
hideEndpointTailscaleFunnel: true,
},
})
);
const body = (await response.json()) as any;
assert.equal(response.status, 200);
assert.equal(body.hideEndpointCloudflaredTunnel, true);
assert.equal(body.hideEndpointTailscaleFunnel, true);
const settings = await harness.getSettings();
assert.equal(settings.hideEndpointCloudflaredTunnel, true);
assert.equal(settings.hideEndpointTailscaleFunnel, true);
});
test("PUT /api/settings reuses the PATCH update flow", async () => {
const response = await harness.settingsRoute.PUT(
await makeManagementSessionRequest("http://localhost/api/settings", {
method: "PUT",
body: { antigravitySignatureCacheMode: "bypass" },
})
);
const body = (await response.json()) as any;
assert.equal(response.status, 200);
assert.equal(body.antigravitySignatureCacheMode, "bypass");
});
});
});