@startsimpli/integrations 0.2.216 → 0.2.218

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 (49) hide show
  1. package/package.json +5 -5
  2. package/src/__tests__/briefing-timezone-memory.test.ts +56 -0
  3. package/src/__tests__/corpus-storage.test.ts +6 -0
  4. package/src/__tests__/corpus-tracker.test.tsx +37 -0
  5. package/src/__tests__/engine-near-date.test.ts +136 -0
  6. package/src/__tests__/fleet-page.test.tsx +24 -0
  7. package/src/__tests__/near-date-ui.test.tsx +74 -0
  8. package/src/__tests__/relay-cli.test.ts +1 -1
  9. package/src/__tests__/share-default-row.test.tsx +44 -0
  10. package/src/__tests__/shared-with.test.tsx +87 -0
  11. package/src/__tests__/sync-health.test.ts +70 -0
  12. package/src/__tests__/task-detail.test.tsx +1 -1
  13. package/src/api/_fetch.ts +1 -1
  14. package/src/api/connections.ts +14 -0
  15. package/src/components/DocumentDetail.tsx +3 -0
  16. package/src/components/SharedWith.tsx +140 -0
  17. package/src/components/index.ts +1 -0
  18. package/src/components/pages/FleetPage.tsx +16 -4
  19. package/src/components/pages/SyncHealthCard.tsx +42 -0
  20. package/src/components/pages/TaskDetailPage.tsx +4 -2
  21. package/src/components/pages/TrackerPage.tsx +27 -7
  22. package/src/components/pages/connections/ConnectionCard.tsx +5 -0
  23. package/src/components/pages/connections/ShareDefaultRow.tsx +91 -0
  24. package/src/components/pages/connections/bound-api.ts +4 -1
  25. package/src/components/pages/tracker/PossiblyDone.tsx +28 -2
  26. package/src/components/pages/tracker/Suggestion.tsx +15 -11
  27. package/src/components/pages/types.ts +11 -0
  28. package/src/components/table/todo-model.ts +3 -0
  29. package/src/corpus/briefing/generate-weekly.ts +2 -1
  30. package/src/corpus/briefing/generate.ts +2 -1
  31. package/src/corpus/briefing/zone.ts +24 -0
  32. package/src/corpus/client.ts +6 -0
  33. package/src/corpus/commitments.ts +48 -3
  34. package/src/corpus/converse/fleet-view.ts +1 -1
  35. package/src/corpus/converse/fleet.ts +1 -1
  36. package/src/corpus/converse/index.ts +2 -0
  37. package/src/corpus/converse/respond.ts +2 -1
  38. package/src/corpus/converse/sync-health.ts +96 -0
  39. package/src/corpus/engine/apply.ts +10 -3
  40. package/src/corpus/engine/decide.ts +3 -2
  41. package/src/corpus/engine/near-match.ts +71 -0
  42. package/src/corpus/engine/proposed-due.ts +44 -0
  43. package/src/corpus/engine/suggestion.ts +5 -0
  44. package/src/corpus/engine/types.ts +2 -0
  45. package/src/corpus/entities.ts +13 -0
  46. package/src/corpus/extract.ts +10 -4
  47. package/src/corpus/index.ts +2 -0
  48. package/src/corpus/sharing.ts +135 -0
  49. package/src/corpus/types.ts +21 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startsimpli/integrations",
3
- "version": "0.2.216",
3
+ "version": "0.2.218",
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/ui": "^0.4.207",
54
- "@startsimpli/auth": "^0.4.62",
55
- "@startsimpli/utils": "^0.4.21"
53
+ "@startsimpli/ui": "^0.4.208",
54
+ "@startsimpli/utils": "^0.4.21",
55
+ "@startsimpli/auth": "^0.4.62"
56
56
  },
57
57
  "peerDependenciesMeta": {
58
58
  "react": {
@@ -99,7 +99,7 @@
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.207",
102
+ "@startsimpli/ui": "0.4.208",
103
103
  "@startsimpli/ui-native": "0.1.15",
104
104
  "@startsimpli/auth": "0.4.62",
105
105
  "@startsimpli/utils": "0.4.21"
@@ -0,0 +1,56 @@
1
+ /**
2
+ * A caller that sends no timeZone must not move the user's briefing to the UTC day.
3
+ * The zone the owner's last briefing was made in is remembered and reused.
4
+ */
5
+ import { describe, expect, it, vi } from 'vitest';
6
+ import { generateBriefing, type BriefingDeps } from '../corpus/briefing';
7
+
8
+ function tenant(shared = new Map<string, any>()) {
9
+ let seq = 0;
10
+ return {
11
+ rows: shared,
12
+ http: {
13
+ get: vi.fn(async (_p: string, o?: { params?: Record<string, unknown> }) => {
14
+ const ext = String(o?.params?.external_id__in ?? '');
15
+ return { results: [...shared.values()].filter((r) => r.external_id === ext) };
16
+ }),
17
+ post: vi.fn(async (_p: string, b: any) => {
18
+ const row = { id: ++seq, owner_sub: 'me', external_id: b.external_id, name: b.name, data: { ...(shared.get(b.external_id)?.data ?? {}), ...b.data } };
19
+ shared.set(b.external_id, row);
20
+ return row;
21
+ }),
22
+ },
23
+ };
24
+ }
25
+
26
+ const depsFor = (t: ReturnType<typeof tenant>, now: string, timeZone?: string): BriefingDeps => ({
27
+ http: t.http as never, orgId: 'org', ownerSub: 'me',
28
+ loadItems: async () => [{ id: 'a', title: 'Do a', status: 'open', ownerSub: 'me', dueAt: '2026-11-05', priority: 2 }],
29
+ synthesize: async () => ({ audio: new Uint8Array([1]), mimeType: 'audio/mpeg', model: 'm', provider: 'p', usage: {} }),
30
+ scriptLlm: null,
31
+ audio: { put: async () => 's3://b/k.mp3', url: async () => '/a' },
32
+ now: () => Date.parse(now),
33
+ ...(timeZone ? { timeZone } : {}),
34
+ });
35
+
36
+ describe('a briefing request with no timeZone', () => {
37
+ it('test_reuses_the_zone_of_the_owners_last_briefing_so_the_day_does_not_flip_to_UTC', async () => {
38
+ const t = tenant();
39
+ // Yesterday, the web sent its zone: Nov 4 in New York.
40
+ await generateBriefing(depsFor(t, '2026-11-04T15:00:00Z', 'America/New_York'), {});
41
+ // 22:00 New York on Nov 5 is already Nov 6 in UTC; this caller sends no zone.
42
+ const out = await generateBriefing(depsFor(t, '2026-11-06T03:00:00Z'), {});
43
+ expect(out.context.localDate).toBe('2026-11-05');
44
+ expect(out.context.timeZone).toBe('America/New_York');
45
+ });
46
+ it('test_falls_back_to_UTC_only_when_the_owner_has_no_history', async () => {
47
+ const out = await generateBriefing(depsFor(tenant(), '2026-11-06T03:00:00Z'), {});
48
+ expect(out.context.timeZone).toBe('UTC');
49
+ });
50
+ it('test_an_explicit_zone_always_wins', async () => {
51
+ const t = tenant();
52
+ await generateBriefing(depsFor(t, '2026-11-04T15:00:00Z', 'America/New_York'), {});
53
+ const out = await generateBriefing(depsFor(t, '2026-11-06T03:00:00Z', 'Asia/Tokyo'), {});
54
+ expect(out.context.timeZone).toBe('Asia/Tokyo');
55
+ });
56
+ });
@@ -354,6 +354,12 @@ describe('listCommitments speaks the tenant data API’s own filter language', (
354
354
  });
355
355
  });
356
356
 
357
+ it('filters by owner member as a server parameter on the declared attr.owner_sub', async () => {
358
+ const { api, seen } = client([]);
359
+ await api.listCommitments({ ownerSub: 'u-jade' });
360
+ expect(seen[0].params['attr.owner_sub']).toBe('u-jade');
361
+ });
362
+
357
363
  it('caps a text filter at the length the server documents', async () => {
358
364
  const { api, seen } = client([]);
359
365
  await api.listCommitments({ owner: 'x'.repeat(900), search: 'y'.repeat(900) });
@@ -609,6 +609,18 @@ describe('TrackerPage — adding a to-do', () => {
609
609
  await vi.waitFor(() => expect(calls).toBeGreaterThan(1));
610
610
  });
611
611
 
612
+ it('opens the new to-do straight away when the host can open items', async () => {
613
+ const created = commitment({ externalId: 'commit:new1', title: 'Call the notary' });
614
+ const createCommitment = vi.fn(async () => created);
615
+ const onOpenItem = vi.fn();
616
+ const api = { ...makeApi(), createCommitment } as CommitmentTrackerApi;
617
+ render(<TrackerPage api={api} scope={SCOPE} onOpenItem={onOpenItem} />);
618
+ await screen.findByText('Chase the inventor for comments on 2148');
619
+ await userEvent.click(screen.getByRole('button', { name: /Add to-do/ }));
620
+ await userEvent.type(screen.getByRole('textbox', { name: 'New to-do title' }), 'Call the notary{Enter}');
621
+ await vi.waitFor(() => expect(onOpenItem).toHaveBeenCalledWith(expect.objectContaining({ externalId: 'commit:new1' })));
622
+ });
623
+
612
624
  it('offers no quick-add when the api cannot create', async () => {
613
625
  render(<TrackerPage api={makeApi()} scope={SCOPE} />);
614
626
  await screen.findByText('Chase the inventor for comments on 2148');
@@ -687,3 +699,28 @@ describe('TrackerPage with the scheduled pass (bd startsim-vrmx5)', () => {
687
699
  expect(screen.queryByRole('button', { name: /Pull from meetings/i })).not.toBeInTheDocument();
688
700
  });
689
701
  });
702
+
703
+ describe('TrackerPage — Owner filter', () => {
704
+ const MEMBERS = [
705
+ { sub: 'u-jade', email: 'jade@x.test', name: 'Jade' },
706
+ { sub: 'u-john', email: 'john@x.test', name: 'John' },
707
+ ];
708
+ const withMembers = (queries: CommitmentQuery[]) =>
709
+ ({ ...makeApi({ onQuery: (q) => queries.push(q) }), listMembers: async () => MEMBERS }) as CommitmentTrackerApi;
710
+
711
+ it('is a third dropdown, listing only the roster the server returns, and sends a server filter', async () => {
712
+ const queries: CommitmentQuery[] = [];
713
+ render(<TrackerPage api={withMembers(queries)} scope={SCOPE} now={NOW} />);
714
+ const owner = await screen.findByRole('combobox', { name: 'Owner' });
715
+ expect(within(owner).getAllByRole('option').map((o) => o.textContent)).toEqual(['All owners', 'Jade', 'John']);
716
+ await userEvent.selectOptions(owner, 'u-jade');
717
+ await vi.waitFor(() => expect(queries.at(-1)?.ownerSub).toBe('u-jade'));
718
+ expect(queries.at(-1)?.page).toBe(1);
719
+ });
720
+
721
+ it('is absent when the api has no roster', async () => {
722
+ render(<TrackerPage api={makeApi()} scope={SCOPE} now={NOW} />);
723
+ await screen.findByText('Chase the inventor for comments on 2148');
724
+ expect(screen.queryByRole('combobox', { name: 'Owner' })).toBeNull();
725
+ });
726
+ });
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Near matches and stated dates go through the decision policy (bd startsim-81mzy, Todo: ENG-151).
3
+ */
4
+ import { describe, expect, it } from 'vitest';
5
+
6
+ import { commitmentIdentity, mergeDrafts, reconcile } from '../corpus/commitments';
7
+ import { applyPolicy } from '../corpus/engine/apply';
8
+ import { acceptPatch, rejectPatch } from '../components/pages/tracker/Suggestion';
9
+ import { FIXTURE_ORG, FIXTURE_TRACKED_DOCUMENTS } from '../corpus/fixtures';
10
+ import type { Commitment, CommitmentDraft, SourceDocument } from '../corpus/types';
11
+
12
+ const OWNER = 'usr_dana';
13
+ const SCOPE = { orgId: FIXTURE_ORG, ownerSub: OWNER };
14
+ const doc = (id: string): SourceDocument => ({ ...FIXTURE_TRACKED_DOCUMENTS[0], id, scope: SCOPE, source: 'granola' } as SourceDocument);
15
+ const DOCS = [doc('d1'), doc('d2'), doc('d3')];
16
+ const ENGINE = { ownerSub: OWNER };
17
+
18
+ const draft = (documentId: string, title: string, extra: Partial<CommitmentDraft> = {}): CommitmentDraft => ({
19
+ documentId, originKey: `${documentId}:${title}`, subtype: 'action', title, detail: '', status: 'open',
20
+ subject: 'matter 2040-01', quote: title, extractor: 'model', ...extra,
21
+ });
22
+
23
+ const run = (existing: Commitment[], drafts: CommitmentDraft[], engine: typeof ENGINE | null = ENGINE) =>
24
+ reconcile(existing, mergeDrafts(drafts), { scope: SCOPE, documents: DOCS, ...(engine ? { engine } : {}) });
25
+
26
+ const first = () => run([], [draft('d1', 'Set a drafting deadline for matter 2040-01')]).commitments.map((c) => ({ ...c, scope: SCOPE }));
27
+
28
+ describe('a near match is proposed, never merged silently', () => {
29
+ const NEAR = 'Deadline needs to be set on 2040-01';
30
+
31
+ it('an identical statement still merges by itself', () => {
32
+ const existing = first();
33
+ const again = run(existing, [draft('d2', 'Set a drafting deadline for matter 2040-01')]);
34
+ expect(again.created).toBe(0);
35
+ expect(again.merged).toBe(1);
36
+ });
37
+
38
+ it('wording that is only near becomes its own row, with the match reported', () => {
39
+ const existing = first();
40
+ expect(commitmentIdentity({ title: NEAR, subject: 'matter 2040-01' }).dedupeKey).not.toBe(existing[0].dedupeKey);
41
+ const result = run(existing, [draft('d2', NEAR)]);
42
+ expect(result.created).toBe(1);
43
+ expect(result.merged).toBe(0);
44
+ const row = result.commitments.find((c) => c.externalId !== existing[0].externalId)!;
45
+ expect(result.matches[row.externalId]).toMatchObject({ itemId: existing[0].externalId, strength: 'anchored', title: existing[0].title });
46
+ expect(result.commitments.find((c) => c.externalId === existing[0].externalId)!.mentions).toHaveLength(1);
47
+ });
48
+
49
+ it('without the engine the old merge is untouched', () => {
50
+ const result = run(first(), [draft('d2', NEAR)], null);
51
+ expect(result.created).toBe(0);
52
+ expect(result.merged).toBe(1);
53
+ });
54
+
55
+ it('the policy turns it into a suggestion that names the item and carries its id', () => {
56
+ const existing = first();
57
+ const result = run(existing, [draft('d2', NEAR)]);
58
+ const fresh = result.commitments.filter((c) => c.externalId !== existing[0].externalId);
59
+ const out = applyPolicy(fresh, { scope: { ownerSub: OWNER, ownerNames: [] }, documents: DOCS, matches: result.matches });
60
+ expect(out.kept[0].status).toBe('suggested');
61
+ expect(out.kept[0].suggestion).toMatchObject({ rule: 'L-NEAR', mode: 'propose', targetId: existing[0].externalId });
62
+ expect(out.kept[0].suggestion!.reason).toContain(existing[0].title);
63
+ });
64
+
65
+ it('never proposes a merge onto another person’s item', () => {
66
+ const theirs = first().map((c) => ({ ...c, scope: { ...SCOPE, ownerSub: 'usr_other' } }));
67
+ const result = run(theirs, [draft('d2', NEAR)]);
68
+ expect(result.matches).toEqual({});
69
+ });
70
+
71
+ it('a second run after the suggestion exists is a no-op, and so is one after "keep separate"', () => {
72
+ const existing = first();
73
+ const one = run(existing, [draft('d2', NEAR)]);
74
+ const suggested = applyPolicy(one.commitments.filter((c) => c.externalId !== existing[0].externalId),
75
+ { scope: { ownerSub: OWNER, ownerNames: [] }, documents: DOCS, matches: one.matches }).kept;
76
+ const stored = [...existing, ...suggested.map((c) => ({ ...c, scope: SCOPE }))];
77
+ const two = run(stored, [draft('d2', NEAR)]);
78
+ expect(two.created).toBe(0);
79
+ expect(two.touched).toEqual([]);
80
+ const separate = stored.map((c) => (c.suggestion ? { ...c, ...rejectPatch(c) } as Commitment : c));
81
+ expect(separate.find((c) => c.suggestion)!.status).toBe('open');
82
+ const three = run(separate, [draft('d2', NEAR)]);
83
+ expect(three.created).toBe(0);
84
+ expect(three.touched).toEqual([]);
85
+ });
86
+
87
+ it('"same item" drops the duplicate and the next pass moves its quotes onto the original', () => {
88
+ const existing = first();
89
+ const one = run(existing, [draft('d2', NEAR)]);
90
+ const suggested = applyPolicy(one.commitments.filter((c) => c.externalId !== existing[0].externalId),
91
+ { scope: { ownerSub: OWNER, ownerNames: [] }, documents: DOCS, matches: one.matches }).kept;
92
+ const accepted = suggested.map((c) => ({ ...c, scope: SCOPE, ...acceptPatch(c) } as Commitment));
93
+ expect(accepted[0].status).toBe('dropped');
94
+ const next = run([...existing, ...accepted], []);
95
+ const target = next.commitments.find((c) => c.externalId === existing[0].externalId)!;
96
+ expect(target.mentions.map((m) => m.documentId).sort()).toEqual(['d1', 'd2']);
97
+ expect(next.touched).toEqual([existing[0].externalId]);
98
+ expect(run(next.commitments, []).touched).toEqual([]);
99
+ });
100
+ });
101
+
102
+ describe('a stated date is proposed, never silently set or dropped', () => {
103
+ const TITLE = 'Set a drafting deadline for matter 2040-01';
104
+ const withDue = (dueAt: string) => ({ dueAt, quote: 'due on the 12th' } as Partial<CommitmentDraft>);
105
+
106
+ it('a different date is kept on the item as a proposal; dueAt stays', () => {
107
+ const existing = first().map((c) => ({ ...c, dueAt: '2026-12-01T00:00:00.000Z' }));
108
+ const result = run(existing, [draft('d2', TITLE, withDue('2026-12-12T00:00:00.000Z'))]);
109
+ const item = result.commitments[0];
110
+ expect(item.dueAt).toBe('2026-12-01T00:00:00.000Z');
111
+ expect(item.proposedDue).toEqual([{ dueAt: '2026-12-12T00:00:00.000Z', documentId: 'd2', quote: 'due on the 12th', state: 'pending' }]);
112
+ expect(result.touched).toContain(item.externalId);
113
+ });
114
+
115
+ it('a date for an undated item is proposed too, not backfilled', () => {
116
+ const result = run(first(), [draft('d2', TITLE, withDue('2026-12-12T00:00:00.000Z'))]);
117
+ expect(result.commitments[0].dueAt).toBeFalsy();
118
+ expect(result.commitments[0].proposedDue).toHaveLength(1);
119
+ });
120
+
121
+ it('the same date, a date a person set, and a repeat of the same document are all left alone', () => {
122
+ const base = first().map((c) => ({ ...c, dueAt: '2026-12-01T00:00:00.000Z' }));
123
+ expect(run(base, [draft('d2', TITLE, withDue('2026-12-01T09:00:00.000Z'))]).commitments[0].proposedDue).toBeUndefined();
124
+ const byPerson = base.map((c) => ({ ...c, dueSetByPerson: true }));
125
+ expect(run(byPerson, [draft('d2', TITLE, withDue('2026-12-12T00:00:00.000Z'))]).commitments[0].proposedDue).toBeUndefined();
126
+ const once = run(base, [draft('d2', TITLE, withDue('2026-12-12T00:00:00.000Z'))]);
127
+ expect(run(once.commitments, [draft('d2', TITLE, withDue('2026-12-12T00:00:00.000Z'))]).touched).toEqual([]);
128
+ const declined = once.commitments.map((c) => ({ ...c, proposedDue: c.proposedDue!.map((p) => ({ ...p, state: 'dismissed' as const })) }));
129
+ expect(run(declined, [draft('d2', TITLE, withDue('2026-12-12T00:00:00.000Z'))]).touched).toEqual([]);
130
+ });
131
+
132
+ it('without the engine a stated date still backfills an undated item', () => {
133
+ const result = run(first(), [draft('d2', TITLE, withDue('2026-12-12T00:00:00.000Z'))], null);
134
+ expect(result.commitments[0].dueAt).toBe('2026-12-12T00:00:00.000Z');
135
+ });
136
+ });
@@ -55,3 +55,27 @@ describe('FleetPage', () => {
55
55
  await waitFor(() => expect(screen.getByTestId('load-error')).toBeTruthy());
56
56
  });
57
57
  });
