Retire automatic glossary companion discovery
This commit is contained in:
@@ -49,18 +49,6 @@ type GlossaryInputError struct{ Err error }
|
||||
func (e *GlossaryInputError) Error() string { return e.Err.Error() }
|
||||
func (e *GlossaryInputError) Unwrap() error { return e.Err }
|
||||
|
||||
const glossaryImports = `config:
|
||||
imports:
|
||||
- path: glossary.yml
|
||||
required: false
|
||||
destination: [glossary_collections]
|
||||
- dir: glossary
|
||||
required: false
|
||||
recursive: true
|
||||
pattern: ["*.yml", "*.yaml"]
|
||||
destination: [glossary_collections]
|
||||
`
|
||||
|
||||
const operatorImports = `config:
|
||||
imports:
|
||||
- path: prompts.yml
|
||||
@@ -155,7 +143,6 @@ func Load(ctx context.Context, input ck.Input, options Options) (*Acquisition, *
|
||||
pk.BundledOpenRouterUnderlay(),
|
||||
{Inputs: embedded},
|
||||
{Inputs: []ck.Input{
|
||||
{Source: ck.Bytes("Audita glossary imports", []byte(glossaryImports)), Imports: true, MainRelative: ck.MainRelative()},
|
||||
{Source: ck.Bytes("Audita automatic prompt imports", []byte(operatorImports)), Destination: ck.Keys("promptkit"), Imports: true, MainRelative: ck.MainRelative()},
|
||||
}},
|
||||
},
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
ck "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func TestGlossarySourcesComposeAndRetainExtensions(t *testing.T) {
|
||||
func TestGlossaryFilesRequireExplicitSelection(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
write := func(name, data string) {
|
||||
t.Helper()
|
||||
@@ -22,73 +22,43 @@ func TestGlossarySourcesComposeAndRetainExtensions(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
write("config.yml", `version: 3
|
||||
config:
|
||||
imports: []
|
||||
glossary_collections:
|
||||
party:
|
||||
entries:
|
||||
- id: hero
|
||||
name: Revised
|
||||
category: character
|
||||
level: 5
|
||||
`)
|
||||
write("glossary.yml", `config:
|
||||
imports:
|
||||
- path: shared/extra.yml
|
||||
required: true
|
||||
party:
|
||||
instruction: Use established names.
|
||||
entries:
|
||||
- id: hero
|
||||
name: Original
|
||||
category: character
|
||||
aliases: [Old]
|
||||
- id: other
|
||||
name: Other
|
||||
category: place
|
||||
`)
|
||||
write("shared/extra.yml", "lore:\n entries:\n - id: hero\n name: Ancient\n category: lore\n")
|
||||
write("glossary/nested/spells.yaml", "spells:\n entries:\n - id: bolt\n name: Bolt\n category: spell\n aliases: [Spark]\n plural: Bolts\n extra: {rank: 2}\n")
|
||||
result, _, err := Load(context.Background(), ck.Input{Source: ck.File(filepath.Join(dir, "config.yml"))}, Options{})
|
||||
write("config.yml", "version: 3\nglossary_collections:\n party:\n entries: [{id: configured, name: Configured, category: person}]\n")
|
||||
write("glossary.yml", "invalid: [\n")
|
||||
write("glossary/nested/spells.yaml", "invalid: [\n")
|
||||
main := ck.Input{Source: ck.SearchConfig("audita", ck.SearchDirectory(dir))}
|
||||
result, _, err := Load(context.Background(), main, Options{})
|
||||
if err != nil {
|
||||
t.Fatalf("%v: %+v", err, err.(*ck.LoadError).Diagnostics())
|
||||
t.Fatal(err)
|
||||
}
|
||||
party := result.Config.Application.GlossaryCollections["party"].Entries
|
||||
if got := result.Config.Application.GlossaryCollections["party"].Instruction; got != "Use established names." {
|
||||
t.Fatalf("instruction not inherited: %q", got)
|
||||
if len(result.Config.Application.GlossaryCollections) != 1 || result.Config.Application.GlossaryCollections["party"].Entries[0].ID != "configured" {
|
||||
t.Fatalf("unexpected vocabulary: %+v", result.Config.Application.GlossaryCollections)
|
||||
}
|
||||
if len(party) != 2 || party[0].Name != "Revised" || len(party[0].Aliases) != 0 || party[1].ID != "other" {
|
||||
t.Fatalf("party=%+v", party)
|
||||
write("glossary.yml", `config:
|
||||
imports: [{path: shared/extra.yml, required: true}]
|
||||
schema_version: maximumdirect.glossary.v1
|
||||
collections:
|
||||
party:
|
||||
entries: [{id: selected, name: Selected, category: person}]
|
||||
`)
|
||||
write("shared/extra.yml", "collections:\n lore:\n entries: [{id: lore, name: Lore, category: topic}]\n")
|
||||
write("glossary/nested/spells.yaml", "schema_version: maximumdirect.glossary.v1\ncollections:\n spells:\n entries: [{id: bolt, name: Bolt, category: spell}]\n")
|
||||
paths := []string{filepath.Join(dir, "glossary.yml"), filepath.Join(dir, "glossary/nested/spells.yaml")}
|
||||
result, _, err = Load(context.Background(), main, Options{GlossaryFiles: paths})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if party[0].Extra["level"] == nil {
|
||||
t.Fatalf("extension missing: %+v", party[0])
|
||||
}
|
||||
if got := result.Config.Application.GlossaryCollections["lore"].Entries; len(got) != 1 || got[0].ID != "hero" {
|
||||
t.Fatalf("lore=%+v", got)
|
||||
}
|
||||
discovered, _, err := Load(context.Background(), ck.Input{Source: ck.SearchConfig("audita", ck.SearchDirectory(dir))}, Options{})
|
||||
if err != nil || len(discovered.Config.Application.GlossaryCollections["party"].Entries) != 2 {
|
||||
t.Fatalf("discovered glossary: %+v %v", discovered, err)
|
||||
}
|
||||
spells := result.Config.Application.GlossaryCollections["spells"].Entries
|
||||
if len(spells) != 1 || spells[0].Plural == nil || *spells[0].Plural != "Bolts" || spells[0].Extra["extra"] == nil {
|
||||
t.Fatalf("spells=%+v", spells)
|
||||
}
|
||||
var paths []string
|
||||
for _, source := range result.Sources() {
|
||||
if source.Kind == ck.SourceKindFile {
|
||||
paths = append(paths, source.Path)
|
||||
}
|
||||
collections := result.Config.Application.GlossaryCollections
|
||||
if collections["party"].Entries[0].ID != "selected" || len(collections["lore"].Entries) != 1 || len(collections["spells"].Entries) != 1 {
|
||||
t.Fatalf("explicit vocabulary = %+v", collections)
|
||||
}
|
||||
for _, name := range []string{"glossary.yml", "shared/extra.yml", "glossary/nested/spells.yaml"} {
|
||||
if !slices.Contains(paths, filepath.Join(dir, name)) {
|
||||
t.Errorf("missing source %s: %v", name, paths)
|
||||
if !slices.Contains(result.GlossarySources, filepath.Join(dir, name)) {
|
||||
t.Errorf("missing source %s: %v", name, result.GlossarySources)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGlossaryValidationAndPeerConflicts(t *testing.T) {
|
||||
func TestInlineGlossaryValidation(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
main := filepath.Join(dir, "config.yml")
|
||||
write := func(path, data string) {
|
||||
@@ -117,15 +87,7 @@ func TestGlossaryValidationAndPeerConflicts(t *testing.T) {
|
||||
t.Fatalf("accepted %q", data)
|
||||
}
|
||||
}
|
||||
write(main, "version: 3\n")
|
||||
write(filepath.Join(dir, "glossary.yml"), "x:\n entries:\n - {id: same, name: One, category: C}\n")
|
||||
if err := os.Mkdir(filepath.Join(dir, "glossary"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
write(filepath.Join(dir, "glossary", "other.yml"), "x:\n entries:\n - {id: same, name: Two, category: C}\n")
|
||||
if _, _, err := Load(context.Background(), ck.Input{Source: ck.File(main)}, Options{}); err == nil {
|
||||
t.Fatal("peer conflict accepted")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestGlossaryUnderlaySkipsAbsentMain(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user