2.4 KiB
Generated Text Internals
internal/generatedtext validates the structured prose produced for generated-
text reports and turns validated prose plus rich module values into typed render
contexts. It owns the catalog that pairs a generated-text report definition
with its validator, schema ID, template ID, and context builder. The complete
maintainer-facing context fields belong to report templates.
Catalog and validation
Only the Daily, Today, Tomorrow, and Hourly report definitions use the
generated-text-template mode. LookupDefinition rejects a direct-Markdown
definition, unknown schema or template IDs, and unsupported schema/template
pairs before the run begins. A handler validates raw JSON, returns a typed
value and canonical normalized JSON, loads its schema, builds a render context,
and renders through internal/reporttemplate.
Daily, Today, and Tomorrow use a day-style value with required trimmed summary and one or more nonblank discussion paragraphs. Hourly requires trimmed summary and a single trimmed discussion string. Each form permits optional trimmed precipitation-timing and confidence prose. Typed decoding rejects unknown JSON fields; no general-purpose JSON Schema engine is used at runtime.
Render contexts
The catalog's report-specific builders receive briefing metadata, a rich module snapshot, collected facts, derived facts, and the matching validated generated text. They decode the module stanzas needed by the template and build typed Daily, Today, Tomorrow, or Hourly contexts. Context construction validates metadata and periods, preserves rich module values, and uses ordered slices for template iteration rather than maps.
Optional source stanzas become nil or fallback context fields. Missing required stanzas, type-decoding failures, invalid metadata, or a generated-text type that does not match the chosen handler fail before template execution. Prompt packages, raw Scriptorium output, state persistence, and template asset lookup remain outside this package.
Verification and invariants
Focused tests cover the catalog, each report-specific validator, normalization, schema/template mismatches, context construction, optional modules, and typed stanza errors:
go test ./internal/generatedtext
Generated text supplies prose slots only; deterministic weather facts remain in module and fact values. Every generated-text definition must resolve to exactly one supported catalog pair.