Preserve capture failures when a run is canceled

This commit is contained in:
2026-11-26 04:16:32 +00:00
parent cc3628e231
commit 5ffe22f5ac
4 changed files with 115 additions and 7 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"testing"
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
"go.maximumdirect.net/promptkit"
)
@@ -23,3 +24,27 @@ func TestRunErrorSelectionPreservesOperationalDeadlines(t *testing.T) {
t.Fatal(got)
}
}
func TestRunErrorSelectionRetainsOnlyCaptureBearingJobsOnCancellation(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
firstCause, extraCause, laterCause := errors.New("first capture"), errors.New("extra capture"), errors.New("later capture")
first := &contracts.CaptureError{Cause: firstCause}
later := &contracts.CaptureError{Cause: laterCause}
ordinary := errors.New("ordinary sibling failure")
got := selectRunError(ctx, []orderedRunError{
{stage: 2, lane: 0, err: later},
{stage: 0, lane: -1, err: ordinary},
{stage: 0, lane: 0, err: errors.Join(first, &contracts.CaptureError{Cause: extraCause})},
{stage: 0, lane: -2, err: context.Canceled},
})
for _, cause := range []error{context.Canceled, firstCause, extraCause, laterCause} {
if !errors.Is(got, cause) {
t.Fatalf("selected error %v lost cause %v", got, cause)
}
}
var captured *contracts.CaptureError
if !errors.As(got, &captured) || captured != first || errors.Is(got, ordinary) {
t.Fatalf("selected error %v changed canonical capture order or retained ordinary siblings", got)
}
}