fix(stats): project trusted mileage source endpoint from metadata

This commit is contained in:
lingniu
2026-07-08 14:39:40 +08:00
parent 99e81a289e
commit 5f79df3fe2
3 changed files with 22 additions and 3 deletions

View File

@@ -48,3 +48,21 @@ Both passed.
## Commit
`aa12317b5` - `feat(stats): project elected mileage source`
## Fix (reviewer findings)
Applied the reviewer correction for the trusted source endpoint contract:
- In `go/vehicle-gateway/internal/stats/source_mileage.go`, `projectDailyMileageSQL` now writes `trusted_source_endpoint` from `vehicle_data_source.latest_source_endpoint` via `COALESCE(NULLIF(ds.latest_source_endpoint, ''), s.source_endpoint)` so latest connection metadata is authoritative with a simple fallback.
- Replaced hardcoded quality predicate with the existing constant using `s.quality_status = '` + QualityOK + `'` in `projectDailyMileageSQL`.
- Updated `go/vehicle-gateway/internal/stats/source_mileage_test.go` to assert both the endpoint expression and constant-based quality predicate.
Validation commands:
```bash
cd go/vehicle-gateway && go test ./internal/stats -run TestProjectDailyMileageSelectsCandidateAndMarksSource -count=1
# PASS: lingniu-vehicle-ingest/go/vehicle-gateway/internal/stats
cd go/vehicle-gateway && go test ./internal/stats -count=1
# PASS: lingniu-vehicle-ingest/go/vehicle-gateway/internal/stats
```