Make production registration asset-free and verify direct deterministic execution
This commit is contained in:
@@ -2,6 +2,7 @@ package appendorder
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -23,3 +24,27 @@ func TestTypedMergerCombinesValuesInFrameworkOrder(t *testing.T) {
|
||||
t.Fatalf("result=%#v err=%v", result, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTypedMergerPropagatesApplicationErrorWithoutRetry(t *testing.T) {
|
||||
failure := errors.New("cannot combine these values")
|
||||
calls := 0
|
||||
merger, err := NewTyped(func([]string) (string, error) {
|
||||
calls++
|
||||
return "", failure
|
||||
})
|
||||
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
|
||||
},
|
||||
},
|
||||
})
|
||||
if !errors.Is(err, failure) || calls != 1 || result.Outcome.Disposition != "" || result.Fallback != nil {
|
||||
t.Fatalf("Merge() = %#v, %v; combine calls = %d", result, err, calls)
|
||||
}
|
||||
}
|
||||
|
||||
33
internal/modules/generic/normalize/noop/typed_test.go
Normal file
33
internal/modules/generic/normalize/noop/typed_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package noop
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
func TestTypedNormalizerReturnsIncomingValueForRunnerAssessment(t *testing.T) {
|
||||
value := []string{"second", "first", "first"}
|
||||
request := contracts.TypedNormalizeRequest[[]string]{
|
||||
MergeOutput: contracts.MergeArtifact[[]string]{Value: value},
|
||||
Operation: contracts.ProducerOperation[[]string]{
|
||||
Controls: contracts.ProducerControls{Mode: contracts.ModePermissive, MaxAdditionalTurns: 3},
|
||||
Assess: func(context.Context, []string) (contracts.CandidateAssessment, error) {
|
||||
t.Fatal("deterministic normalizer invoked the runner's assessor")
|
||||
return contracts.CandidateAssessment{}, nil
|
||||
},
|
||||
},
|
||||
}
|
||||
result, err := NewTyped[[]string]().Normalize(context.Background(), request)
|
||||
if err != nil || !reflect.DeepEqual(result.Value, value) || result.Outcome.Disposition != "" || result.Fallback != nil {
|
||||
t.Fatalf("Normalize() = %#v, %v; want unchanged value for direct runner assessment", result, err)
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
if _, err := NewTyped[[]string]().Normalize(ctx, request); !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("Normalize() after cancellation = %v", err)
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,7 @@ package register
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/llm"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/semanticreconcile"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/generic/chunk/units"
|
||||
jsonoutput "gitea.maximumdirect.net/eric/notarius/internal/modules/generic/output/json"
|
||||
alwaysaccept "gitea.maximumdirect.net/eric/notarius/internal/modules/generic/validate/always_accept"
|
||||
@@ -16,18 +14,14 @@ import (
|
||||
)
|
||||
|
||||
// Register adds all production domain-neutral modules and validators.
|
||||
func Register(registries pipeline.Registries, assets *llm.AssetRegistry) error {
|
||||
func Register(registries pipeline.Registries) error {
|
||||
if err := validateRegistries(registries); err != nil {
|
||||
return err
|
||||
}
|
||||
if assets == nil {
|
||||
return fmt.Errorf("generic registrar: asset registry must not be nil")
|
||||
}
|
||||
registrations := []struct {
|
||||
name string
|
||||
register func() error
|
||||
}{
|
||||
{name: "semantic reconciliation assets", register: func() error { return semanticreconcile.RegisterAssets(assets) }},
|
||||
{name: "generic chunker", register: func() error { return units.Register(registries.Chunkers) }},
|
||||
{name: "always accept validator", register: func() error { return alwaysaccept.Register(registries.Validators) }},
|
||||
{name: "always reject validator", register: func() error { return alwaysreject.Register(registries.Validators) }},
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
package register
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/llm"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
)
|
||||
|
||||
func TestRegisterAddsGenericFamily(t *testing.T) {
|
||||
registries := completeRegistries()
|
||||
assets := llm.NewAssetRegistry()
|
||||
if err := Register(registries, assets); err != nil {
|
||||
if err := Register(registries); err != nil {
|
||||
t.Fatalf("Register() error = %v, want nil", err)
|
||||
}
|
||||
assertContainsKeys(t, "chunkers", registries.Chunkers.RegisteredKeys(), []string{"generic"})
|
||||
@@ -33,31 +30,6 @@ func TestRegisterAddsGenericFamily(t *testing.T) {
|
||||
if output, err := registries.Outputs.Build("json"); err != nil || output.Key() != "json" {
|
||||
t.Fatalf("build json output = %v, %v; want json implementation", output, err)
|
||||
}
|
||||
promptAssets, err := assets.PromptFS()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := fs.ReadFile(promptAssets, "generic.semantic_reconciliation/prompt.yaml"); err != nil {
|
||||
t.Fatalf("registered semantic reconciliation prompt: %v", err)
|
||||
}
|
||||
schemaAssets, err := assets.SchemaFS()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := fs.ReadFile(schemaAssets, "semantic_reconciliation_llm.v1.json"); err != nil {
|
||||
t.Fatalf("registered semantic reconciliation schema: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterRejectsNilAssetRegistryBeforeMutation(t *testing.T) {
|
||||
registries := completeRegistries()
|
||||
err := Register(registries, nil)
|
||||
if err == nil || !strings.Contains(err.Error(), "asset registry must not be nil") {
|
||||
t.Fatalf("Register() error = %v, want nil asset registry error", err)
|
||||
}
|
||||
if len(registries.Chunkers.RegisteredKeys()) != 0 {
|
||||
t.Fatalf("chunker keys = %#v, want validation before mutation", registries.Chunkers.RegisteredKeys())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterRejectsMissingGenericRegistriesBeforeMutation(t *testing.T) {
|
||||
@@ -76,7 +48,7 @@ func TestRegisterRejectsMissingGenericRegistriesBeforeMutation(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
registries := completeRegistries()
|
||||
test.remove(®istries)
|
||||
err := Register(registries, llm.NewAssetRegistry())
|
||||
err := Register(registries)
|
||||
if err == nil || !strings.Contains(err.Error(), test.wantErr) {
|
||||
t.Fatalf("Register() error = %v, want %q", err, test.wantErr)
|
||||
}
|
||||
@@ -89,12 +61,11 @@ func TestRegisterRejectsMissingGenericRegistriesBeforeMutation(t *testing.T) {
|
||||
|
||||
func TestRegisterReportsDuplicateGenericRegistration(t *testing.T) {
|
||||
registries := completeRegistries()
|
||||
assets := llm.NewAssetRegistry()
|
||||
if err := Register(registries, assets); err != nil {
|
||||
if err := Register(registries); err != nil {
|
||||
t.Fatalf("first Register() error = %v, want nil", err)
|
||||
}
|
||||
err := Register(registries, assets)
|
||||
if err == nil || !strings.Contains(err.Error(), "register semantic reconciliation assets") || !strings.Contains(err.Error(), "already registered") {
|
||||
err := Register(registries)
|
||||
if err == nil || !strings.Contains(err.Error(), "register generic chunker") || !strings.Contains(err.Error(), "already registered") {
|
||||
t.Fatalf("second Register() error = %v, want contextual duplicate error", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user