Skip to content

Git designed for AI agents.

review: accept only review commits the storage core holds (R1)

Federico Eliac45609853dc4
diff --git a/doc/graft/PLAN7.md b/doc/graft/PLAN7.md
index 3fa908a..c7945cb 100644
--- a/doc/graft/PLAN7.md
+++ b/doc/graft/PLAN7.md
@@ -362,6 +362,18 @@ between a review write and a checkpoint commit.
keeps this one in the `error_details` metadata). Tested: success after exactly
one conflict, and exhaustion. Comments, verdicts and closes do not move roots and
are not checked.
+
+ *As implemented (WP74).* `dbreview.Store` gains `Refs()` (the snapshot) and
+ `WithRootsAt(S)` (a store whose `Create` and `Update` pass `rootsAt = S`); the
+ review service detects this capability with an interface assertion, so the
+ files store (storage core off or in shadow mode) is unchanged. The check runs
+ inside the write, after the snapshot: `CreateReview` checks head and base;
+ `UpdateReview` checks the new head inside the review store's update function,
+ only when the head moves, so an update that keeps the head is not refused. If
+ a reference tip of the snapshot is missing locally (a changeset committed on
+ another node after the gate caught the repository up), the service calls
+ `EnsureFresh` once before checking; afterwards a missing tip is `Internal`.
+ The reachability test is `gitops.IsReachable`.
* **R2 — checkpoint commit.** The build records the root set it included (the
open reviews' head and base commits, read after `Refs`). `CreateCheckpoint`, in
its transaction under the repository row lock, requires every open review's head
diff --git a/doc/graft/STORAGE.md b/doc/graft/STORAGE.md
index 540a683..88e77cd 100644
--- a/doc/graft/STORAGE.md
+++ b/doc/graft/STORAGE.md
@@ -90,6 +90,11 @@ design is [PLAN6.md](PLAN6.md).
(`ChangesetService`, `graft log`, `graft watch`) is written in the same
database transaction as the reference change, and reviews are stored in the
database. A watcher on another node sees new entries by polling every 250 ms.
+ The head and base commits of a review must be reachable from the references
+ in the storage core: `CreateReview`, and `UpdateReview` when it moves the
+ head, fail with `FailedPrecondition` for a commit that only the serving
+ node's copy has (push it to a branch first). An open review keeps its
+ commits alive after their branch is deleted; a closed or landed one does not.
- **Repository IDs.** A repository is identified by its storage name and
relative path, and gets an ID that is never reused: a repository removed and
created again is a new repository, and the old caches are recognized as
diff --git a/internal/gitaly/service/review/review.go b/internal/gitaly/service/review/review.go
index 8587960..a436fe3 100644
--- a/internal/gitaly/service/review/review.go
+++ b/internal/gitaly/service/review/review.go
@@ -80,15 +80,24 @@ func (s *server) CreateReview(ctx context.Context, req *gitalypb.CreateReviewReq
return nil, structerr.NewInternal("%w", err)
}
- stored, err := st.Create(&gitalypb.Review{
- TargetBranch: []byte(branch),
- BaseCommitId: base.String(),
- HeadCommitId: head.String(),
- Author: identity.Actor(ctx, anonymousActor),
- Title: req.GetTitle(),
- Description: req.GetDescription(),
- State: gitalypb.Review_STATE_OPEN_UNSPECIFIED,
- Files: files,
+ var stored *gitalypb.Review
+ err = s.writeRoots(ctx, req.GetRepository(), repo, st, func(st store.ReviewStore, check rootsCheck) error {
+ if err := check(head, base); err != nil {
+ return err
+ }
+
+ var err error
+ stored, err = st.Create(&gitalypb.Review{
+ TargetBranch: []byte(branch),
+ BaseCommitId: base.String(),
+ HeadCommitId: head.String(),
+ Author: identity.Actor(ctx, anonymousActor),
+ Title: req.GetTitle(),
+ Description: req.GetDescription(),
+ State: gitalypb.Review_STATE_OPEN_UNSPECIFIED,
+ Files: files,
+ })
+ return err
})
if err != nil {
return nil, toStatus(err)
@@ -190,64 +199,79 @@ func (s *server) UpdateReview(ctx context.Context, req *gitalypb.UpdateReviewReq
return nil, err
}
- updated, err := st.Update(req.GetId(), func(r *gitalypb.Review) error {
- if err := checkAuthor(ctx, r, "update"); err != nil {
- return err
- }
- if err := checkOpen(r); err != nil {
- return err
- }
- if expected := req.GetExpectedHeadCommitId(); expected != "" && expected != r.GetHeadCommitId() {
- return structerr.NewFailedPrecondition("review head is %s, expected %s", r.GetHeadCommitId(), expected)
- }
- if head.String() == r.GetHeadCommitId() {
- return nil
- }
+ var updated *gitalypb.Review
+ err = s.writeRoots(ctx, req.GetRepository(), repo, st, func(st store.ReviewStore, check rootsCheck) error {
+ var err error
+ updated, err = st.Update(req.GetId(), func(r *gitalypb.Review) error {
+ return moveHead(ctx, repo, req, r, head, check)
+ })
+ return err
+ })
+ if err != nil {
+ return nil, toStatus(err)
+ }
- base := git.ObjectID(r.GetBaseCommitId())
- descends, err := repo.IsAncestor(ctx, base.Revision(), head.Revision())
- if err != nil {
- if !errors.As(err, new(localrepo.InvalidCommitError)) {
- return structerr.NewInternal("%w", err)
- }
- descends = false
- }
- if !descends {
- return structerr.NewFailedPrecondition("head %s does not descend from the review base %s", head, base)
- }
+ return &gitalypb.UpdateReviewResponse{Review: s.withRequirements(updated)}, nil
+}
- files, err := changedFiles(ctx, repo, base, head)
- if err != nil {
+// moveHead moves the review r to head, for UpdateReview. check verifies the
+// new head as a root of the storage core (REVIEW ROOTS R1); a head that does
+// not move is not checked.
+func moveHead(ctx context.Context, repo *localrepo.Repo, req *gitalypb.UpdateReviewRequest, r *gitalypb.Review, head git.ObjectID, check rootsCheck) error {
+ if err := checkAuthor(ctx, r, "update"); err != nil {
+ return err
+ }
+ if err := checkOpen(r); err != nil {
+ return err
+ }
+ if expected := req.GetExpectedHeadCommitId(); expected != "" && expected != r.GetHeadCommitId() {
+ return structerr.NewFailedPrecondition("review head is %s, expected %s", r.GetHeadCommitId(), expected)
+ }
+ if head.String() == r.GetHeadCommitId() {
+ return nil
+ }
+ if err := check(head); err != nil {
+ return err
+ }
+
+ base := git.ObjectID(r.GetBaseCommitId())
+ descends, err := repo.IsAncestor(ctx, base.Revision(), head.Revision())
+ if err != nil {
+ if !errors.As(err, new(localrepo.InvalidCommitError)) {
return structerr.NewInternal("%w", err)
}
+ descends = false
+ }
+ if !descends {
+ return structerr.NewFailedPrecondition("head %s does not descend from the review base %s", head, base)
+ }
- // Verdicts on the same commit have the same outcome, so the change
- // since that commit is computed once per distinct commit.
- survivesByCommit := map[string]bool{}
- for _, v := range r.GetVerdicts() {
- if !v.GetCurrent() {
- continue
- }
- survives, ok := survivesByCommit[v.GetCommitId()]
- if !ok {
- survives, err = onlyCommentOrDocs(ctx, repo, git.ObjectID(v.GetCommitId()), head)
- if err != nil {
- return structerr.NewInternal("%w", err)
- }
- survivesByCommit[v.GetCommitId()] = survives
+ files, err := changedFiles(ctx, repo, base, head)
+ if err != nil {
+ return structerr.NewInternal("%w", err)
+ }
+
+ // Verdicts on the same commit have the same outcome, so the change
+ // since that commit is computed once per distinct commit.
+ survivesByCommit := map[string]bool{}
+ for _, v := range r.GetVerdicts() {
+ if !v.GetCurrent() {
+ continue
+ }
+ survives, ok := survivesByCommit[v.GetCommitId()]
+ if !ok {
+ survives, err = onlyCommentOrDocs(ctx, repo, git.ObjectID(v.GetCommitId()), head)
+ if err != nil {
+ return structerr.NewInternal("%w", err)
}
- v.Current = survives
+ survivesByCommit[v.GetCommitId()] = survives
}
-
- r.Files = files
- r.HeadCommitId = head.String()
- return nil
- })
- if err != nil {
- return nil, toStatus(err)
+ v.Current = survives
}
- return &gitalypb.UpdateReviewResponse{Review: s.withRequirements(updated)}, nil
+ r.Files = files
+ r.HeadCommitId = head.String()
+ return nil
}
// onlyCommentOrDocs reports whether every file changed between from and to is
diff --git a/internal/gitaly/service/review/roots.go b/internal/gitaly/service/review/roots.go
new file mode 100644
index 0000000..fb0b885
--- /dev/null
+++ b/internal/gitaly/service/review/roots.go
@@ -0,0 +1,131 @@
+package review
+
+import (
+ "context"
+ "errors"
+
+ "github.com/feder-cr/git-ai/internal/git"
+ "github.com/feder-cr/git-ai/internal/git/localrepo"
+ "github.com/feder-cr/git-ai/internal/graft/corestore"
+ "github.com/feder-cr/git-ai/internal/graft/corestore/gitops"
+ "github.com/feder-cr/git-ai/internal/graft/review/store"
+ "github.com/feder-cr/git-ai/internal/structerr"
+ "github.com/feder-cr/git-ai/proto/go/gitalypb"
+)
+
+// maxRootsAttempts bounds the compare-and-swap of REVIEW ROOTS R1: a conflict
+// means a checkpoint was recorded between the check and the write, and
+// checkpoints are minutes apart at the least.
+const maxRootsAttempts = 3
+
+// rootsStore is the review store of authoritative mode (dbreview.Store), where
+// a review's commits are roots of the storage core's object graph.
+type rootsStore interface {
+ // Refs returns the references in the storage core and the sequence of the
+ // snapshot.
+ Refs() (map[string]corestore.Target, uint64, error)
+ // WithRootsAt returns the store whose writes require that no checkpoint
+ // newer than rootsAt was recorded.
+ WithRootsAt(rootsAt uint64) store.ReviewStore
+}
+
+// rootsCheck checks that commits a write is about to record as a review's
+// head or base are reachable from the references of the snapshot the write
+// carries.
+type rootsCheck func(commits ...git.ObjectID) error
+
+// writeRoots runs write, a review write that may record new head or base
+// commits, under REVIEW ROOTS R1 (doc/graft/PLAN7.md). write calls check for
+// the commits it records before it records them. In authoritative mode check
+// verifies them against the references of a snapshot (refs, S) of the storage
+// core, and write's store refuses the write with ErrReviewRootsStale when a
+// checkpoint after S was recorded in between: then a new snapshot is taken and
+// write runs again, at most maxRootsAttempts times in all, after which the
+// request is Aborted. With the files store (the storage core is off or in
+// shadow mode) the commits are not roots of the storage core and check
+// accepts them.
+func (s *server) writeRoots(ctx context.Context, repoProto *gitalypb.Repository, repo *localrepo.Repo, st store.ReviewStore, write func(store.ReviewStore, rootsCheck) error) error {
+ rs, ok := st.(rootsStore)
+ if !ok {
+ return write(st, func(...git.ObjectID) error { return nil })
+ }
+
+ for attempt := 0; attempt < maxRootsAttempts; attempt++ {
+ refs, seq, err := rs.Refs()
+ switch {
+ case errors.Is(err, corestore.ErrRepositoryNotFound):
+ return structerr.NewFailedPrecondition("repository is not imported into the storage core")
+ case err != nil:
+ return structerr.NewUnavailable("storage core: %w", err)
+ }
+
+ snapshot := &rootsSnapshot{ctx: ctx, fresh: s.deps.GetGraftStorageSyncer(), repoProto: repoProto, repo: repo, refs: refs}
+ err = write(rs.WithRootsAt(seq), snapshot.check)
+ if !errors.Is(err, corestore.ErrReviewRootsStale) {
+ return err
+ }
+ }
+
+ return structerr.NewAborted("the commits of the review could not be checked against a stable snapshot: checkpoints were recorded concurrently")
+}
+
+// rootsSnapshot checks commits against the references of one snapshot, in the
+// local repository.
+type rootsSnapshot struct {
+ ctx context.Context
+ fresh corestore.Freshener
+ repoProto *gitalypb.Repository
+ repo *localrepo.Repo
+ refs map[string]corestore.Target
+
+ // tips are the object IDs the references point to, set once the local
+ // repository is known to hold them (a write may check more than once: the
+ // review store calls the write's function again on a version conflict).
+ tips []git.ObjectID
+}
+
+func (r *rootsSnapshot) check(commits ...git.ObjectID) error {
+ if r.tips == nil {
+ tips, err := r.localTips()
+ if err != nil {
+ return err
+ }
+ r.tips = tips
+ }
+
+ for _, commit := range commits {
+ reachable, err := gitops.IsReachable(r.ctx, r.repo, commit, r.tips)
+ if err != nil {
+ return structerr.NewInternal("check the review commit %s: %w", commit, err)
+ }
+ if !reachable {
+ return structerr.NewFailedPrecondition("commit %s of the review is not reachable from the references of the repository in the storage core", commit)
+ }
+ }
+ return nil
+}
+
+// localTips returns the object IDs the snapshot's references point to, after
+// making sure the local repository holds them. The gate caught the repository
+// up before the request, but a changeset committed since (on another node) can
+// be in the snapshot: the repository is then caught up again, to a head read
+// after this call, so at least the snapshot's.
+func (r *rootsSnapshot) localTips() ([]git.ObjectID, error) {
+ tips := make([]git.ObjectID, 0, len(r.refs))
+ for _, target := range r.refs {
+ if !target.IsSymbolic() {
+ tips = append(tips, git.ObjectID(target))
+ }
+ }
+
+ missing, err := gitops.MissingObjects(r.ctx, r.repo, tips)
+ if err != nil {
+ return nil, structerr.NewInternal("look up the references' objects: %w", err)
+ }
+ if len(missing) > 0 {
+ if err := r.fresh.EnsureFresh(r.ctx, r.repoProto); err != nil {
+ return nil, err
+ }
+ }
+ return tips, nil
+}
diff --git a/internal/gitaly/service/review/roots_test.go b/internal/gitaly/service/review/roots_test.go
new file mode 100644
index 0000000..93b2fd4
--- /dev/null
+++ b/internal/gitaly/service/review/roots_test.go
@@ -0,0 +1,217 @@
+package review
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "strings"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+ "google.golang.org/grpc/codes"
+ "google.golang.org/grpc/status"
+
+ "github.com/feder-cr/git-ai/internal/git"
+ "github.com/feder-cr/git-ai/internal/git/gittest"
+ "github.com/feder-cr/git-ai/internal/git/localrepo"
+ "github.com/feder-cr/git-ai/internal/gitaly/service"
+ "github.com/feder-cr/git-ai/internal/gitaly/storage"
+ "github.com/feder-cr/git-ai/internal/graft/corestore"
+ "github.com/feder-cr/git-ai/internal/graft/corestore/coretest"
+ "github.com/feder-cr/git-ai/internal/graft/review/store"
+ "github.com/feder-cr/git-ai/internal/testhelper"
+ "github.com/feder-cr/git-ai/internal/testhelper/testcfg"
+ "github.com/feder-cr/git-ai/proto/go/gitalypb"
+)
+
+// staleStore is a rootsStore whose first stale writes are refused with
+// ErrReviewRootsStale, as when a checkpoint is recorded between the check and
+// each of those writes.
+type staleStore struct {
+ store.ReviewStore
+ stale int
+ // snapshots counts the Refs calls; snapshot n has sequence 10*n.
+ snapshots int
+ // rootsAt are the sequences the writes carried, in order.
+ rootsAt []uint64
+}
+
+func (f *staleStore) Refs() (map[string]corestore.Target, uint64, error) {
+ f.snapshots++
+ return map[string]corestore.Target{}, uint64(10 * f.snapshots), nil
+}
+
+func (f *staleStore) WithRootsAt(rootsAt uint64) store.ReviewStore {
+ return &staleWriter{f: f, rootsAt: rootsAt}
+}
+
+type staleWriter struct {
+ store.ReviewStore
+ f *staleStore
+ rootsAt uint64
+}
+
+func (w *staleWriter) Create(r *gitalypb.Review) (*gitalypb.Review, error) {
+ w.f.rootsAt = append(w.f.rootsAt, w.rootsAt)
+ if len(w.f.rootsAt) <= w.f.stale {
+ return nil, fmt.Errorf("insert review: %w", corestore.ErrReviewRootsStale)
+ }
+ return r, nil
+}
+
+func TestWriteRootsTakesANewSnapshotAfterAConflict(t *testing.T) {
+ ctx := testhelper.Context(t)
+ s := newServer(&service.Dependencies{})
+
+ for _, tc := range []struct {
+ desc string
+ stale int
+ rootsAt []uint64
+ code codes.Code
+ }{
+ {desc: "no conflict", stale: 0, rootsAt: []uint64{10}, code: codes.OK},
+ {desc: "exactly one conflict", stale: 1, rootsAt: []uint64{10, 20}, code: codes.OK},
+ {desc: "two conflicts", stale: 2, rootsAt: []uint64{10, 20, 30}, code: codes.OK},
+ {desc: "attempts exhausted", stale: 3, rootsAt: []uint64{10, 20, 30}, code: codes.Aborted},
+ } {
+ t.Run(tc.desc, func(t *testing.T) {
+ st := &staleStore{stale: tc.stale}
+ checks := 0
+ err := s.writeRoots(ctx, nil, nil, st, func(st store.ReviewStore, _ rootsCheck) error {
+ checks++
+ _, err := st.Create(&gitalypb.Review{})
+ return err
+ })
+ require.Equal(t, tc.code, status.Code(err), "%v", err)
+ require.Equal(t, tc.rootsAt, st.rootsAt, "every attempt writes with its own snapshot")
+ require.Equal(t, len(tc.rootsAt), st.snapshots)
+ require.Equal(t, len(tc.rootsAt), checks, "every attempt checks again")
+ })
+ }
+
+ t.Run("other errors end the write", func(t *testing.T) {
+ st := &staleStore{}
+ broken := errors.New("database is down")
+ err := s.writeRoots(ctx, nil, nil, st, func(store.ReviewStore, rootsCheck) error { return broken })
+ require.ErrorIs(t, err, broken)
+ require.Equal(t, 1, st.snapshots)
+ })
+
+ // The files store holds no storage core roots: nothing is checked.
+ t.Run("files store", func(t *testing.T) {
+ files := store.Open(t.TempDir())
+ err := s.writeRoots(ctx, nil, nil, files, func(st store.ReviewStore, check rootsCheck) error {
+ require.Same(t, files, st)
+ return check(git.ObjectID("not even an object ID"))
+ })
+ require.NoError(t, err)
+ })
+}
+
+// countingFreshener counts EnsureFresh calls.
+type countingFreshener struct {
+ corestore.NopFreshener
+ calls int
+}
+
+func (f *countingFreshener) EnsureFresh(context.Context, storage.Repository) error {
+ f.calls++
+ return nil
+}
+
+func TestRootsCheckReachability(t *testing.T) {
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+ repoProto, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{SkipCreationViaService: true})
+ repo := localrepo.NewTestRepo(t, cfg, repoProto)
+
+ base := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("base"))
+ head := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("head"), gittest.WithParents(base))
+ unreachable := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("unreachable"), gittest.WithParents(base))
+ unrelated := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("unrelated"))
+
+ snapshot := func(fresh corestore.Freshener, refs map[string]corestore.Target) *rootsSnapshot {
+ return &rootsSnapshot{ctx: ctx, fresh: fresh, repoProto: repoProto, repo: repo, refs: refs}
+ }
+ refs := map[string]corestore.Target{
+ "HEAD": corestore.SymbolicTarget("refs/heads/main"),
+ "refs/heads/main": corestore.Target(head),
+ }
+
+ fresh := &countingFreshener{}
+ s := snapshot(fresh, refs)
+ require.NoError(t, s.check(head, base))
+ for _, commit := range []git.ObjectID{unreachable, unrelated} {
+ err := s.check(head, commit)
+ require.Equal(t, codes.FailedPrecondition, status.Code(err), "%v", err)
+ require.ErrorContains(t, err, commit.String())
+ }
+ require.Zero(t, fresh.calls, "every tip is local: no catch-up")
+
+ // No reference reaches anything.
+ err := snapshot(fresh, map[string]corestore.Target{"HEAD": corestore.SymbolicTarget("refs/heads/main")}).check(base)
+ require.Equal(t, codes.FailedPrecondition, status.Code(err), "%v", err)
+
+ // A tip the local repository does not have yet (committed on another node
+ // after the gate caught it up): the repository is caught up before the
+ // check. The counting Freshener does not bring the object, so the check
+ // then fails as Internal: a Freshener that returns nil must have brought
+ // every object of the snapshot.
+ absent := git.ObjectID(strings.Repeat("a", gittest.DefaultObjectHash.EncodedLen()))
+ err = snapshot(fresh, map[string]corestore.Target{"refs/heads/other": corestore.Target(absent)}).check(base)
+ require.Equal(t, 1, fresh.calls)
+ require.Equal(t, codes.Internal, status.Code(err), "%v", err)
+}
+
+// TestAuthoritativeReviewCommitsMustBeReachable is REVIEW ROOTS R1 end to end:
+// a review cannot be created on, or moved to, a commit that the references in
+// the storage core do not reach, even when the local repository has it.
+func TestAuthoritativeReviewCommitsMustBeReachable(t *testing.T) {
+ ctx, cfg, core, client := setupAuthoritative(t)
+
+ repo, repoPath := createLocalRepository(t, ctx, cfg)
+ base := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("base"), gittest.WithBranch("main"))
+ head := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("head"), gittest.WithParents(base), gittest.WithBranch("feature"))
+ tracked := importRepository(t, cfg, core, repo, repoPath, coretest.ImportOptions{})
+
+ // The first request lets the gate replace the imported copy by a cache built
+ // from the storage core; a commit written into that cache afterwards is only
+ // in the local repository, never recorded in the storage core.
+ require.Empty(t, listStoredReviews(t, ctx, client, repo, true))
+ local := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("local only"), gittest.WithParents(base))
+ _, err := client.CreateReview(ctx, &gitalypb.CreateReviewRequest{
+ Repository: repo,
+ TargetBranch: []byte("main"),
+ HeadCommitId: local.String(),
+ })
+ require.Equal(t, codes.FailedPrecondition, status.Code(err), "%v", err)
+ reviews, err := core.Meta.ListReviews(ctx, tracked.ID, "", true, 0)
+ require.NoError(t, err)
+ require.Empty(t, reviews)
+
+ created, err := client.CreateReview(ctx, &gitalypb.CreateReviewRequest{
+ Repository: repo,
+ TargetBranch: []byte("main"),
+ HeadCommitId: head.String(),
+ })
+ require.NoError(t, err)
+ id := created.GetReview().GetId()
+
+ _, err = client.UpdateReview(ctx, &gitalypb.UpdateReviewRequest{
+ Repository: repo,
+ Id: id,
+ HeadCommitId: local.String(),
+ })
+ require.Equal(t, codes.FailedPrecondition, status.Code(err), "%v", err)
+ stored, _, err := core.Meta.GetReview(ctx, tracked.ID, id)
+ require.NoError(t, err)
+ require.Equal(t, head.String(), stored.GetHeadCommitId(), "the head did not move")
+
+ // An update that keeps the head moves no commit and is not checked.
+ _, err = client.UpdateReview(ctx, &gitalypb.UpdateReviewRequest{
+ Repository: repo,
+ Id: id,
+ HeadCommitId: head.String(),
+ })
+ require.NoError(t, err)
+}
diff --git a/internal/graft/corestore/gate/gate_proof_test.go b/internal/graft/corestore/gate/gate_proof_test.go
index b0aaaa7..801b9f3 100644
--- a/internal/graft/corestore/gate/gate_proof_test.go
+++ b/internal/graft/corestore/gate/gate_proof_test.go
@@ -136,8 +136,18 @@ func (n node) ffBranch(t *testing.T, repo *gitalypb.Repository, name string, oid
require.NoError(t, err)
}
+// publish puts commit on a branch of its own, so that the storage core holds
+// it: a review's commits must be reachable from its references (REVIEW ROOTS
+// R1, doc/graft/PLAN7.md).
+func (n node) publish(t *testing.T, s seed, commit git.ObjectID) {
+ t.Helper()
+ n.createBranch(t, s.repo, "review/"+commit.String(), commit)
+}
+
+// createReview publishes head and opens a review of it against main.
func (n node) createReview(t *testing.T, s seed, head git.ObjectID) *gitalypb.Review {
t.Helper()
+ n.publish(t, s, head)
resp, err := gitalypb.NewReviewServiceClient(n.conn).CreateReview(n.ctx, &gitalypb.CreateReviewRequest{
Repository: s.repo,
TargetBranch: []byte("main"),
@@ -649,6 +659,7 @@ func proofCases() map[string]func(t *testing.T, n node, s seed) {
child := n.commit(t, s, s.base, "change", gittest.TreeEntry{Path: "a", Mode: "100644", Content: "change\n"})
next := n.commit(t, s, child, "change 2", gittest.TreeEntry{Path: "a", Mode: "100644", Content: "change 2\n"})
review := n.createReview(t, s, child)
+ n.publish(t, s, next)
_, err := gitalypb.NewReviewServiceClient(n.conn).UpdateReview(n.ctx, &gitalypb.UpdateReviewRequest{
Repository: s.repo,
Id: review.GetId(),