From 115236a6fbd77a4eacdb1ccd2bee6056b8b52615 Mon Sep 17 00:00:00 2001 From: Willie Date: Wed, 30 Sep 2026 01:44:50 +0800 Subject: [PATCH] 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. --- internal/server/handler_check.go | 2 +- internal/server/handler_check_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/internal/server/handler_check.go b/internal/server/handler_check.go index 05e3acb81..0c9b59a54 100644 --- a/internal/server/handler_check.go +++ b/internal/server/handler_check.go @@ -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) } diff --git a/internal/server/handler_check_test.go b/internal/server/handler_check_test.go index b61f31ddc..67b8c1bd0 100644 --- a/internal/server/handler_check_test.go +++ b/internal/server/handler_check_test.go @@ -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) + } +}