Add SPC Outlook summaries to the alert digest template
This commit is contained in:
@@ -71,12 +71,19 @@ func TestSPCConvectiveOutlooksModuleBuildsPromptSafeRiskProduct(t *testing.T) {
|
||||
if !got.ContainsLocation || got.ImageURL == "" {
|
||||
t.Fatalf("outlook = %#v, want location flag and image URL", got)
|
||||
}
|
||||
if len(value.RiskDigest) != 1 {
|
||||
t.Fatalf("RiskDigest length = %d, want 1", len(value.RiskDigest))
|
||||
}
|
||||
digest := value.RiskDigest[0]
|
||||
if digest.LabelText != "Slight Risk" || digest.RiskLabel != "Slight risk" || digest.PeriodBegins != "2026-05-29 at 11:00 AM" || digest.PeriodEnds != "2026-05-30 at 7:00 AM" {
|
||||
t.Fatalf("risk digest = %#v, want prompt-facing slight risk record", digest)
|
||||
}
|
||||
data, err := json.Marshal(output.Value)
|
||||
if err != nil {
|
||||
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", "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", "period_begins", "period_ends", "contains_location", "image_url"} {
|
||||
if !strings.Contains(text, field) {
|
||||
t.Fatalf("json = %s, want field %s", text, field)
|
||||
}
|
||||
@@ -88,6 +95,71 @@ func TestSPCConvectiveOutlooksModuleBuildsPromptSafeRiskProduct(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSPCRiskDigestDefaultPolicyConstants(t *testing.T) {
|
||||
if defaultSPCRiskDigestOutlookType != "categorical" {
|
||||
t.Fatalf("defaultSPCRiskDigestOutlookType = %q, want categorical", defaultSPCRiskDigestOutlookType)
|
||||
}
|
||||
if defaultSPCRiskDigestMinimumSeverityRank != 3 {
|
||||
t.Fatalf("defaultSPCRiskDigestMinimumSeverityRank = %d, want 3", defaultSPCRiskDigestMinimumSeverityRank)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSPCConvectiveOutlooksRiskDigestFilters(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
outlook weatherdata.ConvectiveOutlook
|
||||
wantRisk bool
|
||||
}{
|
||||
{
|
||||
name: "categorical slight risk included",
|
||||
outlook: spcRiskDigestTestOutlook("categorical", "Slight Risk", 3, true,
|
||||
"2026-05-29T11:00:00-05:00", "2026-05-30T07:00:00-05:00"),
|
||||
wantRisk: true,
|
||||
},
|
||||
{
|
||||
name: "marginal risk excluded",
|
||||
outlook: spcRiskDigestTestOutlook("categorical", "Marginal Risk", 2, true,
|
||||
"2026-05-29T11:00:00-05:00", "2026-05-30T07:00:00-05:00"),
|
||||
},
|
||||
{
|
||||
name: "non categorical high rank excluded",
|
||||
outlook: spcRiskDigestTestOutlook("wind", "30% Wind Risk", 30, true,
|
||||
"2026-05-29T11:00:00-05:00", "2026-05-30T07:00:00-05:00"),
|
||||
},
|
||||
{
|
||||
name: "non overlapping excluded",
|
||||
outlook: spcRiskDigestTestOutlook("categorical", "Enhanced Risk", 4, true,
|
||||
"2026-05-30T07:00:00-05:00", "2026-05-31T07:00:00-05:00"),
|
||||
},
|
||||
{
|
||||
name: "location miss excluded",
|
||||
outlook: spcRiskDigestTestOutlook("categorical", "Moderate Risk", 5, false,
|
||||
"2026-05-29T11:00:00-05:00", "2026-05-30T07:00:00-05:00"),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
registry := MustDefaultModuleRegistry()
|
||||
ctx := testModuleContext()
|
||||
ctx.Collected.SPCConvectiveOutlooks = &weatherdata.ConvectiveOutlookRun{
|
||||
Outlooks: []weatherdata.ConvectiveOutlook{tt.outlook},
|
||||
}
|
||||
ctx.Derived.SPCConvectiveOutlooks = []weatherdata.ConvectiveOutlook{tt.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)
|
||||
gotRisk := len(value.RiskDigest) > 0
|
||||
if gotRisk != tt.wantRisk {
|
||||
t.Fatalf("RiskDigest = %#v, want included=%v", value.RiskDigest, tt.wantRisk)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSPCConvectiveOutlooksModuleSkipsNonOverlappingOutlooks(t *testing.T) {
|
||||
registry := MustDefaultModuleRegistry()
|
||||
ctx := testModuleContext()
|
||||
@@ -117,6 +189,9 @@ func TestSPCConvectiveOutlooksModuleSkipsNonOverlappingOutlooks(t *testing.T) {
|
||||
if value.OutlookCount != 0 || len(value.Outlooks) != 0 {
|
||||
t.Fatalf("value = %#v, want non-overlapping outlook omitted", value)
|
||||
}
|
||||
if len(value.RiskDigest) != 0 {
|
||||
t.Fatalf("RiskDigest = %#v, want non-overlapping outlook omitted", value.RiskDigest)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSPCConvectiveOutlooksModuleBuildsCheckedEmptyStanza(t *testing.T) {
|
||||
@@ -167,3 +242,16 @@ func TestSPCConvectiveOutlooksModuleBuildsUncheckedStanzaForMissingSource(t *tes
|
||||
t.Fatalf("missing source value = %#v, want unchecked empty stanza", value)
|
||||
}
|
||||
}
|
||||
|
||||
func spcRiskDigestTestOutlook(outlookType string, labelText string, rank int, containsLocation bool, validFrom string, validTo string) weatherdata.ConvectiveOutlook {
|
||||
return weatherdata.ConvectiveOutlook{
|
||||
ID: labelText,
|
||||
Day: 1,
|
||||
OutlookType: outlookType,
|
||||
LabelText: labelText,
|
||||
SeverityRank: &rank,
|
||||
ValidFrom: mustParseModuleTime(validFrom),
|
||||
ValidTo: mustParseModuleTime(validTo),
|
||||
ContainsLocation: containsLocation,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user