Repository navigation
test: use a deterministic token for fake GitHub app tests - #468
Merged
Merged
Conversation
The test-coverage workflow runs the full testthat suite via uncovr::test(), unlike R CMD check which only runs the scan-deps tests. This surfaced 401 failures in test-github-tools.R: the fake GitHub app validates the Authorization header format, but the tests relied on whatever ambient credential type_github_get_headers() found. On CI, gitcreds_get() returns GITHUB_PAT (secrets.GITHUB_TOKEN), which the fake app rejects as malformed. setup_fake_gh_app() now pins all token sources to a deterministic, well-formed fake token so the fake-app tests never depend on ambient credentials. The "http error" test also calls setup_fake_gh_app() now, since it set the API URL manually and missed the token vars.
test-solve-conflicts.R and test-solve-describe.R spin up their own gh_app() processes and set R_PKG_GITHUB_API_URL directly, bypassing setup_fake_gh_app() and its token. Extract the token setup into local_fake_gh_token() and call it in those tests so they no longer depend on ambient GitHub credentials.
schloerke
marked this pull request as ready for review
June 8, 2026 19:03
3 tasks done
This reverts commit c650870.
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The new
test-coverageworkflow (uncovr::test()) runs the full testthat suite, unlikeR CMD check, which only runs thescan-depstests (tests/testthat.Rfilters to them). This surfaced 15 failures intest-github-tools.R: the fake GitHub app validates theAuthorizationheader format viare_gh_auth(), but the tests relied on whatever ambient credentialtype_github_get_headers()found. On CI,GITHUB_PATis set tosecrets.GITHUB_TOKEN; with no git credential helper present,gitcreds_get()returns it, the fake app rejects it as malformed, and every snapshot fails with HTTP 401.This makes the fake-app tests hermetic:
setup_fake_gh_app()now pins all token sources (CI_GITHUB_TOKEN,GITHUB_PAT_GITHUB_COM,GITHUB_PAT,GITHUB_TOKEN) to a deterministic, well-formed fake token, so requests never depend on ambient credentials. Thehttp errortest now callssetup_fake_gh_app()too (it set the API URL manually and missed the token vars). Tests that exercise bad-credential paths still set their own token values aftersetup_fake_gh_app(), so they are unaffected.Verification
Under a simulated CI runner (
CI=true, no credential helper, a malformed ambientGITHUB_PAT):test-github-tools.R31 passed (was 15 failing),test-type-github.R177 passed,test-type-url.R21 passed. All also pass in the normal local environment.