58
+
59
+ describe('FleetPage sync health', () => {
60
+ it('shows one row per leg from the connections, with todo-sync from the snapshot', async () => {
61
+ const now = new Date().toISOString();
62
+ const load = async () => payload({ snapshot: { text: 'n', updatedAt: now, view, todoSync: { at: now, ok: false, closed: 0, error: 'relay login expired' } } });
63
+ const loadConnections = async () => ({ results: [{ id: 'lin', connector_name: 'Linear', sync: { state: 'ok' }, sync_status: { status: 'ok', last_pull_at: now, last_push_at: now, pending_count: 3, out_of_sync: true } }] });
64
+ render(<FleetPage load={load} loadConnections={loadConnections} />);
65
+ await waitFor(() => expect(screen.getByTestId('sync-leg-lin:push')).toBeTruthy());
66
+ expect(screen.getByTestId('sync-leg-lin:push').textContent).toContain('3 waiting to send');
67
+ expect(screen.getByTestId('sync-leg-lin:push').getAttribute('data-state')).toBe('behind');
68
+ expect(screen.getByTestId('sync-leg-todo-sync').textContent).toContain('relay login expired');
69
+ });
70
+
71
+ it('says so when the connections cannot be read', async () => {
72
+ render(<FleetPage load={async () => payload()} loadConnections={async () => { throw new Error('401'); }} />);
73
+ await waitFor(() => expect(screen.getByTestId('sync-health-error').textContent).toContain('401'));
74
+ });
75
+
76
+ it('shows no sync card when the mount does not pass connections', async () => {
77
+ render(<FleetPage load={async () => payload()} />);
78
+ await waitFor(() => expect(screen.getByTestId('fleet-relay')).toBeTruthy());
79
+ expect(screen.queryByTestId('fleet-sync-health')).toBeNull();
80
+ });
81
+ });
@@ -0,0 +1,74 @@
1
+ /** "Same item?" and "New date" in the existing notes, no new panel (bd startsim-81mzy). */
2
+ import * as React from 'react';
3
+ import { render, screen, waitFor, within } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+ import { describe, expect, it, vi } from 'vitest';
6
+
7
+ import { TrackerPage } from '../components/pages/TrackerPage';
8
+ import type { Commitment, CommitmentTrackerApi } from '../corpus/types';
9
+
10
+ const NOW = Date.parse('2026-11-24T12:00:00Z');
11
+ const SCOPE = { orgId: 'tandem' };
12
+ const item = (externalId: string, title: string, extra: Partial<Commitment> = {}): Commitment => ({
13
+ id: externalId, externalId, dedupeKey: externalId, subtype: 'action', title, detail: '', status: 'open',
14
+ subjectKey: '', actionKey: '', mentions: [], firstSeenAt: '2026-11-20T00:00:00Z', lastSeenAt: '2026-11-20T00:00:00Z',
15
+ extractorVersion: 'x', source: 'granola', sourceLabel: 'Granola', scope: SCOPE, ...extra,
16
+ });
17
+ function api(rows: Commitment[]) {
18
+ const updateCommitment = vi.fn(async (it: Commitment, patch: object) => {
19
+ const i = rows.findIndex((r) => r.externalId === it.externalId);
20
+ rows[i] = { ...rows[i], ...patch } as Commitment;
21
+ return rows[i];
22
+ });
23
+ return {
24
+ updateCommitment,
25
+ api: { listCommitments: vi.fn(async () => ({ count: rows.length, next: null, previous: null, results: [...rows], appliedFilters: [] })), updateCommitment } as unknown as CommitmentTrackerApi,
26
+ };
27
+ }
28
+
29
+ describe('near-match suggestion', () => {
30
+ const near = item('commit:n', 'Deadline needs to be set', {
31
+ status: 'suggested',
32
+ suggestion: { rule: 'L-NEAR', mode: 'propose', confidence: 0.8, reason: 'Looks like “Set a drafting deadline”: same subject, nearly the same wording.', documentId: 'm2', quote: 'deadline', targetId: 'commit:o' },
33
+ });
34
+
35
+ it('"Same item" drops the duplicate as accepted', async () => {
36
+ const { api: a, updateCommitment } = api([near, item('commit:o', 'Set a drafting deadline')]);
37
+ render(<TrackerPage api={a} scope={SCOPE} now={NOW} />);
38
+ const note = await screen.findByTestId('suggestion');
39
+ expect(note).toHaveTextContent(/Looks like “Set a drafting deadline”/);
40
+ await userEvent.click(within(note).getByRole('button', { name: 'Same item' }));
41
+ await waitFor(() => expect(updateCommitment).toHaveBeenCalledWith(expect.objectContaining({ externalId: 'commit:n' }),
42
+ expect.objectContaining({ status: 'dropped', suggestion: expect.objectContaining({ outcome: 'accepted', targetId: 'commit:o' }) })));
43
+ });
44
+
45
+ it('"Keep separate" opens it as its own item and records the rejection', async () => {
46
+ const { api: a, updateCommitment } = api([near, item('commit:o', 'Set a drafting deadline')]);
47
+ render(<TrackerPage api={a} scope={SCOPE} now={NOW} />);
48
+ await userEvent.click(within(await screen.findByTestId('suggestion')).getByRole('button', { name: 'Keep separate' }));
49
+ await waitFor(() => expect(updateCommitment).toHaveBeenCalledWith(expect.objectContaining({ externalId: 'commit:n' }),
50
+ expect.objectContaining({ status: 'open', suggestion: expect.objectContaining({ outcome: 'rejected' }) })));
51
+ });
52
+ });
53
+
54
+ describe('proposed date', () => {
55
+ const dated = () => item('commit:d', 'Send the deck', { dueAt: '2026-12-01T00:00:00Z', proposedDue: [{ dueAt: '2026-12-12T00:00:00Z', documentId: 'm3', quote: 'by the 12th', state: 'pending' }] });
56
+
57
+ it('Use it sets the date and settles the proposal', async () => {
58
+ const { api: a, updateCommitment } = api([dated()]);
59
+ render(<TrackerPage api={a} scope={SCOPE} now={NOW} />);
60
+ const note = await screen.findByTestId('proposed-due');
61
+ expect(note).toHaveTextContent(/New date: a later note says .*“by the 12th”/);
62
+ await userEvent.click(within(note).getByRole('button', { name: 'Use it' }));
63
+ await waitFor(() => expect(updateCommitment).toHaveBeenCalledWith(expect.anything(),
64
+ expect.objectContaining({ dueAt: '2026-12-12T00:00:00Z', proposedDue: [expect.objectContaining({ state: 'dismissed' })] })));
65
+ await waitFor(() => expect(screen.queryByTestId('proposed-due')).toBeNull());
66
+ });
67
+
68
+ it('Keep mine leaves the date and remembers the answer', async () => {
69
+ const { api: a, updateCommitment } = api([dated()]);
70
+ render(<TrackerPage api={a} scope={SCOPE} now={NOW} />);
71
+ await userEvent.click(within(await screen.findByTestId('proposed-due')).getByRole('button', { name: 'Keep mine' }));
72
+ await waitFor(() => expect(updateCommitment).toHaveBeenCalledWith(expect.anything(), { proposedDue: [expect.objectContaining({ state: 'dismissed' })] }));
73
+ });
74
+ });
@@ -32,7 +32,7 @@ describe('fleet inputs for the /fleet page', () => {
32
32
  it('reads roles.md, the loops ledger and the raw bridge listing; leaves out what is missing', async () => {
33
33
  const dir = mkdtempSync(join(tmpdir(), 'rc-'));
34
34
  writeFileSync(join(dir, 'roles.md'), '| Role | s | n |');
35
- const env = { RELAY_ROLES_FILE: join(dir, 'roles.md'), RELAY_LOOPS_FILE: join(dir, 'nope.md'), RELAY_PORTS_FILE: join(dir, 'nope2.md') };
35
+ const env = { RELAY_ROLES_FILE: join(dir, 'roles.md'), RELAY_LOOPS_FILE: join(dir, 'nope.md'), RELAY_PORTS_FILE: join(dir, 'nope2.md'), TODO_SYNC_LAST_RUN: join(dir, 'nope3.json') };
36
36
  expect(await readFleetInputs(env, '[live] `a · b · 12345678` g')).toEqual({ roles: '| Role | s | n |', sessions: '[live] `a · b · 12345678` g' });
37
37
  });
38
38
  });
