Make production registration asset-free and verify direct deterministic execution
This commit is contained in:
81
internal/modules/dnd/register/dependencies_test.go
Normal file
81
internal/modules/dnd/register/dependencies_test.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package register
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/assets"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
"go.maximumdirect.net/configkit"
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
func TestRegisteredDependenciesUseNativeEmbeddedPrompts(t *testing.T) {
|
||||
registries := completeRegistries()
|
||||
if err := Register(registries); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
type document struct {
|
||||
PromptKit promptkit.Settings `yaml:"promptkit"`
|
||||
}
|
||||
filesystem := configkit.NewFilesystem("Notarius assets", assets.FS())
|
||||
definition := promptkit.Configure(configkit.Definition[document]{}, func(value *document) *promptkit.Settings { return &value.PromptKit })
|
||||
result, err := configkit.LoadLayered(configkit.Input{Source: configkit.NoSource()}, configkit.LayeredOptions[document]{
|
||||
Definition: definition,
|
||||
Underlays: []configkit.Underlay{
|
||||
promptkit.BundledOpenRouterUnderlay(),
|
||||
{Inputs: []configkit.Input{{
|
||||
Source: filesystem.File("notarius.yml"), Imports: true,
|
||||
Filesystem: &configkit.FilesystemContext{FS: &filesystem, Root: "."},
|
||||
}}},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
engine, err := promptkit.NewFromConfig(result, promptkit.RuntimeConfig{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
checkPrompts := func(key string, class contracts.ExecutionClass, ids []string, expected int) {
|
||||
t.Helper()
|
||||
if class == contracts.ExecutionClassDeterministic {
|
||||
expected = 0
|
||||
}
|
||||
if len(ids) != expected {
|
||||
t.Fatalf("%s declares %v; want %d static prompt dependencies", key, ids, expected)
|
||||
}
|
||||
for _, id := range ids {
|
||||
if _, err := engine.InspectPrompt(context.Background(), id); err != nil {
|
||||
t.Fatalf("%s prompt %s: %v", key, id, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, key := range registries.Chunkers.RegisteredKeys() {
|
||||
spec, ok := registries.Chunkers.Spec(key)
|
||||
if !ok {
|
||||
t.Fatalf("missing chunker spec %s", key)
|
||||
}
|
||||
checkPrompts(key, spec.ExecutionClass, spec.Prompts, 2)
|
||||
}
|
||||
for _, key := range registries.Extractors.RegisteredKeys() {
|
||||
spec, ok := registries.Extractors.Spec(key)
|
||||
if !ok {
|
||||
t.Fatalf("missing extractor spec %s", key)
|
||||
}
|
||||
checkPrompts(key, spec.ExecutionClass, spec.Prompts, 2)
|
||||
}
|
||||
for _, key := range registries.Normalizers.RegisteredKeys() {
|
||||
for _, kind := range registries.Normalizers.RegisteredArtifactKinds(key) {
|
||||
spec, ok := registries.Normalizers.SpecForArtifact(key, kind)
|
||||
if !ok {
|
||||
t.Fatalf("missing normalizer spec %s/%s", key, kind)
|
||||
}
|
||||
checkPrompts(key, spec.ExecutionClass, spec.Prompts, 2)
|
||||
}
|
||||
}
|
||||
for _, spec := range registries.Validators.RegisteredSpecs() {
|
||||
checkPrompts(spec.Key, spec.ExecutionClass, spec.Prompts, 1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user