Update examples and tests for shared glossaries

This commit is contained in:
2026-11-27 17:00:16 +00:00
parent 410a4109ad
commit cfcb55e28c
38 changed files with 273 additions and 59 deletions

View File

@@ -6,13 +6,17 @@ import (
"encoding/json"
"fmt"
"io"
"path/filepath"
"strings"
"testing"
"time"
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
"gitea.maximumdirect.net/eric/narratio/internal/config"
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
"gitea.maximumdirect.net/eric/narratio/internal/stage"
"go.maximumdirect.net/commandkit"
)
@@ -81,11 +85,62 @@ func seedInvocationPrerequisites(t *testing.T, root, selected string) {
m.Campaign = "sample-campaign"
}
markFixturePrerequisites(t, m, selected)
if selected == "polish" {
seedGlossaryRecords(t, root, m)
}
if err := store.Save(context.Background(), path, m); err != nil {
t.Fatal(err)
}
}
func seedGlossaryRecords(t *testing.T, root string, m *manifest.Manifest) {
t.Helper()
store := artifacts.NewLocalStore(root)
paths, err := store.EnsureLayoutFor("sample-campaign", "2026-05-03")
if err != nil {
t.Fatal(err)
}
for _, descriptor := range artifactpolicy.GlossaryInputSources() {
found := false
for _, input := range m.Inputs {
if input.Kind == descriptor.ManifestKind {
found = true
break
}
}
if found {
continue
}
path := filepath.Join(paths.InputsDir, descriptor.Filename)
mustWriteTestFile(t, path, "synthetic: {entries: []}\n")
checksum, err := store.Checksum(path)
if err != nil {
t.Fatal(err)
}
m.Inputs = append(m.Inputs, manifest.InputRecord{Kind: descriptor.ManifestKind, Path: path, Checksum: checksum})
}
}
func seedPolishGlossaryEvidence(t *testing.T, root string, m *manifest.Manifest) {
t.Helper()
paths := artifacts.NewLocalStore(root).SessionPathsFor("sample-campaign", "2026-05-03")
_, evidence, err := stage.BuildPolishRequest(paths, m, "", filepath.Join(paths.Root, "scratch", "polished.json"), filepath.Join(paths.Root, "scratch", "logs"), filepath.Join(paths.Root, "scratch", "debug"))
if err != nil {
t.Fatal(err)
}
m.Stages["polish"].Metadata = map[string]any{"glossary_evidence": evidence}
}
func seedGlossaryManifest(t *testing.T, cfg *config.Config) {
t.Helper()
m := manifest.New(cfg.Session.SessionID, time.Now().UTC())
m.Campaign = cfg.Session.Campaign
seedGlossaryRecords(t, cfg.Pipeline.Workspace.Root, m)
if err := (&manifest.LocalStore{}).Save(context.Background(), manifestPathFor(cfg), m); err != nil {
t.Fatal(err)
}
}
func findingMatches(findings []finding, severity, category, message string) bool {
for _, item := range findings {
if (severity == "" || item.Severity == severity) && item.Category == category && strings.Contains(item.Message, message) {