mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
fix(dashboard): detect a visible project directory
Two handlers checked for a project's own config by statting .skillshare/config.yaml directly, so a project created with init -p --visible (directory skillshare/) was reported as not having one, and the MCP page missed its override conflict. Both now ask projectdir.Find, which the CLI already uses. Refs #437
This commit is contained in:
@@ -6,8 +6,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -15,6 +13,7 @@ import (
|
||||
|
||||
"skillshare/internal/config"
|
||||
"skillshare/internal/mcp"
|
||||
"skillshare/internal/projectdir"
|
||||
syncpkg "skillshare/internal/sync"
|
||||
)
|
||||
|
||||
@@ -82,7 +81,7 @@ func (s *Server) handleMCPList(w http.ResponseWriter, r *http.Request) {
|
||||
// conflict when both hold one entry, so the dashboard says so up front.
|
||||
ownConfig := []string{}
|
||||
for root := range source.Projects {
|
||||
if _, err := os.Stat(filepath.Join(root, ".skillshare", "config.yaml")); err == nil {
|
||||
if _, ok := projectdir.Find(root); ok {
|
||||
ownConfig = append(ownConfig, root)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"skillshare/internal/config"
|
||||
"skillshare/internal/projectdir"
|
||||
ssync "skillshare/internal/sync"
|
||||
)
|
||||
|
||||
@@ -67,8 +68,8 @@ func (r *projectResource) config() *config.ResourceTargetConfig {
|
||||
// hasOwnProjectConfig reports a folder that project mode manages too. Sync never
|
||||
// overwrites what it does not own there, so the dashboard says so up front.
|
||||
func hasOwnProjectConfig(root string) bool {
|
||||
_, err := os.Stat(filepath.Join(root, ".skillshare", "config.yaml"))
|
||||
return err == nil
|
||||
_, ok := projectdir.Find(root)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (s *Server) requireGlobalProjects(next http.HandlerFunc) http.HandlerFunc {
|
||||
|
||||
@@ -30,6 +30,26 @@ func addProject(t *testing.T, s *Server, root string) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestListProjects_DetectsVisibleProjectConfig(t *testing.T) {
|
||||
s, src := newTestServer(t)
|
||||
root := filepath.Join(filepath.Dir(src), "app")
|
||||
addProject(t, s, root)
|
||||
if err := os.MkdirAll(filepath.Join(root, "skillshare"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(root, "skillshare", "config.yaml"), []byte("targets:\n - claude\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var listed struct {
|
||||
Projects []projectItem `json:"projects"`
|
||||
}
|
||||
json.Unmarshal(projectRequest(t, s, http.MethodGet, "/api/projects", "").Body.Bytes(), &listed)
|
||||
if len(listed.Projects) != 1 || !listed.Projects[0].HasOwnConfig {
|
||||
t.Fatalf("projects %+v, want hasOwnConfig for the visible project dir", listed.Projects)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSaveProject_AddsTargetsThatOnlyTheProjectScopeLists(t *testing.T) {
|
||||
s, src := newTestServer(t)
|
||||
root := filepath.Join(filepath.Dir(src), "app")
|
||||
|
||||
Reference in New Issue
Block a user