Define typed producer assessment and native execution dependencies

This commit is contained in:
2026-11-21 23:12:01 +00:00
parent b899ee32a6
commit 797320b4da
23 changed files with 657 additions and 707 deletions

View File

@@ -32,67 +32,41 @@ func TestValidateModuleSpecRequiresSupportedExecutionClass(t *testing.T) {
}
}
func TestCloneModuleSpecPreservesCorrectionProtocol(t *testing.T) {
spec := normalizeModuleSpec(ModuleSpec{
Key: " module ",
Stage: StageChunk,
ExecutionClass: contracts.ExecutionClassLLMBacked,
CorrectionProtocol: " single_response_v1 ",
})
if spec.CorrectionProtocol != contracts.CorrectionProtocolSingleResponseV1 {
t.Fatalf("normalized CorrectionProtocol = %q, want %q", spec.CorrectionProtocol, contracts.CorrectionProtocolSingleResponseV1)
func TestModuleSpecRetainsDetachedStaticPromptDependencies(t *testing.T) {
const initial = "notarius/test.initial"
const correction = "notarius/test.correction"
prompts := []string{correction, initial}
registry := NewExtractorRegistry()
if err := RegisterExtractor(registry, ModuleSpec{Key: "producer", Stage: StageExtract, ExecutionClass: contracts.ExecutionClassLLMBacked, ArtifactKind: "test/value", Prompts: prompts}, func() (contracts.Extractor[collaborationValue], error) { return &collaborationProducer{}, nil }); err != nil {
t.Fatal(err)
}
cloned := cloneModuleSpec(spec)
if !reflect.DeepEqual(cloned, spec) {
t.Fatalf("cloneModuleSpec() = %#v, want %#v", cloned, spec)
prompts[0] = "changed"
spec, ok := registry.Spec("producer")
if !ok || !reflect.DeepEqual(spec.Prompts, []string{correction, initial}) {
t.Fatalf("static dependencies = %#v", spec.Prompts)
}
spec.Prompts[0] = "also changed"
again, _ := registry.Spec("producer")
if !reflect.DeepEqual(again.Prompts, []string{correction, initial}) {
t.Fatalf("registry declarations mutated: %#v", again.Prompts)
}
}
func TestValidateModuleSpecCorrectionProtocolEligibility(t *testing.T) {
tests := []struct {
name string
stage ModuleStage
class contracts.ExecutionClass
protocol contracts.CorrectionProtocol
want string
}{
{name: "LLM chunk", stage: StageChunk, class: contracts.ExecutionClassLLMBacked, protocol: contracts.CorrectionProtocolSingleResponseV1},
{name: "LLM extract", stage: StageExtract, class: contracts.ExecutionClassLLMBacked, protocol: contracts.CorrectionProtocolSingleResponseV1},
{name: "LLM merge", stage: StageMerge, class: contracts.ExecutionClassLLMBacked, protocol: contracts.CorrectionProtocolSingleResponseV1},
{name: "LLM normalize", stage: StageNormalize, class: contracts.ExecutionClassLLMBacked, protocol: contracts.CorrectionProtocolSingleResponseV1},
{name: "deterministic chunk", stage: StageChunk, class: contracts.ExecutionClassDeterministic, protocol: contracts.CorrectionProtocolSingleResponseV1, want: "LLM-backed"},
{name: "input", stage: StageInput, class: contracts.ExecutionClassLLMBacked, protocol: contracts.CorrectionProtocolSingleResponseV1, want: "not supported"},
{name: "output", stage: StageOutput, class: contracts.ExecutionClassLLMBacked, protocol: contracts.CorrectionProtocolSingleResponseV1, want: "not supported"},
{name: "unknown protocol", stage: StageChunk, class: contracts.ExecutionClassLLMBacked, protocol: "unsupported", want: "unsupported correction protocol"},
func TestValidatorSpecRetainsDetachedPromptDependencies(t *testing.T) {
prompts := []string{"notarius/assessment"}
registry := NewValidatorRegistry()
if err := RegisterTypedValidator(registry, "test/value", ValidatorSpec{Key: "assessment", ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: prompts}, func() (contracts.TypedValidator[collaborationValue], error) { return collaborationValidator{}, nil }); err != nil {
t.Fatal(err)
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
spec := normalizeModuleSpec(ModuleSpec{
Key: "module",
Stage: test.stage,
ExecutionClass: test.class,
CorrectionProtocol: test.protocol,
})
err := validateModuleSpec("module", test.stage, spec)
if test.want == "" && err != nil {
t.Fatalf("validateModuleSpec() error = %v, want nil", err)
}
if test.want != "" && (err == nil || !strings.Contains(err.Error(), test.want)) {
t.Fatalf("validateModuleSpec() error = %v, want %q", err, test.want)
}
})
prompts[0] = "changed"
spec, ok := registry.Spec("assessment")
if !ok || !reflect.DeepEqual(spec.Prompts, []string{"notarius/assessment"}) {
t.Fatalf("validator dependencies = %#v", spec.Prompts)
}
}
func TestNormalizeValidatorSpecRejectsCorrectionProtocol(t *testing.T) {
_, err := normalizeValidatorSpec(ValidatorSpec{
Key: "validator",
ExecutionClass: contracts.ExecutionClassLLMBacked,
CorrectionProtocol: contracts.CorrectionProtocolSingleResponseV1,
})
if err == nil || !strings.Contains(err.Error(), "correction protocol") {
t.Fatalf("normalizeValidatorSpec() error = %v, want correction protocol error", err)
spec.Prompts[0] = "also changed"
again, _ := registry.Spec("assessment")
if !reflect.DeepEqual(again.Prompts, []string{"notarius/assessment"}) {
t.Fatalf("validator declarations mutated: %#v", again.Prompts)
}
}