Make composition and boundary tests extension-friendly
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/llm"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/extract/spells"
|
||||
)
|
||||
|
||||
@@ -19,12 +20,10 @@ func TestRegisterAddsDNDFamily(t *testing.T) {
|
||||
if err := Register(registries, assets); err != nil {
|
||||
t.Fatalf("Register() error = %v, want nil", err)
|
||||
}
|
||||
assertKeys(t, "chunkers", registries.Chunkers.RegisteredKeys(), []string{"dnd/scenes"})
|
||||
assertKeys(t, "extractors", registries.Extractors.RegisteredKeys(), []string{"dnd/spells"})
|
||||
if got := registries.ArtifactCodecs.RegisteredKinds(); !reflect.DeepEqual(got, []contracts.ArtifactKind{"dnd/spell-list"}) {
|
||||
t.Fatalf("artifact codec kinds = %#v, want dnd/spell-list", got)
|
||||
}
|
||||
assertKeys(t, "validators", registries.Validators.RegisteredKeys(), []string{
|
||||
assertContainsKeys(t, "chunkers", registries.Chunkers.RegisteredKeys(), []string{"dnd/scenes"})
|
||||
assertContainsKeys(t, "extractors", registries.Extractors.RegisteredKeys(), []string{"dnd/spells"})
|
||||
assertContainsArtifactKinds(t, registries.ArtifactCodecs.RegisteredKinds(), []contracts.ArtifactKind{dnd.SpellListKind})
|
||||
assertContainsKeys(t, "validators", registries.Validators.RegisteredKeys(), []string{
|
||||
"extract/dnd/spells/shape",
|
||||
"extract/dnd/spells/source_refs",
|
||||
"extract/dnd/spells/source_relatedness",
|
||||
@@ -41,7 +40,7 @@ func TestRegisterAddsDNDFamily(t *testing.T) {
|
||||
if got := registries.ValidatorChains.Validators(pipeline.StageExtract, spells.Key); !reflect.DeepEqual(got, wantChain) {
|
||||
t.Fatalf("spell validator chain = %#v, want %#v", got, wantChain)
|
||||
}
|
||||
assertAssetNames(t, assets.PromptFS, []string{
|
||||
assertAssetNamesContain(t, assets.PromptFS, []string{
|
||||
"dnd.scenes/dnd.scenes.yaml",
|
||||
"dnd.scenes/instructions.md",
|
||||
"dnd.scenes/sharedassets/common-dnd-references.md",
|
||||
@@ -55,10 +54,16 @@ func TestRegisterAddsDNDFamily(t *testing.T) {
|
||||
"dnd.spells/sharedassets/common-dnd-transcript.md",
|
||||
"dnd.spells/task.md",
|
||||
})
|
||||
assertAssetNames(t, assets.SchemaFS, []string{
|
||||
assertAssetNamesContain(t, assets.SchemaFS, []string{
|
||||
"dnd_scenes.v1.json",
|
||||
"dnd_spells_llm.v1.json",
|
||||
})
|
||||
if spec, ok := registries.Chunkers.Spec("dnd/scenes"); !ok || spec.Key != "dnd/scenes" {
|
||||
t.Fatalf("scene chunker spec = %#v, present = %t; want family-owned spec", spec, ok)
|
||||
}
|
||||
if spec, ok := registries.Extractors.Spec(spells.Key); !ok || spec.ArtifactKind != dnd.SpellListKind {
|
||||
t.Fatalf("spell extractor spec = %#v, present = %t; want dnd spell-list artifact", spec, ok)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterRejectsMissingDNDDependenciesBeforeMutation(t *testing.T) {
|
||||
@@ -118,14 +123,33 @@ func completeRegistries() pipeline.Registries {
|
||||
}
|
||||
}
|
||||
|
||||
func assertKeys(t *testing.T, name string, got, want []string) {
|
||||
func assertContainsKeys(t *testing.T, name string, got, want []string) {
|
||||
t.Helper()
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("%s keys = %#v, want %#v", name, got, want)
|
||||
seen := make(map[string]struct{}, len(got))
|
||||
for _, key := range got {
|
||||
seen[key] = struct{}{}
|
||||
}
|
||||
for _, key := range want {
|
||||
if _, ok := seen[key]; !ok {
|
||||
t.Fatalf("%s keys = %#v, want required key %q", name, got, key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func assertAssetNames(t *testing.T, getFS func() (fs.FS, error), want []string) {
|
||||
func assertContainsArtifactKinds(t *testing.T, got, want []contracts.ArtifactKind) {
|
||||
t.Helper()
|
||||
seen := make(map[contracts.ArtifactKind]struct{}, len(got))
|
||||
for _, kind := range got {
|
||||
seen[kind] = struct{}{}
|
||||
}
|
||||
for _, kind := range want {
|
||||
if _, ok := seen[kind]; !ok {
|
||||
t.Fatalf("artifact codec kinds = %#v, want required kind %q", got, kind)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func assertAssetNamesContain(t *testing.T, getFS func() (fs.FS, error), want []string) {
|
||||
t.Helper()
|
||||
fSys, err := getFS()
|
||||
if err != nil {
|
||||
@@ -141,7 +165,13 @@ func assertAssetNames(t *testing.T, getFS func() (fs.FS, error), want []string)
|
||||
t.Fatalf("walk assets: %v", err)
|
||||
}
|
||||
sort.Strings(got)
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("asset names = %#v, want %#v", got, want)
|
||||
seen := make(map[string]struct{}, len(got))
|
||||
for _, name := range got {
|
||||
seen[name] = struct{}{}
|
||||
}
|
||||
for _, name := range want {
|
||||
if _, ok := seen[name]; !ok {
|
||||
t.Fatalf("asset names = %#v, want required asset %q", got, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user