mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
Sync re-copies a managed copy whose recorded naming differs from the current one, for example after a migration stopped between the rename and the re-copy. Diff skipped it on the mtime fast path and reported the target in sync while its SKILL.md kept the old name. Check the recorded naming first in both the CLI and the dashboard diff.
67 lines
2.6 KiB
Go
67 lines
2.6 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)
|
|
}
|
|
}
|
|
|
|
func TestComputeTargetDiff_StaleRecordedNamingIsAnUpdate(t *testing.T) {
|
|
// A sync renamed the entry and saved the manifest, then stopped before re-copying it.
|
|
source, target := t.TempDir(), t.TempDir()
|
|
src := filepath.Join(source, "_emil-design", "skills", "prototype")
|
|
for _, dir := range []string{src, filepath.Join(target, "emil-design-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)
|
|
}
|
|
}
|
|
checksum, err := ssync.DirChecksumWithIgnore(src, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
manifest := &ssync.Manifest{Managed: map[string]string{"emil-design-prototype": checksum}, Naming: map[string]string{"emil-design-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].Action != "update" || dt.Items[0].Reason != "target naming changed" {
|
|
t.Fatalf("items = %+v, want one update for the stale naming", dt.Items)
|
|
}
|
|
}
|