@startsimpli/integrations 0.2.223 → 0.2.224

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/package.json +5 -5
  2. package/src/__tests__/attention-policy.test.ts +174 -0
  3. package/src/__tests__/attention-rhythm.test.ts +95 -0
  4. package/src/__tests__/attention-run.test.ts +123 -0
  5. package/src/__tests__/attention-settings-page.test.tsx +57 -0
  6. package/src/__tests__/attention-settings.test.ts +86 -0
  7. package/src/__tests__/converse-client.test.ts +6 -0
  8. package/src/__tests__/converse-meeting.test.ts +40 -0
  9. package/src/__tests__/converse-relay.test.ts +35 -0
  10. package/src/__tests__/converse-soak.test.ts +61 -0
  11. package/src/__tests__/converse-watchdog.test.ts +107 -0
  12. package/src/__tests__/decisions-page.test.tsx +1 -1
  13. package/src/__tests__/fleet-view.test.ts +1 -1
  14. package/src/components/index.ts +1 -0
  15. package/src/components/pages/AttentionSettings.tsx +51 -0
  16. package/src/components/pages/DecisionsPage.tsx +13 -2
  17. package/src/corpus/attention/controller.ts +37 -0
  18. package/src/corpus/attention/index.ts +8 -0
  19. package/src/corpus/attention/policy.ts +59 -0
  20. package/src/corpus/attention/push.ts +47 -0
  21. package/src/corpus/attention/queue.ts +22 -0
  22. package/src/corpus/attention/rhythm.ts +69 -0
  23. package/src/corpus/attention/run-steps.ts +89 -0
  24. package/src/corpus/attention/run.ts +55 -0
  25. package/src/corpus/attention/settings.ts +80 -0
  26. package/src/corpus/attention/types.ts +63 -0
  27. package/src/corpus/converse/client.ts +3 -2
  28. package/src/corpus/converse/handle.ts +18 -3
  29. package/src/corpus/converse/meeting-config.ts +15 -1
  30. package/src/corpus/converse/meeting.ts +100 -8
  31. package/src/corpus/converse/respond.ts +12 -2
  32. package/src/corpus/converse/types.ts +11 -0
  33. package/src/corpus/index.ts +1 -0
  34. package/src/corpus/notify/client.ts +10 -2
  35. package/src/corpus/notify/handle.ts +9 -5
  36. package/src/corpus/notify/respond.ts +1 -1
  37. package/src/corpus/notify/state.ts +3 -0
  38. package/src/corpus/notify/types.ts +9 -0
  39. package/src/native/app/converseServices.ts +1 -0
  40. package/src/native/app/notifyServices.ts +8 -1
  41. package/src/native/app/registry.tsx +4 -2
  42. package/src/native/app/services.ts +1 -1
  43. package/src/native/converse/DriveScreen.tsx +47 -0
  44. package/src/native/converse/__tests__/driveScreen.test.tsx +54 -0
  45. package/src/native/converse/api.ts +1 -0
  46. package/src/native/converse/fake.ts +4 -0
  47. package/src/native/converse/index.ts +1 -0
  48. package/src/native/converse/io.ts +1 -0
  49. package/src/native/push/AttentionCard.tsx +44 -0
  50. package/src/native/push/DecisionsScreen.tsx +12 -2
  51. package/src/native/push/NeedsYouCard.tsx +42 -0
  52. package/src/native/push/__tests__/decisionsApp.test.tsx +12 -1
  53. package/src/native/push/__tests__/needsYou.test.tsx +106 -0
  54. package/src/native/push/fake.ts +12 -1
  55. package/src/native/push/index.ts +3 -0
  56. package/src/native/push/needsYou.ts +29 -0
  57. package/src/native/push/tab.tsx +4 -2
  58. package/src/native/talk/TalkTab.tsx +24 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startsimpli/integrations",
3
- "version": "0.2.223",
3
+ "version": "0.2.224",
4
4
  "description": "Provider-agnostic types, API clients, hooks, and UI primitives for email + calendar integrations across StartSimpli apps, plus foundry customer email (subpath ./comms).",
5
5
  "license": "MIT",
6
6
  "homepage": "https://startsimpli.com",
@@ -50,9 +50,9 @@
50
50
  "react-native": ">=0.74.0",
51
51
  "@startsimpli/ui-native": ">=0.1.12",
52
52
  "react-native-safe-area-context": ">=4.0.0",
53
- "@startsimpli/utils": "^0.4.22",
53
+ "@startsimpli/ui": "^0.4.211",
54
54
  "@startsimpli/auth": "^0.4.64",
55
- "@startsimpli/ui": "^0.4.210"
55
+ "@startsimpli/utils": "^0.4.23"
56
56
  },
