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.
A GitHub token in Settings → Network and sharing that GitHub refused
(401, expired or revoked) failed every plugin and skill check, so a
stale token was worse than none. Now it is treated as an environment
token already was: the request is asked again without it, the token
isn't sent again while magpie runs or until the field changes, and the
anonymous answer (60 an hour) is the one taken. This overturns the
package comment and TestSettingsTokenRefusedStaysAnError: the token
being the user's choice is a reason to tell them, not to fail the
check.
The page stays honest about it:
- Settings › Network and sharing still shows the token, masked, with
Remove, and says in red that GitHub refused it and requests go
without one until it is replaced (/api/settings githubTokenRefused).
Before, a refused token simply read as none being set.
- After a Settings token's refusal requests go anonymous, not with
GITHUB_TOKEN/GH_TOKEN: the user put the Settings one ahead of those,
and the page says "without one".
Patch by MYCF711 (fix/settings-token-fallback, 7d93f1b5): the ghtoken
change and its tests. Changed from it: the notice is in Settings' row,
where the token lives, instead of the patch's Plugins page note,
which cost ~630 bytes of core script the budget (28 bytes of room at
c54478904) doesn't have; the Library's skill checks reach Settings'
row too. Token() doesn't fall through to the environment; the
library's skill check test (the sibling the patch left red) expects
the anonymous answer; the unreachable new Refused() message is
dropped (Refused's "where" now holds for a refused Settings token).
app.js stays in its budget by shortening renderGitHubToken's comment.
Run at this tree (base c54478904), on mote:
- go test -tags nogui ./internal/ghtoken ./internal/plugin
./internal/library ./internal/gui: ok (TestCoreScriptBudget
included; no budget raised). GOOS=linux and windows go vet, go build
./...: clean.
- github-token-refused.test.cjs (new; chromium and webkit, en and zh,
1000 and 440px): red 8 of 8 against origin/main's assets, green
with the change. With github-token and i18n-keys: 21 of 22; the red
is i18n-keys "a plugin's words are its own" ("Runs as"), red at
origin/main 74dcf40aa alone too (#3897).
- Every GUI file that opens Settings › Network and sharing
(allow-ips, api-key-theme, bare-ids, browser-access, cors-origins,
gateway-port, lan-docker, proxy-test, settings-proxy-auth,
settings-proxy-remember): 126 of 126.
- Broken by hand: Token() falling through to GITHUB_TOKEN after the
Settings token's refusal turns TestSettingsTokenRefusedGoesWithoutEnvToken
red; MYCF711 showed TestSettingsTokenRefusedAskedAgainWithout red with
from == "settings" back in Do.
Not tried: a real revoked token against api.github.com. The Plugins and
Library pages have no notice of their own (Settings' row says it).