@startsimpli/integrations 0.2.145 → 0.2.147

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 (76) hide show
  1. package/package.json +3 -3
  2. package/src/__tests__/briefing-actions.test.ts +2 -0
  3. package/src/__tests__/briefing-reply.test.ts +334 -0
  4. package/src/__tests__/corpus-tracker.test.tsx +79 -0
  5. package/src/__tests__/extract-classify.test.ts +9 -4
  6. package/src/__tests__/owner-backfill.test.ts +114 -0
  7. package/src/__tests__/owner-link.test.ts +115 -0
  8. package/src/__tests__/owner-picker.test.tsx +70 -0
  9. package/src/__tests__/private-items.test.ts +63 -0
  10. package/src/__tests__/roster.test.ts +27 -0
  11. package/src/__tests__/task-detail-private.test.tsx +44 -0
  12. package/src/__tests__/tracker-sort.test.ts +28 -0
  13. package/src/components/index.ts +1 -0
  14. package/src/components/pages/TaskDetailPage.tsx +51 -2
  15. package/src/components/pages/TrackerPage.tsx +28 -6
  16. package/src/components/pages/task-tracker/OwnerPicker.tsx +82 -0
  17. package/src/components/pages/tracker/TrackerBoard.tsx +45 -0
  18. package/src/components/pages/tracker/TrackerToolbar.tsx +44 -0
  19. package/src/corpus/briefing/actions/execute.ts +5 -4
  20. package/src/corpus/briefing/actions/log.ts +1 -1
  21. package/src/corpus/briefing/actions/types.ts +21 -0
  22. package/src/corpus/briefing/index.ts +1 -0
  23. package/src/corpus/briefing/intent/model.ts +3 -0
  24. package/src/corpus/briefing/intent/resolve.ts +14 -6
  25. package/src/corpus/briefing/intent/types.ts +7 -0
  26. package/src/corpus/briefing/reply/handle.ts +174 -0
  27. package/src/corpus/briefing/reply/index.ts +6 -0
  28. package/src/corpus/briefing/reply/respond.ts +95 -0
  29. package/src/corpus/briefing/reply/types.ts +112 -0
  30. package/src/corpus/briefing/store.ts +14 -0
  31. package/src/corpus/client.ts +24 -18
  32. package/src/corpus/entities.ts +7 -0
  33. package/src/corpus/extract.ts +21 -0
  34. package/src/corpus/index.ts +4 -0
  35. package/src/corpus/owner-backfill.ts +200 -0
  36. package/src/corpus/owner-link.ts +160 -0
  37. package/src/corpus/roster.ts +53 -0
  38. package/src/corpus/tracker-groups.ts +8 -4
  39. package/src/corpus/tracker-sort.ts +51 -0
  40. package/src/corpus/types.ts +24 -1
  41. package/src/native/app/FoundryApp.tsx +25 -7
  42. package/src/native/app/__tests__/briefingLink.test.tsx +57 -0
  43. package/src/native/app/__tests__/briefingServices.test.ts +92 -0
  44. package/src/native/app/__tests__/launch.test.ts +2 -1
  45. package/src/native/app/briefingServices.ts +101 -0
  46. package/src/native/app/config/__tests__/briefingConfig.test.ts +49 -0
  47. package/src/native/app/config/links.ts +4 -1
  48. package/src/native/app/config/types.ts +13 -1
  49. package/src/native/app/config/validate.ts +20 -2
  50. package/src/native/app/data.ts +3 -3
  51. package/src/native/app/device.ts +3 -0
  52. package/src/native/app/launch.ts +4 -0
  53. package/src/native/app/registry.tsx +3 -1
  54. package/src/native/app/screens/RecordScreen.tsx +3 -2
  55. package/src/native/app/services.ts +11 -30
  56. package/src/native/app/strings.ts +28 -0
  57. package/src/native/briefing/BriefingCard.tsx +14 -2
  58. package/src/native/briefing/BriefingReply.tsx +68 -0
  59. package/src/native/briefing/__tests__/BriefingReply.test.tsx +144 -0
  60. package/src/native/briefing/__tests__/fakeReply.test.ts +46 -0
  61. package/src/native/briefing/__tests__/notify.test.ts +42 -1
  62. package/src/native/briefing/__tests__/replyApi.test.ts +43 -0
  63. package/src/native/briefing/__tests__/replyController.test.ts +230 -0
  64. package/src/native/briefing/__tests__/replyPosition.test.ts +116 -0
  65. package/src/native/briefing/audioPlayer.ts +9 -2
  66. package/src/native/briefing/controller.ts +50 -5
  67. package/src/native/briefing/fake.ts +25 -18
  68. package/src/native/briefing/fakeReply.ts +65 -0
  69. package/src/native/briefing/index.ts +8 -3
  70. package/src/native/briefing/notify.ts +42 -0
  71. package/src/native/briefing/reply.ts +261 -0
  72. package/src/native/briefing/replyApi.ts +82 -0
  73. package/src/native/recording/__tests__/deeplink.test.ts +20 -0
  74. package/src/native/recording/deeplink.ts +7 -0
  75. package/src/native/tracker/__tests__/itemsChanged.test.ts +13 -0
  76. package/src/native/tracker/tab.tsx +4 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startsimpli/integrations",
3
- "version": "0.2.145",
3
+ "version": "0.2.147",
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/auth": "^0.4.50",
54
53
  "@startsimpli/utils": "^0.4.17",
55
- "@startsimpli/ui": "^0.4.171"
54
+ "@startsimpli/ui": "^0.4.171",
55
+ "@startsimpli/auth": "^0.4.50"
56
56
  },
