Complete shared glossary validation and acceptance checks

This commit is contained in:
2026-11-29 18:19:50 +00:00
parent 3b7baed65e
commit 9af2c146f1
7 changed files with 113 additions and 23 deletions

View File

@@ -1,6 +1,6 @@
# Shared Glossary Implementation Plan
**Status:** In progress. Target release: Audita v4.3.0.
**Status:** Complete. Target release: Audita v4.3.0.
Implement the [shared glossary roadmap](shared-glossary.md). It owns the desired
behavior and user decisions. This plan owns implementation order and validation.
@@ -265,6 +265,13 @@ completed until the integrated sprint has actually passed its acceptance checks.
## Stage 7: Complete Integrated Validation and Cleanup
**Completed.** The integrated offline suite and build passed with Go 1.27.4,
`GOWORK=off GOTOOLCHAIN=local GOPROXY=off GOSUMDB=off`. Focused tests cover
native composition, schema validation, selection and protection, inspection,
preflight, processing, collisions, and maintained examples. The bundled schema
assets and license match the pinned source. Local documentation links and
`git diff --check` passed. No real provider or external application was used.
Use Go 1.27.4 as documented in `docs/release.md`. Prepare dependencies if needed
before running the offline suite; dependency upgrades are not part of adoption.

View File

@@ -1,6 +1,6 @@
# Shared Glossary Adoption
**Status:** Targeted for Audita v4.3.0.
**Status:** Implemented for Audita v4.3.0; publication is separate.
## Purpose

View File

@@ -6,8 +6,11 @@ collections:
category: character
description: A fictional adventurer.
spells:
provenance: {id: synthetic-spells, title: Synthetic spell catalog, version: "1"}
entries:
- id: shield
name: Shield
category: spell
aliases: [Ward]
casting_time: one reaction
rank: 1

View File

@@ -1,8 +1,11 @@
schema_version: maximumdirect.glossary.v1
collections:
spells:
provenance: {id: synthetic-spells, title: Synthetic spell catalog, version: "1"}
entries:
- id: shield
name: Shield
category: spell
aliases: [Ward]
casting_time: one reaction
rank: 1

View File

