fix(34): CR-02 install plugins of an installed module at its version

plugin:install pinned only modules chosen in the same plan, so a second
plugin package in a module the application already required was
installed at the newest release, moving the plugin already there, and
with --source the repository was cloned a second time. PlanInstall now
seeds every module of summer.yaml: a plugin in one installs at the
installed version with no go get or clone (only its summer.yaml entry),
and is refused with a plugin:update hint when that version has no
release of it or is not a release. A git URL whose repository is already
a submodule, or whose module the application has, is refused.
This commit is contained in:
Jakub Zych
2026-10-29 22:01:30 +01:00
parent 60551485ed
commit 9b72439533
5 changed files with 264 additions and 3 deletions

View File

@@ -438,3 +438,74 @@ func TestUpdatePseudoVersion(t *testing.T) {
}
})
}
// TestInstallSharedModule pins CR-02: a plugin in a module the
// application already has installs at the version the application has,
// fetches nothing, and is refused when that version has no release of it.
func TestInstallSharedModule(t *testing.T) {
reg := &memRegistry{}
reg.addIn("acme.pg", "example.test/pg", "example.test/pg", nil, "v0.3.0:v0.6.0", "v0.2.0:v0.6.0")
reg.addIn("acme.pgsubs", "example.test/pg", "example.test/pg/subs", nil, "v0.3.0:v0.6.0", "v0.2.0:v0.6.0")
reg.addIn("acme.pgnew", "example.test/pg", "example.test/pg/fresh", nil, "v0.3.0:v0.6.0")
reg.addIn("acme.shop", "example.test/shop", "example.test/shop", kiosk.Requires{"acme.pgsubs": ""}, "v0.1.0:v0.6.0")
plan := func(t *testing.T, app, arg string) (*InstallPlan, string, error) {
t.Helper()
var out bytes.Buffer
p, err := PlanInstall(t.Context(), InstallOptions{StartDir: app, Arg: arg, Yes: true, Registry: reg, Out: &out})
return p, out.String(), err
}
t.Run("pinned to the installed module version", func(t *testing.T) {
app := installApp(t, "v0.6.0", map[string]string{"acme.pg": "v0.2.0"})
p, out, err := plan(t, app, "acme.pgsubs")
if err != nil {
t.Fatalf("plan: %v\n%s", err, out)
}
if got := planSteps(p); got != "acme.pgsubs@v0.2.0" || !p.Steps[0].existing {
t.Fatalf("steps = %s %+v, want acme.pgsubs at the installed v0.2.0", got, p.Steps)
}
if !strings.Contains(out, "acme.pgsubs@v0.2.0 (module, module already in the application)") {
t.Errorf("plan output:\n%s", out)
}
gomod, _ := os.ReadFile(filepath.Join(app, "go.mod"))
// ApplyInstall runs no go get for it: only summer.yaml changes.
if err := ApplyInstall(t.Context(), p, nil); err != nil {
t.Fatalf("apply: %v", err)
}
after, _ := os.ReadFile(filepath.Join(app, "go.mod"))
if !bytes.Equal(gomod, after) {
t.Errorf("go.mod changed:\n%s", after)
}
yaml, _ := os.ReadFile(filepath.Join(app, manifestName))
if !strings.Contains(string(yaml), "id: acme.pgsubs\n module: example.test/pg/subs") {
t.Errorf("summer.yaml:\n%s", yaml)
}
})
t.Run("a requirement in the installed module", func(t *testing.T) {
app := installApp(t, "v0.6.0", map[string]string{"acme.pg": "v0.2.0"})
p, out, err := plan(t, app, "acme.shop")
if err != nil || planSteps(p) != "acme.pgsubs@v0.2.0,acme.shop@v0.1.0" {
t.Fatalf("plan: %v %v\n%s", p, err, out)
}
})
t.Run("refused when the installed version has no release of it", func(t *testing.T) {
app := installApp(t, "v0.6.0", map[string]string{"acme.pg": "v0.2.0"})
for _, arg := range []string{"acme.pgnew", "acme.pgsubs@v0.3.0"} {
_, out, err := plan(t, app, arg)
if err == nil || !strings.Contains(err.Error(), "lives in example.test/pg, which the application already has at v0.2.0 (for acme.pg)") ||
!strings.Contains(fullError(err), "plugin:update acme.pg") {
t.Errorf("%s: %v\n%s", arg, fullError(err), out)
}
}
})
t.Run("refused at a pseudo-version", func(t *testing.T) {
app := installApp(t, "v0.6.0", map[string]string{"acme.pg": "v0.2.1-0.20261001120000-abcdef123456"})
_, out, err := plan(t, app, "acme.pgsubs")
if err == nil || !strings.Contains(err.Error(), "not a release plugin:install can pin") {
t.Errorf("err = %v\n%s", fullError(err), out)
}
})
}