Files
OmniRoute/tests/unit/proxy-logs-egress-ip.test.ts
Armin Anton” ∴ 8f390efffd feat(codex): self-contained codex app-server transport (executor + provider + sign-in) (#11205)
Merged after conflict resolution: the 5 conflicting test files were the base-red drains that #11201 already landed on the tip — kept the tip versions; the feature content is untouched. Validated on the combined batch board + this branch: codex-app-server + codex-gpt56-catalog 25/25, typecheck:core clean, docs-counts green (351 providers), provider-consistency 268/351/0. The opt-in codex-app-server transport (JSON-RPC-over-WS, turn/completed-awaited close, Responses SSE bridge) leaves the default codex path untouched. Thank you @arminanton — a 3.4k-line transport with the docs wave and tests to match!
2026-08-23 10:20:06 -03:00

90 lines
3.4 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";
// Persistence to SQLite only runs when shouldPersistToDisk is true
// (local mode: !isCloud && !isBuildPhase). Setting DATA_DIR to a fresh temp
// dir keeps the test in local mode; the assertions below would otherwise fail
// with no explanatory guard.
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-proxy-egress-ip-"));
process.env.DATA_DIR = TEST_DATA_DIR;
const core = await import("../../src/lib/db/core.ts");
const proxyLogger = await import("../../src/lib/proxyLogger.ts");
// Fresh DB + fresh in-memory buffer per test (mirrors
// proxy-logger-client-ip.test.ts). clearProxyLogs() runs BEFORE closeDbInstance()
// so it never reopens a closed DB.
function resetStorage() {
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(() => {
core.closeDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
});
test("fresh install exposes egress_ip and the reconciler is idempotent", async () => {
const { ensureProxyLogsColumns, hasColumn } = await import("../../src/lib/db/schemaColumns.ts");
const db = core.getDbInstance();
assert.equal(hasColumn(db, "proxy_logs", "egress_ip"), true, "column exists after migration");
assert.doesNotThrow(() => ensureProxyLogsColumns(db));
assert.doesNotThrow(() => ensureProxyLogsColumns(db));
});
test("logProxyEvent persists egressIp into proxy_logs.egress_ip", () => {
proxyLogger.logProxyEvent({
status: "success",
provider: "codex",
targetUrl: "codex/gpt-5.5",
egressIp: "203.0.113.9",
});
proxyLogger.flushProxyLogsSync(); // persist the enqueued batch before the synchronous read
const db = core.getDbInstance();
const row = db.prepare("SELECT egress_ip FROM proxy_logs ORDER BY rowid DESC LIMIT 1").get() as {
egress_ip: string | null;
};
assert.equal(row.egress_ip, "203.0.113.9");
});
test("egress_ip survives a DB close/reopen cycle (on-disk)", () => {
proxyLogger.logProxyEvent({
status: "success",
provider: "openai",
egressIp: "198.51.100.7",
});
proxyLogger.flushProxyLogsSync(); // persist to disk BEFORE the close/reopen cycle
core.closeDbInstance();
const db = core.getDbInstance();
const row = db.prepare("SELECT egress_ip FROM proxy_logs ORDER BY rowid DESC LIMIT 1").get() as {
egress_ip: string | null;
};
assert.equal(row.egress_ip, "198.51.100.7");
});
test("egress_ip is NULL when not provided (never synthesized)", () => {
proxyLogger.logProxyEvent({ status: "success", provider: "claude" });
proxyLogger.flushProxyLogsSync(); // persist the enqueued batch before the synchronous read
const db = core.getDbInstance();
const row = db.prepare("SELECT egress_ip FROM proxy_logs ORDER BY rowid DESC LIMIT 1").get() as {
egress_ip: string | null;
};
assert.equal(row.egress_ip, null);
});
test("getProxyLogs search matches the egress IP", () => {
proxyLogger.logProxyEvent({ status: "success", provider: "codex", egressIp: "203.0.113.55" });
const [log] = proxyLogger.getProxyLogs({ search: "203.0.113.55" });
assert.ok(log, "expected a matching log");
assert.equal(log.egressIp, "203.0.113.55");
});