fix(kiosk): fetch a required plugin module whose replace directory is missing

A plugin developed inside an application replaces its required plugins
with sibling directories (../user). Checked out on its own, that
directory is missing and plugin.yaml lost the minimum (golem15.user: ""),
so the manifest differed between the two layouts and TestPluginManifest
could not pass in both. Such a module is now fetched at the version
go.mod requires, as a consumer would see it.

- listedModule.fallback marks a local replace whose directory is absent
- fallback modules download separately, so one unfetchable version does
  not hold up the others
- TestDeriveMissingReplace over a file:// proxy (offline)
This commit is contained in:
Jakub Zych
2026-10-29 23:18:07 +01:00
parent a9237c8ec3
commit 87921c27f6
4 changed files with 140 additions and 9 deletions

View File

@@ -78,6 +78,10 @@ type listedModule struct {
Dir string
GoMod string
Error *struct{ Err string }
// fallback marks a module replaced by a local directory that is not
// there; its Dir and GoMod are cleared so it is fetched at Version.
fallback bool
}
func newResolver(ctx context.Context, start string) *resolver {
@@ -447,6 +451,13 @@ func (r *resolver) list(paths []string) ([]listedModule, error) {
if err := dec.Decode(&m); err != nil {
return nil, fmt.Errorf("kiosk: go list -m: %w", err)
}
// A replace to a directory that is not checked out here (one
// that only exists where the plugin is mounted in an
// application) says nothing about the module: use the version
// go.mod requires, as a consumer of the plugin would.
if m.Dir != "" && m.Error == nil && !isDir(m.Dir) {
m.Dir, m.GoMod, m.fallback = "", "", true
}
r.modDirs[m.Path] = m
}
}
@@ -529,19 +540,28 @@ func (r *resolver) minimums(ids []string) (Requires, []string, error) {
if err != nil {
return nil, nil, err
}
// Only a module whose go.mod requires the framework can hold a plugin.
var candidates []listedModule
// Only a module whose go.mod requires the framework can hold a
// plugin. A fallback module is fetched first and checked after,
// in its own download so a version that cannot be fetched does not
// hold up the others.
var candidates, fallbacks []listedModule
for _, m := range listed {
if m.Error == nil && requiresFramework(m) {
switch {
case m.Error != nil:
case m.fallback && m.Version != "" && m.Version != "v0.0.0":
fallbacks = append(fallbacks, m)
case requiresFramework(m):
candidates = append(candidates, m)
}
}
if err := r.download(candidates); err != nil {
warnings = append(warnings, fmt.Sprintf("required plugins not matched to modules: %v", err))
for _, mods := range [][]listedModule{candidates, fallbacks} {
if err := r.download(mods); err != nil {
warnings = append(warnings, fmt.Sprintf("required plugins not matched to modules: %v", err))
}
}
for _, m := range candidates {
for _, m := range append(candidates, fallbacks...) {
m = r.modDirs[m.Path]
if m.Dir == "" {
if m.Dir == "" || (m.fallback && !requiresFramework(m)) {
continue
}
for _, d := range pluginDirs(m.Dir) {
@@ -576,6 +596,12 @@ func (r *resolver) minimums(ids []string) (Requires, []string, error) {
return out, warnings, nil
}
// isDir reports whether path is an existing directory.
func isDir(path string) bool {
fi, err := os.Stat(path)
return err == nil && fi.IsDir()
}
// requiresFramework reports whether the module's go.mod names the
// framework module.
func requiresFramework(m listedModule) bool {