mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-13 18:32:12 +03:00
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.
87 lines
3.1 KiB
TypeScript
87 lines
3.1 KiB
TypeScript
/**
|
|
* tests/unit/stream-timing.test.ts
|
|
*
|
|
* Canonical stream instrumentation (open-sse/utils/streamTiming.ts):
|
|
* - TTFT = first-forwarded-SSE-chunk latency (NOT token-level) — documented
|
|
* - ITL = mean inter-chunk gap (chunk-latency proxy)
|
|
* - first-byte vs first-forward distinction
|
|
* - interruption marking
|
|
* - malformed/empty chunks do not corrupt timing
|
|
*/
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { createStreamTiming, type StreamTiming } from "../../open-sse/utils/streamTiming.ts";
|
|
|
|
test("ttft() is null when nothing was forwarded", () => {
|
|
const t = createStreamTiming();
|
|
t.markByte();
|
|
assert.equal(t.ttftMs(), null);
|
|
assert.equal(t.avgItlMs(), null);
|
|
});
|
|
|
|
test("ttft() measures first-forwarded-chunk latency (byte vs forward distinguished)", async () => {
|
|
const t = createStreamTiming();
|
|
t.markByte(); // first upstream byte arrives immediately
|
|
await new Promise((r) => setTimeout(r, 20));
|
|
t.markForward(); // first chunk forwarded 20ms later
|
|
const ttft = t.ttftMs();
|
|
assert.ok(ttft !== null && ttft >= 20 && ttft < 5000, `ttft=${ttft}`);
|
|
assert.ok(t.firstByteAt !== null);
|
|
assert.ok(t.firstByteAt! < t.firstForwardAt!, "first byte precedes first forward");
|
|
});
|
|
|
|
test("avgItlMs() measures mean inter-chunk gap across multiple chunks", async () => {
|
|
const t = createStreamTiming();
|
|
for (let i = 0; i < 4; i++) {
|
|
t.markForward();
|
|
await new Promise((r) => setTimeout(r, 10));
|
|
}
|
|
const itl = t.avgItlMs();
|
|
assert.ok(itl !== null && itl >= 8 && itl < 5000, `itl=${itl}`);
|
|
assert.equal(t.forwardedChunks, 4);
|
|
});
|
|
|
|
test("empty chunks do not corrupt timing (markByte without forward)", () => {
|
|
const t = createStreamTiming();
|
|
t.markByte();
|
|
t.markByte(); // duplicate bytes are idempotent for first-byte
|
|
assert.equal(t.ttftMs(), null, "no forward → no ttft");
|
|
t.markForward();
|
|
assert.ok(t.ttftMs() !== null);
|
|
});
|
|
|
|
test("malformed/keepalive-only traffic (no forward) yields no ttft", () => {
|
|
const t = createStreamTiming();
|
|
// Simulate a provider that only sends keepalives/blank lines, never data.
|
|
for (let i = 0; i < 5; i++) t.markByte();
|
|
assert.equal(t.ttftMs(), null);
|
|
assert.equal(t.forwardedChunks, 0);
|
|
});
|
|
|
|
test("interruption is recorded and does not reset other timing", async () => {
|
|
const t = createStreamTiming();
|
|
t.markForward();
|
|
await new Promise((r) => setTimeout(r, 5));
|
|
t.markForward();
|
|
t.markInterrupted();
|
|
assert.equal(t.interrupted, true);
|
|
assert.ok(t.ttftMs() !== null);
|
|
assert.ok(t.avgItlMs() !== null);
|
|
});
|
|
|
|
test("normal completion: totalMs() is monotonic and >= first-forward latency", async () => {
|
|
const t = createStreamTiming();
|
|
await new Promise((r) => setTimeout(r, 15));
|
|
t.markForward();
|
|
const total = t.totalMs();
|
|
const ttft = t.ttftMs();
|
|
assert.ok(total >= 15);
|
|
assert.ok(ttft !== null && ttft <= total, "ttft must be <= total duration");
|
|
});
|
|
|
|
test("max inter-chunk samples are bounded (memory bound)", async () => {
|
|
const t = createStreamTiming();
|
|
for (let i = 0; i < 200; i++) t.markForward();
|
|
assert.ok(t.interChunkGaps.length <= 32, `bounded to 32 samples, got ${t.interChunkGaps.length}`);
|
|
});
|