Files
weatherreporter/docs/internal/changes.md

57 lines
2.4 KiB
Markdown
Raw Normal View History

2026-05-29 17:53:03 +00:00
# Changes Internals
`internal/changes` deterministically compares a compatible prior module
snapshot with the current snapshot. It returns compact structured changes for
prompt input; it never reads state, finds a prior report, renders Markdown, or
compares generated text. Snapshot construction belongs to
[module internals](module.md), and prior-snapshot discovery belongs to
[state internals](state.md).
2026-05-29 17:53:03 +00:00
## Comparison inputs and output
2026-05-29 17:53:03 +00:00
Each comparator receives a prior snapshot, a current snapshot, and
`Thresholds`. A `Change` has a stable type and message plus previous and
current values where useful. Changes are sorted by type and then message, so
the same inputs always yield the same order.
2026-05-29 17:53:03 +00:00
Threshold values are supplied by application orchestration from the
[Recent Changes configuration](../config.md#recent_change); this package does
not load configuration or choose defaults. Numeric changes are emitted when
the absolute difference meets the configured threshold. Precipitation also
requires a change between its low, possible, likely, and high categories.
2026-05-29 17:53:03 +00:00
## Strategies
2026-05-29 17:53:03 +00:00
| Comparator | Required snapshot data | Compared values |
| --- | --- | --- |
| `CompareDaily` | `derived_daily_summary`, `derived_daypart_summaries` | Low and high temperature, daily precipitation probability and timing, peak gust, alerts, and aggregate indicators |
2026-05-29 17:53:03 +00:00
For daily comparison, `alert_digest` and `precip_timing` are optional: alerts
are compared when present, and timing is compared only when both snapshots
contain it.
2026-05-29 17:53:03 +00:00
The application selects a comparator only after state lookup establishes a
compatible prior snapshot. Daily, Today, and Tomorrow use the daily comparator.
Hourly reports do not produce a Recent Changes list.
2026-05-29 17:53:03 +00:00
## Missing data and failures
2026-05-29 17:53:03 +00:00
Required stanzas that are absent or cannot be decoded return an error with the
snapshot and stanza context. Optional stanzas may be absent. A snapshot with no
eligible predecessor is not a comparison failure: the caller supplies an empty
change list without invoking this package.
2026-05-29 17:53:03 +00:00
The package has no filesystem, transport, CLI, renderer, or persistence
behavior. It does not decide report compatibility or retain snapshots.
2026-05-29 17:53:03 +00:00
## Verification and invariants
2026-05-29 17:53:03 +00:00
Focused tests cover the daily strategy, threshold boundaries, indicator and
alert changes, and missing required stanzas:
2026-05-29 17:53:03 +00:00
```sh
go test ./internal/changes
```
2026-05-29 17:53:03 +00:00
Recent Changes always compare structured snapshot values, never report prose.