Complete the core operation execution cutover

This commit is contained in:
2026-11-25 16:17:59 +00:00
parent b6a3638d70
commit 7d96c69a32
73 changed files with 891 additions and 1065 deletions

View File

@@ -255,7 +255,7 @@ func TestExtractRejectsInvalidRequestsAndProviderFailures(t *testing.T) {
name string
extractor *extractionFixture
ctx context.Context
req contracts.TypedExtractionRequest[dnd.NPCOccurrenceList]
req extractionTestInput
want string
}{
{"nil extractor", nilExtractor, context.Background(), valid, "extractor"},

View File

@@ -23,7 +23,7 @@ func operationReferences(t *testing.T) (contracts.ReferenceSet, string) {
return requiredRegistryReferences(t, "Mira Thorn"), identity.DeriveID("Mira Thorn")
}
func sourceAssessment(ctx context.Context, request contracts.TypedExtractionRequest[dnd.NPCOccurrenceList], value dnd.NPCOccurrenceList) (contracts.CandidateAssessment, error) {
func sourceAssessment(ctx context.Context, request extractionTestInput, value dnd.NPCOccurrenceList) (contracts.CandidateAssessment, error) {
validator := refs.New(refs.Options{})
result, err := validator.Validate(ctx, contracts.TypedValidationRequest[dnd.NPCOccurrenceList]{Stage: "extract", Source: request.Source, Chunk: request.Chunk, Value: value})
if err != nil {
@@ -41,14 +41,14 @@ func TestNativeCorrectionKeepsRegistryResolutionAndInputsFixed(t *testing.T) {
request := extractionRequest()
references, expectedID := operationReferences(t)
request.References = references
request.Operation.Controls.MaxAdditionalTurns = 1
request.Execution.Controls.MaxAdditionalTurns = 1
// Accepted work consuming an ineligible generated reference stays ineligible.
request.Operation.ReuseEligible = false
request.Operation.Execution.Execution = &promptkit.ExecutionTargetOverride{Model: "occurrence-override"}
request.Execution.ReuseEligible = false
request.Execution.Execution.Execution = &promptkit.ExecutionTargetOverride{Model: "occurrence-override"}
var prepared []promptkit.PreparedRun
request.Operation.Execution.OnPrepared = func(_ context.Context, value promptkit.PreparedRun) { prepared = append(prepared, value) }
request.Execution.Execution.OnPrepared = func(_ context.Context, value promptkit.PreparedRun) { prepared = append(prepared, value) }
assessments := 0
request.Operation.Assess = func(ctx context.Context, value dnd.NPCOccurrenceList) (contracts.CandidateAssessment, error) {
request.Execution.Assess = func(ctx context.Context, value dnd.NPCOccurrenceList) (contracts.CandidateAssessment, error) {
assessments++
return sourceAssessment(ctx, request, value)
}
@@ -118,11 +118,11 @@ func TestNativeOccurrenceFallbackIsAnExplicitEmptyList(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
request := extractionRequest()
request.References, _ = operationReferences(t)
request.Operation.Controls.Mode = test.mode
request.Operation.Controls.MaxAdditionalTurns = 1
request.Execution.Controls.Mode = test.mode
request.Execution.Controls.MaxAdditionalTurns = 1
assessments, prepared := 0, 0
request.Operation.Execution.OnPrepared = func(context.Context, promptkit.PreparedRun) { prepared++ }
request.Operation.Assess = func(ctx context.Context, value dnd.NPCOccurrenceList) (contracts.CandidateAssessment, error) {
request.Execution.Execution.OnPrepared = func(context.Context, promptkit.PreparedRun) { prepared++ }
request.Execution.Assess = func(ctx context.Context, value dnd.NPCOccurrenceList) (contracts.CandidateAssessment, error) {
assessments++
return sourceAssessment(ctx, request, value)
}
@@ -152,7 +152,7 @@ func TestCanceledOccurrenceDeliveryCannotConstructFallback(t *testing.T) {
defer cancel()
request := extractionRequest()
request.References, _ = operationReferences(t)
request.Operation.Controls.Mode = contracts.ModePermissive
request.Execution.Controls.Mode = contracts.ModePermissive
client := &fakeOccurrencesLLMClient{raw: knownOccurrence, onGenerate: func(context.Context, promptkit.GenerateRequest) { cancel() }}
result, err := runExtraction(ctx, newExtractor(t, client, request.References), request)
if !errors.Is(err, context.Canceled) || result.Outcome.Disposition != "" || len(client.requests) != 1 {

View File

@@ -12,8 +12,6 @@ import (
occurrencecodec "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/codec/npcoccurrences"
npccodec "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/codec/npcregistry"
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/npcs/identity"
"gitea.maximumdirect.net/eric/notarius/internal/modules/generic/merge/appendorder"
"gitea.maximumdirect.net/eric/notarius/internal/modules/generic/normalize/noop"
)
type generatedInput struct{ document *source.SourceDocument }
@@ -43,6 +41,30 @@ func (generatedRegistry) PrepareExtraction(_ context.Context, input contracts.Ex
type generatedOutput struct{ outputs *[]contracts.SerializedOutput }
type generatedMerger[T any] struct{}
func (generatedMerger[T]) Key() string { return "generated/merge" }
func (generatedMerger[T]) PrepareMerge(_ context.Context, input contracts.MergeInput[T]) (contracts.PreparedOperation[T], error) {
value := input.ExtractOutputs[0].Value
return contracts.DeterministicOperation[T]{Evaluation: contracts.CandidateEvaluation[T]{Result: contracts.EvaluationView[T]{Candidate: &value}}}, nil
}
type generatedNormalizer[T any] struct{}
func (generatedNormalizer[T]) Key() string { return "generated/normalize" }
func (generatedNormalizer[T]) ReferenceSlots() []contracts.ReferenceSlot { return nil }
func (generatedNormalizer[T]) PrepareNormalize(_ context.Context, input contracts.NormalizeInput[T]) (contracts.PreparedOperation[T], error) {
value := input.MergeOutput.Value
return contracts.DeterministicOperation[T]{Evaluation: contracts.CandidateEvaluation[T]{Result: contracts.EvaluationView[T]{Candidate: &value}}}, nil
}
func registerGeneratedLane[T any](catalog pipeline.ModuleCatalog, kind contracts.ArtifactKind) error {
if err := pipeline.RegisterMerger(catalog.Mergers, pipeline.ModuleSpec{Key: "generated/merge", Stage: pipeline.StageMerge, ArtifactKind: kind, ExecutionClass: contracts.ExecutionClassDeterministic, Provides: []string{"merged"}}, func() (contracts.Merger[T], error) { return generatedMerger[T]{}, nil }); err != nil {
return err
}
return pipeline.RegisterNormalizer(catalog.Normalizers, pipeline.ModuleSpec{Key: "generated/normalize", Stage: pipeline.StageNormalize, ArtifactKind: kind, ExecutionClass: contracts.ExecutionClassDeterministic, Requires: []string{"merged"}, Provides: []string{"normalized"}}, func() (contracts.Normalizer[T], error) { return generatedNormalizer[T]{}, nil })
}
func (generatedOutput) Key() string { return "generated/output" }
func (output generatedOutput) Encode(_ context.Context, request contracts.OutputRequest) (contracts.OutputResult, error) {
*output.outputs = request.NormalizeOutputs
@@ -74,15 +96,13 @@ func TestRegisteredOccurrenceExtractionUsesGeneratedRegistry(t *testing.T) {
check(pipeline.RegisterArtifactCodec(catalog.ArtifactCodecs, occurrencecodec.New()))
check(pipeline.RegisterExtractor(catalog.Extractors, pipeline.ModuleSpec{Key: "generated/registry", Stage: pipeline.StageExtract, ArtifactKind: dnd.NPCRegistryKind, ExecutionClass: contracts.ExecutionClassDeterministic, Requires: []string{"chunks"}, Provides: []string{"extracted"}}, func() (contracts.Extractor[dnd.NPCRegistry], error) { return generatedRegistry{}, nil }))
check(Register(catalog.Extractors))
check(appendorder.RegisterTyped(catalog.Mergers, dnd.NPCRegistryKind, func(values []dnd.NPCRegistry) (dnd.NPCRegistry, error) { return values[0], nil }))
check(appendorder.RegisterTyped(catalog.Mergers, dnd.NPCOccurrenceListKind, func(values []dnd.NPCOccurrenceList) (dnd.NPCOccurrenceList, error) { return values[0], nil }))
check(noop.RegisterTyped[dnd.NPCRegistry](catalog.Normalizers, dnd.NPCRegistryKind))
check(noop.RegisterTyped[dnd.NPCOccurrenceList](catalog.Normalizers, dnd.NPCOccurrenceListKind))
check(registerGeneratedLane[dnd.NPCRegistry](catalog, dnd.NPCRegistryKind))
check(registerGeneratedLane[dnd.NPCOccurrenceList](catalog, dnd.NPCOccurrenceListKind))
var outputs []contracts.SerializedOutput
check(catalog.Outputs.RegisterWithSpec(pipeline.ModuleSpec{Key: "generated/output", Stage: pipeline.StageOutput, ExecutionClass: contracts.ExecutionClassDeterministic}, func() (contracts.OutputEncoder, error) { return generatedOutput{&outputs}, nil }))
profile := pipeline.PipelineProfile{ID: "generated", Input: pipeline.Binding("generated/input"), Chunk: pipeline.Binding("generated/chunk"), Output: pipeline.Binding("generated/output"), LLMProfile: "profile-npc-occurrences", Steps: []pipeline.PipelineStepProfile{
{ID: "build", Artifacts: map[string]pipeline.ArtifactLaneProfile{"registry": {Extract: pipeline.Binding("generated/registry"), Merge: pipeline.Binding(appendorder.Key), Normalize: pipeline.Binding(noop.Key)}}},
{ID: "consume", Artifacts: map[string]pipeline.ArtifactLaneProfile{"occurrences": {Extract: pipeline.ModuleBinding{Module: Key, References: map[string]pipeline.ReferenceSource{NPCRegistryReferenceSlot: pipeline.GeneratedReference("build", "registry")}}, Merge: pipeline.Binding(appendorder.Key), Normalize: pipeline.Binding(noop.Key)}}},
{ID: "build", Artifacts: map[string]pipeline.ArtifactLaneProfile{"registry": {Extract: pipeline.Binding("generated/registry"), Merge: pipeline.Binding("generated/merge"), Normalize: pipeline.Binding("generated/normalize")}}},
{ID: "consume", Artifacts: map[string]pipeline.ArtifactLaneProfile{"occurrences": {Extract: pipeline.ModuleBinding{Module: Key, References: map[string]pipeline.ReferenceSource{NPCRegistryReferenceSlot: pipeline.GeneratedReference("build", "registry")}}, Merge: pipeline.Binding("generated/merge"), Normalize: pipeline.Binding("generated/normalize")}}},
}}
resolved, err := pipeline.ResolvePipeline(profile, pipeline.ResolveOptions{}, catalog)
check(err)

View File

@@ -19,7 +19,7 @@ import (
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/npcs/identity"
)
func extractionRequest() contracts.TypedExtractionRequest[dnd.NPCOccurrenceList] {
func extractionRequest() extractionTestInput {
doc := sourceDocument()
chunk := &source.Chunk{
ID: "session-alpha:chunk:0", SourceID: doc.ID, Index: 0,
@@ -27,11 +27,11 @@ func extractionRequest() contracts.TypedExtractionRequest[dnd.NPCOccurrenceList]
Content: []byte(`{"units":[10,2,7,5,20,30]}`), MediaType: "application/json",
Units: append([]source.SourceUnit(nil), doc.Units...),
}
return contracts.TypedExtractionRequest[dnd.NPCOccurrenceList]{
return extractionTestInput{
Source: doc, Chunk: chunk,
SourceInput: contracts.NewLLMInputMaterial("source", chunk.MediaType, chunk.Content, "sha256:chunk", "file:///session-alpha.json"),
SessionID: "session-123", LLMProfile: "profile-npc-occurrences",
Operation: contracts.ProducerOperation[dnd.NPCOccurrenceList]{Controls: contracts.ProducerControls{Mode: contracts.ModeStrict, Cache: contracts.CacheBypass}, ReuseEligible: true, Assess: func(context.Context, dnd.NPCOccurrenceList) (contracts.CandidateAssessment, error) {
Execution: pipeline.ExecutionContext[dnd.NPCOccurrenceList]{Controls: contracts.ProducerControls{Mode: contracts.ModeStrict, Cache: contracts.CacheBypass}, ReuseEligible: true, Assess: func(context.Context, dnd.NPCOccurrenceList) (contracts.CandidateAssessment, error) {
return contracts.CandidateAssessment{}, nil
}},
}
@@ -92,11 +92,23 @@ func occurrenceKinds(value dnd.NPCOccurrenceList) []dnd.NPCOccurrenceKind {
return kinds
}
func mismatchedSourceInputRequest(req contracts.TypedExtractionRequest[dnd.NPCOccurrenceList]) contracts.TypedExtractionRequest[dnd.NPCOccurrenceList] {
func mismatchedSourceInputRequest(req extractionTestInput) extractionTestInput {
req.SourceInput = contracts.NewLLMInputMaterial("source", "application/json", []byte(`{"different":true}`), "sha256:other", "")
return req
}
type extractionTestInput struct {
Source *source.SourceDocument
Chunk *source.Chunk
AmbientContext map[string]any
SourceInput contracts.LLMInputMaterial
SessionID string
References contracts.ReferenceSet
LLMProfile string
Metadata map[string]any
Execution pipeline.ExecutionContext[dnd.NPCOccurrenceList]
}
type extractionFixture struct {
*Extractor
engine *promptkit.Engine
@@ -133,13 +145,13 @@ func newExtractor(t *testing.T, client promptkit.LLMClient, references ...contra
return &extractionFixture{Extractor: extractor, engine: engine}
}
func runExtraction(ctx context.Context, fixture *extractionFixture, req contracts.TypedExtractionRequest[dnd.NPCOccurrenceList]) (pipeline.OperationResult[dnd.NPCOccurrenceList], error) {
func runExtraction(ctx context.Context, fixture *extractionFixture, req extractionTestInput) (pipeline.OperationResult[dnd.NPCOccurrenceList], error) {
var extractor *Extractor
var engine *promptkit.Engine
if fixture != nil {
extractor, engine = fixture.Extractor, fixture.engine
}
op := req.Operation
op := req.Execution
execution := pipeline.ExecutionContext[dnd.NPCOccurrenceList]{Engine: engine, Controls: op.Controls, Assess: op.Assess, Execution: op.Execution, ReuseEligible: op.ReuseEligible, Cache: op.Cache}
input := contracts.ExtractionInput{Source: req.Source, Chunk: req.Chunk, SourceInput: req.SourceInput, SessionID: req.SessionID, References: req.References, LLMProfile: req.LLMProfile, Metadata: req.Metadata, AmbientContext: req.AmbientContext}
return pipeline.ExecuteOperation(ctx, execution, func(ctx context.Context) (contracts.PreparedOperation[dnd.NPCOccurrenceList], error) {