Files
mesh-delivery/sdk/seatdefs/domain.go
T
jschoubben 67127ce60d The checker takes a head's seat definitions as the indexer does, from one reading in the domain SDK, so an outside definer is never laid over the seat list (ADR 0636 §5, ADR 0634 §1-2; issue 1966)
The checker read any touched contracts module's definitions, skipped the
check that a definition names its own directory's seat, and copied the
indexer's tree reading. sdk/seatdefs now holds the reading and the rule of
which contracts module may define a seat; the indexer's keeping, its
revision seats and the checker's head seats all use it. Two heads defining
one seat fail the judging unless one hands it over to its domain's module.

Claude-Session: https://claude.ai/code/session_01NcbgfFSnn24M3GcqttoU7i
2026-11-06 10:37:00 +01:00

65 lines
2.9 KiB
Go

package seatdefs
// Where a seat of the mesh's own contracts may be defined (novox/hq ADR 0636 §5, ADR 0634 §7): a definition names its
// glossary domain; a seat of the mesh's own contracts is taken only from that domain's contracts module
// (mesh-<domain>-contracts), or from mesh-contracts for a domain with none. A definition moving from mesh-contracts to
// its domain's contracts module is a handover: the new definer takes the seat over, and a removal from the module that is
// not the seat's domain's keeps the last trunk definition until the domain's module defines it.
import (
"fmt"
"slices"
"strings"
"git.novox.be/novox/mesh-sdk/go/seatdef"
)
// Fallback is the mesh's contracts module for a domain with no contracts module of its own.
const Fallback = "mesh-contracts"
// domainsWithContracts are the domains whose seats have a contracts module of their own (ADR 0634 §7). Every other
// domain's seats are defined in Fallback.
var domainsWithContracts = []string{"Delivery", "Provisioning", "Identity and access", "Health and repair",
"Connectivity", "Operator and conversation"}
// DomainContracts is the module that defines a domain's seats: mesh-<domain>-contracts, the heading lowercased with its
// spaces as dashes, or Fallback for a domain with none.
func DomainContracts(domain string) string {
if !slices.Contains(domainsWithContracts, domain) {
return Fallback
}
return "mesh-" + strings.ReplaceAll(strings.ToLower(domain), " ", "-") + "-contracts"
}
// Own says a contracts module is one of the mesh's own: Fallback or a domain's.
func Own(module string) bool {
return module == Fallback || slices.ContainsFunc(seatdef.Domains, func(d string) bool {
return module == DomainContracts(d) && module != Fallback
})
}
// Refusal is, for a definition a contracts module of the mesh's own holds, why it may not: the words naming the module
// and the domain's. Empty when the module may define the seat (a module outside the mesh's own contracts defines what it
// likes, ADR 0625 §7).
func Refusal(module string, d seatdef.Definition) string {
if !Own(module) {
return ""
}
if want := DomainContracts(d.Domain); want != module {
return fmt.Sprintf("it is a seat of the domain %q, whose seats %s defines, and %s defines it", d.Domain, want, module)
}
return ""
}
// HandsOver says a seat its holder defines is handed over to a definer: the holder is a module of the mesh's own that is
// not the definer, and the definer is the seat's domain's contracts module.
func HandsOver(holder, definer string, d seatdef.Definition) bool {
return holder != definer && Own(holder) && DomainContracts(d.Domain) == definer
}
// HandoverPending says a seat a holder of the mesh's own no longer defines waits for its domain's module: the holder is
// not the domain's (named by the definition it held), so its last definition stays until that module defines it.
func HandoverPending(holder, domain string) bool {
return Own(holder) && DomainContracts(domain) != holder
}