firstview adopts the shared branch follower over a wiring of its own consumer (views held with the assigner's, findings through its held writer, events routed to each adopted view); the console's Source gives Modules from the catalog entries, the manifest an entry carries whole; the indexer's modules and manifests first views and their consumes are removed, the registrations and the gate's source-moved are consumed. Builds: design 47 G §196, §594, §614; lead answers A-5, A-27, A-103 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package console
|
|
|
|
import (
|
|
"encoding/json"
|
|
"sync"
|
|
|
|
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog"
|
|
|
|
"github.com/novox/mesh-tools/node-tools/internal/bus"
|
|
mt "github.com/novox/mesh-tools/node-tools/internal/meshtest"
|
|
)
|
|
|
|
// busSource is a Source over a bus connection's own states, which a test's fixture mesh fills: the console's tests stand a
|
|
// membership that reads the four states beside it, where the tool runner itself holds first views (firstview.Views).
|
|
type busSource struct{ conn *bus.Conn }
|
|
|
|
func (b busSource) State(name string) (map[string][]byte, error) {
|
|
var mu sync.Mutex
|
|
keys := map[string][]byte{}
|
|
stop, err := b.conn.StateWatch(b.conn.Credential().Module, name, "", func(c bus.StateChange) error {
|
|
if c.Current && c.Op == "put" {
|
|
mu.Lock()
|
|
keys[c.Key] = c.Value
|
|
mu.Unlock()
|
|
}
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
stop()
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
return keys, nil
|
|
}
|
|
|
|
func (b busSource) Entry(name, key string) ([]byte, error) {
|
|
entry, err := b.conn.StateGet(b.conn.Credential().Module, name, key)
|
|
if err != nil || entry == nil {
|
|
return nil, err
|
|
}
|
|
return entry.Value, nil
|
|
}
|
|
|
|
// Modules reads the test bed's entries of the catalog half (meshtest.ModulesRead), as the tool runner's first views hold them.
|
|
func (b busSource) Modules() (map[string]meshcatalog.CatalogEntry, error) {
|
|
raw, err := b.State(mt.ModulesRead)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := map[string]meshcatalog.CatalogEntry{}
|
|
for module, value := range raw {
|
|
var e meshcatalog.CatalogEntry
|
|
if err := json.Unmarshal(value, &e); err != nil {
|
|
return nil, err
|
|
}
|
|
out[module] = e
|
|
}
|
|
return out, nil
|
|
}
|