Files
mesh-delivery/modules/mesh-delivery-forge-bridge/internal/bridge/bridge_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

97 lines
3.3 KiB
Go

package bridge
import (
"context"
"encoding/json"
"errors"
"strings"
"testing"
"mesh-delivery-forge-bridge/internal/gitfixture"
)
// gitFixture is one answer of the seat git's fixtures, by its name and what it is of.
func gitFixture(t *testing.T, name, of string) json.RawMessage {
t.Helper()
return gitfixture.Given(t, name, of)
}
func TestBridgeTagsAnswersAPackagesTagsByPrefixPageByPage(t *testing.T) { // DLV-FB1, design 51 *The floor*; design 47 *The seat git*
more := gitFixture(t, "tags answers", "verb:tags.answer") // go/v0.1.15, go/v0.1.14, more
failed := gitFixture(t, "tags answers an error, never none", "verb:tags.answer")
last := json.RawMessage(`{"repository":"novox/mesh-sdk","tags":["go/v0.1.2","v0.0.1"],"page":2,"bound":50}`)
type asked struct {
key string
in string
}
for _, row := range []struct {
name string
answer func(page int) (json.RawMessage, error)
repo string
tags []string
more bool
pages int
failing string
}{
{name: "two pages, the second says no more", repo: "novox/mesh-sdk", tags: []string{"go/v0.1.14", "go/v0.1.15", "go/v0.1.2"}, pages: 2,
answer: func(p int) (json.RawMessage, error) {
if p == 1 {
return more, nil
}
return last, nil
}},
{name: "every page says more: stopped at the bound", repo: "novox/mesh-sdk", more: true, pages: TagsMaxPages,
answer: func(int) (json.RawMessage, error) { return json.RawMessage(`{"tags":[],"more":true}`), nil }},
{name: "the seat does not answer", repo: "novox/mesh-sdk", failing: "page 1", pages: 1,
answer: func(int) (json.RawMessage, error) { return nil, errors.New("down") }},
{name: "an error answer is an error, never none", repo: "novox/mesh-sdk", failing: "404", pages: 1,
answer: func(int) (json.RawMessage, error) { return failed, nil }},
{name: "a repository with no owner", repo: "mesh-sdk", failing: "<owner>/<name>"},
} {
var calls []asked
call := func(_ context.Context, key string, body any) (json.RawMessage, error) {
in, _ := json.Marshal(body)
calls = append(calls, asked{key, string(in)})
var p struct{ Page int }
_ = json.Unmarshal(in, &p)
return row.answer(p.Page)
}
a, err := Tags(context.Background(), call, row.repo, "go/v")
if row.failing != "" {
if err == nil || !strings.Contains(err.Error(), row.failing) {
t.Errorf("%s: %v, want an error naming %q", row.name, err, row.failing)
}
} else if err != nil || !slicesEqual(a.Tags, row.tags) || a.More != row.more {
t.Errorf("%s: Tags = %+v, %v", row.name, a, err)
}
if len(calls) != row.pages {
t.Errorf("%s: %d calls, want %d", row.name, len(calls), row.pages)
}
if len(calls) > 0 && (calls[0].key != "seat:git.tags" || calls[0].in != `{"page":1,"prefix":"go/v","repository":"novox/mesh-sdk"}`) {
t.Errorf("%s: first call %+v", row.name, calls[0])
}
}
}
func slicesEqual(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}
// watchesMain watches the branch main of every repository, as the registrations of a test name it.
var watchesMain = watchedOf("main")
// watchedOf watches the branches of every repository, before the first registration, as the gate's source names them.
func watchedOf(branches ...string) *Watched {
w := &Watched{}
w.Set(nil, branches)
return w
}