Repository navigation
feat(audit): search-first discovery for large repos (per-lexicon content search with walk fallback) - #1971
Merged
Conversation
Above a size threshold, fetch.ts switches from a full tree walk + extension filter to per-lexicon content search: known-path lexicons (github, forgejo workflows; gitlab's canonical file) are kept straight from the tree already in hand, while content-detected lexicons (k8s, aws, azure, gcp, docker, helm) are found via each host's search API using a characteristic content term. Any search failure, rate limit, or unsupported API degrades to the walk rather than failing the audit. Closes #520. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Aug 26, 2026
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
fetchRepoFilesused to walk the entire repo tree, filter by extension (isCandidatePath), and download every candidate — thousands of files on a large monorepo, most yielding nothing, while CI/IaC files at non-canonical paths still went undetected. This adds a search-first discovery strategy for large repos, used alongside the existing walk for small ones.Heuristic: when to switch strategies
LARGE_REPO_TREE_ENTRIES = 500— a repo switches from the walk to search-first once its tree is bigger than that, measured off data a call already has to make:git/trees?recursive=1API returns the whole tree in one call regardless of repo size, so the entry count from that call (or GitHub'struncatedflag) is a free signal.Per-forge search
One row per content-detected lexicon (
k8s,aws,azure,gcp,docker,helm) in a single table (CONTENT_SEARCH_TERMS) drives all three hosts — adding a lexicon here is the only change needed to search for it:GET /search/code?q=<term>+repo:<owner>/<repo>— subject to GitHub's ~10 req/min unauthenticated rate limit.GET /projects/:id/search?scope=blobs&search=<term>— requires a token even for public projects; GitLab's basic (non-Elasticsearch) blob search returns at most ~20 results per query and doesn't paginate past them, which the existing "short page = last page" loop already handles correctly.GET /repos/:owner/:repo/search?q=<term>, tolerating both a bare array and Gitea's{ok, data}envelope. Forgejo's code-search availability/shape isn't consistently documented across versions, so this is explicitly best-effort.Known-path lexicons bypass search entirely. GitHub/Forgejo Actions must live under
.github/.forgejoworkflows (platform-enforced), so those are filtered straight out of the tree already in hand — zero search calls. GitLab'sinclude:can pull a CI file in from anywhere, so its canonical file additionally gets astages:search term (unchanged from #519) to catch non-canonical includes (#520's original under-detection symptom).Fallback behavior
Search is additive, never load-bearing. Any error, rate limit, or unsupported/unavailable search API (a 403/429/500, or a 404 meaning "this endpoint doesn't exist" — distinguished from a legitimate empty result set) is caught and the code falls back to:
isCandidatePathdownstream — identical to small-repo behavior.Tests
Added to
packages/core/src/audit/fetch.test.ts:/search/code, GitLab/search?scope=blobs, Forgejo/repos/.../search)packages/core/src/audit/discover.ts: exportedciLexiconForPath(previously module-private) so fetch.ts can filter known-path matches straight from an already-fetched tree.Test results
npx vitest run packages/core/src/audit— 12 files, 124 tests passednpx vitest run packages/core— 327 files, 5027 tests passednpx tsc --noEmit -p packages/core/tsconfig.json— cleannpx vitest run— 1075 passed / 3 skipped test files, 14291 passed / 32 skipped tests, 0 failuresFixes #520
🤖 Generated with Claude Code