Merge pull request 'Let a block show a value its module keeps on the bus, and grant the bar the read (hq ADR 0260)' (#149) from feat/the-bar-takes-blocks into main

This commit was merged in pull request #149.
This commit is contained in:
2026-10-08 13:46:14 +00:00
6 changed files with 192 additions and 9 deletions
+15
View File
@@ -79,6 +79,10 @@ func (i *Inventory) BusRecords(ctx context.Context) (broker.Records, error) {
"be derived", module, n.Name)
}
d := declaredFor(m, seats)
// And the state offered to it as a seat's holder by the modules beside it (novox/hq ADR 0255).
if granted := catalogue.ReadsGranted(m, onMachine(declared, modules)); len(granted) > 0 {
d.Reads = append(append([]string(nil), d.Reads...), granted...)
}
d.Holds = heldHere(d.Holds, holdings, n.Name, module)
out.Assigned[n.Name] = append(out.Assigned[n.Name], d)
if m.Instances == catalogue.InstancesInterchangeable {
@@ -103,6 +107,17 @@ func (i *Inventory) BusRecords(ctx context.Context) (broker.Records, error) {
return out, nil
}
// onMachine is the manifests of the modules assigned to one machine that the catalogue knows.
func onMachine(declared map[string]catalogue.Manifest, modules []string) []catalogue.Manifest {
var out []catalogue.Manifest
for _, module := range modules {
if m, known := declared[module]; known {
out = append(out, m)
}
}
return out
}
// declaredFor is one module's manifest as the composer needs it: what it says about itself, and the
// protocol of every seat it holds or uses.
func declaredFor(m catalogue.Manifest, seats map[string]catalogue.SeatDeclaration) broker.Declared {
+45
View File
@@ -296,3 +296,48 @@ func TestTheBussOwnModuleBecomesTheSnapshotUser(t *testing.T) {
t.Fatalf("users derived: %v", seen)
}
}
// The bar's holder reads the state the modules beside it offer in its blocks (novox/hq ADR 0255),
// without naming them: granted on the machine where both are, and nowhere else.
func TestABarIsGrantedTheStateItsMachinesModulesOfferIt(t *testing.T) {
bar := catalogue.Manifest{Module: "a-bar", Version: "1",
Claims: []catalogue.Claim{{Name: catalogue.BarSeat, Scope: catalogue.ScopeNode}}}
power := catalogue.Manifest{Module: "power", Version: "1",
State: []catalogue.StateDeclaration{{Name: "draw"}},
Contributions: []catalogue.SeatContribution{{Seat: catalogue.BarSeat, Kind: catalogue.BarKindBlock,
Data: map[string]any{"bar": "bottom", "place": "status", "shows": "state",
"options": map[string]any{"state": "power.draw"}}}}}
inv, ctx := aMeshWith(t, bar, power)
for node, modules := range map[string][]string{"laptop": {"a-bar", "power"}, "desk": {"a-bar"}} {
if _, err := inv.AddNode(ctx, node); err != nil {
t.Fatal(err)
}
for _, module := range modules {
if _, err := inv.Assign(ctx, node, module); err != nil {
t.Fatal(err)
}
}
}
records, err := inv.BusRecords(ctx)
if err != nil {
t.Fatal(err)
}
reads := func(node, module string) []string {
for _, d := range records.Assigned[node] {
if d.Module == module {
return d.Reads
}
}
t.Fatalf("%s is not on %s", module, node)
return nil
}
if got := reads("laptop", "a-bar"); len(got) != 1 || got[0] != "power.draw" {
t.Fatalf("the laptop's bar reads %v", got)
}
if got := reads("desk", "a-bar"); len(got) != 0 {
t.Fatalf("a bar with no power beside it reads %v", got)
}
if got := reads("laptop", "power"); len(got) != 0 {
t.Fatalf("power reads %v", got)
}
}