@@ -3,7 +3,6 @@ package sharedglossary
import (
"context"
"errors"
"strings"
"gitea.maximumdirect.net/eric/audita/v4/internal/core/config"
ck "go.maximumdirect.net/configkit"
@@ -30,8 +29,15 @@ func Load(ctx context.Context, inputs []ck.Input) (*ck.Result[map[string]any], e
main := inputs[len(inputs)-1]
main.Imports = true
result, err := ck.LoadLayered(main, ck.LayeredOptions[map[string]any]{
Definition: ck.Definition[map[string]any]{SequenceIdentities: []ck.SequenceIdentity{config.GlossaryEntryIdentity(ck.SequenceSelector{ck.SequenceLiteralKey("collections")})}},
Underlays: underlays,
Definition: ck.Definition[map[string]any]{
SequenceIdentities: []ck.SequenceIdentity{config.GlossaryEntryIdentity(ck.SequenceSelector{ck.SequenceLiteralKey("collections")})},
Validate: func(document *map[string]any, validation *ck.Validation) {
if err := validator.Validate(*document, "input"); err != nil {
validation.Error(ck.Keys(), err.Error())
}
},
},
Underlays: underlays,
})
if canceled := ctx.Err(); canceled != nil {
return nil, errors.Join(err, canceled)
@@ -39,14 +45,5 @@ func Load(ctx context.Context, inputs []ck.Input) (*ck.Result[map[string]any], e
if err != nil {
return nil, err
}
var sources []string
for _, source := range result.Sources() {
if source.Path != "" {
sources = append(sources, source.Path)
}
}
if err := validator.Validate(result.Config, strings.Join(sources, ", ")); err != nil {
return nil, err
}
return result, nil
}

View File

@@ -5,6 +5,7 @@ import (
"errors"
"os"
"path/filepath"
"reflect"
"slices"
"strings"
"testing"
@@ -108,12 +109,78 @@ func TestLoadErrorsAndEmptyInput(t *testing.T) {
t.Fatal(err)
}
_, err := Load(context.Background(), []ck.Input{{Source: ck.File(path)}})
if err == nil || !strings.Contains(err.Error(), tc.contains) {
t.Fatalf("Load() = %v", err)
var loadErr *ck.LoadError
if !errors.As(err, &loadErr) {
t.Fatalf("expected native load error, got %v", err)
}
if tc.name == "missing marker" && !strings.Contains(err.Error(), path) {
t.Fatalf("missing source context: %v", err)
var messages []string
for _, diagnostic := range loadErr.Diagnostics() {
messages = append(messages, diagnostic.Message)
}
if !strings.Contains(strings.Join(messages, " "), tc.contains) {
t.Fatalf("diagnostics = %v", messages)
}
var paths []string
for _, source := range loadErr.Sources() {
paths = append(paths, source.Path)
}
if !slices.Contains(paths, path) {
t.Fatalf("missing source context: %v", paths)
}
})
}
}
func TestLoadResolvesInheritanceAndPreservesExtensions(t *testing.T) {
path := filepath.Join(t.TempDir(), "shared.yml")
body := `schema_version: maximumdirect.glossary.v1
custom: {revision: 1, ratio: 1.5}
collections:
original:
provenance: {title: Synthetic source, custom: true}
entries: [{id: a, name: Alpha, category: spell, rank: 1}]
derived:
extends: original
instruction: {text: data}
`
if err := os.WriteFile(path, []byte(body), 0644); err != nil {
t.Fatal(err)
}
result, err := Load(context.Background(), []ck.Input{{Source: ck.File(path)}})
if err != nil {
t.Fatal(err)
}
collections := result.Config["collections"].(map[string]any)
derived := collections["derived"].(map[string]any)
entries := derived["entries"].([]any)
if len(entries) != 1 || entries[0].(map[string]any)["rank"] != int64(1) || derived["provenance"].(map[string]any)["title"] != "Synthetic source" || derived["instruction"].(map[string]any)["text"] != "data" {
t.Fatalf("resolved data = %#v", result.Config)
}
custom := result.Config["custom"].(map[string]any)
if custom["revision"] != int64(1) || custom["ratio"] != 1.5 {
t.Fatalf("extensions = %#v", custom)
}
}
func TestEquivalentYAMLAndJSON(t *testing.T) {
dir := t.TempDir()
documents := map[string]string{
"input.yml": "schema_version: maximumdirect.glossary.v1\ncollections:\n terms:\n entries: [{id: a, name: Alpha, category: term}, {id: A, name: Alpha, category: term}]\n",
"input.json": `{"schema_version":"maximumdirect.glossary.v1","collections":{"terms":{"entries":[{"id":"a","name":"Alpha","category":"term"},{"id":"A","name":"Alpha","category":"term"}]}}}`,
}
var results []map[string]any
for name, body := range documents {
path := filepath.Join(dir, name)
if err := os.WriteFile(path, []byte(body), 0644); err != nil {
t.Fatal(err)
}
result, err := Load(context.Background(), []ck.Input{{Source: ck.File(path)}})
if err != nil {
t.Fatal(err)
}
results = append(results, result.Config)
}
if !reflect.DeepEqual(results[0], results[1]) {
t.Fatalf("documents differ: %#v, %#v", results[0], results[1])
}
}

View File

@@ -102,11 +102,13 @@ func TestProcessRuntimeGlossaryFailures(t *testing.T) {
func TestNativeCommandsUseRuntimeGlossary(t *testing.T) {
dir := t.TempDir()
for name, data := range map[string]string{
"left.yml": "version: 3\ncontext: {description: left}\nglossary_collections: {party: {entries: [{id: a, name: Left, category: C}]}}\n",
"right.yml": "version: 3\ncontext: {description: right}\nglossary_collections: {party: {entries: [{id: b, name: Right, category: C}]}}\n",
"input.yml": "schema_version: maximumdirect.glossary.v1\ncollections: {party: {entries: [{id: c, name: Runtime, category: C}]}}\n",
"bad.yml": "party: [\n",
"additional.yml": "schema_version: maximumdirect.glossary.v1\ncollections: {extra: {entries: [{id: d, name: Additional, category: C}]}}\n",
"left.yml": "version: 3\ncontext: {description: left}\nglossary_collections: {party: {entries: [{id: a, name: Left, category: C}]}}\n",
"right.yml": "version: 3\ncontext: {description: right}\nglossary_collections: {party: {entries: [{id: b, name: Right, category: C}]}}\n",
"input.yml": "schema_version: maximumdirect.glossary.v1\ncollections: {party: {entries: [{id: c, name: Runtime, category: C}]}}\n",
"bad.yml": "party: [\n",
"invalid.yml": "schema_version: wrong\ncollections: {}\n",
"empty-shared.yml": "schema_version: maximumdirect.glossary.v1\ncollections: {}\n",
"additional.yml": "schema_version: maximumdirect.glossary.v1\ncollections: {extra: {entries: [{id: d, name: Additional, category: C}]}}\n",
} {
if err := os.WriteFile(filepath.Join(dir, name), []byte(data), 0600); err != nil {
t.Fatal(err)
@@ -149,6 +151,17 @@ func TestNativeCommandsUseRuntimeGlossary(t *testing.T) {
t.Fatalf("%v: %d %s", args, code, stderr)
}
}
code, _, stderr = run("config", "show", "--scope=app", "--config", main, "--glossary-file", filepath.Join(dir, "empty-shared.yml"))
if code != 0 {
t.Fatalf("empty shared inspection: %d %s", code, stderr)
}
for _, args := range [][]string{{"config", "show", "--scope=app"}, {"promptkit", "list", "prompts"}} {
args = append(args, "--config", main, "--glossary-file", filepath.Join(dir, "invalid.yml"))
code, _, stderr = run(args...)
if code != 2 || !strings.Contains(stderr, "invalid.yml") || !strings.Contains(stderr, "schema_version") {
t.Fatalf("invalid shared data %v: %d %s", args, code, stderr)
}
}
for _, args := range [][]string{{"--help"}, {"version"}, {"config", "scopes"}, {"promptkit", "--help"}} {
code, _, stderr = run(args...)
if code != 0 {