| 1 | package equipo |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | "time" |
| 6 | |
| 7 | "amadan.net/oficina/equipo/internal/wire" |
| 8 | ) |
| 9 | |
| 10 | // The note under a failed reply says why in the approved words (Paul's |
| 11 | // copy review, 2026-11-22), names the account where Equipo knows it, and |
| 12 | // offers the one thing to do: Try again, Sign in again, or nothing. |
| 13 | func TestFailedNoteByReason(t *testing.T) { |
| 14 | now := time.Date(2026, 11, 22, 12, 0, 0, 0, time.UTC) |
| 15 | past, future := now.Add(-time.Minute), now.Add(time.Hour) |
| 16 | known := &failedAccount{ID: "cn_1", Label: "Claude (pabqas@gmail.com)", State: wire.ConnHealthy} |
| 17 | limited := func(at *time.Time) *failedAccount { |
| 18 | return &failedAccount{ID: "cn_1", Label: "Claude (pabqas@gmail.com)", State: wire.ConnLimited, ResetsAt: at} |
| 19 | } |
| 20 | one, many := []string{"m1"}, []string{"m1", "m2"} |
| 21 | const ( |
| 22 | none = "" |
| 23 | retry = "retry" |
| 24 | ) |
| 25 | for _, c := range []struct { |
| 26 | name, reason string |
| 27 | ids []string |
| 28 | acct *failedAccount |
| 29 | line, action string |
| 30 | }{ |
| 31 | {"timeout", "turn_timeout", one, nil, "The reply ran out of time on your runner. Try again, or ask for less at once.", retry}, |
| 32 | {"restarted", "runner_restarted", one, nil, "Your runner stopped before it could reply. Try again.", retry}, |
| 33 | {"interrupted", "interrupted", many, nil, "Your runner stopped before it could reply. Try again.", retry}, |
| 34 | {"provider failed, known", "provider_failed", one, known, "Claude (pabqas@gmail.com) stopped before finishing the reply. Try again.", retry}, |
| 35 | {"provider failed, unknown", "provider_failed", one, nil, "The model stopped before finishing the reply. Try again.", retry}, |
| 36 | {"account unavailable, known", "account_unavailable", one, known, "Your runner could not open Claude (pabqas@gmail.com) for this reply. Try again.", retry}, |
| 37 | {"account unavailable, unknown", "account_unavailable", one, nil, "Your runner could not open an account for this reply. Try again.", retry}, |
| 38 | {"sign in again, known", "sign_in_again", one, known, "Claude (pabqas@gmail.com) needs you to sign in again.", "/conversation/settings/connections#connection-cn_1"}, |
| 39 | {"sign in again, unknown", "sign_in_again", one, nil, "The coordinator could not answer this message.", "/conversation/settings/connections"}, |
| 40 | {"sign in again, unknown batch", "sign_in_again", many, nil, "The coordinator could not answer these messages.", "/conversation/settings/connections"}, |
| 41 | {"limited, resets later", "limited", one, limited(&future), "Claude (pabqas@gmail.com) reached its usage limit. Try again once it resets, or add another account.", none}, |
| 42 | {"limited, reset", "limited", one, limited(&past), "Claude (pabqas@gmail.com) reached its usage limit. Try again once it resets, or add another account.", retry}, |
| 43 | {"limited, reset unknown", "limited", one, limited(nil), "Claude (pabqas@gmail.com) reached its usage limit. Try again once it resets, or add another account.", none}, |
| 44 | {"limited, healthy again", "limited", one, known, "Claude (pabqas@gmail.com) reached its usage limit. Try again once it resets, or add another account.", retry}, |
| 45 | {"limited, unknown", "limited", many, nil, "The coordinator could not answer these messages.", none}, |
| 46 | {"policy", "policy_rejected", one, nil, "A safety check on your runner stopped this reply. Try again, and if it keeps happening, update your runner.", retry}, |
| 47 | {"provider rejected, known", "provider_rejected", one, known, "Claude (pabqas@gmail.com) could not work with the message as sent. Try again, or send it without attachments.", retry}, |
| 48 | {"provider rejected, unknown", "provider_rejected", one, nil, "The model could not work with the message as sent. Try again, or send it without attachments.", retry}, |
| 49 | {"attachment", "attachment_unavailable", one, nil, "A file did not arrive whole on your runner. Attach it again.", none}, |
| 50 | {"too old", "runner_too_old", one, nil, "Your runner is too old for this conversation. Update it, then try again.", none}, |
| 51 | {"storage", wire.ReasonStorageFull, many, nil, "Your runner has no room left for these attachments. Try fewer or smaller files.", none}, |
| 52 | {"unknown", "superseded", one, nil, "The coordinator could not answer this message.", retry}, |
| 53 | {"unknown batch", "failed", many, nil, "The coordinator could not answer these messages.", retry}, |
| 54 | } { |
| 55 | t.Run(c.name, func(t *testing.T) { |
| 56 | n := endedNote(wire.Turn{ID: "t_1", State: wire.TurnFailed, Reason: c.reason, MessageIDs: c.ids}, c.acct, now) |
| 57 | if n.ID != "t_1" || n.Line != c.line { |
| 58 | t.Fatalf("line %q, want %q", n.Line, c.line) |
| 59 | } |
| 60 | action := n.SignIn |
| 61 | if n.Retry { |
| 62 | if action != "" { |
| 63 | t.Fatal("two actions") |
| 64 | } |
| 65 | action = retry |
| 66 | } |
| 67 | if action != c.action { |
| 68 | t.Fatalf("action %q, want %q", action, c.action) |
| 69 | } |
| 70 | }) |
| 71 | } |
| 72 | // A stopped turn says so, with nothing to do. |
| 73 | if n := endedNote(wire.Turn{ID: "t_2", State: wire.TurnCancelled, Reason: "cancelled", MessageIDs: one}, nil, now); n.Line != "Stopped." || n.Retry || n.SignIn != "" { |
| 74 | t.Fatalf("stopped %+v", n) |
| 75 | } |
| 76 | if copyText("chat.failed.retry") != "Try again" { |
| 77 | t.Fatal("Try again") |
| 78 | } |
| 79 | } |
| 80 | |