Skip to content

test: use a deterministic token for fake GitHub app tests - #468

Merged
gaborcsardi merged 5 commits into
r-lib:mainfrom
schloerke:schloerke/fix-test-coverage-ci
Jun 9, 2026
Merged

gaborcsardi merged 5 commits into
r-lib:mainfrom
schloerke:schloerke/fix-test-coverage-ci

Conversation

@schloerke

Copy link
Copy Markdown
Contributor

Summary

The new test-coverage workflow (uncovr::test()) runs the full testthat suite, unlike R CMD check, which only runs the scan-deps tests (tests/testthat.R filters to them). This surfaced 15 failures in test-github-tools.R: the fake GitHub app validates the Authorization header format via re_gh_auth(), but the tests relied on whatever ambient credential type_github_get_headers() found. On CI, GITHUB_PAT is set to secrets.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. The http error test now calls setup_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 after setup_fake_gh_app(), so they are unaffected.

Verification

Under a simulated CI runner (CI=true, no credential helper, a malformed ambient GITHUB_PAT): test-github-tools.R 31 passed (was 15 failing), test-type-github.R 177 passed, test-type-url.R 21 passed. All also pass in the normal local environment.

schloerke added 2 commits June 8, 2026 14:42
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
schloerke marked this pull request as ready for review June 8, 2026 19:03
@gaborcsardi
gaborcsardi merged commit a3ce03e into r-lib:main Jun 9, 2026
9 of 11 checks passed
@gaborcsardi

Copy link
Copy Markdown
Member

Thanks!

@schloerke
schloerke deleted the schloerke/fix-test-coverage-ci branch June 10, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants