@startsimpli/integrations 0.2.137 → 0.2.139

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startsimpli/integrations",
3
- "version": "0.2.137",
3
+ "version": "0.2.139",
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",
@@ -98,11 +98,11 @@
98
98
  "vitest": "^3.0.0",
99
99
  "react-native": "0.85.3",
100
100
  "react-native-safe-area-context": "~5.7.0",
101
+ "@startsimpli/llm": "0.4.31",
101
102
  "@startsimpli/ui": "0.4.171",
102
103
  "@startsimpli/ui-native": "0.1.14",
103
104
  "@startsimpli/auth": "0.4.50",
104
- "@startsimpli/utils": "0.4.17",
105
- "@startsimpli/llm": "0.4.31"
105
+ "@startsimpli/utils": "0.4.17"
106
106
  },
107
107
  "scripts": {
108
108
  "type-check": "tsc --noEmit && tsc --noEmit -p tsconfig.native.json",
@@ -613,3 +613,17 @@ describe('TrackerPage — watching a queued sweep', () => {
613
613
  expect(await screen.findByText(/Read 1 meeting/)).toBeInTheDocument();
614
614
  });
615
615
  });
616
+
617
+ describe('TrackerPage — opening a to-do', () => {
618
+ it('opens the to-do itself, including one with no source meeting', async () => {
619
+ const onOpenItem = vi.fn();
620
+ const onOpenDocument = vi.fn();
621
+ const rows = [commitment({ externalId: 'commit:hand1', title: 'Pay the invoice', mentions: [] }), ...ROWS];
622
+ render(<TrackerPage api={makeApi({ rows })} scope={SCOPE} onOpenItem={onOpenItem} onOpenDocument={onOpenDocument} />);
623
+ await userEvent.click(await screen.findByRole('button', { name: 'Pay the invoice' }));
624
+ expect(onOpenItem).toHaveBeenCalledWith(expect.objectContaining({ externalId: 'commit:hand1' }));
625
+ await userEvent.click(await screen.findByRole('button', { name: 'Chase the inventor for comments on 2148' }));
626
+ expect(onOpenItem).toHaveBeenCalledWith(expect.objectContaining({ externalId: 'commit:open1' }));
627
+ expect(onOpenDocument).not.toHaveBeenCalled();
628
+ });
629
+ });
@@ -0,0 +1,268 @@
1
+ /**
2
+ * The open-questions queue (bd startsim-tmrvi.3, tmrvi.9): per-user, ranked,
3
+ * deduped by (item, kind), resolved or expired when the item moves on, answered
4
+ * through the item edit path so the answer syncs to the tracker.
5
+ */
6
+ import { describe, expect, it, vi } from 'vitest';
7
+
8
+ import { answerQuestion, listOpenQuestions, syncOpenQuestions } from '../corpus/questions';
9
+ import { commitmentEditSeam } from '../corpus/briefing/actions/seam';
10
+ import { createPlanningApi } from '../corpus/client';
11
+ import { guessOf, unknownGuess } from '../corpus/extraction-fields';
12
+ import type { ItemFields } from '../corpus/extraction-fields';
13
+ import type { CorpusHttp } from '../corpus/client';
14
+
15
+ const SCOPE = { orgId: 'o' } as never;
16
+ const ME = 'user-me';
17
+
18
+ interface Row { id: string; entity_type: string; external_id: string; name: string; data: Record<string, unknown>; version: number }
19
+
20
+ /** A tenant in memory: list/get, shallow-merging upsert, and the PATCH door. */
21
+ function tenant(seed: Array<Omit<Row, 'version'>> = []) {
22
+ const rows = new Map<string, Row>(seed.map((r) => [r.id, { ...r, version: 1 }]));
23
+ let next = 1000;
24
+ const http: CorpusHttp & { post: NonNullable<CorpusHttp['post']>; patch: NonNullable<CorpusHttp['patch']> } = {
25
+ async get(path, options) {
26
+ const clean = path.replace(/\/+$/, '');
27
+ if (clean === 'api/v1/entities') {
28
+ const type = String(options?.params?.type ?? '');
29
+ const all = [...rows.values()].filter((r) => r.entity_type === type);
30
+ return { results: all, next: null } as never;
31
+ }
32
+ const row = rows.get(decodeURIComponent(clean.split('/').pop() as string));
33
+ if (!row) throw Object.assign(new Error('nf'), { status: 404 });
34
+ return structuredClone(row) as never;
35
+ },
36
+ async post(path, body) {
37
+ const b = body as { entity_type: string; external_id: string; name?: string; data: Record<string, unknown> };
38
+ expect(path).toContain('upsert');
39
+ const hit = [...rows.values()].find((r) => r.entity_type === b.entity_type && r.external_id === b.external_id);
40
+ if (hit) {
41
+ hit.data = { ...hit.data, ...b.data };
42
+ if (b.name) hit.name = b.name;
43
+ hit.version += 1;
44
+ return structuredClone(hit) as never;
45
+ }
46
+ const row: Row = { id: `e${next++}`, entity_type: b.entity_type, external_id: b.external_id, name: b.name ?? '', data: { ...b.data }, version: 1 };
47
+ rows.set(row.id, row);
48
+ return structuredClone(row) as never;
49
+ },
50
+ async patch(path, body) {
51
+ const row = rows.get(decodeURIComponent(path.replace(/\/+$/, '').split('/').pop() as string)) as Row;
52
+ row.data = (body as { data: Record<string, unknown> }).data;
53
+ row.version += 1;
54
+ return structuredClone(row) as never;
55
+ },
56
+ };
57
+ return { rows, http };
58
+ }
59
+
60
+ const item = (id: string, data: Record<string, unknown> = {}) => ({
61
+ id, entity_type: 'commitment', external_id: `commit:${id}`, name: String(data.title ?? id),
62
+ data: { title: `Item ${id}`, status: 'open', mentions: [{ document_id: 'note1', quote: 'q' }], ...data },
63
+ });
64
+
65
+ const held = (id: string, kind: 'team' | 'personal_space', extra: Record<string, unknown> = {}) =>
66
+ item(id, {
67
+ sync_state: kind === 'team' ? 'needs_team' : 'needs_private_space',
68
+ open_question_kind: kind,
69
+ open_question: kind === 'team' ? 'Which team is this for?' : 'Which private Linear team should hold your personal to-dos?',
70
+ ...extra,
71
+ });
72
+
73
+ const fields = (over: Partial<ItemFields>): ItemFields => ({
74
+ due: unknownGuess('x'), project: unknownGuess('x'), owner: unknownGuess('x'),
75
+ priority: unknownGuess('x'), estimate: unknownGuess('x'), ...over,
76
+ });
77
+
78
+ const voiceNote = (records: unknown[]) => ({
79
+ id: 'note1', entity_type: 'source_document', external_id: 'voice:n1', name: 'Voice note',
80
+ data: { source: 'voice', title: 'Voice note', voice_items: JSON.stringify(records) },
81
+ });
82
+
83
+ const deps = (t: ReturnType<typeof tenant>, now = Date.parse('2026-11-06T12:00:00Z')) =>
84
+ ({ http: t.http, scope: SCOPE, ownerSub: ME, now: () => now });
85
+
86
+ describe('syncOpenQuestions: ingest', () => {
87
+ it('turns held items into team and private-space questions', async () => {
88
+ const t = tenant([held('a', 'team'), held('b', 'personal_space'), item('c')]);
89
+ await syncOpenQuestions(deps(t));
90
+ const open = await listOpenQuestions(deps(t));
91
+ expect(open.map((q) => [q.itemId, q.kind, q.status])).toEqual([
92
+ ['a', 'team', 'open'], ['b', 'private_space', 'open'],
93
+ ]);
94
+ expect(open[0].question).toBe('Which team is this for?');
95
+ });
96
+
97
+ it('is deduped by (item, kind): syncing twice leaves one question and keeps its age', async () => {
98
+ const t = tenant([held('a', 'team')]);
99
+ await syncOpenQuestions(deps(t, Date.parse('2026-11-06T10:00:00Z')));
100
+ await syncOpenQuestions(deps(t, Date.parse('2026-11-06T12:00:00Z')));
101
+ const open = await listOpenQuestions(deps(t));
102
+ expect(open).toHaveLength(1);
103
+ expect(open[0].createdAt).toBe('2026-11-06T10:00:00.000Z');
104
+ });
105
+
106
+ it('reads the voice note questions: due, project and owner, with the assumed value', async () => {
107
+ const t = tenant([
108
+ item('d', { title: 'Call the vet', due_at: '2026-11-06', external_focus_id: 'p1', owner_name: 'Sam' }),
109
+ voiceNote([{
110
+ section: 's', title: 'Call the vet', fields: fields({
111
+ due: guessOf('2026-11-06', 0.5, 'assumed', 'said Friday on a Friday', {
112
+ question: 'Did you mean today or next Friday?',
113
+ candidates: [{ value: '2026-11-06', confidence: 0.5, reason: 'today' }, { value: '2026-11-13', confidence: 0.45, reason: 'next week' }],
114
+ }),
115
+ project: guessOf('p1', 0.4, 'assumed', 'maybe home', { question: 'Which project?' }),
116
+ owner: guessOf('Sam', 0.4, 'assumed', 'a Sam', { question: 'Who owns this?' }),
117
+ }),
118
+ }]),
119
+ ]);
120
+ await syncOpenQuestions(deps(t));
121
+ const open = await listOpenQuestions(deps(t));
122
+ expect(new Set(open.map((q) => q.kind))).toEqual(new Set(['due_date', 'project', 'ownership']));
123
+ const due = open.find((q) => q.kind === 'due_date')!;
124
+ expect(due.assumed).toMatchObject({ value: '2026-11-06', confidence: 0.5 });
125
+ expect(due.candidates.map((c) => c.value)).toEqual(['2026-11-06', '2026-11-13']);
126
+ });
127
+
128
+ it('ranks what blocks the sync first, then low-confidence guesses', async () => {
129
+ const t = tenant([
130
+ held('team', 'team'),
131
+ item('due', { title: 'Pay rent', due_at: '2026-11-06' }),
132
+ voiceNote([{ section: 's', title: 'Pay rent', fields: fields({ due: guessOf('2026-11-06', 0.5, 'assumed', 'r', { question: 'When?' }) }) }]),
133
+ ]);
134
+ await syncOpenQuestions(deps(t));
135
+ const open = await listOpenQuestions(deps(t));
136
+ expect(open.map((q) => q.kind)).toEqual(['team', 'due_date']);
137
+ expect(open[0].score).toBeGreaterThan(open[1].score);
138
+ });
139
+
140
+ it('resolves a question when the item moves on, and expires it when the item is gone or closed', async () => {
141
+ const t = tenant([held('a', 'team'), held('b', 'team'), held('c', 'team')]);
142
+ await syncOpenQuestions(deps(t));
143
+ // a: the engine placed it (question cleared). b: closed. c: deleted.
144
+ t.rows.get('a')!.data = { ...t.rows.get('a')!.data, open_question_kind: '', open_question: '', sync_state: 'synced' };
145
+ t.rows.get('b')!.data.status = 'done';
146
+ t.rows.delete('c');
147
+ await syncOpenQuestions(deps(t));
148
+ expect(await listOpenQuestions(deps(t))).toEqual([]);
149
+ const all = await listOpenQuestions(deps(t), { status: 'all' });
150
+ expect(Object.fromEntries(all.map((q) => [q.itemId, q.status]))).toEqual({ a: 'resolved', b: 'expired', c: 'expired' });
151
+ });
152
+
153
+ it('resolves a voice-note question once someone changed the field it was about', async () => {
154
+ const t = tenant([
155
+ item('d', { title: 'Call the vet', due_at: '2026-11-06' }),
156
+ voiceNote([{ section: 's', title: 'Call the vet', fields: fields({ due: guessOf('2026-11-06', 0.5, 'assumed', 'r', { question: 'When?' }) }) }]),
157
+ ]);
158
+ await syncOpenQuestions(deps(t));
159
+ t.rows.get('d')!.data.due_at = '2026-11-13';
160
+ await syncOpenQuestions(deps(t));
161
+ expect(await listOpenQuestions(deps(t))).toEqual([]);
162
+ // and it is not asked again on the next pass
163
+ await syncOpenQuestions(deps(t));
164
+ expect(await listOpenQuestions(deps(t))).toEqual([]);
165
+ });
166
+
167
+ it('keeps one queue per person', async () => {
168
+ const t = tenant([held('a', 'team')]);
169
+ await syncOpenQuestions(deps(t));
170
+ await syncOpenQuestions({ ...deps(t), ownerSub: 'someone-else' });
171
+ expect(await listOpenQuestions(deps(t))).toHaveLength(1);
172
+ expect(await listOpenQuestions({ ...deps(t), ownerSub: 'someone-else' })).toHaveLength(1);
173
+ expect([...t.rows.values()].filter((r) => r.entity_type === 'open_question')).toHaveLength(2);
174
+ });
175
+ });
176
+
177
+ describe('answerQuestion', () => {
178
+ function setup(rowsIn: Parameters<typeof tenant>[0]) {
179
+ const t = tenant(rowsIn);
180
+ const api = createPlanningApi({ http: t.http, scope: SCOPE, supportedFilters: [], resolveParticipants: false } as never);
181
+ const seam = commitmentEditSeam({ api, http: t.http, scope: SCOPE });
182
+ const d = {
183
+ ...deps(t), seam,
184
+ patchItem: vi.fn(async (id: string, wire: Record<string, unknown>) => {
185
+ const row = t.rows.get(id)!;
186
+ row.data = { ...row.data, ...wire };
187
+ }),
188
+ setPersonalContainer: vi.fn(async () => undefined),
189
+ fileItem: vi.fn(async () => undefined),
190
+ };
191
+ return { t, d };
192
+ }
193
+
194
+ it('team: sets the container, queues the push, clears the question, resolves it', async () => {
195
+ const { t, d } = setup([held('a', 'team')]);
196
+ await syncOpenQuestions(d);
197
+ const [q] = await listOpenQuestions(d);
198
+ const result = await answerQuestion(d, q.id, { value: 'team-eng' });
199
+ expect(result.status).toBe('resolved');
200
+ expect(d.patchItem).toHaveBeenCalledWith('a', expect.objectContaining({
201
+ external_container_id: 'team-eng', open_question_kind: '', open_question: '', sync_state: 'pending',
202
+ }));
203
+ expect(t.rows.get('a')!.data.external_container_id).toBe('team-eng');
204
+ expect(await listOpenQuestions(d)).toEqual([]);
205
+ });
206
+
207
+ it('private space: saves the personal container once and releases every held personal item', async () => {
208
+ const { d } = setup([held('a', 'personal_space'), held('b', 'personal_space')]);
209
+ await syncOpenQuestions(d);
210
+ const [q] = await listOpenQuestions(d);
211
+ await answerQuestion(d, q.id, { value: 'team-mine' });
212
+ expect(d.setPersonalContainer).toHaveBeenCalledTimes(1);
213
+ expect(d.setPersonalContainer).toHaveBeenCalledWith('team-mine');
214
+ expect(d.patchItem).toHaveBeenCalledTimes(2);
215
+ expect(await listOpenQuestions(d)).toEqual([]);
216
+ });
217
+
218
+ it('due date: goes through the item edit seam (stamped, so it syncs)', async () => {
219
+ const { t, d } = setup([
220
+ item('d', { title: 'Call the vet', due_at: '2026-11-06' }),
221
+ voiceNote([{ section: 's', title: 'Call the vet', fields: fields({ due: guessOf('2026-11-06', 0.5, 'assumed', 'r', { question: 'When?' }) }) }]),
222
+ ]);
223
+ await syncOpenQuestions(d);
224
+ const [q] = await listOpenQuestions(d);
225
+ await answerQuestion(d, q.id, { value: '2026-11-13' });
226
+ const data = t.rows.get('d')!.data;
227
+ expect(String(data.due_at)).toContain('2026-11-13');
228
+ expect((data.field_edited_at as Record<string, string>).due_at).toBeTruthy();
229
+ expect(d.patchItem).not.toHaveBeenCalled();
230
+ expect(await listOpenQuestions(d)).toEqual([]);
231
+ });
232
+
233
+ it('project: files the item; ownership: patches the owner', async () => {
234
+ const { d } = setup([
235
+ item('d', { title: 'Call the vet', external_focus_id: 'p1', owner_name: 'Sam' }),
236
+ voiceNote([{ section: 's', title: 'Call the vet', fields: fields({
237
+ project: guessOf('p1', 0.4, 'assumed', 'r', { question: 'Which project?' }),
238
+ owner: guessOf('Sam', 0.4, 'assumed', 'r', { question: 'Who?' }),
239
+ }) }]),
240
+ ]);
241
+ await syncOpenQuestions(d);
242
+ const open = await listOpenQuestions(d);
243
+ await answerQuestion(d, open.find((q) => q.kind === 'project')!.id, { value: 'focus-9' });
244
+ await answerQuestion(d, open.find((q) => q.kind === 'ownership')!.id, { value: 'sub-7', label: 'Sam Lee' });
245
+ expect(d.fileItem).toHaveBeenCalledWith('d', 'focus-9');
246
+ expect(d.patchItem).toHaveBeenCalledWith('d', expect.objectContaining({ owner_sub: 'sub-7', owner_name: 'Sam Lee' }));
247
+ });
248
+
249
+ it('refuses an empty answer, an unknown question and someone else\'s question', async () => {
250
+ const { d } = setup([held('a', 'team')]);
251
+ await syncOpenQuestions(d);
252
+ const [q] = await listOpenQuestions(d);
253
+ await expect(answerQuestion(d, q.id, { value: ' ' })).rejects.toThrow(/answer/i);
254
+ await expect(answerQuestion(d, 'nope', { value: 'x' })).rejects.toThrow(/not found/i);
255
+ await expect(answerQuestion({ ...d, ownerSub: 'other' }, q.id, { value: 'x' })).rejects.toThrow(/not found/i);
256
+ expect(d.patchItem).not.toHaveBeenCalled();
257
+ });
258
+
259
+ it('answering twice does not edit twice', async () => {
260
+ const { d } = setup([held('a', 'team')]);
261
+ await syncOpenQuestions(d);
262
+ const [q] = await listOpenQuestions(d);
263
+ await answerQuestion(d, q.id, { value: 'team-eng' });
264
+ const again = await answerQuestion(d, q.id, { value: 'team-other' });
265
+ expect(again.status).toBe('resolved');
266
+ expect(d.patchItem).toHaveBeenCalledTimes(1);
267
+ });
268
+ });
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Clicking a to-do opens THAT to-do (not the Library): a detail view with the
3
+ * item's own fields, its tracker link, its source meetings, and the actions.
4
+ */
5
+ import { describe, expect, it, vi } from 'vitest';
6
+ import { render, screen, waitFor, fireEvent } from '@testing-library/react';
7
+
8
+ import { TaskDetailPage } from '../components/pages/TaskDetailPage';
9
+ import { toCommitment, type TenantEntity } from '../corpus/entities';
10
+ import type { Commitment, CommitmentApi } from '../corpus/types';
11
+
12
+ const make = (id: string, data: Record<string, unknown> = {}): Commitment =>
13
+ toCommitment({
14
+ id, external_id: `commit:${id}`, name: id, entity_type: 'commitment', version: 1,
15
+ data: { title: `Task ${id}`, status: 'open', subtype: 'action', mentions: [], ...data },
16
+ } as unknown as TenantEntity, { orgId: 'o' });
17
+
18
+ const scope = { orgId: 'o' } as never;
19
+
20
+ function apiWith(items: Commitment[]): CommitmentApi & { updateCommitment: ReturnType<typeof vi.fn> } {
21
+ return {
22
+ listCommitments: vi.fn(async (q: { page?: number } = {}) => ({
23
+ results: (q.page ?? 1) === 1 ? items : [], count: items.length,
24
+ })) as never,
25
+ updateCommitment: vi.fn(async (item: Commitment, patch: object) => ({ ...item, ...patch })) as never,
26
+ };
27
+ }
28
+
29
+ describe('TaskDetailPage', () => {
30
+ it('shows the requested item, even with no source meeting', async () => {
31
+ const api = apiWith([make('a'), make('b', { detail: 'Bring the signed copy', owner_name: 'Megan' })]);
32
+ render(<TaskDetailPage api={api} scope={scope} itemId="commit:b" />);
33
+ expect(await screen.findByRole('heading', { name: 'Task b' })).toBeInTheDocument();
34
+ expect(screen.getByText('Bring the signed copy')).toBeInTheDocument();
35
+ expect(screen.getByText('Megan')).toBeInTheDocument();
36
+ expect(screen.getByText(/Added by hand|No meeting recorded/)).toBeInTheDocument();
37
+ });
38
+
39
+ it('says so when the item does not exist, with a way back', async () => {
40
+ const onBack = vi.fn();
41
+ render(<TaskDetailPage api={apiWith([make('a')])} scope={scope} itemId="commit:zzz" onBack={onBack} />);
42
+ expect(await screen.findByText(/couldn.t find that to-do/i)).toBeInTheDocument();
43
+ fireEvent.click(screen.getByRole('button', { name: /back to tracker/i }));
44
+ expect(onBack).toHaveBeenCalled();
45
+ });
46
+
47
+ it('completes the item through updateCommitment and shows it done', async () => {
48
+ const api = apiWith([make('a')]);
49
+ render(<TaskDetailPage api={api} scope={scope} itemId="commit:a" />);
50
+ fireEvent.click(await screen.findByRole('button', { name: /mark done/i }));
51
+ await waitFor(() => expect(api.updateCommitment).toHaveBeenCalledWith(expect.objectContaining({ externalId: 'commit:a' }), expect.objectContaining({ status: 'done' })));
52
+ expect(await screen.findByRole('button', { name: /reopen/i })).toBeInTheDocument();
53
+ });
54
+
55
+ it('opens a source meeting through onOpenDocument', async () => {
56
+ const onOpenDocument = vi.fn();
57
+ const api = apiWith([make('a', { mentions: [{ document_id: 'doc-9', origin_key: 'k', occurred_at: '2026-11-01T00:00:00Z' }] })]);
58
+ render(<TaskDetailPage api={api} scope={scope} itemId="commit:a" onOpenDocument={onOpenDocument} />);
59
+ fireEvent.click(await screen.findByRole('button', { name: /\d+\/\d+\/\d{4}/ }));
60
+ expect(onOpenDocument).toHaveBeenCalledWith('doc-9');
61
+ });
62
+
63
+ it('shows the tracker link for a synced item', async () => {
64
+ const api = apiWith([make('a', { external_key: 'ENG-7', external_url: 'https://linear.app/x/ENG-7', sync_state: 'synced' })]);
65
+ render(<TaskDetailPage api={api} scope={scope} itemId="commit:a" trackerName="Linear" />);
66
+ expect(await screen.findByRole('link', { name: 'Open in Linear: ENG-7' })).toBeInTheDocument();
67
+ });
68
+ });
@@ -0,0 +1,96 @@
1
+ /**
2
+ * The tracker's real teams, read from the member's connected task tracker, as the
3
+ * classes of the team classifier (bd startsim-6z7vi.7).
4
+ */
5
+ import { describe, expect, it, vi } from 'vitest';
6
+
7
+ import { createPersonalSpaceSetter, createTrackerTeamLister } from '../corpus/tracker-teams';
8
+
9
+ const choice = (id: string, label: string, detail: Record<string, unknown> = {}) =>
10
+ ({ id, label, kind: 'team', selectable: true, reason: '', remediation: '', hidden_by_default: false, detail });
11
+
12
+ function api(opts: { connections?: unknown[]; teams?: unknown[][]; kinds?: Record<string, string> } = {}) {
13
+ const pages = opts.teams ?? [[choice('t1', 'Engineering', { key: 'ENG', description: 'Builds the product' }), choice('t2', 'Design', { key: 'DSN' })]];
14
+ const connections = vi.fn(async () => ({
15
+ results: (opts.connections ?? [
16
+ { id: 'c-drive', connector_key: 'dropbox', status: 'connected', config: {} },
17
+ { id: 'c-lin', connector_key: 'linear', status: 'connected', config: {} },
18
+ ]) as never[],
19
+ permissions: {} as never,
20
+ }));
21
+ const connectorCatalog = vi.fn(async () => ({
22
+ results: [
23
+ { key: 'dropbox', kind: '' },
24
+ { key: 'linear', kind: opts.kinds?.linear ?? 'task_tracker' },
25
+ ] as never[],
26
+ }));
27
+ const connectionChoices = vi.fn(async (_id: string, params?: { kind?: string; cursor?: string }) => {
28
+ const index = params?.cursor ? Number(params.cursor) : 0;
29
+ return { results: pages[index] as never[], kind: 'team', cursor: index + 1 < pages.length ? String(index + 1) : null, has_more: index + 1 < pages.length };
30
+ });
31
+ return { connections, connectorCatalog, connectionChoices };
32
+ }
33
+
34
+ describe('createTrackerTeamLister', () => {
35
+ it('lists the teams of the connected task tracker, with key and description', async () => {
36
+ const a = api();
37
+ const teams = await createTrackerTeamLister(a)();
38
+ expect(teams).toEqual([
39
+ { id: 't1', title: 'Engineering', key: 'ENG', detail: 'Builds the product' },
40
+ { id: 't2', title: 'Design', key: 'DSN', detail: '' },
41
+ ]);
42
+ expect(a.connectionChoices).toHaveBeenCalledWith('c-lin', { kind: 'team' });
43
+ });
44
+
45
+ it('reads every page of teams', async () => {
46
+ const a = api({ teams: [[choice('t1', 'A')], [choice('t2', 'B')]] });
47
+ expect((await createTrackerTeamLister(a)()).map((t) => t.id)).toEqual(['t1', 't2']);
48
+ });
49
+
50
+ it('is empty when no task tracker is connected', async () => {
51
+ const a = api({ connections: [{ id: 'c-lin', connector_key: 'linear', status: 'needs_reauth', config: {} }] });
52
+ expect(await createTrackerTeamLister(a)()).toEqual([]);
53
+ expect(a.connectionChoices).not.toHaveBeenCalled();
54
+ });
55
+
56
+ it('never offers a private team or the personal space as a team for business work', async () => {
57
+ const a = api({
58
+ connections: [{ id: 'c-lin', connector_key: 'linear', status: 'connected', config: { task_sync: { personal_container_id: 't2' } } }],
59
+ teams: [[choice('t1', 'Eng'), choice('t2', 'Mine'), choice('t3', 'Secret', { private: true })]],
60
+ });
61
+ expect((await createTrackerTeamLister(a)()).map((t) => t.id)).toEqual(['t1']);
62
+ });
63
+
64
+ it('answers once for repeated asks within the same run', async () => {
65
+ const a = api();
66
+ const list = createTrackerTeamLister(a);
67
+ await list();
68
+ await list();
69
+ expect(a.connectionChoices).toHaveBeenCalledTimes(1);
70
+ });
71
+
72
+ it('lets the failure out so the caller can decide (extraction swallows it)', async () => {
73
+ const a = api();
74
+ a.connectionChoices.mockRejectedValueOnce(new Error('central down'));
75
+ await expect(createTrackerTeamLister(a)()).rejects.toThrow('central down');
76
+ });
77
+ });
78
+
79
+ describe('createPersonalSpaceSetter', () => {
80
+ it('saves the private team on the tracker connection, keeping the rest of the task_sync block', async () => {
81
+ const a = {
82
+ ...api({ connections: [{ id: 'c-lin', connector_key: 'linear', status: 'connected', config: { task_sync: { default_container_id: 't1', assignee_id: 'u1' } } }] }),
83
+ updateConnectionConfig: vi.fn(async () => ({}) as never),
84
+ };
85
+ await createPersonalSpaceSetter(a)('t9');
86
+ expect(a.updateConnectionConfig).toHaveBeenCalledWith('c-lin', {
87
+ task_sync: { default_container_id: 't1', assignee_id: 'u1', personal_container_id: 't9' },
88
+ });
89
+ });
90
+
91
+ it('says so when no tracker is connected', async () => {
92
+ const a = { ...api({ connections: [] }), updateConnectionConfig: vi.fn() };
93
+ await expect(createPersonalSpaceSetter(a as never)('t9')).rejects.toThrow(/no task tracker/i);
94
+ expect(a.updateConnectionConfig).not.toHaveBeenCalled();
95
+ });
96
+ });
@@ -42,6 +42,7 @@ export { FolderTree, folderTrail } from './FolderTree';
42
42
  export type { FolderSource, FolderTreeProps, FolderTreeSlot } from './FolderTree';
43
43
  export * from './pages/AskPage';
44
44
  export * from './pages/TrackerPage';
45
+ export * from './pages/TaskDetailPage';
45
46
  // Task-tracker pieces (bd startsim-2nn3h): the sync settings and the link chip.
46
47
  export { TaskTrackerSettings } from './pages/task-tracker/TaskTrackerSettings';
47
48
  export type { TaskTrackerSettingsApi, TaskTrackerSettingsProps } from './pages/task-tracker/TaskTrackerSettings';