|
1 | 1 | import { describe, expect, it } from 'vitest'; |
2 | 2 |
|
3 | 3 | import { |
| 4 | + hasPowerContent, |
4 | 5 | mergeArtifactPower, |
5 | 6 | powerFromAggRow, |
6 | 7 | powerFromValidationSidecar, |
@@ -108,6 +109,25 @@ describe('powerFromAggRow', () => { |
108 | 109 | it('returns an empty partial for a row with no power fields', () => { |
109 | 110 | expect(powerFromAggRow({ output_toks_per_sec: 1000 })).toEqual({}); |
110 | 111 | }); |
| 112 | + |
| 113 | + it('rejects implausible window epochs (garbage, ms-scale, non-positive)', () => { |
| 114 | + // 1e16 s → new Date(1e19 ms) would throw RangeError in the client render. |
| 115 | + expect( |
| 116 | + powerFromAggRow({ |
| 117 | + power_audit: { window_start_unix: 1e16, window_end_unix: 1e16 + 60 }, |
| 118 | + }).window, |
| 119 | + ).toBeUndefined(); |
| 120 | + expect( |
| 121 | + powerFromAggRow({ |
| 122 | + power_audit: { window_start_unix: 1_755_000_020_000, window_end_unix: 1_755_000_080_000 }, |
| 123 | + }).window, |
| 124 | + ).toBeUndefined(); |
| 125 | + expect( |
| 126 | + powerFromAggRow({ |
| 127 | + power_audit: { window_start_unix: -5, window_end_unix: 1_755_000_080 }, |
| 128 | + }).window, |
| 129 | + ).toBeUndefined(); |
| 130 | + }); |
111 | 131 | }); |
112 | 132 |
|
113 | 133 | // --------------------------------------------------------------------------- |
@@ -138,11 +158,21 @@ describe('powerFromValidationSidecar', () => { |
138 | 158 | expect(result.published).toEqual({ |
139 | 159 | avg_power_w: 401.25, |
140 | 160 | avg_total_gpu_power_w: 3210, |
141 | | - power_metric_schema_version: 1, |
| 161 | + // The sidecar's own schema_version is a different versioning axis than |
| 162 | + // the agg row's power_metric_schema_version — never mapped through. |
| 163 | + power_metric_schema_version: null, |
142 | 164 | source: 'validation_metrics', |
143 | 165 | }); |
144 | 166 | }); |
145 | 167 |
|
| 168 | + it('rejects implausible window epochs in the sidecar', () => { |
| 169 | + expect( |
| 170 | + powerFromValidationSidecar({ |
| 171 | + benchmark_window: { start_time_unix: 1_755_000_020_000, end_time_unix: 1_755_000_080_000 }, |
| 172 | + }).window, |
| 173 | + ).toBeUndefined(); |
| 174 | + }); |
| 175 | + |
146 | 176 | it('maps an invalid verdict with reasons', () => { |
147 | 177 | const result = powerFromValidationSidecar({ |
148 | 178 | power_valid: false, |
@@ -252,6 +282,19 @@ describe('selectValidationEntry', () => { |
252 | 282 | }); |
253 | 283 | }); |
254 | 284 |
|
| 285 | +// --------------------------------------------------------------------------- |
| 286 | +// hasPowerContent |
| 287 | +// --------------------------------------------------------------------------- |
| 288 | + |
| 289 | +describe('hasPowerContent', () => { |
| 290 | + it('distinguishes empty partials from ones carrying a power field', () => { |
| 291 | + expect(hasPowerContent(null)).toBe(false); |
| 292 | + expect(hasPowerContent({})).toBe(false); |
| 293 | + expect(hasPowerContent({ power_valid: 1 })).toBe(true); |
| 294 | + expect(hasPowerContent(powerFromAggRow({ output_toks_per_sec: 1000 }))).toBe(false); |
| 295 | + }); |
| 296 | +}); |
| 297 | + |
255 | 298 | // --------------------------------------------------------------------------- |
256 | 299 | // mergeArtifactPower |
257 | 300 | // --------------------------------------------------------------------------- |
|
0 commit comments