package app import ( "context" "encoding/json" "errors" "strings" "testing" "gitea.maximumdirect.net/eric/weatherreporter/internal/collect" "gitea.maximumdirect.net/eric/weatherreporter/internal/config" "gitea.maximumdirect.net/eric/weatherreporter/internal/promptexec" ) func TestRunBatchDetailedInspectsEveryCandidateBeforeCollection(t *testing.T) { cfg := config.Defaults() cfg.Workspace.Root = t.TempDir() now := mustParse("2026-05-29T08:00:00-05:00") req := BatchRequest{Config: cfg, Batch: BatchMorning, Now: now} candidates, err := batchInspectionCandidates(req, now) if err != nil { t.Fatalf("batchInspectionCandidates() error = %v", err) } executor := &inspectionExecutor{profiles: map[string]promptexec.ProfileInspection{ "default-profile": {ProfileID: "default-profile", BackendID: "local", ModelName: "model"}, }, prompts: map[string]promptexec.PromptInspection{}} for _, candidate := range candidates { executor.prompts[candidate.Definition.PromptID] = validPromptInspection(candidate.Definition) } collector := collectorFunc(func(context.Context, collect.Request) (*collect.Result, error) { return nil, errors.New("collection reached") }) req.Executor = executor req.Collector = collector _, err = RunBatchDetailed(context.Background(), req) if err == nil || err.Error() != "collection reached" { t.Fatalf("RunBatchDetailed() error = %v, want collection error", err) } if len(executor.promptRequests) != 3 || len(executor.profileRequests) != 1 { t.Fatalf("inspection calls = prompts %#v profiles %#v", executor.promptRequests, executor.profileRequests) } } func TestCopyBatchReportPathsLeavesUnreachedPathsEmpty(t *testing.T) { item := BatchReportResult{} copyBatchReportPaths(&item, &ReportResult{ DataPackagePath: "/runs/daily/data_package.yaml", PreparationPath: "/runs/daily/preparation.json", }) data, err := json.Marshal(item) if err != nil { t.Fatalf("Marshal() error = %v", err) } text := string(data) for _, omitted := range []string{"executionPath", "reportPath", "outputPath", "metadataPath", "notificationPath"} { if strings.Contains(text, omitted) { t.Fatalf("batch item includes unreached field %q:\n%s", omitted, text) } } if !strings.Contains(text, "dataPackagePath") || !strings.Contains(text, "preparationPath") { t.Fatalf("batch item omits reached paths:\n%s", text) } } type collectorFunc func(context.Context, collect.Request) (*collect.Result, error) func (f collectorFunc) Run(ctx context.Context, req collect.Request) (*collect.Result, error) { return f(ctx, req) } var _ Collector = collectorFunc(nil)