mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 12:23:22 +00:00
fix(plugin): let an imported Claude plugin update to what its marketplace holds (#536)
An imported plugin's native marketplace decides the version an update installs, so the update check now applies only to bindings with a reviewed source and an import records the version installed. Importing an imported plugin again also records the installed version; a source binding keeps the version Skillshare reviewed. Refs #535
This commit is contained in:
@@ -132,13 +132,14 @@ func (s *Service) materialize(ctx context.Context, b Binding, target string) (st
|
||||
return expected, nil
|
||||
}
|
||||
|
||||
func (s *Service) applyChange(ctx context.Context, c Change, b Binding) (resultErr error) {
|
||||
// applyChange records in b the version an imported plugin's update installed.
|
||||
func (s *Service) applyChange(ctx context.Context, c Change, b *Binding) (resultErr error) {
|
||||
if b.Source != "" && (c.Action == "install" || c.Action == "update") {
|
||||
if _, err := os.Stat(s.snapshotPath(b, c.Target) + ".previous"); err == nil {
|
||||
if _, err := os.Stat(s.snapshotPath(*b, c.Target) + ".previous"); err == nil {
|
||||
return fmt.Errorf("unfinished snapshot replacement; inspect previous snapshot before retrying")
|
||||
}
|
||||
defer func() {
|
||||
path := s.snapshotPath(b, c.Target)
|
||||
path := s.snapshotPath(*b, c.Target)
|
||||
backup := path + ".previous"
|
||||
if _, err := os.Stat(backup); err != nil {
|
||||
return
|
||||
@@ -172,7 +173,7 @@ func (s *Service) applyChange(ctx context.Context, c Change, b Binding) (resultE
|
||||
}
|
||||
agent := s.agentOf(c.Target)
|
||||
if !marketplaceAgent(agent) {
|
||||
return s.applyAdditional(ctx, c, b)
|
||||
return s.applyAdditional(ctx, c, *b)
|
||||
}
|
||||
if agent == "omp" && c.Action == "install" {
|
||||
if err := ompEmptyRuntime(c.ompRuntimePath); err != nil {
|
||||
@@ -180,7 +181,7 @@ func (s *Service) applyChange(ctx context.Context, c Change, b Binding) (resultE
|
||||
}
|
||||
}
|
||||
if (c.Action == "install" || c.Action == "update") && b.Source != "" {
|
||||
path, err := s.materialize(ctx, b, c.Target)
|
||||
path, err := s.materialize(ctx, *b, c.Target)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -221,7 +222,7 @@ func (s *Service) applyChange(ctx context.Context, c Change, b Binding) (resultE
|
||||
if (c.Action == "remove" || c.Action == "uninstall") && b.Source != "" {
|
||||
// Removed natively already: only the marketplace Skillshare registered is left.
|
||||
if h := s.host(ctx, c.Target); h.Error == "" && !slices.ContainsFunc(h.Installed, func(i Installed) bool { return i.ID == b.ID }) {
|
||||
return s.removeMarketplace(ctx, c.Target, b)
|
||||
return s.removeMarketplace(ctx, c.Target, *b)
|
||||
}
|
||||
}
|
||||
args, err := s.nativeArgs(c.Target, c.Action, b.ID)
|
||||
@@ -256,15 +257,17 @@ func (s *Service) applyChange(ctx context.Context, c Change, b Binding) (resultE
|
||||
if c.Action == "disable" && item.Enabled {
|
||||
return fmt.Errorf("plugin is still enabled")
|
||||
}
|
||||
// An upgraded marketplace sets its own version, which Skillshare never reviewed.
|
||||
if c.Action == "update" && !upgrade && b.Version != "" && item.Version != b.Version {
|
||||
// An import updates to whatever its native marketplace holds, which Skillshare never reviewed.
|
||||
if c.Action == "update" && b.Source == "" {
|
||||
b.Version = item.Version
|
||||
} else if c.Action == "update" && b.Version != "" && item.Version != b.Version {
|
||||
return fmt.Errorf("native update returned version %s; expected %s", item.Version, b.Version)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if c.Action == "remove" || c.Action == "uninstall" {
|
||||
return s.removeMarketplace(ctx, c.Target, b)
|
||||
return s.removeMarketplace(ctx, c.Target, *b)
|
||||
}
|
||||
return fmt.Errorf("native operation completed but plugin was not found; inspect the native client before retrying")
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ func (s *Service) applyPlan(ctx context.Context, r Request, p *Plan) (*Result, e
|
||||
}
|
||||
b := d.packages[c.Name].Bindings[c.Target]
|
||||
c.piRestores = piRestores
|
||||
applyErr := s.applyChange(ctx, c, b)
|
||||
applyErr := s.applyChange(ctx, c, &b)
|
||||
outcome := Outcome{Name: c.Name, Target: c.Target, Status: "installed", Message: "Native installation recorded. Reload the Agent and complete any required login or hook trust."}
|
||||
if applyErr != nil {
|
||||
outcome.Status = "failed"
|
||||
|
||||
@@ -399,6 +399,10 @@ func (s *Service) Preview(ctx context.Context, r Request) (*Plan, error) {
|
||||
if old.ID != b.ID {
|
||||
return nil, fmt.Errorf("package already manages a different plugin")
|
||||
}
|
||||
// An import follows what is installed; a source binding keeps the version Skillshare reviewed.
|
||||
if old.Source == "" {
|
||||
old.Version = installed.Version
|
||||
}
|
||||
b = old
|
||||
}
|
||||
change := Change{Name: name, Target: r.From, ID: b.ID, Binding: b, Action: "import", Message: "Record the existing native installation; leave its content and enabled state unchanged."}
|
||||
|
||||
@@ -805,6 +805,87 @@ func TestCodexUpdateOfAnImportUpgradesItsMarketplace(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// importedDemo imports demo@team from Claude into a package that also has a source, as when
|
||||
// another Agent was added from it, and leaves the Claude update pending at 1.0.0.
|
||||
func importedDemo(t *testing.T) (*Service, *fakeAgents) {
|
||||
t.Helper()
|
||||
agents := &fakeAgents{version: "2.0.0", installed: map[string][]Installed{"claude": {{ID: "demo@team", PluginID: "demo@team", Installed: true, Enabled: true, Version: "1.0.0", Scope: "user"}}}, markets: map[string]map[string]string{"claude": {"team": "/team"}}}
|
||||
s := agents.service(t)
|
||||
applyPluginRequest(t, s, Request{Action: "import", From: "claude", Plugin: "demo@team"})
|
||||
cfg, err := s.load()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pack := cfg.packages["demo"]
|
||||
pack.Source = "https://example.com/demo"
|
||||
b := pack.Bindings["claude"]
|
||||
b.Pending = "update"
|
||||
pack.Bindings["claude"] = b
|
||||
cfg.packages["demo"] = pack
|
||||
if err := s.save(cfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return s, agents
|
||||
}
|
||||
|
||||
func loadBinding(t *testing.T, s *Service) Binding {
|
||||
t.Helper()
|
||||
cfg, err := s.load()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return cfg.packages["demo"].Bindings["claude"]
|
||||
}
|
||||
|
||||
// An imported plugin updates to whatever its native marketplace now holds, and records it.
|
||||
func TestClaudeUpdateOfAnImportRecordsTheVersionItInstalled(t *testing.T) {
|
||||
s, _ := importedDemo(t)
|
||||
applyPluginRequest(t, s, Request{Action: "update", Name: "demo", Targets: []string{"claude"}})
|
||||
if b := loadBinding(t, s); b.Version != "2.0.0" || b.Pending != "" {
|
||||
t.Fatalf("binding: %+v", b)
|
||||
}
|
||||
}
|
||||
|
||||
// The dashboard's batch update takes the same path for an import.
|
||||
func TestBatchUpdateOfAnImportRecordsTheVersionItInstalled(t *testing.T) {
|
||||
s, _ := importedDemo(t)
|
||||
unlock, err := s.Lock()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer unlock()
|
||||
if _, err := updateDemo(s, map[string]Seen{"claude": {Version: "1.0.0"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if b := loadBinding(t, s); b.Version != "2.0.0" {
|
||||
t.Fatalf("binding: %+v", b)
|
||||
}
|
||||
}
|
||||
|
||||
// Importing again records the version the native client has now, not the one first imported.
|
||||
func TestImportAgainRecordsTheInstalledVersion(t *testing.T) {
|
||||
agents := &fakeAgents{installed: map[string][]Installed{"claude": {{ID: "demo@team", PluginID: "demo@team", Installed: true, Enabled: true, Version: "1.0.0", Scope: "user"}}}, markets: map[string]map[string]string{"claude": {"team": "/team"}}}
|
||||
s := agents.service(t)
|
||||
applyPluginRequest(t, s, Request{Action: "import", From: "claude", Plugin: "demo@team"})
|
||||
agents.installed["claude"][0].Version = "2.0.0"
|
||||
applyPluginRequest(t, s, Request{Action: "import", From: "claude", Plugin: "demo@team"})
|
||||
if cfg, _ := s.load(); cfg.packages["demo"].Bindings["claude"].Version != "2.0.0" {
|
||||
t.Fatalf("binding: %+v", cfg.packages["demo"].Bindings["claude"])
|
||||
}
|
||||
}
|
||||
|
||||
// A binding added from a source keeps the version Skillshare reviewed when imported again.
|
||||
func TestImportAgainKeepsTheReviewedVersion(t *testing.T) {
|
||||
agents := &fakeAgents{version: "1.0.0"}
|
||||
s := agents.service(t)
|
||||
applyPluginRequest(t, s, Request{Action: "add", Source: fixture(t), Targets: []string{"claude"}})
|
||||
agents.installed["claude"][0].Version = "native-1"
|
||||
applyPluginRequest(t, s, Request{Action: "import", From: "claude", Plugin: agents.installed["claude"][0].ID, Name: "demo"})
|
||||
if b := loadBinding(t, s); b.Version != "1.0.0" {
|
||||
t.Fatalf("binding: %+v", b)
|
||||
}
|
||||
}
|
||||
|
||||
// A skipped update stays pending, so a later sync still knows the plugin is behind.
|
||||
func TestSkippedUpdateStaysPending(t *testing.T) {
|
||||
agents := &fakeAgents{version: "1.0.0"}
|
||||
|
||||
Reference in New Issue
Block a user