feat(pluginstore): make registry version field optional

The latest release is now the source of truth for plugin versions, so
the registry version only serves as a display fallback. Validate its
format only when present.
This commit is contained in:
LTbinglingfeng
2026-06-13 04:10:11 +08:00
parent 220b4e5bbd
commit b2b5d10b75
2 changed files with 18 additions and 2 deletions
+3 -2
View File
@@ -94,7 +94,6 @@ func ValidatePlugin(plugin Plugin) error {
"name": plugin.Name,
"description": plugin.Description,
"author": plugin.Author,
"version": plugin.Version,
"repository": plugin.Repository,
}
for field, value := range required {
@@ -105,7 +104,9 @@ func ValidatePlugin(plugin Plugin) error {
if !pluginhost.ValidatePluginID(strings.TrimSpace(plugin.ID)) {
return fmt.Errorf("invalid plugin id %q", plugin.ID)
}
if !validPluginVersion(strings.TrimSpace(plugin.Version)) {
// The version is optional since the latest release is the source of truth;
// when present it is only used as a display fallback and must be valid.
if version := strings.TrimSpace(plugin.Version); version != "" && !validPluginVersion(version) {
return fmt.Errorf("invalid plugin version %q", plugin.Version)
}
if _, _, errRepository := GitHubRepositoryParts(plugin.Repository); errRepository != nil {
+15
View File
@@ -68,6 +68,21 @@ func TestParseRegistryNormalizesPluginFields(t *testing.T) {
}
}
func TestValidateRegistryAllowsMissingVersion(t *testing.T) {
t.Parallel()
registry := Registry{SchemaVersion: 1, Plugins: []Plugin{{
ID: "sample-provider",
Name: "Sample Provider",
Description: "Adds sample provider support.",
Author: "author-name",
Repository: "https://github.com/author-name/cliproxy-sample-provider-plugin",
}}}
if errValidate := ValidateRegistry(registry); errValidate != nil {
t.Fatalf("ValidateRegistry() error = %v, want nil for missing version", errValidate)
}
}
func TestValidateRegistryRejectsInvalidEntries(t *testing.T) {
t.Parallel()