K18 (asker hears refused): Take answers Refused with the router's words for a refused ask

The ask is closed as any ended ask is, then the asker's request ends with why.

Builds: design 47 G §570, §638

Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
This commit is contained in:
2026-11-11 20:31:03 +01:00
parent 6beae382b3
commit 9cefd47223
2 changed files with 18 additions and 0 deletions
@@ -153,6 +153,10 @@ func (c *Client) Take(w seat.Warrant, act func(seat.Option, seat.Warrant) error)
if _, err := c.State.Update(c.key(w.Ask), k, e.Revision); err != nil && !errors.Is(err, stdio.ErrChanged) {
return "", err
}
if w.Outcome == OutcomeRefused {
// The router never took the ask (design 47 G 570): its asker's request ends with the router's words.
return Refused, fmt.Errorf("the ask %s was refused: %s", w.Ask, w.Words)
}
return Recorded, nil
}
o, err := For(w, c.Module, k.Ask)
@@ -140,6 +140,20 @@ func TestAnAskEndedWithoutAChoiceIsRecordedAndNothingDone(t *testing.T) {
}
}
func TestAnAskTheRouterRefusedEndsTheRequestWithItsWords(t *testing.T) {
c, _ := client()
_ = c.Ask(askedHeld())
w := askedWarrant()
w.Outcome, w.Option, w.By, w.Words = OutcomeRefused, "", nil, "its expiry passes the bound of its level"
h, err := c.Take(w, func(seat.Option, seat.Warrant) error { t.Fatal("acted"); return nil })
if h != Refused || err == nil || !strings.Contains(err.Error(), w.Words) {
t.Fatalf("%s %v, want refused with the router's words", h, err)
}
if h, _ := c.Take(askedWarrant(), func(seat.Option, seat.Warrant) error { t.Fatal("acted after it ended"); return nil }); h != Done {
t.Errorf("the refused ask was not closed: %s", h)
}
}
func TestAKeyPrefixIsPutBeforeEveryKeyOfTheClientsOwnStateAndNotBeforeWhere(t *testing.T) {
for _, tc := range []struct{ prefix, key string }{{"n1.", "n1.ask.d-1"}, {"", "ask.d-1"}} {
c, _ := client()