86 lines
3.1 KiB
Go
86 lines
3.1 KiB
Go
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) {
|
|
tests := []struct {
|
|
name string
|
|
batch BatchKind
|
|
now string
|
|
wantPrompts int
|
|
}{
|
|
{name: "morning", batch: BatchMorning, now: "2026-05-29T08:00:00-05:00", wantPrompts: 3},
|
|
{name: "evening", batch: BatchEvening, now: "2026-05-29T18:00:00-05:00", wantPrompts: 2},
|
|
}
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
cfg := config.Defaults()
|
|
cfg.Workspace.Root = t.TempDir()
|
|
now := mustParse(test.now)
|
|
req := BatchRequest{Config: cfg, Batch: test.batch, Now: now, WorkingDir: t.TempDir()}
|
|
candidates, err := batchInspectionCandidates(req, now)
|
|
if err != nil {
|
|
t.Fatalf("batchInspectionCandidates() error = %v", err)
|
|
}
|
|
executor := &inspectionExecutor{profiles: map[string]promptexec.ProfileInspection{
|
|
"weather-balanced": {ProfileID: "weather-balanced", BackendID: "openrouter", ModelName: "~google/gemini-flash-latest"},
|
|
}, prompts: map[string]promptexec.PromptInspection{}}
|
|
for _, candidate := range candidates {
|
|
executor.prompts[candidate.Definition.PromptID] = logicalPromptInspection(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) != test.wantPrompts || len(executor.profileRequests) != 1 || executor.profileRequests[0] != "weather-balanced" {
|
|
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)
|