till's Plugins page said "无法连接 GitHub: GitHub refused GITHUB_TOKEN (no GitHub token is set in Settings → Network and sharing)". ghtoken.Token falls back to the environment's GITHUB_TOKEN / GH_TOKEN, and a stale one there made every GitHub read fail, though GitHub serves the same reads without a token. ghtoken.Do now sends a GitHub API request with the token. When the token came from the environment and GitHub answers 401, it remembers that token as refused for the rest of the process (Token() skips it, so GH_TOKEN is still tried after a refused GITHUB_TOKEN, and Settings no longer shows it) and asks once more without Authorization, returning that answer. A token set in Settings is never dropped: its 401 is still Refused()'s error. An anonymous rate limit after the drop is said by LimitedBy as before. Every caller goes through it: plugin fetchJSONFrom (tagged-repo search, git plugin checks, githubHead) and getURLFrom (Bun), and library apiGet, skills fetch, skilltree fetchBlob and latestRTK via doGitHub. internal/davsync/github.go stays strict: its token is the one the user gave sync to write a private repo, outside ghtoken, and an anonymous retry can't write there, so it would only hide why sync failed. Tests (httptest only): ghtoken_test covers an env token refused then asked again without, not sent again (and GH_TOKEN tried next), a Settings token refused stays an error, an env token refused then an anonymous rate limit is reported, and another host untouched. plugin TestTaggedReposStaleEnvTokenDropped is till's case: TaggedRepos with GITHUB_TOKEN=stale-till lists 7 repos, no error. github_token_test and library TestGitHubRateLimitSaid now expect the env token dropped and the Settings token still refused. Broken by hand, each red: (a) no anonymous retry: every new env test, the plugin and library tests red, and TestTaggedReposStaleEnvTokenDropped shows till's exact error; (b) no memory of the refusal: NotSentAgain, the plugin and library tests red; (c) a Settings token also retried: SettingsTokenRefusedStaysAnError, the plugin and library tests red. Run on the commit before the rebase (base9b04c4e20): - gofmt -l: clean. go vet ./... on darwin, GOOS=linux -tags nogui, GOOS=windows: clean. - set -o pipefail; go test -timeout 45m ./... at load ~30: 62 packages ok. agent, gateway and library ran past 45m while still progressing; gui failed TestSetAnswersWhileDevinAndProvidersHang (set took 10.26s, #1375) and TestMainWindowCorners (measuring killed, #1936/#2645); provider failed TestPluginPicksComeBackWithTheirList (#3051, fixed on main inc922225f1). - Each rerun alone at load 21-56: library ok 809.7s, provider ok 308.8s, gui ok 159.5s, agent ok 1673.3s, gateway ok 780.4s. After rebasing ontoa3ebed202(main moved 8 commits): gofmt -l clean; go vet darwin, linux -tags nogui, windows clean; go test -count=1 at load ~57: ghtoken ok 2.9s, plugin ok 277.6s, library ok 144.2s.
11 lines
198 B
Go
11 lines
198 B
Go
package ghtoken
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/testenv"
|
|
)
|
|
|
|
// The tests run in a home of their own, so Settings is theirs.
|
|
func TestMain(m *testing.M) { testenv.Main(m) }
|