Repository navigation
Expand file tree
/
Copy pathselector.test.ts
More file actions
133 lines (112 loc) · 4.72 KB
/
Copy pathselector.test.ts
File metadata and controls
133 lines (112 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import { describe, expect, it } from "vitest";
import {
calculateModelCost,
filterCandidatesByCapacity,
filterByExcludeList,
filterByToolCalling,
selectModel,
type ModelPricing,
} from "./selector.js";
import type { TierConfig } from "./types.js";
const TIER_CONFIGS: Record<"SIMPLE" | "MEDIUM" | "COMPLEX" | "REASONING", TierConfig> = {
SIMPLE: { primary: "moonshot/kimi-k2.5", fallback: [] },
MEDIUM: { primary: "moonshot/kimi-k2.5", fallback: [] },
COMPLEX: { primary: "moonshot/kimi-k2.5", fallback: [] },
REASONING: { primary: "moonshot/kimi-k2.5", fallback: [] },
};
const MODEL_PRICING = new Map<string, ModelPricing>([
["moonshot/kimi-k2.5", { inputPrice: 0.5, outputPrice: 2.4 }],
["anthropic/claude-opus-4.7", { inputPrice: 5, outputPrice: 25 }],
["anthropic/claude-opus-4.8", { inputPrice: 5, outputPrice: 25 }],
]);
describe("selectModel", () => {
it("uses claude-opus-4.7 as baseline ID when computing savings", () => {
const decision = selectModel(
"SIMPLE",
0.95,
"rules",
"test",
TIER_CONFIGS,
MODEL_PRICING,
1000,
1000,
);
expect(decision.baselineCost).toBeGreaterThan(0);
expect(decision.savings).toBeGreaterThan(0);
});
it("does not claim savings for a model whose price is unknown", () => {
const unpriced: typeof TIER_CONFIGS = {
...TIER_CONFIGS,
SIMPLE: { primary: "vendor/unlisted-model", fallback: [] },
};
const decision = selectModel("SIMPLE", 0.95, "rules", "test", unpriced, MODEL_PRICING, 1000, 1000);
expect(decision.baselineCost).toBeGreaterThan(0);
expect(decision.savings).toBe(0);
});
});
describe("filterByToolCalling", () => {
const supportsToolCalling = (modelId: string) =>
!["minimax/minimax-m2.5", "nvidia/gpt-oss-120b"].includes(modelId);
it("removes models without tool calling support when request has tools", () => {
const models = ["moonshot/kimi-k2.5", "minimax/minimax-m2.5", "deepseek/deepseek-chat"];
const filtered = filterByToolCalling(models, true, supportsToolCalling);
expect(filtered).toEqual(["moonshot/kimi-k2.5", "deepseek/deepseek-chat"]);
});
it("keeps all models when request has no tools", () => {
const models = ["moonshot/kimi-k2.5", "minimax/minimax-m2.5", "nvidia/gpt-oss-120b"];
const filtered = filterByToolCalling(models, false, supportsToolCalling);
expect(filtered).toEqual(models);
});
it("returns original list unchanged when all models support tool calling", () => {
const models = ["moonshot/kimi-k2.5", "anthropic/claude-sonnet-4.6", "deepseek/deepseek-chat"];
const filtered = filterByToolCalling(models, true, supportsToolCalling);
expect(filtered).toEqual(models);
});
it("returns full list unchanged when no models support tool calling, to avoid empty chain", () => {
const models = ["minimax/minimax-m2.5", "nvidia/gpt-oss-120b"];
const filtered = filterByToolCalling(models, true, supportsToolCalling);
expect(filtered).toEqual(models);
});
});
describe("filterByExcludeList", () => {
const chain = ["moonshot/kimi-k2.5", "deepseek/deepseek-chat", "anthropic/claude-sonnet-4.6"];
it("removes excluded models from chain", () => {
const excludeList = new Set(["deepseek/deepseek-chat"]);
const filtered = filterByExcludeList(chain, excludeList);
expect(filtered).toEqual(["moonshot/kimi-k2.5", "anthropic/claude-sonnet-4.6"]);
});
it("returns original chain if ALL models excluded (safety net)", () => {
const excludeList = new Set(chain);
const filtered = filterByExcludeList(chain, excludeList);
expect(filtered).toEqual(chain);
});
it("returns original chain for empty exclude set", () => {
const filtered = filterByExcludeList(chain, new Set());
expect(filtered).toEqual(chain);
});
});
describe("calculateModelCost", () => {
it("uses claude-opus-4.7 as baseline ID when recomputing fallback costs", () => {
const costs = calculateModelCost("moonshot/kimi-k2.5", MODEL_PRICING, 1000, 1000);
expect(costs.baselineCost).toBeGreaterThan(0);
expect(costs.savings).toBeGreaterThan(0);
});
});
describe("filterCandidatesByCapacity", () => {
const capabilities = new Map([
["small", { contextWindow: 8_000, maxOutput: 2_000 }],
["large", { contextWindow: 128_000, maxOutput: 32_000 }],
]);
it("preserves portfolio order while removing candidates that cannot fit the request", () => {
expect(
filterCandidatesByCapacity(["small", "large"], 10_000, 4_000, (model) =>
capabilities.get(model),
),
).toEqual(["large"]);
});
it("returns an empty chain when no known candidate fits", () => {
expect(
filterCandidatesByCapacity(["small"], 100_000, 40_000, (model) => capabilities.get(model)),
).toEqual([]);
});
});