Apply shared glossary entries to application configuration
This commit is contained in:
@@ -127,6 +127,8 @@ current restrictions as permanent Audita behavior.
|
|||||||
|
|
||||||
## Stage 3: Integrate Runtime Vocabulary with Application Loading
|
## Stage 3: Integrate Runtime Vocabulary with Application Loading
|
||||||
|
|
||||||
|
**Completed.**
|
||||||
|
|
||||||
**Work**
|
**Work**
|
||||||
|
|
||||||
1. Replace the old wrapperless runtime-load block in `internal/appconfig.Load`
|
1. Replace the old wrapperless runtime-load block in `internal/appconfig.Load`
|
||||||
|
|||||||
@@ -125,7 +125,13 @@ func Load(ctx context.Context, input ck.Input, options Options) (*Acquisition, *
|
|||||||
glossarySources = append(glossarySources, source.Path)
|
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)
|
embedded, err := pk.FilesystemInputs("Audita embedded prompts", prompts.Filesystem(), prompts.AssetRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -28,17 +28,23 @@ glossary_collections:
|
|||||||
`,
|
`,
|
||||||
"first.yml": `config:
|
"first.yml": `config:
|
||||||
imports: [{path: imported.yml, required: true}]
|
imports: [{path: imported.yml, required: true}]
|
||||||
party:
|
schema_version: maximumdirect.glossary.v1
|
||||||
entries:
|
collections:
|
||||||
- {id: shared, name: Old, category: person, aliases: [Former]}
|
party:
|
||||||
- {id: retained, name: Retained, category: person}
|
instruction: {not: executable}
|
||||||
|
entries:
|
||||||
|
- {id: shared, name: Old, category: person, aliases: [Former]}
|
||||||
|
- {id: retained, name: Retained, category: person}
|
||||||
`,
|
`,
|
||||||
"imported.yml": `other:
|
"imported.yml": `collections:
|
||||||
entries: [{id: imported, name: Imported, category: lore}]
|
other:
|
||||||
|
entries: [{id: imported, name: Imported, category: lore}]
|
||||||
`,
|
`,
|
||||||
"last.yml": `party:
|
"last.yml": `schema_version: maximumdirect.glossary.v1
|
||||||
entries:
|
collections:
|
||||||
- {id: shared, name: New, category: person, note: kept}
|
party:
|
||||||
|
entries:
|
||||||
|
- {id: shared, name: New, category: person, note: kept, aliases: null, plural: null}
|
||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
for name, contents := range files {
|
for name, contents := range files {
|
||||||
@@ -105,13 +111,14 @@ func TestRuntimeGlossaryLoadErrors(t *testing.T) {
|
|||||||
|
|
||||||
func TestRuntimeGlossaryPresence(t *testing.T) {
|
func TestRuntimeGlossaryPresence(t *testing.T) {
|
||||||
for _, tc := range []struct {
|
for _, tc := range []struct {
|
||||||
name, body string
|
name, body string
|
||||||
wantInstruction string
|
valid bool
|
||||||
wantEntries int
|
wantEntries int
|
||||||
}{
|
}{
|
||||||
{"omitted", "party: {}\n", "original", 1},
|
{"empty", "party: {entries: []}", true, 0},
|
||||||
{"empty", "party: {instruction: '', entries: []}\n", "", 0},
|
{"missing entries", "party: {}", false, 0},
|
||||||
{"null entries", "party: {entries: null}\n", "original", 0},
|
{"null entries", "party: {entries: null}", false, 0},
|
||||||
|
{"empty collections", "", true, 1},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
dir := t.TempDir()
|
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 {
|
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)
|
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)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
got, _, err := Load(context.Background(), ck.Input{Source: ck.File(main)}, Options{GlossaryFiles: []string{incoming}})
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("%v: %+v", err, err.(*ck.LoadError).Diagnostics())
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
party := got.Config.Application.GlossaryCollections["party"]
|
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)
|
t.Fatalf("party = %+v", party)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user