G-24 tests on main: the assigner hears presence once; grants composes each module's consumer from its own subjects #247
@@ -43,36 +43,6 @@ const (
|
||||
seatDefinitionsKey = "seat:" + meshcatalog.Seat + "." + meshcatalog.VerbSeatDefinitions
|
||||
)
|
||||
|
||||
// awayNodes are the machines the watchman said away (machine-away of the seat mesh-watchdogs, §389) and not back since.
|
||||
type awayNodes struct {
|
||||
mu sync.Mutex
|
||||
away map[string]bool
|
||||
}
|
||||
|
||||
// set keeps machine away (true) or back (false).
|
||||
func (a *awayNodes) set(machine string, away bool) {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if a.away == nil {
|
||||
a.away = map[string]bool{}
|
||||
}
|
||||
if away {
|
||||
a.away[machine] = true
|
||||
} else {
|
||||
delete(a.away, machine)
|
||||
}
|
||||
}
|
||||
|
||||
// is says machine is away.
|
||||
func (a *awayNodes) is(machine string) bool {
|
||||
if a == nil {
|
||||
return false
|
||||
}
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
return a.away[machine]
|
||||
}
|
||||
|
||||
// compositionRun runs a composition step.
|
||||
type compositionRun struct {
|
||||
// runs are the composition runs of the state composition-runs (compositionruns.go).
|
||||
@@ -85,7 +55,9 @@ type compositionRun struct {
|
||||
trunk func() (mcc.Half, bool)
|
||||
// running is the last `running` heard of a module on a node (world.runningOf), never the node-engine's bucket.
|
||||
running func(node, module string) (ne.Running, bool)
|
||||
away *awayNodes
|
||||
// away says the watchman holds machine away (machine-away, not back since): the one presence the assigner keeps (world.awayNow),
|
||||
// so a durable on the watchman's streams has one hearer.
|
||||
away func(machine string) bool
|
||||
// put puts a run ask on the build seat's check queue under the assigner's name.
|
||||
put func(ctx context.Context, a buildstep.StepAsk) error
|
||||
// reads shares the catalog reads among steps (compositionreads.go); sleep waits between two tries of a read (nil: a timer).
|
||||
@@ -122,7 +94,7 @@ func (r *compositionRun) run(ctx context.Context, id string, step meshwants.Step
|
||||
var ends []machineEnd
|
||||
var keys []string
|
||||
for _, node := range nodes {
|
||||
if r.away.is(node) {
|
||||
if r.away != nil && r.away(node) {
|
||||
ends = append(ends, machineEnd{warnings: []string{node + " is away (the watchman's machine-away), so it is not composed"}})
|
||||
continue
|
||||
}
|
||||
@@ -633,26 +605,6 @@ func (r *compositionRun) programs(ctx context.Context, half mcc.Half) (func(node
|
||||
}, nil
|
||||
}
|
||||
|
||||
// heardPresence keeps a machine-away (away true) or machine-back of the seat mesh-watchdogs (§389, §436): the machine it names.
|
||||
func heardPresence(a *awayNodes, away bool, m jetstream.Msg, logf func(string, ...any)) {
|
||||
var e struct {
|
||||
Machine string `json:"machine"`
|
||||
}
|
||||
if err := json.Unmarshal(m.Data(), &e); err != nil || e.Machine == "" {
|
||||
logf("%s holds no machine, left: %v", m.Subject(), err)
|
||||
} else {
|
||||
a.set(e.Machine, away)
|
||||
if away {
|
||||
logf("%s is away (machine-away): a composition step does not compose it until its machine-back", e.Machine)
|
||||
} else {
|
||||
logf("%s is back (machine-back): a composition step composes it again", e.Machine)
|
||||
}
|
||||
}
|
||||
if err := m.Ack(); err != nil {
|
||||
logf("acknowledging %s: %v", m.Subject(), err)
|
||||
}
|
||||
}
|
||||
|
||||
// trunkOf is the trunk's catalog half the assigner's views hold, trunk naming the first watched branch, or false while none is
|
||||
// held.
|
||||
func trunkOf(iv *catalogViews, trunk func() string) func() (mcc.Half, bool) {
|
||||
|
||||
@@ -102,8 +102,7 @@ func newRunStand(t *testing.T, revisionEngine, trunkEngine, seatDigest string) *
|
||||
return json.RawMessage(`{"candidate":"main.7","node":"` + node + `","verdict":"composed","input":{"node":"` + node + `"},"modules":[],"own":{},"took":1,"v":1}`), nil
|
||||
}
|
||||
running := map[string]string{"ace": "src2:e1", "g14": "src2:e2"}
|
||||
away := &awayNodes{}
|
||||
away.set("shanks", true)
|
||||
away := func(machine string) bool { return machine == "shanks" }
|
||||
keeper := testKeeper(&objectsMem{objs: map[string][]byte{}}, time.Now)
|
||||
s.runs = newCompositionRuns(newRunsMem(), defaultRunSettings, time.Now, t.Logf)
|
||||
s.r = &compositionRun{runs: s.runs,
|
||||
|
||||
@@ -123,6 +123,7 @@ func hearDelivery(ctx context.Context, js jetstream.JetStream, w *world, wake fu
|
||||
m, at, err := presenceOf(data)
|
||||
if err == nil {
|
||||
w.heardPresence(m, true, at)
|
||||
logf("%s is away (machine-away): a composition step does not compose it until its machine-back", m)
|
||||
}
|
||||
return err
|
||||
}},
|
||||
@@ -130,6 +131,7 @@ func hearDelivery(ctx context.Context, js jetstream.JetStream, w *world, wake fu
|
||||
m, at, err := presenceOf(data)
|
||||
if err == nil {
|
||||
w.heardPresence(m, false, at)
|
||||
logf("%s is back (machine-back): a composition step composes it again", m)
|
||||
}
|
||||
return err
|
||||
}},
|
||||
|
||||
@@ -32,7 +32,6 @@ import (
|
||||
|
||||
mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshwatchdogs"
|
||||
occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
|
||||
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
@@ -527,9 +526,7 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
||||
gate.Follow(seatlist.ProcessBus(bus.Call, hub), wake, logger.Printf)
|
||||
}
|
||||
// The build seat's step-ended of an ask deletes the input kept for it (design 47 G §354) and ends the composition run that waits
|
||||
// for it (A-240); the watchman's machine-away and machine-back say which machines a composition step does not compose (§64,
|
||||
// §389). Registered before the hub starts.
|
||||
away := &awayNodes{}
|
||||
// for it (A-240). The machines a composition step does not compose are the watchman's machine-away, heard once, in the world (§64, §389).
|
||||
// The composition runs (design 47 G §718, §719), watched in their own state; a build seat's step-ended of a run's ask ends
|
||||
// the run in its key.
|
||||
var runs *compositionRuns
|
||||
@@ -560,11 +557,6 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
||||
return err
|
||||
}
|
||||
}
|
||||
for subject, isAway := range map[string]bool{meshwatchdogs.SubjectMachineAwayAll: true, meshwatchdogs.SubjectMachineBackAll: false} {
|
||||
if err := hub.Handle(subject, func(m jetstream.Msg) { heardPresence(away, isAway, m, logger.Printf) }); err != nil {
|
||||
logger.Printf("%s is not heard, so a composition step asks a machine that sleeps: %v", subject, err)
|
||||
}
|
||||
}
|
||||
// The indexer's manifests, modules and module graph, through its first views and views family, never its buckets
|
||||
// (DLV-F2r, ADR 0631): the first pass waits for the three answers, as it waits for every watch to hand what stands.
|
||||
if iv != nil {
|
||||
@@ -712,7 +704,7 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
||||
// The composition step (design 47 G §22, §354): the seat mesh-wants' accepted kind step, run by one run ask per machine.
|
||||
if bus != nil && js != nil && inputs != nil && p.publishWants != nil && runs != nil {
|
||||
run := &compositionRun{runs: runs, inputs: &compositionInputs{machines: w.machinesOf, callFile: bus.CallFile}, keeper: inputs, reads: &compositionReads{}, call: bus.CallKept,
|
||||
trunk: trunkOf(iv, w.trunkName), running: w.runningOf, away: away, put: runAskPublisher(js), ask: bus.CallFile, now: time.Now, logf: logger.Printf}
|
||||
trunk: trunkOf(iv, w.trunkName), running: w.runningOf, away: func(machine string) bool { return w.awayNow()[machine] }, put: runAskPublisher(js), ask: bus.CallFile, now: time.Now, logf: logger.Printf}
|
||||
steps := &compositionSteps{node: thisNode, say: p.publishWants, run: run.run, resume: run.resume, ended: runs.stepEnded, now: time.Now, logf: logger.Printf,
|
||||
asker: stepAskerOf(seatlist.Definition(gate.Reader, meshwants.Seat))}
|
||||
move := steps.move(ctx) // the readers a rerun carried (§727, A-470d)
|
||||
|
||||
@@ -35,6 +35,7 @@ import (
|
||||
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
|
||||
"mesh-grants/internal/buscompose"
|
||||
"mesh-grants/internal/grants"
|
||||
)
|
||||
|
||||
@@ -651,9 +652,19 @@ func TestTheGrantsPartWhole(t *testing.T) {
|
||||
})
|
||||
|
||||
// And what the part composes holds on a server that loads it (one integration test per module, the test budget).
|
||||
t.Run("the composed grants hold on a server that loads them", theBusNodeFollowsTheSealedListUnderTheComposedGrants)
|
||||
t.Run("the tool runner hears every event on a server that loads its grants", theToolRunnerHearsEveryEventOnTheBus)
|
||||
t.Run("a runtime denied the marks is delivered no call on a marked subject", aRuntimeDeniedTheMarksHearsNoMarkedCall)
|
||||
// These read each account's own subjects, which the part composes beneath the wide grant of every account (the unit tests'
|
||||
// TestMain does the same): the mechanisms of the scoped grants are built whole all the same.
|
||||
scoped := func(f func(*testing.T)) func(*testing.T) {
|
||||
return func(t *testing.T) {
|
||||
was := buscompose.EveryAccountMayDoEverything
|
||||
buscompose.EveryAccountMayDoEverything = false
|
||||
defer func() { buscompose.EveryAccountMayDoEverything = was }()
|
||||
f(t)
|
||||
}
|
||||
}
|
||||
t.Run("the composed grants hold on a server that loads them", scoped(theBusNodeFollowsTheSealedListUnderTheComposedGrants))
|
||||
t.Run("the tool runner hears every event on a server that loads its grants", scoped(theToolRunnerHearsEveryEventOnTheBus))
|
||||
t.Run("a runtime denied the marks is delivered no call on a marked subject", scoped(aRuntimeDeniedTheMarksHearsNoMarkedCall))
|
||||
}
|
||||
|
||||
// lockedLog is the part's log, read by the test while the part writes it.
|
||||
|
||||
@@ -1698,6 +1698,11 @@ func TestEveryMeshAccountMayDoEverything(t *testing.T) {
|
||||
if err != nil || !slices.Equal(m.Publish, []string{AllSubjects}) || !slices.Equal(m.Subscribe, []string{AllSubjects}) {
|
||||
t.Fatalf("a module account = %v / %v (%v), want every subject both ways", m.Publish, m.Subscribe, err)
|
||||
}
|
||||
// The wide grant leaves a module its consumer: its filters are its own events', never the grant's ">".
|
||||
if c, ok := ConsumerFor(Principal{Kind: KindModule, Node: "a", Module: "plain", Consumes: []string{"nats.done"}}); !ok || slices.Contains(c.Filters, AllSubjects) ||
|
||||
!slices.Contains(c.Filters, "mesh.mod.nats.event.done") {
|
||||
t.Errorf("a module's consumer under the wide grant = %v, %v, want its own event filters", c.Filters, ok)
|
||||
}
|
||||
e, err := PermissionsFor(Principal{Kind: KindEnrolment, Node: "new"})
|
||||
if err == nil && slices.Contains(e.Publish, AllSubjects) {
|
||||
t.Errorf("an enrolling node is granted every subject: %v", e.Publish)
|
||||
|
||||
@@ -148,7 +148,9 @@ func ConsumerFor(p Principal) (Consumer, bool) {
|
||||
if p.Kind != KindModule || (len(p.Consumes) == 0 && len(p.Watches) == 0 && !hearsItsOwn && !hearsAStream) {
|
||||
return Consumer{}, false
|
||||
}
|
||||
perms, err := PermissionsFor(p)
|
||||
// The module's own subjects, never its account's grant: every account may subscribe to every subject (EveryAccountMayDoEverything),
|
||||
// and a filter drawn from ">" names no event, so no consumer would be composed for any module.
|
||||
perms, err := scopedPermissionsFor(p)
|
||||
if err != nil {
|
||||
return Consumer{}, false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user