From 447888e06213a6dad57b4afb23a8cd1e8cae676d Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Fri, 27 Nov 2026 21:16:27 +0000 Subject: [PATCH] Reject selected catalog entries without source paths --- docs/roadmap/remediation.md | 7 +- internal/app/glossary_remediation_test.go | 81 +++++++++++++++++++++++ internal/config/reference_catalog.go | 8 ++- 3 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 internal/app/glossary_remediation_test.go diff --git a/docs/roadmap/remediation.md b/docs/roadmap/remediation.md index 367a4ae..2577243 100644 --- a/docs/roadmap/remediation.md +++ b/docs/roadmap/remediation.md @@ -15,7 +15,12 @@ were left unchanged during review. Priority: P2 -Status: Pending +Status: Complete + +Selected blank catalog paths now fail with kind/ID context. Acquisition and +prepare-only regression tests cover empty/null values in both catalog groups +and successful empty roles with unused empty or uninstalled entries. Focused +configuration and application tests passed with Go 1.27.4. Affected stages: 3 and 5; prepare and downstream vocabulary coverage are affected. diff --git a/internal/app/glossary_remediation_test.go b/internal/app/glossary_remediation_test.go new file mode 100644 index 0000000..e184d60 --- /dev/null +++ b/internal/app/glossary_remediation_test.go @@ -0,0 +1,81 @@ +package app + +import ( + "context" + "fmt" + "os" + "path/filepath" + "strings" + "testing" + + "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" +) + +func TestSelectedCatalogSourcesBeforePreparation(t *testing.T) { + for _, group := range []struct{ name, selector string }{{"settings", "setting"}, {"systems", "system"}} { + for _, tc := range []struct { + name, value string + selected, invalid bool + }{ + {"selected empty", `""`, true, true}, + {"selected null", "null", true, true}, + {"omitted empty", `""`, false, false}, + {"omitted missing file", "not-installed.yml", false, false}, + } { + t.Run(group.name+"/"+tc.name, func(t *testing.T) { + pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir()) + body, err := os.ReadFile(pipeline) + if err != nil { + t.Fatal(err) + } + mustWriteTestFile(t, pipeline, string(body)+fmt.Sprintf("reference_catalog:\n %s:\n broken: %s\n", group.name, tc.value)) + if tc.selected { + body, err = os.ReadFile(campaign) + if err != nil { + t.Fatal(err) + } + mustWriteTestFile(t, campaign, string(body)+fmt.Sprintf(" %s: broken\n", group.selector)) + } + cfg, err := config.LoadWithSessionOptions(pipeline, campaign, session, config.SessionLoadOptions{}) + if tc.invalid { + if err == nil { + t.Fatal("invalid selected source accepted") + } + if tc.value != "null" && (!strings.Contains(err.Error(), group.selector) || !strings.Contains(err.Error(), "broken")) { + t.Fatalf("missing selection context: %v", err) + } + return + } + if err != nil { + t.Fatal(err) + } + prepare, err := stage.Select("prepare") + if err != nil { + t.Fatal(err) + } + if _, err := executeStages(context.Background(), cfg, []stage.Stage{prepare}, RunOptions{}); err != nil { + t.Fatal(err) + } + paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID) + m, err := (&manifest.LocalStore{}).Load(context.Background(), paths.ManifestPath) + if err != nil { + t.Fatal(err) + } + for _, source := range []string{artifactpolicy.SourceInputGlossarySetting, artifactpolicy.SourceInputGlossarySpells} { + identity, err := artifacts.ResolvePreparedInput(paths, m, source) + if err != nil { + t.Fatal(err) + } + data, err := os.ReadFile(filepath.Clean(identity.Path)) + if err != nil || !strings.Contains(string(data), "entries: []") { + t.Fatalf("empty role: %s %v", data, err) + } + } + }) + } + } +} diff --git a/internal/config/reference_catalog.go b/internal/config/reference_catalog.go index c237800..4dc6d48 100644 --- a/internal/config/reference_catalog.go +++ b/internal/config/reference_catalog.go @@ -1,6 +1,9 @@ package config -import "fmt" +import ( + "fmt" + "strings" +) // SelectSetting returns the source for a selected setting, or no source for an omitted selection. func (catalog ReferenceCatalogConfig) SelectSetting(id string) (string, error) { @@ -20,5 +23,8 @@ func selectReference(kind, id string, entries map[string]string) (string, error) if !ok { return "", fmt.Errorf("unknown reference catalog %s %q", kind, id) } + if strings.TrimSpace(path) == "" { + return "", fmt.Errorf("reference catalog %s %q has an empty source path", kind, id) + } return path, nil }