mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
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.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user