From fd18cda6554e6ea6262d4ff0684bf8c122a3ec24 Mon Sep 17 00:00:00 2001 From: Willie Date: Tue, 13 Oct 2026 03:33:28 +0800 Subject: [PATCH] fix(plugin): read plugin sources through their real path on macOS (#544) Adding a plugin from a Git URL to Oh My Pi on macOS was always blocked with "linked or non-directory OMP path component", which the dashboard shows as "The reviewed OMP runtime destination must be verified empty". The source is cloned into os.MkdirTemp, which lives under /var/folders, and /var links to /private/var. The OMP install check reads the source's package.json through ompSafePath, which rejects any linked component, so Skillshare's own temp clone failed it. A local source under a linked parent failed the same way. acquireRef now hands callers the resolved root of the temp clone and of a local directory, while the recorded source stays as given. Links inside the source are still handled as before; cleanup still removes the original temp directory. --- internal/plugin/omp_test.go | 15 +++++++++++++++ internal/plugin/source.go | 14 ++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/internal/plugin/omp_test.go b/internal/plugin/omp_test.go index fbd07bb04..61fffa13a 100644 --- a/internal/plugin/omp_test.go +++ b/internal/plugin/omp_test.go @@ -181,6 +181,21 @@ func TestOMPAddInstallsFromTheSnapshotMarketplace(t *testing.T) { } } +// macOS temp clones live under /var, a link to /private/var; the source location is not an OMP path. +func TestOMPAddReadsSourceBehindLinkedDirectory(t *testing.T) { + agents := &fakeAgents{version: "1.0.0"} + s := agents.service(t) + source := fixture(t) + link := filepath.Join(t.TempDir(), "linked") + if err := os.Symlink(filepath.Dir(source), link); err != nil { + t.Fatal(err) + } + p, err := s.Preview(context.Background(), Request{Action: "add", Source: filepath.Join(link, filepath.Base(source)), Targets: []string{"omp"}}) + if err != nil || len(p.Changes) != 1 || p.Changes[0].Action != "install" { + t.Fatalf("source behind a linked directory was not installable: %+v %v", p, err) + } +} + // omp deletes a plugin's cache folder on uninstall and replaces it on upgrade, checking only the // registries visible from its working directory. A project elsewhere that installed the same // identity is invisible, so Skillshare never runs those commands. Scoped removal uses diff --git a/internal/plugin/source.go b/internal/plugin/source.go index a4e70a090..db29585ee 100644 --- a/internal/plugin/source.go +++ b/internal/plugin/source.go @@ -48,7 +48,12 @@ func acquireRef(ctx context.Context, source, ref string) (string, string, func() return "", "", cleanup, fmt.Errorf("source ref requires a remote Git source") } p, err := filepath.Abs(source) - return p, p, cleanup, err + if err != nil { + return "", "", cleanup, err + } + // Read from the real location: a linked parent (macOS /var -> /private/var) is not plugin content. + root, err := filepath.EvalSymlinks(p) + return root, p, cleanup, err } if isNpmSource(source) { return "", "", cleanup, fmt.Errorf("npm packages can't be previewed: Pi downloads them when it installs them. Add one to a Pi target with: skillshare plugin add %s --target pi", source) @@ -65,6 +70,11 @@ func acquireRef(ctx context.Context, source, ref string) (string, string, func() return "", "", cleanup, err } cleanup = func() { _ = os.RemoveAll(root) } + clone, err := filepath.EvalSymlinks(root) + if err != nil { + cleanup() + return "", "", func() {}, err + } _, err = runCommand(ctx, "", nil, "git", "-c", "core.hooksPath=/dev/null", "clone", "--depth", "1", "--", source, root) if err != nil { cleanup() @@ -79,7 +89,7 @@ func acquireRef(ctx context.Context, source, ref string) (string, string, func() return "", "", func() {}, fmt.Errorf("resolve source ref: %w", err) } } - return root, source, cleanup, nil + return clone, source, cleanup, nil } // treeDigest includes safe relative links, leaves out unsafe ones and rejects special files.