Files
mesh-catalog/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/writes_test.go
T
jschoubben 24b244bc88
mesh/delivery merged: source.main moved to novox/mesh-catalog@27a7757b970e
mesh/check pass 24b244bc88dc on 27a7757b970e | carried from 6b6d5cba7195 | unit 2046 run, 2327 kept, 6 skipped | integration 2066 run, 2346 kept, 10 s…
mesh-delivery-gate: ask no Approve of a merge the forge account cannot carry out, and say why (issue 1945)
car-hunter #2 was approved and its commit status then refused 403. Before the ask the
gate reads merge.writes for each repository it covers; where the merging account cannot
write, nothing is asked, the delivery waits on 'the forge account cannot write <repo>:
gitea_grant_write' and a condition is raised. gitea.repo.writable reads it again and
asks an approved, refused merge of it again.
2026-10-26 16:39:56 +01:00

45 lines
2.1 KiB
Go

package main
import (
"strings"
"testing"
)
// Issue 1945: car-hunter #2 was asked, approved, and its commit status refused 403, since the forge's merging account only
// read the repository. 1945/AC3: a pull request whose checks passed, in a repository the merging account cannot write, is
// not asked; it waits saying so, loud as a condition at once. 1945/AC4: the gitea module's gitea.repo.writable asks it then.
func TestAnUnwritableRepositoryIsNotAskedAndSaysSoUntilTheWriteIsGranted(t *testing.T) {
w := announced(t)
conds := hearConditions(w)
w.forge.unwritable = map[string]bool{"novox/app": true}
hear(t, w, shimCheckedKey, judgedAt("novox/app", 7, readyHead, "pass", "t1t1t1t1t1t1"))
w.h.React()
if w.op.count() != 0 || len(w.op.open()) != 0 {
t.Fatalf("the operator was asked %d times for a merge the forge account cannot carry out", w.op.count())
}
d := w.h.deliveries[IDOf("novox/app", readyHead)]
want := "the forge account cannot write novox/app: gitea_grant_write"
if d.Ready.Waits != want || d.Ready.CannotWrite != want {
t.Fatalf("waits %q, cannot_write %q; wanted %q", d.Ready.Waits, d.Ready.CannotWrite, want)
}
if c := conds.last(d.ID); c == nil || c.State != "raised" || !strings.Contains(c.Summary+c.Explanation+c.Headline, "cannot write novox/app") {
t.Fatalf("not said as a condition: %+v", c)
}
// Looked at again with nothing changed, the forge is not read again: the read holds until the grant or its bound.
asked := len(w.forge.asked)
w.h.React()
if len(w.forge.asked) != asked || w.op.count() != 0 {
t.Fatalf("read again %d times, asked %d", len(w.forge.asked)-asked, w.op.count())
}
delete(w.forge.unwritable, "novox/app")
hear(t, w, writableEvent, map[string]string{"owner": "novox", "repo": "app", "account": "mesh-tools"})
w.h.React()
if w.op.count() != 1 {
t.Fatalf("after the write was granted the operator was asked %d times, wanted once", w.op.count())
}
if d.Ready.CannotWrite != "" || strings.Contains(d.Ready.Waits, "cannot write") {
t.Fatalf("still says it cannot write: %q / %q", d.Ready.CannotWrite, d.Ready.Waits)
}
}