57
57
  "peerDependenciesMeta": {
58
58
  "react": {
@@ -275,6 +275,8 @@ describe('what is said back', () => {
275
275
  const out = await t.run([{ type: 'done', itemId: 'bench' }, { type: 'drop', itemId: 'paper' }]);
276
276
  expect(out.results.map((r) => r.status)).toEqual(['failed', 'applied']);
277
277
  expect(out.text).toMatch(/could not update/i);
278
+ expect(out.results[0].reason).toBe('503'); // why, for the diagnostics; never spoken
279
+ expect(out.text).not.toContain('503');
278
280
  expect(out.undoDepth).toBe(1); // only what really changed can be undone
279
281
  });
280
282
  });
@@ -0,0 +1,334 @@
1
+ // @vitest-environment node
2
+ /**
3
+ * POST /corpus/briefing/reply (bd startsim-t1hsu.1): a spoken reply to the briefing becomes edits.
4
+ * Real grammar, real executor, real tenant verbs over an in-memory tenant; only the model, speech and
5
+ * transcription are fakes.
6
+ */
7
+ import { describe, expect, it, vi } from 'vitest';
8
+
9
+ import { createPlanningApi } from '../corpus/client';
10
+ import {
11
+ briefingReplyResponse, briefingReplyAudioResponse, commitmentEditSeam, createEntityActionLog, createEntityBriefingStore,
12
+ handleBriefingReply,
13
+ type BriefingReplyDeps, type BriefingScriptLlm, type ReplyResult,
14
+ } from '../corpus/briefing';
15
+
16
+ const ME = 'me';
17
+ const NOW = Date.parse('2026-11-04T15:00:00Z'); // Wednesday 10:00 in New York
18
+ const TZ = 'America/New_York';
19
+ const TEXT = "Good morning. First, Order dad's bench, due today. Then, Pick up printer paper, due today. That is all.";
20
+ const at = (needle: string) => ({ start: TEXT.indexOf(needle), end: TEXT.indexOf(needle) + needle.length });
21
+
22
+ function tenant() {
23
+ const rows = new Map<string, any>();
24
+ let seq = 500;
25
+ const add = (id: string, title: string, due: string, extra: object = {}) => rows.set(`item:${id}`, {
26
+ id, entity_type: 'commitment', external_id: `item:${id}`, name: title,
27
+ data: { title, status: 'open', owner_sub: ME, subtype: 'action', due_at: due, ...extra },
28
+ });
29
+ add('bench', "Order dad's bench", '2026-11-04');
30
+ add('paper', 'Pick up printer paper', '2026-11-04');
31
+ add('john', 'Call John', '2026-11-12');
32
+ const http = {
33
+ get: vi.fn(async (path: string, options?: { params?: Record<string, unknown> }) => {
34
+ if (path.startsWith('api/v1/entities/')) {
35
+ const id = decodeURIComponent(path.split('/').pop() ?? '');
36
+ const hit = [...rows.values()].find((r) => String(r.id) === id);
37
+ if (hit) return hit;
38
+ throw Object.assign(new Error('not found'), { status: 404 });
39
+ }
40
+ const ext = options?.params?.external_id__in;
41
+ return { results: [...rows.values()].filter((r) => r.external_id === ext) };
42
+ }),
43
+ post: vi.fn(async (_path: string, body: any) => {
44
+ const prev = rows.get(body.external_id);
45
+ const row = { id: prev?.id ?? String(++seq), entity_type: body.entity_type, external_id: body.external_id, name: body.name ?? prev?.name, data: { ...(prev?.data ?? {}), ...body.data } };
46
+ rows.set(body.external_id, row);
47
+ return row;
48
+ }),
49
+ };
50
+ return { rows, http, due: (id: string) => (rows.get(`item:${id}`).data.due_at as string | undefined)?.slice(0, 10), status: (id: string) => rows.get(`item:${id}`).data.status as string };
51
+ }
52
+
53
+ async function setup(over: Partial<BriefingReplyDeps> = {}, owner = ME) {
54
+ const t = tenant();
55
+ const scope = { orgId: 'org', userId: owner } as never;
56
+ const api = createPlanningApi({ http: t.http as never, scope });
57
+ const store = createEntityBriefingStore(t.http as never, owner);
58
+ const saved = await store.save({
59
+ externalId: `briefing:2026-11-04:${owner}`, localDate: '2026-11-04', contentHash: 'h', text: TEXT, scriptSource: 'template',
60
+ items: [
61
+ { id: 'bench', title: "Order dad's bench", kind: 'due_today', group: 'Personal', dueDate: '2026-11-04' },
62
+ { id: 'paper', title: 'Pick up printer paper', kind: 'due_today', group: 'Personal', dueDate: '2026-11-04' },
63
+ ],
64
+ remaining: 0,
65
+ context: {
66
+ itemIds: ['bench', 'paper'], localDate: '2026-11-04', timeZone: TZ,
67
+ offsets: [{ id: 'bench', ...at("Order dad's bench, due today.") }, { id: 'paper', ...at('Pick up printer paper, due today.') }],
68
+ },
69
+ createdAt: new Date(NOW).toISOString(),
70
+ });
71
+ const synthesize = vi.fn(async ({ text }: { text: string }) => ({
72
+ audio: new Uint8Array([1, 2, 3]), mimeType: 'audio/mpeg', model: 'm', provider: 'openai', usage: { characters: text.length },
73
+ }));
74
+ const put = vi.fn(async ({ noteId }: { noteId: string }) => `s3://voice/${noteId}.mp3`);
75
+ const transcribe = vi.fn(async (_i: { audio: Uint8Array; mimeType: string; hints: string[] }) => 'move this one to friday');
76
+ const deps: BriefingReplyDeps = {
77
+ http: t.http as never,
78
+ ownerSub: owner,
79
+ loadItems: async () => [...t.rows.values()].filter((r) => r.data.status === 'open').map((r) => ({
80
+ id: r.id, title: r.data.title, status: r.data.status, dueAt: r.data.due_at, ownerSub: ME,
81
+ })),
82
+ seam: commitmentEditSeam({ api, http: t.http as never, scope }),
83
+ log: createEntityActionLog(t.http as never, owner),
84
+ synthesize,
85
+ audio: { put, get: async () => ({ audio: new Uint8Array([1, 2, 3]), mimeType: 'audio/mpeg' }) },
86
+ transcribe,
87
+ now: () => NOW,
88
+ timeZone: TZ,
89
+ ...over,
90
+ };
91
+ return { t, deps, saved, synthesize, put, transcribe, store };
92
+ }
93
+
94
+ const reply = (deps: BriefingReplyDeps, briefingId: string, over: Record<string, unknown> = {}) =>
95
+ handleBriefingReply(deps, { subject: { kind: 'briefing', id: briefingId }, clientActionId: `a-${Math.random().toString(36).slice(2, 10)}`, ...over } as never);
96
+
97
+ describe('preview, apply and auto-apply', () => {
98
+ it('test_preview_says_what_was_understood_and_writes_nothing', async () => {
99
+ const s = await setup();
100
+ const out = await reply(s.deps, s.saved.id, { utterance: 'move the bench one to friday', mode: 'preview' });
101
+ expect(out).toMatchObject({ kind: 'preview', needsConfirm: true, understood: "Move Order dad's bench to Friday" });
102
+ expect(out.actions).toEqual([expect.objectContaining({ type: 'defer', itemId: 'bench', to: '2026-11-06' })]);
103
+ expect(s.t.due('bench')).toBe('2026-11-04');
104
+ expect(out.confirmation).toBeNull();
105
+ });
106
+
107
+ it('test_apply_runs_the_stored_preview_by_client_action_id_without_a_second_parse', async () => {
108
+ const llm: BriefingScriptLlm = { write: vi.fn(async () => JSON.stringify({ confidence: 0.95, actions: [{ type: 'defer', item_id: 'bench', to: '2026-11-06' }] })) };
109
+ const s = await setup({ intentLlm: llm });
110
+ const first = await reply(s.deps, s.saved.id, { utterance: 'push the bench thing to friday', mode: 'preview', clientActionId: 'press-0001' });
111
+ expect(llm.write).toHaveBeenCalledTimes(1);
112
+ const out = await reply(s.deps, s.saved.id, { clientActionId: 'press-0001', apply: true });
113
+ expect(llm.write).toHaveBeenCalledTimes(1);
114
+ expect(first.kind).toBe('preview');
115
+ expect(out).toMatchObject({ kind: 'applied', needsConfirm: false, undoDepth: 1, refresh: true });
116
+ expect(s.t.due('bench')).toBe('2026-11-06');
117
+ expect(out.confirmation?.text).toBe("Moved Order dad's bench to Friday.");
118
+ expect(out.confirmation?.audioUrl).toBe(`/corpus/briefing/${s.saved.id}/reply/press-0001/audio`);
119
+ });
120
+
121
+ it('test_apply_with_nothing_stored_is_a_conflict_not_a_guess', async () => {
122
+ const s = await setup();
123
+ await expect(reply(s.deps, s.saved.id, { clientActionId: 'press-0002', apply: true })).rejects.toMatchObject({ status: 409 });
124
+ });
125
+
126
+ it('test_auto_mode_applies_a_sure_reply_at_once_and_speaks_the_confirmation', async () => {
127
+ const s = await setup();
128
+ const out = await reply(s.deps, s.saved.id, { utterance: 'push the paper one to friday', mode: 'auto' });
129
+ expect(out).toMatchObject({ kind: 'applied', needsConfirm: false, confidence: 1, source: 'grammar' });
130
+ expect(s.t.due('paper')).toBe('2026-11-06');
131
+ expect(s.synthesize).toHaveBeenCalledWith({ text: 'Moved Pick up printer paper to Friday.' });
132
+ expect(out.confirmation).toMatchObject({ text: 'Moved Pick up printer paper to Friday.', mimeType: 'audio/mpeg' });
133
+ });
134
+
135
+ it('test_auto_mode_asks_for_confirmation_when_the_model_is_unsure', async () => {
136
+ const llm: BriefingScriptLlm = { write: vi.fn(async () => JSON.stringify({ confidence: 0.7, actions: [{ type: 'defer', item_id: 'bench', to: '2026-11-06' }] })) };
137
+ const s = await setup({ intentLlm: llm });
138
+ const out = await reply(s.deps, s.saved.id, { utterance: 'maybe the bench could go to friday', mode: 'auto' });
139
+ expect(out).toMatchObject({ kind: 'preview', needsConfirm: true, confidence: 0.7 });
140
+ expect(s.t.due('bench')).toBe('2026-11-04');
141
+ });
142
+
143
+ it('test_this_one_is_the_item_being_read_at_the_press', async () => {
144
+ const s = await setup();
145
+ const out = await reply(s.deps, s.saved.id, { utterance: 'move this one to friday', mode: 'auto', position: { charPosition: at('Pick up printer paper').start + 3 } });
146
+ expect(out.actions).toEqual([expect.objectContaining({ type: 'defer', itemId: 'paper' })]);
147
+ expect(s.t.due('paper')).toBe('2026-11-06');
148
+ expect(s.t.due('bench')).toBe('2026-11-04');
149
+ });
150
+
151
+ it('test_position_in_seconds_is_estimated_against_the_text_length', async () => {
152
+ const s = await setup();
153
+ const frac = (at('Pick up printer paper').start + 3) / TEXT.length;
154
+ const out = await reply(s.deps, s.saved.id, { utterance: 'done with this one', mode: 'auto', position: { seconds: 30 * frac, durationSeconds: 30 } });
155
+ expect(out.actions).toEqual([{ type: 'done', itemId: 'paper' }]);
156
+ });
157
+ });
158
+
159
+ describe('undo and replay', () => {
160
+ it('test_undo_restores_the_last_change_through_the_same_seam', async () => {
161
+ const s = await setup();
162
+ await reply(s.deps, s.saved.id, { utterance: 'push the bench one to friday', mode: 'auto' });
163
+ const out = await reply(s.deps, s.saved.id, { undo: true });
164
+ expect(out).toMatchObject({ kind: 'applied', undoDepth: 0 });
165
+ expect(out.confirmation?.text).toMatch(/^Undid it\./);
166
+ expect(s.t.due('bench')).toBe('2026-11-04');
167
+ });
168
+
169
+ it('test_saying_undo_works_too', async () => {
170
+ const s = await setup();
171
+ await reply(s.deps, s.saved.id, { utterance: 'push the bench one to friday', mode: 'auto' });
172
+ const out = await reply(s.deps, s.saved.id, { utterance: 'undo', mode: 'auto' });
173
+ expect(out.actions).toEqual([{ type: 'undo' }]);
174
+ expect(s.t.due('bench')).toBe('2026-11-04');
175
+ });
176
+
177
+ it('test_a_resend_of_the_same_press_replays_without_transcribing_or_writing_again', async () => {
178
+ const s = await setup();
179
+ const audio = { audio: new Uint8Array([9, 9]), mimeType: 'audio/mp4' };
180
+ const first = await reply(s.deps, s.saved.id, { audio, mode: 'auto', clientActionId: 'press-0003', position: { charPosition: at('Pick up printer paper').start + 3 } });
181
+ const writes = (s.t.http.post as any).mock.calls.length;
182
+ const again = await reply(s.deps, s.saved.id, { audio, mode: 'auto', clientActionId: 'press-0003' });
183
+ expect(s.transcribe).toHaveBeenCalledTimes(1);
184
+ expect((s.t.http.post as any).mock.calls.length).toBe(writes);
185
+ expect(again).toMatchObject({ kind: 'applied', replayed: true, undoDepth: 1 });
186
+ expect(again.confirmation?.text).toBe(first.confirmation?.text);
187
+ expect(again.utterance).toBe('move this one to friday');
188
+ });
189
+ });
190
+
191
+ describe('asking back', () => {
192
+ it('test_an_ambiguous_reply_asks_a_spoken_question_and_changes_nothing', async () => {
193
+ const s = await setup();
194
+ const out = await reply(s.deps, s.saved.id, { utterance: 'move that one to friday', mode: 'auto' });
195
+ expect(out.kind).toBe('clarify');
196
+ expect(out.question).toMatch(/^Which one:/);
197
+ expect(out.confirmation?.text).toBe(out.question);
198
+ expect(out.refresh).toBe(false);
199
+ expect(s.t.due('bench')).toBe('2026-11-04');
200
+ });
201
+
202
+ it('test_the_answer_to_a_question_is_read_with_the_earlier_reply', async () => {
203
+ const s = await setup();
204
+ const asked = await reply(s.deps, s.saved.id, { utterance: 'move that one to friday', mode: 'auto', clientActionId: 'press-0004' });
205
+ const out = await reply(s.deps, s.saved.id, { utterance: 'the bench one', mode: 'auto', inReplyTo: 'press-0004' });
206
+ expect(asked.kind).toBe('clarify');
207
+ expect(out).toMatchObject({ kind: 'applied' });
208
+ expect(out.actions).toEqual([expect.objectContaining({ type: 'defer', itemId: 'bench', to: '2026-11-06' })]);
209
+ expect(s.t.due('bench')).toBe('2026-11-06');
210
+ });
211
+
212
+ it('test_the_model_sees_the_question_and_the_earlier_words', async () => {
213
+ const prompts: string[] = [];
214
+ const llm: BriefingScriptLlm = { write: vi.fn(async ({ prompt }) => { prompts.push(prompt); return JSON.stringify({ confidence: 0.9, actions: [{ type: 'defer', item_id: 'bench', to: '2026-11-06' }] }); }) };
215
+ const s = await setup({ intentLlm: llm });
216
+ await reply(s.deps, s.saved.id, { utterance: 'move that one to friday', mode: 'preview', clientActionId: 'press-0005' });
217
+ await reply(s.deps, s.saved.id, { utterance: 'the bench one', mode: 'preview', inReplyTo: 'press-0005' });
218
+ expect(prompts[1]).toContain('move that one to friday');
219
+ expect(prompts[1]).toContain('Which one');
220
+ });
221
+
222
+ it('test_silence_is_asked_again_not_sent_to_the_model', async () => {
223
+ const llm: BriefingScriptLlm = { write: vi.fn(async () => '{}') };
224
+ const s = await setup({ intentLlm: llm, transcribe: vi.fn(async () => ' ') });
225
+ const out = await reply(s.deps, s.saved.id, { audio: { audio: new Uint8Array([1]), mimeType: 'audio/mp4' }, mode: 'auto' });
226
+ expect(out.kind).toBe('clarify');
227
+ expect(out.question).toMatch(/say that again/i);
228
+ expect(llm.write).not.toHaveBeenCalled();
229
+ });
230
+ });
231
+
232
+ describe('what the transcriber is told', () => {
233
+ it('test_the_titles_read_out_and_the_other_open_ones_are_offered_as_vocabulary', async () => {
234
+ const s = await setup();
235
+ await reply(s.deps, s.saved.id, { audio: { audio: new Uint8Array([1]), mimeType: 'audio/mp4' }, mode: 'preview' });
236
+ expect(s.transcribe.mock.calls[0][0].hints).toEqual(["Order dad's bench", 'Pick up printer paper', 'Call John']);
237
+ });
238
+ });
239
+
240
+ describe('what it refuses', () => {
241
+ it("test_another_person's_briefing_is_not_found", async () => {
242
+ const s = await setup();
243
+ const other = { ...s.deps, ownerSub: 'someone-else' };
244
+ await expect(reply(other, s.saved.id, { utterance: 'undo', mode: 'auto' })).rejects.toMatchObject({ status: 404 });
245
+ });
246
+
247
+ it('test_a_reply_to_a_question_row_is_not_wired_yet', async () => {
248
+ const s = await setup();
249
+ await expect(handleBriefingReply(s.deps, { subject: { kind: 'question', id: 'q1' }, clientActionId: 'press-0006', utterance: 'today' } as never)).rejects.toMatchObject({ status: 501 });
250
+ });
251
+
252
+ it('test_a_failed_transcription_is_a_retryable_error_that_keeps_the_press_unapplied', async () => {
253
+ const s = await setup({ transcribe: vi.fn(async () => { throw new Error('stt down'); }) });
254
+ await expect(reply(s.deps, s.saved.id, { audio: { audio: new Uint8Array([1]), mimeType: 'audio/mp4' }, mode: 'auto', clientActionId: 'press-0007' }))
255
+ .rejects.toMatchObject({ status: 502, code: 'transcription_failed' });
256
+ });
257
+
258
+ it('test_speech_failing_never_loses_the_confirmation_text', async () => {
259
+ const s = await setup({ synthesize: vi.fn(async () => { throw new Error('tts down'); }) });
260
+ const out = await reply(s.deps, s.saved.id, { utterance: 'push the paper one to friday', mode: 'auto' });
261
+ expect(out.kind).toBe('applied');
262
+ expect(out.confirmation).toMatchObject({ text: 'Moved Pick up printer paper to Friday.', audioUrl: null });
263
+ });
264
+ });
265
+
266
+ describe('the HTTP wrapper', () => {
267
+ const post = (url: string, body: BodyInit, headers: Record<string, string> = {}) => new Request(`http://x${url}`, { method: 'POST', body, headers });
268
+
269
+ it('test_json_body_with_a_transcript', async () => {
270
+ const s = await setup();
271
+ const res = await briefingReplyResponse(post('/corpus/briefing/reply', JSON.stringify({ briefingId: s.saved.id, clientActionId: 'press-0008', utterance: 'push the paper one to friday' }), { 'content-type': 'application/json' }), s.deps);
272
+ expect(res.status).toBe(200);
273
+ const body = (await res.json()) as ReplyResult;
274
+ expect(body).toMatchObject({ kind: 'applied', clientActionId: 'press-0008' });
275
+ expect(s.t.due('paper')).toBe('2026-11-06');
276
+ });
277
+
278
+ it('test_multipart_body_with_audio_is_transcribed', async () => {
279
+ const s = await setup();
280
+ const form = new FormData();
281
+ form.append('audio', new Blob([new Uint8Array([1, 2, 3])], { type: 'audio/mp4' }), 'reply.m4a');
282
+ form.append('briefingId', s.saved.id);
283
+ form.append('clientActionId', 'press-0009');
284
+ form.append('position', JSON.stringify({ charPosition: at('Pick up printer paper').start + 3 }));
285
+ const res = await briefingReplyResponse(post('/corpus/briefing/reply', form), s.deps);
286
+ expect(res.status).toBe(200);
287
+ expect(((await res.json()) as ReplyResult).utterance).toBe('move this one to friday');
288
+ expect(s.transcribe.mock.calls[0][0]).toMatchObject({ mimeType: 'audio/mp4' });
289
+ expect(s.t.due('paper')).toBe('2026-11-06');
290
+ });
291
+
292
+ it('test_bad_requests_are_400_and_a_stranger_is_404', async () => {
293
+ const s = await setup();
294
+ expect((await briefingReplyResponse(post('/r', '{nope'), s.deps)).status).toBe(400);
295
+ expect((await briefingReplyResponse(post('/r', JSON.stringify({ briefingId: s.saved.id, utterance: 'undo' })), s.deps)).status).toBe(400);
296
+ expect((await briefingReplyResponse(post('/r', JSON.stringify({ briefingId: s.saved.id, clientActionId: 'x', utterance: 'undo' })), s.deps)).status).toBe(400);
297
+ expect((await briefingReplyResponse(post('/r', JSON.stringify({ briefingId: s.saved.id, clientActionId: 'press-0010' })), s.deps)).status).toBe(400);
298
+ const res = await briefingReplyResponse(post('/r', JSON.stringify({ briefingId: s.saved.id, clientActionId: 'press-0011', utterance: 'undo' })), { ...s.deps, ownerSub: 'nobody' });
299
+ expect(res.status).toBe(404);
300
+ });
301
+
302
+ it('test_a_failed_transcription_is_502_with_a_code_the_app_can_retry_on', async () => {
303
+ const s = await setup({ transcribe: vi.fn(async () => { throw new Error('stt down'); }) });
304
+ const form = new FormData();
305
+ form.append('audio', new Blob([new Uint8Array([1])], { type: 'audio/mp4' }), 'r.m4a');
306
+ form.append('briefingId', s.saved.id);
307
+ form.append('clientActionId', 'press-0012');
308
+ const res = await briefingReplyResponse(post('/r', form), s.deps);
309
+ expect(res.status).toBe(502);
310
+ expect(await res.json()).toMatchObject({ code: 'transcription_failed' });
311
+ });
312
+ });
313
+
314
+ describe('the spoken confirmation, served to its owner only', () => {
315
+ it('test_confirmation_audio_is_served_for_the_owners_reply_and_404_for_others', async () => {
316
+ const s = await setup();
317
+ await reply(s.deps, s.saved.id, { utterance: 'push the paper one to friday', mode: 'auto', clientActionId: 'press-0013' });
318
+ const ok = await briefingReplyAudioResponse(s.saved.id, 'press-0013', s.deps);
319
+ expect(ok.status).toBe(200);
320
+ expect(ok.headers.get('content-type')).toBe('audio/mpeg');
321
+ expect((await briefingReplyAudioResponse(s.saved.id, 'press-9999', s.deps)).status).toBe(404);
322
+ expect((await briefingReplyAudioResponse(s.saved.id, 'press-0013', { ...s.deps, ownerSub: 'nobody' })).status).toBe(404);
323
+ });
324
+ });
325
+
326
+ describe('the store', () => {
327
+ it('test_get_by_id_is_owner_checked_and_only_briefing_rows', async () => {
328
+ const s = await setup();
329
+ expect((await s.store.get(s.saved.id))?.text).toBe(TEXT);
330
+ expect(await createEntityBriefingStore(s.t.http as never, 'nobody').get(s.saved.id)).toBeNull();
331
+ expect(await s.store.get('bench')).toBeNull();
332
+ expect(await s.store.get('does-not-exist')).toBeNull();
333
+ });
334
+ });
@@ -727,3 +727,82 @@ describe('TrackerPage — quick filters', () => {
727
727
  expect(screen.getByText('Stuck one')).toBeInTheDocument();
728
728
  });
