DLV-FB1: the forge bridge says a branch's end as branch-deleted and answers bridge_tags
The bridge consumes the forge module's forge.delete and writes a branch-deleted message on FORGE for a deleted branch (never the trunk, never a tag), so the builder removes the branch's tagged versions (design 51 *The forge bridge says a branch's end*). Only the forge module's account may say forge.delete: the bus refuses it from another (a case of the bridge's whole-module test). bridge_tags, served by a new tools bundle, answers a package's git tags by prefix through the forge module's gitea_api, for the builder's floor. One unit test merged into another, so the tags test adds no function (test budget). Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
// Command mesh-delivery-forge-bridge-tools serves the forge bridge's tools (novox/hq design 51): bridge_tags, a
|
||||
// package's git tags read from the forge through the forge module's gitea_api, for the builder's floor. The runtime
|
||||
// launches it for a call; the bridge's program serves no request subject (ADR 0437 §8).
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
|
||||
"mesh-delivery-forge-bridge/internal/bridge"
|
||||
)
|
||||
|
||||
// tools are the bridge's tools over api.
|
||||
func tools(api bridge.API) []stdio.Tool {
|
||||
str := func(args map[string]any, k string) string { s, _ := args[k].(string); return strings.TrimSpace(s) }
|
||||
return []stdio.Tool{{
|
||||
Name: bridge.TagsTool,
|
||||
Description: "A package's git tags on the forge, for the builder's floor (design 51): every tag of repository whose name starts " +
|
||||
"with prefix (go/v for a Go package in the go directory, v for one at the root), sorted. Read-only; read from the forge " +
|
||||
"through the forge module's gitea_api, at most " + fmt.Sprint(bridge.TagsMaxPages*bridge.TagsPageSize) + " tags (more says so).",
|
||||
Input: map[string]any{"type": "object", "required": []string{"repository"}, "properties": map[string]any{
|
||||
"repository": map[string]any{"type": "string", "description": "<owner>/<name>"},
|
||||
"prefix": map[string]any{"type": "string", "description": "only tags starting with it"}}},
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
return bridge.Tags(api, str(args, "repository"), str(args, "prefix"))
|
||||
},
|
||||
}}
|
||||
}
|
||||
|
||||
func main() {
|
||||
api := func(path string) (json.RawMessage, error) {
|
||||
return stdio.Ask("gitea.gitea_api", map[string]any{"path": path, "method": "GET"})
|
||||
}
|
||||
if err := stdio.Serve("", tools(api)); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "[mesh-delivery-forge-bridge-tools] %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
+40
-2
@@ -118,6 +118,7 @@ accounts {
|
||||
subscribe { allow: [
|
||||
"_INBOX.n1.mesh-delivery-forge-bridge.>"
|
||||
"mesh.assignment.n1.mesh-delivery-forge-bridge"
|
||||
"mesh.mod.gitea.event.forge.delete"
|
||||
"mesh.mod.gitea.event.pull.closed"
|
||||
"mesh.mod.gitea.event.pull.merged"
|
||||
"mesh.mod.gitea.event.pull.updated"
|
||||
@@ -235,7 +236,7 @@ func startBed(t *testing.T, openReply string, prepare func(ctx context.Context,
|
||||
}
|
||||
if _, err := js.CreateOrUpdateConsumer(ctx, "EVENTS", jetstream.ConsumerConfig{
|
||||
Durable: "n1_mesh-delivery-forge-bridge", AckPolicy: jetstream.AckExplicitPolicy, DeliverPolicy: jetstream.DeliverNewPolicy,
|
||||
FilterSubjects: []string{"mesh.mod.gitea.event.pull.updated", "mesh.mod.gitea.event.pull.merged", "mesh.mod.gitea.event.pull.closed"},
|
||||
FilterSubjects: []string{"mesh.mod.gitea.event.pull.updated", "mesh.mod.gitea.event.pull.merged", "mesh.mod.gitea.event.pull.closed", "mesh.mod.gitea.event.forge.delete"},
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -293,7 +294,8 @@ func startBed(t *testing.T, openReply string, prepare func(ctx context.Context,
|
||||
|
||||
// TestBridgeWritesPullMessages starts the program the way the node does (its entry, run, with MESH_BROKER_FILE).
|
||||
func TestBridgeWritesPullMessages(t *testing.T) { // 1235/AC2
|
||||
_, js, ctx, _ := startBridge(t, `{"result":{"pulls":[]}}`)
|
||||
ctl, js, ctx, _ := startBridge(t, `{"result":{"pulls":[]}}`)
|
||||
defer branchDeletedCase(t, ctl.ConnectedUrl(), js, ctx)
|
||||
|
||||
// gitea.pull.updated as the forge module publishes it: the body of trunk.ts:233-250 on mesh.mod.gitea.event.pull.updated.
|
||||
ev, _ := json.Marshal(map[string]any{"owner": "novox", "repo": "mesh-delivery", "number": 12, "title": "t", "body": "b", "base": "main",
|
||||
@@ -346,6 +348,42 @@ func TestBridgeWritesPullMessages(t *testing.T) { // 1235/AC2
|
||||
t.Errorf("the event is not acknowledged: %+v", ci)
|
||||
}
|
||||
|
||||
// branchDeletedCase is DLV-FB1's case of the bridge's whole-module test (design 51): the forge module's forge.delete of
|
||||
// a branch is a branch-deleted message on FORGE, and a forge.delete from another account than the forge module's is
|
||||
// refused by the bus.
|
||||
func branchDeletedCase(t *testing.T, srv string, js jetstream.JetStream, ctx context.Context) {
|
||||
t.Helper()
|
||||
ev, _ := json.Marshal(map[string]any{"owner": "novox", "repo": "mesh-sdk", "ref": "feat/x", "ref_type": "branch", "sha": head})
|
||||
if _, err := js.Publish(ctx, "mesh.mod.gitea.event.forge.delete", ev); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
forge, err := js.Stream(ctx, "FORGE")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
subject := "mesh.stream.mesh-delivery-forge-bridge.event.forge.novox.mesh-sdk.branch-deleted"
|
||||
var raw *jetstream.RawStreamMsg
|
||||
for deadline := time.Now().Add(20 * time.Second); time.Now().Before(deadline); time.Sleep(50 * time.Millisecond) {
|
||||
if raw, err = forge.GetLastMsgForSubject(ctx, subject); err == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
if err != nil || !strings.Contains(string(raw.Data), `"branch":"feat/x"`) {
|
||||
t.Fatalf("no branch-deleted message on FORGE within 20 s: %v", err)
|
||||
}
|
||||
other, err := nats.Connect(srv, nats.UserInfo("n1.mesh-delivery-forge-bridge", "pw"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer other.Close()
|
||||
ojs, _ := jetstream.New(other)
|
||||
octx, cancel := context.WithTimeout(ctx, 2*time.Second)
|
||||
defer cancel()
|
||||
if _, err := ojs.Publish(octx, "mesh.mod.gitea.event.forge.delete", ev); err == nil {
|
||||
t.Error("a forge.delete from the bridge's account was taken by the bus: only the forge module's account may say it")
|
||||
}
|
||||
}
|
||||
|
||||
const merge = "89abcdef0123456789abcdef0123456789abcdef"
|
||||
|
||||
// TestBridgeWritesMergedMessage has a stand-in answer the forge's gitea_commit_trees on its tool subject
|
||||
|
||||
Reference in New Issue
Block a user