Files
weatherreporter/docs/internal/collect.md

51 lines
2.3 KiB
Markdown
Raw Normal View History

2026-06-17 16:11:09 +00:00
# Collection Internals
`internal/collect` is the application-facing boundary for collecting the
normalized Weather API bundle. The external HTTP contract belongs in the
[Weather API integration guide](../integrations/weatherapi.md); normalized data
semantics belong in [weather-data internals](weather-data.md).
2026-06-17 16:11:09 +00:00
## Contract
`Run` accepts a `context.Context` and a `Request` containing effective
`config.Config`. It constructs the Weather API adapter from that configuration,
calls `FetchBundle`, and returns `Result{Bundle: *weatherdata.Bundle}`.
2026-06-17 16:11:09 +00:00
The package wraps adapter construction failures, including an invalid Weather
API base URL, as weather-collection setup errors and fetch failures as
bundle-collection errors. It does not retry, persist, select reports, derive
facts, build modules, invoke Promptkit, or notify Distributor.
2026-06-17 16:11:09 +00:00
2026-08-13 00:35:38 +00:00
Fetch failures retain Weather API endpoint context but do not project upstream
response bodies into application-facing errors. Oversized response bodies fail
collection before source decoding.
2026-08-13 00:37:43 +00:00
The required hourly product must contain one or more periods with usable time
bounds. An invalid hourly product fails collection before derivation begins.
## Application Composition
2026-06-17 16:11:09 +00:00
`internal/app` owns the narrow `Collector` interface used by workflow tests;
the production implementation delegates to `collect.Run`. Generation, batch
execution, and explicit bundle fetching all use this boundary. Application
orchestration rejects a nil collector result or a nil bundle before report work
can continue.
2026-06-17 16:11:09 +00:00
Single-report generation and a batch each collect once. A batch passes the same
normalized collection to planning and to every report it generates. Collection
failure prevents later workflow work for that request.
2026-06-17 16:11:09 +00:00
## Boundaries And Invariants
2026-06-17 16:11:09 +00:00
Collection owns adapter creation and retrieval of one normalized bundle. It
must not make report, period, batch, prompt, module, filesystem, or notification
decisions.
2026-06-17 16:11:09 +00:00
- App-facing Weather API collection always passes through this package.
- The returned value is normalized source data, not facts or prompt input.
- Context cancellation is passed to the Weather API adapter.
- Errors retain whether setup or fetching failed.
2026-06-17 16:11:09 +00:00
Focused tests are in `internal/collect/collect_test.go`; orchestration use is
also covered by `internal/app/app_test.go`.