From 8bf98110b88047db0d2e480ee92067dbe1803fbc Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 15 Oct 2026 02:24:11 +0800 Subject: [PATCH] plugin: a folder plugin's path written on macOS or Linux is a path on Windows too, so a backup or a sync leaves it out (#2229, JasonBuildAI) plugin.IsPath read a spec as a path when filepath.IsAbs said so on the host. On Windows "/Users/me/plugin" is not absolute, so a folder plugin added on a Mac was carried into a backup and a WebDAV sync as if it were an npm package, and the Windows machine restoring it asked bun to install "/Users/me/plugin". A spec starting with / or \ (a UNC path among them) now counts as a path on every system, as a drive-rooted one already did off Windows. Run: - TestIsPathWhicheverSystemWroteIt (new). On the Windows box at the old code it fails for "/Users/me/plugin", "/home/me/plugin/index.js" and `\Users\me\plugin`; on macOS for the two backslash forms. Passes on both with the change. - On the Windows box, the three reds the issue names, old code then new: TestPluginsCarried (provider), TestRestorePluginsAndSignIn (backup), TestSyncPluginsAndSignIn (davsync) FAIL then PASS. - go test -tags nogui ./... on macOS with this and the next four commits: every package ok. - gofmt -l, go vet ./... on darwin, linux (nogui) and windows, and the three builds: clean. - Windows internal/plugin as a whole: TestTaggedRepos, TestTaggedReposSlowRead, TestReadmeOfTaggedRepo, TestGitPluginUpdateOnlyWhenItsRepositoryMoved, TestMarketIconsAreBundled, TestEnsurePi and TestGitPlugin fail there with and without the change (Windows-only, CI compiles them only). TestLoadConcurrentWithSavesAndEdits failed once in the full package run with the change; alone it passed 6 of 6 at the old code and 6 of 6 with it. Noted on #1827, the open issue for Windows-only reds. --- internal/plugin/ispath_test.go | 28 ++++++++++++++++++++++++++++ internal/plugin/store.go | 9 +++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 internal/plugin/ispath_test.go diff --git a/internal/plugin/ispath_test.go b/internal/plugin/ispath_test.go new file mode 100644 index 000000000..6c1ee9062 --- /dev/null +++ b/internal/plugin/ispath_test.go @@ -0,0 +1,28 @@ +package plugin + +import "testing" + +// #2229: plugins.json travels between machines in a backup or a sync, so +// a folder plugin's path written on macOS or Linux is a path on Windows +// too, and a Windows one is a path off Windows, or the restoring machine +// asks bun to install it as an npm package. +func TestIsPathWhicheverSystemWroteIt(t *testing.T) { + for spec, want := range map[string]bool{ + "/Users/me/plugin": true, + "/home/me/plugin/index.js": true, + `\Users\me\plugin`: true, + `\\server\share\plugin`: true, + `C:\plugins\x`: true, + "D:/plugins/x": true, + "file:///Users/me/plugin": true, + "./my-plugin.js": true, + "opencode-gemini-auth": false, + "@magpie-community/opencode-kiro-auth": false, + "owner/repo": false, + "github:owner/repo": false, + } { + if got := IsPath(spec); got != want { + t.Errorf("IsPath(%q) = %v, want %v", spec, got, want) + } + } +} diff --git a/internal/plugin/store.go b/internal/plugin/store.go index e81696fa0..5d6c70e59 100644 --- a/internal/plugin/store.go +++ b/internal/plugin/store.go @@ -281,11 +281,16 @@ func checkList() { } // IsPath is whether spec names a file or folder rather than a package, -// as OpenCode tells them apart. +// as OpenCode tells them apart. A path rooted the way any system roots +// one counts on every system, since plugins.json travels between +// machines in a backup or a sync: a leading / or \ (a UNC path among +// them) on Windows as well, and a drive letter off it (#2229). func IsPath(spec string) bool { - return strings.HasPrefix(spec, "file://") || strings.HasPrefix(spec, ".") || filepath.IsAbs(spec) || regexp.MustCompile(`^[A-Za-z]:[\\/]`).MatchString(spec) + return strings.HasPrefix(spec, "file://") || strings.HasPrefix(spec, ".") || strings.HasPrefix(spec, "/") || strings.HasPrefix(spec, `\`) || filepath.IsAbs(spec) || driveRooted.MatchString(spec) } +var driveRooted = regexp.MustCompile(`^[A-Za-z]:[\\/]`) + var pkgName = regexp.MustCompile(`^(@[a-z0-9][a-z0-9._~-]*/)?[a-z0-9][a-z0-9._~-]*$`) // gitSpec is a package bun fetches from a git repository, not npm: