GR10 (A-12, A-10): the grants part says wait-held and wait-ended as its seat's events, and a release ends the wait as released
A release writes an ask to compose; the pass says wait-ended how released once, and a wait whose grant came says how ran. The events go through Conn.EmitSeat. The late finding is the watchman's (design 47 G §269), not written here. Builds: design 47 G §276, §266, §269, G-20 A-10, A-12 Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
This commit is contained in:
@@ -222,3 +222,5 @@ func (s ownStore) Delete(state, key string) error { return s.c.State(state).Dele
|
||||
type emitting struct{ c *process.Conn }
|
||||
|
||||
func (e emitting) Emit(event string, body any) error { return e.c.Emit(event, body) }
|
||||
|
||||
func (e emitting) EmitSeat(seat, event string, body any) error { return e.c.EmitSeat(seat, event, body) }
|
||||
|
||||
@@ -144,6 +144,11 @@ type runtimeBus struct{}
|
||||
func (runtimeBus) Call(key string, body any) (json.RawMessage, error) { return stdio.Ask(key, body) }
|
||||
func (runtimeBus) Emit(event string, body any) error { return stdio.Emit(event, body) }
|
||||
|
||||
// EmitSeat is never asked of the tools: only the process holds the grant to publish a seat's event (design 47 G A-10).
|
||||
func (runtimeBus) EmitSeat(seat, event string, _ any) error {
|
||||
return fmt.Errorf("the tools do not say the seat %s's %s: the part's process does", seat, event)
|
||||
}
|
||||
|
||||
func schema(properties map[string]string, required ...string) map[string]any {
|
||||
props := map[string]any{}
|
||||
for name, description := range properties {
|
||||
|
||||
@@ -62,6 +62,8 @@ type fakeBus struct {
|
||||
refuseTo map[string]bool
|
||||
calls []string
|
||||
events []string
|
||||
// seatEvents are the seat events said, as seat.event.
|
||||
seatEvents []string
|
||||
writes []string
|
||||
// Each membership's subject: the last membership said there, every notice, and whether it is refused.
|
||||
stream map[string][]byte
|
||||
@@ -389,6 +391,13 @@ func (b *fakeBus) Emit(event string, _ any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *fakeBus) EmitSeat(seat, event string, _ any) error {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
b.seatEvents = append(b.seatEvents, seat+"."+event)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *fakeBus) count(key string) int {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
@@ -2585,6 +2594,15 @@ func TestGrants(t *testing.T) {
|
||||
if w := func() []grants.HeldWait { x, _ := p.WaitsOf(); return x.(grants.WaitsSaid).Waits }(); len(w) != 1 || !w[0].Released {
|
||||
t.Errorf("after the release: %+v", w)
|
||||
}
|
||||
// A-12: the held wait is said at its start, a release is said ended at the pass its ask makes, and said once.
|
||||
p.Compose()
|
||||
p.Compose()
|
||||
if got := strings.Join(b.seatEvents, ","); got != "mesh-grants.wait-held,mesh-grants.wait-ended" {
|
||||
t.Errorf("seat events = %q, want wait-held then one wait-ended (released)", got)
|
||||
}
|
||||
if x, _ := p.WaitsOf(); len(x.(grants.WaitsSaid).Late) != 0 {
|
||||
t.Errorf("a released wait is late: %+v", x)
|
||||
}
|
||||
b.put(grants.ReadModules, "mod-y", meshcatalog.ModulesByModuleValue{V: keys.Version, Fp2: fp, Manifest: meshcatalogclient.ManifestDigest([]byte(yManifest)),
|
||||
Repository: "novox/y", Commit: "c"})
|
||||
if res := p.Compose(); len(res.Grants.Missing) != 0 || len(said) != 2 || said[1].State != occ.StateCleared {
|
||||
|
||||
@@ -62,6 +62,8 @@ type Store interface {
|
||||
// Emitter says one of the part's events.
|
||||
type Emitter interface {
|
||||
Emit(event string, body any) error
|
||||
// EmitSeat says an event of a seat the module holds, on mesh.seat.<seat>.event.<event> (design 47 G A-10).
|
||||
EmitSeat(seat, event string, body any) error
|
||||
}
|
||||
|
||||
// UserListState is the value of `user-list`: the list the grants part composed (users and grants, no hashes),
|
||||
|
||||
@@ -28,6 +28,8 @@ type HeldWait struct {
|
||||
meshgrants.Wait
|
||||
// Released says a person released the entry (grants_release): it is held no more.
|
||||
Released bool `json:"released,omitempty"`
|
||||
// Ended says wait-ended was said for the release: a released entry is said ended once.
|
||||
Ended bool `json:"ended,omitempty"`
|
||||
}
|
||||
|
||||
// WaitsState is the value of KeyWaits, by the held module.
|
||||
@@ -77,16 +79,48 @@ func (p *Part) settleWaits(res *Result, in Inputs, missing []string) {
|
||||
held[module] = true
|
||||
}
|
||||
changed := false
|
||||
for module := range held {
|
||||
say := func(event string, w meshgrants.Wait) bool {
|
||||
if p.Emit == nil {
|
||||
return true
|
||||
}
|
||||
if err := p.Emit.EmitSeat(meshgrants.Seat, event, w); err != nil {
|
||||
res.Errors = append(res.Errors, fmt.Sprintf("the seat event %s of %s could not be said: %v", event, w.Module, err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
for _, module := range sortedKeys(held) {
|
||||
if _, ok := st.Waits[module]; ok {
|
||||
continue
|
||||
}
|
||||
st.Waits[module] = HeldWait{Wait: meshgrants.Wait{Bound: GrantingBound.String(), ClockFrom: clock, Fp: in.Fingerprints[module],
|
||||
w := HeldWait{Wait: meshgrants.Wait{Bound: GrantingBound.String(), ClockFrom: clock, Fp: in.Fingerprints[module],
|
||||
Module: module, Part: "mesh-grants", Since: now, Step: meshgrants.WaitStepGrant, Version: in.Fingerprints["mesh-grants"]}}
|
||||
if !say(meshgrants.EventWaitHeld, w.Wait) {
|
||||
continue
|
||||
}
|
||||
st.Waits[module] = w
|
||||
changed = true
|
||||
}
|
||||
for module := range st.Waits {
|
||||
if !held[module] {
|
||||
for _, module := range sortedKeys(st.Waits) {
|
||||
w := st.Waits[module]
|
||||
switch {
|
||||
case w.Released && !w.Ended:
|
||||
// A-12: the released entry goes on, the wait is said ended `released`, and nothing is raised late for it.
|
||||
ended := w.Wait
|
||||
ended.How = meshgrants.WaitHowReleased
|
||||
if say(meshgrants.EventWaitEnded, ended) {
|
||||
w.Ended = true
|
||||
st.Waits[module] = w
|
||||
changed = true
|
||||
}
|
||||
case !held[module]:
|
||||
if !w.Released {
|
||||
ended := w.Wait
|
||||
ended.How = meshgrants.WaitHowRan
|
||||
if !say(meshgrants.EventWaitEnded, ended) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
delete(st.Waits, module)
|
||||
changed = true
|
||||
}
|
||||
@@ -148,5 +182,10 @@ func (p *Part) ReleaseWait(caller, module, why string, record func(what, why str
|
||||
if _, err := p.Store.Put(StateUserList, KeyWaits, data); err != nil {
|
||||
return nil, fmt.Errorf("the release could not be kept: %w", err)
|
||||
}
|
||||
// The part's process says wait-ended at the pass this ask makes (only it holds the grant to publish a seat's event).
|
||||
ask, _ := json.Marshal(Ask{By: caller, At: p.now()})
|
||||
if _, err := p.Store.Put(StateUserList, KeyAsked, ask); err != nil {
|
||||
return nil, fmt.Errorf("the release was kept, but the ask to compose could not be written: %w", err)
|
||||
}
|
||||
return map[string]any{"released": module, "by": w.By}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user