Repository navigation
test(forge): cover Check, auth errors and the PR, issue and commit-review fetchers - #327
Conversation
Vulnetix config planManager
0 to create, 1 to update, 0 to delete, 0 unchanged |
Vulnetix config planManager
0 to create, 1 to update, 0 to delete, 0 unchanged |
1 similar comment
Vulnetix config planManager
0 to create, 1 to update, 0 to delete, 0 unchanged |
0x73746F66
left a comment
There was a problem hiding this comment.
Reuse review: test-only (internal/analyze/forge). Fake GitHub uses httptest and the package's real Client; the fakeGh PATH shim mirrors the pattern in internal/license/github_miss_test.go, and it is unexported per package so there is nothing shared to import (internal/testutils has only env/stdout helpers). No changes needed.
0x73746F66
left a comment
There was a problem hiding this comment.
Reuse review: no reinvented Vulnetix patterns found. The change stays inside the package it covers, uses stdlib/testify helpers already used by the repo's tests, and adds no new client, auth, config-schema or shared-package duplicate (checked internal/testutils and sibling repos). Rebased onto current main locally: go vet and go test pass for every touched package. The earlier red checks (CodeQL Analyze, Install a release with verified provenance, Lockfile) were GitHub API rate-limit failures, not code failures; this will be re-run on a rebased head before merge.
Check runs against an httptest TLS server posing as a GitHub Enterprise host, so every branch of the two-check flow is exercised without network: user token with and without repository access, a repository-scoped token, a rejected token with no repository, and a rate-limit read that fails. repoAccessError, comma, CheckResult.String and NewClient's enterprise URL handling get direct cases. Package coverage 19.3% -> 37.6%. Closes #292
FetchPullRequests against a fake GitHub Enterprise API: merged versus rejected state, the window ending the walk, review state casing, the author's own and bot reviews and comments excluded from first review and first response, draft intervals summed across cycles and a response before ready-for-review discarded. FetchIssues drops the pull requests the issues endpoint returns. FetchCommitReviews: approved on a PR into the default branch, self-approval as review_required, PRs into other branches and failed lookups as unknown. Coverage 37.6% -> 85.5%. Closes #218
A stub gh on PATH: its trimmed token is used with source "gh CLI"; a failing gh, a blank answer and no gh at all give ErrNoCredentials.
30c8541 to
45f24c7
Compare
Vulnetix config planManager
0 to create, 1 to update, 0 to delete, 0 unchanged |
Closes #292
Closes #218
What
Both cards cover
internal/analyze/forgeand share one fake GitHub Enterprise API, so they land together (two separate PRs would both declare the same test helper in one package).auth_check_test.go(#292): a TLShttptestserver reached throughNewClient's enterprise-host path (the test swapshttp.DefaultTransportfor the server's trusted transport and restores it).Check: user token with repo access;/userrejected with no repo; repository-scoped token (no login); same with/rate_limitfailing; repository-scoped token that cannot see the repo; user token that gets 404 on the repo (access message naming source and login);/rate_limitfailing for a user token is not fatal.repoAccessError: 404/403 give the access message; 500 and a nil response pass the raw error through, wrapped.comma, 4.CheckResult.String, 5.NewCliententerprise base URL / public host / unparsable host error.fetch_test.go(#218): a path-routed fake API.FetchPullRequests/hydratePR: merged vs closed-unmerged state, the first PR older than the window ends the walk, review states lower-cased, the author's own and bot reviews/comments excluded from first review and first response, a comment that beats the first review is the first response.draftHistory: ready at the firstready_for_review, draft time summed across two draft cycles, and a comment before the PR was ready is not a response.FetchIssues: the PR the issues endpoint returns is skipped; labels, state reason, first response.FetchCommitReviews: approval on a PR into the default branch, self-approval ->review_required, only non-default-branch PRs ->unknown, failed lookup ->unknown.ResolveCredentialsgh CLI fallback: a stubghon PATH; its trimmed token is used with source "gh CLI", and a failing gh, a blank answer or no gh giveErrNoCredentials.Test-only. Package coverage 19.3% -> 89.7%.
Verified
go test -cover ./internal/analyze/forge/andgo vetpass;gofmtclean.