W16.5: claude-code reads which modules exist and their manifests from the catalog half through meshcatalogclient's branch follower (milestone 47/G)
Builds: design 47 G §196, §594, §614; lead answers A-5, A-15 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -2,13 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
assignerclient "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
||||
mesh "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||
catalogclient "git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient"
|
||||
catalog "git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog"
|
||||
"os"
|
||||
"reflect"
|
||||
@@ -57,7 +54,7 @@ func someSeats() []seatdef.Definition {
|
||||
// saying what its tool replaces, as the seat mesh-module-assigner and the indexer keep them on the bus.
|
||||
func aMesh(t *testing.T) aBus {
|
||||
t.Helper()
|
||||
b := aBus{AssignmentsRead: {}, ModulesRead: {}, ManifestsRead: {}}
|
||||
b := aBus{AssignmentsRead: {}}
|
||||
for _, p := range []mesh.Assignments{
|
||||
{V: 1, Node: "anchor", Decided: mesh.NodeDecided{PublicDomain: "Anchor.Example"},
|
||||
Modules: []mesh.PlacedModule{{Module: "docker"}, {Module: "zsh"}}},
|
||||
@@ -71,21 +68,33 @@ func aMesh(t *testing.T) aBus {
|
||||
b[AssignmentsRead][k] = v
|
||||
}
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// fakeCatalog is the catalog half as the tests give it: docker and zsh, docker's manifest saying what its tool replaces.
|
||||
type fakeCatalog struct {
|
||||
entries map[string]catalog.CatalogEntry
|
||||
notYet error
|
||||
}
|
||||
|
||||
func (f fakeCatalog) Entry(module string) (catalog.CatalogEntry, bool, error) {
|
||||
e, ok := f.entries[module]
|
||||
return e, ok, f.notYet
|
||||
}
|
||||
|
||||
func (f fakeCatalog) Ready() error { return f.notYet }
|
||||
|
||||
func aCatalog() fakeCatalog {
|
||||
f := fakeCatalog{entries: map[string]catalog.CatalogEntry{}}
|
||||
for module, manifest := range map[string]string{
|
||||
"docker": `{"module":"docker","replaces":{"docker_logs":["docker logs"]}}`,
|
||||
"zsh": `{"module":"zsh"}`,
|
||||
} {
|
||||
digest := fmt.Sprintf("%x", sha256.Sum256([]byte(manifest)))
|
||||
mkey, _ := catalogclient.ManifestsKey(digest)
|
||||
raw, err := json.Marshal(catalog.ManifestsByDigestValue{V: 1, Module: module, Manifest: manifest})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b[ManifestsRead][mkey] = raw
|
||||
key, _ := catalogclient.ModulesKey(module)
|
||||
b[ModulesRead][key], _ = json.Marshal(catalog.ModulesByModuleValue{V: 1, None: "nothing is built of it", Manifest: digest, Repository: "novox/mesh-catalog", Commit: "c"})
|
||||
var whole map[string]any
|
||||
_ = json.Unmarshal([]byte(manifest), &whole)
|
||||
f.entries[module] = catalog.CatalogEntry{Module: module, Manifest: whole}
|
||||
}
|
||||
return b
|
||||
return f
|
||||
}
|
||||
|
||||
func resolving(name string) []string {
|
||||
@@ -97,7 +106,7 @@ func resolving(name string) []string {
|
||||
// controller: the seats' verbs, the placed modules' own tools, every machine with its domains and addresses — a
|
||||
// loopback address never one of them.
|
||||
func TestTheMeshsToolsAreReadFromTheBus(t *testing.T) {
|
||||
m, err := ReadMeshToolsFrom(aMesh(t), someSeats(), resolving)
|
||||
m, err := ReadMeshToolsFrom(aMesh(t), aCatalog(), someSeats(), resolving)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -134,7 +143,7 @@ func TestTheMeshsToolsAreReadFromTheBus(t *testing.T) {
|
||||
case <-time.After(10 * time.Second):
|
||||
t.Fatalf("the seat list was not read: %+v", seatList.Status())
|
||||
}
|
||||
got, err := ReadMeshToolsFrom(aMesh(t), definedSeats(), resolving)
|
||||
got, err := ReadMeshToolsFrom(aMesh(t), aCatalog(), definedSeats(), resolving)
|
||||
var addrs []string
|
||||
for _, r := range got.Replacements {
|
||||
addrs = append(addrs, r.Address)
|
||||
@@ -156,7 +165,7 @@ func TestTheMeshsToolsAreReadFromTheBus(t *testing.T) {
|
||||
// **The table is generated, not written** (novox/hq ADR 0245): what the records say a verb replaces is a row,
|
||||
// the machines' seats first, and nothing is rendered where the records say nothing.
|
||||
func TestTheInsteadOfTableIsGeneratedFromTheRecords(t *testing.T) {
|
||||
m, _ := ReadMeshToolsFrom(aMesh(t), someSeats(), resolving)
|
||||
m, _ := ReadMeshToolsFrom(aMesh(t), aCatalog(), someSeats(), resolving)
|
||||
table := InsteadOf(&m)
|
||||
for _, want := range []string{
|
||||
"| `<node>/node-service-manager.` | `status` — `systemctl status`, `systemctl is-active` · `journal` — `journalctl` |",
|
||||
@@ -206,7 +215,7 @@ func TestTheInsteadOfTableIsGeneratedFromTheRecords(t *testing.T) {
|
||||
// Asked again with the same answer, nothing is written and nothing renders.
|
||||
func TestTheMeshsToolsAreKeptOnlyWhenTheyChange(t *testing.T) {
|
||||
p := Paths{State: t.TempDir()}
|
||||
m, _ := ReadMeshToolsFrom(aMesh(t), someSeats(), resolving)
|
||||
m, _ := ReadMeshToolsFrom(aMesh(t), aCatalog(), someSeats(), resolving)
|
||||
if !KeepMeshTools(p, m) {
|
||||
t.Fatal("the first answer was not kept")
|
||||
}
|
||||
@@ -243,7 +252,7 @@ func TestTheMachinesRunningAModuleAreReadFromAssignments(t *testing.T) {
|
||||
func TestTheMeshIsReadFromTheOwnersFirstViews(t *testing.T) {
|
||||
bus := aMesh(t)
|
||||
r := newMeshViews()
|
||||
for _, name := range []string{ModulesRead, ManifestsRead, AssignmentsRead} {
|
||||
for _, name := range []string{AssignmentsRead} {
|
||||
state := strings.TrimPrefix(name, strings.Split(name, ".")[0]+".")
|
||||
values := map[string]json.RawMessage{}
|
||||
for k, v := range bus[name] {
|
||||
@@ -257,16 +266,20 @@ func TestTheMeshIsReadFromTheOwnersFirstViews(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
want, err := ReadMeshToolsFrom(bus, someSeats(), resolving)
|
||||
want, err := ReadMeshToolsFrom(bus, aCatalog(), someSeats(), resolving)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := ReadMeshToolsFrom(viewStates{r}, someSeats(), resolving)
|
||||
got, err := ReadMeshToolsFrom(viewStates{r}, aCatalog(), someSeats(), resolving)
|
||||
if err != nil || !reflect.DeepEqual(got, want) || len(got.Replacements) == 0 {
|
||||
t.Fatalf("from the views: %+v, %v\nfrom the state: %+v", got, err, want)
|
||||
}
|
||||
// A reader not yet answered says so, and reads nothing.
|
||||
if _, err := ReadMeshToolsFrom(viewStates{newMeshViews()}, someSeats(), resolving); err == nil || !strings.Contains(err.Error(), "no first view") {
|
||||
// A catalog half with no first view says so, and reads no module as absent.
|
||||
if _, err := ReadMeshToolsFrom(bus, fakeCatalog{notYet: errors.New("the catalog half has no first view of main yet")}, someSeats(), resolving); err == nil || !strings.Contains(err.Error(), "no first view") {
|
||||
t.Fatalf("an unanswered catalog half: %v", err)
|
||||
}
|
||||
if _, err := ReadMeshToolsFrom(viewStates{newMeshViews()}, aCatalog(), someSeats(), resolving); err == nil || !strings.Contains(err.Error(), "no first view") {
|
||||
t.Fatalf("an unanswered first view: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -274,7 +287,7 @@ func TestTheMeshIsReadFromTheOwnersFirstViews(t *testing.T) {
|
||||
// Issue 1126 B13 AC1 (ADR 0590): over the seats the mesh defines, the rendered instructions, their table among them,
|
||||
// name no address of the controller, which is not placed: each job is named by the seat that owns it now.
|
||||
func TestTheRenderedInstructionsNameNoControllerAddress(t *testing.T) {
|
||||
m, err := ReadMeshToolsFrom(aMesh(t), someSeats(), resolving)
|
||||
m, err := ReadMeshToolsFrom(aMesh(t), aCatalog(), someSeats(), resolving)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user