mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-19 21:32:20 +03:00
* feat(proxylogs): show registry proxy name in proxy log columns Registry resolution already attaches name to the runtime proxy object; the name was dropped at the persistence boundary (ProxyInfo had no name field) and never rendered. Add proxy_name column (base schema + ALTER heal for existing DBs), persist/hydrate it, render it in the ProxyLogger table and ProxyLogDetail pane with host:port fallback, and search by name. Local-only (PMO City): not submitted upstream. Re-apply after upgrades via patch file (see pmo-city-builds omniroute/Operator/runbooks/upgrade.md). * test(proxylogs): flush batched writes before asserting persisted row The v3.8.50 rebase kept upstream's batched proxy-log persistence (enqueueProxyLogs/flushProxyLogsSync); logProxyEvent no longer writes synchronously, so the persist+hydrate test closed the DB before the row was flushed. Flush explicitly first. * test(proxylogs): drain batched queue in resetStorage to avoid cross-test row bleed * docs(changelog): add changelog fragment for proxy registry name in proxy logs Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: Tiangao (hermes) <montigaud@aikumi.pro> Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
92 lines
3.0 KiB
TypeScript
92 lines
3.0 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-proxy-logger-name-"));
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
|
|
const core = await import("../../src/lib/db/core.ts");
|
|
const proxyLogger = await import("../../src/lib/proxyLogger.ts");
|
|
|
|
function resetStorage() {
|
|
// Batched persistence: logProxyEvent() enqueues and flushes on a timer, so a
|
|
// queued entry from a previous test would otherwise be written into the fresh
|
|
// DB after the reset. Drain the queue (and stop the timer) before clearing.
|
|
proxyLogger.flushProxyLogsSync();
|
|
proxyLogger.clearProxyLogs();
|
|
core.closeDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
|
|
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
|
|
}
|
|
|
|
test.beforeEach(() => {
|
|
resetStorage();
|
|
});
|
|
|
|
test.after(() => {
|
|
resetStorage();
|
|
});
|
|
|
|
test("proxy logs carry the registry name on the proxy entry", () => {
|
|
proxyLogger.logProxyEvent({
|
|
status: "success",
|
|
provider: "nous-research",
|
|
targetUrl: "nous/deepseek/deepseek-v4-flash-0731",
|
|
level: "provider",
|
|
levelId: "nous-research",
|
|
proxy: { type: "http", host: "gw-eu.murphyproxies.com", port: 7777, name: "murphy-eu-fr" },
|
|
});
|
|
|
|
const [log] = proxyLogger.getProxyLogs();
|
|
assert.equal(log.proxy.name, "murphy-eu-fr");
|
|
assert.equal(log.proxy.host, "gw-eu.murphyproxies.com");
|
|
});
|
|
|
|
test("registry name survives SQLite persist + hydrate", () => {
|
|
proxyLogger.logProxyEvent({
|
|
status: "success",
|
|
provider: "nous-research",
|
|
proxy: { type: "http", host: "gw-eu.murphyproxies.com", port: 7777, name: "murphy-eu-de" },
|
|
});
|
|
|
|
// logProxyEvent() enqueues writes on the batched persistence path; force the
|
|
// flush to SQLite before inspecting the raw row.
|
|
proxyLogger.flushProxyLogsSync();
|
|
core.closeDbInstance();
|
|
const db = core.getDbInstance();
|
|
const rows = db.prepare("SELECT proxy_name, proxy_host FROM proxy_logs").all();
|
|
assert.equal(rows.length, 1);
|
|
assert.equal(rows[0].proxy_name, "murphy-eu-de");
|
|
assert.equal(rows[0].proxy_host, "gw-eu.murphyproxies.com");
|
|
});
|
|
|
|
test("search matches the registry name", () => {
|
|
proxyLogger.logProxyEvent({
|
|
status: "success",
|
|
provider: "nous-research",
|
|
proxy: { type: "http", host: "gw-eu.murphyproxies.com", port: 7777, name: "murphy-eu-fr" },
|
|
});
|
|
proxyLogger.logProxyEvent({
|
|
status: "success",
|
|
provider: "openrouter",
|
|
});
|
|
|
|
const hits = proxyLogger.getProxyLogs({ search: "murphy-eu-fr" });
|
|
assert.equal(hits.length, 1);
|
|
assert.equal(hits[0].proxy.name, "murphy-eu-fr");
|
|
});
|
|
|
|
test("legacy rows without a name hydrate cleanly (host:port only)", () => {
|
|
proxyLogger.logProxyEvent({
|
|
status: "success",
|
|
provider: "openrouter",
|
|
proxy: { type: "http", host: "203.0.113.50", port: 8080 },
|
|
});
|
|
|
|
const [log] = proxyLogger.getProxyLogs();
|
|
assert.equal(log.proxy.name, undefined);
|
|
assert.equal(log.proxy.host, "203.0.113.50");
|
|
});
|