57
57
  "peerDependenciesMeta": {
58
58
  "react": {
@@ -99,10 +99,10 @@
99
99
  "react-native": "0.85.3",
100
100
  "react-native-safe-area-context": "~5.7.0",
101
101
  "@startsimpli/llm": "0.4.31",
102
- "@startsimpli/ui": "0.4.210",
102
+ "@startsimpli/ui": "0.4.211",
103
103
  "@startsimpli/ui-native": "0.1.15",
104
104
  "@startsimpli/auth": "0.4.64",
105
- "@startsimpli/utils": "0.4.22"
105
+ "@startsimpli/utils": "0.4.23"
106
106
  },
107
107
  "scripts": {
108
108
  "type-check": "tsc --noEmit && tsc --noEmit -p tsconfig.native.json",
@@ -0,0 +1,174 @@
1
+ // @vitest-environment node
2
+ /** Urgency policy, needs-you queue and the push on a fleet snapshot (bd startsim-nd3qa, slice 1). */
3
+ import { describe, expect, it, vi } from 'vitest';
4
+ import {
5
+ ATTENTION_DEFAULTS, buildNeedsYou, classifyItem, inQuietHours, itemId, resolveAttentionPolicy, runAttention,
6
+ } from '../corpus/attention';
7
+ import type { NotifyDeps, PushSender } from '../corpus/notify';
8
+ import { buildFleetView } from '../corpus/converse/fleet-view';
9
+
10
+ const P = ATTENTION_DEFAULTS;
11
+ const at = (iso: string) => Date.parse(iso);
12
+ const item = (text: string, source: 'fleet' | 'decision' = 'fleet') => ({ id: itemId(text), text, source });
13
+
14
+ describe('classifyItem', () => {
15
+ it('a decision waiting on him needs an answer; an urgent word makes it urgent', () => {
16
+ expect(classifyItem(item('Which build goes first?', 'decision'), P)).toBe('needs-answer');
17
+ expect(classifyItem(item('TEST: urgent sample C, no action needed', 'decision'), P)).toBe('urgent');
18
+ });
19
+ it('a fleet approval needs an answer when fleet approvals are in scope, digest when only decisions are', () => {
20
+ expect(classifyItem(item('Approve the PR for slice 2'), P)).toBe('needs-answer');
21
+ expect(classifyItem(item('Approve the PR for slice 2'), resolveAttentionPolicy({ notifyScope: 'decisions' }))).toBe('digest');
22
+ expect(classifyItem(item('URGENT: payment failed on prod'), resolveAttentionPolicy({ notifyScope: 'decisions' }))).toBe('urgent');
23
+ });
24
+ it('optional or on-hold lines wait in the digest instead of asking for an answer', () => {
25
+ expect(classifyItem(item('Search Console numbers for debugg.ai (optional, re-rank video backlog)'), P)).toBe('digest');
26
+ expect(classifyItem(item('Flip the category pages? HOLD until he reads transit'), P)).toBe('digest');
27
+ expect(classifyItem(item('Unpause crochet-patterns later? stays paused until he says'), P)).toBe('digest');
28
+ expect(classifyItem(item('Optional: but prod is down'), P)).toBe('urgent');
29
+ expect(classifyItem(item('x (optional)'), resolveAttentionPolicy({ digestPatterns: [] }))).toBe('needs-answer');
30
+ });
31
+ it('continue / proceed / status acks are never escalated', () => {
32
+ for (const t of ['Should we continue?', 'Okay to proceed with the migration?', 'I am going to do X, can I keep going?']) expect(classifyItem(item(t), P)).toBe('noise');
33
+ });
34
+ it('FYI lines are noise', () => {
35
+ expect(classifyItem(item('FYI: nothing needed from you'), P)).toBe('noise');
36
+ expect(classifyItem(item('No action needed, merged'), P)).toBe('noise');
37
+ });
38
+ it('the patterns come from the policy, not the code', () => {
39
+ const custom = resolveAttentionPolicy({ urgentPatterns: ['\\bsev1\\b'], noisePatterns: [] });
40
+ expect(classifyItem(item('sev1 on checkout'), custom)).toBe('urgent');
41
+ expect(classifyItem(item('prod is down'), custom)).toBe('needs-answer');
42
+ expect(classifyItem(item('FYI x'), custom)).toBe('needs-answer');
43
+ });
44
+ });
45
+
46
+ describe('quiet hours', () => {
47
+ const q = { ...P.quiet, enabled: true, timeZone: 'America/Los_Angeles' };
48
+ it('wraps midnight and reads the policy time zone', () => {
49
+ expect(inQuietHours(at('2026-11-20T06:30:00Z'), q)).toBe(true); // 22:30 PST
50
+ });
51
+ it('is inside 22:00-07:00 and outside the day', () => {
52
+ expect(inQuietHours(at('2026-11-20T14:00:00Z'), q)).toBe(true); // 06:00 PST
53
+ expect(inQuietHours(at('2026-11-20T16:00:00Z'), q)).toBe(false); // 08:00 PST
54
+ expect(inQuietHours(at('2026-11-20T05:59:00Z'), q)).toBe(false); // 21:59 PST
55
+ expect(inQuietHours(at('2026-11-20T06:00:00Z'), q)).toBe(true); // 22:00 PST
56
+ });
57
+ it('can be switched off', () => {
58
+ expect(inQuietHours(at('2026-11-20T10:00:00Z'), { ...q, enabled: false })).toBe(false);
59
+ });
60
+ });
61
+
62
+ describe('resolveAttentionPolicy', () => {
63
+ it('defaults are the answers still pending with Quinn, all overridable', () => {
64
+ expect(P).toMatchObject({ callMeAt: 3, brief: { hour: 8 }, wrap: { hour: 18 }, quiet: { enabled: true, start: 22, end: 7 }, selfAnswerRoutine: true, notifyScope: 'decisions+fleet' });
65
+ expect(resolveAttentionPolicy({ callMeAt: 5, quiet: { start: 23 } })).toMatchObject({ callMeAt: 5, quiet: { start: 23, end: 7 } });
66
+ });
67
+ });
68
+
69
+ const view = (loops: string) => buildFleetView({ loops });
70
+ const LOOPS = (...bullets: string[]) => `Updated 2026-11-20\n## Waiting on Quinn\n${bullets.map((b) => `- ${b}`).join('\n')}\n`;
71
+
72
+ describe('buildNeedsYou', () => {
73
+ it('queues fleet bullets and pending decisions, urgent first, noise dropped, ids stable', () => {
74
+ const q = buildNeedsYou({ view: view(LOOPS('Approve staging promote', 'FYI merged', 'TEST: urgent sample B, no action needed')), decisions: [{ id: 'dec-0001', title: 'Pick a colour', status: 'pending', created_at: '' }], policy: P });
75
+ expect(q.items.map((i) => i.class)).toEqual(['urgent', 'needs-answer', 'needs-answer']);
76
+ expect(q.items.map((i) => i.text)).toEqual(['TEST: urgent sample B, no action needed', 'Pick a colour', 'Approve staging promote']);
77
+ expect(q.items[0].id).toBe(itemId('TEST: urgent sample B, no action needed'));
78
+ expect(q.counts).toEqual({ urgent: 1, 'needs-answer': 2, digest: 0, noise: 1 });
79
+ });
80
+ it('callMe turns on at the threshold of waiting items (urgent included)', () => {
81
+ const two = buildNeedsYou({ view: view(LOOPS('a one', 'a two')), decisions: [], policy: P });
82
+ expect(two.callMe).toBe(false);
83
+ const three = buildNeedsYou({ view: view(LOOPS('a one', 'a two', 'a three')), decisions: [], policy: P });
84
+ expect(three.callMe).toBe(true);
85
+ expect(buildNeedsYou({ view: view(LOOPS('a one', 'a two', 'a three')), decisions: [], policy: resolveAttentionPolicy({ callMeAt: 4 }) }).callMe).toBe(false);
86
+ });
87
+ it('an item id is the same however the line is spaced or cased', () => {
88
+ expect(itemId('Approve the PR ')).toBe(itemId('approve the pr'));
89
+ expect(itemId('x')).toMatch(/^[A-Za-z0-9_-]{8,64}$/);
90
+ });
91
+ });
92
+
93
+ function setup(over: Partial<NotifyDeps> = {}) {
94
+ const rows = new Map<string, any>();
95
+ let seq = 0;
96
+ const sent: any[] = [];
97
+ const sender: PushSender = { kind: 'apns', send: async (d, m) => { sent.push(m); return { ok: true }; } };
98
+ const http = {
99
+ get: vi.fn(async (_p: string, o?: { params?: Record<string, unknown> }) => ({ results: [...rows.values()].filter((r) => r.external_id === o?.params?.external_id__in) })),
100
+ post: vi.fn(async (_p: string, b: any) => { const row = { id: String(++seq), external_id: b.external_id, data: b.data }; rows.set(b.external_id, row); return row; }),
101
+ };
102
+ const deps: NotifyDeps = { http: http as never, ownerSub: 'me', sender, now: () => at('2026-11-20T18:00:00Z'), ...over };
103
+ rows.set('notify-state:me', { id: '0', external_id: 'notify-state:me', data: { source: 'notify_state', owner_sub: 'me', push_enabled: true, pings: [], decisions: [], devices: [{ token: 'ab'.repeat(32), environment: 'sandbox', platform: 'ios', label: '', registered_at: '' }] } });
104
+ return { deps, sent };
105
+ }
106
+
107
+ describe('runAttention: push on a fleet snapshot', () => {
108
+ const now = at('2026-11-20T21:00:00Z'); // 13:00 PST: not quiet, between the morning and evening batches
109
+ it('pushes one attention ping per urgent item, high priority, and not again for the same snapshot', async () => {
110
+ const { deps, sent } = setup();
111
+ const v = view(LOOPS('TEST: urgent sample B, no action needed', 'Approve staging promote'));
112
+ const first = await runAttention(deps, { view: v, now });
113
+ expect(first.pushed).toHaveLength(1);
114
+ expect(sent).toHaveLength(1);
115
+ expect(sent[0]).toMatchObject({ priority: 'high', title: expect.stringContaining('TEST: urgent sample B'), data: { kind: 'attention' } });
116
+ await runAttention(deps, { view: v, now });
117
+ await runAttention(deps, { view: v, now });
118
+ expect(sent).toHaveLength(1);
119
+ });
120
+ it('sends one call-me ping when enough are waiting, and only once for that same set', async () => {
121
+ const { deps, sent } = setup();
122
+ const v = view(LOOPS('a one', 'a two', 'a three'));
123
+ const out = await runAttention(deps, { view: v, now });
124
+ expect(out.pushed.map((p) => p.reason)).toEqual(['call-me']);
125
+ expect(sent[0]).toMatchObject({ title: expect.stringMatching(/3/), data: { kind: 'attention' } });
126
+ await runAttention(deps, { view: v, now });
127
+ expect(sent).toHaveLength(1);
128
+ });
129
+ it('quiet hours hold needs-answer and call-me, but urgent goes through', async () => {
130
+ const { deps, sent } = setup();
131
+ const quiet = at('2026-11-20T08:00:00Z'); // 00:00 PST
132
+ const v = view(LOOPS('a one', 'a two', 'a three'));
133
+ const { setSettings } = await import('../corpus/notify');
134
+ await setSettings(deps, { attention: { quiet_mode: 'auto' } });
135
+ expect((await runAttention(deps, { view: v, now: quiet })).pushed).toEqual([]);
136
+ expect(sent).toHaveLength(0);
137
+ const u = view(LOOPS('TEST: urgent sample D', 'a two', 'a three'));
138
+ expect((await runAttention(deps, { view: u, now: quiet })).pushed.map((p) => p.reason)).toEqual(['urgent']);
139
+ });
140
+ it('sends nothing when the queue is empty', async () => {
141
+ const { deps, sent } = setup();
142
+ expect((await runAttention(deps, { view: view(LOOPS()), now })).pushed).toEqual([]);
143
+ expect(sent).toHaveLength(0);
144
+ });
145
+ });
146
+
147
+ describe('fleet-status route wiring', () => {
148
+ it('POST runs the attention hook with the parsed view; GET returns the needs-you queue', async () => {
149
+ const { converseFleetStatusResponse, converseFleetViewResponse } = await import('../corpus/converse');
150
+ const rows = new Map<string, any>();
151
+ const http = {
152
+ get: vi.fn(async (_p: string, o?: { params?: Record<string, unknown> }) => ({ results: [...rows.values()].filter((r) => r.external_id === o?.params?.external_id__in) })),
153
+ post: vi.fn(async (_p: string, b: any) => { const row = { id: '1', external_id: b.external_id, data: b.data }; rows.set(b.external_id, row); return row; }),
154
+ };
155
+ const seen: unknown[] = [];
156
+ const deps: any = { http, ownerSub: 'me', onFleetSnapshot: async (i: unknown) => { seen.push(i); } };
157
+ const body = { text: 'fleet', inputs: { loops: LOOPS('TEST: urgent sample B, no action needed', 'Approve promote') } };
158
+ const res = await converseFleetStatusResponse(new Request('http://x', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) }), deps);
159
+ expect(res.status).toBe(200);
160
+ expect((seen[0] as any).view.waitingOnQuinn).toHaveLength(2);
161
+ const got = await (await converseFleetViewResponse(deps)).json();
162
+ expect(got.needs_you.items.map((i: any) => i.class)).toEqual(['urgent', 'needs-answer']);
163
+ expect(got.needs_you.callMe).toBe(false);
164
+ });
165
+ it('a failing hook does not fail the snapshot', async () => {
166
+ const { converseFleetStatusResponse } = await import('../corpus/converse');
167
+ const http = { get: vi.fn(async () => ({ results: [] })), post: vi.fn(async (_p: string, b: any) => ({ id: '1', ...b })) };
168
+ const err = vi.spyOn(console, 'error').mockImplementation(() => undefined);
169
+ const deps: any = { http, ownerSub: 'me', onFleetSnapshot: async () => { throw new Error('apns down'); } };
170
+ const res = await converseFleetStatusResponse(new Request('http://x', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ text: 'fleet' }) }), deps);
171
+ expect(res.status).toBe(200);
172
+ err.mockRestore();
173
+ });
174
+ });
@@ -0,0 +1,95 @@
1
+ // @vitest-environment node
2
+ /** The daily rhythm and routine answers (bd startsim-nd3qa.3): a morning and an evening batch, and continue-style questions answered for him. */
3
+ import { describe, expect, it, vi } from 'vitest';
4
+ import { ATTENTION_DEFAULTS, mergeAttention, policyFrom, runAttention, settingsView } from '../corpus/attention';
5
+ import { createDecision, getDecision, setSettings, loadState, type NotifyDeps, type PushSender } from '../corpus/notify';
6
+ import { buildFleetView } from '../corpus/converse/fleet-view';
7
+
8
+ const at = (iso: string) => Date.parse(iso);
9
+ const view = (...b: string[]) => buildFleetView({ loops: `Updated 2026-11-20\n## Waiting on Quinn\n${b.map((x) => `- ${x}`).join('\n')}\n` });
10
+
11
+ function setup(nowIso = '2026-11-20T16:30:00Z') {
12
+ const rows = new Map<string, any>();
13
+ let seq = 0;
14
+ const sent: any[] = [];
15
+ const sender: PushSender = { kind: 'apns', send: async (_d, m) => { sent.push(m); return { ok: true }; } };
16
+ const http = {
17
+ get: vi.fn(async (_p: string, o?: { params?: Record<string, unknown> }) => ({ results: [...rows.values()].filter((r) => r.external_id === o?.params?.external_id__in) })),
18
+ post: vi.fn(async (_p: string, b: any) => { const row = { id: String(++seq), external_id: b.external_id, data: b.data }; rows.set(b.external_id, row); return row; }),
19
+ };
20
+ let now = at(nowIso);
21
+ const deps: NotifyDeps = { http: http as never, ownerSub: 'me', sender, now: () => now };
22
+ rows.set('notify-state:me', { id: '0', external_id: 'notify-state:me', data: { source: 'notify_state', owner_sub: 'me', push_enabled: true, pings: [], decisions: [], devices: [{ token: 'ab'.repeat(32), environment: 'sandbox', platform: 'ios', label: '', registered_at: '2026-11-19T00:00:00Z' }] } });
23
+ return { deps, sent, setNow: (iso: string) => { now = at(iso); } };
24
+ }
25
+
26
+ describe('hours are configurable', () => {
27
+ it('defaults are 8am and 6pm; stored hours override and are validated', () => {
28
+ expect(ATTENTION_DEFAULTS).toMatchObject({ brief: { hour: 8 }, wrap: { hour: 18 }, selfAnswerRoutine: true });
29
+ const stored = mergeAttention(undefined, { brief_hour: 7, wrap_hour: 19 });
30
+ expect(policyFrom(stored)).toMatchObject({ brief: { hour: 7 }, wrap: { hour: 19 } });
31
+ expect(settingsView(stored, 0)).toMatchObject({ brief_hour: 7, wrap_hour: 19 });
32
+ expect(() => mergeAttention(undefined, { brief_hour: 24 })).toThrow();
33
+ });
34
+ });
35
+
36
+ describe('morning and evening batches', () => {
37
+ // 2026-11-20 16:30Z = 08:30 PST, after the 8am brief hour.
38
+ it('sends ONE morning batch a day with what is waiting, not again, and a new one the next morning', async () => {
39
+ const { deps, sent, setNow } = setup();
40
+ const v = view('Approve the staging promote', 'Pick the launch date');
41
+ const first = await runAttention(deps, { view: v });
42
+ expect(first.pushed.map((p) => p.reason)).toEqual(['brief']);
43
+ expect(sent[0]).toMatchObject({ priority: 'normal', title: expect.stringMatching(/Morning.*2/), body: expect.stringContaining('Approve the staging promote') });
44
+ await runAttention(deps, { view: v });
45
+ expect(sent).toHaveLength(1);
46
+ setNow('2026-11-21T16:30:00Z');
47
+ expect((await runAttention(deps, { view: v })).pushed.map((p) => p.reason)).toEqual(['brief']);
48
+ });
49
+ it('sends nothing before the hour, nothing when empty, nothing when quiet mode is on', async () => {
50
+ const early = setup('2026-11-20T14:00:00Z'); // 06:00 PST
51
+ expect((await runAttention(early.deps, { view: view('a one', 'a two') })).pushed).toEqual([]);
52
+ const empty = setup();
53
+ expect((await runAttention(empty.deps, { view: view() })).pushed).toEqual([]);
54
+ const quiet = setup();
55
+ await setSettings(quiet.deps, { attention: { quiet_mode: 'on' } });
56
+ expect((await runAttention(quiet.deps, { view: view('a one') })).pushed).toEqual([]);
57
+ });
58
+ it('the evening batch says what is still open and how many he answered today', async () => {
59
+ const { deps, sent } = setup('2026-11-21T02:30:00Z'); // 18:30 PST on the 20th
60
+ const v = view('Approve the staging promote');
61
+ const out = await runAttention(deps, { view: v });
62
+ expect(out.pushed.map((p) => p.reason)).toEqual(['wrap']);
63
+ expect(sent[0]).toMatchObject({ title: expect.stringMatching(/End of day.*1 still open/) });
64
+ });
65
+ it('a configured hour moves the batch', async () => {
66
+ const { deps, sent } = setup(); // 08:30 PST
67
+ await setSettings(deps, { attention: { brief_hour: 9 } });
68
+ expect((await runAttention(deps, { view: view('a one') })).pushed).toEqual([]);
69
+ expect(sent).toHaveLength(0);
70
+ });
71
+ });
72
+
73
+ describe('continue-style questions answer themselves', () => {
74
+ it('a pending "should we continue?" decision is answered yes for him, leaves the queue, and is recorded', async () => {
75
+ const { deps } = setup();
76
+ const made = (await createDecision(deps, { title: 'Should we continue with the migration?', questions: [{ n: 1, text: 'Continue?' }] } as never)).decision;
77
+ const out = await runAttention(deps, { view: view() });
78
+ expect(out.autoAnswered).toEqual([made.id]);
79
+ expect((await getDecision(deps, made.id)).status).toBe('answered');
80
+ expect(Object.values((await loadState(deps)).answered ?? {})).toMatchObject([{ ref: made.id, delivered: 'decision' }]);
81
+ expect((await runAttention(deps, { view: view() })).autoAnswered).toEqual([]);
82
+ });
83
+ it('never answers an urgent one, a real question, or when switched off', async () => {
84
+ const { deps } = setup();
85
+ const urgent = (await createDecision(deps, { title: 'Prod is down, should we continue?', questions: [{ n: 1, text: 'x' }] } as never)).decision;
86
+ const real = (await createDecision(deps, { title: 'Which colour for the logo?', questions: [{ n: 1, text: 'x' }] } as never)).decision;
87
+ expect((await runAttention(deps, { view: view() })).autoAnswered).toEqual([]);
88
+ expect((await getDecision(deps, urgent.id)).status).toBe('pending');
89
+ expect((await getDecision(deps, real.id)).status).toBe('pending');
90
+ const off = setup();
91
+ const d = (await createDecision(off.deps, { title: 'Okay to proceed?', questions: [{ n: 1, text: 'x' }] } as never)).decision;
92
+ expect((await runAttention(off.deps, { view: view(), policy: { selfAnswerRoutine: false } })).autoAnswered).toEqual([]);
93
+ expect((await getDecision(off.deps, d.id)).status).toBe('pending');
94
+ });
95
+ });
@@ -0,0 +1,123 @@
1
+ // @vitest-environment node
2
+ /** The needs-you briefing: the assistant asks item i of n, records each answer, ends by saying what it did (bd startsim-nd3qa). */
3
+ import { describe, expect, it } from 'vitest';
4
+ import { hear, startRun, stepRun, type AttentionRunState } from '../corpus/attention/run-steps';
5
+
6
+ const NOW = '2026-11-20T00:00:00Z';
7
+ const items = [{ id: 'q-1', text: 'TEST: urgent sample A, no action needed' }, { id: 'q-2', text: 'TEST: sample question, pick a colour?', ref: 'dec-1' }, { id: 'q-3', text: 'TEST: third sample' }];
8
+
9
+ describe('what he says is understood', () => {
10
+ it.each([['yes', 'yes'], ['Yeah go ahead', 'yes'], ['okay', 'yes'], ['no', 'no'], ["don't", 'no'], ['skip it', 'skip'], ['later', 'skip'], ['what was that again', 'again'], ['say that again', 'again'], ["that's all", 'stop'], ['stop', 'stop']])('%s -> %s', (said, kind) => {
11
+ expect(hear(said).kind).toBe(kind);
12
+ });
13
+ it('anything else is his own answer, kept as he said it', () => {
14
+ expect(hear('make it blue')).toEqual({ kind: 'free', text: 'make it blue' });
15
+ });
16
+ });
17
+
18
+ describe('walking the queue', () => {
19
+ it('opens by saying how many, asks item 1 of n most important first, and never speaks as him', () => {
20
+ const { run, reply } = startRun({ conversationId: 'conv-0001', items, now: NOW });
21
+ expect(reply).toMatchObject({ active: true, index: 0, of: 3 });
22
+ expect(reply.text).toBe('3 things need you, most important first. Question 1 of 3: TEST: urgent sample A, no action needed. Yes or no?');
23
+ expect(run.status).toBe('asking');
24
+ });
25
+ it('records each answer against its item, moves on, and ends by saying what it saved', () => {
26
+ let { run, reply } = startRun({ conversationId: 'conv-0001', items, now: NOW });
27
+ ({ run, reply } = stepRun(run, 'yes', NOW));
28
+ expect(reply.text).toBe('Yes, noted. Question 2 of 3: TEST: sample question, pick a colour?. Yes or no?'.replace('?.', '.'));
29
+ expect(reply.recorded).toMatchObject({ answer: 'yes', item: { id: 'q-1' } });
30
+ ({ run, reply } = stepRun(run, 'make it blue', NOW));
31
+ expect(reply.recorded).toMatchObject({ answer: 'make it blue', item: { id: 'q-2', ref: 'dec-1' } });
32
+ ({ run, reply } = stepRun(run, 'later', NOW));
33
+ expect(reply).toMatchObject({ active: false });
34
+ expect(reply.text).toContain('That was the last one.');
35
+ expect(reply.text).toContain('I saved 2 answers in your queue.');
36
+ expect(reply.text).toContain('1 item is still waiting in your queue.');
37
+ expect(run).toMatchObject({ status: 'done', answers: { 'q-1': { answer: 'yes' }, 'q-2': { answer: 'make it blue' } }, skipped: ['q-3'] });
38
+ expect(stepRun(run, 'yes', NOW).reply.text).toBe('That list is finished.');
39
+ });
40
+ it('"what was that again" repeats the same question and records nothing; "stop" ends cleanly', () => {
41
+ let { run } = startRun({ conversationId: 'conv-0001', items, now: NOW });
42
+ const again = stepRun(run, 'what was that again', NOW);
43
+ expect(again.reply.text).toBe('Question 1 of 3: TEST: urgent sample A, no action needed. Yes or no?');
44
+ expect(again.run.answers).toEqual({});
45
+ const stop = stepRun(again.run, 'that is all', NOW);
46
+ expect(stop.reply).toMatchObject({ active: false });
47
+ expect(stop.reply.text).toContain('Okay, stopping here. I did not record any answers.');
48
+ expect(stop.run.status).toBe('done');
49
+ });
50
+ it('one item reads "One thing needs you"; an empty queue says so and is not active', () => {
51
+ expect(startRun({ conversationId: 'conv-0001', items: items.slice(0, 1), now: NOW }).reply.text).toMatch(/^One thing needs you\. Question 1 of 1:/);
52
+ const none = startRun({ conversationId: 'conv-0001', items: [], now: NOW });
53
+ expect(none.reply).toMatchObject({ text: 'Nothing is waiting on you right now.', active: false });
54
+ });
55
+ it('an empty answer is asked again, not recorded', () => {
56
+ const { run } = startRun({ conversationId: 'conv-0001', items, now: NOW });
57
+ const out = stepRun(run, ' ', NOW);
58
+ expect(out.reply.text).toContain('I did not catch that.');
59
+ expect(out.run.answers).toEqual({});
60
+ });
61
+ });
62
+
63
+ import { vi } from 'vitest';
64
+ import { createAttentionRun } from '../corpus/attention/run';
65
+ import { buildNeedsYou, policyFrom } from '../corpus/attention';
66
+ import { createDecision, getDecision } from '../corpus/notify';
67
+ import { loadState } from '../corpus/notify/state';
68
+ import { buildFleetView } from '../corpus/converse/fleet-view';
69
+
70
+ function tenant() {
71
+ const rows = new Map<string, any>();
72
+ let seq = 0;
73
+ const http = {
74
+ get: vi.fn(async (_p: string, o?: { params?: Record<string, unknown> }) => ({ results: [...rows.values()].filter((r) => r.external_id === o?.params?.external_id__in) })),
75
+ post: vi.fn(async (_p: string, b: any) => { const row = { id: String(++seq), external_id: b.external_id, data: b.data }; rows.set(b.external_id, row); return row; }),
76
+ };
77
+ const deps = { http: http as never, ownerSub: 'me', now: () => Date.parse(NOW), newId: () => `generated-${++seq}` };
78
+ const fleet = (...b: string[]) => rows.set('fleet-status:me', { id: 'f', external_id: 'fleet-status:me', data: { source: 'fleet_status', owner_sub: 'me', body: 'x', fleet_inputs: { loops: `## Waiting on Quinn\n${b.map((x) => `- ${x}`).join('\n')}\n` } } });
79
+ return { deps, fleet, rows };
80
+ }
81
+
82
+ describe('the stored run', () => {
83
+ it('starts from the real queue, records answers into the queue, and answered items leave it', async () => {
84
+ const { deps, fleet } = tenant();
85
+ fleet('TEST: urgent sample A, no action needed', 'TEST: sample B', 'TEST: sample C');
86
+ const run = createAttentionRun(deps);
87
+ const start = await run.start('conv-0001');
88
+ expect(start).toMatchObject({ active: true, of: 3 });
89
+ expect(start!.text).toContain('Question 1 of 3: TEST: urgent sample A, no action needed');
90
+ expect(await run.answer('other-conv-1', 'yes')).toBeNull();
91
+ const second = await run.answer('conv-0001', 'yes');
92
+ expect(second!.text).toContain('Question 2 of 3');
93
+ const st = await loadState(deps);
94
+ expect(Object.keys(st.answered ?? {})).toHaveLength(1);
95
+ const q = buildNeedsYou({ view: buildFleetView({ loops: '## Waiting on Quinn\n- TEST: urgent sample A, no action needed\n- TEST: sample B\n- TEST: sample C\n' }), decisions: [], policy: policyFrom(st.attention), answered: st.answered });
96
+ expect(q.items.map((i) => i.text)).toEqual(['TEST: sample B', 'TEST: sample C']);
97
+ await run.answer('conv-0001', 'no');
98
+ const last = await run.answer('conv-0001', 'skip');
99
+ expect(last).toMatchObject({ active: false });
100
+ expect(await run.answer('conv-0001', 'yes')).toBeNull();
101
+ });
102
+ it('an answer to a one-question decision is delivered to that decision', async () => {
103
+ const { deps } = tenant();
104
+ const made = await createDecision(deps, { title: 'TEST: sample decision, pick a colour', questions: ['TEST: blue or green?'] });
105
+ const run = createAttentionRun(deps);
106
+ const start = await run.start('conv-0002');
107
+ expect(start!.text).toContain('TEST: sample decision, pick a colour');
108
+ await run.answer('conv-0002', 'green');
109
+ const d = await getDecision(deps, made.decision.id);
110
+ expect(d.answers).toMatchObject([{ n: 1, answer: 'green' }]);
111
+ expect(d.status).toBe('answered');
112
+ });
113
+ it('nothing waiting: says so and is not active', async () => {
114
+ const { deps } = tenant();
115
+ expect(await createAttentionRun(deps).start('conv-0003')).toMatchObject({ text: 'Nothing is waiting on you right now.', active: false });
116
+ });
117
+ it('asks only a batch at a time, most important first', async () => {
118
+ const { deps, fleet } = tenant();
119
+ fleet(...Array.from({ length: 8 }, (_, i) => `TEST: sample ${i + 1}`));
120
+ const start = await createAttentionRun(deps, { batch: 3 }).start('conv-0004');
121
+ expect(start).toMatchObject({ of: 3 });
122
+ });
123
+ });
@@ -0,0 +1,57 @@
1
+ // @vitest-environment jsdom
2
+ import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
3
+ import * as React from 'react';
4
+ import { afterEach, describe, expect, it, vi } from 'vitest';
5
+ import { AttentionSettings } from '../components/pages/AttentionSettings';
6
+ import { DecisionsPage } from '../components/pages/DecisionsPage';
7
+ import { quietSummary } from '../corpus/attention';
8
+ import { createFakeNotify } from '../native/push/fake';
9
+
10
+ afterEach(cleanup);
11
+
12
+ describe('AttentionSettings', () => {
13
+ it('shows what quiet means now, and the three modes save through the client', async () => {
14
+ const { client } = createFakeNotify();
15
+ const spy = vi.spyOn(client, 'setAttention');
16
+ render(<AttentionSettings client={client} />);
17
+ expect((await screen.findByTestId('quiet-summary')).textContent).toBe('Never quiet. You can add a schedule (22:00 to 7:00) or switch on Quiet now.');
18
+ fireEvent.click(screen.getByTestId('quiet-mode-on'));
19
+ await waitFor(() => expect(screen.getByTestId('quiet-summary').textContent).toBe('Quiet now: only urgent items reach you.'));
20
+ expect(spy).toHaveBeenCalledWith({ quiet_mode: 'on' });
21
+ expect(screen.getByTestId('quiet-mode-on').getAttribute('aria-checked')).toBe('true');
22
+ fireEvent.click(screen.getByTestId('quiet-mode-off'));
23
+ await waitFor(() => expect(screen.getByTestId('quiet-summary').textContent).toContain('Never quiet'));
24
+ });
25
+ it('saves the schedule hours, the urgent words and the call threshold', async () => {
26
+ const { client } = createFakeNotify();
27
+ const spy = vi.spyOn(client, 'setAttention');
28
+ render(<AttentionSettings client={client} />);
29
+ await screen.findByTestId('quiet-start');
30
+ fireEvent.change(screen.getByTestId('quiet-start'), { target: { value: '23' } });
31
+ await waitFor(() => expect(spy).toHaveBeenCalledWith({ quiet: { start: 23 } }));
32
+ fireEvent.change(screen.getByTestId('urgent-words'), { target: { value: 'Overdue, sev1' } });
33
+ fireEvent.submit(screen.getByTestId('urgent-words').closest('form')!);
34
+ await waitFor(() => expect(spy).toHaveBeenCalledWith({ urgent_words: ['Overdue', 'sev1'] }));
35
+ fireEvent.change(screen.getByTestId('call-me-at'), { target: { value: '5' } });
36
+ fireEvent.blur(screen.getByTestId('call-me-at'));
37
+ await waitFor(() => expect(spy).toHaveBeenCalledWith({ call_me_at: 5 }));
38
+ fireEvent.change(screen.getByTestId('brief-hour'), { target: { value: '7' } });
39
+ await waitFor(() => expect(spy).toHaveBeenCalledWith({ brief_hour: 7 }));
40
+ fireEvent.change(screen.getByTestId('wrap-hour'), { target: { value: '19' } });
41
+ await waitFor(() => expect(spy).toHaveBeenCalledWith({ wrap_hour: 19 }));
42
+ });
43
+ it('is part of the Decisions page when the tenant serves attention settings, and absent when it does not', async () => {
44
+ const { client } = createFakeNotify();
45
+ render(<DecisionsPage client={client} />);
46
+ expect(await screen.findByTestId('attention-settings')).toBeTruthy();
47
+ cleanup();
48
+ render(<DecisionsPage client={{ ...client, settings: async () => ({ push: true, devices: 0 }) }} />);
49
+ await screen.findByText(/Notify me on my phone/);
50
+ expect(screen.queryByTestId('attention-settings')).toBeNull();
51
+ });
52
+ it('summaries read plainly', () => {
53
+ const base = { quiet_mode: 'auto' as const, quiet: { enabled: true, start: 22, end: 7, timeZone: 'x' }, quiet_active: true, urgent_words: [], call_me_at: 3, notify_scope: 'decisions' as const };
54
+ expect(quietSummary(base)).toBe('Quiet until 7:00. Urgent items still reach you.');
55
+ expect(quietSummary({ ...base, quiet_mode: 'off' })).toContain('Never quiet');
56
+ });
57
+ });
@@ -0,0 +1,86 @@
1
+ // @vitest-environment node
2
+ /** Quiet mode (manual + schedule + urgent override) and tunable urgency, stored per person (bd startsim-nd3qa, slices 3 and 6). */
3
+ import { describe, expect, it, vi } from 'vitest';
4
+ import { classifyItem, isQuiet, itemId, resolveAttentionPolicy, runAttention } from '../corpus/attention';
5
+ import { getSettings, setSettings, type NotifyDeps, type PushSender } from '../corpus/notify';
6
+ import { buildFleetView } from '../corpus/converse/fleet-view';
7
+
8
+ const at = (iso: string) => Date.parse(iso);
9
+ const DAY = at('2026-11-20T18:00:00Z'); // 10:00 PST
10
+ const NIGHT = at('2026-11-20T08:00:00Z'); // 00:00 PST
11
+ const P = resolveAttentionPolicy();
12
+
13
+ function setup() {
14
+ const rows = new Map<string, any>();
15
+ const sent: any[] = [];
16
+ const sender: PushSender = { kind: 'apns', send: async (_d, m) => { sent.push(m); return { ok: true }; } };
17
+ const http = {
18
+ get: vi.fn(async (_p: string, o?: { params?: Record<string, unknown> }) => ({ results: [...rows.values()].filter((r) => r.external_id === o?.params?.external_id__in) })),
19
+ post: vi.fn(async (_p: string, b: any) => { const row = { id: '1', external_id: b.external_id, data: b.data }; rows.set(b.external_id, row); return row; }),
20
+ };
21
+ rows.set('notify-state:me', { id: '0', external_id: 'notify-state:me', data: { source: 'notify_state', owner_sub: 'me', push_enabled: true, pings: [], decisions: [], devices: [{ token: 'ab'.repeat(32), environment: 'sandbox', platform: 'ios', label: '', registered_at: '' }] } });
22
+ const deps: NotifyDeps = { http: http as never, ownerSub: 'me', sender, now: () => DAY };
23
+ return { deps, sent };
24
+ }
25
+ const view = (...b: string[]) => buildFleetView({ loops: `## Waiting on Quinn\n${b.map((x) => `- ${x}`).join('\n')}\n` });
26
+
27
+ describe('isQuiet: manual toggle over the schedule', () => {
28
+ it('auto follows the schedule; on is quiet all day; off is never quiet', () => {
29
+ const sched = { ...P.quiet, enabled: true };
30
+ expect(isQuiet(NIGHT, P.quiet)).toBe(false); // the default mode is Never quiet
31
+ expect(isQuiet(NIGHT, sched, 'auto')).toBe(true);
32
+ expect(isQuiet(DAY, sched, 'auto')).toBe(false);
33
+ expect(isQuiet(DAY, P.quiet, 'on')).toBe(true);
34
+ expect(isQuiet(NIGHT, P.quiet, 'off')).toBe(false);
35
+ });
36
+ });
37
+
38
+ describe('urgent words are plain, tunable and case-insensitive', () => {
39
+ it('a word the person adds makes a line urgent; removing it does not', () => {
40
+ const it1 = { id: itemId('Invoice from Acme is overdue'), text: 'Invoice from Acme is overdue', source: 'fleet' as const };
41
+ expect(classifyItem(it1, P)).toBe('needs-answer');
42
+ expect(classifyItem(it1, resolveAttentionPolicy({ urgentWords: ['Overdue'] }))).toBe('urgent');
43
+ expect(classifyItem({ ...it1, text: 'a.b (x) overdue+' }, resolveAttentionPolicy({ urgentWords: ['a.b (x)'] }))).toBe('urgent');
44
+ });
45
+ });
46
+
47
+ describe('settings endpoint state', () => {
48
+ it('defaults come back with the schedule and whether quiet is active now', async () => {
49
+ const { deps } = setup();
50
+ const s = await getSettings(deps);
51
+ expect(s).toMatchObject({ push: true, attention: { quiet_mode: 'off', quiet: { enabled: true, start: 22, end: 7, timeZone: 'America/Los_Angeles' }, quiet_active: false, urgent_words: [], call_me_at: 3, notify_scope: 'decisions+fleet' } });
52
+ });
53
+ it('saves quiet mode, schedule and urgent words, validates them, and leaves push alone', async () => {
54
+ const { deps } = setup();
55
+ const out = await setSettings(deps, { attention: { quiet_mode: 'on', quiet: { enabled: true, start: 23, end: 6 }, urgent_words: [' Overdue ', 'overdue', 'sev1'], call_me_at: 5, notify_scope: 'decisions' } });
56
+ expect(out).toMatchObject({ push: true, attention: { quiet_mode: 'on', quiet_active: true, quiet: { start: 23, end: 6, enabled: true }, urgent_words: ['overdue', 'sev1'], call_me_at: 5, notify_scope: 'decisions' } });
57
+ expect((await getSettings(deps)).attention.quiet_mode).toBe('on');
58
+ for (const bad of [{ quiet_mode: 'maybe' }, { quiet: { start: 24 } }, { quiet: { timeZone: 'Mars/Base' } }, { call_me_at: 0 }, { notify_scope: 'all' }, { urgent_words: 'x' }]) {
59
+ await expect(setSettings(deps, { attention: bad as never })).rejects.toMatchObject({ status: 400 });
60
+ }
61
+ await expect(setSettings(deps, {})).rejects.toMatchObject({ status: 400 });
62
+ expect(await setSettings(deps, { push: false })).toMatchObject({ push: false, attention: { quiet_mode: 'on' } });
63
+ });
64
+ });
65
+
66
+ describe('runAttention uses the saved settings', () => {
67
+ it('manual quiet on holds the call-me but urgent still goes through', async () => {
68
+ const { deps, sent } = setup();
69
+ await setSettings(deps, { attention: { quiet_mode: 'on' } });
70
+ await runAttention(deps, { view: view('a one', 'a two', 'a three') });
71
+ expect(sent).toHaveLength(0);
72
+ await runAttention(deps, { view: view('TEST: urgent sample D', 'a two', 'a three') });
73
+ expect(sent.map((m) => m.title)).toEqual([expect.stringContaining('TEST: urgent sample D')]);
74
+ });
75
+ it('quiet off pushes the call-me at night; a saved urgent word pushes; a raised threshold holds', async () => {
76
+ const { deps, sent } = setup();
77
+ await setSettings(deps, { attention: { quiet_mode: 'off', urgent_words: ['overdue'] } });
78
+ await runAttention(deps, { view: view('a one', 'a two', 'a three'), now: NIGHT });
79
+ expect(sent).toHaveLength(1);
80
+ await runAttention(deps, { view: view('Invoice overdue'), now: NIGHT });
81
+ expect(sent).toHaveLength(2);
82
+ await setSettings(deps, { attention: { call_me_at: 4 } });
83
+ await runAttention(deps, { view: view('b one', 'b two', 'b three'), now: NIGHT });
84
+ expect(sent).toHaveLength(2);
85
+ });
86
+ });
@@ -49,3 +49,9 @@ describe('thread', () => {
49
49
  expect((init.headers as Record<string, string>).authorization).toBe('Bearer tok');
50
50
  });
