Move NPC registry reconciliation into shared operations

This commit is contained in:
2026-11-25 15:55:49 +00:00
parent 987b9cb60f
commit bbb667b9b2
3 changed files with 80 additions and 128 deletions

View File

@@ -33,9 +33,6 @@ func TestModuleContractAndIdentity(t *testing.T) {
if err := Register(registry); err != nil {
t.Fatalf("Register() error = %v", err)
}
if _, err := New(nil, Options{}); err == nil {
t.Fatal("New(nil, Options{}) error = nil, want nil native engine rejection")
}
spec := ModuleSpec()
spec.Prompts[0] = "mutated"
if !reflect.DeepEqual(ModuleSpec(), want) {
@@ -132,7 +129,7 @@ func TestNormalizeHandlesNilAndCanceledCalls(t *testing.T) {
}
canceled, cancel := context.WithCancel(context.Background())
cancel()
if _, err := normalizer.Normalize(canceled, normalizeRequest(dnd.NPCRegistry{})); err == nil || !strings.Contains(err.Error(), "context error") {
if _, err := normalizer.Normalize(canceled, normalizeRequest(dnd.NPCRegistry{})); err == nil || !strings.Contains(err.Error(), "context canceled") {
t.Fatalf("canceled Normalize() error = %v", err)
}
}
@@ -168,7 +165,12 @@ func (c *recordingNPCNormalizerClient) Generate(ctx context.Context, request pro
return &promptkit.GenerateResponse{Content: response}, nil
}
func newNormalizer(t *testing.T, client promptkit.LLMClient) *Normalizer {
type normalizerFixture struct {
*Normalizer
engine *promptkit.Engine
}
func newNormalizer(t *testing.T, client promptkit.LLMClient) *normalizerFixture {
t.Helper()
type settings struct {
PromptKit promptkit.Settings `yaml:"promptkit"`
@@ -192,11 +194,20 @@ func newNormalizer(t *testing.T, client promptkit.LLMClient) *Normalizer {
if err != nil {
t.Fatal(err)
}
normalizer, err := New(engine, Options{})
normalizer, err := New(Options{})
if err != nil {
t.Fatal(err)
}
return normalizer
return &normalizerFixture{Normalizer: normalizer, engine: engine}
}
func (fixture *normalizerFixture) Normalize(ctx context.Context, req contracts.TypedNormalizeRequest[dnd.NPCRegistry]) (pipeline.OperationResult[dnd.NPCRegistry], error) {
op := req.Operation
execution := pipeline.ExecutionContext[dnd.NPCRegistry]{Engine: fixture.engine, Controls: op.Controls, Assess: op.Assess, Execution: op.Execution, ReuseEligible: op.ReuseEligible, Cache: op.Cache}
input := contracts.NormalizeInput[dnd.NPCRegistry]{Source: req.Source, LaneID: req.LaneID, MergeOutput: req.MergeOutput, SourceInput: req.SourceInput, SessionID: req.SessionID, References: req.References, LLMProfile: req.LLMProfile, Metadata: req.Metadata}
return pipeline.ExecuteOperation(ctx, execution, func(ctx context.Context) (contracts.PreparedOperation[dnd.NPCRegistry], error) {
return fixture.Normalizer.PrepareNormalize(ctx, input)
})
}
func renderedInput(t *testing.T, request promptkit.GenerateRequest, name string) []byte {