Merge pull request 'Grant a bar one key of the state it shows, and per-machine state its own machine's key (hq ADR 0260)' (#151) from fix/state-grants-per-key into main

This commit was merged in pull request #151.
This commit is contained in:
2026-10-08 14:09:25 +00:00
12 changed files with 242 additions and 51 deletions
+5 -3
View File
@@ -80,8 +80,9 @@ func (i *Inventory) BusRecords(ctx context.Context) (broker.Records, error) {
}
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...)
// For this machine's key alone (novox/hq ADR 0260): a bar shows its own machine's draw.
for _, sr := range catalogue.ReadsGranted(m, onMachine(declared, modules), n.Name) {
d.KeyedReads = append(d.KeyedReads, broker.KeyedRead{Read: sr.Read, Key: sr.Key})
}
d.Holds = heldHere(d.Holds, holdings, n.Name, module)
out.Assigned[n.Name] = append(out.Assigned[n.Name], d)
@@ -182,7 +183,8 @@ func declaredFor(m catalogue.Manifest, seats map[string]catalogue.SeatDeclaratio
func bucketsOf(m catalogue.Manifest) []broker.Bucket {
var out []broker.Bucket
for _, s := range m.State {
out = append(out, broker.Bucket{Module: m.Module, Name: s.Name, History: s.History, TTLSeconds: s.TTLSeconds})
out = append(out, broker.Bucket{Module: m.Module, Name: s.Name, History: s.History, TTLSeconds: s.TTLSeconds,
PerMachine: s.PerMachine})
}
return out
}
+7 -3
View File
@@ -322,16 +322,20 @@ func TestABarIsGrantedTheStateItsMachinesModulesOfferIt(t *testing.T) {
if err != nil {
t.Fatal(err)
}
reads := func(node, module string) []string {
reads := func(node, module string) []broker.KeyedRead {
for _, d := range records.Assigned[node] {
if d.Module == module {
return d.Reads
if len(d.Reads) != 0 {
t.Fatalf("%s on %s reads whole buckets: %v", module, node, d.Reads)
}
return d.KeyedReads
}
}
t.Fatalf("%s is not on %s", module, node)
return nil
}
if got := reads("laptop", "a-bar"); len(got) != 1 || got[0] != "power.draw" {
// The laptop's own key, and no other (novox/hq ADR 0260).
if got := reads("laptop", "a-bar"); len(got) != 1 || got[0] != (broker.KeyedRead{Read: "power.draw", Key: "laptop"}) {
t.Fatalf("the laptop's bar reads %v", got)
}
if got := reads("desk", "a-bar"); len(got) != 0 {