729
729
  });
730
+
731
+ describe('TrackerPage — sort and board', () => {
732
+ const rows = [
733
+ commitment({ externalId: 'commit:b', title: 'Bravo', ownerName: 'Zed', dueAt: '2026-08-20T00:00:00Z', lastSeenAt: '2026-08-02T00:00:00Z' }),
734
+ commitment({ externalId: 'commit:a', title: 'Alpha', ownerName: 'Amy', dueAt: '2026-08-25T00:00:00Z', lastSeenAt: '2026-08-09T00:00:00Z' }),
735
+ commitment({ externalId: 'commit:c', title: 'Charlie', status: 'blocked', statusReason: 'waiting', dueAt: '2026-08-30T00:00:00Z' }),
736
+ ];
737
+ const order = () => screen.getAllByRole('listitem').map((li) => li.textContent ?? '');
738
+
739
+ it('asks the SERVER for the chosen order and re-reads page one', async () => {
740
+ const queries: CommitmentQuery[] = [];
741
+ render(<TrackerPage api={makeApi({ rows, onQuery: (q) => queries.push(q) })} scope={SCOPE} now={NOW} />);
742
+ await screen.findByText('Alpha');
743
+ expect(queries[0].sort ?? 'due').toBe('due');
744
+ await userEvent.selectOptions(screen.getByRole('combobox', { name: /sort to-dos/i }), 'title');
745
+ await vi.waitFor(() => expect(queries.at(-1)?.sort).toBe('title'));
746
+ expect(queries.at(-1)?.page).toBeUndefined();
747
+ });
748
+
749
+ it('orders rows within a group by the chosen sort', async () => {
750
+ render(<TrackerPage api={makeApi({ rows })} scope={SCOPE} now={NOW} />);
751
+ await screen.findByText('Alpha');
752
+ const pos = (t: string[]) => (name: string) => t.findIndex((x) => x.includes(name));
753
+ let p = pos(order());
754
+ expect(p('Bravo')).toBeLessThan(p('Alpha'));
755
+ await userEvent.selectOptions(screen.getByRole('combobox', { name: /sort to-dos/i }), 'title');
756
+ p = pos(order());
757
+ expect(p('Alpha')).toBeLessThan(p('Bravo'));
758
+ await userEvent.selectOptions(screen.getByRole('combobox', { name: /sort to-dos/i }), 'updated');
759
+ p = pos(order());
760
+ expect(p('Alpha')).toBeLessThan(p('Bravo'));
761
+ });
762
+
763
+ it('shows the same to-dos as a board with one column per status, and back', async () => {
764
+ render(<TrackerPage api={makeApi({ rows })} scope={SCOPE} now={NOW} />);
765
+ await screen.findByText('Alpha');
766
+ await userEvent.click(screen.getByRole('button', { name: 'Board' }));
767
+ const blocked = screen.getByRole('region', { name: 'Blocked column' });
768
+ expect(within(blocked).getByText('Charlie')).toBeInTheDocument();
769
+ const open = screen.getByRole('region', { name: 'Open column' });
770
+ expect(within(open).getByText('Alpha')).toBeInTheDocument();
771
+ expect(within(open).queryByText('Charlie')).toBeNull();
772
+ expect(screen.queryByRole('region', { name: 'Up next' })).toBeNull();
773
+ await userEvent.click(screen.getByRole('button', { name: 'List' }));
774
+ expect(screen.queryByTestId('tracker-board')).toBeNull();
775
+ });
776
+ });
777
+
778
+ describe('TrackerPage — 400+ open to-dos, paged by the server (bd startsim-768w.38.46)', () => {
779
+ const MANY = Array.from({ length: 437 }, (_, i) =>
780
+ commitment({ externalId: `commit:n${String(i).padStart(3, '0')}`, title: `Todo ${String(i).padStart(3, '0')}`, dueAt: '2026-09-01T00:00:00Z' }));
781
+
782
+ function pagedApi(onQuery: (q: CommitmentQuery) => void): CommitmentTrackerApi {
783
+ return {
784
+ async listCommitments(query: CommitmentQuery = {}) {
785
+ onQuery(query);
786
+ const size = Math.min(query.pageSize ?? 50, 200);
787
+ const page = query.page ?? 1;
788
+ const slice = MANY.slice((page - 1) * size, page * size);
789
+ return { count: MANY.length, next: page * size < MANY.length ? String(page + 1) : null, previous: null, results: slice, appliedFilters: ['status'] };
790
+ },
791
+ };
792
+ }
793
+
794
+ it('loads 200 at a time, never the whole set, and reaches every row with no duplicates', async () => {
795
+ const queries: CommitmentQuery[] = [];
796
+ render(<TrackerPage api={pagedApi((q) => queries.push(q))} scope={SCOPE} now={NOW} />);
797
+ await screen.findByText('Todo 000');
798
+ expect(screen.getByText(/Showing 200 of 437/)).toBeInTheDocument();
799
+ expect(queries.every((q) => (q.pageSize ?? 0) <= 200)).toBe(true);
800
+ await userEvent.click(screen.getByRole('button', { name: 'Load more' }));
801
+ await screen.findByText(/Showing 400 of 437/);
802
+ await userEvent.click(screen.getByRole('button', { name: 'Load more' }));
803
+ await vi.waitFor(() => expect(screen.queryByText(/Showing/)).toBeNull());
804
+ expect(screen.getByTestId('tracker-summary').textContent).toMatch(/437 owed/);
805
+ expect(screen.getAllByText(/^Todo \d{3}$/)).toHaveLength(437);
806
+ expect(queries.filter((q) => q.page).map((q) => q.page)).toEqual([2, 3]);
807
+ });
808
+ });
@@ -78,11 +78,13 @@ describe('the Nov 5 replay (startsim-8dttf)', () => {
78
78
  expect(filed[byTitle(items, 'tunnel timeout').externalId]).toBe('f-dbg');
79
79
  });
