Repository navigation
refactor(#7361): add force-re-root commit to forge.Client - #7368
Conversation
Add ForceCommitFileToBranch so GitLab poller state can live on a Developer-writable unprotected branch (phase 1 of #7343). Each write re-roots the target branch on the repository root commit with force:true, leaving history at base + 1 commit. GitLab extends commitFilesImpl with force and start_sha, resolves the root SHA internally, and suffixes [skip ci]. GitHub returns ErrNotSupported. FakeClient models per-branch last-write-wins files and prune-to-one-commit. GetFileContentAtRef 404 already unwraps to ErrNotFound via APIError; tests lock that contract. Note: pre-commit could not fetch remote hook repos (HTTP 403). Local equivalents were run: gofmt, go vet, whitespace/EOF checks, gitleaks, and lint-broken-symlinks. Closes #7361
|
🤖 Finished Review · ✅ Success · Started 12:37 PM UTC · Completed 12:54 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5 · Effort: high · Cost: $4.77 |
|
Risk Assessment: moderate (2/5) DetailsTier 1 signals are unchanged from the prior review (same file count/blast-radius bucket, no protected/security/dependency changes, bot author) and remain low apart from the large diff size; Tier 2 remains elevated due to heavy historical fix/revert churn and multi-author contention in the shared forge package (same file set as before, since the new commit only touched already-included gitlab/repo.go and gitlab_test.go to fix a review-identified bug); Tier 3 remains tightly scoped and well-matched to the linked issue with no risk labels. Anchored to the prior moderate (2) rating. Previous runRisk Assessment: moderate (2/5) DetailsTier 1 is low outside of the large diff size, Tier 3 shows a tightly-scoped, well-matched change against the linked issue's checklist with no risk labels, while Tier 2 is elevated due to heavy historical fix/revert churn and multi-author contention in the shared forge package; together these average to a moderate composite score. |
|
Looks good to me Previous runReviewFindingsHigh
Next steps:
|
|
🤖 Finished Fix · ✅ Success · Started 12:56 PM UTC · Completed 1:05 PM UTC Commit: Runtime: claude · Model: sonnet → claude-sonnet-5 · Effort: high · Cost: $1.21 |
The commits-list endpoint does not support order_by/sort (those belong to other GitLab endpoints); unrecognized params are silently ignored, so resolveRootCommitSHA's per_page=1 request returned main's current HEAD instead of the DAG root. That let start_sha drift with every push to main, breaking ForceCommitFileToBranch's base+1 history guarantee. Resolve the root by paginating first-parent history (first_parent=true) to its last page and taking that page's last entry, mirroring the pagination pattern already used by getTreeMap/ListRepositoryFiles. Update GitLab httptest coverage to assert the real query params and add a multi-page test proving the root is taken from the last page, not the branch tip. Addresses review feedback on PR #7368
🔧 Fix agent — iteration 1 (bot-triggered)Fixed the single high-severity finding: resolveRootCommitSHA now resolves the actual repository DAG root via first-parent pagination instead of relying on order_by/sort params the GitLab commits-list endpoint doesn't support (which previously returned main's moving HEAD instead of a fixed root). Updated and added GitLab httptest coverage to assert the real resolution protocol, including a multi-page test that would fail under the old bug or a naive first-page-first-entry fix. Fixed (1):
Tests: passed Decision points
Next steps:
|
|
🤖 Review · ❌ Terminated · Started 1:07 PM UTC · Ended 1:25 PM UTC Commit: |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Superseded by updated review
|
🤖 Finished Review · ✅ Success · Started 1:07 PM UTC · Completed 1:25 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5 · Effort: high · Cost: $3.83 |
|
🤖 Finished Retro · ✅ Success · Started 2:00 PM UTC · Completed 2:06 PM UTC Commit: Runtime: claude · Model: sonnet → claude-sonnet-5 · Effort: high · Cost: $0.92 |
|
PR #7368 (phase 1/4 of #7343, branch-backed poller state) shows a healthy, fast pipeline: triage → |
Summary
Adds
ForceCommitFileToBranchtoforge.Clientso later GitLab poller-state work can persist HMAC-signed JSON on a Developer-writable unprotected branch. Each write re-roots the branch on the repository's root commit withforce:true, so history stays at base + 1 commit and never grows.Related Issue
Phase 1 of #7343 (branch-backed poller state). Blocks phases 2 and 3 (#7362, #7366).
Changes
forge.Client.ForceCommitFileToBranch(ctx, owner, repo, branch, path, message, content)commitFilesImplwithforce+start_sha; resolve the root commit SHA internally; suffix[skip ci]forge.ErrNotSupported(explicit, no silent success)FakeClient: per-branch files, create-on-first-write, last-write-wins, prune to one reachable commitGetFileContentAtRef404 unwraps toforge.ErrNotFoundso a missing state file is distinguishableTesting
force:trueandstart_sha; repeated writes keep the same start SHA; missing file →ErrNotFound; missing/unreachable base → error;[skip ci]suffixErrNotSupportedgo test ./internal/forge/ ./internal/forge/github/ ./internal/forge/gitlab/andgo vetpass; new functions ≥ 80% coverageChecklist
Closes #7361
Post-script verification
agent/7361-force-reroot-commit)90a86f0b1ad9cb8aa27effbd623f4227dba4e21e..HEAD)