From fb612b361da79799cf921c5321714b6e44c73259 Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Sun, 29 Nov 2026 18:43:13 +0000 Subject: [PATCH] Allow disjoint glossary overrides alongside shared files --- docs/config.md | 9 ++-- docs/internal/cli-config.md | 9 ++-- docs/roadmap/remediation.md | 12 +++++- internal/appconfig/config.go | 31 ++++++++++++- internal/appconfig/runtime_glossary_test.go | 27 ++++++++++++ internal/cli/runtime_glossary_test.go | 48 +++++++++++++++++++++ 6 files changed, 127 insertions(+), 9 deletions(-) diff --git a/docs/config.md b/docs/config.md index a5b2e5d..b785937 100644 --- a/docs/config.md +++ b/docs/config.md @@ -26,9 +26,12 @@ Explicit `--glossary-file` inputs use the shared `glossary@0.2.0` contract from schemas distribution `2026.11.1` and the `maximumdirect.glossary.v1` marker. The files are ordered native layers; imports within a file are native peers and resolve beside their declaring file. Audita validates the completed envelope, -then projects collection entries as one CLI assignment to -`glossary_collections`. Supplied entry lists replace configured lists at that -boundary; unrelated configured collections remain. ConfigKit governs native +then projects collection entries through native CLI assignments to +`glossary_collections`. When other CLI overrides target that namespace, file +assignments are scoped to their supplied entry lists so disjoint overrides can +coexist. An empty collection map adds no assignment. Native override budgets and +genuine overlap checks still apply. Supplied entry lists replace configured lists +at that boundary; unrelated configured collections remain. ConfigKit governs native composition and assignment. Final explanation records the CLI assignment; runtime files and imports remain recorded for collision protection. See the [shared file contract](integrations/transcript-glossary-files.md#glossary-collections). diff --git a/docs/internal/cli-config.md b/docs/internal/cli-config.md index 98d130d..a4b27f2 100644 --- a/docs/internal/cli-config.md +++ b/docs/internal/cli-config.md @@ -45,9 +45,12 @@ without running processing readiness checks. Explicit shared glossary files use a preliminary ConfigKit load with ordered layers, native imports, and entry identities. The shared-glossary adapter validates the completed envelope against the bundled offline schema before -projecting entries into the application load. Processing retains acquired source -paths for output collision checks; inspection receives the final native result -and CLI origin. Both sides of comparison use the same invocation file list. +projecting entries into the application load. Entry assignments share the +glossary namespace with disjoint caller overrides; ordinary loads retain a +single batch contribution to avoid consuming a native override record per +collection, and empty maps contribute no override. Processing retains acquired +source paths for output collision checks; inspection receives the final native +result and CLI origin. Both sides of comparison use the same invocation file list. Automatic prompt companions remain; glossary companions are not discovered. ## Validating Examples diff --git a/docs/roadmap/remediation.md b/docs/roadmap/remediation.md index ef90eed..4da2b12 100644 --- a/docs/roadmap/remediation.md +++ b/docs/roadmap/remediation.md @@ -1,6 +1,6 @@ # Shared Glossary Remediation -**Status:** Open. +**Status:** Complete. Review covers all seven stages of [the implementation plan](implementation.md), including the pinned assets, native composition, application projection, retired @@ -91,7 +91,15 @@ on complete diagnostic wording or generated source IDs. ## R2: Shared-file assignment conflicts with disjoint native glossary overrides -**Priority:** P2. **Status:** Open. **Plan stages:** 3 and 5. +**Priority:** P2. **Status:** Complete. **Plan stages:** 3 and 5. + +**Completion:** File contributions use entry-level native assignments when caller +overrides share the glossary namespace; empty collection maps add no assignment. +Ordinary loads retain one batch assignment to avoid consuming an override record +per collection. Regression coverage verifies disjoint populated/empty inputs, +native CLI origins, genuine overlap rejection, and a large collection batch. +Existing list-replacement tests, the full Go 1.27.4 offline suite, and the +application build passed. **Locations:** [application acquisition](../../internal/appconfig/config.go), lines 94 and 116–122; [native command wiring](../../internal/cli/app_wiring.go). diff --git a/internal/appconfig/config.go b/internal/appconfig/config.go index aac6d53..5dc0879 100644 --- a/internal/appconfig/config.go +++ b/internal/appconfig/config.go @@ -6,6 +6,8 @@ import ( "errors" "fmt" "path/filepath" + "sort" + "strings" "gitea.maximumdirect.net/eric/audita/v4/internal/appconfig/sharedglossary" "gitea.maximumdirect.net/eric/audita/v4/internal/core/config" @@ -119,7 +121,7 @@ func Load(ctx context.Context, input ck.Input, options Options) (*Acquisition, * 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"}) + overrides = append(overrides, glossaryOverrides(projected, options.Overrides)...) } embedded, err := pk.FilesystemInputs("Audita embedded prompts", prompts.Filesystem(), prompts.AssetRoot) if err != nil { @@ -155,3 +157,30 @@ func Load(ctx context.Context, input ck.Input, options Options) (*Acquisition, * } return &Acquisition{Result: result, GlossarySources: glossarySources}, report, nil } + +func glossaryOverrides(projected map[string]any, supplied []ck.Override) []ck.Override { + if len(projected) == 0 { + return nil + } + root := ck.Keys("glossary_collections") + for _, override := range supplied { + path := override.Path.String() + if path != root.String() && !strings.HasPrefix(path, root.String()+"/") { + continue + } + // Only split when caller overrides need to share this namespace. The + // usual batch keeps one native record regardless of collection count. + names := make([]string, 0, len(projected)) + for name := range projected { + names = append(names, name) + } + sort.Strings(names) + result := make([]ck.Override, 0, len(names)) + for _, name := range names { + entries := projected[name].(map[string]any)["entries"] + result = append(result, ck.Override{Path: root.Key(name).Key("entries"), Value: entries, Flag: "--glossary-file"}) + } + return result + } + return []ck.Override{{Path: root, Value: projected, Flag: "--glossary-file"}} +} diff --git a/internal/appconfig/runtime_glossary_test.go b/internal/appconfig/runtime_glossary_test.go index ce006be..6a6de87 100644 --- a/internal/appconfig/runtime_glossary_test.go +++ b/internal/appconfig/runtime_glossary_test.go @@ -2,7 +2,9 @@ package appconfig import ( "context" + "encoding/json" "errors" + "fmt" "os" "path/filepath" "slices" @@ -109,6 +111,31 @@ func TestRuntimeGlossaryLoadErrors(t *testing.T) { } } +func TestRuntimeGlossaryLargeCollectionBatch(t *testing.T) { + collections := make(map[string]any) + for i := range 1100 { + collections[fmt.Sprintf("collection-%d", i)] = map[string]any{"entries": []any{}} + } + data, err := json.Marshal(map[string]any{"schema_version": "maximumdirect.glossary.v1", "collections": collections}) + if err != nil { + t.Fatal(err) + } + file := filepath.Join(t.TempDir(), "shared.json") + if err := os.WriteFile(file, data, 0600); err != nil { + t.Fatal(err) + } + got, _, err := Load(context.Background(), ck.Input{Source: ck.NoSource()}, Options{ + GlossaryFiles: []string{file}, + Overrides: []ck.Override{{Path: ck.Keys("context", "description"), Value: "batch", Flag: "--set"}}, + }) + if err != nil { + t.Fatal(err) + } + if len(got.Config.Application.GlossaryCollections) != len(collections) { + t.Fatalf("loaded %d collections, want %d", len(got.Config.Application.GlossaryCollections), len(collections)) + } +} + func TestRuntimeGlossaryPresence(t *testing.T) { for _, tc := range []struct { name, body string diff --git a/internal/cli/runtime_glossary_test.go b/internal/cli/runtime_glossary_test.go index 3586619..3203ee9 100644 --- a/internal/cli/runtime_glossary_test.go +++ b/internal/cli/runtime_glossary_test.go @@ -247,3 +247,51 @@ func TestSharedGlossaryReadinessBeforeRequests(t *testing.T) { t.Fatalf("local preflight: status=%d calls=%d stderr=%s", status, calls.Load(), stderr.String()) } } + +func TestSharedGlossaryWithDisjointNativeOverrides(t *testing.T) { + dir := t.TempDir() + main := filepath.Join(dir, "config.yml") + if err := os.WriteFile(main, []byte("version: 3\nglossary_collections:\n people:\n entries: [{id: configured, name: Configured, category: person}]\n"), 0600); err != nil { + t.Fatal(err) + } + for _, tc := range []struct{ name, collections, wantName string }{ + {"populated", "{people: {entries: [{id: a, name: Alice, category: person}]}}", "Alice"}, + {"empty", "{}", "Configured"}, + } { + t.Run(tc.name, func(t *testing.T) { + file := filepath.Join(dir, tc.name+".yml") + if err := os.WriteFile(file, []byte("schema_version: maximumdirect.glossary.v1\ncollections: "+tc.collections+"\n"), 0600); err != nil { + t.Fatal(err) + } + common := []string{"--scope=app", "--config", main, "--glossary-file", file, "--set", `/glossary_collections/other/entries=[{"id":"b","name":"Bob","category":"person"}]`} + var out, stderr bytes.Buffer + if code := Run(context.Background(), append([]string{"config", "show"}, common...), &out, &stderr); code != 0 || !strings.Contains(out.String(), "name: "+tc.wantName) || !strings.Contains(out.String(), "name: Bob") { + t.Fatalf("show: code=%d out=%s stderr=%s", code, out.String(), stderr.String()) + } + for _, origin := range []struct{ path, flag string }{ + {"/glossary_collections/other/entries", "--set"}, + {"/glossary_collections/people/entries", "--glossary-file"}, + } { + if tc.name == "empty" && origin.flag == "--glossary-file" { + continue + } + out.Reset() + stderr.Reset() + args := append([]string{"config", "explain"}, common...) + args = append(args, "--path", origin.path) + if code := Run(context.Background(), args, &out, &stderr); code != 0 || !strings.Contains(out.String(), origin.flag) { + t.Fatalf("explain: code=%d out=%s stderr=%s", code, out.String(), stderr.String()) + } + } + if tc.name == "populated" { + out.Reset() + stderr.Reset() + args := append([]string{"config", "show"}, common...) + args = append(args, "--set", `/glossary_collections/people={"entries":[]}`) + if code := Run(context.Background(), args, &out, &stderr); code != 2 || !strings.Contains(stderr.String(), "override.overlap") { + t.Fatalf("overlap: code=%d stderr=%s", code, stderr.String()) + } + } + }) + } +}