diff --git a/internal/server/handler_mcp.go b/internal/server/handler_mcp.go index 4191f0d49..9c891f476 100644 --- a/internal/server/handler_mcp.go +++ b/internal/server/handler_mcp.go @@ -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) } } diff --git a/internal/server/handler_projects.go b/internal/server/handler_projects.go index d562a8d24..326599f95 100644 --- a/internal/server/handler_projects.go +++ b/internal/server/handler_projects.go @@ -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 { diff --git a/internal/server/handler_projects_test.go b/internal/server/handler_projects_test.go index d3926a8b8..bccf403fd 100644 --- a/internal/server/handler_projects_test.go +++ b/internal/server/handler_projects_test.go @@ -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")