forked from xebia/github-copilot-premium-reqs-usage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel-info-limits.test.ts
More file actions
172 lines (148 loc) · 5.93 KB
/
model-info-limits.test.ts
File metadata and controls
172 lines (148 loc) · 5.93 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import { describe, it, expect } from 'vitest';
import {
getModelUsageSummary,
CopilotUsageData,
COPILOT_PLANS,
PLAN_MONTHLY_LIMITS,
MODEL_MULTIPLIERS,
DEFAULT_MODELS,
EXCESS_REQUEST_COST
} from '../lib/utils';
describe('Model Info and Limits Feature', () => {
const mockData: CopilotUsageData[] = [
{
timestamp: new Date('2025-01-01T10:00:00Z'),
user: 'user1',
model: 'gpt-4o-2024-11-20',
requestsUsed: 100,
exceedsQuota: false,
totalMonthlyQuota: '500'
},
{
timestamp: new Date('2025-01-01T11:00:00Z'),
user: 'user2',
model: 'gpt-4.1-2025-04-14',
requestsUsed: 50,
exceedsQuota: true,
totalMonthlyQuota: '500'
},
{
timestamp: new Date('2025-01-01T12:00:00Z'),
user: 'user3',
model: 'gpt-4.1-vision',
requestsUsed: 25,
exceedsQuota: false,
totalMonthlyQuota: '500'
},
{
timestamp: new Date('2025-01-01T13:00:00Z'),
user: 'user4',
model: 'o3-mini-2025-01-31',
requestsUsed: 10,
exceedsQuota: true,
totalMonthlyQuota: '500'
}
];
it('should calculate plan limits based on model multipliers', () => {
const result = getModelUsageSummary(mockData);
const defaultGroup = result.find(item => item.model === 'Default (GPT-4o, GPT-4.1)');
expect(defaultGroup).toBeDefined();
if (defaultGroup) {
expect(defaultGroup.multiplier).toBe(0);
expect(defaultGroup.individualPlanLimit).toBe(50); // Constant plan limit, not Infinity
expect(defaultGroup.businessPlanLimit).toBe(300); // Constant plan limit, not Infinity
expect(defaultGroup.enterprisePlanLimit).toBe(1000); // Constant plan limit, not Infinity
}
});
it('should group default models (GPT-4o and GPT-4.1) together', () => {
const result = getModelUsageSummary(mockData);
const defaultGroup = result.find(item => item.model === 'Default (GPT-4o, GPT-4.1)');
expect(defaultGroup).toBeDefined();
if (defaultGroup) {
// Should combine requests from both gpt-4o-2024-11-20 (100) and gpt-4.1-2025-04-14 (50)
expect(defaultGroup.totalRequests).toBe(150);
expect(defaultGroup.compliantRequests).toBe(100);
expect(defaultGroup.exceedingRequests).toBe(50);
}
// Should not have individual entries for default models
const gpt4oEntry = result.find(item => item.model === 'gpt-4o-2024-11-20');
const gpt41Entry = result.find(item => item.model === 'gpt-4.1-2025-04-14');
expect(gpt4oEntry).toBeUndefined();
expect(gpt41Entry).toBeUndefined();
});
it('should keep non-default models separate', () => {
const result = getModelUsageSummary(mockData);
const visionModel = result.find(item => item.model === 'gpt-4.1-vision');
expect(visionModel).toBeDefined();
expect(visionModel?.totalRequests).toBe(25);
const o3Model = result.find(item => item.model === 'o3-mini-2025-01-31');
expect(o3Model).toBeDefined();
expect(o3Model?.totalRequests).toBe(10);
});
it('should calculate excess costs correctly', () => {
const result = getModelUsageSummary(mockData);
const defaultGroup = result.find(item => item.model === 'Default (GPT-4o, GPT-4.1)');
expect(defaultGroup).toBeDefined();
if (defaultGroup) {
// Default models are free (multiplier = 0), so excess cost is always $0.00
// even if there are exceeding requests
expect(defaultGroup.excessCost).toBe(0);
}
const o3Model = result.find(item => item.model === 'o3-mini-2025-01-31');
if (o3Model) {
// 10 exceeding requests * $0.04 = $0.40
expect(o3Model.excessCost).toBe(10 * EXCESS_REQUEST_COST);
}
});
it('should include all required fields in ModelUsageSummary', () => {
const result = getModelUsageSummary(mockData);
expect(result.length).toBeGreaterThan(0);
result.forEach(item => {
expect(item).toHaveProperty('model');
expect(item).toHaveProperty('displayName');
expect(item).toHaveProperty('totalRequests');
expect(item).toHaveProperty('compliantRequests');
expect(item).toHaveProperty('exceedingRequests');
expect(item).toHaveProperty('multiplier');
expect(item).toHaveProperty('individualPlanLimit');
expect(item).toHaveProperty('businessPlanLimit');
expect(item).toHaveProperty('enterprisePlanLimit');
expect(item).toHaveProperty('excessCost');
// Validate types
expect(typeof item.model).toBe('string');
expect(typeof item.displayName).toBe('string');
expect(typeof item.totalRequests).toBe('number');
expect(typeof item.compliantRequests).toBe('number');
expect(typeof item.exceedingRequests).toBe('number');
expect(typeof item.multiplier).toBe('number');
expect(typeof item.individualPlanLimit).toBe('number');
expect(typeof item.businessPlanLimit).toBe('number');
expect(typeof item.enterprisePlanLimit).toBe('number');
expect(typeof item.excessCost).toBe('number');
});
});
it('should handle unknown models with default multiplier', () => {
const unknownModelData: CopilotUsageData[] = [
{
timestamp: new Date('2025-01-01T10:00:00Z'),
user: 'user1',
model: 'unknown-model-2025',
requestsUsed: 20,
exceedsQuota: false,
totalMonthlyQuota: '500'
}
];
const result = getModelUsageSummary(unknownModelData);
expect(result).toHaveLength(1);
expect(result[0].model).toBe('unknown-model-2025');
expect(result[0].multiplier).toBe(1); // Default multiplier
expect(result[0].individualPlanLimit).toBe(50); // 50 / 1
expect(result[0].businessPlanLimit).toBe(300); // 300 / 1
});
it('should sort results by total requests descending', () => {
const result = getModelUsageSummary(mockData);
for (let i = 0; i < result.length - 1; i++) {
expect(result[i].totalRequests).toBeGreaterThanOrEqual(result[i + 1].totalRequests);
}
});
});