mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
fix(config): reconcile tracked checkouts by exact metadata key
Prevent nested tracked repositories from borrowing and migrating a top-level entry with the same basename. Preserve GetByPath fallback for ordinary skills and cover persisted metadata across two reconcile passes.
This commit is contained in:
@@ -60,7 +60,10 @@ func reconcileSkillsWalk(sourcePath string, walk sourcewalk.Options, store *inst
|
||||
var source string
|
||||
tracked := install.IsTrackedCheckout(path)
|
||||
|
||||
existing := store.GetByPath(fullPath)
|
||||
existing := store.Get(fullPath)
|
||||
if !tracked {
|
||||
existing = store.GetByPath(fullPath)
|
||||
}
|
||||
if existing != nil && existing.Source != "" {
|
||||
source = existing.Source
|
||||
} else if tracked {
|
||||
|
||||
@@ -3,6 +3,7 @@ package config
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"skillshare/internal/install"
|
||||
@@ -11,6 +12,41 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func TestReconcileGlobalSkills_NestedTrackedRepoWithoutEntry(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
sourceDir := filepath.Join(root, "skills")
|
||||
t.Setenv("SKILLSHARE_CONFIG", filepath.Join(root, "config.yaml"))
|
||||
remotes := map[string]string{}
|
||||
for _, name := range []string{"_team", "org/_team"} {
|
||||
repoRoot := filepath.Join(root, filepath.FromSlash(name))
|
||||
if err := os.MkdirAll(repoRoot, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
remote := testutil.SetupBareRemoteRepo(t, repoRoot)
|
||||
testutil.SeedRemoteBranch(t, repoRoot, remote, "main", map[string]string{"README.md": name})
|
||||
testutil.RunGit(t, "", "clone", remote, filepath.Join(sourceDir, filepath.FromSlash(name)))
|
||||
remotes[name] = remote
|
||||
}
|
||||
|
||||
top := install.MetadataEntry{Source: remotes["_team"], Tracked: true, Branch: "main", FileHashes: map[string]string{"README.md": "unchanged"}}
|
||||
store := install.NewMetadataStore()
|
||||
store.Set("_team", &top)
|
||||
wantTop := top
|
||||
cfg := &Config{Source: sourceDir}
|
||||
for pass := 1; pass <= 2; pass++ {
|
||||
if err := ReconcileGlobalSkills(cfg, store); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store = install.LoadMetadataOrNew(sourceDir)
|
||||
if got := store.Get("_team"); !reflect.DeepEqual(got, &wantTop) {
|
||||
t.Errorf("pass %d: top-level entry = %+v, want %+v", pass, got, wantTop)
|
||||
}
|
||||
if got := store.Get("org/_team"); got == nil || got.Source != remotes["org/_team"] || !got.Tracked || got.Group != "org" || got.Branch != "main" {
|
||||
t.Errorf("pass %d: nested entry = %+v, want source %q, tracked, group org, branch main", pass, got, remotes["org/_team"])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestReconcileGlobalSkills_AddsNewSkill(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
sourceDir := filepath.Join(root, "skills")
|
||||
|
||||
Reference in New Issue
Block a user