feat(vendor): add rename command for deployed item names
- Add `vendor rename <source> [upstream-id=name ...] [--reset ids]` to change deployed names after `vendor add`, without moving the pinned rev or selection - Persist renames in the lockfile so they survive `vendor update` and `vendor select` - Rewrite SKILL.md frontmatter `name:` to the folder name so OpenCode loads renamed skills - Validate rename targets: single path segment, no leading dot, and OpenCode skill naming rules for skills - Re-run collision checks before writing; failed renames leave lockfile and external area untouched - Add unit tests for frontmatter rewrite and name validation, plus e2e rename coverage - Document renames in README; sync beads issue export
This commit is contained in:
1 parent
f37c3dce5e
commit
d6821c6d7c
11 files changed
+472
-2
No files matched your search
@@ -0,0 +1,89 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestVendorRenameAfterAdd(t *testing.T) {
|
||||
h := newHarness(t)
|
||||
standardFixture(h, t)
|
||||
h.mustRun(t, "vendor", "add", "superpowers", h.upstreamDir)
|
||||
|
||||
out := h.mustRun(t, "vendor", "rename", "superpowers", "good-skill=gute-skill", "review=pruefen")
|
||||
for _, want := range []string{"good-skill → gute-skill", "review → pruefen"} {
|
||||
if !contains(out, want) {
|
||||
t.Errorf("report must contain %q:\n%s", want, out)
|
||||
}
|
||||
}
|
||||
|
||||
skill := readFile(t, filepath.Join(h.workDir, "external/superpowers/skills/gute-skill/SKILL.md"))
|
||||
if !contains(skill, "name: gute-skill\n") || !contains(skill, "description: works") {
|
||||
t.Errorf("renamed skill must carry the new frontmatter name and keep the rest:\n%s", skill)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(h.workDir, "external/superpowers/skills/gute-skill/helper.py")); err != nil {
|
||||
t.Error("skill artifacts must move with the rename")
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(h.workDir, "external/superpowers/skills/good-skill")); err == nil {
|
||||
t.Error("old skill folder must be gone")
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(h.workDir, "external/superpowers/commands/pruefen.md")); err != nil {
|
||||
t.Error("renamed command must exist under the new name")
|
||||
}
|
||||
lock := readLock(t, h.workDir)
|
||||
if got := lock.Sources["superpowers"].Renames["good-skill"]; got != "gute-skill" {
|
||||
t.Errorf("lockfile rename = %q", got)
|
||||
}
|
||||
h.mustRun(t, "validate")
|
||||
|
||||
// Listing.
|
||||
if out := h.mustRun(t, "vendor", "rename", "superpowers"); !contains(out, "good-skill → gute-skill") {
|
||||
t.Errorf("listing must show renames:\n%s", out)
|
||||
}
|
||||
|
||||
// Survives update with new upstream content.
|
||||
h.write(t, "skills/good-skill/SKILL.md", "---\nname: Good Skill\ndescription: v2\n---\n# Good v2\n")
|
||||
h.commitUpstream(t, "v2")
|
||||
h.mustRun(t, "vendor", "update", "superpowers")
|
||||
skill = readFile(t, filepath.Join(h.workDir, "external/superpowers/skills/gute-skill/SKILL.md"))
|
||||
if !contains(skill, "name: gute-skill\n") || !contains(skill, "description: v2") {
|
||||
t.Errorf("update must keep the rename and frontmatter rewrite:\n%s", skill)
|
||||
}
|
||||
|
||||
// Reset.
|
||||
h.mustRun(t, "vendor", "rename", "superpowers", "--reset", "good-skill")
|
||||
if _, err := os.Stat(filepath.Join(h.workDir, "external/superpowers/skills/good-skill/SKILL.md")); err != nil {
|
||||
t.Error("reset must restore the upstream folder name")
|
||||
}
|
||||
if got := readLock(t, h.workDir).Sources["superpowers"].Renames["good-skill"]; got != "" {
|
||||
t.Errorf("reset must drop the rename, got %q", got)
|
||||
}
|
||||
h.mustRun(t, "validate")
|
||||
}
|
||||
|
||||
func TestVendorRenameRejectsBadInput(t *testing.T) {
|
||||
h := newHarness(t)
|
||||
ownSkillFixture(h, t) // own skills/good-skill
|
||||
standardFixture(h, t)
|
||||
h.mustRun(t, "vendor", "add", "superpowers", h.upstreamDir, "--rename", "good-skill=sp-good")
|
||||
before := readFile(t, filepath.Join(h.workDir, "agent-lib.lock.json"))
|
||||
|
||||
for _, args := range [][]string{
|
||||
{"broken-skill=good-skill"}, // collides with own skill
|
||||
{"good-skill=Gute Skill"}, // invalid skill name
|
||||
{"does-not-exist=whatever"}, // unknown upstream id
|
||||
{"--reset", "broken-skill"}, // nothing to reset
|
||||
} {
|
||||
out, err := h.run(t, append([]string{"vendor", "rename", "superpowers"}, args...)...)
|
||||
if err == nil {
|
||||
t.Errorf("rename %v must fail:\n%s", args, out)
|
||||
}
|
||||
}
|
||||
if after := readFile(t, filepath.Join(h.workDir, "agent-lib.lock.json")); after != before {
|
||||
t.Error("failed renames must not touch the lockfile")
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(h.workDir, "external/superpowers/skills/sp-good")); err != nil {
|
||||
t.Error("failed renames must not touch the external area")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user