@@ -0,0 +1,44 @@
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
+
6
+ import { ShareDefaultRow, parse, valueOf } from '../components/pages/connections/ShareDefaultRow';
7
+
8
+ afterEach(cleanup);
9
+ const cn = { muted: 'm', error: 'e' };
10
+ const connection = { id: 'c1', share_default: null } as never;
11
+
12
+ describe('ShareDefaultRow', () => {
13
+ it('says only me by default and offers the organisation and its teams', async () => {
14
+ const api = {
15
+ updateConnectionSharing: vi.fn(async () => ({}) as never),
16
+ shareTeams: vi.fn(async () => [{ slug: 'editorial', name: 'Editorial' }]),
17
+ };
18
+ const changed = vi.fn();
19
+ render(<ShareDefaultRow api={api} connection={connection} classNames={cn} onChanged={changed} />);
20
+ expect((screen.getByLabelText('Records are shared with') as HTMLSelectElement).value).toBe('none');
21
+ await waitFor(() => expect(screen.getByText('Editorial (team)')).toBeTruthy());
22
+ fireEvent.change(screen.getByLabelText('Records are shared with'), { target: { value: 'org' } });
23
+ await waitFor(() => expect(api.updateConnectionSharing).toHaveBeenCalledWith('c1', { kind: 'org' }));
24
+ await waitFor(() => expect(changed).toHaveBeenCalled());
25
+ });
26
+
27
+ it('turns it off with null and shows a failure', async () => {
28
+ const api = { updateConnectionSharing: vi.fn(async () => { throw new Error('tenant down'); }) };
29
+ render(<ShareDefaultRow api={api as never} connection={{ id: 'c1', share_default: { kind: 'org' } } as never} classNames={cn} onChanged={vi.fn()} />);
30
+ fireEvent.change(screen.getByLabelText('Records are shared with'), { target: { value: 'none' } });
31
+ await waitFor(() => expect(api.updateConnectionSharing).toHaveBeenCalledWith('c1', null));
32
+ expect(await screen.findByRole('alert')).toBeTruthy();
33
+ });
34
+
35
+ it('renders nothing for a client without the verb', () => {
36
+ const { container } = render(<ShareDefaultRow api={{}} connection={connection} classNames={cn} onChanged={vi.fn()} />);
37
+ expect(container.textContent).toBe('');
38
+ });
39
+
40
+ it('maps values both ways', () => {
41
+ expect(parse(valueOf({ kind: 'group', id: 'a:b' }))).toEqual({ kind: 'group', id: 'a:b' });
42
+ expect(parse(valueOf(null))).toBeNull();
43
+ });
44
+ });
@@ -0,0 +1,87 @@
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
+
6
+ import { SharedWith } from '../components/SharedWith';
7
+ import { addRecordShare, listRecordShares, listShareChoices } from '../corpus/sharing';
8
+
9
+ afterEach(cleanup);
10
+ const cn = { badge: 'b', input: 'i', muted: 'm', error: 'e' };
11
+ const choices = async () => ({
12
+ org: { id: 'acme', label: 'Everyone in my organisation' },
13
+ people: [{ id: 'u1', label: 'Ada' }, { id: 'u2', label: 'Ben' }],
14
+ teams: [{ id: 'editorial', label: 'Editorial' }],
15
+ });
16
+
17
+ describe('SharedWith', () => {
18
+ it('says "Only you" for a private record and offers org, team and people', async () => {
19
+ const api = {
20
+ listRecordShares: vi.fn(async () => ({ shares: [], canShare: true })),
21
+ listShareChoices: choices,
22
+ addRecordShare: vi.fn(async () => undefined),
23
+ removeRecordShare: vi.fn(async () => undefined),
24
+ };
25
+ render(<SharedWith api={api} documentId="d" classNames={cn} />);
26
+ expect(await screen.findByText('Only you')).toBeTruthy();
27
+ await waitFor(() => expect(screen.getByText('Editorial (team)')).toBeTruthy());
28
+ expect(screen.getByText('Everyone in my organisation')).toBeTruthy();
29
+ fireEvent.change(screen.getByLabelText('Share with'), { target: { value: 'group:editorial' } });
30
+ await waitFor(() => expect(api.addRecordShare).toHaveBeenCalledWith('d', { kind: 'group', subjectId: 'editorial', level: 'viewer' }));
31
+ });
32
+
33
+ it('shows the line without the menu when the caller may not share', async () => {
34
+ const api = {
35
+ listRecordShares: vi.fn(async () => ({
36
+ shares: [{ id: 'g1', kind: 'org' as const, subjectId: 'acme', level: 'viewer' as const }], canShare: false,
37
+ })),
38
+ listShareChoices: choices,
39
+ addRecordShare: vi.fn(), removeRecordShare: vi.fn(),
40
+ };
41
+ render(<SharedWith api={api} documentId="d" classNames={cn} />);
42
+ expect(await screen.findByText(/Everyone in my organisation/)).toBeTruthy();
43
+ expect(screen.queryByLabelText('Share with')).toBeNull();
44
+ });
45
+
46
+ it('renders nothing when the client cannot read shares', () => {
47
+ const { container } = render(<SharedWith api={{}} documentId="d" classNames={cn} />);
48
+ expect(container.textContent).toBe('');
49
+ });
50
+ });
51
+
52
+ describe('sharing client', () => {
53
+ it('reads shares and ignores a public link', async () => {
54
+ const http = { get: vi.fn(async () => ({
55
+ may_share: true,
56
+ results: [
57
+ { id: '1', subject_type: 'user', subject_id: 'u1', level: 'editor' },
58
+ { id: '2', subject_type: 'public', subject_id: '', level: 'viewer' },
59
+ ] })) };
60
+ const r = await listRecordShares(http as never, 'd');
61
+ expect(r.canShare).toBe(true);
62
+ expect(r.shares).toEqual([{ id: '1', kind: 'user', subjectId: 'u1', level: 'editor' }]);
63
+ });
64
+
65
+ it('writes a grant naming the record, the kind and the level', async () => {
66
+ const post = vi.fn(async () => ({}));
67
+ await addRecordShare({ get: vi.fn(), post } as never, 'd', { kind: 'org', subjectId: 'acme' });
68
+ expect(post).toHaveBeenCalledWith('/api/v1/grants/', { entity: 'd', subject_type: 'org', subject_id: 'acme', level: 'viewer' });
69
+ });
70
+
71
+ it('survives a failing picker list', async () => {
72
+ const http = { get: vi.fn(async (p: string) => { if (p.includes('teams')) throw new Error('x'); return p.includes('whoami') ? { org_id: 'acme' } : { results: [{ sub: 'u1', label: 'Ada' }] }; }) };
73
+ const c = await listShareChoices(http as never);
74
+ expect(c.org?.id).toBe('acme');
75
+ expect(c.people).toEqual([{ id: 'u1', label: 'Ada' }]);
76
+ expect(c.teams).toEqual([]);
77
+ });
78
+ });
79
+
80
+ describe('sharing client with a camelizing http client', () => {
81
+ it('reads mayShare and subjectType', async () => {
82
+ const http = { get: vi.fn(async () => ({ mayShare: true, results: [{ id: '1', subjectType: 'group', subjectId: 'editorial', level: 'viewer' }] })) };
83
+ const r = await listRecordShares(http as never, 'd');
84
+ expect(r.canShare).toBe(true);
85
+ expect(r.shares[0]).toMatchObject({ kind: 'group', subjectId: 'editorial' });
86
+ });
87
+ });
@@ -0,0 +1,70 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { buildSyncHealth, type SyncConnectionInput } from '../corpus/converse/sync-health';
4
+
5
+ const NOW = Date.parse('2026-11-26T12:00:00Z');
6
+ const ago = (min: number) => new Date(NOW - min * 60000).toISOString();
7
+ const conn = (over: Partial<SyncConnectionInput>): SyncConnectionInput => ({ id: 'c1', connector_name: 'Gmail', ...over });
8
+ const sync = (over: Record<string, unknown>) => ({ state: 'ok', note: '', records: 10, last_attempt_at: ago(5), last_success_at: ago(5), next_sync_at: new Date(NOW + 600000).toISOString(), interval_minutes: 15, ...over });
9
+ const rows = (c: SyncConnectionInput[], todo: Parameters<typeof buildSyncHealth>[1] = { at: ago(3), ok: true, closed: 0, error: '' }) => buildSyncHealth(c, todo, NOW);
10
+
11
+ describe('buildSyncHealth', () => {
12
+ it('a clean connector is one ok leg with last-success and lag', () => {
13
+ const [leg] = rows([conn({ sync: sync({}) })]).filter((l) => l.key === 'c1');
14
+ expect(leg).toMatchObject({ label: 'Gmail', state: 'ok', lastOkAt: ago(5), lagMs: 5 * 60000, lastError: '' });
15
+ });
16
+
17
+ it('a failing connector carries the scrubbed last error', () => {
18
+ const [leg] = rows([conn({ sync: sync({ state: 'failing', note: 'The last sync did not finish; it will try again' }), last_error: 'Quota exhausted' })]).filter((l) => l.key === 'c1');
19
+ expect(leg).toMatchObject({ state: 'failing', lastError: 'Quota exhausted' });
20
+ });
21
+
22
+ it('limited reads as behind with the retry time; reauth and waiting keep their own state', () => {
23
+ const out = rows([
24
+ conn({ id: 'a', sync: sync({ state: 'limited', note: 'The provider is limiting requests' }) }),
25
+ conn({ id: 'b', sync: sync({ state: 'reauth', note: 'Reconnect this account' }) }),
26
+ conn({ id: 'c', sync: sync({ state: 'waiting', last_success_at: null, last_attempt_at: null }) }),
27
+ ]);
28
+ const by = Object.fromEntries(out.map((l) => [l.key, l]));
29
+ expect(by.a.state).toBe('behind');
30
+ expect(by.b.state).toBe('reauth');
31
+ expect(by.c).toMatchObject({ state: 'waiting', lastOkAt: null, lagMs: null });
32
+ });
33
+
34
+ it('an ok connector whose next sync is long overdue is stale, not ok', () => {
35
+ const [leg] = rows([conn({ sync: sync({ next_sync_at: ago(60), interval_minutes: 15 }) })]).filter((l) => l.key === 'c1');
36
+ expect(leg.state).toBe('stale');
37
+ });
38
+
39
+ it('passive connectors are shown but never alarm', () => {
40
+ const [leg] = rows([conn({ sync: sync({ state: 'passive', note: 'Receives data only when sent' }) })]).filter((l) => l.key === 'c1');
41
+ expect(leg.state).toBe('passive');
42
+ });
43
+
44
+ it('a task tracker splits into a pull leg and a push leg with rows behind', () => {
45
+ const out = rows([conn({ id: 'lin', connector_name: 'Linear', sync: sync({}), sync_status: { status: 'ok', last_pull_at: ago(2), last_push_at: ago(40), pending_count: 4, out_of_sync: true, last_error: '', retry_at: null } })]);
46
+ const pull = out.find((l) => l.key === 'lin:pull')!;
47
+ const push = out.find((l) => l.key === 'lin:push')!;
48
+ expect(pull).toMatchObject({ label: 'Linear pull', state: 'ok', lastOkAt: ago(2) });
49
+ expect(push).toMatchObject({ label: 'Linear push', state: 'behind', behind: 4, lastOkAt: ago(40) });
50
+ });
51
+
52
+ it('a failing task-tracker push shows the error and retry time', () => {
53
+ const out = rows([conn({ id: 'lin', connector_name: 'Linear', sync: sync({}), sync_status: { status: 'error', last_pull_at: ago(1), last_push_at: ago(90), pending_count: 2, out_of_sync: true, last_error: 'HTTP 500', retry_at: ago(-5) } })]);
54
+ expect(out.find((l) => l.key === 'lin:push')).toMatchObject({ state: 'failing', lastError: 'HTTP 500', retryAt: ago(-5), behind: 2 });
55
+ });
56
+
57
+ it('todo-sync: never reported is waiting, recent is ok, old is stale, failed is failing', () => {
58
+ const t = (todo: Parameters<typeof rows>[1]) => rows([], todo).find((l) => l.key === 'todo-sync')!;
59
+ expect(t(null)).toMatchObject({ state: 'waiting', lastOkAt: null });
60
+ expect(t({ at: ago(4), ok: true, closed: 2, error: '' })).toMatchObject({ state: 'ok', lastOkAt: ago(4), lagMs: 4 * 60000 });
61
+ expect(t({ at: ago(45), ok: true, closed: 0, error: '' }).state).toBe('stale');
62
+ expect(t({ at: ago(2), ok: false, closed: 0, error: 'relay login expired' })).toMatchObject({ state: 'failing', lastError: 'relay login expired' });
63
+ });
64
+
65
+ it('puts the worst legs first', () => {
66
+ const out = rows([conn({ id: 'ok', sync: sync({}) }), conn({ id: 'bad', sync: sync({ state: 'failing' }) })], null);
67
+ expect(out[0].key).toBe('bad');
68
+ expect(out.at(-1)!.state).not.toBe('failing');
69
+ });
70
+ });
@@ -40,7 +40,7 @@ describe('TaskDetailPage', () => {
40
40
  const onBack = vi.fn();
41
41
  render(<TaskDetailPage api={apiWith([make('a')])} scope={scope} itemId="commit:zzz" onBack={onBack} />);
42
42
  expect(await screen.findByText(/couldn.t find that to-do/i)).toBeInTheDocument();
43
- fireEvent.click(screen.getByRole('button', { name: /back to tracker/i }));
43
+ fireEvent.click(screen.getByRole('button', { name: /back to to-dos/i }));
44
44
  expect(onBack).toHaveBeenCalled();
45
45
  });
46
46
 
package/src/api/_fetch.ts CHANGED
@@ -43,7 +43,7 @@ export function setAuthTokenProvider(
43
43
  }
44
44
 
45
45
  export interface RequestOptions {
46
- method?: 'GET' | 'POST' | 'PATCH' | 'DELETE';
46
+ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
47
47
  body?: unknown;
48
48
  query?: Record<string, string | number | boolean | undefined | null>;
49
49
  headers?: Record<string, string>;