fix(server): reload skills metadata store after install

install.Install persists metadata through its own store instance, leaving
the server's cached skillsStore stale. Freshly installed skills resolved
to a nil metadata entry and rendered with an empty source/type (shown as
"Local" in the UI) until restart. The agent path already reloaded
agentsStore; mirror it for skills across all three install completion
points (batch, tracked repo, single install).
This commit is contained in:
Willie
2026-07-21 00:31:37 +08:00
parent 86d989035b
commit 51af05ce6b
2 changed files with 48 additions and 0 deletions
+15
View File
@@ -15,6 +15,17 @@ import (
"skillshare/internal/install"
)
// reloadSkillsStore refreshes the in-memory skills metadata store from disk.
// install.Install writes metadata to the file via its own store instance, so the
// server's cached s.skillsStore stays stale after an install — a freshly
// installed skill would then render with an empty source/type (shown as "Local"
// with a blank source in the UI) until the server restarts.
func (s *Server) reloadSkillsStore() {
if st, err := install.LoadMetadataWithMigration(s.cfg.EffectiveSkillsSource(), ""); err == nil && st != nil {
s.skillsStore = st
}
}
func discoverInstallSource(source *install.Source) (*install.DiscoveryResult, error) {
if source.IsGit() {
if source.HasSubdir() {
@@ -276,6 +287,8 @@ func (s *Server) handleInstallBatch(w http.ResponseWriter, r *http.Request) {
if st, loadErr := install.LoadMetadataWithMigration(s.agentsSource(), install.MetadataKindAgent); loadErr == nil && st != nil {
s.agentsStore = st
}
} else {
s.reloadSkillsStore()
}
if s.IsProjectMode() {
if rErr := config.ReconcileProjectSkills(s.projectRoot, s.projectCfg, s.skillsStore, s.cfg.EffectiveSkillsSource()); rErr != nil {
@@ -398,6 +411,7 @@ func (s *Server) handleInstall(w http.ResponseWriter, r *http.Request) {
}
// Reconcile config after tracked repo install
if trackedKind == "skill" {
s.reloadSkillsStore()
if s.IsProjectMode() {
if rErr := config.ReconcileProjectSkills(s.projectRoot, s.projectCfg, s.skillsStore, s.cfg.EffectiveSkillsSource()); rErr != nil {
log.Printf("warning: failed to reconcile project skills config: %v", rErr)
@@ -486,6 +500,7 @@ func (s *Server) handleInstall(w http.ResponseWriter, r *http.Request) {
}
// Reconcile config after single install
s.reloadSkillsStore()
if s.IsProjectMode() {
if rErr := config.ReconcileProjectSkills(s.projectRoot, s.projectCfg, s.skillsStore, s.cfg.EffectiveSkillsSource()); rErr != nil {
log.Printf("warning: failed to reconcile project skills config: %v", rErr)
+33
View File
@@ -285,3 +285,36 @@ func TestHandleInstall_TrackPureAgentRepoInstallsIntoAgentsSource(t *testing.T)
t.Fatalf("expected no tracked agent repo in skills source, got err=%v", err)
}
}
// TestReloadSkillsStore_PicksUpNewEntry guards the "installed skill shows as
// Local with empty source" regression: install writes metadata to disk via its
// own store instance, so the server's cached skillsStore must be reloaded or a
// freshly installed skill renders with an empty source/type in the UI.
func TestReloadSkillsStore_PicksUpNewEntry(t *testing.T) {
s, sourceDir := newTestServer(t)
if got := s.skillsStore.GetByPath("frontend/react-best-practices"); got != nil {
t.Fatalf("expected empty store at startup, got %+v", got)
}
// Simulate an install persisting metadata through a separate store instance.
disk := install.NewMetadataStore()
disk.Set("frontend/react-best-practices", &install.MetadataEntry{
Source: "https://github.com/vercel-labs/agent-skills/tree/main/skills/react-best-practices",
Type: "github-subdir",
Group: "frontend",
})
if err := disk.Save(sourceDir); err != nil {
t.Fatalf("failed to save metadata: %v", err)
}
s.reloadSkillsStore()
got := s.skillsStore.GetByPath("frontend/react-best-practices")
if got == nil {
t.Fatal("reloadSkillsStore did not pick up the on-disk entry (skill would show as Local)")
}
if got.Type != "github-subdir" {
t.Errorf("Type = %q, want github-subdir", got.Type)
}
}