diff --git a/pkg/skills/config_bridge.go b/pkg/skills/config_bridge.go index 49febfbd9..bb607401b 100644 --- a/pkg/skills/config_bridge.go +++ b/pkg/skills/config_bridge.go @@ -2,6 +2,8 @@ package skills import "github.com/sipeed/picoclaw/pkg/config" +const defaultGitHubRegistryBaseURL = "https://github.com" + func effectiveRegistryConfigsFromToolsConfig(cfg config.SkillsToolsConfig) []config.SkillRegistryConfig { effective := make([]config.SkillRegistryConfig, 0, len(cfg.Registries)+1) seen := map[string]struct{}{} @@ -44,7 +46,10 @@ func applyLegacyGithubRegistryCompatibility( if registryCfg.Param == nil { registryCfg.Param = map[string]any{} } - if registryCfg.BaseURL == "" { + if registryCfg.BaseURL == "" || + (registryCfg.BaseURL == defaultGitHubRegistryBaseURL && + cfg.Github.BaseURL != "" && + cfg.Github.BaseURL != defaultGitHubRegistryBaseURL) { registryCfg.BaseURL = cfg.Github.BaseURL } if registryCfg.AuthToken.String() == "" { diff --git a/pkg/skills/registry_test.go b/pkg/skills/registry_test.go index a50f8831c..b870b3df9 100644 --- a/pkg/skills/registry_test.go +++ b/pkg/skills/registry_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/assert" + "github.com/sipeed/picoclaw/pkg/config" "github.com/sipeed/picoclaw/pkg/utils" ) @@ -207,3 +208,33 @@ func TestIsSafeSlug(t *testing.T) { assert.Error(t, utils.ValidateSkillIdentifier("path/traversal")) assert.Error(t, utils.ValidateSkillIdentifier("path\\traversal")) } + +func TestLegacyGithubBaseURLOverridesDefaultRegistryBaseURL(t *testing.T) { + cfg := config.DefaultConfig().Tools.Skills + cfg.Github.BaseURL = "https://ghe.example.com/git" + + registry := LookupRegistryFromToolsConfig(cfg, "github") + assert.NotNil(t, registry) + + ghRegistry, ok := registry.(*GitHubRegistry) + assert.True(t, ok) + assert.Equal(t, "https://ghe.example.com/git", ghRegistry.webBase) +} + +func TestExplicitGithubRegistryBaseURLBeatsLegacyCompat(t *testing.T) { + cfg := config.DefaultConfig().Tools.Skills + cfg.Github.BaseURL = "https://ghe-legacy.example.com/git" + cfg.Registries.Set("github", config.SkillRegistryConfig{ + Name: "github", + Enabled: true, + BaseURL: "https://ghe-explicit.example.com/scm", + Param: map[string]any{}, + }) + + registry := LookupRegistryFromToolsConfig(cfg, "github") + assert.NotNil(t, registry) + + ghRegistry, ok := registry.(*GitHubRegistry) + assert.True(t, ok) + assert.Equal(t, "https://ghe-explicit.example.com/scm", ghRegistry.webBase) +}