Remove recent changes from prompt execution
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
||||
|
||||
distributoradapter "gitea.maximumdirect.net/eric/weatherreporter/internal/adapters/distributor"
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/briefing"
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/changes"
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/collect"
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/config"
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/facts"
|
||||
@@ -93,8 +92,6 @@ type ReportResult struct {
|
||||
NotificationPath string
|
||||
Metadata state.Metadata
|
||||
MetadataPath string
|
||||
PriorSnapshot *state.PriorSnapshot
|
||||
RecentChanges []changes.Change
|
||||
GeneratedTextRawPath string
|
||||
GeneratedTextPath string
|
||||
RenderContextPath string
|
||||
@@ -998,28 +995,6 @@ func defaultStore(cfg config.Config) (*state.FilesystemStore, error) {
|
||||
return state.NewFilesystemStore(cfg.Workspace)
|
||||
}
|
||||
|
||||
func recentChanges(ctx context.Context, store state.Store, priorSnapshot *state.PriorSnapshot, reportID report.ID, current module.Snapshot, cfg config.RecentChangeConfig) ([]changes.Change, error) {
|
||||
if priorSnapshot == nil {
|
||||
return nil, nil
|
||||
}
|
||||
previous, err := store.LoadModuleSnapshot(ctx, priorSnapshot.ModuleSnapshotPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
thresholds := changes.Thresholds{
|
||||
TemperatureDegrees: cfg.TemperatureDegrees,
|
||||
PrecipProbabilityPoints: cfg.PrecipProbabilityPoints,
|
||||
WindGustMilesPerHour: cfg.WindGustMilesPerHour,
|
||||
PrecipTimingShiftMinutes: cfg.PrecipTimingShiftMinutes,
|
||||
}
|
||||
switch reportID {
|
||||
case report.Daily, report.Today, report.Tomorrow:
|
||||
return changes.CompareDaily(previous, current, thresholds)
|
||||
default:
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
func generatedReportError(resolved report.Resolved, runID string, operation string, err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
|
||||
@@ -379,34 +379,6 @@ func TestRunBatchDetailedKeepsDynamicDailyArtifactsDistinct(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunBatchDetailedUsesPriorSnapshotsForPromptPackages(t *testing.T) {
|
||||
cfg := assembledBatchConfig(t, false)
|
||||
firstBundle := assembledBatchBundle(t, "2026-05-31")
|
||||
setWorkflowTemperatures(&firstBundle, 45)
|
||||
first, err := RunBatchDetailed(context.Background(), BatchRequest{
|
||||
Config: cfg, Batch: BatchMorning, Now: workflowTime("2026-05-29T08:00:00-05:00"),
|
||||
Collector: &workflowCollector{result: &collect.Result{Bundle: &firstBundle}}, Executor: newAssembledBatchExecutor(),
|
||||
})
|
||||
if err != nil || first.Failed != 0 {
|
||||
t.Fatalf("first result/error = %#v/%v", first, err)
|
||||
}
|
||||
secondBundle := assembledBatchBundle(t, "2026-05-31")
|
||||
setWorkflowTemperatures(&secondBundle, 85)
|
||||
second, err := RunBatchDetailed(context.Background(), BatchRequest{
|
||||
Config: cfg, Batch: BatchMorning, Now: workflowTime("2026-05-29T08:30:00-05:00"),
|
||||
Collector: &workflowCollector{result: &collect.Result{Bundle: &secondBundle}}, Executor: newAssembledBatchExecutor(),
|
||||
})
|
||||
if err != nil || second.Failed != 0 || len(second.Reports) != len(first.Reports) {
|
||||
t.Fatalf("second result/error = %#v/%v", second, err)
|
||||
}
|
||||
for _, item := range second.Reports {
|
||||
pkg := loadBatchDataPackage(t, item.DataPackagePath)
|
||||
if len(pkg.RecentChanges.Items) == 0 {
|
||||
t.Fatalf("report %s data package has no changes from prior snapshot", item.ReportID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func assembledBatchConfig(t *testing.T, notify bool) config.Config {
|
||||
t.Helper()
|
||||
cfg := workflowConfig(t)
|
||||
|
||||
@@ -109,10 +109,6 @@ func (w *promptReportWorkflow) buildInputs() error {
|
||||
return err
|
||||
}
|
||||
w.result = &ReportResult{}
|
||||
priorSnapshot, err := w.store.FindPriorSnapshot(w.ctx, w.req.Resolved)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w.reportFacts, err = BuildReportFacts(ModuleSnapshotRequest{Config: w.req.Config, Resolved: w.req.Resolved}, w.req.Collection.Bundle)
|
||||
if err != nil {
|
||||
return generatedReportError(w.req.Resolved, w.req.Resolved.Metadata().RunID, "build report facts", err)
|
||||
@@ -127,13 +123,6 @@ func (w *promptReportWorkflow) buildInputs() error {
|
||||
}
|
||||
w.result.ModuleSnapshot = w.moduleSnapshot
|
||||
w.result.ModuleSnapshotPath = moduleSnapshotPath
|
||||
w.result.PriorSnapshot = priorSnapshot
|
||||
|
||||
recent, err := recentChanges(w.ctx, w.store, priorSnapshot, w.req.Resolved.Definition.ID, w.moduleSnapshot, w.req.Config.RecentChange)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w.result.RecentChanges = recent
|
||||
w.briefingMetadata = briefing.BuildMetadata(briefingBuildContext(w.req.Config, w.req.Resolved, w.reportFacts.Collected))
|
||||
w.metadata = state.BuildPromptMetadataFromBriefingMetadata(w.req.Resolved, w.briefingMetadata, state.ArtifactPaths{
|
||||
ModuleSnapshot: moduleSnapshotPath,
|
||||
@@ -141,7 +130,7 @@ func (w *promptReportWorkflow) buildInputs() error {
|
||||
})
|
||||
w.result.Metadata = w.metadata
|
||||
dataPackage, err := promptinput.Build(promptinput.BuildRequest{
|
||||
Metadata: promptMetadata(w.metadata), Modules: w.moduleSnapshot, RecentChanges: recent,
|
||||
Metadata: promptMetadata(w.metadata), Modules: w.moduleSnapshot,
|
||||
})
|
||||
if err != nil {
|
||||
return w.reportError("build data package", err)
|
||||
|
||||
@@ -612,69 +612,6 @@ func workflowBundlePaths(id report.ID, validDate, runID string) []string {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateDetailedSelectsPriorSnapshotsForRetainedReports(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
kind ReportKind
|
||||
id report.ID
|
||||
date time.Time
|
||||
raw string
|
||||
wantPrior bool
|
||||
wantRecentChanges bool
|
||||
}{
|
||||
{name: "daily", kind: ReportDaily, id: report.Daily, date: workflowTime("2026-05-29T12:00:00-05:00"), raw: validDailyWorkflowJSON(), wantPrior: true, wantRecentChanges: true},
|
||||
{name: "today", kind: ReportToday, id: report.Today, raw: validTodayWorkflowJSON(), wantPrior: true, wantRecentChanges: true},
|
||||
{name: "tomorrow", kind: ReportTomorrow, id: report.Tomorrow, raw: validTomorrowWorkflowJSON(), wantPrior: true, wantRecentChanges: true},
|
||||
{name: "hourly", kind: ReportHourly, id: report.Hourly, raw: validHourlyWorkflowJSON()},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
cfg := workflowConfig(t)
|
||||
cfg.Notify.Distributor.Enabled = false
|
||||
definition := report.DefaultRegistry().MustLookup(test.id)
|
||||
firstBundle := workflowBundle(t)
|
||||
setWorkflowTemperatures(&firstBundle, 45)
|
||||
first, err := GenerateDetailed(context.Background(), GenerateRequest{
|
||||
Config: cfg, Report: test.kind, Date: test.date, Now: workflowTime("2026-05-29T08:00:00-05:00"),
|
||||
Collector: &workflowCollector{result: &collect.Result{Bundle: &firstBundle}},
|
||||
Executor: &workflowExecutor{definition: definition, raw: []byte(test.raw)},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("first GenerateDetailed() error = %v", err)
|
||||
}
|
||||
secondBundle := workflowBundle(t)
|
||||
setWorkflowTemperatures(&secondBundle, 85)
|
||||
second, err := GenerateDetailed(context.Background(), GenerateRequest{
|
||||
Config: cfg, Report: test.kind, Date: test.date, Now: workflowTime("2026-05-29T08:30:00-05:00"),
|
||||
Collector: &workflowCollector{result: &collect.Result{Bundle: &secondBundle}},
|
||||
Executor: &workflowExecutor{definition: definition, raw: []byte(test.raw)},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("second GenerateDetailed() error = %v", err)
|
||||
}
|
||||
if test.wantPrior && (second.PriorSnapshot == nil || second.PriorSnapshot.Metadata.RunID != first.Metadata.RunID || second.PriorSnapshot.Metadata.ReportID != test.id) {
|
||||
t.Fatalf("prior snapshot = %#v, want first %s run %q", second.PriorSnapshot, test.id, first.Metadata.RunID)
|
||||
}
|
||||
if !test.wantPrior && second.PriorSnapshot != nil {
|
||||
t.Fatalf("prior snapshot = %#v, want none for non-overlapping rolling window", second.PriorSnapshot)
|
||||
}
|
||||
if (len(second.RecentChanges) > 0) != test.wantRecentChanges {
|
||||
t.Fatalf("recent changes = %#v, want present %t", second.RecentChanges, test.wantRecentChanges)
|
||||
}
|
||||
if (len(second.DataPackage.RecentChanges.Items) > 0) != test.wantRecentChanges {
|
||||
t.Fatalf("data package recent changes = %#v, want present %t", second.DataPackage.RecentChanges.Items, test.wantRecentChanges)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func setWorkflowTemperatures(bundle *weatherdata.Bundle, temperature float64) {
|
||||
for index := range bundle.Hourly.Periods {
|
||||
value := temperature
|
||||
bundle.Hourly.Periods[index].TemperatureF = &value
|
||||
}
|
||||
}
|
||||
|
||||
func workflowConfig(t *testing.T) config.Config {
|
||||
t.Helper()
|
||||
cfg := config.Defaults()
|
||||
|
||||
Reference in New Issue
Block a user