Files
CatoandClaude Fable 5.1 39bf29f158 test(bots): the rehearsal retries a gateway error once (#1516)
* feat(bots): a bot writes first, on the person's own key

A person can tell one of their bots to write first, every day at a time
they pick, with a prompt they wrote. The run happens on the person's own
OpenRouter key only; without a key the routine is kept, shown as waiting,
and skipped with the reason, so no platform key is ever spent by a timer
(fleet standing rule 2026-09-25).

- companion_routines table (one per person per bot, owner-only RLS),
  routines-store (time validation, next run in the person's zone) and the
  runner behind a cron route + 15-minute systemd timer, registered as a
  person-asked timer in the no-background-ai gate with a marker check.
- GET/PUT/DELETE /api/ai-assistants/[id]/routine for the owner.
- RoutineRow in a bot's own chat: "Writes first, every day", time and
  prompt inline, a line to Settings when a key is missing.
- Hands: the proposal line names what will be set up, never only "Sure";
  a created event's outcome carries its link.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmrXvMqAqZtbpQ4x3et

* feat(bots): a bot can ask Loki, as the person — the first connector

ask_loki: a Cat action (communication, low risk, confirmed) in the hands
launch set. The bot relays a question over the signed OrangeCat → Loki rail
to Loki's POST /api/orangecat/ask, which runs a read-only turn as the Loki
user linked to the actor; Loki's own sentence is the outcome the person
reads, and a refusal (no linked account, a spent budget) is relayed as
written. A relayed question can never dispatch, approve or spend: that stays
with send_task_to_loki, and the two verbs name each other so a question is
never dispatched as a task.

ADR-0013: D6 first connector and D7 recorded as shipped.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmrXvMqAqZtbpQ4x3et

* fix(bots): the routine's day-in-zone comes from the timezone helper

check:app-locale (new on main) refuses a literal locale handed to Intl; the
routine's next-run computation now takes the day in the person's zone from
instantToWallTime, the one rendering the app already trusts.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmrXvMqAqZtbpQ4x3et

* fix(bots): the chip knows the verb of ask_loki

The tool-label table of leading verbs gains ask → Asking / Asked, so the
chip for a bot's question to Loki never falls back to the generic label.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmrXvMqAqZtbpQ4x3et

* fix(cat): a failed "Do it?" card shows the server's sentence, not [object Object]

The confirm and reject hook handed the API's error envelope (an object) to
new Error(), so every failed action read "[object Object]". Seen live the
first time a bot asked Loki for an account not linked to Loki: Loki's
sentence naming the one step was on the action row and lost on the card.
The hook, the memory import and the interests list now read the message
through apiErrorMessage, the reader written for exactly this.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmrXvMqAqZtbpQ4x3et

* fix(companions): a bot keeps offering its hands on a repeat ask

Live on 2026-11-01 the second "Ask Loki" in one thread came back as
"I can ask Loki for you." with no fence and no "Do it?" card. The
proposal fence is taken off a reply before it is stored, so the model
saw its own earlier offers as plain sentences and copied them.

- The queued proposal is kept in the assistant message's metadata.
- The history given to the model writes the fence back onto those
  turns (withProposal), so a proposal in the history looks like one.
- proposeFromReply returns the proposal as queued; hands tests cover
  the round trip and metadata reading.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmrXvMqAqZtbpQ4x3et

* fix(companions): a proposal is a worked example, and a bare block still becomes a card

Live on 2026-11-01 a fresh bot's first "Ask Loki" came back as "Here's the
query I'll send to Loki:" over a json fence holding {"question": "..."}:
the free-tier model copied the template's inner half and left out the
action, so the person saw code and no card.

- The hands section ends with a complete block for a real offered action,
  required fields filled with their own names, instead of a template with
  <id> and {...}; it says the block is the proposal itself and to write no
  other code block.
- extractProposal reads a propose, json or untagged fence at the end; a
  block with fields but no "action" names the one offered action that owns
  every field and has its required ones present; a propose fence that said
  nothing usable comes off so it is never shown as code.
- Tests for the example, the lenient read, the inference and its refusals.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmrXvMqAqZtbpQ4x3et

* fix(bots): a failed "Do it?" card is finished, a second card starts clean, no empty bubble

Seen live on 2026-11-01 (fresh thread, two asks of Loki):
- a card whose action ran and failed kept Confirm/Reject under the reason;
  the reason is now the outcome line, as a success would be
- the second card in the thread showed the first card's failure line inside
  it: the card is keyed by its action
- a model that wrote only the block left an empty bubble above the card:
  the card's description stands in for the words, and ask_loki is described
  as the question ("Ask Loki: ...") rather than "Execute Ask Loki"

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmrXvMqAqZtbpQ4x3et

* test(bots): the five demos as one live rehearsal, run by a person

tests/e2e/bots-rehearsal.live.spec.ts walks the live site as a brand-new
person (a pseudonymous account minted at the start, no fixture secret): one
door, the shelf and a real letter, a group with two specialists in their
lanes, an event proposed and created from a "Do it?" card, Loki asked twice
with an honest outcome and a clean second card, a routine set and stopped,
and the API edges. Every assertion names the value it protects.

The Live rehearsal workflow runs it on workflow_dispatch only and keeps the
screenshots; it has no schedule, because a free-tier key is spent only when
a person asks (fleet rule 2026-09-25). docs/testing/live-rehearsal.md.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmrXvMqAqZtbpQ4x3et

* feat(bots): what a bot did stays in the thread

A "Do it?" card's outcome lived only in the slot above the composer: it left
the screen when a second card arrived and was gone on reload (seen live
2026-11-01). The confirm route now records the outcome as a line of the bot
conversation the card came from (services/companions/outcomes.ts): the
handler's own sentence with its page, or the reason it failed. The chat
re-reads the thread after the tap, so the line shows where it was asked
for, and the bot's next turn knows what happened.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmrXvMqAqZtbpQ4x3et

* test(bots): the rehearsal retries a gateway error once

Seen 2026-11-01 at 16:50Z: the first post-deploy rehearsal passed six of
seven and failed the routine step on one PUT that answered 502, because
another merge (#1515) was rolling out at that second; the same call
answered 400 a minute later. An API call in the rehearsal now retries once
after five seconds on 502/503/504 and logs that it did; two in a row stay a
failure. Documented in docs/testing/live-rehearsal.md.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmrXvMqAqZtbpQ4x3et

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-01 18:13:29 +01:00
..

OrangeCat testing

created_date: 2025-01-01 last_modified_date: 2026-09-23 last_modified_summary: Wave-6 Cat cull — dropped byok active-step source-grep; resolveProvider return is the contract.

What we believe

Signal beats headcount. A thousand tests that restate implementation are slower and weaker than a hundred that pin user-visible contracts and static invariants.

The real gate is pnpm run verify: typecheck, lint, and the check:* scripts (dead fields/labels, routes, currency units, schema columns, RPC existence, locale, changelog, …) then unit tests. Those static checks catch whole classes of rot that unit tests usually miss.

Layers

Layer Tool What belongs here
Static gates scripts/check-*.mjs inside verify Drift, forbidden patterns, SSOT
Unit Vitest Behaviour contracts, money paths, Cat tool/prompt invariants
E2E Playwright (@p0 matrix) Thin, sacred journeys that must work on a real browser

Do not grow Playwright to match unit volume. Do not chase a coverage percentage.

Cat tests (__tests__/unit/cat/)

Keep tests that fail when a user-visible or money-moving behaviour breaks, or when two sources of truth drift (registries, plan limits, provider lists, tool wiring).

Do not add:

  • Byte snapshots of prompt prose (they train people to update goldens instead of thinking)
  • Per-field exhaustiveness for every create handler (one table of forbidden/required columns is enough — see action-executor-columns.test.ts)
  • Source-grep theatre that breaks when Prettier wraps a line (unless the assertion is about wiring arguments or a TDZ order that typecheck cannot see, with whitespace collapsed)
  • A second file that re-pins the same ladder/order/fit relationship already covered in prompt-budget.test.ts

Commands

pnpm run test:unit          # what verify runs
pnpm exec vitest run __tests__/unit/cat   # Cat only
pnpm run test:e2e:matrix:p0 # sacred browser paths
pnpm run verify             # the real merge gate

When you change Cat

  1. Prefer extending an existing contract test over a new file.
  2. If a create handler learns a new money column name, add one row to the column contract table — not a new describe block with three variants.
  3. Run pnpm exec vitest run __tests__/unit/cat before push.
  • Live rehearsal: the five bot demos against the live site, started by a person, never on a timer.