Correct curated prompt package contracts
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package promptinput
|
||||
|
||||
import (
|
||||
"math"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -8,6 +9,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/module"
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/report"
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/timeutil"
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/weatherdata"
|
||||
)
|
||||
|
||||
func TestBuildDailyDataPackage(t *testing.T) {
|
||||
@@ -161,6 +163,37 @@ func TestBuildUsesPromptValuesFromSnapshot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarshalYAMLProjectsSourceWarningsWithoutTransportDetails(t *testing.T) {
|
||||
req := validBuildRequest(t)
|
||||
req.Metadata.SourceWarnings = []weatherdata.SourceWarning{{
|
||||
Source: "hourly",
|
||||
Code: "missing_source",
|
||||
Severity: "warning",
|
||||
Message: "hourly source is unavailable",
|
||||
Endpoint: "/transport/path/only-for-this-test",
|
||||
CompletenessImpact: "source omitted",
|
||||
}}
|
||||
|
||||
pkg, err := Build(req)
|
||||
if err != nil {
|
||||
t.Fatalf("Build() error = %v", err)
|
||||
}
|
||||
data, err := MarshalYAML(pkg)
|
||||
if err != nil {
|
||||
t.Fatalf("MarshalYAML() error = %v", err)
|
||||
}
|
||||
text := string(data)
|
||||
|
||||
for _, safeDetail := range []string{"source_warnings:", "source: hourly", "code: missing_source", "severity: warning", "message: hourly source is unavailable", "completeness_impact: source omitted"} {
|
||||
if !strings.Contains(text, safeDetail) {
|
||||
t.Fatalf("YAML output missing safe warning detail %q:\n%s", safeDetail, text)
|
||||
}
|
||||
}
|
||||
if strings.Contains(text, "/transport/path/only-for-this-test") || strings.Contains(text, "endpoint:") {
|
||||
t.Fatalf("YAML output contains raw warning transport details:\n%s", text)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarshalYAMLIsDeterministicAndGroupsNamedStanzas(t *testing.T) {
|
||||
pkg, err := Build(validBuildRequest(t))
|
||||
if err != nil {
|
||||
@@ -287,6 +320,23 @@ func TestMarshalYAMLRejectsUncategorizedStanza(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarshalYAMLAttributesStanzaSerializationFailures(t *testing.T) {
|
||||
req := validBuildRequest(t)
|
||||
req.Modules = snapshotWithOutputs(t,
|
||||
module.Output{ID: module.Metadata, StanzaName: "metadata", Value: map[string]string{"run_id": req.Metadata.RunID}},
|
||||
module.Output{ID: module.CurrentConditions, StanzaName: "current_conditions", Value: map[string]float64{"temperature": math.Inf(1)}},
|
||||
)
|
||||
pkg, err := Build(req)
|
||||
if err != nil {
|
||||
t.Fatalf("Build() error = %v", err)
|
||||
}
|
||||
|
||||
_, err = MarshalYAML(pkg)
|
||||
if err == nil || !strings.Contains(err.Error(), `marshal briefing stanza "current_conditions"`) {
|
||||
t.Fatalf("MarshalYAML() error = %v, want current_conditions stanza context", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadYAMLRejectsMisplacedStanza(t *testing.T) {
|
||||
data := []byte(`
|
||||
schema_version: weatherreporter.data_package.v4
|
||||
|
||||
Reference in New Issue
Block a user