51
51
  });
52
+
53
+ describe('speech not set up', () => {
54
+ it('the speech_unavailable code is not retryable', () => {
55
+ expect(new ConverseClientError('x', 503, 'speech_unavailable').retryable).toBe(false);
56
+ });
57
+ });
@@ -149,6 +149,17 @@ describe('meeting controller', () => {
149
149
  await c.end();
150
150
  });
151
151
 
152
+ it('voice not set up on the server: the error is shown once, nothing is resent, the mic turns off and the screen is idle', async () => {
153
+ const turn = vi.fn().mockRejectedValue(new ConverseClientError('Voice is not set up on this server. You can type instead.', 503, 'speech_unavailable'));
154
+ const { c } = rig({ turn: turn as any, utterances: [blob(), blob()] });
155
+ c.start();
156
+ await settle(() => !!c.state().error);
157
+ await new Promise((r) => setTimeout(r, 80));
158
+ expect(turn).toHaveBeenCalledTimes(1);
159
+ expect(c.state()).toMatchObject({ phase: 'idle', micOn: false, retryable: false, error: expect.stringContaining('type instead') });
160
+ await c.end();
161
+ });
162
+
152
163
  it('a rejected session stops the meeting with the error instead of looping', async () => {
153
164
  const turn = vi.fn().mockRejectedValue(new ConverseClientError('Your session is not valid', 401));
154
165
  const { c } = rig({ turn: turn as any, utterances: [blob(), blob()] });
@@ -418,3 +429,32 @@ describe('the relay writes into an open meeting', () => {
418
429
  vi.useRealTimers();
419
430
  });
420
431
  });
