fix(server): use token auth when checking default-branch skill remotes

The dashboard check fetched the remote HEAD without credentials when a
skill had no pinned branch. Private repos therefore reported an error in
the dashboard while the CLI check, which uses
GetRemoteHeadHashWithAuth, succeeded. The pinned-branch path already
used auth, and the default-branch path now matches it.
This commit is contained in:
Willie
2026-09-30 01:44:50 +08:00
parent 1c8e462179
commit 115236a6fb
2 changed files with 28 additions and 1 deletions
+1 -1
View File
@@ -184,5 +184,5 @@ func (g urlBranchGroup) remoteHash() (string, error) {
if g.branch != "" {
return git.GetRemoteRefHashWithAuth(g.url, g.branch)
}
return git.GetRemoteHeadHash(g.url)
return git.GetRemoteHeadHashWithAuth(g.url)
}
+27
View File
@@ -6,6 +6,7 @@ import (
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
)
@@ -71,3 +72,29 @@ func TestHandleCheck_DirtyCheckErrorReported(t *testing.T) {
t.Fatalf("expected one repo with status error, got %+v", resp.TrackedRepos)
}
}
// TestURLBranchGroupRemoteHash_DefaultBranchUsesAuth verifies that a skill
// without a pinned branch still probes the remote HEAD with token auth, as the
// CLI check does. The fake git answers ls-remote only when the auth env
// carries the token.
func TestURLBranchGroupRemoteHash_DefaultBranchUsesAuth(t *testing.T) {
const token = "ghp_check_default_branch_token"
fakeBin := t.TempDir()
script := "#!/bin/sh\n" +
"case \"$GIT_CONFIG_KEY_0\" in *" + token + "*) ;; *) echo 'fatal: Authentication failed' >&2; exit 128;; esac\n" +
"printf '0123456789abcdef0123456789abcdef01234567\\tHEAD\\n'\n"
if err := os.WriteFile(filepath.Join(fakeBin, "git"), []byte(script), 0755); err != nil {
t.Fatal(err)
}
t.Setenv("PATH", fakeBin+string(os.PathListSeparator)+os.Getenv("PATH"))
t.Setenv("GIT_CONFIG_COUNT", "")
t.Setenv("GITHUB_TOKEN", token)
hash, err := urlBranchGroup{url: "https://github.com/org/private-skills.git"}.remoteHash()
if err != nil {
t.Fatalf("remoteHash without branch failed: %v", err)
}
if !strings.HasPrefix("0123456789abcdef0123456789abcdef01234567", hash) || hash == "" {
t.Fatalf("unexpected hash %q", hash)
}
}