80
80
 
81
- it("dad's bench present links to Prezzies, or to the personal destination", async () => {
81
+ it("dad's bench present is under the note's Personal heading: private and personal, even when the model would file it under Prezzies (bd startsim-768w.38.48)", async () => {
82
82
  const { corpus, saves } = world();
83
83
  await extractCommitments({ scope: SCOPE }, { corpus, extractor: extractor(reader()) });
84
84
  const bench = byTitle(saves[0].items, 'bench');
85
- expect(saves[0].options!.fileUnder![bench.externalId]).toBe('f-prez');
85
+ expect(saves[0].options?.fileUnder?.[bench.externalId]).toBeUndefined();
86
+ expect(bench.visibility).toBe('private');
87
+ expect(bench.destination).toBe('personal');
86
88
  const second = world();
87
89
  await extractCommitments({ scope: SCOPE }, { corpus: second.corpus, extractor: extractor(reader({ 'Order the bench as a present for dad': PERSONAL })) });
88
90
  const personal = byTitle(second.saves[0].items, 'bench');
@@ -118,7 +120,9 @@ describe('one destination per item', () => {
118
120
  await extractCommitments({ scope: SCOPE }, { corpus, extractor: extractor(reader({ 'Book the dentist for next week': 'f-invented' })) });
119
121
  const dentist = byTitle(saves[0].items, 'dentist');
120
122
  expect(dentist.focusId).toBeUndefined();
121
- expect(dentist.destination).toBeUndefined();
123
+ // Under the Personal heading, so private + personal whatever the model said.
124
+ expect(dentist.destination).toBe('personal');
125
+ expect(dentist.visibility).toBe('private');
122
126
  expect(saves[0].options!.fileUnder![dentist.externalId]).toBeUndefined();
123
127
  });
124
128
 
@@ -161,7 +165,8 @@ describe('no loss', () => {
161
165
  const result = await extractCommitments({ scope: SCOPE }, { corpus, extractor: extractor(async () => { throw new Error('model down'); }) });
162
166
  expect(saves[0].items).toHaveLength(5);
163
167
  expect(saves[0].options?.fileUnder).toBeUndefined();
164
- expect(saves[0].items.every((i) => !i.focusId && !i.destination)).toBe(true);
168
+ // The Personal-heading items are private without the model; nothing is FILED.
169
+ expect(saves[0].items.every((i) => !i.focusId && (!i.destination || i.visibility === 'private'))).toBe(true);
165
170
  expect(result.classifyFailure?.message).toContain('model down');
166
171
  });
167
172
 
@@ -0,0 +1,114 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { backfillOwners, formatBackfillReport, undoOwnerBackfill } from '../corpus/owner-backfill';
3
+
4
+ const roster = [
5
+ { sub: 'u-q', email: 'q@x.com', name: 'Quinn Osha' },
6
+ { sub: 'u-j', email: 'j@x.com', name: 'Jonathan Osha' },
7
+ { sub: 'u-s1', email: 's1@x.com', name: 'Stephanie Lee' },
8
+ { sub: 'u-s2', email: 's2@x.com', name: 'Stephanie Lopez' },
9
+ ];
10
+
11
+ function fake(owners: Array<Record<string, unknown>>) {
12
+ const rows = owners.map((data, i) => ({ id: i + 1, version: 1, data: { ...data } }));
13
+ const patches: Array<{ path: string; body: any }> = [];
14
+ return {
15
+ rows, patches,
16
+ http: {
17
+ async get(_p: string, o?: { params?: Record<string, unknown> }) {
18
+ const page = Number(o?.params?.page ?? 1);
19
+ const size = Number(o?.params?.page_size ?? 100);
20
+ const slice = rows.slice((page - 1) * size, page * size);
21
+ return { results: slice, next: page * size < rows.length ? 'more' : null };
22
+ },
23
+ async patch(path: string, body: any) {
24
+ patches.push({ path, body });
25
+ const row = rows.find((r) => `api/v1/entities/${r.id}` === path)!;
26
+ row.data = body.data;
27
+ return row;
28
+ },
29
+ },
30
+ };
31
+ }
32
+
33
+ const sample = [
34
+ { owner_name: 'Quinn' }, { owner_name: 'Jonathan Osha' }, { owner_name: 'Jonathan' },
35
+ { owner_name: 'Stephanie' }, { owner_name: 'Najima' }, { owner_name: 'Jonathan, Kevin' },
36
+ { owner_name: 'Quinn', owner_sub: 'picked-by-person' }, { title: 'no owner' },
37
+ ];
38
+
39
+ describe('backfillOwners', () => {
40
+ it('dry run counts and writes nothing', async () => {
41
+ const f = fake(sample);
42
+ const r = await backfillOwners({ http: f.http, roster, runId: 'r1' });
43
+ expect(f.patches).toHaveLength(0);
44
+ expect(r.mode).toBe('dry-run');
45
+ expect(r.rows).toBe(8);
46
+ expect(r.rowCounts).toMatchObject({ linked: 3, partial: 1, ambiguous: 1, unmatched: 1, already_linked: 1, none: 1 });
47
+ expect(r.tokenCounts).toEqual({ linked: 4, ambiguous: 1, unmatched: 2 });
48
+ expect(formatBackfillReport(r)).toContain('ambiguous');
49
+ });
50
+
51
+ it('pages through every row', async () => {
52
+ const f = fake(Array.from({ length: 250 }, () => ({ owner_name: 'Quinn' })));
53
+ const r = await backfillOwners({ http: f.http, roster, runId: 'r2' });
54
+ expect(r.rows).toBe(250);
55
+ });
56
+
57
+ it('apply links only the unambiguous, keeps owner_name, and leaves human picks alone', async () => {
58
+ const f = fake(sample);
59
+ const r = await backfillOwners({ http: f.http, roster, runId: 'r3', apply: true });
60
+ expect(r.written).toBe(4);
61
+ const byName = (n: string) => f.rows.filter((x) => x.data.owner_name === n);
62
+ expect(byName('Quinn')[0].data).toMatchObject({ owner_sub: 'u-q', owner_subs: '|u-q|', owner_name: 'Quinn' });
63
+ expect(byName('Jonathan, Kevin')[0].data).toMatchObject({ owner_sub: 'u-j', owner_subs: '|u-j|', owner_name: 'Jonathan, Kevin' });
64
+ expect(byName('Stephanie')[0].data.owner_sub).toBeUndefined();
65
+ expect(byName('Najima')[0].data.owner_sub).toBeUndefined();
66
+ expect(byName('Quinn')[1].data.owner_sub).toBe('picked-by-person');
67
+ expect(f.patches[0].body.expected_version).toBe(1);
68
+ });
69
+
70
+ it('joint owners both link', async () => {
71
+ const f = fake([{ owner_name: 'Quinn & Jonathan Osha' }]);
72
+ await backfillOwners({ http: f.http, roster, runId: 'r4', apply: true });
73
+ expect(f.rows[0].data).toMatchObject({ owner_sub: 'u-q', owner_subs: '|u-q|u-j|' });
74
+ });
75
+
76
+ it('is idempotent: a second run does not rewrite linked rows', async () => {
77
+ const f = fake(sample);
78
+ await backfillOwners({ http: f.http, roster, runId: 'a', apply: true });
79
+ const n = f.patches.length;
80
+ const again = await backfillOwners({ http: f.http, roster, runId: 'b', apply: true });
81
+ expect(f.patches.length).toBe(n);
82
+ expect(again.rowCounts.auto_linked).toBe(4);
83
+ });
84
+ });
85
+
86
+ describe('undoOwnerBackfill', () => {
87
+ it('restores prior owner fields exactly and keeps the text', async () => {
88
+ const f = fake(sample);
89
+ const before = JSON.stringify(f.rows.map((r) => r.data));
90
+ await backfillOwners({ http: f.http, roster, runId: 'u1', apply: true });
91
+ const u = await undoOwnerBackfill({ http: f.http, runId: 'u1' });
92
+ expect(u.restored).toBe(4);
93
+ for (const row of f.rows) {
94
+ expect(row.data.owner_link || '').toBe('');
95
+ expect(row.data.owner_sub || '').toBe(((JSON.parse(before)[Number(row.id) - 1].owner_sub) as string) || '');
96
+ expect(row.data.owner_subs || '').toBe('');
97
+ }
98
+ });
99
+
100
+ it('does not undo a row someone re-picked since', async () => {
101
+ const f = fake([{ owner_name: 'Quinn' }]);
102
+ await backfillOwners({ http: f.http, roster, runId: 'u2', apply: true });
103
+ f.rows[0].data.owner_sub = 'u-j';
104
+ const u = await undoOwnerBackfill({ http: f.http, runId: 'u2' });
105
+ expect(u).toMatchObject({ restored: 0, skippedChanged: 1 });
106
+ expect(f.rows[0].data.owner_sub).toBe('u-j');
107
+ });
108
+
109
+ it('only touches the named run', async () => {
110
+ const f = fake([{ owner_name: 'Quinn' }]);
111
+ await backfillOwners({ http: f.http, roster, runId: 'keep', apply: true });
112
+ expect((await undoOwnerBackfill({ http: f.http, runId: 'other' })).restored).toBe(0);
113
+ });
114
+ });