432
+
433
+ describe('the needs-you briefing on the meeting loop', () => {
434
+ const walkTurn = (n: number, text: string, active: boolean, transcript = '') => ({
435
+ conversation_id: 'c1', turn_id: `t${n}`, turn: n, transcript, reply_text: text, audio_url: `/a/${n}`, audio_reason: null,
436
+ briefing: { active, index: n - 1, of: 2 },
437
+ });
438
+ it('start makes the assistant speak the first question with NO user line, then listens; the answer is spoken and the end goes idle', async () => {
439
+ const turn = vi.fn()
440
+ .mockResolvedValueOnce(walkTurn(1, 'Question 1 of 2: TEST: sample A. Yes or no?', true))
441
+ .mockResolvedValueOnce(walkTurn(2, 'Yes, noted. Question 2 of 2: TEST: sample B. Yes or no?', true, 'yes'))
442
+ .mockResolvedValueOnce(walkTurn(3, 'No, noted. That was the last one. I saved 2 answers in your queue.', false, 'no'));
443
+ const spoken: string[] = [];
444
+ const { c } = rig({ turn: turn as any, utterances: [], speak: (async (r: any) => { spoken.push(r.replyText); }) as any });
445
+ await c.startBriefing();
446
+ expect(spoken).toEqual(['Question 1 of 2: TEST: sample A. Yes or no?']);
447
+ expect(c.state().lines).toEqual([{ role: 'assistant', text: 'Question 1 of 2: TEST: sample A. Yes or no?' }]);
448
+ expect(turn.mock.calls[0][0]).toMatchObject({ briefing: 'start' });
449
+ await settle(() => c.state().micOn);
450
+ expect(c.state().micOn).toBe(true);
451
+ await c.sendText('yes');
452
+ await c.sendText('no');
453
+ expect(spoken).toHaveLength(3);
454
+ expect(c.state().lines.map((l) => l.role)).toEqual(['assistant', 'user', 'assistant', 'user', 'assistant']);
455
+ await settle(() => !c.state().micOn);
456
+ expect(c.state().micOn).toBe(false);
457
+ expect(c.state().phase).toBe('idle');
458
+ await c.end();
459
+ });
460
+ });