mirror of
https://gh-proxy.org/https://github.com/klinsmaya/CLIProxyAPI.git
synced 2026-11-08 01:16:47 +08:00
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:
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user