Route report projections through prepared identity

This commit is contained in:
2026-08-13 02:00:18 +00:00
parent e2dd8d0e29
commit 360c665a3e
15 changed files with 163 additions and 253 deletions

View File

@@ -3,9 +3,11 @@ package briefing
import (
"reflect"
"testing"
"gitea.maximumdirect.net/eric/weatherreporter/internal/weatherdata"
)
func TestPreparedIdentityBuildsEquivalentMetadata(t *testing.T) {
func TestPreparedIdentityCopiesMutableFields(t *testing.T) {
moduleContext := testModuleContext()
context := BuildContext{
Resolved: moduleContext.Resolved,
@@ -15,18 +17,10 @@ func TestPreparedIdentityBuildsEquivalentMetadata(t *testing.T) {
Location: moduleContext.Location,
}
identity := BuildPreparedIdentity(context)
metadata := BuildMetadata(identity, context.Bundle)
if metadata.RunID != identity.RunID || metadata.ReportID != identity.ReportID || metadata.Variant != identity.Variant || metadata.PromptID != identity.PromptID || !metadata.GeneratedAt.Equal(identity.GeneratedAt) || metadata.Units != identity.Units || metadata.Timezone != identity.Timezone || metadata.ValidPeriod != identity.ValidPeriod {
t.Fatalf("metadata identity = %#v, want %#v", metadata, identity)
}
if !reflect.DeepEqual(metadata.Location, identity.Location) || !reflect.DeepEqual(metadata.SourceWarnings, identity.SourceWarnings) {
t.Fatalf("metadata location/warnings = %#v/%#v, want %#v/%#v", metadata.Location, metadata.SourceWarnings, identity.Location, identity.SourceWarnings)
}
metadata.Location.Name = "consumer mutation"
metadata.SourceWarnings = append(metadata.SourceWarnings, moduleContext.Collected.SourceWarnings[0])
if identity.Location.Name == "consumer mutation" || len(identity.SourceWarnings) != len(moduleContext.Collected.SourceWarnings) {
t.Fatalf("identity changed through metadata mutation: %#v", identity)
originalWarnings := append([]weatherdata.SourceWarning(nil), moduleContext.Collected.SourceWarnings...)
identity.Location.Name = "consumer mutation"
identity.SourceWarnings = append(identity.SourceWarnings, moduleContext.Collected.SourceWarnings[0])
if moduleContext.Location.Name == "consumer mutation" || !reflect.DeepEqual(moduleContext.Collected.SourceWarnings, originalWarnings) {
t.Fatalf("prepared identity changed its source context: %#v", identity)
}
}