Complete shared glossary validation and acceptance checks
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# Shared Glossary Implementation Plan
|
# 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
|
Implement the [shared glossary roadmap](shared-glossary.md). It owns the desired
|
||||||
behavior and user decisions. This plan owns implementation order and validation.
|
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
|
## 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
|
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.
|
before running the offline suite; dependency upgrades are not part of adoption.
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Shared Glossary Adoption
|
# Shared Glossary Adoption
|
||||||
|
|
||||||
**Status:** Targeted for Audita v4.3.0.
|
**Status:** Implemented for Audita v4.3.0; publication is separate.
|
||||||
|
|
||||||
## Purpose
|
## Purpose
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,11 @@ collections:
|
|||||||
category: character
|
category: character
|
||||||
description: A fictional adventurer.
|
description: A fictional adventurer.
|
||||||
spells:
|
spells:
|
||||||
|
provenance: {id: synthetic-spells, title: Synthetic spell catalog, version: "1"}
|
||||||
entries:
|
entries:
|
||||||
- id: shield
|
- id: shield
|
||||||
name: Shield
|
name: Shield
|
||||||
category: spell
|
category: spell
|
||||||
aliases: [Ward]
|
aliases: [Ward]
|
||||||
|
casting_time: one reaction
|
||||||
|
rank: 1
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
schema_version: maximumdirect.glossary.v1
|
schema_version: maximumdirect.glossary.v1
|
||||||
collections:
|
collections:
|
||||||
spells:
|
spells:
|
||||||
|
provenance: {id: synthetic-spells, title: Synthetic spell catalog, version: "1"}
|
||||||
entries:
|
entries:
|
||||||
- id: shield
|
- id: shield
|
||||||
name: Shield
|
name: Shield
|
||||||
category: spell
|
category: spell
|
||||||
aliases: [Ward]
|
aliases: [Ward]
|
||||||
|
casting_time: one reaction
|
||||||
|
rank: 1
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package sharedglossary
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/audita/v4/internal/core/config"
|
"gitea.maximumdirect.net/eric/audita/v4/internal/core/config"
|
||||||
ck "go.maximumdirect.net/configkit"
|
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 := inputs[len(inputs)-1]
|
||||||
main.Imports = true
|
main.Imports = true
|
||||||
result, err := ck.LoadLayered(main, ck.LayeredOptions[map[string]any]{
|
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")})}},
|
Definition: ck.Definition[map[string]any]{
|
||||||
Underlays: underlays,
|
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 {
|
if canceled := ctx.Err(); canceled != nil {
|
||||||
return nil, errors.Join(err, canceled)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
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
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -108,12 +109,78 @@ func TestLoadErrorsAndEmptyInput(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
_, err := Load(context.Background(), []ck.Input{{Source: ck.File(path)}})
|
_, err := Load(context.Background(), []ck.Input{{Source: ck.File(path)}})
|
||||||
if err == nil || !strings.Contains(err.Error(), tc.contains) {
|
var loadErr *ck.LoadError
|
||||||
t.Fatalf("Load() = %v", err)
|
if !errors.As(err, &loadErr) {
|
||||||
|
t.Fatalf("expected native load error, got %v", err)
|
||||||
}
|
}
|
||||||
if tc.name == "missing marker" && !strings.Contains(err.Error(), path) {
|
var messages []string
|
||||||
t.Fatalf("missing source context: %v", err)
|
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])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -102,11 +102,13 @@ func TestProcessRuntimeGlossaryFailures(t *testing.T) {
|
|||||||
func TestNativeCommandsUseRuntimeGlossary(t *testing.T) {
|
func TestNativeCommandsUseRuntimeGlossary(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
for name, data := range map[string]string{
|
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",
|
"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",
|
"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",
|
"input.yml": "schema_version: maximumdirect.glossary.v1\ncollections: {party: {entries: [{id: c, name: Runtime, category: C}]}}\n",
|
||||||
"bad.yml": "party: [\n",
|
"bad.yml": "party: [\n",
|
||||||
"additional.yml": "schema_version: maximumdirect.glossary.v1\ncollections: {extra: {entries: [{id: d, name: Additional, category: C}]}}\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 {
|
if err := os.WriteFile(filepath.Join(dir, name), []byte(data), 0600); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -149,6 +151,17 @@ func TestNativeCommandsUseRuntimeGlossary(t *testing.T) {
|
|||||||
t.Fatalf("%v: %d %s", args, code, stderr)
|
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"}} {
|
for _, args := range [][]string{{"--help"}, {"version"}, {"config", "scopes"}, {"promptkit", "--help"}} {
|
||||||
code, _, stderr = run(args...)
|
code, _, stderr = run(args...)
|
||||||
if code != 0 {
|
if code != 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user