Reject selected catalog entries without source paths
This commit is contained in:
@@ -15,7 +15,12 @@ were left unchanged during review.
|
|||||||
|
|
||||||
Priority: P2
|
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.
|
Affected stages: 3 and 5; prepare and downstream vocabulary coverage are affected.
|
||||||
|
|
||||||
|
|||||||
81
internal/app/glossary_remediation_test.go
Normal file
81
internal/app/glossary_remediation_test.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
// SelectSetting returns the source for a selected setting, or no source for an omitted selection.
|
// SelectSetting returns the source for a selected setting, or no source for an omitted selection.
|
||||||
func (catalog ReferenceCatalogConfig) SelectSetting(id string) (string, error) {
|
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 {
|
if !ok {
|
||||||
return "", fmt.Errorf("unknown reference catalog %s %q", kind, id)
|
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
|
return path, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user