feat(kiosk): resolve constant plugin IDs, overrides and the CheckT helper

- kiosk.ReadIdentity: ID()/Requires() as literals or constants across packages and modules, read with go/parser, never run
- plugin minimums from go.mod requires; v0.0.0 is an error, a pseudo-version warns
- kiosk.Validate, kiosk.CheckT (no testing import)
- plugin:add reads IDs through kiosk.ReadIdentity, so const-ID plugins register
This commit is contained in:
Jakub Zych
2026-10-29 17:02:38 +01:00
parent ec6a1955fc
commit 51ec2f9daa
22 changed files with 1156 additions and 115 deletions

View File

@@ -3,7 +3,9 @@ package kiosk
import (
"bytes"
"fmt"
"regexp"
"sort"
"strings"
"github.com/goccy/go-yaml"
)
@@ -86,5 +88,76 @@ func Parse(data []byte) (Manifest, error) {
if m.Schema > SchemaVersion {
return Manifest{}, fmt.Errorf("kiosk: %s has schema %d, this summer reads up to %d; update summer", FileName, m.Schema, SchemaVersion)
}
if err := Validate(m); err != nil {
return Manifest{}, err
}
return m, nil
}
var (
pluginIDRe = regexp.MustCompile(`^[a-z][a-z0-9]*\.[a-z][a-z0-9]*$`)
releaseVersion = regexp.MustCompile(`^v\d+\.\d+\.\d+$`)
)
// Validate checks a manifest: the schema is between 1 and SchemaVersion,
// the ID and every required ID are lowercase vendor.plugin, module and
// package are plain module paths (package inside module), name and
// description are set, and the framework and every non-empty plugin
// minimum is a vX.Y.Z release or a Go pseudo-version.
func Validate(m Manifest) error {
if m.Schema < 1 || m.Schema > SchemaVersion {
return fmt.Errorf("kiosk: schema %d is not between 1 and %d", m.Schema, SchemaVersion)
}
if !pluginIDRe.MatchString(m.ID) {
return fmt.Errorf("kiosk: id %q must be lowercase vendor.plugin", m.ID)
}
if err := validPath(m.Module); err != nil {
return fmt.Errorf("kiosk: module: %w", err)
}
if err := validPath(m.Package); err != nil {
return fmt.Errorf("kiosk: package: %w", err)
}
if m.Package != m.Module && !strings.HasPrefix(m.Package, m.Module+"/") {
return fmt.Errorf("kiosk: package %q is not inside module %q", m.Package, m.Module)
}
if strings.TrimSpace(m.Name) == "" {
return fmt.Errorf("kiosk: name is empty")
}
if strings.TrimSpace(m.Description) == "" {
return fmt.Errorf("kiosk: description is empty")
}
if !releaseOrPseudo(m.Framework) {
return fmt.Errorf("kiosk: framework %q must be a vX.Y.Z release", m.Framework)
}
for id, v := range m.Requires {
if !pluginIDRe.MatchString(id) {
return fmt.Errorf("kiosk: required id %q must be lowercase vendor.plugin", id)
}
if v != "" && !releaseOrPseudo(v) {
return fmt.Errorf("kiosk: minimum %q of %s must be a vX.Y.Z release", v, id)
}
}
return nil
}
func releaseOrPseudo(v string) bool {
return releaseVersion.MatchString(v) || isPseudoVersion(v)
}
// validPath accepts a slash-separated module or import path.
func validPath(p string) error {
switch {
case p == "":
return fmt.Errorf("is empty")
case strings.HasPrefix(p, "-"):
return fmt.Errorf("%q must not start with -", p)
case strings.ContainsAny(p, " \t\r\n\\\"'`$;&|*?<>()[]{}@"):
return fmt.Errorf("%q contains invalid characters", p)
}
for _, seg := range strings.Split(p, "/") {
if seg == "" || seg == "." || seg == ".." {
return fmt.Errorf("%q has an invalid path segment", p)
}
}
return nil
}