fix(install): reload metadata before project reconcile

Config-driven `install -p` wrote new entries to .metadata.json but then
reconciled with the store loaded before the install. Skills installed as
plain copies (subdir sources, no .git) were not in that stale store and
not detectable as tracked repos, so reconcile pruned their entries from
config.yaml, breaking the teammate `install -p && sync` flow.

Move the reload into reconcileProjectRemoteSkills so every caller
(config install, direct install, search) sees the on-disk state.

Refs #280
This commit is contained in:
Willie
2026-09-10 18:27:43 +08:00
parent 18734ab9bd
commit 898cde8add
3 changed files with 39 additions and 11 deletions
-11
View File
@@ -76,10 +76,6 @@ func cmdInstallProjectParsed(parsed *installArgs, root string) (installLogSummar
return summary, err
}
if !parsed.opts.DryRun {
freshStore, loadErr := install.LoadMetadata(runtime.sourcePath)
if loadErr == nil {
runtime.skillsStore = freshStore
}
return summary, reconcileProjectRemoteSkills(runtime)
}
return summary, nil
@@ -95,13 +91,6 @@ func cmdInstallProjectParsed(parsed *installArgs, root string) (installLogSummar
return summary, nil
}
// Reload metadata store: install may have written new entries via WriteMeta
// that the pre-install runtime doesn't know about.
freshStore, loadErr := install.LoadMetadata(runtime.sourcePath)
if loadErr == nil {
runtime.skillsStore = freshStore
}
return summary, reconcileProjectRemoteSkills(runtime)
}
+7
View File
@@ -2,8 +2,15 @@ package main
import (
"skillshare/internal/config"
"skillshare/internal/install"
)
func reconcileProjectRemoteSkills(runtime *projectRuntime) error {
// Installs write .metadata.json directly, so the store loaded before the
// install is stale. Reconciling with it prunes config entries for skills it
// never saw (#280) — always reload from disk first.
if fresh, err := install.LoadMetadata(runtime.sourcePath); err == nil {
runtime.skillsStore = fresh
}
return config.ReconcileProjectSkills(runtime.root, runtime.config, runtime.skillsStore, runtime.sourcePath)
}
+32
View File
@@ -5,6 +5,7 @@ package integration
import (
"os"
"path/filepath"
"strings"
"testing"
"skillshare/internal/install"
@@ -178,3 +179,34 @@ func TestInstallProject_AuditThresholdShortFlag_BlocksHighFinding(t *testing.T)
t.Error("project install should be blocked when -T high is set")
}
}
// Regression for #280: config-driven `install -p` must not prune the skills:
// entries it just installed from config.yaml. Uses a subdir source so the
// skill is a plain copy (no .git) — the case the stale store cannot see.
func TestInstallProject_FromConfig_KeepsConfigSkills(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
projectRoot := sb.SetupProjectDir("claude")
repoPath := filepath.Join(sb.Root, "cfg-src")
os.MkdirAll(filepath.Join(repoPath, "skills", "cfg-skill"), 0755)
os.WriteFile(filepath.Join(repoPath, "skills", "cfg-skill", "SKILL.md"), []byte("---\nname: cfg-skill\n---\n# Cfg"), 0644)
initGitRepo(t, repoPath)
sb.WriteProjectConfig(projectRoot, `targets:
- claude
skills:
- name: cfg-skill
source: file://`+repoPath+`//skills/cfg-skill
`)
sb.RunCLIInDir(projectRoot, "install", "-p").AssertSuccess(t)
if !sb.FileExists(filepath.Join(projectRoot, ".skillshare", "skills", "cfg-skill", "SKILL.md")) {
t.Fatal("skill should be installed from config")
}
cfg := sb.ReadFile(filepath.Join(projectRoot, ".skillshare", "config.yaml"))
if !strings.Contains(cfg, "name: cfg-skill") {
t.Errorf("config.yaml lost the skills entry after install -p:\n%s", cfg)
}
}