mesh-vault: a read of the assignments before their first view is answered is the fault away

H-A-717's answer to DQ-55: mesh-vault's word is answered as away, the view's owner verb named.

Builds: design 47 H2 H-A-708 (2), H-A-717 (DQ-55)
This commit is contained in:
2026-11-25 17:15:24 +01:00
parent 8f8d749bb8
commit 3b7d5c8328
2 changed files with 14 additions and 10 deletions
@@ -77,21 +77,18 @@ func unwrapToolAnswer(raw json.RawMessage) []byte {
return raw
}
// viewAssignments is the assignments reader over the picture: a key asked before the first view is answered is an error, so
// the caller waits (the "not yet" of the vault's other reads), never a read of the owner's bucket.
// viewAssignments is the assignments reader over the picture: a key asked before the first view is answered is the fault
// `away` naming the view's owner verb (design 47 H2 H-A-708 (2), H-A-717 DQ-55), never a read of the owner's bucket.
func viewAssignments(f func() *views.Follower) AssignerReader {
ready := func() (*views.Follower, error) {
fol := f()
if fol == nil {
return nil, fmt.Errorf("the vault reads the assigner's assignments only when it runs as the module")
}
select {
case <-fol.Ready():
return fol, nil
default:
s := fol.Status()
return nil, fmt.Errorf("the first view of the assigner's assignments is not answered yet (%s asked %d times)", s.Tool, s.Asks)
if err := fol.Unread(); err != nil {
return nil, err
}
return fol, nil
}
return AssignerReader{
Keys: func() ([]string, error) {
@@ -5,10 +5,12 @@ import (
"encoding/json"
"errors"
"fmt"
"strings"
"sync"
"testing"
"time"
"git.novox.be/novox/mesh-sdk/go/busretry"
"git.novox.be/novox/mesh-sdk/go/views"
)
@@ -32,8 +34,13 @@ func TestAnUnansweredFirstViewOfTheAssignmentsIsAFindingTheAnswerClears(t *testi
f, _ := newAssignmentsView(ask, func(string) {}, nil, heldFindings{&mu, held})
f.Bound, f.Wait = 30*time.Millisecond, 10*time.Millisecond
reader := viewAssignments(func() *views.Follower { return f })
if _, err := reader.Keys(); err == nil {
t.Fatal("the assignments was read before its first view")
// H-A-708 (2): before the first view a read is the fault `away` naming the view's owner verb, at once.
var away *busretry.Away
if _, err := reader.Keys(); !errors.As(err, &away) || away.Part != AssignmentsTool || !strings.HasPrefix(away.Words, "not read yet since ") {
t.Fatalf("the assignments was read before its first view, or not as away: %v", err)
}
if _, err := reader.Read("g14.node"); !errors.As(err, &away) {
t.Fatalf("a read before the first view: %v", err)
}
done := make(chan error, 1)
go func() { done <- f.Start(context.Background()) }()