Fix TestRoutingIntegration and improve DetectUserRole robustness

Amp-Thread-ID: https://ampcode.com/threads/T-fc47ce9d-88a4-4bcd-b9cb-79327d98dee7
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-11-20 19:04:42 -05:00
parent 345766badc
commit 8e05847d31
4 changed files with 694 additions and 138 deletions

View File

@@ -14,6 +14,10 @@ import (
)
func TestRoutingIntegration(t *testing.T) {
// Isolate from user's git config (e.g. url.insteadOf) to ensure deterministic URLs
t.Setenv("GIT_CONFIG_GLOBAL", "/dev/null")
t.Setenv("GIT_CONFIG_SYSTEM", "/dev/null")
tests := []struct {
name string
setupGit func(t *testing.T, dir string)

View File

@@ -44,8 +44,16 @@ func DetectUserRole(repoPath string) (UserRole, error) {
}
output, err = cmd.Output()
if err != nil {
// No remote or error - default to contributor
return Contributor, nil
// Fallback to standard fetch URL if push URL fails (some git versions/configs)
cmd = exec.Command("git", "remote", "get-url", "origin")
if repoPath != "" {
cmd.Dir = repoPath
}
output, err = cmd.Output()
if err != nil {
// No remote or error - default to contributor
return Contributor, nil
}
}
pushURL := strings.TrimSpace(string(output))