Use exported module values in data packages
This commit is contained in:
@@ -126,6 +126,44 @@ func TestBuildUsesNamedSnapshotStanzas(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildUsesPromptValuesFromSnapshot(t *testing.T) {
|
||||
req := validBuildRequest(t)
|
||||
req.Modules = snapshotWithOutputs(t,
|
||||
module.Output{
|
||||
ID: module.Metadata,
|
||||
StanzaName: "metadata",
|
||||
Value: map[string]string{"run_id": "rich"},
|
||||
PromptValue: map[string]string{"run_id": "prompt"},
|
||||
},
|
||||
module.Output{
|
||||
ID: module.CurrentConditions,
|
||||
StanzaName: "current_conditions",
|
||||
Value: map[string]string{"condition_text": "Rich conditions"},
|
||||
PromptValue: map[string]string{"condition_text": "Prompt conditions"},
|
||||
},
|
||||
module.Output{
|
||||
ID: module.AlertDigest,
|
||||
StanzaName: "alert_digest",
|
||||
Value: map[string]bool{"checked": true},
|
||||
},
|
||||
)
|
||||
|
||||
pkg, err := Build(req)
|
||||
if err != nil {
|
||||
t.Fatalf("Build() error = %v", err)
|
||||
}
|
||||
|
||||
if got := pkg.Briefing.Values["metadata"].(map[string]string)["run_id"]; got != "prompt" {
|
||||
t.Fatalf("metadata.run_id = %q, want prompt value", got)
|
||||
}
|
||||
if got := pkg.Briefing.Values["current_conditions"].(map[string]string)["condition_text"]; got != "Prompt conditions" {
|
||||
t.Fatalf("current_conditions.condition_text = %q, want prompt value", got)
|
||||
}
|
||||
if got := pkg.Briefing.Values["alert_digest"].(map[string]bool)["checked"]; !got {
|
||||
t.Fatalf("alert_digest.checked = %v, want rich value fallback", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarshalYAMLIsDeterministicAndGroupsNamedStanzas(t *testing.T) {
|
||||
pkg, err := Build(validBuildRequest(t))
|
||||
if err != nil {
|
||||
@@ -143,7 +181,7 @@ func TestMarshalYAMLIsDeterministicAndGroupsNamedStanzas(t *testing.T) {
|
||||
if string(first) != string(second) {
|
||||
t.Fatalf("YAML output changed between marshals:\n%s\n---\n%s", string(first), string(second))
|
||||
}
|
||||
if !strings.Contains(string(first), "schema_version: weatherreporter.data_package.v2") ||
|
||||
if !strings.Contains(string(first), "schema_version: weatherreporter.data_package.v3") ||
|
||||
!strings.Contains(string(first), "briefing:\n") ||
|
||||
!strings.Contains(string(first), " applicable_risk_products:\n") ||
|
||||
!strings.Contains(string(first), " derived_summaries:\n") ||
|
||||
@@ -251,7 +289,7 @@ func TestMarshalYAMLRejectsUncategorizedStanza(t *testing.T) {
|
||||
|
||||
func TestLoadYAMLRejectsMisplacedStanza(t *testing.T) {
|
||||
data := []byte(`
|
||||
schema_version: weatherreporter.data_package.v2
|
||||
schema_version: weatherreporter.data_package.v3
|
||||
run_id: 20260529T100000Z_daily
|
||||
report:
|
||||
id: daily
|
||||
@@ -278,6 +316,23 @@ recent_changes:
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadYAMLRejectsOldSchemaVersion(t *testing.T) {
|
||||
pkg, err := Build(validBuildRequest(t))
|
||||
if err != nil {
|
||||
t.Fatalf("Build() error = %v", err)
|
||||
}
|
||||
data, err := MarshalYAML(pkg)
|
||||
if err != nil {
|
||||
t.Fatalf("MarshalYAML() error = %v", err)
|
||||
}
|
||||
data = []byte(strings.Replace(string(data), "weatherreporter.data_package.v3", "weatherreporter.data_package.v2", 1))
|
||||
|
||||
_, err = LoadYAML(data)
|
||||
if err == nil || !strings.Contains(err.Error(), "schemaVersion must be weatherreporter.data_package.v3") {
|
||||
t.Fatalf("LoadYAML() error = %v, want current schema version error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func validBuildRequest(t *testing.T) BuildRequest {
|
||||
t.Helper()
|
||||
generatedAt := time.Date(2026, 5, 29, 10, 0, 0, 0, time.UTC)
|
||||
|
||||
Reference in New Issue
Block a user