feat(environment): resolve past days conservatively, never guessing from home

Rework the per-day location resolution so it can no longer fabricate weather for
days before the home was set. Precedence, first hit wins:

  1. an explicit dated location period (a trip, or a corrected stretch of
     history) covering the day;
  2. DEVICE — a reserved slot for a future client-supplied coarse per-day
     location (ranks between the period and home; not produced server-side yet);
  3. the home location, but only for days on/after its effective-from date;
  4. otherwise the day is skipped.

The home route stamps `homeSince` whenever the home is set/updated and returns
it. The overview exposes it. Backfill bounds are now optional and default to the
conservative `[homeSince .. today]` span instead of a fixed reach onto the
current home; days before `homeSince` still resolve to a skip in the worker, so
even a wider explicit start cannot back-fill weather for the pre-home past. To
reach further back a user adds an explicit location period for that range.

Add unit coverage for the precedence (including the effective-from boundary and
the skip-not-guess rule) and the default backfill range.
This commit is contained in:
Marc-André Bombeck committed 2026-06-28 17:36:14 +02:00
1 parent 6aad4a465e
commit c254135406
7 files changed
+209 -29

No files matched your search

+9 -4
View File
@@ -48,14 +48,19 @@ export const travelLocationSchema = z
export type TravelLocationInput = z.infer<typeof travelLocationSchema>;
/** A backfill request: fetch + store the environment rows over a date range. */
/**
* A backfill request: fetch + store the environment rows over a date range.
* Both bounds are optional — an omitted span defaults to the conservative
* `[homeSince .. today]` range on the server (never a fixed reach into the past
* onto the current home).
*/
export const environmentBackfillSchema = z
.object({
startDate: dayStringSchema,
endDate: dayStringSchema,
startDate: dayStringSchema.optional(),
endDate: dayStringSchema.optional(),
})
.strict()
.refine((v) => v.startDate <= v.endDate, {
.refine((v) => !v.startDate || !v.endDate || v.startDate <= v.endDate, {
message: "startDate must be on or before endDate",
path: ["endDate"],
});