With no callers list on the seat mesh-wants, the asker a step's progress names is the one the runner writes on the StepRun it asks (C-W2), mesh-pipeline-runner. Builds: design 47 H §752 (consequence), G §496; H-A-41, H-A-88 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
394 lines
21 KiB
Go
394 lines
21 KiB
Go
package assign
|
|
|
|
import (
|
|
"fmt"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-teller/tellerevents"
|
|
"mesh-delivery-assigner/internal/assignment"
|
|
"mesh-delivery-assigner/internal/puts"
|
|
"regexp"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient"
|
|
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-view/viewstate"
|
|
|
|
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
|
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-sdk/go/views"
|
|
)
|
|
|
|
// 1297/B9 (the assigner's half): the backup ask is a valid ask of the router and of mesh-sdk's layout at its key, of a kind the
|
|
// view may answer; the hold and restore asks went with the hold of a fingerprint (design 47 H §750, H-A-55).
|
|
func TestTheAssignersAsks(t *testing.T) {
|
|
t.Run("backup", theBackupAskIsValid)
|
|
t.Run("ended at the channel", anAskEndedAtTheChannelIsWrittenAgain)
|
|
t.Run("ended at the channel, read at bind", anAskEndedAtTheChannelIsReadAtBind)
|
|
}
|
|
|
|
// Issue 1966, note 151: an ask the teller says ended at the operator channel without an answer (its event ask-ended) is
|
|
// written again under a new asking, an id of its own and a new expiry, one row per kind: the rules' asks are; the
|
|
// authorising ask of a proposal (ADR 0567 §5, §11) and a put's record ask (ADR 0546) are not, nor an asking the key no longer
|
|
// holds, an end asking again would not change, or a body that does not read.
|
|
func anAskEndedAtTheChannelIsWrittenAgain(t *testing.T) {
|
|
asked := time.Date(2026, 11, 9, 22, 0, 0, 0, time.UTC)
|
|
now := asked.Add(8 * 24 * time.Hour)
|
|
digest := "sha256:" + strings.Repeat("e", 64)
|
|
backupKey, _ := asks.BackupAskKey("novox", "nats", fNew)
|
|
revertKey, _ := asks.RevertAskKey("novox", "nats", fNew)
|
|
recordKey, _ := asks.RecordAskKey("novox", "nats", digest)
|
|
assignmentsKey, _ := asks.AssignmentsAskKey("p-20261028t183000-1a2b3c")
|
|
need := RecordNeed{Node: "novox", Digest: digest, Judgement: JudgedMovesData}
|
|
record := RecordAsk(recordKey, "novox", "nats", fNew, need, 0, asked) // written before #195: no asking
|
|
put := puts.Put{FP: fNew, Why: "w", At: asked, Step: puts.Person, Ask: recordKey}
|
|
byPut := RecordAsk(recordKey, "novox", "nats", fNew, need, PutAsking(put), asked)
|
|
other := puts.Put{FP: fNew, Why: "w", At: asked.Add(time.Hour), Step: puts.Person, Ask: recordKey}
|
|
assignments := assignerAsk(AskingSeconds(asked), oc.Ask{ID: meshdeliveryclient.AskingID(assignmentsKey, AskingSeconds(asked)), Headline: "h",
|
|
Explanation: "e", Who: occ.Operator, Expires: occ.FormatTime(asked.Add(occ.ApproveLasts)), OnExpiry: "o",
|
|
Options: []oc.Option{{ID: OptionYes, Label: "Yes", Does: "d", Level: occ.Approve}}})
|
|
for _, c := range []struct {
|
|
name string
|
|
key string
|
|
a *asks.Ask // the ask the key holds; nil for none
|
|
ended string // the id of the asking that ended; "" for the one the key holds
|
|
outcome string
|
|
put *puts.Put
|
|
why string // "" when it is written again
|
|
}{
|
|
{name: "backup", key: backupKey, a: ptr(BackupAsk(backupKey, "novox", "nats", fNew, "w", 0, asked)), outcome: occ.OutcomeCancelled},
|
|
{name: "revert", key: revertKey, a: ptr(assignerAsk(AskingSeconds(asked), oc.Ask{ID: meshdeliveryclient.AskingID(revertKey, AskingSeconds(asked)),
|
|
Headline: "h", Explanation: "e", Who: occ.Operator, Expires: occ.FormatTime(asked.Add(AskLasts)), OnExpiry: "o",
|
|
Options: []oc.Option{{ID: "hold", Label: "Hold", Does: "d", Level: occ.Acknowledge}}})), outcome: occ.OutcomeExpired},
|
|
{name: "record", key: recordKey, a: &record, outcome: occ.OutcomeCancelled},
|
|
{name: "record of another put", key: recordKey, a: &record, outcome: occ.OutcomeExpired, put: &other},
|
|
{name: "record a put asked", key: recordKey, a: &byPut, outcome: occ.OutcomeExpired, put: &put, why: "put"},
|
|
{name: "assignments", key: assignmentsKey, a: &assignments, outcome: occ.OutcomeExpired, why: "ADR 0567"},
|
|
{name: "another asking stands", key: backupKey, a: ptr(BackupAsk(backupKey, "novox", "nats", fNew, "w", AskingSeconds(now), now)),
|
|
ended: meshdeliveryclient.AskingID(backupKey, AskingSeconds(asked)), outcome: occ.OutcomeExpired, why: "holds the asking"},
|
|
{name: "taken away", key: backupKey, ended: "backup-x", outcome: occ.OutcomeExpired, why: "taken away"},
|
|
{name: "refused", key: backupKey, a: ptr(BackupAsk(backupKey, "novox", "nats", fNew, "w", 0, asked)), outcome: occ.OutcomeRefused, why: "refused"},
|
|
{name: "replaced", key: backupKey, a: ptr(BackupAsk(backupKey, "novox", "nats", fNew, "w", 0, asked)), outcome: occ.OutcomeReplaced, why: "replaced"},
|
|
} {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
var current []byte
|
|
ended := c.ended
|
|
if c.a != nil {
|
|
var err error
|
|
if current, err = EncodeAsk(c.key, *c.a); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if ended == "" {
|
|
ended = mustAsk(t, *c.a).ID
|
|
}
|
|
}
|
|
body, err := tellerevents.EncodeEnded(tellerevents.Ended{Key: c.key, Ask: ended, Outcome: c.outcome})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
e, err := tellerevents.DecodeEnded(body)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
value, why := AskedAgain(e, current, c.put, now)
|
|
if c.why != "" {
|
|
if value != nil || !strings.Contains(why, c.why) {
|
|
t.Fatalf("AskedAgain = %s, %q; want nothing written, %q", value, why, c.why)
|
|
}
|
|
return
|
|
}
|
|
if why != "" {
|
|
t.Fatalf("AskedAgain says %q, want the ask written again", why)
|
|
}
|
|
a, ask, err := DecodeAsk(c.key, value)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if a.Asking <= c.a.Asking || ask.ID != meshdeliveryclient.AskingID(c.key, a.Asking) || ask.ID == ended {
|
|
t.Errorf("asking %d under %s, want a new asking above %d under an id of its own, not %s", a.Asking, ask.ID, c.a.Asking, ended)
|
|
}
|
|
if err := occ.Check(ask, now); err != nil || !ExpiresAt(ask).Equal(now.Add(AskLasts).Truncate(time.Second)) {
|
|
t.Errorf("the router refuses the ask written again (%v), or it lapses at %s, want %s", err, ExpiresAt(ask), now.Add(AskLasts))
|
|
}
|
|
})
|
|
}
|
|
for _, raw := range []string{`{"v":1,"key":"k","ask":"a"}`, `{"v":1,"key":"k","ask":"a","outcome":"expired","more":1}`} {
|
|
if _, err := tellerevents.DecodeEnded([]byte(raw)); err == nil {
|
|
t.Errorf("DecodeEnded(%s) takes a body that is not an ended ask", raw)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Issue 1966 note 155, ADR 0668 §4: an ended ask the teller said before the assigner's consumer existed is not delivered to
|
|
// it, so at bind the assigner reads the operator-channel seat's asks: the query reaches back to the earliest held asking,
|
|
// and of the answer only the held askings that lapsed or were cancelled are taken, as the teller's event says them; an
|
|
// answered or another asker's ask, and one the key no longer holds, are not.
|
|
func anAskEndedAtTheChannelIsReadAtBind(t *testing.T) {
|
|
asked := time.Date(2026, 11, 9, 22, 0, 0, 0, time.UTC)
|
|
backupKey, _ := asks.BackupAskKey("novox", "nats", fNew)
|
|
holdKey, _ := asks.BackupAskKey("g14", "nats", fNew)
|
|
restoreKey, _ := asks.BackupAskKey("ace", "nats", fNew)
|
|
hold := BackupAsk(holdKey, "g14", "nats", fNew, "w", AskingSeconds(asked), asked)
|
|
restore := BackupAsk(restoreKey, "ace", "nats", fNew, "w", AskingSeconds(asked.Add(time.Hour)), asked.Add(time.Hour))
|
|
backup := BackupAsk(backupKey, "novox", "nats", fNew, "w", 0, asked.Add(-time.Hour)) // no asking
|
|
held := map[string][]byte{}
|
|
for key, a := range map[string]asks.Ask{holdKey: hold, restoreKey: restore, backupKey: backup} {
|
|
v, err := EncodeAsk(key, a)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
held[key] = v
|
|
}
|
|
if _, ok := ChannelAsksQuery(nil); ok {
|
|
t.Error("with no ask held the channel is asked")
|
|
}
|
|
q, ok := ChannelAsksQuery(held)
|
|
if !ok || q.State != "ended" || q.Bound != ChannelAsksBound || q.Since != asked.Add(-time.Hour-time.Minute).Format(time.RFC3339) {
|
|
t.Errorf("the query is %v, want the ended asks since %s", q, asked.Add(-time.Hour-time.Minute).Format(time.RFC3339))
|
|
}
|
|
at := func(key string, a asks.Ask, state string) string {
|
|
return fmt.Sprintf(`{"key":"t.%s","state":%q}`, mustAsk(t, a).ID, state)
|
|
}
|
|
answer := `{"asks":[` + strings.Join([]string{at(holdKey, hold, occ.OutcomeExpired), at(restoreKey, restore, occ.OutcomeChosen),
|
|
at(backupKey, backup, occ.OutcomeCancelled), `{"key":"t.hold-gone","state":"expired"}`, `{"key":"open","state":"open"}`}, ",") + `],"cut":"c"}`
|
|
ended, cut, err := EndedAtChannel(held, []byte(answer))
|
|
want := []tellerevents.Ended{{Key: backupKey, Ask: mustAsk(t, backup).ID, Outcome: occ.OutcomeCancelled},
|
|
{Key: holdKey, Ask: mustAsk(t, hold).ID, Outcome: occ.OutcomeExpired}}
|
|
slices.SortFunc(want, func(a, b tellerevents.Ended) int { return strings.Compare(a.Key, b.Key) })
|
|
if err != nil || cut != "c" || !slices.Equal(ended, want) {
|
|
t.Errorf("EndedAtChannel = %+v, %q, %v; want %+v and the answer's cut", ended, cut, err, want)
|
|
}
|
|
if _, _, err := EndedAtChannel(held, []byte(`[1]`)); err == nil {
|
|
t.Error("an answer that does not read is taken")
|
|
}
|
|
}
|
|
|
|
func ptr(a asks.Ask) *asks.Ask { return &a }
|
|
|
|
func theBackupAskIsValid(t *testing.T) {
|
|
key, err := asks.BackupAskKey("ace", "mail", fNew)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
now := time.Now()
|
|
a := BackupAsk(key, "ace", "mail", fNew, "health failed, phase running: connection refused", 0, now)
|
|
if err := occ.Check(mustAsk(t, a), now); err != nil {
|
|
t.Errorf("the router refuses the ask: %v", err)
|
|
}
|
|
if _, err := EncodeAsk(key, a); err != nil {
|
|
t.Errorf("the ask cannot be written: %v", err)
|
|
}
|
|
// The ask names the machine whose backup failed and the backup's words.
|
|
if !strings.Contains(mustAsk(t, a).Explanation, "on ace") || !strings.Contains(mustAsk(t, a).Explanation, "connection refused") {
|
|
t.Errorf("the ask does not name the node and the hold's words: %q", mustAsk(t, a).Explanation)
|
|
}
|
|
// An ask written again is another asking, under an id of its own.
|
|
again := BackupAsk(key, "ace", "mail", fNew, "x", 7, now)
|
|
if again.Asking != 7 || mustAsk(t, again).ID != meshdeliveryclient.AskingID(key, 7) || mustAsk(t, again).ID == mustAsk(t, a).ID {
|
|
t.Errorf("the asking again = %d %s", again.Asking, mustAsk(t, again).ID)
|
|
}
|
|
if _, err := EncodeAsk(key, again); err != nil {
|
|
t.Errorf("the ask asked again cannot be written: %v", err)
|
|
}
|
|
if _, err := viewstate.ViewAnswerKey(key); err != nil {
|
|
t.Errorf("the view may not answer it: %v", err)
|
|
}
|
|
// The join (A1d ruling 1): mesh-sdk no longer refuses another id, no option or no ask in an assigner's ask; EncodeAsk does.
|
|
t.Run("EncodeAsk refuses what mesh-sdk no longer does", func(t *testing.T) {
|
|
good := BackupAsk(key, "ace", "mail", fNew, "x", 0, time.Unix(100, 0))
|
|
other := good
|
|
other.Asking = 3 // its id is the asking 0's
|
|
empty := good
|
|
ask := mustAsk(t, good)
|
|
ask.Options = nil
|
|
empty.Ask = assignerAsk(0, ask).Ask
|
|
for name, a := range map[string]asks.Ask{"another id": other, "no option": empty, "no ask": {}} {
|
|
if _, err := EncodeAsk(key, a); err == nil {
|
|
t.Errorf("%s: written", name)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
// 1952/WM6: the assigner's conditions are findings.
|
|
func TestTheAssignersConditions(t *testing.T) {
|
|
t.Run("1952/WM6: each said condition is a finding, its clear deletes it, said straight only with no findings bucket", saidConditionsAreFindings)
|
|
}
|
|
|
|
// 1952/WM6 (ADR 0564 §2, issue 1952 note 16): every condition the assigner says is a finding in its own bucket, under
|
|
// `<scope>.<id>.<kind>`, written at the raise and deleted at the clear, and only as a finding: the keeper is the one
|
|
// source since the controller's end (novox/hq ADR 0590 §3, issue 1126 B8). Said straight to the router only where the
|
|
// findings bucket cannot be written to at all.
|
|
func saidConditionsAreFindings(t *testing.T) {
|
|
at := time.Date(2026, 10, 29, 21, 0, 0, 0, time.UTC)
|
|
for _, c := range []struct {
|
|
raised, cleared oc.Condition
|
|
key string
|
|
}{
|
|
{SeatWaitsCondition([]string{"assignments"}), SeatWaitsCondition(nil), "module.mesh-delivery-assigner.seat-states"},
|
|
{BackupCondition("ace", "mail", fNew, "disk full", true), BackupCondition("ace", "mail", fNew, "", false), "module.ace.mail." + strings.TrimPrefix(fNew, meshcatalogclient.SourcePrefix2) + ".backup"},
|
|
} {
|
|
puts, deletes, said := map[string]mcseat.Finding{}, []string{}, 0
|
|
f := Findings{Put: func(f mcseat.Finding) error {
|
|
puts[views.FindingKey(f.Scope, f.ID, f.Kind)] = f
|
|
return nil
|
|
}, Delete: func(k string) error { deletes = append(deletes, k); return nil }, Now: func() time.Time { return at }}
|
|
say := f.Say(func(oc.Condition) error { said++; return nil })
|
|
if err := say(c.raised); err != nil {
|
|
t.Fatalf("%s: %v", c.key, err)
|
|
}
|
|
got, ok := puts[c.key]
|
|
if !ok || got.Severity != c.raised.Severity || got.Headline != c.raised.Headline || got.Observer != assignment.Module() ||
|
|
got.Subject.Machine != c.raised.Subject.Machine || said != 0 {
|
|
t.Fatalf("%s: finding %+v (written %v), said %d", c.key, got, puts, said)
|
|
}
|
|
if err := say(c.cleared); err != nil || !slices.Equal(deletes, []string{c.key}) || said != 0 {
|
|
t.Fatalf("%s: deleted %v, said %d (%v)", c.key, deletes, said, err)
|
|
}
|
|
if err := (Findings{}).Say(func(oc.Condition) error { said++; return nil })(c.raised); err != nil || said != 1 {
|
|
t.Fatalf("%s: with no findings bucket said %d (%v), want straight once", c.key, said, err)
|
|
}
|
|
}
|
|
if _, _, err := FindingOf(oc.Condition{Key: "another.x", State: occ.StateRaised}, at); err == nil {
|
|
t.Error("a condition not the assigner's is a finding")
|
|
}
|
|
}
|
|
|
|
// 1906/D4: the record ask and the backup ask are valid asks of the router and of mesh-sdk's layout at their keys, answerable in
|
|
// the view, and name the move and the node.
|
|
func TestTheRecordAndBackupAsksAreValid(t *testing.T) {
|
|
now := time.Now()
|
|
rkey, err := asks.RecordAskKey("ace", "mail", "sha256:"+strings.Repeat("b", 64))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
r := RecordAsk(rkey, "ace", "mail", fNew, RecordNeed{Node: "ace", Digest: "sha256:" + strings.Repeat("b", 64), Judgement: JudgedCannot, Words: "the composition it runs is gone"}, 2, now)
|
|
bkey, err := asks.BackupAskKey("ace", "mail", fNew)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b := BackupAsk(bkey, "ace", "mail", fNew, "no space left", 0, now)
|
|
vkey, err := asks.RevertAskKey("ace", "mail", fNew)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
v := RevertAsk(vkey, "ace", "mail", fNew, "records", "3", "restore point missing: none of form 3", 0, now)
|
|
for key, a := range map[string]asks.Ask{rkey: r, bkey: b, vkey: v} {
|
|
if err := occ.Check(mustAsk(t, a), now); err != nil {
|
|
t.Errorf("%s: the router refuses the ask: %v", key, err)
|
|
}
|
|
if _, err := EncodeAsk(key, a); err != nil {
|
|
t.Errorf("%s: cannot be written: %v", key, err)
|
|
}
|
|
if _, err := viewstate.ViewAnswerKey(key); err != nil {
|
|
t.Errorf("%s: the view may not answer it: %v", key, err)
|
|
}
|
|
}
|
|
if !strings.Contains(mustAsk(t, r).Explanation, "gone") || mustAsk(t, r).Options[0].ID != OptionYes {
|
|
t.Errorf("the record ask = %+v", mustAsk(t, r))
|
|
}
|
|
if !strings.Contains(mustAsk(t, b).Explanation, "no space left") || mustAsk(t, b).Options[0].ID != mwc.BackupAgain || mustAsk(t, b).Options[1].ID != mwc.BackupSkip {
|
|
t.Errorf("the backup ask = %+v", mustAsk(t, b))
|
|
}
|
|
// the id binds the ask to its number (review round 1, item 4); its key binds it to the build (design 47 H §750: a want names no composition)
|
|
if again := BackupAsk(bkey, "ace", "mail", fNew, "x", NextBackupAsking(0), now); mustAsk(t, again).ID == mustAsk(t, b).ID {
|
|
t.Errorf("asked again under the same id")
|
|
}
|
|
if NextBackupAsking(-1) != 0 || NextBackupAsking(0) != 2 || NextBackupAsking(2) != 3 {
|
|
t.Errorf("the numbers of the askings: %d %d %d", NextBackupAsking(-1), NextBackupAsking(0), NextBackupAsking(2))
|
|
}
|
|
// novox 2026-11-16: the router refuses a long hexadecimal string, so no word of an ask carries a digest or fingerprint whole.
|
|
held := BackupAsk(bkey, "novox", "mail", fNew, "the kept data between "+fNew+" and "+fNew+" is not known", 0, now)
|
|
if a := mustAsk(t, held); regexp.MustCompile(`[0-9a-f]{20,}`).MatchString(a.Headline + a.Explanation + a.Details) {
|
|
t.Errorf("the ask carries a long hexadecimal string: %q", a.Explanation)
|
|
}
|
|
if BackupAnswerWords("again", 0) == BackupAnswerWords("again", 1) {
|
|
t.Errorf("two answers of the same option are one want value")
|
|
}
|
|
// design 47 G §710: the revert ask names the build, the kept data, its form and the node's words, and offers hold and live;
|
|
// its finding is delivery.<node>.<module>.revert-held, a warning that needs nothing, the ask being the one message.
|
|
if va := mustAsk(t, v); va.Headline != "The revert of mail on ace has no restore point" || va.Options[0].ID != OptionRevertHold ||
|
|
va.Options[1].ID != mwc.RevertLive || len(va.Options) != 2 || va.OnExpiry != "the module keeps running its newer build" ||
|
|
!strings.Contains(va.Explanation, "records") || !strings.Contains(va.Explanation, "form 3") || !strings.Contains(va.Explanation, short(fNew)) ||
|
|
!strings.Contains(va.Explanation, "Started on the live data, the older build reads data written in the newer form.") {
|
|
t.Errorf("the revert ask = %+v", va)
|
|
}
|
|
if f := RevertHeldFinding("ace", "mail", "records", "3", "restore point missing").Finding(now); views.FindingKey(f.Scope, f.ID, f.Kind) != "delivery.ace.mail.revert-held" ||
|
|
f.Severity != "warning" || f.Needs != "Nothing for you to do." ||
|
|
f.Summary != "The revert of mail on ace is held: restore point missing (records, form 3); the ask about it waits for your answer" {
|
|
t.Errorf("the revert finding = %+v", f)
|
|
}
|
|
if RevertAnswerWords(OptionRevertLive, 1) != `the operator answered "live" to the revert ask (asking 2)` {
|
|
t.Errorf("the words of a live answer: %q", RevertAnswerWords(OptionRevertLive, 1))
|
|
}
|
|
c := BackupCondition("ace", "mail", fNew, "no space left", true)
|
|
if _, err := occ.EncodeCondition(c); err != nil {
|
|
t.Errorf("the backup condition is refused: %v", err)
|
|
}
|
|
// ADR 0546 clauses 7 and 8: a put's ask is valid at the record ask's key; for the bus its yes approves and binds the act,
|
|
// so the view cannot answer it, and it lasts no longer than an approving ask may.
|
|
put := puts.Put{FP: fNew, Why: "the bus's user list", Hold: true}
|
|
dgst := "sha256:" + strings.Repeat("b", 64)
|
|
d := ComposedDigest{Digest: dgst, Judgement: JudgedCannot, Words: "the have names no composition"}
|
|
for _, bus := range []bool{false, true} {
|
|
a, err := PutAsk(rkey, "ace", "mail", put, d, bus, now)
|
|
if err != nil {
|
|
t.Fatalf("bus %v: %v", bus, err)
|
|
}
|
|
if err := occ.Check(mustAsk(t, a), now); err != nil {
|
|
t.Errorf("bus %v: the router refuses the put's ask: %v", bus, err)
|
|
}
|
|
if _, err := EncodeAsk(rkey, a); err != nil {
|
|
t.Errorf("bus %v: the put's ask cannot be written: %v", bus, err)
|
|
}
|
|
viewed := viewstate.ViewAnswerFits(viewstate.ViewAnswer{Asking: mustAsk(t, a).ID, Option: OptionYes}, rkey, a)
|
|
yes := mustAsk(t, a).Options[0]
|
|
// mesh-sdk gives no refusal by level any more: the teller refuses an option a view cannot answer (its level is not
|
|
// acknowledge), as it did through the sdk before.
|
|
if viewed == nil {
|
|
if o, ok := occ.OptionOf(mustAsk(t, a), OptionYes); ok && o.Level != "" && o.Level != occ.Acknowledge {
|
|
viewed = fmt.Errorf("only a channel that proves who answered takes the option %s", o.ID)
|
|
}
|
|
}
|
|
switch {
|
|
case !strings.Contains(mustAsk(t, a).Explanation, "the bus's user list"):
|
|
t.Errorf("bus %v: the put's ask does not say why: %s", bus, mustAsk(t, a).Explanation)
|
|
case bus && (yes.Level != occ.Approve || yes.Binds == "" || viewed == nil || expiresAt(t, a).After(now.Add(occ.ApproveLasts))):
|
|
t.Errorf("bus: the yes is %+v, the view's answer %v, expiring %s", yes, viewed, expiresAt(t, a))
|
|
case !bus && (yes.Level != occ.Acknowledge || viewed != nil):
|
|
t.Errorf("a recorded module: the yes is %+v, the view's answer %v", yes, viewed)
|
|
}
|
|
later := put
|
|
later.At = now.Add(time.Minute)
|
|
b, _ := PutAsk(rkey, "ace", "mail", later, d, bus, now)
|
|
if mustAsk(t, b).ID == mustAsk(t, a).ID || b.Asking != PutAsking(later) {
|
|
t.Errorf("bus %v: a later put's ask is asking %d under id %q, the earlier's %q", bus, b.Asking, mustAsk(t, b).ID, mustAsk(t, a).ID)
|
|
}
|
|
if err := occ.Performs(yes, PutAct("ace", "mail", fNew, dgst)); err != nil {
|
|
t.Errorf("bus %v: the yes does not perform the act it bound: %v", bus, err)
|
|
}
|
|
if err := occ.Performs(yes, PutAct("ace", "mail", fNew, dig(fOld))); bus && err == nil {
|
|
t.Errorf("bus: the yes performs another composition's act")
|
|
}
|
|
}
|
|
}
|
|
|
|
// mustAsk is the router's ask an asks-state value carries.
|
|
func mustAsk(t *testing.T, a asks.Ask) oc.Ask {
|
|
t.Helper()
|
|
ask, err := AskOf(a)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return ask
|
|
}
|
|
|
|
func expiresAt(t *testing.T, a asks.Ask) time.Time {
|
|
t.Helper()
|
|
return ExpiresAt(mustAsk(t, a))
|
|
}
|