package inventory import ( "slices" "testing" "git.novox.be/novox/mesh-sdk/go/announce" "github.com/novox/mesh-controller/internal/broker" ) // Sweep 2026-10-30 (issue 774): a read is judged for its reader. The controller's lease, which its announcement marks // readable by nobody, is granted to the parts named for it (ADR 0561 ยง3) and refused to every other; a state its owner // announced readable is granted; one it keeps and did not is refused; an owner that announced nothing is read as before. // Each refusal is said, and a refusal already said is not said again. func TestAReadIsJudgedForItsReader(t *testing.T) { announced := map[string]announce.States{ "mesh-controller": broker.ControllerAnnouncement("novox"), "owner": {Module: "owner", States: []announce.State{{Name: "open", Readable: true}, {Name: "closed"}}}, } for name, c := range map[string]struct { reader, read string granted bool }{ "the lease, by the vault": {"mesh-vault", "mesh-controller.lease", true}, "the lease, by the grants part": {"mesh-grants", "mesh-controller.lease", true}, "the lease, by a module not named": {"mesh-config", "mesh-controller.lease", false}, "a readable state": {"reader", "owner.open", true}, "a state kept and not readable": {"reader", "owner.closed", false}, "an owner that announced nothing": {"reader", "quiet.any", true}, "a mirror the controller marks open": {"pacman", "mesh-controller.declared-packages", true}, } { assigned := map[string][]broker.Declared{"novox": {{Module: c.reader, Reads: []string{c.read}}}} var said []string judgeReads(assigned, announced, func(module, node, read string) { said = append(said, read) }) d := assigned["novox"][0] if slices.Contains(d.Reads, c.read) != c.granted || slices.Contains(d.ReadsRefused, c.read) == c.granted { t.Errorf("%s: granted %v, refused %v", name, d.Reads, d.ReadsRefused) } if (len(said) == 1) == c.granted { t.Errorf("%s: said %v", name, said) } } }