feat(backend): configure revision sort order#1379
Conversation
Constraint: Issue sourcebot-dev#1016 has maintainer-approved config names branchSort and tagSort, and existing behavior must remain the default. Rejected: Changing the 64-revision cap or adding per-kind limits | useful follow-up, but broader than the approved sort-control scope. Confidence: high Scope-risk: moderate Directive: Keep date-based revision sorts newest-first so unset config and explicit date config preserve current indexing priority. Tested: node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/backend test src/git.test.ts src/repoIndexManager.test.ts; node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/schemas build; node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/shared build; node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/backend build Not-tested: Full monorepo test suite.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds ChangesConfigurable revision sorting
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Constraint: Sourcebot requires every non-doc PR to add an Unreleased changelog entry that links to the PR. Confidence: high Scope-risk: narrow Directive: Keep schema/config additions under Added unless they are pure fixes. Tested: Changelog format matched adjacent Unreleased Added entries. Not-tested: No code tests run for changelog-only commit.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/backend/src/git.test.ts`:
- Around line 95-119: The getTags/getBranches sort tests are currently masked by
the shared repo fixture’s refname defaults, so they don’t verify the new sort
argument is used. In the getTags and getBranches test cases, override the repo
config to a different default sort before calling getTags(..., { sort: "refname"
}) / getBranches(..., { sort: "refname" }), then assert the returned order
changes only because of the explicit sort option. Use the existing getTags,
getBranches, createTempRepo, and runGit helpers to set up the conflicting config
inside each test.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5275d52d-c96f-4442-b450-e39fee67b14b
📒 Files selected for processing (39)
CHANGELOG.mddocs/docs/features/search/multi-branch-indexing.mdxdocs/snippets/schemas/v3/azuredevops.schema.mdxdocs/snippets/schemas/v3/bitbucket.schema.mdxdocs/snippets/schemas/v3/connection.schema.mdxdocs/snippets/schemas/v3/genericGitHost.schema.mdxdocs/snippets/schemas/v3/gerrit.schema.mdxdocs/snippets/schemas/v3/gitea.schema.mdxdocs/snippets/schemas/v3/github.schema.mdxdocs/snippets/schemas/v3/gitlab.schema.mdxdocs/snippets/schemas/v3/index.schema.mdxdocs/snippets/schemas/v3/shared.schema.mdxpackages/backend/src/git.test.tspackages/backend/src/git.tspackages/backend/src/repoCompileUtils.tspackages/backend/src/repoIndexManager.test.tspackages/backend/src/repoIndexManager.tspackages/schemas/src/v3/azuredevops.schema.tspackages/schemas/src/v3/azuredevops.type.tspackages/schemas/src/v3/bitbucket.schema.tspackages/schemas/src/v3/bitbucket.type.tspackages/schemas/src/v3/connection.schema.tspackages/schemas/src/v3/connection.type.tspackages/schemas/src/v3/genericGitHost.schema.tspackages/schemas/src/v3/genericGitHost.type.tspackages/schemas/src/v3/gerrit.schema.tspackages/schemas/src/v3/gerrit.type.tspackages/schemas/src/v3/gitea.schema.tspackages/schemas/src/v3/gitea.type.tspackages/schemas/src/v3/github.schema.tspackages/schemas/src/v3/github.type.tspackages/schemas/src/v3/gitlab.schema.tspackages/schemas/src/v3/gitlab.type.tspackages/schemas/src/v3/index.schema.tspackages/schemas/src/v3/index.type.tspackages/schemas/src/v3/shared.schema.tspackages/schemas/src/v3/shared.type.tspackages/shared/src/types.tsschemas/v3/shared.json
Clarify that Sourcebot applies one global revision budget after the default branch, then matching branches, then matching tags. Add a mixed branch/tag overflow regression so future changes cannot accidentally present branch and tag limits as independent. Constraint: Existing runtime behavior has a 64 total revision cap including the default branch, with matching branches considered before matching tags. Rejected: Changing selection semantics in this PR | larger behavioral change than the scoped sort-configuration fix and would need maintainer direction. Confidence: high Scope-risk: moderate Directive: Do not describe branch and tag caps as independent; tags can be skipped when branches fill the revision budget. Tested: node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/backend test src/git.test.ts src/repoIndexManager.test.ts; node .yarn/releases/yarn-4.7.0.cjs build:deps; node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/backend build; rg stale 64 branch/tag wording; git diff --check. Not-tested: Full monorepo test suite.
Bring the remote branch's main merge into the local PR branch so the reviewer-blocker fix can be pushed without force. The integration is limited to the upstream zoekt argument hardening commit and its changelog entry. Constraint: Remote branch had advanced with origin/main and rejected a fast-forward push. Rejected: Force-pushing over the remote branch | would discard branch history and violate the safe PR workflow. Confidence: high Scope-risk: narrow Directive: Preserve upstream merge commits on contributor branches unless maintainers explicitly ask for a history rewrite. Tested: git diff --check --cached. Not-tested: Post-merge backend test/build rerun before this commit; those run after integration.
Strengthen the explicit revision sort regression tests so they fail if the sort argument is ignored and repo-local defaults would otherwise mask the behavior. Constraint: CodeRabbit found the explicit-sort tests inherited matching repo config defaults. Rejected: Change production git sort handling | existing implementation already passes --sort for branch and tag reads. Confidence: high Scope-risk: narrow Directive: Keep revision ordering tests configured so explicit sort options conflict with repo defaults. Tested: node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/backend test src/git.test.ts Not-tested: Full monorepo test suite; change is limited to backend git regression tests.
Fixes #1016
Problem
When
revisions.branchesorrevisions.tagsmatch more refs than Sourcebot can index, the order used before truncation determines which refs survive. Branches and tags currently use hardcoded ordering, so users cannot choose lexicographic ref-name ordering or use the maintainer-approved sort config from the issue.Root cause
getBranches()always sorted by-committerdate,getTags()always sorted by-creatordate, and the connection schema only exposed branch/tag glob arrays. The index manager had no metadata field to pass sort preferences into Git ref discovery. The docs also needed to match the existing runtime cap: Sourcebot keeps one global 64-revision budget, including the default branch, and considers matching branches before matching tags.Solution
revisions.branchSortandrevisions.tagSortto the v3 schema withcommitterdate,creatordate, andrefnamevalues.for-each-refsort semantics.Tests
refnameordering on branches and tags.node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/backend test src/git.test.ts src/repoIndexManager.test.ts src/zoekt.test.tsnode .yarn/releases/yarn-4.7.0.cjs build:depsnode .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/backend buildrgcheck for stale independent branch/tag cap wordinggit diff --check origin/main...HEADRisk
Moderate. The schema artifacts are broad because the shared
GitRevisionsschema is dereferenced by every v3 connection schema, but the runtime behavior is limited to revision ordering before existing matching/deduplication/truncation.Summary by CodeRabbit
branchSortandtagSortoptions for indexed revisions to control how candidate branches and tags are prioritized before the global revision cap is applied.committerdate,creatordate, andrefname, with defaults applied per branch vs tag.refnamesorting and for propagating configured sort settings during indexing.