From fefab53d226a73958e524c33cca830f883070e13 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 18 Nov 2026 13:09:32 +0800 Subject: [PATCH] gui: TestGitHubTokenRefusedShown refuses a token of its own each run ghtoken keeps the tokens GitHub answered 401 for as long as the process runs, keyed by the token. The test refused one constant token, so a second run in the same process (-count=2) found it refused before GitHub was asked: red every time. Each run now builds its own token, ending in 4567 so the mask it checks is the same. Run on mote at this head: - go test ./internal/gui -run ^TestGitHubTokenRefusedShown$ -count=2 on the old test: FAIL "refused before GitHub was asked", 2 of 2 tries. - go test ./internal/gui -run ^TestGitHubToken -count=5: ok. - gofmt -l: clean. Test-only; no other file changed. --- internal/gui/github_token_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/gui/github_token_test.go b/internal/gui/github_token_test.go index bf0b99c51..60c9612fa 100644 --- a/internal/gui/github_token_test.go +++ b/internal/gui/github_token_test.go @@ -1,11 +1,13 @@ package gui import ( + "fmt" "net/http" "net/http/httptest" "path/filepath" "strings" "testing" + "time" "github.com/yetone/magpie/internal/ghtoken" "github.com/yetone/magpie/internal/settings" @@ -75,7 +77,10 @@ func TestGitHubTokenRefusedShown(t *testing.T) { Handler(nil, nil).ServeHTTP(rec, httptest.NewRequest("GET", "/api/settings", nil)) return rec.Body.String() } - const tok = "ghp_refusedrefusedrefusedrefused4567" + // ghtoken keeps the tokens GitHub refused for as long as the process + // runs, so each run refuses a token of its own: with one constant a + // second run (-count=2) found it refused before GitHub was asked. + tok := fmt.Sprintf("ghp_refused%025d4567", time.Now().UnixNano()) s := settings.Load() s.GitHubToken = tok if err := settings.Save(s); err != nil {