From a686ee910ff2cc768745ea810aae43d82e4c7cad Mon Sep 17 00:00:00 2001 From: Willie Date: Thu, 8 Oct 2026 12:26:26 +0800 Subject: [PATCH] fix(server): install config entries into the project source in project mode The dashboard's install-from-config context read the global skills source from s.cfg, which stays global in project mode. Missing entries were checked against the global folder and installed there instead of the project's .skillshare/skills. Use the project-aware skillsSource and reload the metadata store from that same folder before reconciling. --- internal/server/handler_install_config.go | 8 +++++-- .../server/handler_install_config_test.go | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/internal/server/handler_install_config.go b/internal/server/handler_install_config.go index 7132409ba..063f45978 100644 --- a/internal/server/handler_install_config.go +++ b/internal/server/handler_install_config.go @@ -15,7 +15,8 @@ type serverInstallContext struct{ s *Server } var _ install.InstallContext = serverInstallContext{} -func (c serverInstallContext) SourcePath() string { return c.s.cfg.EffectiveSkillsSource() } +// SourcePath is the project's skills folder in project mode, else the global one. +func (c serverInstallContext) SourcePath() string { return c.s.skillsSource() } func (c serverInstallContext) ConfigSkills() []install.SkillEntryDTO { if !c.s.IsProjectMode() { @@ -25,7 +26,10 @@ func (c serverInstallContext) ConfigSkills() []install.SkillEntryDTO { } func (c serverInstallContext) Reconcile() error { - c.s.reloadSkillsStore() + // Reload from the same folder the install wrote to; reloadSkillsStore reads the global one. + if st, err := install.LoadMetadataWithMigration(c.SourcePath(), ""); err == nil && st != nil { + c.s.skillsStore = st + } c.s.reconcileSkillsConfig(c.SourcePath()) return nil } diff --git a/internal/server/handler_install_config_test.go b/internal/server/handler_install_config_test.go index 7fad0130f..cc9e25984 100644 --- a/internal/server/handler_install_config_test.go +++ b/internal/server/handler_install_config_test.go @@ -4,8 +4,11 @@ import ( "encoding/json" "net/http" "net/http/httptest" + "os" + "path/filepath" "testing" + "skillshare/internal/config" "skillshare/internal/install" ) @@ -39,3 +42,24 @@ func TestHandleInstallFromConfig_NothingMissing(t *testing.T) { t.Fatalf("expected 200, got %d: %s", rr.Code, rr.Body.String()) } } + +func TestHandleMissingConfigEntries_ProjectModeChecksProjectSource(t *testing.T) { + s, root := newTestProjectServerWithExtras(t, nil) + s.projectCfg.Skills = []config.SkillEntry{{Name: "present", Source: "github.com/team/skills/present"}, {Name: "absent", Source: "github.com/team/skills/absent"}} + // Only the project source has "present"; the global source has neither. + if err := os.MkdirAll(filepath.Join(s.projectCfg.EffectiveSkillsSource(root), "present"), 0o755); err != nil { + t.Fatal(err) + } + + rr := httptest.NewRecorder() + s.handleMissingConfigEntries(rr, httptest.NewRequest(http.MethodGet, "/api/install/missing", nil)) + var resp struct { + Entries []configEntryInfo `json:"entries"` + } + if err := json.Unmarshal(rr.Body.Bytes(), &resp); err != nil { + t.Fatal(err) + } + if len(resp.Entries) != 1 || resp.Entries[0].Name != "absent" { + t.Fatalf("entries = %+v, want only absent", resp.Entries) + } +}