diff --git a/apps/mobile/src/tokens.test.ts b/apps/mobile/src/tokens.test.ts
new file mode 100644
index 0000000..e5e23ec
--- /dev/null
+++ b/apps/mobile/src/tokens.test.ts
@@ -0,0 +1,73 @@
+///
+// Hermit's design tokens (docs/design/polish/decisions.md): every color is a docs/brand/tokens.json value, or a mix of
+// two of them (mix): the surfaces between the canvas and white, the tonal fills between a surface and an accent, and
+// the scrims. Light is Quiet craft; dark is Deep sea. The motion tokens live beside them (docs/design/polish/decisions.md,
+// "Motion"): plain numbers, no animation library.
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { mix } from "./theme.ts";
+import { duration, easing, stagger, staggerDelay } from "./motion.ts";
+
+test("mix(a, b, t) holds at a when t is 0 and at b when t is 1", () => {
+ assert.equal(mix("#F5EDE1", "#B4483A", 0), "#F5EDE1");
+ assert.equal(mix("#F5EDE1", "#B4483A", 1), "#B4483A");
+});
+
+test("mix rounds to a whole hex channel at the midpoint", () => {
+ // Half of #000000 → #808080: the blend rounds, it does not truncate.
+ assert.equal(mix("#000000", "#FFFFFF", 0.5), "#808080");
+});
+
+test("mix answers in uppercase #RRGGBB even when the inputs are lowercase", () => {
+ assert.match(mix("#ffffff", "#2b221b", 0.5), /^#[0-9A-F]{6}$/);
+});
+
+test("mix keeps every channel between the two inputs while t is between 0 and 1", () => {
+ const pairs: Array<[string, string]> = [
+ ["#000000", "#FFFFFF"],
+ ["#06121D", "#5EF0CF"],
+ ["#2B221B", "#8A5912"],
+ ];
+ for (const [a, b] of pairs) {
+ for (const t of [0.25, 0.5, 0.75]) {
+ const c = mix(a, b, t);
+ const blend = [0, 1, 2].map((i) => parseInt(c.slice(1 + i * 2, 3 + i * 2), 16));
+ const from = [0, 1, 2].map((i) => parseInt(a.slice(1 + i * 2, 3 + i * 2), 16));
+ const to = [0, 1, 2].map((i) => parseInt(b.slice(1 + i * 2, 3 + i * 2), 16));
+ for (let i = 0; i < 3; i++) {
+ assert.ok(
+ blend[i] >= Math.min(from[i], to[i]) && blend[i] <= Math.max(from[i], to[i]),
+ `channel ${i} of ${c} should stay between ${a} and ${b} at t=${t}`,
+ );
+ }
+ }
+ }
+});
+
+test("staggerDelay spaces items out by one step and stops at stagger.max", () => {
+ assert.equal(staggerDelay(0), 0);
+ assert.equal(staggerDelay(1), stagger.step);
+ assert.equal(staggerDelay(2), stagger.step * 2);
+ assert.equal(staggerDelay(stagger.max - 1), (stagger.max - 1) * stagger.step);
+ assert.equal(staggerDelay(stagger.max), stagger.max * stagger.step);
+ assert.equal(staggerDelay(stagger.max + 4), stagger.max * stagger.step);
+});
+
+test("duration tokens are positive whole milliseconds, a press is instant and sheet is the longest", () => {
+ const values = Object.values(duration);
+ for (const v of values) {
+ assert.ok(Number.isInteger(v), `duration ${v} should be a whole number of milliseconds`);
+ assert.ok(v > 0, `duration ${v} should be positive`);
+ }
+ assert.ok(duration.press < 100, `a press should read as instant, got ${duration.press}`);
+ assert.equal(duration.sheet, Math.max(...values), `sheet should be the longest duration, got ${duration.sheet}`);
+});
+
+test("easing curves are four numbers whose control-x values sit between 0 and 1", () => {
+ for (const curve of Object.values(easing)) {
+ assert.equal(curve.length, 4, `a cubic-bezier needs four numbers, got ${curve.length}`);
+ for (const x of [curve[0], curve[2]]) {
+ assert.ok(x >= 0 && x <= 1, `a cubic-bezier x value should sit between 0 and 1, got ${x}`);
+ }
+ }
+});
diff --git a/packages/core/test/a2a-store.test.ts b/packages/core/test/a2a-store.test.ts
index ca84579..918c160 100644
--- a/packages/core/test/a2a-store.test.ts
+++ b/packages/core/test/a2a-store.test.ts
@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, test } from "vitest";
import { nodeSql } from "@hermit/sql-node";
-import { createA2aStore, TASK_STATES, type A2aStore, type TaskState } from "../src/a2a-store.ts";
+import { canTransition, createA2aStore, OPEN_TASK_STATES, TASK_STATES, TERMINAL_TASK_STATES, type A2aStore, type TaskState } from "../src/a2a-store.ts";
import { migrate } from "../src/schema.ts";
import type { SqlPort } from "../src/ports.ts";
@@ -313,3 +313,64 @@ describe("a2a store (A2A 1.0, migration 18)", () => {
expect(rejected.status.reason).toBe("hop_cap");
});
});
+
+describe("A2A task states", () => {
+ test("the open and terminal lists hold every state exactly once and share none", () => {
+ const all = [...OPEN_TASK_STATES, ...TERMINAL_TASK_STATES];
+ expect(new Set(all).size).toBe(all.length);
+ expect([...all].sort()).toEqual([...TASK_STATES].sort());
+ for (const state of OPEN_TASK_STATES) {
+ expect(TERMINAL_TASK_STATES).not.toContain(state);
+ }
+ });
+
+ test("a terminal state cannot move anywhere", () => {
+ for (const terminal of TERMINAL_TASK_STATES) {
+ for (const next of TASK_STATES) {
+ expect(canTransition(terminal, next), `${terminal} to ${next}`).toBe(false);
+ }
+ }
+ });
+
+ test("no state moves to itself", () => {
+ for (const state of TASK_STATES) {
+ expect(canTransition(state, state), state).toBe(false);
+ }
+ });
+
+ test("nothing moves back to submitted", () => {
+ for (const state of TASK_STATES) {
+ expect(canTransition(state, "TASK_STATE_SUBMITTED"), state).toBe(false);
+ }
+ });
+
+ test("every open state can reach a terminal state", () => {
+ const reachesTerminal = (start: TaskState): boolean => {
+ const seen = new Set([start]);
+ const queue: TaskState[] = [start];
+ while (queue.length > 0) {
+ const current = queue.shift()!;
+ if (TERMINAL_TASK_STATES.includes(current)) return true;
+ for (const next of TASK_STATES) {
+ if (canTransition(current, next) && !seen.has(next)) {
+ seen.add(next);
+ queue.push(next);
+ }
+ }
+ }
+ return false;
+ };
+ for (const state of OPEN_TASK_STATES) {
+ expect(reachesTerminal(state), state).toBe(true);
+ }
+ });
+
+ test("the A2A 1.0 spot checks hold", () => {
+ expect(canTransition("TASK_STATE_SUBMITTED", "TASK_STATE_WORKING")).toBe(true);
+ expect(canTransition("TASK_STATE_WORKING", "TASK_STATE_INPUT_REQUIRED")).toBe(true);
+ expect(canTransition("TASK_STATE_INPUT_REQUIRED", "TASK_STATE_WORKING")).toBe(true);
+ expect(canTransition("TASK_STATE_AUTH_REQUIRED", "TASK_STATE_CANCELED")).toBe(true);
+ expect(canTransition("TASK_STATE_SUBMITTED", "TASK_STATE_COMPLETED")).toBe(false);
+ expect(canTransition("TASK_STATE_INPUT_REQUIRED", "TASK_STATE_COMPLETED")).toBe(false);
+ });
+});
diff --git a/packages/mail/test/accounts.test.ts b/packages/mail/test/accounts.test.ts
new file mode 100644
index 0000000..a3e64a8
--- /dev/null
+++ b/packages/mail/test/accounts.test.ts
@@ -0,0 +1,107 @@
+// #219: how a request picks the email account (US-MAIL-08). Tests only, accounts.ts is unchanged.
+import { describe, expect, test } from "vitest";
+import { accountName, MemoryMailAccountStore, resolveAccounts, type MailAccount } from "../src/accounts.ts";
+
+const gmail: MailAccount = { id: "a1", provider: "gmail", address: "ana.personal@example.com", label: "personal", credentialId: "c1", createdAt: 1 };
+const outlook: MailAccount = { id: "a2", provider: "outlook", address: "ana.trabajo@example.com", label: "trabajo", credentialId: "c2", createdAt: 2 };
+const imap: MailAccount = { id: "a3", provider: "imap", address: "bot@example.com", credentialId: "c3", createdAt: 3 };
+const accounts: MailAccount[] = [gmail, outlook, imap];
+
+const ids = (r: ReturnType): string[] => {
+ if (!r.ok) throw new Error(`expected ok, got: ${r.modelText}`);
+ return r.accounts.map((a) => a.id);
+};
+
+describe("accountName (#219)", () => {
+ test("an account with a label reads address and label, one without reads just the address", () => {
+ expect(accountName(gmail)).toBe("ana.personal@example.com (personal)");
+ expect(accountName(imap)).toBe("bot@example.com");
+ });
+});
+
+describe("resolveAccounts (#219)", () => {
+ test("with no accounts connected it is not ok", () => {
+ const r = resolveAccounts([], undefined);
+ expect(r.ok).toBe(false);
+ expect(resolveAccounts([], "ana.personal@example.com").ok).toBe(false);
+ });
+
+ test("with nothing wanted it gives every account in order", () => {
+ for (const wanted of [undefined, "", 42, null, {}]) {
+ expect(ids(resolveAccounts(accounts, wanted))).toEqual(["a1", "a2", "a3"]);
+ }
+ });
+
+ test("an exact address wins in any case and with spaces around it", () => {
+ expect(ids(resolveAccounts(accounts, " ANA.PERSONAL@EXAMPLE.COM "))).toEqual(["a1"]);
+ expect(ids(resolveAccounts(accounts, "bot@example.com"))).toEqual(["a3"]);
+ });
+
+ test("a label matches without accents or case", () => {
+ expect(ids(resolveAccounts(accounts, "Trabajo"))).toEqual(["a2"]);
+ expect(ids(resolveAccounts(accounts, "trabájo"))).toEqual(["a2"]);
+ expect(ids(resolveAccounts(accounts, "PERSONAL"))).toEqual(["a1"]);
+ });
+
+ test("a provider matches by id and by service name", () => {
+ expect(ids(resolveAccounts(accounts, "gmail"))).toEqual(["a1"]);
+ expect(ids(resolveAccounts(accounts, "Gmail"))).toEqual(["a1"]);
+ expect(ids(resolveAccounts(accounts, "outlook"))).toEqual(["a2"]);
+ expect(ids(resolveAccounts(accounts, "Outlook"))).toEqual(["a2"]);
+ expect(ids(resolveAccounts(accounts, "imap"))).toEqual(["a3"]);
+ expect(ids(resolveAccounts(accounts, "Email (IMAP)"))).toEqual(["a3"]);
+ });
+
+ test("when a higher tier matches a lower tier is never mixed in", () => {
+ const labelled: MailAccount = { id: "a9", provider: "imap", address: "owner@example.com", label: "viajes", credentialId: "c9", createdAt: 9 };
+ const inAddress: MailAccount = { id: "a8", provider: "gmail", address: "viajes.owner@example.com", credentialId: "c8", createdAt: 8 };
+ expect(ids(resolveAccounts([inAddress, labelled], "viajes"))).toEqual(["a9"]);
+ // An exact address also wins over a label that is part of the same words.
+ expect(ids(resolveAccounts(accounts, "ana.trabajo@example.com"))).toEqual(["a2"]);
+ });
+
+ test("a part of an address or label matches when nothing exact does", () => {
+ expect(ids(resolveAccounts(accounts, "personal@"))).toEqual(["a1"]);
+ expect(ids(resolveAccounts(accounts, "trab"))).toEqual(["a2"]);
+ expect(ids(resolveAccounts(accounts, "bot@exam"))).toEqual(["a3"]);
+ });
+
+ test("no match is not ok, names the connected accounts and cuts what was wanted to 100 characters", () => {
+ const r = resolveAccounts(accounts, "no-existe@example.com");
+ if (r.ok) throw new Error("expected a refusal");
+ expect(r.modelText).toContain(accountName(gmail));
+ expect(r.modelText).toContain(accountName(outlook));
+ expect(r.modelText).toContain(accountName(imap));
+ expect(r.modelText).toContain("no-existe@example.com");
+
+ const long = resolveAccounts(accounts, "x".repeat(150));
+ if (long.ok) throw new Error("expected a refusal");
+ expect(long.modelText).toContain(`"${"x".repeat(100)}"`);
+ expect(long.modelText).not.toContain("x".repeat(101));
+ });
+});
+
+describe("MemoryMailAccountStore (#219)", () => {
+ test("save replaces by id, get and list return copies, delete reports what it removed", async () => {
+ const store = new MemoryMailAccountStore();
+ await store.save(gmail);
+ await store.save({ ...gmail, label: "nueva" });
+ expect((await store.get("a1"))?.label).toBe("nueva");
+ expect(await store.list()).toHaveLength(1);
+
+ const got = (await store.get("a1"))!;
+ got.label = "changed";
+ got.address = "changed@example.com";
+ expect((await store.get("a1"))?.label).toBe("nueva");
+ expect((await store.get("a1"))?.address).toBe(gmail.address);
+
+ const listed = await store.list();
+ listed[0]!.label = "changed again";
+ expect((await store.get("a1"))?.label).toBe("nueva");
+
+ expect(await store.get("missing")).toBeUndefined();
+ expect(await store.delete("a1")).toBe(true);
+ expect(await store.get("a1")).toBeUndefined();
+ expect(await store.delete("a1")).toBe(false);
+ });
+});