Add background definitions for SPC convective outlook risk products
This commit is contained in:
@@ -65,6 +65,12 @@ func TestSPCConvectiveOutlooksModuleBuildsPromptSafeRiskProduct(t *testing.T) {
|
||||
if got.Day != 1 || got.OutlookType != "categorical" || got.Label != "SLGT" || got.LabelText != "Slight Risk" {
|
||||
t.Fatalf("outlook = %#v, want categorical slight risk fields", got)
|
||||
}
|
||||
if got.BackgroundDefinition == nil ||
|
||||
got.BackgroundDefinition.PlainLanguage != "Scattered severe storms possible." ||
|
||||
got.BackgroundDefinition.OfficialDescription != "Isolated intense storms are possible within the risk area, but severe weather is generally expected to be short-lived and/or not widespread." ||
|
||||
got.BackgroundDefinition.RelativeLevel != "2 of 5" {
|
||||
t.Fatalf("background definition = %#v, want Slight Risk helper", got.BackgroundDefinition)
|
||||
}
|
||||
if got.PeriodBegins != "2026-05-29 at 11:00 AM" || got.PeriodEnds != "2026-05-30 at 7:00 AM" || got.IssuedAt != "2026-05-29 at 8:45 AM" {
|
||||
t.Fatalf("outlook times = %#v, want friendly local labels", got)
|
||||
}
|
||||
@@ -83,7 +89,7 @@ func TestSPCConvectiveOutlooksModuleBuildsPromptSafeRiskProduct(t *testing.T) {
|
||||
t.Fatalf("Marshal() error = %v", err)
|
||||
}
|
||||
text := string(data)
|
||||
for _, field := range []string{"checked", "as_of", "issued_at", "location_id", "location_name", "outlook_count", "outlooks", "risk_digest", "period_begins", "period_ends", "contains_location", "image_url"} {
|
||||
for _, field := range []string{"checked", "as_of", "issued_at", "location_id", "location_name", "outlook_count", "outlooks", "risk_digest", "background_definition", "plain_language", "official_description", "relative_level", "period_begins", "period_ends", "contains_location", "image_url"} {
|
||||
if !strings.Contains(text, field) {
|
||||
t.Fatalf("json = %s, want field %s", text, field)
|
||||
}
|
||||
@@ -95,6 +101,98 @@ func TestSPCConvectiveOutlooksModuleBuildsPromptSafeRiskProduct(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSPCOutlookBackgroundDefinitionLookup(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
outlookType string
|
||||
label string
|
||||
want bool
|
||||
}{
|
||||
{name: "exact slight risk", outlookType: "categorical", label: "SLGT", want: true},
|
||||
{name: "normalized slight risk", outlookType: " Categorical ", label: "slgt", want: true},
|
||||
{name: "expanded marginal risk", outlookType: "categorical", label: "MRGL", want: true},
|
||||
{name: "expanded conditional tornado risk", outlookType: "tornado", label: "CIG3", want: true},
|
||||
{name: "unknown risk", outlookType: "categorical", label: "FOO"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
definition := spcOutlookBackgroundDefinition(tt.outlookType, tt.label)
|
||||
if tt.want && definition == nil {
|
||||
t.Fatalf("spcOutlookBackgroundDefinition(%q, %q) = nil, want definition", tt.outlookType, tt.label)
|
||||
}
|
||||
if !tt.want && definition != nil {
|
||||
t.Fatalf("spcOutlookBackgroundDefinition(%q, %q) = %#v, want nil", tt.outlookType, tt.label, definition)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSPCConvectiveOutlooksModuleOmitsUnknownBackgroundDefinition(t *testing.T) {
|
||||
registry := MustDefaultModuleRegistry()
|
||||
ctx := testModuleContext()
|
||||
outlook := spcRiskDigestTestOutlook("categorical", "Unknown Risk", 2, true,
|
||||
"2026-05-29T11:00:00-05:00", "2026-05-30T07:00:00-05:00")
|
||||
outlook.Label = "FOO"
|
||||
ctx.Collected.SPCConvectiveOutlooks = &weatherdata.ConvectiveOutlookRun{
|
||||
Outlooks: []weatherdata.ConvectiveOutlook{outlook},
|
||||
}
|
||||
ctx.Derived.SPCConvectiveOutlooks = []weatherdata.ConvectiveOutlook{outlook}
|
||||
|
||||
output, err := registry.BuildModule(ctx, module.ConfigItem{ID: module.SPCConvectiveOutlooks})
|
||||
if err != nil {
|
||||
t.Fatalf("BuildModule() error = %v", err)
|
||||
}
|
||||
value := moduleValue[SPCConvectiveOutlooksModule](t, output)
|
||||
if len(value.Outlooks) != 1 {
|
||||
t.Fatalf("Outlooks length = %d, want 1", len(value.Outlooks))
|
||||
}
|
||||
if value.Outlooks[0].BackgroundDefinition != nil {
|
||||
t.Fatalf("BackgroundDefinition = %#v, want nil for undefined risk", value.Outlooks[0].BackgroundDefinition)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSPCOutlookBackgroundDefinitionsAssetHasUsableEntries(t *testing.T) {
|
||||
wantKeys := []string{
|
||||
"categorical:TSTM",
|
||||
"categorical:MRGL",
|
||||
"categorical:SLGT",
|
||||
"categorical:ENH",
|
||||
"categorical:MDT",
|
||||
"categorical:HIGH",
|
||||
"tornado:CIG1",
|
||||
"tornado:CIG2",
|
||||
"tornado:CIG3",
|
||||
"wind:CIG1",
|
||||
"wind:CIG2",
|
||||
"wind:CIG3",
|
||||
"hail:CIG1",
|
||||
"hail:CIG2",
|
||||
}
|
||||
if len(spcOutlookBackgroundDefinitions) != len(wantKeys) {
|
||||
t.Fatalf("embedded SPC outlook background definitions length = %d, want %d", len(spcOutlookBackgroundDefinitions), len(wantKeys))
|
||||
}
|
||||
for _, key := range wantKeys {
|
||||
if _, ok := spcOutlookBackgroundDefinitions[key]; !ok {
|
||||
t.Fatalf("embedded SPC outlook background definitions missing %q", key)
|
||||
}
|
||||
}
|
||||
for key, definition := range spcOutlookBackgroundDefinitions {
|
||||
if strings.TrimSpace(key) == "" {
|
||||
t.Fatal("embedded SPC outlook background definitions contain empty key")
|
||||
}
|
||||
if definition.PlainLanguage == "" || definition.OfficialDescription == "" || definition.RelativeLevel == "" {
|
||||
t.Fatalf("embedded SPC outlook background definition %q is incomplete: %#v", key, definition)
|
||||
}
|
||||
if strings.Contains(definition.OfficialDescription, ".Note") || strings.Contains(definition.OfficialDescription, "higher.Note") {
|
||||
t.Fatalf("embedded SPC outlook background definition %q has missing sentence spacing: %q", key, definition.OfficialDescription)
|
||||
}
|
||||
if strings.Contains(definition.OfficialDescription, "by themselves") {
|
||||
t.Fatalf("embedded SPC outlook background definition %q has singular grammar issue: %q", key, definition.OfficialDescription)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSPCRiskDigestDefaultPolicyConstants(t *testing.T) {
|
||||
if defaultSPCRiskDigestOutlookType != "categorical" {
|
||||
t.Fatalf("defaultSPCRiskDigestOutlookType = %q, want categorical", defaultSPCRiskDigestOutlookType)
|
||||
|
||||
Reference in New Issue
Block a user