From 021e5dd8b1015b60c248e4157129c84b35f57b1b Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Sat, 20 Jun 2026 02:42:20 +0000 Subject: [PATCH] Add report distributor path defaults --- internal/report/daily_report.go | 14 +++-- internal/report/definition.go | 33 +++++------ internal/report/hourly_report.go | 11 ++-- internal/report/period_test.go | 85 +++++++++++++++++++++++++++++ internal/report/registry.go | 9 ++- internal/report/storm_report.go | 4 ++ internal/report/three_day_report.go | 4 ++ internal/report/today_report.go | 15 +++-- internal/report/tomorrow_report.go | 15 +++-- internal/report/weekend_report.go | 4 ++ 10 files changed, 157 insertions(+), 37 deletions(-) diff --git a/internal/report/daily_report.go b/internal/report/daily_report.go index c2bdd51..ef09626 100644 --- a/internal/report/daily_report.go +++ b/internal/report/daily_report.go @@ -18,11 +18,15 @@ func dailyDefinition() Definition { ComparisonStrategy: CompareSameValidDate, ArtifactGroup: "daily", BatchOutputName: "daily.md", - Generated: true, - CompatiblePriorIDs: []ID{Daily}, - Modules: dailyModules(), - resolve: resolveDaily, - runIDDisambiguator: validStartDateRunIDDisambiguator, + DistributorPathTemplates: []string{ + "daily/{valid_start_date}/{run_id}.md", + "daily/{valid_start_date}/index.md", + }, + Generated: true, + CompatiblePriorIDs: []ID{Daily}, + Modules: dailyModules(), + resolve: resolveDaily, + runIDDisambiguator: validStartDateRunIDDisambiguator, } } diff --git a/internal/report/definition.go b/internal/report/definition.go index b567ea2..b722749 100644 --- a/internal/report/definition.go +++ b/internal/report/definition.go @@ -46,22 +46,23 @@ const ( ) type Definition struct { - ID ID - Name string - PromptID string - GenerationMode GenerationMode - TemplateID string - GeneratedTextSchemaID string - ComparisonStrategy ComparisonStrategy - ArtifactGroup string - BatchOutputName string - Generated bool - CompatiblePriorIDs []ID - Modules []module.ConfigItem - Morning bool - Evening bool - resolve func(ResolveRequest) (timeutil.Period, error) - runIDDisambiguator func(Resolved) string + ID ID + Name string + PromptID string + GenerationMode GenerationMode + TemplateID string + GeneratedTextSchemaID string + ComparisonStrategy ComparisonStrategy + ArtifactGroup string + BatchOutputName string + DistributorPathTemplates []string + Generated bool + CompatiblePriorIDs []ID + Modules []module.ConfigItem + Morning bool + Evening bool + resolve func(ResolveRequest) (timeutil.Period, error) + runIDDisambiguator func(Resolved) string } func (d Definition) ResolvePeriod(req ResolveRequest) (timeutil.Period, error) { diff --git a/internal/report/hourly_report.go b/internal/report/hourly_report.go index 2e6f4e0..08a8c94 100644 --- a/internal/report/hourly_report.go +++ b/internal/report/hourly_report.go @@ -20,10 +20,13 @@ func hourlyDefinition() Definition { ComparisonStrategy: CompareRollingWindow, ArtifactGroup: "hourly", BatchOutputName: "hourly.md", - Generated: true, - CompatiblePriorIDs: []ID{Hourly}, - Modules: hourlyModules(), - resolve: resolveHourly, + DistributorPathTemplates: []string{ + "hourly/index.md", + }, + Generated: true, + CompatiblePriorIDs: []ID{Hourly}, + Modules: hourlyModules(), + resolve: resolveHourly, } } diff --git a/internal/report/period_test.go b/internal/report/period_test.go index 31a1af3..60e1d38 100644 --- a/internal/report/period_test.go +++ b/internal/report/period_test.go @@ -520,6 +520,88 @@ func TestRegistryDefinitionsDeclarePathAndCompatibilityPolicy(t *testing.T) { } } +func TestGeneratedRegistryDefinitionsDeclareDistributorPathDefaults(t *testing.T) { + for _, definition := range DefaultRegistry().All() { + if !definition.Generated { + continue + } + if len(definition.DistributorPathTemplates) == 0 { + t.Fatalf("%s DistributorPathTemplates is empty", definition.ID) + } + } +} + +func TestRegistryDefinitionsDeclareDefaultDistributorPathTemplates(t *testing.T) { + tests := []struct { + id ID + want []string + }{ + { + id: Hourly, + want: []string{ + "hourly/index.md", + }, + }, + { + id: Daily, + want: []string{ + "daily/{valid_start_date}/{run_id}.md", + "daily/{valid_start_date}/index.md", + }, + }, + { + id: Today, + want: []string{ + "daily/{valid_start_date}/{run_id}.md", + "daily/{valid_start_date}/index.md", + "today/index.md", + }, + }, + { + id: Tomorrow, + want: []string{ + "daily/{valid_start_date}/{run_id}.md", + "daily/{valid_start_date}/index.md", + "tomorrow/index.md", + }, + }, + { + id: ThreeDay, + want: []string{ + "three-day/{valid_start_date}/{run_id}.md", + "three-day/{valid_start_date}/index.md", + }, + }, + { + id: Weekend, + want: []string{ + "weekend/{valid_start_date}/{run_id}.md", + "weekend/{valid_start_date}/index.md", + }, + }, + { + id: Storm, + want: []string{ + "storm/{storm_id}/{run_id}.md", + "storm/{storm_id}/index.md", + }, + }, + } + + registry := DefaultRegistry() + for _, tt := range tests { + t.Run(string(tt.id), func(t *testing.T) { + definition, err := registry.Lookup(tt.id) + if err != nil { + t.Fatalf("Lookup() error = %v", err) + } + if !reflect.DeepEqual(definition.DistributorPathTemplates, tt.want) { + t.Fatalf("DistributorPathTemplates = %#v, want %#v", definition.DistributorPathTemplates, tt.want) + } + }) + } +} + func TestRegistryDefinitionsDeclareDefaultModules(t *testing.T) { tests := []struct { id ID @@ -682,6 +764,9 @@ func TestRegistryAppliesModuleOverridesWithoutChangingDefaults(t *testing.T) { if len(defaultDefinition.ModuleIDs()) <= len(definition.ModuleIDs()) { t.Fatalf("default ModuleIDs() = %#v, want original defaults unchanged", defaultDefinition.ModuleIDs()) } + if !reflect.DeepEqual(definition.DistributorPathTemplates, defaultDefinition.DistributorPathTemplates) { + t.Fatalf("overridden DistributorPathTemplates = %#v, want %#v", definition.DistributorPathTemplates, defaultDefinition.DistributorPathTemplates) + } } func TestRegistryRejectsModuleOverrideForUnknownReport(t *testing.T) { diff --git a/internal/report/registry.go b/internal/report/registry.go index 6258569..18eaf1b 100644 --- a/internal/report/registry.go +++ b/internal/report/registry.go @@ -30,8 +30,7 @@ func DefaultRegistry() Registry { func (r Registry) WithModuleOverrides(overrides map[ID][]module.ConfigItem) (Registry, error) { next := Registry{definitions: map[ID]Definition{}} for id, definition := range r.definitions { - definition.Modules = append([]module.ConfigItem(nil), definition.Modules...) - next.definitions[id] = definition + next.definitions[id] = cloneDefinition(definition) } for id, items := range overrides { definition, ok := next.definitions[id] @@ -44,6 +43,12 @@ func (r Registry) WithModuleOverrides(overrides map[ID][]module.ConfigItem) (Reg return next, nil } +func cloneDefinition(definition Definition) Definition { + definition.Modules = cloneModuleItems(definition.Modules) + definition.DistributorPathTemplates = append([]string(nil), definition.DistributorPathTemplates...) + return definition +} + func moduleItems(ids ...module.ID) []module.ConfigItem { items := make([]module.ConfigItem, 0, len(ids)) for _, id := range ids { diff --git a/internal/report/storm_report.go b/internal/report/storm_report.go index b53496d..736e495 100644 --- a/internal/report/storm_report.go +++ b/internal/report/storm_report.go @@ -17,6 +17,10 @@ func stormDefinition() Definition { ComparisonStrategy: CompareExplicitWindow, ArtifactGroup: "storm", BatchOutputName: "storm.md", + DistributorPathTemplates: []string{ + "storm/{storm_id}/{run_id}.md", + "storm/{storm_id}/index.md", + }, Generated: true, CompatiblePriorIDs: []ID{Storm}, Modules: stormModules(), diff --git a/internal/report/three_day_report.go b/internal/report/three_day_report.go index 21b21f7..5ac094c 100644 --- a/internal/report/three_day_report.go +++ b/internal/report/three_day_report.go @@ -16,6 +16,10 @@ func threeDayDefinition() Definition { ComparisonStrategy: CompareSameValidDate, ArtifactGroup: "three-day", BatchOutputName: "three-day.md", + DistributorPathTemplates: []string{ + "three-day/{valid_start_date}/{run_id}.md", + "three-day/{valid_start_date}/index.md", + }, Generated: true, CompatiblePriorIDs: []ID{ThreeDay}, Modules: threeDayModules(), diff --git a/internal/report/today_report.go b/internal/report/today_report.go index 813ce91..048df15 100644 --- a/internal/report/today_report.go +++ b/internal/report/today_report.go @@ -16,11 +16,16 @@ func todayDefinition() Definition { ComparisonStrategy: CompareSameValidDate, ArtifactGroup: "today", BatchOutputName: "today.md", - Generated: true, - CompatiblePriorIDs: []ID{Today}, - Modules: todayModules(), - Morning: true, - resolve: resolveToday, + DistributorPathTemplates: []string{ + "daily/{valid_start_date}/{run_id}.md", + "daily/{valid_start_date}/index.md", + "today/index.md", + }, + Generated: true, + CompatiblePriorIDs: []ID{Today}, + Modules: todayModules(), + Morning: true, + resolve: resolveToday, } } diff --git a/internal/report/tomorrow_report.go b/internal/report/tomorrow_report.go index 9ff0934..cb3bfbe 100644 --- a/internal/report/tomorrow_report.go +++ b/internal/report/tomorrow_report.go @@ -16,11 +16,16 @@ func tomorrowDefinition() Definition { ComparisonStrategy: CompareSameValidDate, ArtifactGroup: "tomorrow", BatchOutputName: "tomorrow.md", - Generated: true, - CompatiblePriorIDs: []ID{Tomorrow}, - Modules: tomorrowModules(), - Evening: true, - resolve: resolveTomorrow, + DistributorPathTemplates: []string{ + "daily/{valid_start_date}/{run_id}.md", + "daily/{valid_start_date}/index.md", + "tomorrow/index.md", + }, + Generated: true, + CompatiblePriorIDs: []ID{Tomorrow}, + Modules: tomorrowModules(), + Evening: true, + resolve: resolveTomorrow, } } diff --git a/internal/report/weekend_report.go b/internal/report/weekend_report.go index 84c4bcb..6cda31a 100644 --- a/internal/report/weekend_report.go +++ b/internal/report/weekend_report.go @@ -17,6 +17,10 @@ func weekendDefinition() Definition { ComparisonStrategy: CompareWeekendWindow, ArtifactGroup: "weekend", BatchOutputName: "weekend.md", + DistributorPathTemplates: []string{ + "weekend/{valid_start_date}/{run_id}.md", + "weekend/{valid_start_date}/index.md", + }, Generated: true, CompatiblePriorIDs: []ID{Weekend}, Modules: weekendModules(),