diff --git a/cmd/ninja/cmd/plugin_test.go b/cmd/ninja/cmd/plugin_test.go index 9c16359..e4870fc 100644 --- a/cmd/ninja/cmd/plugin_test.go +++ b/cmd/ninja/cmd/plugin_test.go @@ -548,6 +548,78 @@ func TestParsePrivateCoord(t *testing.T) { } } +func TestMutateTags_AddRmSetClear(t *testing.T) { + dir := t.TempDir() + t.Chdir(dir) + + must := func(err error) { + t.Helper() + if err != nil { + t.Fatal(err) + } + } + + // Seed plugin.mod with no tags. + must(upsertPluginMod("themes", "darkpro", "Dark Pro", "Sleek dark theme", "theme", []string{}, nil, false)) + + // add + must(mutateTags("add", []string{"dark", "agency"})) + mod, err := readLocalMod() + must(err) + if len(mod.Plugin.Tags) != 2 || mod.Plugin.Tags[0] != "dark" || mod.Plugin.Tags[1] != "agency" { + t.Errorf("after add: %v", mod.Plugin.Tags) + } + + // add (dedupe + normalise) + must(mutateTags("add", []string{"Agency", "Serif"})) + mod, _ = readLocalMod() + if len(mod.Plugin.Tags) != 3 { + t.Errorf("after dedupe add: %v", mod.Plugin.Tags) + } + + // rm + must(mutateTags("rm", []string{"dark"})) + mod, _ = readLocalMod() + for _, tag := range mod.Plugin.Tags { + if tag == "dark" { + t.Errorf("after rm: dark still present: %v", mod.Plugin.Tags) + } + } + + // set + must(mutateTags("set", []string{"editorial"})) + mod, _ = readLocalMod() + if len(mod.Plugin.Tags) != 1 || mod.Plugin.Tags[0] != "editorial" { + t.Errorf("after set: %v", mod.Plugin.Tags) + } + + // clear + must(mutateTags("clear", nil)) + mod, _ = readLocalMod() + if len(mod.Plugin.Tags) != 0 { + t.Errorf("after clear: %v", mod.Plugin.Tags) + } +} + +func TestMutateTags_RejectsInvalidNoWrite(t *testing.T) { + dir := t.TempDir() + t.Chdir(dir) + + if err := upsertPluginMod("themes", "x", "X", "", "theme", nil, []string{"dark"}, false); err != nil { + t.Fatal(err) + } + if err := mutateTags("add", []string{"BAD SPACE"}); err == nil { + t.Fatal("expected validation error") + } + mod, err := readLocalMod() + if err != nil { + t.Fatal(err) + } + if len(mod.Plugin.Tags) != 1 || mod.Plugin.Tags[0] != "dark" { + t.Errorf("tags mutated despite error: %v", mod.Plugin.Tags) + } +} + func runGit(t *testing.T, dir string, args ...string) { t.Helper() cmd := exec.Command("git", args...)