Complete comparison failure summaries
This commit is contained in:
@@ -90,6 +90,11 @@ func CompareDetailed(ctx context.Context, req ComparisonRequest) (*ComparisonRes
|
||||
return nil, fmt.Errorf("build comparison identity: %w", err)
|
||||
}
|
||||
result := initialComparisonResult(req, resolved, comparisonID, now.UTC())
|
||||
defer func() {
|
||||
if result.FinishedAt.IsZero() {
|
||||
finalizeComparisonResult(result, clock)
|
||||
}
|
||||
}()
|
||||
|
||||
outputName, err := resolved.OutputName()
|
||||
if err != nil {
|
||||
@@ -99,11 +104,11 @@ func CompareDetailed(ctx context.Context, req ComparisonRequest) (*ComparisonRes
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
initialPlan, err := comparison.PlanDestination(req.WorkingDir, outputDirectory, req.Replace)
|
||||
result.OutputDirectory = outputDirectory
|
||||
_, err = comparison.PlanDestination(req.WorkingDir, outputDirectory, req.Replace)
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("preflight comparison destination: %w", err)
|
||||
}
|
||||
result.OutputDirectory = initialPlan.Target
|
||||
|
||||
debugWriter, err := promptdebug.NewPromptDebugWriter(req.LLMDebugDir)
|
||||
if err != nil {
|
||||
@@ -129,7 +134,7 @@ func CompareDetailed(ctx context.Context, req ComparisonRequest) (*ComparisonRes
|
||||
executed := executeComparisonProfiles(ctx, comparisonExecutionRequest{
|
||||
Prepared: prepared, Inspection: inspection, ComparisonID: comparisonID, DebugWriter: debugWriter, Executor: req.Executor,
|
||||
})
|
||||
result.FinishedAt = clock.Now().UTC()
|
||||
finalizeComparisonResult(result, clock)
|
||||
copyComparisonOutcomes(result, executed.Outcomes, false)
|
||||
if executed.Canceled {
|
||||
return result, fmt.Errorf("comparison execution: %w", ctx.Err())
|
||||
@@ -160,6 +165,17 @@ func CompareDetailed(ctx context.Context, req ComparisonRequest) (*ComparisonRes
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func finalizeComparisonResult(result *ComparisonResult, clock timeutil.Clock) {
|
||||
finishedAt := clock.Now().UTC()
|
||||
if finishedAt.IsZero() {
|
||||
finishedAt = time.Unix(0, 1).UTC()
|
||||
}
|
||||
if finishedAt.Before(result.StartedAt) {
|
||||
finishedAt = result.StartedAt
|
||||
}
|
||||
result.FinishedAt = finishedAt
|
||||
}
|
||||
|
||||
func initialComparisonResult(req ComparisonRequest, resolved report.Resolved, comparisonID string, startedAt time.Time) *ComparisonResult {
|
||||
metadata := resolved.Metadata()
|
||||
return &ComparisonResult{
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/comparison"
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/config"
|
||||
@@ -130,6 +131,78 @@ func TestCompareDetailedPreflightsBeforePromptOrCollection(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompareDetailedFinalizesUnpublishedFailures(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
prepare func(t *testing.T, outputDirectory string)
|
||||
debugDir string
|
||||
executor *generationExecutor
|
||||
collector *generationCollector
|
||||
wantPrompt bool
|
||||
}{
|
||||
{
|
||||
name: "destination preflight",
|
||||
prepare: func(t *testing.T, outputDirectory string) {
|
||||
t.Helper()
|
||||
if err := os.WriteFile(outputDirectory, []byte("not a directory"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
},
|
||||
executor: &generationExecutor{},
|
||||
},
|
||||
{
|
||||
name: "debug initialization",
|
||||
debugDir: "relative-debug-directory",
|
||||
executor: &generationExecutor{},
|
||||
collector: &generationCollector{},
|
||||
},
|
||||
{
|
||||
name: "prompt preflight",
|
||||
executor: &generationExecutor{inspectErr: promptexec.NewError(promptexec.PromptLoad, "unsafe prompt detail", errors.New("unsafe cause"))},
|
||||
collector: &generationCollector{},
|
||||
wantPrompt: false,
|
||||
},
|
||||
{
|
||||
name: "collection",
|
||||
executor: &generationExecutor{},
|
||||
collector: &generationCollector{err: errors.New("collection failed")},
|
||||
wantPrompt: true,
|
||||
},
|
||||
{
|
||||
name: "preparation",
|
||||
executor: &generationExecutor{},
|
||||
collector: &generationCollector{bundle: &weatherdata.Bundle{}},
|
||||
wantPrompt: true,
|
||||
},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
workingDirectory := t.TempDir()
|
||||
outputDirectory := filepath.Join(workingDirectory, "comparison-output")
|
||||
if test.prepare != nil {
|
||||
test.prepare(t, outputDirectory)
|
||||
}
|
||||
collector := test.collector
|
||||
if collector == nil {
|
||||
bundle := generationBundle(t)
|
||||
collector = &generationCollector{bundle: &bundle}
|
||||
}
|
||||
result, err := CompareDetailed(context.Background(), ComparisonRequest{
|
||||
Config: comparisonConfig(), Report: ReportDaily, ProfileIDs: []string{"weather-light", "weather-deep"},
|
||||
WorkingDir: workingDirectory, OutputDir: outputDirectory, LLMDebugDir: test.debugDir,
|
||||
Date: generationTime("2026-05-29T12:00:00-05:00"), Clock: timeutil.FixedClock{Time: generationTime("2026-05-29T08:30:00-05:00")},
|
||||
Collector: collector, Executor: test.executor,
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("CompareDetailed() error = nil")
|
||||
}
|
||||
assertUnpublishedComparisonResult(t, result, outputDirectory)
|
||||
if (result.PromptID != "") != test.wantPrompt || (result.PromptHash != "") != test.wantPrompt {
|
||||
t.Fatalf("prompt identity = %q/%q, want resolved=%t", result.PromptID, result.PromptHash, test.wantPrompt)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompareDetailedLeavesDestinationWhenCollectionOrPreparationFails(t *testing.T) {
|
||||
collectionErr := errors.New("weather collection failed")
|
||||
for _, test := range []struct {
|
||||
@@ -233,3 +306,15 @@ func comparisonConfig() config.Config {
|
||||
cfg.WeatherAPI.Timezone, cfg.Location.ID = "America/Chicago", "home"
|
||||
return cfg
|
||||
}
|
||||
|
||||
func assertUnpublishedComparisonResult(t *testing.T, result *ComparisonResult, outputDirectory string) {
|
||||
t.Helper()
|
||||
if result == nil || result.OutputDirectory != outputDirectory || !filepath.IsAbs(result.OutputDirectory) || result.FinishedAt.IsZero() || result.FinishedAt.Location() != time.UTC || result.FinishedAt.Before(result.StartedAt) || result.ManifestPath != "" || result.DataPackagePath != "" {
|
||||
t.Fatalf("unpublished comparison result = %#v", result)
|
||||
}
|
||||
for _, profile := range result.Results {
|
||||
if profile.ReportPath != "" {
|
||||
t.Fatalf("unpublished profile result = %#v", profile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user