Route merge and normalization through core with domain migrations pending
This commit is contained in:
@@ -24,15 +24,15 @@ func NewTyped[T any](combine CombineFunc[T]) (*TypedMerger[T], error) {
|
||||
|
||||
func (m *TypedMerger[T]) Key() string { return Key }
|
||||
|
||||
func (m *TypedMerger[T]) Merge(ctx context.Context, req contracts.TypedMergeRequest[T]) (contracts.TypedMergeResult[T], error) {
|
||||
func (m *TypedMerger[T]) PrepareMerge(ctx context.Context, req contracts.MergeInput[T]) (contracts.PreparedOperation[T], error) {
|
||||
if m == nil || m.combine == nil {
|
||||
return contracts.TypedMergeResult[T]{}, mergerErrorf("merger must not be nil")
|
||||
return nil, mergerErrorf("merger must not be nil")
|
||||
}
|
||||
if ctx == nil {
|
||||
return contracts.TypedMergeResult[T]{}, mergerErrorf("context must not be nil")
|
||||
return nil, mergerErrorf("context must not be nil")
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return contracts.TypedMergeResult[T]{}, mergerErrorf("context error before merge: %w", err)
|
||||
return nil, mergerErrorf("context error before merge: %w", err)
|
||||
}
|
||||
values := make([]T, len(req.ExtractOutputs))
|
||||
for i, output := range req.ExtractOutputs {
|
||||
@@ -40,9 +40,9 @@ func (m *TypedMerger[T]) Merge(ctx context.Context, req contracts.TypedMergeRequ
|
||||
}
|
||||
value, err := m.combine(values)
|
||||
if err != nil {
|
||||
return contracts.TypedMergeResult[T]{}, mergerErrorf("combine values: %w", err)
|
||||
return nil, mergerErrorf("combine values: %w", err)
|
||||
}
|
||||
return contracts.TypedMergeResult[T]{Value: value}, nil
|
||||
return contracts.DeterministicOperation[T]{Evaluation: contracts.CandidateEvaluation[T]{Result: contracts.EvaluationView[T]{Candidate: &value}}}, nil
|
||||
}
|
||||
|
||||
func TypedModuleSpec(kind contracts.ArtifactKind) pipeline.ModuleSpec {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
)
|
||||
|
||||
func TestTypedMergerCombinesValuesInFrameworkOrder(t *testing.T) {
|
||||
@@ -19,7 +20,11 @@ func TestTypedMergerCombinesValuesInFrameworkOrder(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result, err := merger.Merge(context.Background(), contracts.TypedMergeRequest[string]{ExtractOutputs: []contracts.ExtractArtifact[string]{{ChunkIndex: 0, Value: "first"}, {ChunkIndex: 1, Value: "second"}}})
|
||||
result, err := pipeline.ExecuteOperation(context.Background(), pipeline.ExecutionContext[string]{Assess: func(context.Context, string) (contracts.CandidateAssessment, error) {
|
||||
return contracts.CandidateAssessment{}, nil
|
||||
}}, func(ctx context.Context) (contracts.PreparedOperation[string], error) {
|
||||
return merger.PrepareMerge(ctx, contracts.MergeInput[string]{ExtractOutputs: []contracts.ExtractArtifact[string]{{ChunkIndex: 0, Value: "first"}, {ChunkIndex: 1, Value: "second"}}})
|
||||
})
|
||||
if err != nil || result.Value != "firstsecond" {
|
||||
t.Fatalf("result=%#v err=%v", result, err)
|
||||
}
|
||||
@@ -35,16 +40,16 @@ func TestTypedMergerPropagatesApplicationErrorWithoutRetry(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result, err := merger.Merge(context.Background(), contracts.TypedMergeRequest[string]{
|
||||
Operation: contracts.ProducerOperation[string]{
|
||||
Controls: contracts.ProducerControls{Mode: contracts.ModePermissive, MaxAdditionalTurns: 3},
|
||||
Assess: func(context.Context, string) (contracts.CandidateAssessment, error) {
|
||||
t.Fatal("merger invoked assessment instead of returning its operation error")
|
||||
return contracts.CandidateAssessment{}, nil
|
||||
},
|
||||
result, err := pipeline.ExecuteOperation(context.Background(), pipeline.ExecutionContext[string]{
|
||||
Controls: contracts.ProducerControls{Mode: contracts.ModePermissive, MaxAdditionalTurns: 3},
|
||||
Assess: func(context.Context, string) (contracts.CandidateAssessment, error) {
|
||||
t.Fatal("merger invoked assessment instead of returning its operation error")
|
||||
return contracts.CandidateAssessment{}, nil
|
||||
},
|
||||
}, func(ctx context.Context) (contracts.PreparedOperation[string], error) {
|
||||
return merger.PrepareMerge(ctx, contracts.MergeInput[string]{})
|
||||
})
|
||||
if !errors.Is(err, failure) || calls != 1 || result.Outcome.Disposition != "" || result.Fallback != nil {
|
||||
if !errors.Is(err, failure) || calls != 1 || result.Outcome.Disposition != "" {
|
||||
t.Fatalf("Merge() = %#v, %v; combine calls = %d", result, err, calls)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user