From 2ec925b880d083aa3856c7fae3df95ff9bba92cb Mon Sep 17 00:00:00 2001 From: Willie Date: Wed, 7 Oct 2026 13:04:58 +0800 Subject: [PATCH] fix(mcp): treat skillshare/config.yaml as a project config too configProjectRoot matched only /.skillshare/config.yaml, so a project that keeps its config in the visible skillshare/ folder was treated as a global config and its MCP saves skipped the project boundary entirely, config.yaml included. Match every project config folder name through projectdir.IsName. --- internal/mcp/lifecycle_test.go | 13 +++++++------ internal/mcp/service.go | 9 ++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/internal/mcp/lifecycle_test.go b/internal/mcp/lifecycle_test.go index a99045819..4b0e72425 100644 --- a/internal/mcp/lifecycle_test.go +++ b/internal/mcp/lifecycle_test.go @@ -41,17 +41,18 @@ func TestExternalMutationLeavesConfigUntouched(t *testing.T) { // mutation must not rewrite one outside the project. func TestProjectExternalMutationStaysInsideProject(t *testing.T) { for _, tc := range []struct { - name, source string - refused bool + name, dir, source string + refused bool }{ - {"outside the project", "../../outside.yaml", true}, - {"next to config.yaml", "./mcp.yaml", false}, - {"at the project root", "../mcp.yaml", false}, + {"outside the project", ".skillshare", "../../outside.yaml", true}, + {"outside the project, visible config folder", "skillshare", "../../outside.yaml", true}, + {"next to config.yaml", ".skillshare", "./mcp.yaml", false}, + {"at the project root", ".skillshare", "../mcp.yaml", false}, } { t.Run(tc.name, func(t *testing.T) { global := testService(t) root := filepath.Join(global.Home, "project") - configPath := filepath.Join(root, ".skillshare", "config.yaml") + configPath := filepath.Join(root, tc.dir, "config.yaml") if err := os.MkdirAll(filepath.Dir(configPath), 0755); err != nil { t.Fatal(err) } diff --git a/internal/mcp/service.go b/internal/mcp/service.go index 1d978e91d..93f397095 100644 --- a/internal/mcp/service.go +++ b/internal/mcp/service.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/gofrs/flock" + "skillshare/internal/projectdir" ) // Service is scoped to one Skillshare config; StateDir is shared across scopes @@ -33,10 +34,12 @@ type Service struct { account string } -// configProjectRoot returns the project whose own config ConfigPath is, so saves stay -// inside it. A global config scoped to a project in mcp.projects returns "". +// configProjectRoot returns the project whose own config ConfigPath is (in .skillshare/ +// or skillshare/), so saves stay inside it. A global config scoped to a project in +// mcp.projects returns "". func (s *Service) configProjectRoot() string { - if s.ProjectRoot != "" && filepath.Clean(s.ConfigPath) == filepath.Join(s.ProjectRoot, ".skillshare", "config.yaml") { + dir := filepath.Dir(filepath.Clean(s.ConfigPath)) + if s.ProjectRoot != "" && projectdir.IsName(filepath.Base(dir)) && filepath.Dir(dir) == filepath.Clean(s.ProjectRoot) { return s.ProjectRoot } return ""