chore(gateway): satisfy strict index checks in traffic meter

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
max bittkerandClaude Opus 5.5 committed 2026-10-12 14:30:11 -04:00
1 parent 76391328ec
commit f4b0e4a068
2 files changed
+8 -7

No files matched your search

+6 -6
View File
@@ -59,7 +59,7 @@ describe('TrafficMeter', () => {
expect(goo.outMBps).toBe(0.12);
expect(goo.avgOutFrameKB).toBe(40);
expect(goo.sdkOutMBpsByMode).toEqual({ control: 0.04, observe: 0.08 });
expect(r.groups[0].group).toBe('goo'); // most expensive first
expect(r.groups[0]!.group).toBe('goo'); // most expensive first
// single-account names fold into one row instead of one row each
expect(r.groups.some(g => g.group === 'chiefkeefer')).toBe(false);
@@ -114,11 +114,11 @@ describe('StateFieldSampler', () => {
const r = sampler.report();
expect(r.all.pairs).toBe(2);
const fields = Object.fromEntries(r.all.fields.map(f => [f.field, f]));
expect(fields.bank.unchangedPct).toBe(100);
expect(fields.tick.unchangedPct).toBe(0);
expect(fields.player.unchangedPct).toBe(0);
expect(r.all.fields[0].field).toBe('bank');
expect(r.groups[0].group).toBe('goo');
expect(fields.bank!.unchangedPct).toBe(100);
expect(fields.tick!.unchangedPct).toBe(0);
expect(fields.player!.unchangedPct).toBe(0);
expect(r.all.fields[0]!.field).toBe('bank');
expect(r.groups[0]!.group).toBe('goo');
expect(r.all.unchangedPct).toBeGreaterThan(95);
expect(formatFieldReport(r)).toContain('bank');
});
+2 -1
View File
@@ -99,7 +99,8 @@ export class TrafficMeter {
// Newest snapshot at least windowSec old, so the window is never shorter
// than asked; with less history than that, the oldest snapshot we have.
const target = now - windowSec * 1000;
const base = this.snapshots.findLast(s => s.at <= target) ?? this.snapshots[0];
// The constructor seeds a snapshot, and pruning always retains one.
const base = this.snapshots.findLast(s => s.at <= target) ?? this.snapshots[0]!;
const seconds = Math.max(1, (now - base.at) / 1000);
const byKind = new Map<string, number>();