Apply shared glossary entries to application configuration
This commit is contained in:
@@ -125,7 +125,13 @@ func Load(ctx context.Context, input ck.Input, options Options) (*Acquisition, *
|
||||
glossarySources = append(glossarySources, source.Path)
|
||||
}
|
||||
}
|
||||
overrides = append(overrides, ck.Override{Path: ck.Keys("glossary_collections"), Value: glossaries.Config, Flag: "--glossary-file"})
|
||||
collections := glossaries.Config["collections"].(map[string]any)
|
||||
projected := make(map[string]any, len(collections))
|
||||
for name, value := range collections {
|
||||
collection := value.(map[string]any)
|
||||
projected[name] = map[string]any{"entries": collection["entries"]}
|
||||
}
|
||||
overrides = append(overrides, ck.Override{Path: ck.Keys("glossary_collections"), Value: projected, Flag: "--glossary-file"})
|
||||
}
|
||||
embedded, err := pk.FilesystemInputs("Audita embedded prompts", prompts.Filesystem(), prompts.AssetRoot)
|
||||
if err != nil {
|
||||
|
||||
@@ -28,17 +28,23 @@ glossary_collections:
|
||||
`,
|
||||
"first.yml": `config:
|
||||
imports: [{path: imported.yml, required: true}]
|
||||
party:
|
||||
entries:
|
||||
- {id: shared, name: Old, category: person, aliases: [Former]}
|
||||
- {id: retained, name: Retained, category: person}
|
||||
schema_version: maximumdirect.glossary.v1
|
||||
collections:
|
||||
party:
|
||||
instruction: {not: executable}
|
||||
entries:
|
||||
- {id: shared, name: Old, category: person, aliases: [Former]}
|
||||
- {id: retained, name: Retained, category: person}
|
||||
`,
|
||||
"imported.yml": `other:
|
||||
entries: [{id: imported, name: Imported, category: lore}]
|
||||
"imported.yml": `collections:
|
||||
other:
|
||||
entries: [{id: imported, name: Imported, category: lore}]
|
||||
`,
|
||||
"last.yml": `party:
|
||||
entries:
|
||||
- {id: shared, name: New, category: person, note: kept}
|
||||
"last.yml": `schema_version: maximumdirect.glossary.v1
|
||||
collections:
|
||||
party:
|
||||
entries:
|
||||
- {id: shared, name: New, category: person, note: kept, aliases: null, plural: null}
|
||||
`,
|
||||
}
|
||||
for name, contents := range files {
|
||||
@@ -105,13 +111,14 @@ func TestRuntimeGlossaryLoadErrors(t *testing.T) {
|
||||
|
||||
func TestRuntimeGlossaryPresence(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name, body string
|
||||
wantInstruction string
|
||||
wantEntries int
|
||||
name, body string
|
||||
valid bool
|
||||
wantEntries int
|
||||
}{
|
||||
{"omitted", "party: {}\n", "original", 1},
|
||||
{"empty", "party: {instruction: '', entries: []}\n", "", 0},
|
||||
{"null entries", "party: {entries: null}\n", "original", 0},
|
||||
{"empty", "party: {entries: []}", true, 0},
|
||||
{"missing entries", "party: {}", false, 0},
|
||||
{"null entries", "party: {entries: null}", false, 0},
|
||||
{"empty collections", "", true, 1},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
@@ -120,15 +127,28 @@ func TestRuntimeGlossaryPresence(t *testing.T) {
|
||||
if err := os.WriteFile(main, []byte("glossary_collections:\n party:\n instruction: original\n entries: [{id: a, name: A, category: C}]\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(incoming, []byte(tc.body), 0644); err != nil {
|
||||
body := "schema_version: maximumdirect.glossary.v1\ncollections:"
|
||||
if tc.body == "" {
|
||||
body += " {}\n"
|
||||
} else {
|
||||
body += "\n " + tc.body + "\n"
|
||||
}
|
||||
if err := os.WriteFile(incoming, []byte(body), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, _, err := Load(context.Background(), ck.Input{Source: ck.File(main)}, Options{GlossaryFiles: []string{incoming}})
|
||||
if !tc.valid {
|
||||
var inputErr *GlossaryInputError
|
||||
if !errors.As(err, &inputErr) {
|
||||
t.Fatalf("expected glossary input error, got %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("%v: %+v", err, err.(*ck.LoadError).Diagnostics())
|
||||
t.Fatal(err)
|
||||
}
|
||||
party := got.Config.Application.GlossaryCollections["party"]
|
||||
if party.Instruction != tc.wantInstruction || len(party.Entries) != tc.wantEntries {
|
||||
if party.Instruction != "original" || len(party.Entries) != tc.wantEntries {
|
||||
t.Fatalf("party = %+v", party)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user