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.
This commit is contained in:
yetone
2026-10-15 03:34:58 +08:00
parent 1ad60446ff
commit 8bf98110b8
2 changed files with 35 additions and 2 deletions
+28
View File
@@ -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)
}
}
}
+7 -2
View File
@@ -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: