mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
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.
66 lines
2.2 KiB
Go
66 lines
2.2 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"skillshare/internal/config"
|
|
"skillshare/internal/install"
|
|
)
|
|
|
|
func TestHandleMissingConfigEntries_ListsAbsentEntries(t *testing.T) {
|
|
s, src := newTestServer(t)
|
|
store := install.LoadMetadataOrNew(src)
|
|
store.Set("_team-skills", &install.MetadataEntry{Source: "https://github.com/team/skills.git", Tracked: true, Branch: "main"})
|
|
if err := store.Save(src); err != nil {
|
|
t.Fatalf("save metadata: %v", 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)
|
|
}
|
|
want := configEntryInfo{Name: "_team-skills", Source: "https://github.com/team/skills.git", Tracked: true, Branch: "main"}
|
|
if len(resp.Entries) != 1 || resp.Entries[0] != want {
|
|
t.Fatalf("entries = %+v, want [%+v]", resp.Entries, want)
|
|
}
|
|
}
|
|
|
|
func TestHandleInstallFromConfig_NothingMissing(t *testing.T) {
|
|
s, _ := newTestServer(t)
|
|
rr := httptest.NewRecorder()
|
|
s.handleInstallFromConfig(rr, httptest.NewRequest(http.MethodPost, "/api/install/from-config", nil))
|
|
if rr.Code != http.StatusOK {
|
|
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)
|
|
}
|
|
}
|