Add module contracts and registry validation

This commit is contained in:
2026-06-09 20:30:49 +00:00
parent e9508089ab
commit 24dba3bd60
11 changed files with 802 additions and 3 deletions

View File

@@ -21,6 +21,8 @@ Outputs:
- `briefing.Package` with common metadata and one report-specific content
object for Daily, 3-Day, Weekend, or Storm Report
- module registry definitions for known module IDs, stanza names, option
shapes, fact requirements, report compatibility, and missing-data behavior
- optional `currentConditions` prompt context from normalized
`/conditions/current` data when available
- optional structured `weatherStory` context on report-specific briefing
@@ -30,6 +32,8 @@ Outputs:
## Boundaries
- This package selects and shapes weather facts for prompts.
- It owns module registry validation, but app orchestration does not execute
modules yet.
- It does not fetch weather data, compare prior snapshots, build
`data_package` files, invoke Scriptorium, or write workflow metadata.
@@ -65,6 +69,10 @@ None. Builders either return a complete briefing package or an error.
least one derived summary.
- Storm briefing construction requires a Storm Report definition and forecast
bundle.
- Module registry construction rejects duplicate module IDs and duplicate
stanza names.
- Module composition validation rejects unknown modules, duplicate modules,
incompatible report/module combinations, and invalid typed options.
- Save failures include path and operation context.
## Tests
@@ -75,6 +83,7 @@ Inspect:
- `internal/briefing/three_day_test.go`
- `internal/briefing/weekend_test.go`
- `internal/briefing/storm_test.go`
- `internal/briefing/modules_test.go`
- `internal/app/app_test.go`
## Invariants

58
docs/internal/module.md Normal file
View File

@@ -0,0 +1,58 @@
# Module Contract Internals
This document describes the implemented module contract boundary.
## Purpose
`internal/module` defines stable module IDs, typed configuration items, module
outputs, and module snapshots. It is a shared contract imported by report
definitions and briefing registry code.
## Inputs And Outputs
Inputs:
- ordered `module.ConfigItem` values from report definitions
- `module.Output` values assembled by callers
Outputs:
- stable `module.ID` constants
- typed option structs for known modules
- `module.Snapshot` with ordered outputs and schema version
- typed stanza lookup through `module.StanzaValue`
## Boundaries
- This package owns shared module identifiers and output envelope contracts.
- It does not define report IDs, build briefing stanzas, fetch weather data,
derive facts, write state, or invoke Scriptorium.
## State Or Manifest Behavior
`module.Snapshot` uses schema version `weatherreporter.modules.v1`. Snapshot
validation rejects duplicate module outputs and duplicate stanza names while
preserving output order.
## Failure Behavior
- Snapshot validation fails when schema version, module ID, or stanza name is
missing.
- Snapshot validation fails on duplicate module IDs or duplicate stanza names.
- Typed stanza lookup returns `found=false` for missing stanzas and wraps JSON
marshal/decode failures with stanza context.
## Tests
Inspect:
- `internal/module/module_test.go`
- `internal/briefing/modules_test.go`
- `internal/report/period_test.go`
## Invariants
- `internal/module` does not import `internal/report`.
- Module IDs are stable strings.
- Each module output has exactly one stanza name and one typed value.
- Snapshot output order is caller-owned and preserved.

View File

@@ -23,6 +23,7 @@ Each report definition declares:
- generated-report eligibility
- prior-report compatibility list
- morning or evening batch membership
- default ordered module composition
## Implemented Reports
@@ -70,6 +71,7 @@ output path copying uses batch output names from report definitions.
- State paths use `ArtifactGroup`.
- Batch output copies use `BatchOutputName`.
- Generation checks `Generated`.
- Module composition defaults use `Modules`.
- Prior lookup checks `CompatiblePriorIDs` and the comparison strategy.
- RunIDs include the resolved report ID.
@@ -93,5 +95,5 @@ Inspect:
- Daily Today and Daily Tomorrow both use `weather.daily_report`.
- Valid periods are half-open intervals independent of rendered report text.
- Artifact grouping, batch output filenames, generated-report eligibility,
comparison compatibility, and comparison strategy are declared by report
definition.
default module composition, comparison compatibility, and comparison strategy
are declared by report definition.

View File

@@ -20,6 +20,7 @@ Developers and LLM coding agents should use it with
source warnings.
- `internal/forecast`: deterministic forecast derivation.
- `internal/facts`: collected and derived report fact contracts.
- `internal/module`: module IDs, config items, output envelopes, and snapshots.
- `internal/report`: report definitions, valid periods, batches, output names,
and comparison declarations.
- `internal/briefing`: report-specific briefing package builders.