Skip to content

test(forge): cover Check, auth errors and the PR, issue and commit-review fetchers - #327

Merged
0x73746F66 merged 3 commits into
mainfrom
fix/292-forge-check-tests
Nov 13, 2026
Merged

0x73746F66 merged 3 commits into
mainfrom
fix/292-forge-check-tests

Conversation

@0x73746F66

@0x73746F66 0x73746F66 commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Closes #292
Closes #218

What

Both cards cover internal/analyze/forge and 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 TLS httptest server reached through NewClient's enterprise-host path (the test swaps http.DefaultTransport for the server's trusted transport and restores it).

  1. Check: user token with repo access; /user rejected with no repo; repository-scoped token (no login); same with /rate_limit failing; repository-scoped token that cannot see the repo; user token that gets 404 on the repo (access message naming source and login); /rate_limit failing for a user token is not fatal.
  2. repoAccessError: 404/403 give the access message; 500 and a nil response pass the raw error through, wrapped.
  3. comma, 4. CheckResult.String, 5. NewClient enterprise 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 first ready_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.

  • ResolveCredentials gh CLI fallback: a stub gh on PATH; its trimmed token is used with source "gh CLI", and a failing gh, a blank answer or no gh give ErrNoCredentials.

Test-only. Package coverage 19.3% -> 89.7%.

Verified

go test -cover ./internal/analyze/forge/ and go vet pass; gofmt clean.

@github-actions

Copy link
Copy Markdown
Contributor

Vulnetix config plan

Manager gitops:vulnetix/cli, prune off, plan hash a8bd984f1753c68b180298051dd9e2524ab644d2ebe9e4c7c811ff4126753b5f

Object Action Changes
~ QualityGate/default update (adopt) severity: null -> "high"

0 to create, 1 to update, 0 to delete, 0 unchanged

@github-actions

Copy link
Copy Markdown
Contributor

Vulnetix config plan

Manager gitops:vulnetix/cli, prune off, plan hash a8bd984f1753c68b180298051dd9e2524ab644d2ebe9e4c7c811ff4126753b5f

Object Action Changes
~ QualityGate/default update (adopt) severity: null -> "high"

0 to create, 1 to update, 0 to delete, 0 unchanged

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

Vulnetix config plan

Manager gitops:vulnetix/cli, prune off, plan hash a8bd984f1753c68b180298051dd9e2524ab644d2ebe9e4c7c811ff4126753b5f

Object Action Changes
~ QualityGate/default update (adopt) severity: null -> "high"

0 to create, 1 to update, 0 to delete, 0 unchanged

@0x73746F66 0x73746F66 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 0x73746F66 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@0x73746F66
0x73746F66 force-pushed the fix/292-forge-check-tests branch from 30c8541 to 45f24c7 Compare November 13, 2026 11:11
@github-actions

Copy link
Copy Markdown
Contributor

Vulnetix config plan

Manager gitops:vulnetix/cli, prune off, plan hash a8bd984f1753c68b180298051dd9e2524ab644d2ebe9e4c7c811ff4126753b5f

Object Action Changes
~ QualityGate/default update (adopt) severity: null -> "high"

0 to create, 1 to update, 0 to delete, 0 unchanged

@0x73746F66
0x73746F66 merged commit 3728dd1 into main Nov 13, 2026
29 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant