mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
After target_naming changes, sync renames the managed entry in place, but diff looked only under the new name, so the CLI and the dashboard showed the skill as new while hiding the old entry. Resolve the legacy entry and report it as a rename instead.
36 lines
1.3 KiB
Go
36 lines
1.3 KiB
Go
package server
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"skillshare/internal/config"
|
|
ssync "skillshare/internal/sync"
|
|
)
|
|
|
|
func TestComputeTargetDiff_NamingChangeReportsRename(t *testing.T) {
|
|
source, target := t.TempDir(), t.TempDir()
|
|
for _, dir := range []string{filepath.Join(source, "_emil-design", "skills", "prototype"), filepath.Join(target, "prototype")} {
|
|
if err := os.MkdirAll(dir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(dir, "SKILL.md"), []byte("---\nname: prototype\n---\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
manifest := &ssync.Manifest{Managed: map[string]string{"prototype": "x"}, Naming: map[string]string{"prototype": "standard"}}
|
|
if err := ssync.WriteManifest(target, manifest); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
discovered, err := ssync.DiscoverSourceSkills(source)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
dt := (&Server{}).computeTargetDiff("claude", config.TargetConfig{Skills: &config.ResourceTargetConfig{Path: target, Mode: "copy", TargetNaming: "prefixed"}}, discovered, "merge", source, nil)
|
|
if len(dt.Items) != 1 || dt.Items[0].Skill != "emil-design-prototype" || dt.Items[0].Action != "update" || dt.Items[0].Reason != "renamed from prototype (target naming changed)" {
|
|
t.Fatalf("items = %+v, want one update renaming prototype", dt.Items)
|
|
}
|
|
}
|