Files
OmniRoute/tests/unit/proxy-egress-summary.test.ts
Praveen K Palaniswamy 65e81158ab fix(ollama): route models by advertised capability (#11088)
Landed with the design call resolved per the owner's pick — **option 1**: the synced store is now endpoint-agnostic (persistDiscoveredModels and managedModelImport no longer drop non-chat models at write time), and chat selectability moved to read time (auto-pool expansion in autoStrategy applies filterChatSelectableModels; the models-route projection already had its chatOnly filter). Your discovery test now passes end-to-end (3/3): /api/show capabilities persist per connection and image/embedding requests route through the advertising host.

Reconciliation notes: conflicted areas merged onto the current tip (adobe discovery import, requestedModel preflight signature, resolvedProvider fast-path coexists with the synced-route override — explicit resolution wins); carried base-red drains (#10055 memoization, #11071 test variants) dropped as already-landed; the managed-model-import exclusion test was propagated to the new contract (image/video models persist; the read filter still hides them from chat pickers — pinned by a new assertion). Full battery: 205/206 focused (the one red is a confirmed periodic-timer timing flake on the loaded devbox — 20/20 isolated), autoCombo vitest 30/30, combo suites 46/46, gates + typecheck clean.

Thank you @yourspraveen — the capability probe + routing design was right; it just needed the store contract opened up. Fixes #11087.
2026-08-23 11:45:01 -03:00

119 lines
4.0 KiB
TypeScript

/**
* Anonymous egress-IP sharing summary (#10677). The pure aggregate
* must never leak IP literals or account identities — the redaction decision
* from #10348/#10539. Dedupes proxy_logs rows per account, reuses
* analyzeEgressSharing's rotation-group semantics.
*/
import test from "node:test";
import assert from "node:assert/strict";
const { summarizeEgressSharing } = (await import("../../src/lib/proxyEgress.ts")) as unknown as {
summarizeEgressSharing: (
rows: Array<{
provider: string | null;
account: string | null;
connectionId: string | null;
egressIp: string | null;
}>,
window: { start: string; end: string }
) => {
summary: {
windowStart: string;
windowEnd: string;
distinctEgressIps: number;
sharingByRotationGroup: Array<{
rotationGroup: string;
sharedIps: number;
maxAccountsSharingOneIp: number;
}>;
maxAccountsSharingOneIp: number;
};
warnings: Array<{ egressIp: string; rotationGroup: string; connections: string[] }>;
};
};
const WINDOW = { start: "2026-08-20T00:00:00.000Z", end: "2026-08-21T00:00:00.000Z" };
const row = (
over: Partial<{ provider: string; account: string; connectionId: string; egressIp: string }>
) => ({
provider: "codex",
account: "acc-a",
connectionId: "conn-a",
egressIp: "100.115.194.84",
...over,
});
test("summarizeEgressSharing: two accounts of one rotation group on the same IP", () => {
const { summary: s } = summarizeEgressSharing(
[
row({ account: "acc-a", connectionId: "conn-a" }),
row({ account: "acc-b", connectionId: "conn-b" }),
],
WINDOW
);
assert.equal(s.windowStart, WINDOW.start);
assert.equal(s.windowEnd, WINDOW.end);
assert.equal(s.distinctEgressIps, 1);
assert.equal(s.maxAccountsSharingOneIp, 2);
assert.equal(s.sharingByRotationGroup.length, 1);
assert.equal(s.sharingByRotationGroup[0].rotationGroup, "openai-auth0"); // codex+openai family
assert.equal(s.sharingByRotationGroup[0].sharedIps, 1);
assert.equal(s.sharingByRotationGroup[0].maxAccountsSharingOneIp, 2);
});
test("summarizeEgressSharing: repeated rows of the same account on one IP count once", () => {
const { summary: s } = summarizeEgressSharing(
[
row({ account: "acc-a", connectionId: "conn-a" }),
row({ account: "acc-a", connectionId: "conn-a" }),
row({ account: "acc-b", connectionId: "conn-b" }),
row({ account: "acc-b", connectionId: "conn-b" }),
],
WINDOW
);
assert.equal(s.maxAccountsSharingOneIp, 2, "dedupe per account, not per request");
});
test("summarizeEgressSharing: rows without egressIp are ignored", () => {
const { summary: s } = summarizeEgressSharing([row({ egressIp: null })], WINDOW);
assert.equal(s.distinctEgressIps, 0);
assert.equal(s.maxAccountsSharingOneIp, 0);
assert.deepEqual(s.sharingByRotationGroup, []);
});
test("summarizeEgressSharing: distinct IPs per account = no sharing", () => {
const { summary: s } = summarizeEgressSharing(
[
row({ egressIp: "203.0.113.1" }),
row({ account: "acc-b", connectionId: "conn-b", egressIp: "203.0.113.2" }),
],
WINDOW
);
assert.equal(s.distinctEgressIps, 2);
assert.equal(s.sharingByRotationGroup.length, 0);
});
test("summarizeEgressSharing: summary carries counts only — no IP, no account", () => {
const { summary: s } = summarizeEgressSharing(
[row({}), row({ account: "acc-b", connectionId: "conn-b" })],
WINDOW
);
const json = JSON.stringify(s);
assert.ok(!json.includes("100.115.194.84"), "no IP literal in the summary");
assert.ok(
!json.includes("acc-a") && !json.includes("acc-b"),
"no account identity in the summary"
);
});
test("summarizeEgressSharing: provider without rotation group falls back to provider:<name>", () => {
const { summary: s } = summarizeEgressSharing(
[
row({ provider: "weird-provider" }),
row({ provider: "weird-provider", account: "acc-b", connectionId: "conn-b" }),
],
WINDOW
);
assert.equal(s.sharingByRotationGroup[0].rotationGroup, "provider:weird-provider");
});