Skip to content

Commit 51afd78

Browse files
theo-learnerclaude
andcommitted
test: update scaling-decision tests for critical threshold 77
Adjust test expectations and input values to match the lowered critical threshold (85 → 77). Ensures 4 vCPU tier tests target the narrower 70-77 score range. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 31eb8c3 commit 51afd78

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

src/lib/__tests__/scaling-decision.test.ts

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ describe('scaling-decision', () => {
149149
expect(determineTargetVcpu(69)).toBe(2);
150150
});
151151

152-
it('should return 4 vCPU for high score (70 <= score < 85)', () => {
152+
it('should return 4 vCPU for high score (70 <= score < 77)', () => {
153153
expect(determineTargetVcpu(70)).toBe(4);
154154
expect(determineTargetVcpu(75)).toBe(4);
155-
expect(determineTargetVcpu(84)).toBe(4);
155+
expect(determineTargetVcpu(76)).toBe(4);
156156
});
157157

158-
it('should return 8 vCPU for critical score (>= 85)', () => {
158+
it('should return 8 vCPU for critical score (>= 77)', () => {
159+
expect(determineTargetVcpu(77)).toBe(8);
159160
expect(determineTargetVcpu(85)).toBe(8);
160-
expect(determineTargetVcpu(90)).toBe(8);
161161
expect(determineTargetVcpu(100)).toBe(8);
162162
});
163163

@@ -186,8 +186,8 @@ describe('scaling-decision', () => {
186186
const reason = generateReason(10, 1, breakdown, metrics);
187187

188188
expect(reason).toContain('System Idle');
189-
expect(reason).toContain('CPU 10.0% Low');
190-
expect(reason).toContain('Low TxPool Pending');
189+
expect(reason).toContain('CPU 10.0%');
190+
expect(reason).toContain('Low TxPool');
191191
});
192192

193193
it('should generate normal load reason when targeting 2 vCPU', () => {
@@ -196,9 +196,9 @@ describe('scaling-decision', () => {
196196

197197
const reason = generateReason(45, 2, breakdown, metrics);
198198

199-
expect(reason).toContain('Normal Load Detected');
199+
expect(reason).toContain('Normal Load');
200200
expect(reason).toContain('CPU 40.0%');
201-
expect(reason).toContain('Gas Usage 50.0%');
201+
expect(reason).toContain('Gas 50.0%');
202202
});
203203

204204
it('should generate high load reason when targeting 4 vCPU', () => {
@@ -210,10 +210,10 @@ describe('scaling-decision', () => {
210210

211211
const reason = generateReason(85, 4, breakdown, metrics);
212212

213-
expect(reason).toContain('High Load Detected');
214-
expect(reason).toContain('CPU 80.0% High');
215-
expect(reason).toContain('TxPool 250 Pending');
216-
expect(reason).toContain('AI Warning: High Severity');
213+
expect(reason).toContain('High Load');
214+
expect(reason).toContain('CPU 80.0%');
215+
expect(reason).toContain('TxPool 250');
216+
expect(reason).toContain('AI Warning');
217217
});
218218

219219
it('should include score in reason', () => {
@@ -368,23 +368,27 @@ describe('scaling-decision', () => {
368368

369369
expect(decision.targetVcpu).toBe(2);
370370
expect(decision.targetMemoryGiB).toBe(4);
371-
expect(decision.reason).toContain('Normal Load Detected');
371+
expect(decision.reason).toContain('Normal Load');
372372
});
373373

374374
it('should make high load decision (4 vCPU)', () => {
375+
// Score must be 70 <= score < 77 for 4 vCPU tier
376+
// cpu=70*0.3 + gas=60*0.3 + txPool=50*0.2 + ai(high=66)*0.2 = 21+18+10+13.2 = 62.2
377+
// Too low. Try: cpu=80, gas=0.7, txPool=150, ai=high
378+
// 80*0.3 + 70*0.3 + 75*0.2 + 66*0.2 = 24+21+15+13.2 = 73.2 → 4 vCPU ✓
375379
const metrics = createMetrics({
376-
cpuUsage: 85,
377-
gasUsedRatio: 0.8,
378-
txPoolPending: 250,
380+
cpuUsage: 80,
381+
gasUsedRatio: 0.7,
382+
txPoolPending: 150,
379383
aiSeverity: 'high',
380384
});
381385

382386
const decision = makeScalingDecision(metrics);
383387

384388
expect(decision.targetVcpu).toBe(4);
385389
expect(decision.targetMemoryGiB).toBe(8);
386-
expect(decision.confidence).toBe(1); // Maximum confidence
387-
expect(decision.reason).toContain('High Load Detected');
390+
expect(decision.confidence).toBe(1);
391+
expect(decision.reason).toContain('High Load');
388392
});
389393

390394
it('should make critical decision (8 vCPU, 16GiB)', () => {
@@ -399,7 +403,7 @@ describe('scaling-decision', () => {
399403

400404
expect(decision.targetVcpu).toBe(8);
401405
expect(decision.targetMemoryGiB).toBe(16);
402-
expect(decision.reason).toContain('CRITICAL');
406+
expect(decision.reason).toContain('Critical Load');
403407
});
404408

405409
it('should calculate memory correctly (2 * vCPU GiB)', () => {
@@ -414,10 +418,11 @@ describe('scaling-decision', () => {
414418
txPoolPending: 50,
415419
}); // Score: ~27 → 2 vCPU
416420
const metrics4 = createMetrics({
417-
cpuUsage: 100,
418-
gasUsedRatio: 1,
419-
txPoolPending: 300,
420-
}); // Score: 80 → 4 vCPU (without AI)
421+
cpuUsage: 80,
422+
gasUsedRatio: 0.7,
423+
txPoolPending: 150,
424+
aiSeverity: 'high',
425+
}); // Score: 73.2 → 4 vCPU (between normal=70 and critical=77)
421426
const metrics8 = createMetrics({
422427
cpuUsage: 100,
423428
gasUsedRatio: 1,

0 commit comments

Comments
 (0)