Files
mesh-delivery/modules/mesh-delivery-forge-bridge/internal/bridge/moved_test.go
T
jschoubben 7ac48fd882 B2, B3: the forge bridge says head-moved and carries the one model
B2: on every branch-moved of a watched branch, and at its start for every watched branch's head,
the bridge reads the head through the seat git's verb branch, as a kept call that waits on the
holder's return while the branch is watched, and writes one head-moved (repository, branch,
head, before the head held in its state heads, start) on its stream forge; a head equal to the
one held writes nothing. It reads no pull request, no tree, no file and no protection: the
merged and pushed messages, their inputs and the state inputs, the call of git.pull, the finding
branch-unprotected with its held finding writer, and the ten-second redelivery go. A move whose
head cannot be read is left unacknowledged for the bus to deliver again.

B3: the pull-message path (Convert, the open pull requests at start and reconnect, the
forge-delete message), the groups (internal/groups' group part, forge.group.merged, end-asks,
bridge_groups, bridge_group_end_again), bridge_merged_message with the forge-made reader, the
checker's owed and the merge act of a switched key (with the switch's bookkeeping read) go, with
their consumes, invokes, states and requires. The gate's owed path stays (H-A-71), its catch-up
from the gate's verb groups gone with that verb.

The two meet in main.go and the package compiles only with both, as it did not since B1. The
unit suites pass; the whole test (integration) is rewritten in B4.

Builds: design 47 H §739, §764 (the forge bridge; the branch protection); lead answers H-A-23, H-A-27, H-A-48, H-A-71

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-20 03:31:04 +01:00

78 lines
3.3 KiB
Go

package bridge
import (
"context"
"encoding/json"
"testing"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-forge-bridge/forgemsg"
"git.novox.be/novox/mesh-sdk/go/keys"
)
// Design 47 G §4, §507, A-236; H §739: the watched branches are the registrations' by origin, and before the first
// registration the gate's source's, no branch fixed in code; a move of a watched branch is one head-moved naming the
// repository, the branch, the head read through the seat git's verb branch, the head held before and start; the read asks
// nothing but branch, and an unprotected branch's head is read like any other.
func TestAMoveOfAWatchedBranchIsOneHeadMoved(t *testing.T) {
w := &Watched{}
w.Set([]Registered{{Origin: "novox/mesh-sdk", Branches: []string{"main", "beta"}}}, []string{"main"})
for _, c := range []struct {
repo, branch string
want bool
}{{"novox/mesh-sdk", "beta", true}, {"novox/mesh-sdk", "feat/x", false}, {"novox/other", "main", false}} {
if got := w.Watches(c.repo, c.branch); got != c.want {
t.Errorf("registered: %s of %s watched %v, want %v", c.branch, c.repo, got, c.want)
}
}
if !watchedOf("main").Watches("novox/other", "main") || watchedOf("main").Watches("novox/other", "beta") {
t.Errorf("before the first registration the gate's source's branches are watched, of every repository")
}
const head, before = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "cccccccccccccccccccccccccccccccccccccccc"
moved := Moved{Owner: "novox", Repo: "mesh-sdk", Branch: "feat/47-H"}
for _, c := range []struct {
name string
answer string
head string
fails bool
}{
{"a protected branch", `{"head":"` + head + `","protected":true}`, head, false},
{"an unprotected branch, read like any other (ADR 0682 §13)", `{"head":"` + head + `","protected":false}`, head, false},
{"an answer naming no head", `{"head":"abc"}`, "", true},
{"a refusal", `{"error":"no such branch","error-kind":"not-found"}`, "", true},
} {
var asked []string
ask := func(_ context.Context, key string, body any) (json.RawMessage, error) {
b, _ := json.Marshal(body)
asked = append(asked, key+" "+string(b))
return json.RawMessage(c.answer), nil
}
got, err := ReadHead(context.Background(), ask, moved)
if (err != nil) != c.fails || got != c.head {
t.Errorf("%s: %q %v, want %q, failing %v", c.name, got, err, c.head, c.fails)
}
if len(asked) != 1 || asked[0] != `seat:git.branch {"branch":"feat/47-H","repository":"novox/mesh-sdk"}` {
t.Errorf("%s: asked %v, want only the seat git's branch", c.name, asked)
}
}
for _, c := range []struct {
name string
before string
start bool
}{{"the first move", "", false}, {"a later move", before, false}, {"read at the start", before, true}} {
msg, err := HeadMoved(moved, head, c.before, c.start)
if err != nil {
t.Fatalf("%s: %v", c.name, err)
}
h, err := forgemsg.DecodeHeadMoved(msg.Data)
want := forgemsg.HeadMoved{V: forgemsg.Version, Repository: "novox/mesh-sdk", Branch: "feat/47-H", Head: head, Before: c.before, Start: c.start}
if err != nil || h != want || msg.Event != "forge.novox.mesh-sdk."+keys.EscapeName("feat/47-H")+".head-moved" {
t.Errorf("%s: %s %+v (%v), want %+v", c.name, msg.Event, h, err, want)
}
}
if _, err := HeadMoved(moved, head, head, false); err == nil {
t.Errorf("a head equal to the one held makes a message; want none")
}
}