Repository navigation
Conversation
plumber analyze --debug[=path] writes a markdown report of every GitHub request of a run (#618): per endpoint, repeated URLs, every request in order, the quota windows the response headers report, and GET /rate_limit before and after. Every GitHub client sends through the counting transport in internal/httpcount; the process-wide http.DefaultTransport is untouched because OPA's http.send asserts its type. --verbose is unchanged. Refs #618 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Answer a repeated GitHub GET from memory for the rest of the run (httpcount.MemoTransport). Only 2xx and 404 answers are kept, the key is the URL and every header, a waiter keeps its own deadline, and the kept bodies stay under 32 MB. Only the GitHub API and raw-content clients use it: the OIDC token, the score push, the update check and the job logs keep the counting-only DefaultTransport. After a raw-host 404 sent with a token, the contents API is asked only until it has accepted that token once. An expired or revoked token still ends as could-not-verify, never as a missing file. The definition fetcher now records the token its raw reads send instead of re-reading the environment. A branch GitHub redirects to another name is dropped before its protection is read, which could only 404. The --debug report counts the requests answered from memory. Refs #618 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…setup The report kept every request's raw query, so the job-log store's signed redirect URL landed in plumber-debug.md with its SAS signature. The log now keeps a query only when the GitHub API answered (x-ratelimit headers) and writes <redacted> for every other host. Credential discovery and naming move out of startGitHubDebugReport, and the rate-limit read becomes a seam, so tests cover the credential labels, both auth schemes' names, and each credential's before/after row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, looks good overall. The memo, the request counting and the branch-redirect change don't change results. One thing to fix before merge: A raw 404 can now hide an action the token is not allowed to read In That works for expired tokens, but not when a valid token is refused for one org only:
In those cases the raw host answers 404, but the API would answer 403. Before this PR that gave Suggestion: prove the token per Question: were the 11 regression runs done with Minor: a branch-pinned action that just added |
The contents API now has to accept the token in the same repository before a raw 404 counts as final. SAML SSO or an IP allow list can refuse a valid token for one organization: the raw host then answers 404, the API 403, and the read has to stay could-not-verify. The ref also has to be a full commit SHA. The raw host's CDN keeps a 404 for about a minute (measured at 58 to 64 s, although `expires` says 5 min), so an action.yml pushed to a branch or under a moved tag right after a miss is still a 404 there. Reproduced on getplumber-examples/cli-working-lab, branch 618-raw-cdn-cache: bb33a2e dropped the action's ISSUE-714 and ISSUE-307 findings, while v0.7.23 and this commit report them. Cost against bb33a2e, same reports: getplumber/plumber 265 -> 298 requests, facebook/react v19.3.1 242 -> 250. Refs #618 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The mutable-exec scan tries action.js, index.js, dist/index.js and src/index.js for every third-party action, and most of them do not exist. Since a raw 404 on a tag or a branch is no longer final, each miss cost a raw request plus a contents-API request. One GraphQL query per 25 actions now asks which of these files exist. GitHub answers null for a missing one with no CDN cache in between, so read returns it as missing without a request. Files that exist, and the declared main:, are read as before. The query carries every untrusted value as a variable. A ref that is not a plain name (rev-parse operators, `:`) or a path that climbs out of the repository is not queried. An error GitHub ties to one repository drops that repository's answers only; any other error drops the chunk. With no token, or offline, no query is sent. A name that is both a tag and a branch resolves to the tag in GraphQL, while the raw host may serve the branch. ISSUE-402 reports that ambiguity, so it is accepted here. Against v0.7.23, with identical reports: getplumber/plumber main 230 requests (bb33a2e: 265), facebook/react v19.3.1 231 (bb33a2e: 242). The test metadata client no longer keeps a live GraphQL client, and the default --debug report is gitignored. Refs #618 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| } | ||
| total := len(uniqueRefs) | ||
| if scanMutableExec { | ||
| defs.prefetchAbsent(candidateRefs(pipeline, defs)) |
There was a problem hiding this comment.
🔴 Test coverage
Medium: the entrypoint prefetch is never exercised end-to-end through the mutable-exec scan, so a mismatch between the candidate paths it marks absent and the paths the scan actually reads would silently defeat the #618 request reduction with no failing test. (Medium)
The new wiring at github/github_workflows.go:329 (defs.prefetchAbsent(candidateRefs(pipeline, defs))) is the heart of the #618 optimization, but no test runs it with a working GraphQL client. Every test that reaches enrichActions/resolveMutableExec with scanMutableExec=true builds its client via stubbedMetadataClient, which now sets client.gql = nil (see github/degraded_checks_test.go:34 and the assertion in entrypoint_prefetch_test.go TestPrefetchAbsent_SendsNothing/"stubbed metadata client"). With f.gql == nil, prefetchAbsent returns immediately, so in those tests candidateRefs runs but prefetchAbsent is a no-op and no entrypoint read is ever short-circuited.
The two halves are only tested in isolation:
TestCandidateRefschecks the pathscandidateRefsproduces (path.Join(subpath, p)for eachentrypointCandidates).TestPrefetchAbsent_NullObjectIsAbsentchecks thatprefetchAbsent+defs.readwith hand-writtencandidateRefs skips the raw host.
What no test covers is that the paths candidateRefs emits are the same keys read looks up during a real scan. read keys the absent map with containerKey(owner, repo, p, ref) (github/nested_actions.go:205) where p is the entrypoint path the scan derives independently in scanActionDefinition via key(rel) = path.Join(dir, rel) with dir = path.Dir(ymlKey) (github/action_source.go:939-945). If either side's path construction drifts (subpath joining, entrypointCandidates contents/order, or ref/case handling), prefetchAbsent would populate f.absent under keys read never queries, and every entrypoint would be re-fetched from the raw host — i.e. the optimization becomes a production no-op that re-introduces exactly the rate-limit pressure #618 set out to remove, while the entire test suite stays green.
Suggested test: in github/nested_actions_test.go (or entrypoint_prefetch_test.go), build a definitionFetcher with a stubbed GraphQL client that answers null for a nested action's entrypoint candidate, run it through enrichActions(..., scanMutableExec=true) with a real pipeline (e.g. acme/mono/tools/lint@v2, exercising a subpath), and assert the raw stub received zero reads for the prefetched-absent entrypoint while a non-null candidate is still read. This pins the candidateRefs ↔ scanActionDefinition/read key agreement that currently only holds by coincidence.
Control: .github/claude-prompts/test-coverage.md · resolve this conversation once addressed.
What type of PR is this?
feat
What this PR does / why we need it:
An analyze of a GitHub repository sends many requests, and large repositories hit the rate limit (#618). Two commits:
1. Count every GitHub request and write a
--debugreport.internal/httpcountcounts each request per host and per rate-limit quota.analyze --debug[=file]writes a markdown report of every request and of the rate limit before and after the run, so the cost of a run can be measured.2. Send fewer requests.
httpcount.MemoTransport). The same request sent twice in a run reaches GitHub once.Rangeor API version is a separate request.--score-push, the update check and the job logs stay on the counting-onlyDefaultTransport, so a minted token or a signed one-shot URL is never replayed.The
--debugreport shows how many requests were answered from memory.Which issue(s) this PR is related to:
Refs #618
Special notes for your reviewer:
A
/code-reviewof the first version raised 10 findings, all fixed here. Two of them changed the design:action.ymlwas reported missing and the mutable-exec and nested-action checks silently passed. That is why the token now has to be proven first.The test fetchers built from a stub used to count as authenticated through
PLUMBER_METADATA_TOKEN. They now say so explicitly with atokenFetcherhelper, since the fetcher no longer reads the environment.Does this PR introduce a user-facing change?
How was this tested?
go vet ./...,go test -race ./...andgolangci-lint runpass.readWith: a proven token asks the contents API once, a rejected token asks every time and returnsfetchError.cliVersion, the JSON reports are identical, as are the exit code and the score:mainAll 11 are identical. getplumber/plumber is scanned on
mainrather than a tag, because a tag is not a branch and would skip the branch-protection lane. Its--debugreport shows the lane ran:/branches/main200,/branches/main/protection404 (the repo uses rulesets),/rules/branches/main200.Follow-up, not a regression: in that run
GET /repos/getplumber/plumber/branches/mainis still sent twice. v0.7.23 sends it too, but memory does not answer the second request, probably because the two calls carry different headers.PLUMBER_METADATA_TOKEN, a scan inside a clone, and GitHub Enterprise Server. The unit tests cover the expired-token case.AI usage disclosure:
YES. Claude Code wrote the code and the tests, ran the review and fixed its findings, and ran the regression check against v0.7.23. The author is responsible for the change and reviews it (see CONTRIBUTING.md and AI_POLICY.md).
🤖 Generated with Claude Code