Remove static batch report resolution

This commit is contained in:
2026-06-17 16:07:40 +00:00
parent a9d87bdbaa
commit 3eccafad6b
6 changed files with 21 additions and 167 deletions

View File

@@ -272,7 +272,7 @@ func RunBatchDetailed(ctx context.Context, req BatchRequest) (*BatchResult, erro
if err != nil {
return nil, err
}
plannedReports, err := planBatchReports(req, now, *collection)
plannedReports, err := planBatchRun(req, now, *collection)
if err != nil {
return nil, err
}
@@ -398,25 +398,6 @@ func ResolveGenerate(req GenerateRequest, now time.Time) (report.Resolved, error
})
}
func ResolveBatch(req BatchRequest, now time.Time) ([]report.Resolved, error) {
location, err := timeutil.LoadLocation(req.Config.WeatherAPI.Timezone)
if err != nil {
return nil, err
}
batch, err := report.BatchForCommandName(string(req.Batch))
if err != nil {
return nil, err
}
registry, err := reportRegistry(req.Config)
if err != nil {
return nil, err
}
return registry.BatchReports(batch, report.ResolveRequest{
Now: now,
Location: location,
})
}
func reportRegistry(cfg config.Config) (report.Registry, error) {
overrides, err := cfg.ReportModuleOverrides()
if err != nil {

View File

@@ -2214,25 +2214,6 @@ func TestResolveGenerateStorm(t *testing.T) {
}
}
func TestResolveBatchMorningSkipsWeekendOnSunday(t *testing.T) {
cfg := config.Defaults()
cfg.WeatherAPI.Timezone = "America/Chicago"
now := mustParse("2026-05-31T06:00:00-05:00")
resolved, err := ResolveBatch(BatchRequest{Config: cfg, Batch: BatchMorning}, now)
if err != nil {
t.Fatalf("ResolveBatch() error = %v", err)
}
if len(resolved) != 2 {
t.Fatalf("resolved length = %d, want 2", len(resolved))
}
for _, item := range resolved {
if item.Definition.ID == report.Weekend {
t.Fatal("morning batch included weekend on Sunday")
}
}
}
func TestRunBatchContinuesAfterReportFailure(t *testing.T) {
server := dailyBundleServer(t)
cfg := dailyWorkspaceConfig(t, server)

View File

@@ -15,7 +15,7 @@ type plannedBatchReport struct {
OutputCopyName string
}
func planBatchReports(req BatchRequest, now time.Time, collection collect.Result) ([]plannedBatchReport, error) {
func planBatchRun(req BatchRequest, now time.Time, collection collect.Result) ([]plannedBatchReport, error) {
location, err := timeutil.LoadLocation(req.Config.WeatherAPI.Timezone)
if err != nil {
return nil, err

View File

@@ -12,39 +12,39 @@ import (
"gitea.maximumdirect.net/eric/weatherreporter/internal/weatherdata"
)
func TestPlanBatchReportsMorningOrder(t *testing.T) {
func TestPlanBatchRunMorningOrder(t *testing.T) {
location := mustLoadTestLocation(t, "America/Chicago")
hourly := hourlyRun(fullDayPeriods(t, "2026-05-31", location)...)
planned, err := planBatchReports(BatchRequest{Config: planningConfig(), Batch: BatchMorning}, mustParse("2026-05-29T08:00:00-05:00"), collectionWithHourly(hourly))
planned, err := planBatchRun(BatchRequest{Config: planningConfig(), Batch: BatchMorning}, mustParse("2026-05-29T08:00:00-05:00"), collectionWithHourly(hourly))
if err != nil {
t.Fatalf("planBatchReports() error = %v", err)
t.Fatalf("planBatchRun() error = %v", err)
}
assertPlannedReportIDs(t, planned, report.Today, report.Tomorrow, report.Daily)
}
func TestPlanBatchReportsEveningOrder(t *testing.T) {
func TestPlanBatchRunEveningOrder(t *testing.T) {
location := mustLoadTestLocation(t, "America/Chicago")
hourly := hourlyRun(fullDayPeriods(t, "2026-05-31", location)...)
planned, err := planBatchReports(BatchRequest{Config: planningConfig(), Batch: BatchEvening}, mustParse("2026-05-29T18:00:00-05:00"), collectionWithHourly(hourly))
planned, err := planBatchRun(BatchRequest{Config: planningConfig(), Batch: BatchEvening}, mustParse("2026-05-29T18:00:00-05:00"), collectionWithHourly(hourly))
if err != nil {
t.Fatalf("planBatchReports() error = %v", err)
t.Fatalf("planBatchRun() error = %v", err)
}
assertPlannedReportIDs(t, planned, report.Tomorrow, report.Daily)
}
func TestPlanBatchReportsDynamicDailyDatesStartAfterTomorrow(t *testing.T) {
func TestPlanBatchRunDynamicDailyDatesStartAfterTomorrow(t *testing.T) {
location := mustLoadTestLocation(t, "America/Chicago")
periods := fullDayPeriods(t, "2026-05-30", location)
periods = append(periods, fullDayPeriods(t, "2026-05-31", location)...)
periods = append(periods, fullDayPeriods(t, "2026-06-01", location)...)
planned, err := planBatchReports(BatchRequest{Config: planningConfig(), Batch: BatchMorning}, mustParse("2026-05-29T08:00:00-05:00"), collectionWithHourly(hourlyRun(periods...)))
planned, err := planBatchRun(BatchRequest{Config: planningConfig(), Batch: BatchMorning}, mustParse("2026-05-29T08:00:00-05:00"), collectionWithHourly(hourlyRun(periods...)))
if err != nil {
t.Fatalf("planBatchReports() error = %v", err)
t.Fatalf("planBatchRun() error = %v", err)
}
daily := plannedDailyReports(planned)
@@ -55,10 +55,10 @@ func TestPlanBatchReportsDynamicDailyDatesStartAfterTomorrow(t *testing.T) {
assertPlanningPeriod(t, daily[1].Resolved.ValidPeriod, "2026-06-01T00:00:00-05:00", "2026-06-02T00:00:00-05:00")
}
func TestPlanBatchReportsMorningExcludesLegacyStaticReports(t *testing.T) {
planned, err := planBatchReports(BatchRequest{Config: planningConfig(), Batch: BatchMorning}, mustParse("2026-05-29T08:00:00-05:00"), collect.Result{Bundle: &weatherdata.Bundle{}})
func TestPlanBatchRunMorningExcludesLegacyStaticReports(t *testing.T) {
planned, err := planBatchRun(BatchRequest{Config: planningConfig(), Batch: BatchMorning}, mustParse("2026-05-29T08:00:00-05:00"), collect.Result{Bundle: &weatherdata.Bundle{}})
if err != nil {
t.Fatalf("planBatchReports() error = %v", err)
t.Fatalf("planBatchRun() error = %v", err)
}
for _, item := range planned {
@@ -68,13 +68,13 @@ func TestPlanBatchReportsMorningExcludesLegacyStaticReports(t *testing.T) {
}
}
func TestPlanBatchReportsDynamicDailyOutputCopyNames(t *testing.T) {
func TestPlanBatchRunDynamicDailyOutputCopyNames(t *testing.T) {
location := mustLoadTestLocation(t, "America/Chicago")
hourly := hourlyRun(fullDayPeriods(t, "2026-05-31", location)...)
planned, err := planBatchReports(BatchRequest{Config: planningConfig(), Batch: BatchEvening}, mustParse("2026-05-29T18:00:00-05:00"), collectionWithHourly(hourly))
planned, err := planBatchRun(BatchRequest{Config: planningConfig(), Batch: BatchEvening}, mustParse("2026-05-29T18:00:00-05:00"), collectionWithHourly(hourly))
if err != nil {
t.Fatalf("planBatchReports() error = %v", err)
t.Fatalf("planBatchRun() error = %v", err)
}
daily := plannedDailyReports(planned)
@@ -89,10 +89,10 @@ func TestPlanBatchReportsDynamicDailyOutputCopyNames(t *testing.T) {
}
}
func TestPlanBatchReportsRejectsUnknownBatch(t *testing.T) {
_, err := planBatchReports(BatchRequest{Config: planningConfig(), Batch: BatchKind("hourly")}, mustParse("2026-05-29T08:00:00-05:00"), collect.Result{Bundle: &weatherdata.Bundle{}})
func TestPlanBatchRunRejectsUnknownBatch(t *testing.T) {
_, err := planBatchRun(BatchRequest{Config: planningConfig(), Batch: BatchKind("hourly")}, mustParse("2026-05-29T08:00:00-05:00"), collect.Result{Bundle: &weatherdata.Bundle{}})
if err == nil || !strings.Contains(err.Error(), `unknown batch command "hourly"`) {
t.Fatalf("planBatchReports() error = %v, want unknown batch command", err)
t.Fatalf("planBatchRun() error = %v, want unknown batch command", err)
}
}