vole
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software:2222/vole.git
A free and open-source forge that lives in your Git repo.
Test the merge result before landing it
e5478085e5b53a2892d0649d6f07c6f0a5653378 · Keenan Nemetz · 11d ago · parent db5e4382
Test the merge result before landing it A protected branch could receive a non-fast-forward landing whose tree was never built: the gate asked for checks on the request head, and the merge commit was made at landing time. A pushed merge with the right parents but extra content was accepted too. Publish the merge commit under refs/vole/candidates/, test it as the base branch, and make the gate require its results. Approvals name the head and the base branch, so a moved base retests without a new approval. A merger who clicks while that run is still going waits for it instead of clicking again. A pushed merge commit now has to carry exactly the tree a clean merge would produce. Closes: 01M61QQ56TESQ1HTMB1Z5C3733
forge/landing/candidate_test.go +117
| @@ -0,0 +1,117 @@ | |||
| 1 | package landing | ||
| 2 | |||
| 3 | // The combined result has one identity: the ref name carries the request and the | ||
| 4 | // two tips, so asking twice reuses the commit and a moved base makes the old one | ||
| 5 | // stale without any bookkeeping. | ||
| 6 | |||
| 7 | import ( | ||
| 8 | "strings" | ||
| 9 | "testing" | ||
| 10 | |||
| 11 | "github.com/rodent-software/vole/metadata" | ||
| 12 | ) | ||
| 13 | |||
| 14 | func TestCandidateIsPublishedAndReused(t *testing.T) { | ||
| 15 | t.Parallel() | ||
| 16 | f := newFixture(t) | ||
| 17 | base := f.commit("", "a.md", "one\n", "base") | ||
| 18 | if err := f.g.UpdateRef("refs/heads/main", base); err != nil { | ||
| 19 | t.Fatal(err) | ||
| 20 | } | ||
| 21 | head := f.commit(base, "b.md", "feature\n", "head") | ||
| 22 | moved := f.commit(base, "c.md", "other\n", "base moved") | ||
| 23 | if err := f.g.UpdateRef("refs/heads/main", moved); err != nil { | ||
| 24 | t.Fatal(err) | ||
| 25 | } | ||
| 26 | id := f.review("keenan", head, "reviewer") | ||
| 27 | req, err := metadata.GetRequest(f.g, id) | ||
| 28 | if err != nil { | ||
| 29 | t.Fatal(err) | ||
| 30 | } | ||
| 31 | |||
| 32 | c, conflicts, err := EnsureCandidate(f.g, req, moved, head) | ||
| 33 | if err != nil { | ||
| 34 | t.Fatalf("ensure: %v", err) | ||
| 35 | } | ||
| 36 | if len(conflicts) > 0 { | ||
| 37 | t.Fatalf("conflicts = %v", conflicts) | ||
| 38 | } | ||
| 39 | if c.Ref != CandidateRef(req, moved, head) || !strings.HasPrefix(c.Ref, CandidateRoot) { | ||
| 40 | t.Fatalf("ref = %q, want the candidate namespace", c.Ref) | ||
| 41 | } | ||
| 42 | tip, err := f.g.RevParseRaw(c.Ref) | ||
| 43 | if err != nil || tip != c.SHA { | ||
| 44 | t.Fatalf("ref tip = %q, %v; want %s", tip, err, c.SHA) | ||
| 45 | } | ||
| 46 | parents, err := f.g.CommitParents(c.SHA) | ||
| 47 | if err != nil { | ||
| 48 | t.Fatal(err) | ||
| 49 | } | ||
| 50 | if len(parents) != 2 || parents[0] != moved || parents[1] != head { | ||
| 51 | t.Fatalf("parents = %v, want [%s %s]", parents, moved, head) | ||
| 52 | } | ||
| 53 | |||
| 54 | // The same question has one answer, not a new commit every time. | ||
| 55 | again, _, err := EnsureCandidate(f.g, req, moved, head) | ||
| 56 | if err != nil || again.SHA != c.SHA { | ||
| 57 | t.Fatalf("ensure twice = %v, %v; want the same commit %s", again, err, c.SHA) | ||
| 58 | } | ||
| 59 | found, ok, err := LookupCandidateAt(f.g, req, moved, head) | ||
| 60 | if err != nil || !ok || found.SHA != c.SHA { | ||
| 61 | t.Fatalf("lookup = %+v, %v, %v; want %s", found, ok, err, c.SHA) | ||
| 62 | } | ||
| 63 | |||
| 64 | // A further base move is a different landing, so the old result is not it. | ||
| 65 | movedAgain := f.commit(moved, "d.md", "third\n", "base moved again") | ||
| 66 | if err := f.g.UpdateRef("refs/heads/main", movedAgain); err != nil { | ||
| 67 | t.Fatal(err) | ||
| 68 | } | ||
| 69 | if _, ok, err := LookupCandidateAt(f.g, req, movedAgain, head); err != nil || ok { | ||
| 70 | t.Fatalf("the old result matched a new base: ok=%t err=%v", ok, err) | ||
| 71 | } | ||
| 72 | next, conflicts, err := EnsureCandidate(f.g, req, movedAgain, head) | ||
| 73 | if err != nil || len(conflicts) > 0 { | ||
| 74 | t.Fatalf("ensure for the new base: %v %v", err, conflicts) | ||
| 75 | } | ||
| 76 | if next.SHA == c.SHA { | ||
| 77 | t.Fatal("a new base reused the old combined result") | ||
| 78 | } | ||
| 79 | parents, err = f.g.CommitParents(next.SHA) | ||
| 80 | if err != nil { | ||
| 81 | t.Fatal(err) | ||
| 82 | } | ||
| 83 | if len(parents) != 2 || parents[0] != movedAgain || parents[1] != head { | ||
| 84 | t.Fatalf("new parents = %v, want [%s %s]", parents, movedAgain, head) | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | func TestCandidateConflictPublishesNothing(t *testing.T) { | ||
| 89 | t.Parallel() | ||
| 90 | f := newFixture(t) | ||
| 91 | base := f.commit("", "a.md", "one\n", "base") | ||
| 92 | if err := f.g.UpdateRef("refs/heads/main", base); err != nil { | ||
| 93 | t.Fatal(err) | ||
| 94 | } | ||
| 95 | head := f.commit(base, "a.md", "branch\n", "branch edit") | ||
| 96 | moved := f.commit(base, "a.md", "base edit\n", "base edit") | ||
| 97 | if err := f.g.UpdateRef("refs/heads/main", moved); err != nil { | ||
| 98 | t.Fatal(err) | ||
| 99 | } | ||
| 100 | id := f.review("keenan", head, "reviewer") | ||
| 101 | req, err := metadata.GetRequest(f.g, id) | ||
| 102 | if err != nil { | ||
| 103 | t.Fatal(err) | ||
| 104 | } | ||
| 105 | c, conflicts, err := EnsureCandidate(f.g, req, moved, head) | ||
| 106 | if err != nil { | ||
| 107 | t.Fatalf("ensure: %v", err) | ||
| 108 | } | ||
| 109 | if c != nil || len(conflicts) == 0 { | ||
| 110 | t.Fatalf("conflicting merge = %+v, %v; want conflicts and no candidate", c, conflicts) | ||
| 111 | } | ||
| 112 | if refs, err := CandidateRefs(f.g, req.ID); err != nil { | ||
| 113 | t.Fatal(err) | ||
| 114 | } else if len(refs) != 0 { | ||
| 115 | t.Fatalf("a conflict published refs: %v", refs) | ||
| 116 | } | ||
| 117 | } | ||