mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
test: increase coverage to >60% — 353 new test cases (#3018)
Integrated into release/v3.8.8 — 122 new passing tests (DB core/models/settings, executor base, stream payload collector, model resolver). Thanks @oyi77!
This commit is contained in:
@@ -66,10 +66,11 @@ test("getDbInstance returns same instance on second call (singleton)", async ()
|
||||
|
||||
test("resetDbInstance allows getting a fresh instance", async () => {
|
||||
await resetStorage();
|
||||
const db1 = core.getDbInstance();
|
||||
core.getDbInstance();
|
||||
core.resetDbInstance();
|
||||
const db2 = core.getDbInstance();
|
||||
assert.ok(db1 !== db2 || true);
|
||||
assert.ok(db2);
|
||||
assert.ok(typeof db2.prepare === "function");
|
||||
});
|
||||
|
||||
test("closeDbInstance closes the database", async () => {
|
||||
|
||||
@@ -124,10 +124,10 @@ test("getModelPreserveOpenAIDeveloperRole returns boolean or undefined", async (
|
||||
assert.ok(result === undefined || typeof result === "boolean");
|
||||
});
|
||||
|
||||
test("getModelUpstreamExtraHeaders returns null or object", async () => {
|
||||
test("getModelUpstreamExtraHeaders returns empty object when no overrides", async () => {
|
||||
await resetStorage();
|
||||
const result = models.getModelUpstreamExtraHeaders("openai", "gpt-4o");
|
||||
assert.ok(result === null || typeof result === "object");
|
||||
assert.deepEqual(result, {});
|
||||
});
|
||||
|
||||
test("removeModelCompatOverride does not throw for unknown provider/model", async () => {
|
||||
|
||||
@@ -69,7 +69,7 @@ test("getPricing returns an object", async () => {
|
||||
test("getPricingForModel returns null for unknown model", async () => {
|
||||
await resetStorage();
|
||||
const result = await settings.getPricingForModel("unknown-provider", "unknown-model");
|
||||
assert.ok(result === null || result === undefined || typeof result === "object");
|
||||
assert.equal(result, null);
|
||||
});
|
||||
|
||||
test("updatePricing stores pricing data", async () => {
|
||||
@@ -120,7 +120,7 @@ test("setProxyConfig stores proxy configuration", async () => {
|
||||
test("getProxyForLevel returns null for unset level", async () => {
|
||||
await resetStorage();
|
||||
const result = await settings.getProxyForLevel("global");
|
||||
assert.ok(result === null || result === undefined || typeof result === "object");
|
||||
assert.equal(result, null);
|
||||
});
|
||||
|
||||
test("setProxyForLevel stores proxy for level", async () => {
|
||||
@@ -138,11 +138,8 @@ test("deleteProxyForLevel removes proxy", async () => {
|
||||
assert.ok(result === null || result === undefined);
|
||||
});
|
||||
|
||||
test("bumpProxyConfigGeneration increments generation", () => {
|
||||
const gen1 = (settings as any).proxyConfigGeneration;
|
||||
settings.bumpProxyConfigGeneration();
|
||||
const gen2 = (settings as any).proxyConfigGeneration;
|
||||
assert.ok(gen2 === undefined || gen2 > gen1 || true);
|
||||
test("bumpProxyConfigGeneration does not throw", () => {
|
||||
assert.doesNotThrow(() => settings.bumpProxyConfigGeneration());
|
||||
});
|
||||
|
||||
test("isCloudEnabled returns boolean", async () => {
|
||||
|
||||
@@ -116,17 +116,32 @@ test("mergeAbortSignals aborts when secondary fires", () => {
|
||||
assert.ok(merged.aborted);
|
||||
});
|
||||
|
||||
test("sanitizeReasoningEffortForProvider clamps values", () => {
|
||||
const result = base.sanitizeReasoningEffortForProvider("high", "openai");
|
||||
assert.ok(result === "high" || result === "medium" || result === "low" || typeof result === "string");
|
||||
test("sanitizeReasoningEffortForProvider passes through body without reasoning_effort", () => {
|
||||
const body = { model: "gpt-4o", temperature: 0.7 };
|
||||
const result = base.sanitizeReasoningEffortForProvider(body, "openai", "gpt-4o");
|
||||
assert.deepEqual(result, body);
|
||||
});
|
||||
|
||||
test("sanitizeReasoningEffortForProvider handles null", () => {
|
||||
const result = base.sanitizeReasoningEffortForProvider(null, "openai");
|
||||
assert.ok(result === null || result === undefined || typeof result === "string");
|
||||
test("sanitizeReasoningEffortForProvider clamps xhigh to high for unsupported providers", () => {
|
||||
const body = { reasoning_effort: "xhigh" };
|
||||
const result = base.sanitizeReasoningEffortForProvider(body, "openai", "gpt-4o") as any;
|
||||
assert.equal(result.reasoning_effort, "high");
|
||||
});
|
||||
|
||||
test("sanitizeReasoningEffortForProvider handles undefined", () => {
|
||||
const result = base.sanitizeReasoningEffortForProvider(undefined, "anthropic");
|
||||
assert.ok(result === null || result === undefined || typeof result === "string");
|
||||
test("sanitizeReasoningEffortForProvider preserves high effort", () => {
|
||||
const body = { reasoning_effort: "high" };
|
||||
const result = base.sanitizeReasoningEffortForProvider(body, "openai", "gpt-4o") as any;
|
||||
assert.equal(result.reasoning_effort, "high");
|
||||
});
|
||||
|
||||
test("sanitizeReasoningEffortForProvider preserves medium effort", () => {
|
||||
const body = { reasoning_effort: "medium" };
|
||||
const result = base.sanitizeReasoningEffortForProvider(body, "openai", "gpt-4o") as any;
|
||||
assert.equal(result.reasoning_effort, "medium");
|
||||
});
|
||||
|
||||
test("sanitizeReasoningEffortForProvider returns non-object body as-is", () => {
|
||||
assert.equal(base.sanitizeReasoningEffortForProvider(null, "openai", "gpt-4o"), null);
|
||||
assert.equal(base.sanitizeReasoningEffortForProvider("string", "openai", "gpt-4o"), "string");
|
||||
assert.equal(base.sanitizeReasoningEffortForProvider(42, "openai", "gpt-4o"), 42);
|
||||
});
|
||||
|
||||
@@ -18,9 +18,9 @@ test("resolveProviderAlias returns known alias", () => {
|
||||
assert.ok(result === "claude" || result === "anthropic" || typeof result === "string");
|
||||
});
|
||||
|
||||
test("resolveProviderAlias returns null for unknown alias", () => {
|
||||
test("resolveProviderAlias returns input string for unknown alias", () => {
|
||||
const result = model.resolveProviderAlias("totally-unknown-provider");
|
||||
assert.ok(result === null || typeof result === "string");
|
||||
assert.equal(result, "totally-unknown-provider");
|
||||
});
|
||||
|
||||
test("parseModel parses provider/model format", () => {
|
||||
@@ -68,12 +68,13 @@ test("normalizeCrossProxyModelId handles undefined", () => {
|
||||
});
|
||||
|
||||
test("resolveCanonicalProviderModel returns object for known model", () => {
|
||||
const result = model.resolveCanonicalProviderModel("gpt-4o");
|
||||
const result = model.resolveCanonicalProviderModel("openai", "gpt-4o");
|
||||
assert.ok(typeof result === "object");
|
||||
assert.ok(result !== null);
|
||||
});
|
||||
|
||||
test("resolveCanonicalProviderModel returns object for null", () => {
|
||||
const result = model.resolveCanonicalProviderModel(null);
|
||||
test("resolveCanonicalProviderModel handles null modelId", () => {
|
||||
const result = model.resolveCanonicalProviderModel("openai", null);
|
||||
assert.ok(typeof result === "object");
|
||||
});
|
||||
|
||||
|
||||
@@ -42,18 +42,19 @@ test("buildStreamSummaryFromEvents handles empty array", () => {
|
||||
});
|
||||
|
||||
test("buildStreamSummaryFromEvents handles single event", () => {
|
||||
const events = [{ data: '{"choices":[{"delta":{"content":"hello"}}]}' }];
|
||||
const result = collector.buildStreamSummaryFromEvents(events);
|
||||
const events = [{ data: { choices: [{ delta: { content: "hello" } }] } }];
|
||||
const result = collector.buildStreamSummaryFromEvents(events) as any;
|
||||
assert.ok(result !== null);
|
||||
assert.ok(typeof result === "object");
|
||||
});
|
||||
|
||||
test("buildStreamSummaryFromEvents handles multiple events", () => {
|
||||
const events = [
|
||||
{ data: '{"choices":[{"delta":{"content":"hello"}}]}' },
|
||||
{ data: '{"choices":[{"delta":{"content":" world"}}]}' },
|
||||
{ data: "[DONE]" },
|
||||
{ data: { choices: [{ delta: { content: "hello" } }] } },
|
||||
{ data: { choices: [{ delta: { content: " world" } }] } },
|
||||
];
|
||||
const result = collector.buildStreamSummaryFromEvents(events);
|
||||
const result = collector.buildStreamSummaryFromEvents(events) as any;
|
||||
assert.ok(result !== null);
|
||||
assert.ok(typeof result === "object");
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user