Complete comparison failure summaries
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -135,3 +136,76 @@ func TestComparisonSummaryClassifiesCompleteAndAllFailedResults(t *testing.T) {
|
||||
t.Fatalf("all-failed summary = %#v", summary)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSafeComparisonSummaryErrorClassifiesWrappedFailures(t *testing.T) {
|
||||
unsafeDetail := "unsafe filesystem and provider detail"
|
||||
unsafeCause := errors.New(unsafeDetail)
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
err error
|
||||
category string
|
||||
message string
|
||||
}{
|
||||
{
|
||||
name: "aggregate profile failure",
|
||||
err: fmt.Errorf("outer wrapper: %w", errors.New("comparison completed with 2 failed profiles")),
|
||||
category: "application",
|
||||
message: "comparison completed with 2 failed profiles",
|
||||
},
|
||||
{
|
||||
name: "canceled",
|
||||
err: fmt.Errorf("outer wrapper: %w", context.Canceled),
|
||||
category: "canceled",
|
||||
message: "comparison canceled",
|
||||
},
|
||||
{
|
||||
name: "deadline exceeded",
|
||||
err: fmt.Errorf("outer wrapper: %w", context.DeadlineExceeded),
|
||||
category: "deadline_exceeded",
|
||||
message: "comparison deadline exceeded",
|
||||
},
|
||||
{
|
||||
name: "prompt operation",
|
||||
err: fmt.Errorf("outer wrapper: %w", promptexec.NewError(promptexec.Generation, "unsafe prompt detail", fmt.Errorf("%w: %s", context.Canceled, unsafeDetail))),
|
||||
category: string(promptexec.Generation),
|
||||
message: "comparison prompt operation failed",
|
||||
},
|
||||
{
|
||||
name: "destination preflight",
|
||||
err: fmt.Errorf("outer wrapper: %w", &comparison.DestinationError{
|
||||
Kind: comparison.DestinationNotEmpty, Target: "/tmp/" + unsafeDetail, Err: fmt.Errorf("%w: %s", context.Canceled, unsafeDetail),
|
||||
}),
|
||||
category: "destination_not_empty",
|
||||
message: "comparison destination preflight failed",
|
||||
},
|
||||
{
|
||||
name: "publication cleanup",
|
||||
err: fmt.Errorf("outer wrapper: %w", &comparison.PublicationCleanupError{
|
||||
RetainedBackupPath: "/tmp/" + unsafeDetail, Err: fmt.Errorf("%w: %s", context.Canceled, unsafeDetail),
|
||||
}),
|
||||
category: "publication_cleanup",
|
||||
message: "comparison published but cleanup did not complete",
|
||||
},
|
||||
{
|
||||
name: "unknown",
|
||||
err: fmt.Errorf("outer wrapper: %w", unsafeCause),
|
||||
category: "application",
|
||||
message: "comparison did not complete",
|
||||
},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
result := &app.ComparisonResult{ComparisonID: "comparison_test", ReportID: report.Daily}
|
||||
summary := newComparisonSummary(result, test.err)
|
||||
if summary.Error == nil || summary.Error.Category != test.category || summary.Error.Message != test.message {
|
||||
t.Fatalf("summary error = %#v, want %q/%q", summary.Error, test.category, test.message)
|
||||
}
|
||||
data, err := json.Marshal(summary)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(string(data), unsafeDetail) {
|
||||
t.Fatalf("summary includes unsafe detail: %s", data)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user