fix(stats): enforce latest source endpoint only for projected daily mileage

This commit is contained in:
lingniu
2026-07-08 14:41:53 +08:00
parent 5f79df3fe2
commit bc2071ef42
3 changed files with 22 additions and 2 deletions

View File

@@ -66,3 +66,17 @@ cd go/vehicle-gateway && go test ./internal/stats -run TestProjectDailyMileageSe
cd go/vehicle-gateway && go test ./internal/stats -count=1
# PASS: lingniu-vehicle-ingest/go/vehicle-gateway/internal/stats
```
## Fix (reviewer findings #2)
Corrected the remaining `projectDailyMileageSQL` contract issue so `trusted_source_endpoint` uses only `vehicle_data_source.latest_source_endpoint`:
- In `go/vehicle-gateway/internal/stats/source_mileage.go`, changed the projection from:
`COALESCE(NULLIF(ds.latest_source_endpoint, ''), s.source_endpoint)`
to:
`ds.latest_source_endpoint`.
- In `go/vehicle-gateway/internal/stats/source_mileage_test.go`, extended `TestProjectDailyMileageSelectsCandidateAndMarksSource` assertions to:
- require `ds.latest_source_endpoint` is selected, and
- explicitly verify no fallback expression using `s.source_endpoint` remains.
This enforces the strict source-of-truth rule that endpoint data for final projection must come from latest connection metadata only, even when it is null/empty.