Clean up and normalize prompt output modules
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
@@ -204,6 +205,7 @@ func TestGenerateReportWritesReportAndPreflight(t *testing.T) {
|
||||
if _, ok := savedDataPackage.Briefing.Values["metadata"]; !ok {
|
||||
t.Fatal("data package metadata stanza missing")
|
||||
}
|
||||
assertNoStaleModuleIntervalKeys(t, savedDataPackage.Briefing.Values)
|
||||
spcOutlooks, ok := savedDataPackage.Briefing.Values["spc_convective_outlooks"].(map[string]any)
|
||||
if !ok || spcOutlooks["checked"] != true || spcOutlooks["outlook_count"] != 0 {
|
||||
t.Fatalf("data package SPC convective outlooks = %#v, want checked empty source", savedDataPackage.Briefing.Values["spc_convective_outlooks"])
|
||||
@@ -274,15 +276,21 @@ func TestGenerateReportIncludesSPCConvectivePromptStanzas(t *testing.T) {
|
||||
for _, want := range []string{
|
||||
" spc_convective_outlooks:",
|
||||
" spc_convective_discussion:",
|
||||
" included_because: severity_rank >= 3",
|
||||
" included_because: categorical severity_rank >= 3",
|
||||
" label_text: Slight Risk",
|
||||
" severity_rank: 3",
|
||||
" period_begins:",
|
||||
" period_ends:",
|
||||
" discussion: Severe thunderstorms may produce damaging winds during the afternoon.",
|
||||
} {
|
||||
if !strings.Contains(text, want) {
|
||||
t.Fatalf("data package missing %q:\n%s", want, text)
|
||||
}
|
||||
}
|
||||
for _, omitted := range []string{" severity_rank:", " expires_at:", " source_url:"} {
|
||||
if strings.Contains(text, omitted) {
|
||||
t.Fatalf("data package contains %q, want SPC prompt schema without it:\n%s", omitted, text)
|
||||
}
|
||||
}
|
||||
|
||||
riskIndex := strings.Index(text, " applicable_risk_products:")
|
||||
alertIndex := strings.Index(text, " alert_digest:")
|
||||
@@ -304,6 +312,7 @@ func TestGenerateReportIncludesSPCConvectivePromptStanzas(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("LoadYAML() error = %v", err)
|
||||
}
|
||||
assertNoStaleModuleIntervalKeys(t, loaded.Briefing.Values)
|
||||
if _, ok := loaded.Briefing.Values["spc_convective_outlooks"]; !ok {
|
||||
t.Fatal("loaded package missing spc_convective_outlooks stanza")
|
||||
}
|
||||
@@ -324,9 +333,14 @@ func TestGenerateReportOmitsSPCConvectiveDiscussionBelowThreshold(t *testing.T)
|
||||
t.Fatal("module snapshot has spc_convective_discussion stanza, want omitted below threshold")
|
||||
}
|
||||
text := string(readDataPackageForTest(t, result))
|
||||
if !strings.Contains(text, " spc_convective_outlooks:") || !strings.Contains(text, " label_text: Marginal Risk") || !strings.Contains(text, " severity_rank: 2") {
|
||||
if !strings.Contains(text, " spc_convective_outlooks:") || !strings.Contains(text, " label_text: Marginal Risk") {
|
||||
t.Fatalf("data package missing lower-risk SPC outlook:\n%s", text)
|
||||
}
|
||||
for _, omitted := range []string{" severity_rank:", " expires_at:", " source_url:"} {
|
||||
if strings.Contains(text, omitted) {
|
||||
t.Fatalf("data package contains %q, want SPC prompt schema without it:\n%s", omitted, text)
|
||||
}
|
||||
}
|
||||
if strings.Contains(text, "spc_convective_discussion:") || strings.Contains(text, "Low-end severe threat discussion.") {
|
||||
t.Fatalf("data package has SPC convective discussion, want omitted below threshold:\n%s", text)
|
||||
}
|
||||
@@ -1470,6 +1484,34 @@ func readDataPackageForTest(t *testing.T, result *ReportResult) []byte {
|
||||
return data
|
||||
}
|
||||
|
||||
func assertNoStaleModuleIntervalKeys(t *testing.T, values map[string]any) {
|
||||
t.Helper()
|
||||
for name, value := range values {
|
||||
if name == "metadata" {
|
||||
continue
|
||||
}
|
||||
assertNoStaleIntervalKeys(t, "briefing."+name, value)
|
||||
}
|
||||
}
|
||||
|
||||
func assertNoStaleIntervalKeys(t *testing.T, path string, value any) {
|
||||
t.Helper()
|
||||
switch typed := value.(type) {
|
||||
case map[string]any:
|
||||
for key, child := range typed {
|
||||
switch key {
|
||||
case "start_time", "end_time", "period", "start", "end":
|
||||
t.Fatalf("%s has stale interval key %q in %#v", path, key, typed)
|
||||
}
|
||||
assertNoStaleIntervalKeys(t, path+"."+key, child)
|
||||
}
|
||||
case []any:
|
||||
for i, child := range typed {
|
||||
assertNoStaleIntervalKeys(t, fmt.Sprintf("%s[%d]", path, i), child)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func assertPathsExist(t *testing.T, paths ...string) {
|
||||
t.Helper()
|
||||
for _, path := range paths {
|
||||
@@ -1515,9 +1557,10 @@ func priorDailyModuleSnapshot(t *testing.T, resolved report.Resolved) module.Sna
|
||||
}},
|
||||
{ID: module.DerivedDaypartSummaries, StanzaName: "derived_daypart_summaries", Value: map[string]any{
|
||||
"morning": map[string]any{
|
||||
"date": resolved.ValidPeriod.Start.Format(timeutil.DateLayout),
|
||||
"period": resolved.ValidPeriod.Start.Add(6*time.Hour).Format("2006-01-02 at 3:04 PM") + " to " + resolved.ValidPeriod.Start.Add(10*time.Hour).Format("2006-01-02 at 3:04 PM"),
|
||||
"temp_range_f": "50-58",
|
||||
"date": resolved.ValidPeriod.Start.Format(timeutil.DateLayout),
|
||||
"period_begins": resolved.ValidPeriod.Start.Add(6 * time.Hour).Format("2006-01-02 at 3:04 PM"),
|
||||
"period_ends": resolved.ValidPeriod.Start.Add(10 * time.Hour).Format("2006-01-02 at 3:04 PM"),
|
||||
"temp_range_f": "50-58",
|
||||
},
|
||||
}},
|
||||
{ID: module.PrecipTiming, StanzaName: "precip_timing", Value: map[string]any{
|
||||
@@ -1539,7 +1582,8 @@ func priorOutlookModuleSnapshot(t *testing.T, date string) module.Snapshot {
|
||||
{ID: module.DerivedDaypartSummaries, StanzaName: "derived_daypart_summaries", Value: map[string]any{
|
||||
date + "_morning": map[string]any{
|
||||
"date": date,
|
||||
"period": date + " at 6:00 AM to " + date + " at 10:00 AM",
|
||||
"period_begins": date + " at 6:00 AM",
|
||||
"period_ends": date + " at 10:00 AM",
|
||||
"temp_range_f": "50-58",
|
||||
"max_pop_percent": precip,
|
||||
"max_pop_time": "6 AM",
|
||||
|
||||
Reference in New Issue
Block a user