mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 12:23:22 +00:00
fix(plugin): name Skillshare-installed packages in Pi project views
Codex review on #399: piProjectState never set ManagedBy, unlike piGlobalState. A project's Extensions tab (<project>@pi, or pi in project mode) therefore titled a plugin Skillshare installed by its state path and dropped the "Managed by Skillshare" tag, for both the project's own entries and the global entries it inherits. The lookup by source, then by resolved local path, moves into piManagedBy and runs for every package of both views.
This commit is contained in:
@@ -594,10 +594,7 @@ func (s *Service) piGlobalState(ctx context.Context, target string) (*piTargetSt
|
||||
p := openPiPackage(e.source, agentDir, "", "user")
|
||||
st.packages[e.index] = p
|
||||
pkg.Kind, pkg.Identity, pkg.Install, pkg.Problem = p.src.kind, redactSource(p.src.identity), p.install, p.problem
|
||||
pkg.ManagedBy = managed[strings.TrimSpace(e.source)]
|
||||
if pkg.ManagedBy == "" && p.src.kind == "local" {
|
||||
pkg.ManagedBy = managed[p.src.install]
|
||||
}
|
||||
pkg.ManagedBy = piManagedBy(managed, e.source, p.src)
|
||||
switch {
|
||||
case p.src.identity != "" && seen[p.src.identity]:
|
||||
// Pi keeps the first entry of a package and ignores the rest.
|
||||
@@ -643,6 +640,15 @@ func (s *Service) piManaged(target string) map[string]string {
|
||||
return result
|
||||
}
|
||||
|
||||
// piManagedBy is the plugin that owns a settings entry: Skillshare records a Pi
|
||||
// binding by its source, or for a local package by the path it resolves to.
|
||||
func piManagedBy(managed map[string]string, source string, src piSource) string {
|
||||
if name := managed[strings.TrimSpace(source)]; name != "" || src.kind != "local" {
|
||||
return name
|
||||
}
|
||||
return managed[src.install]
|
||||
}
|
||||
|
||||
// piFolders lists the extensions Pi discovers in baseDir/extensions and the paths
|
||||
// listed in the settings' own "extensions", which apply to them as overrides.
|
||||
func (s *Service) piFolders(baseDir string, settings *piSettings) []PiExtensionFolder {
|
||||
|
||||
@@ -89,6 +89,7 @@ func (s *Service) piProjectState(ctx context.Context, target string) (*piProject
|
||||
rows []piRowState
|
||||
problem string
|
||||
}
|
||||
managed := s.piManaged(target)
|
||||
globals := map[string]*globalPkg{}
|
||||
globalOrder := []*globalPkg{}
|
||||
unresolvedGlobal := false
|
||||
@@ -146,8 +147,10 @@ func (s *Service) piProjectState(ctx context.Context, target string) (*piProject
|
||||
v.Packages = append(v.Packages, pkg)
|
||||
continue
|
||||
}
|
||||
id := resolvePiSource(e.source, agentDir, projectDir, "project").identity
|
||||
src := resolvePiSource(e.source, agentDir, projectDir, "project")
|
||||
id := src.identity
|
||||
pkg.Identity = redactSource(id)
|
||||
pkg.ManagedBy = piManagedBy(managed, e.source, src)
|
||||
if id != "" && lastProject[id] != e.index {
|
||||
pkg.Problem = "duplicate"
|
||||
v.Packages = append(v.Packages, pkg)
|
||||
@@ -217,6 +220,7 @@ func (s *Service) piProjectState(ctx context.Context, target string) (*piProject
|
||||
if g.entry.hasRules {
|
||||
pkg.Rules = g.entry.rules
|
||||
}
|
||||
pkg.ManagedBy = piManagedBy(managed, g.entry.source, g.pkg.src)
|
||||
reference, readOnly := piOverrideReference(g.entry.source, g.pkg, agentDir, projectDir)
|
||||
pkg.ReadOnly = readOnly
|
||||
for _, r := range g.rows {
|
||||
|
||||
@@ -425,6 +425,25 @@ func TestPiExtensionsUnruledInAnOverrideIsTheInheritedSelection(t *testing.T) {
|
||||
assertRows(t, got, "extensions/a.ts:loads", "extensions/c.ts:skipped", "extensions/b.ts:")
|
||||
}
|
||||
|
||||
// A project view names the plugin Skillshare installed, for the project's entry and an inherited global one.
|
||||
func TestPiProjectExtensionsNameTheManagedPlugin(t *testing.T) {
|
||||
for _, project := range []bool{true, false} {
|
||||
f := newPiFixture(t)
|
||||
root := filepath.Join(f.home, "code", "acme")
|
||||
writeTree(t, f.home, map[string]string{"config.yaml": "plugins:\n packages:\n powers:\n bindings:\n pi:\n id: " + f.pkg + "\n"})
|
||||
f.global(map[string]any{"packages": []any{f.pkg}})
|
||||
entries := []any{}
|
||||
if project {
|
||||
entries = append(entries, map[string]any{"source": f.pkg, "autoload": false, "extensions": []string{"-extensions/a.ts"}})
|
||||
}
|
||||
f.writeJSON(filepath.Join(root, ".pi", "settings.json"), map[string]any{"packages": entries})
|
||||
f.svc.ProjectRoot = root
|
||||
if got := f.view("pi").Packages[0]; got.ManagedBy != "powers" {
|
||||
t.Fatalf("project entry %v: managedBy = %q, scope %s", project, got.ManagedBy, got.Scope)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPiExtensionsMarksAnExtraInPisFolder(t *testing.T) {
|
||||
f := newPiFixture(t)
|
||||
extra := filepath.Join(f.home, "extras", "pi-ext")
|
||||
|
||||
Reference in New Issue
Block a user