@@ -420,6 +420,54 @@ func TestAggregate_CounterResetContributesNoDistanceAndIsCounted(t *testing.T) {
420420 }
421421}
422422
423+ func TestAggregate_SpuriousZeroDoesNotAttributeTripMeterAbsolute (t * testing.T ) {
424+ // SelfDrivingMilesSinceReset / MilesSinceReset sometimes emit 0 on an
425+ // include_fields companion row, then snap back to the trip-meter
426+ // absolute. That used to become a ~5 000 mile "day".
427+ const fsdM = 4_913.0 * 1609.344
428+ const drivingM = 12_231.5 * 1609.344
429+ resp := Aggregate (utcParams (t , []Sample {
430+ fsdSample (t , "2026-02-28T22:00:00Z" , fp (fsdM )),
431+ drivingSample (t , "2026-02-28T22:00:00Z" , fp (drivingM )),
432+ fsdSample (t , "2026-03-01T09:00:00Z" , fp (fsdM + 1_000 )),
433+ drivingSample (t , "2026-03-01T09:00:00Z" , fp (drivingM + 1_600 )),
434+ fsdSample (t , "2026-03-01T09:00:01Z" , fp (0 )),
435+ drivingSample (t , "2026-03-01T09:00:01Z" , fp (0 )),
436+ fsdSample (t , "2026-03-01T09:00:02Z" , fp (fsdM + 2_000 )),
437+ drivingSample (t , "2026-03-01T09:00:02Z" , fp (drivingM + 3_200 )),
438+ }))
439+
440+ wantMeasured (t , resp .Totals .FSDDistanceM , 2_000 , "total fsd (1 km before glitch + 1 km after restore)" )
441+ wantMeasured (t , resp .Totals .DrivingDistanceM , 3_200 , "total driving" )
442+ if resp .Quality .FSDResetCount != 0 {
443+ t .Errorf ("fsd reset count = %d, want 0 after spurious restore" , resp .Quality .FSDResetCount )
444+ }
445+ if resp .Quality .DrivingResetCount != 0 {
446+ t .Errorf ("driving reset count = %d, want 0 after spurious restore" , resp .Quality .DrivingResetCount )
447+ }
448+ if ! resp .Quality .ShareBasisAvailable {
449+ t .Error ("a restored include_fields zero must not void the shared basis" )
450+ }
451+ day := dayOf (t , resp , "2026-03-01" )
452+ wantMeasured (t , day .FSDDistanceM , 2_000 , "glitch day fsd" )
453+ wantMeasured (t , day .DrivingDistanceM , 3_200 , "glitch day driving" )
454+ if day .ResetCount != 0 {
455+ t .Errorf ("glitch day reset_count = %d, want 0" , day .ResetCount )
456+ }
457+ }
458+
459+ func TestAggregate_ImplausibleJumpIsNotDistance (t * testing.T ) {
460+ resp := Aggregate (utcParams (t , []Sample {
461+ fsdSample (t , "2026-02-28T22:00:00Z" , fp (50 )),
462+ fsdSample (t , "2026-03-01T09:00:00Z" , fp (50 + 4_913 * 1609.344 )),
463+ }))
464+ wantMeasured (t , resp .Totals .FSDDistanceM , 0 , "implausible jump contributes no distance" )
465+ wantMeasured (t , dayOf (t , resp , "2026-03-01" ).FSDDistanceM , 0 , "implausible day" )
466+ if resp .Quality .FSDResetCount != 0 {
467+ t .Errorf ("reset count = %d, want 0 (discontinuity is not a driver reset)" , resp .Quality .FSDResetCount )
468+ }
469+ }
470+
423471func TestAggregate_IndependentResetsClampShareAtOneHundredPercent (t * testing.T ) {
424472 resp := Aggregate (utcParams (t , []Sample {
425473 fsdSample (t , "2026-02-28T22:00:00Z" , fp (0 )),
0 commit comments