@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.
- package/package.json +3 -3
- package/src/__tests__/briefing-actions.test.ts +2 -0
- package/src/__tests__/briefing-reply.test.ts +334 -0
- package/src/__tests__/corpus-tracker.test.tsx +79 -0
- package/src/__tests__/extract-classify.test.ts +9 -4
- package/src/__tests__/owner-backfill.test.ts +114 -0
- package/src/__tests__/owner-link.test.ts +115 -0
- package/src/__tests__/owner-picker.test.tsx +70 -0
- package/src/__tests__/private-items.test.ts +63 -0
- package/src/__tests__/roster.test.ts +27 -0
- package/src/__tests__/task-detail-private.test.tsx +44 -0
- package/src/__tests__/tracker-sort.test.ts +28 -0
- package/src/components/index.ts +1 -0
- package/src/components/pages/TaskDetailPage.tsx +51 -2
- package/src/components/pages/TrackerPage.tsx +28 -6
- package/src/components/pages/task-tracker/OwnerPicker.tsx +82 -0
- package/src/components/pages/tracker/TrackerBoard.tsx +45 -0
- package/src/components/pages/tracker/TrackerToolbar.tsx +44 -0
- package/src/corpus/briefing/actions/execute.ts +5 -4
- package/src/corpus/briefing/actions/log.ts +1 -1
- package/src/corpus/briefing/actions/types.ts +21 -0
- package/src/corpus/briefing/index.ts +1 -0
- package/src/corpus/briefing/intent/model.ts +3 -0
- package/src/corpus/briefing/intent/resolve.ts +14 -6
- package/src/corpus/briefing/intent/types.ts +7 -0
- package/src/corpus/briefing/reply/handle.ts +174 -0
- package/src/corpus/briefing/reply/index.ts +6 -0
- package/src/corpus/briefing/reply/respond.ts +95 -0
- package/src/corpus/briefing/reply/types.ts +112 -0
- package/src/corpus/briefing/store.ts +14 -0
- package/src/corpus/client.ts +24 -18
- package/src/corpus/entities.ts +7 -0
- package/src/corpus/extract.ts +21 -0
- package/src/corpus/index.ts +4 -0
- package/src/corpus/owner-backfill.ts +200 -0
- package/src/corpus/owner-link.ts +160 -0
- package/src/corpus/roster.ts +53 -0
- package/src/corpus/tracker-groups.ts +8 -4
- package/src/corpus/tracker-sort.ts +51 -0
- package/src/corpus/types.ts +24 -1
- package/src/native/app/FoundryApp.tsx +25 -7
- package/src/native/app/__tests__/briefingLink.test.tsx +57 -0
- package/src/native/app/__tests__/briefingServices.test.ts +92 -0
- package/src/native/app/__tests__/launch.test.ts +2 -1
- package/src/native/app/briefingServices.ts +101 -0
- package/src/native/app/config/__tests__/briefingConfig.test.ts +49 -0
- package/src/native/app/config/links.ts +4 -1
- package/src/native/app/config/types.ts +13 -1
- package/src/native/app/config/validate.ts +20 -2
- package/src/native/app/data.ts +3 -3
- package/src/native/app/device.ts +3 -0
- package/src/native/app/launch.ts +4 -0
- package/src/native/app/registry.tsx +3 -1
- package/src/native/app/screens/RecordScreen.tsx +3 -2
- package/src/native/app/services.ts +11 -30
- package/src/native/app/strings.ts +28 -0
- package/src/native/briefing/BriefingCard.tsx +14 -2
- package/src/native/briefing/BriefingReply.tsx +68 -0
- package/src/native/briefing/__tests__/BriefingReply.test.tsx +144 -0
- package/src/native/briefing/__tests__/fakeReply.test.ts +46 -0
- package/src/native/briefing/__tests__/notify.test.ts +42 -1
- package/src/native/briefing/__tests__/replyApi.test.ts +43 -0
- package/src/native/briefing/__tests__/replyController.test.ts +230 -0
- package/src/native/briefing/__tests__/replyPosition.test.ts +116 -0
- package/src/native/briefing/audioPlayer.ts +9 -2
- package/src/native/briefing/controller.ts +50 -5
- package/src/native/briefing/fake.ts +25 -18
- package/src/native/briefing/fakeReply.ts +65 -0
- package/src/native/briefing/index.ts +8 -3
- package/src/native/briefing/notify.ts +42 -0
- package/src/native/briefing/reply.ts +261 -0
- package/src/native/briefing/replyApi.ts +82 -0
- package/src/native/recording/__tests__/deeplink.test.ts +20 -0
- package/src/native/recording/deeplink.ts +7 -0
- package/src/native/tracker/__tests__/itemsChanged.test.ts +13 -0
- package/src/native/tracker/tab.tsx +4 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { act, allText, hostById, maybeById, render } from '../../../../../ui-native/test/render';
|
|
3
|
+
import type { BriefingResult } from '../../../corpus/briefing';
|
|
4
|
+
import { BriefingCard } from '../BriefingCard';
|
|
5
|
+
import { BriefingReply } from '../BriefingReply';
|
|
6
|
+
import { createBriefingController } from '../controller';
|
|
7
|
+
import type { PlayerState } from '../audioPlayer';
|
|
8
|
+
import type { ReplyState } from '../reply';
|
|
9
|
+
import { foundryStrings } from '../../app/strings';
|
|
10
|
+
import { resolveFoundryApp } from '../../app/config/validate';
|
|
11
|
+
|
|
12
|
+
const strings = foundryStrings(resolveFoundryApp({ app: { name: 'Acme Go' }, brand: { name: 'Acme' }, tenant: { url: 'http://x' } }));
|
|
13
|
+
const BLANK: ReplyState = { phase: 'idle', utterance: null, understood: null, confirmation: null, question: null, awaitingAnswer: false, targetId: null, canUndo: false, error: null, retryable: false, speaking: false };
|
|
14
|
+
|
|
15
|
+
function fakeReply(initial: Partial<ReplyState> = {}) {
|
|
16
|
+
let state: ReplyState = { ...BLANK, ...initial };
|
|
17
|
+
const ls = new Set<() => void>();
|
|
18
|
+
return {
|
|
19
|
+
getState: () => state,
|
|
20
|
+
subscribe: (l: () => void) => { ls.add(l); return () => ls.delete(l); },
|
|
21
|
+
set: (p: Partial<ReplyState>) => { state = { ...state, ...p }; act(() => { ls.forEach((l) => l()); }); },
|
|
22
|
+
pressStart: vi.fn(async () => undefined), pressEnd: vi.fn(async () => undefined), apply: vi.fn(async () => undefined),
|
|
23
|
+
cancel: vi.fn(async () => undefined), undo: vi.fn(async () => undefined), retry: vi.fn(async () => undefined), continueBriefing: vi.fn(async () => undefined),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const press = (id: string, r: ReturnType<typeof render>, prop: 'onPress' | 'onPressIn' | 'onPressOut') => act(() => { hostById(r, id).props[prop]?.({}); });
|
|
27
|
+
|
|
28
|
+
describe('BriefingReply', () => {
|
|
29
|
+
it('test_hold_to_talk_button_goes_down_and_up_on_press_in_and_out', () => {
|
|
30
|
+
const c = fakeReply();
|
|
31
|
+
const r = render(<BriefingReply controller={c as never} strings={strings} />);
|
|
32
|
+
const b = hostById(r, 'briefing-talk');
|
|
33
|
+
expect(b.props.accessibilityLabel).toBe(strings.replyTalk);
|
|
34
|
+
press('briefing-talk', r, 'onPressIn');
|
|
35
|
+
press('briefing-talk', r, 'onPressOut');
|
|
36
|
+
expect(c.pressStart).toHaveBeenCalledTimes(1);
|
|
37
|
+
expect(c.pressEnd).toHaveBeenCalledTimes(1);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('test_the_same_button_stays_mounted_while_held_and_says_listening', () => {
|
|
41
|
+
const c = fakeReply();
|
|
42
|
+
const r = render(<BriefingReply controller={c as never} strings={strings} />);
|
|
43
|
+
c.set({ phase: 'recording' });
|
|
44
|
+
expect(hostById(r, 'briefing-talk').props.accessibilityLabel).toBe(strings.replyListening);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('test_a_question_is_shown_and_the_button_offers_to_answer', () => {
|
|
48
|
+
const c = fakeReply({ phase: 'asked', question: 'Which one: A, or B?', awaitingAnswer: true });
|
|
49
|
+
const r = render(<BriefingReply controller={c as never} strings={strings} />);
|
|
50
|
+
expect(allText(r)).toContain('Which one: A, or B?');
|
|
51
|
+
expect(hostById(r, 'briefing-talk').props.accessibilityLabel).toBe(strings.replyHoldToAnswer);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('test_what_was_understood_is_shown_with_do_it_and_cancel_before_anything_is_applied', () => {
|
|
55
|
+
const c = fakeReply({ phase: 'preview', understood: 'Move Send the deck to later', utterance: 'not today' });
|
|
56
|
+
const r = render(<BriefingReply controller={c as never} strings={strings} />);
|
|
57
|
+
expect(allText(r)).toContain('Move Send the deck to later?');
|
|
58
|
+
expect(allText(r)).toContain('"not today"');
|
|
59
|
+
press('briefing-apply', r, 'onPress');
|
|
60
|
+
press('briefing-cancel', r, 'onPress');
|
|
61
|
+
expect(c.apply).toHaveBeenCalled();
|
|
62
|
+
expect(c.cancel).toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('test_after_applying_the_confirmation_has_undo_and_continue', () => {
|
|
66
|
+
const c = fakeReply({ phase: 'applied', confirmation: 'Moved Send the deck to later.', canUndo: true });
|
|
67
|
+
const r = render(<BriefingReply controller={c as never} strings={strings} />);
|
|
68
|
+
expect(allText(r)).toContain('Moved Send the deck to later.');
|
|
69
|
+
press('briefing-undo', r, 'onPress');
|
|
70
|
+
press('briefing-continue', r, 'onPress');
|
|
71
|
+
expect(c.undo).toHaveBeenCalled();
|
|
72
|
+
expect(c.continueBriefing).toHaveBeenCalled();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('test_no_undo_button_when_there_is_nothing_to_undo', () => {
|
|
76
|
+
const c = fakeReply({ phase: 'applied', confirmation: 'Undid it.', canUndo: false });
|
|
77
|
+
const r = render(<BriefingReply controller={c as never} strings={strings} />);
|
|
78
|
+
expect(maybeById(r, 'briefing-undo')).toHaveLength(0);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('test_a_failure_shows_the_message_with_retry_only_when_a_retry_can_work', () => {
|
|
82
|
+
const c = fakeReply({ phase: 'error', error: 'Could not make that out. Try again.', retryable: true });
|
|
83
|
+
const r = render(<BriefingReply controller={c as never} strings={strings} />);
|
|
84
|
+
expect(allText(r)).toContain('Could not make that out');
|
|
85
|
+
press('briefing-reply-retry', r, 'onPress');
|
|
86
|
+
expect(c.retry).toHaveBeenCalled();
|
|
87
|
+
c.set({ retryable: false });
|
|
88
|
+
expect(maybeById(r, 'briefing-reply-retry')).toHaveLength(0);
|
|
89
|
+
press('briefing-reply-dismiss', r, 'onPress');
|
|
90
|
+
expect(c.cancel).toHaveBeenCalled();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('BriefingCard with a reply', () => {
|
|
95
|
+
const TEXT = 'Good morning. Send the deck. Call Dana. That is everything.';
|
|
96
|
+
const result: BriefingResult = {
|
|
97
|
+
briefingId: 'b1', text: TEXT, audioUrl: '/a',
|
|
98
|
+
items: [{ id: 'a', title: 'Send the deck', kind: 'due_today', group: 'Launch', dueDate: null }, { id: 'b', title: 'Call Dana', kind: 'due_today', group: 'Launch', dueDate: null }],
|
|
99
|
+
remaining: 0, context: { itemIds: ['a', 'b'], localDate: '2026-11-05', timeZone: 'UTC', offsets: [{ id: 'a', start: 14, end: 28 }, { id: 'b', start: 29, end: 39 }] }, scriptSource: 'llm', cached: false, ms: 1,
|
|
100
|
+
};
|
|
101
|
+
function card(withReply = true) {
|
|
102
|
+
let ps: PlayerState = { phase: 'idle', positionMillis: 0, durationMillis: 0 };
|
|
103
|
+
const ls = new Set<(s: PlayerState) => void>();
|
|
104
|
+
const emit = (p: Partial<PlayerState>) => { ps = { ...ps, ...p }; ls.forEach((l) => l(ps)); };
|
|
105
|
+
const player = {
|
|
106
|
+
getState: () => ps, subscribe: (cb: (s: PlayerState) => void) => { ls.add(cb); return () => ls.delete(cb); },
|
|
107
|
+
play: vi.fn(async () => { emit({ phase: 'playing', durationMillis: 10_000 }); }), stop: vi.fn(async () => { emit({ phase: 'idle' }); }), handoffToRecording: vi.fn(async () => undefined),
|
|
108
|
+
};
|
|
109
|
+
const controller = createBriefingController({
|
|
110
|
+
api: { fetch: async () => result, audioSource: async () => ({ uri: 'http://x/a' }) } as never, player: player as never,
|
|
111
|
+
messages: { failed: 'f', empty: 'e', textOnly: 't', audioFailed: 'a' },
|
|
112
|
+
});
|
|
113
|
+
const reply = fakeReply();
|
|
114
|
+
const r = render(<BriefingCard controller={controller} reply={withReply ? (reply as never) : null} strings={strings} />);
|
|
115
|
+
return { r, controller, reply, emit };
|
|
116
|
+
}
|
|
117
|
+
const flush = () => act(async () => { await Promise.resolve(); await Promise.resolve(); await Promise.resolve(); });
|
|
118
|
+
|
|
119
|
+
it('test_reply_button_is_visible_during_and_after_playback_and_never_before', async () => {
|
|
120
|
+
const { r, controller, emit } = card();
|
|
121
|
+
expect(maybeById(r, 'briefing-talk')).toHaveLength(0);
|
|
122
|
+
await act(async () => { await controller.start(); });
|
|
123
|
+
await flush();
|
|
124
|
+
expect(maybeById(r, 'briefing-talk')).toHaveLength(1);
|
|
125
|
+
act(() => { emit({ phase: 'ended' }); });
|
|
126
|
+
expect(maybeById(r, 'briefing-talk')).toHaveLength(1);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('test_no_reply_button_when_the_reply_is_not_configured', async () => {
|
|
130
|
+
const { r, controller } = card(false);
|
|
131
|
+
await act(async () => { await controller.start(); });
|
|
132
|
+
await flush();
|
|
133
|
+
expect(maybeById(r, 'briefing-talk')).toHaveLength(0);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('test_current_item_highlight_follows_the_reply_target_when_playback_is_silent', async () => {
|
|
137
|
+
const { r, controller, reply, emit } = card();
|
|
138
|
+
await act(async () => { await controller.start(); });
|
|
139
|
+
await flush();
|
|
140
|
+
act(() => { emit({ phase: 'ended' }); });
|
|
141
|
+
reply.set({ targetId: 'b', phase: 'applied', confirmation: 'ok' });
|
|
142
|
+
expect(hostById(r, 'briefing-current').props.children).toContain('Call Dana');
|
|
143
|
+
});
|
|
144
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { createFakeNativeCorpusApi } from '../../corpus/fake';
|
|
4
|
+
import { createFakeBriefingReplyApi, fakeBriefingRows } from '../fakeReply';
|
|
5
|
+
import { FAKE_BRIEFING } from '../fake';
|
|
6
|
+
|
|
7
|
+
const NOW = Date.parse('2026-11-05T15:00:00Z');
|
|
8
|
+
const setup = (script: string[]) => {
|
|
9
|
+
const corpus = createFakeNativeCorpusApi({ extraEntities: fakeBriefingRows() });
|
|
10
|
+
const api = createFakeBriefingReplyApi({ corpus, script, now: () => NOW });
|
|
11
|
+
const due = async (id: string) => ((await corpus.tenant.http.get<TenantRow>(`api/v1/entities/${id}`)).data as { due_at?: string }).due_at?.slice(0, 10) ?? null;
|
|
12
|
+
const press = (n: number, over: object = {}) => api.send({ briefingId: FAKE_BRIEFING.briefingId, clientActionId: `fake-press-${n}`, recording: { uri: 'file:///x', durationMs: 900 }, mode: 'auto', ...over });
|
|
13
|
+
return { api, corpus, due, press };
|
|
14
|
+
};
|
|
15
|
+
type TenantRow = { data: unknown };
|
|
16
|
+
const at = FAKE_BRIEFING.context.offsets[1].start + 2; // inside the second item
|
|
17
|
+
|
|
18
|
+
describe('the fake reply: the real route over the fake tenant', () => {
|
|
19
|
+
it('test_this_one_is_the_item_being_read_and_the_fake_tracker_row_changes', async () => {
|
|
20
|
+
const s = setup(['move this one to later']);
|
|
21
|
+
const out = await s.press(1, { position: { charPosition: at } });
|
|
22
|
+
expect(out.kind).toBe('applied');
|
|
23
|
+
expect(out.confirmation?.text).toBe('Moved Review the launch checklist to later.');
|
|
24
|
+
expect(await s.due('t2')).toBeNull();
|
|
25
|
+
expect(await s.due('t1')).toBe('2026-11-03');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('test_undo_puts_the_date_back', async () => {
|
|
29
|
+
const s = setup(['move this one to later']);
|
|
30
|
+
await s.press(1, { position: { charPosition: at } });
|
|
31
|
+
const out = await s.api.send({ briefingId: FAKE_BRIEFING.briefingId, clientActionId: 'fake-press-2', undo: true });
|
|
32
|
+
expect(out.confirmation?.text).toMatch(/^Undid it/);
|
|
33
|
+
expect(await s.due('t2')).toBe('2026-11-05');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('test_a_question_then_an_answer_from_the_script', async () => {
|
|
37
|
+
const s = setup(['move that one to later', 'the car one']);
|
|
38
|
+
const asked = await s.press(1);
|
|
39
|
+
expect(asked.kind).toBe('clarify');
|
|
40
|
+
expect(asked.question).toMatch(/^Which one:/);
|
|
41
|
+
const done = await s.press(2, { inReplyTo: 'fake-press-1' });
|
|
42
|
+
expect(done.kind).toBe('applied');
|
|
43
|
+
expect(await s.due('t3')).toBeNull();
|
|
44
|
+
expect(done.actions).toEqual([expect.objectContaining({ itemId: 't3' })]);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import { planMorningNotification, syncMorningNotification, type MorningNotifier } from '../notify';
|
|
3
|
+
import { pickMorningSchedule, planMorningNotification, syncMorningFromCentral, syncMorningNotification, type MorningNotifier } from '../notify';
|
|
4
4
|
|
|
5
5
|
const NY = 'America/New_York';
|
|
6
6
|
// Wednesday 2026-11-04 10:00 in New York.
|
|
@@ -50,3 +50,44 @@ describe('syncMorningNotification', () => {
|
|
|
50
50
|
expect(await syncMorningNotification(n, { enabled: true, morningTime: '07:30', timeZone: NY, scheme: 'x', now: NOW })).toBeNull();
|
|
51
51
|
});
|
|
52
52
|
});
|
|
53
|
+
|
|
54
|
+
describe('the morning setting lives on central', () => {
|
|
55
|
+
const schedules = { schedules: [
|
|
56
|
+
{ tenant: 'hours', enabled: true, morningTime: '06:00' },
|
|
57
|
+
{ tenant: 'tandem', enabled: true, morningTime: '07:30' },
|
|
58
|
+
] };
|
|
59
|
+
|
|
60
|
+
it('test_picks_this_foundrys_row', () => {
|
|
61
|
+
expect(pickMorningSchedule(schedules, 'tandem')).toEqual({ enabled: true, morningTime: '07:30' });
|
|
62
|
+
expect(pickMorningSchedule(schedules, 'nobody')).toBeNull();
|
|
63
|
+
expect(pickMorningSchedule({ schedules: [] }, 'tandem')).toBeNull();
|
|
64
|
+
expect(pickMorningSchedule(undefined, 'tandem')).toBeNull();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const notifier = (): MorningNotifier => ({ schedule: vi.fn(async () => 'n1'), cancel: vi.fn(async () => {}) });
|
|
68
|
+
const fetchOf = (body: unknown, status = 200) => vi.fn(async () => new Response(JSON.stringify(body), { status }));
|
|
69
|
+
|
|
70
|
+
it('test_reads_central_and_schedules_the_local_notification_with_the_deep_link', async () => {
|
|
71
|
+
const n = notifier();
|
|
72
|
+
const fetch = fetchOf(schedules);
|
|
73
|
+
const plan = await syncMorningFromCentral({ notifier: n, authorizedFetch: fetch, centralUrl: 'https://api.example.com/', tenantSlug: 'tandem', scheme: 'tandemgo', timeZone: NY, now: NOW });
|
|
74
|
+
expect(fetch.mock.calls[0][0]).toBe('https://api.example.com/api/v1/auth/briefing-schedule/');
|
|
75
|
+
expect(plan).toMatchObject({ time: '07:30', deepLink: 'tandemgo://briefing' });
|
|
76
|
+
expect(n.schedule).toHaveBeenCalledTimes(1);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('test_no_row_or_a_disabled_row_cancels', async () => {
|
|
80
|
+
const n = notifier();
|
|
81
|
+
expect(await syncMorningFromCentral({ notifier: n, authorizedFetch: fetchOf({ schedules: [] }), centralUrl: 'https://c', tenantSlug: 'tandem', scheme: 's', timeZone: NY, now: NOW })).toBeNull();
|
|
82
|
+
expect(await syncMorningFromCentral({ notifier: n, authorizedFetch: fetchOf({ schedules: [{ tenant: 'tandem', enabled: false, morningTime: '07:30' }] }), centralUrl: 'https://c', tenantSlug: 'tandem', scheme: 's', timeZone: NY, now: NOW })).toBeNull();
|
|
83
|
+
expect(n.cancel).toHaveBeenCalledTimes(2);
|
|
84
|
+
expect(n.schedule).not.toHaveBeenCalled();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('test_a_central_outage_leaves_the_existing_notification_alone', async () => {
|
|
88
|
+
const n = notifier();
|
|
89
|
+
expect(await syncMorningFromCentral({ notifier: n, authorizedFetch: fetchOf({}, 503), centralUrl: 'https://c', tenantSlug: 'tandem', scheme: 's', timeZone: NY, now: NOW })).toBeNull();
|
|
90
|
+
expect(n.cancel).not.toHaveBeenCalled();
|
|
91
|
+
expect(n.schedule).not.toHaveBeenCalled();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { createBriefingReplyApi } from '../replyApi';
|
|
3
|
+
|
|
4
|
+
const OK = { kind: 'applied', clientActionId: 'p1', confirmation: { text: 'ok', audioUrl: '/corpus/briefing/b1/reply/p1/audio' } };
|
|
5
|
+
const json = (body: unknown, status = 200) => new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json' } });
|
|
6
|
+
const setup = (res: Response = json(OK)) => {
|
|
7
|
+
const fetch = vi.fn(async (_u: string, _i?: RequestInit) => res);
|
|
8
|
+
const forms: Array<Array<[string, unknown]>> = [];
|
|
9
|
+
const createForm = () => { const rows: Array<[string, unknown]> = []; forms.push(rows); return { append: (k: string, v: unknown) => rows.push([k, v]) } as unknown as FormData; };
|
|
10
|
+
const api = createBriefingReplyApi({ tandemUrl: 'https://t.example/', authorizedFetch: fetch, bearer: async () => 'tok', filePart: (u) => ({ uri: u }) as never, createForm, timeZone: 'America/New_York' });
|
|
11
|
+
return { api, fetch, forms };
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
describe('briefing reply api', () => {
|
|
15
|
+
it('test_audio_goes_up_as_multipart_with_the_press_the_position_and_the_zone', async () => {
|
|
16
|
+
const s = setup();
|
|
17
|
+
await s.api.send({ briefingId: 'b1', clientActionId: 'p1', mode: 'auto', recording: { uri: 'file:///r.m4a', durationMs: 900 }, position: { seconds: 3, durationSeconds: 10 }, inReplyTo: 'p0' });
|
|
18
|
+
expect(s.fetch.mock.calls[0][0]).toBe('https://t.example/corpus/briefing/reply');
|
|
19
|
+
const fields = Object.fromEntries(s.forms[0].map(([k, v]) => [k, v]));
|
|
20
|
+
expect(fields).toMatchObject({ briefingId: 'b1', clientActionId: 'p1', mode: 'auto', inReplyTo: 'p0', timeZone: 'America/New_York', audio: { uri: 'file:///r.m4a' } });
|
|
21
|
+
expect(JSON.parse(fields.position as string)).toEqual({ seconds: 3, durationSeconds: 10 });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('test_apply_and_undo_are_small_json', async () => {
|
|
25
|
+
const s = setup();
|
|
26
|
+
await s.api.send({ briefingId: 'b1', clientActionId: 'p1', apply: true });
|
|
27
|
+
const init = s.fetch.mock.calls[0][1] as RequestInit;
|
|
28
|
+
expect((init.headers as Record<string, string>)['content-type']).toBe('application/json');
|
|
29
|
+
expect(JSON.parse(init.body as string)).toMatchObject({ briefingId: 'b1', clientActionId: 'p1', apply: 'true' });
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('test_a_refusal_throws_with_the_status_and_code', async () => {
|
|
33
|
+
const s = setup(json({ detail: 'I could not make out the recording', code: 'transcription_failed' }, 502));
|
|
34
|
+
await expect(s.api.send({ briefingId: 'b1', clientActionId: 'p1', recording: { uri: 'u', durationMs: 900 } })).rejects.toMatchObject({ status: 502, code: 'transcription_failed', message: 'I could not make out the recording' });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('test_the_confirmation_audio_carries_the_bearer_and_resolves_against_the_tenant', async () => {
|
|
38
|
+
const s = setup();
|
|
39
|
+
const src = await s.api.confirmationSource(OK as never);
|
|
40
|
+
expect(src).toEqual({ uri: 'https://t.example/corpus/briefing/b1/reply/p1/audio', headers: { authorization: 'Bearer tok' } });
|
|
41
|
+
expect(await s.api.confirmationSource({ confirmation: { text: 'x', audioUrl: null } } as never)).toBeNull();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import type { ReplyResult } from '../../../corpus/briefing';
|
|
3
|
+
import { createBriefingReplyController } from '../reply';
|
|
4
|
+
import type { PlayerState } from '../audioPlayer';
|
|
5
|
+
|
|
6
|
+
const STRINGS = { micDenied: 'Mic is off.', tooShort: 'Hold while you speak.', notHeard: 'Could not make that out.', failed: 'Did not go through.', noAudio: 'No audio.' };
|
|
7
|
+
|
|
8
|
+
const result = (over: Partial<ReplyResult> = {}): ReplyResult => ({
|
|
9
|
+
kind: 'applied', clientActionId: 'x', utterance: 'push this to friday', understood: 'Move Send the deck to Friday',
|
|
10
|
+
actions: [{ type: 'defer', itemId: 'a', to: '2026-11-06' }], source: 'grammar', confidence: 1, needsConfirm: false,
|
|
11
|
+
results: [{ status: 'applied', spoken: 'Moved Send the deck to Friday.', itemId: 'a' }], question: null,
|
|
12
|
+
confirmation: { text: 'Moved Send the deck to Friday.', audioUrl: '/corpus/briefing/b1/reply/x/audio' }, undoDepth: 1, refresh: true, replayed: false, ...over,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
function setup(opts: { confirm?: 'auto' | 'ask'; permission?: 'granted' | 'denied'; api?: Record<string, unknown>; file?: Record<string, unknown>; allowSilence?: boolean } = {}) {
|
|
16
|
+
const order: string[] = [];
|
|
17
|
+
let n = 0;
|
|
18
|
+
const audio = {
|
|
19
|
+
start: vi.fn(async () => { order.push('audio.start'); }),
|
|
20
|
+
stop: vi.fn(async () => ({ uri: 'file:///r.m4a', durationMs: 1800, bytes: 9000, peakDb: -10, ...opts.file })),
|
|
21
|
+
};
|
|
22
|
+
const briefing = {
|
|
23
|
+
getState: () => ({ briefingId: 'b1', phase: 'playing' }),
|
|
24
|
+
snapshotPosition: vi.fn(() => { order.push('snapshot'); return { seconds: 3, durationSeconds: 10 }; }),
|
|
25
|
+
handoffToRecording: vi.fn(async () => { order.push('handoff'); }),
|
|
26
|
+
resumeAfter: vi.fn(async () => true),
|
|
27
|
+
};
|
|
28
|
+
const api = {
|
|
29
|
+
send: vi.fn(async () => result()),
|
|
30
|
+
confirmationSource: vi.fn(async () => ({ uri: 'http://x/c.mp3' })),
|
|
31
|
+
...opts.api,
|
|
32
|
+
};
|
|
33
|
+
let ps: PlayerState = { phase: 'idle', positionMillis: 0, durationMillis: 0 };
|
|
34
|
+
const ls = new Set<(s: PlayerState) => void>();
|
|
35
|
+
const speaker = {
|
|
36
|
+
getState: () => ps, subscribe: (cb: (s: PlayerState) => void) => { ls.add(cb); return () => ls.delete(cb); },
|
|
37
|
+
play: vi.fn(async () => { order.push('speak'); }), stop: vi.fn(async () => undefined),
|
|
38
|
+
};
|
|
39
|
+
const removeFile = vi.fn(async () => undefined);
|
|
40
|
+
const onChanged = vi.fn();
|
|
41
|
+
const c = createBriefingReplyController({
|
|
42
|
+
briefing: briefing as never, api: api as never, audio, speaker: speaker as never, removeFile,
|
|
43
|
+
ensurePermission: async () => opts.permission ?? 'granted', confirm: opts.confirm ?? 'auto',
|
|
44
|
+
newId: () => `press-${++n}`, strings: STRINGS, onChanged, diag: { log: vi.fn() }, allowSilence: opts.allowSilence,
|
|
45
|
+
});
|
|
46
|
+
return { c, order, audio, briefing, api, speaker, removeFile, onChanged };
|
|
47
|
+
}
|
|
48
|
+
const talk = async (s: ReturnType<typeof setup>) => { await s.c.pressStart(); await s.c.pressEnd(); };
|
|
49
|
+
|
|
50
|
+
describe('push to talk', () => {
|
|
51
|
+
it('test_press_takes_the_position_then_releases_the_session_before_the_mic_starts', async () => {
|
|
52
|
+
const s = setup();
|
|
53
|
+
await s.c.pressStart();
|
|
54
|
+
expect(s.order).toEqual(['snapshot', 'handoff', 'audio.start']);
|
|
55
|
+
expect(s.c.getState().phase).toBe('recording');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('test_release_sends_the_recording_with_the_position_and_a_fresh_id_then_deletes_the_file', async () => {
|
|
59
|
+
const s = setup();
|
|
60
|
+
await talk(s);
|
|
61
|
+
expect(s.api.send).toHaveBeenCalledWith({
|
|
62
|
+
briefingId: 'b1', clientActionId: 'press-1', mode: 'auto', recording: { uri: 'file:///r.m4a', durationMs: 1800 }, position: { seconds: 3, durationSeconds: 10 },
|
|
63
|
+
});
|
|
64
|
+
expect(s.removeFile).toHaveBeenCalledWith('file:///r.m4a');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('test_release_before_the_mic_is_up_still_sends', async () => {
|
|
68
|
+
const s = setup();
|
|
69
|
+
let go!: () => void;
|
|
70
|
+
s.audio.start.mockImplementation(() => new Promise<void>((r) => { go = r; }));
|
|
71
|
+
const pressed = s.c.pressStart();
|
|
72
|
+
await Promise.resolve(); await Promise.resolve(); await Promise.resolve();
|
|
73
|
+
await s.c.pressEnd();
|
|
74
|
+
go();
|
|
75
|
+
await pressed;
|
|
76
|
+
expect(s.api.send).toHaveBeenCalledTimes(1);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('test_a_tap_too_short_to_hold_a_sentence_sends_nothing_and_says_how', async () => {
|
|
80
|
+
const s = setup({ file: { durationMs: 200 } });
|
|
81
|
+
await talk(s);
|
|
82
|
+
expect(s.api.send).not.toHaveBeenCalled();
|
|
83
|
+
expect(s.removeFile).toHaveBeenCalledWith('file:///r.m4a');
|
|
84
|
+
expect(s.c.getState()).toMatchObject({ phase: 'error', error: STRINGS.tooShort, retryable: false });
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('test_a_silent_recording_is_not_sent', async () => {
|
|
88
|
+
const s = setup({ file: { peakDb: -80 } });
|
|
89
|
+
await talk(s);
|
|
90
|
+
expect(s.api.send).not.toHaveBeenCalled();
|
|
91
|
+
expect(s.c.getState().error).toBe(STRINGS.noAudio);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('test_a_silent_recording_is_sent_when_the_fakes_ignore_the_audio', async () => {
|
|
95
|
+
const s = setup({ file: { peakDb: -80 }, allowSilence: true });
|
|
96
|
+
await talk(s);
|
|
97
|
+
expect(s.api.send).toHaveBeenCalledTimes(1);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('test_mic_permission_denied_is_a_message_not_a_recording', async () => {
|
|
101
|
+
const s = setup({ permission: 'denied' });
|
|
102
|
+
await s.c.pressStart();
|
|
103
|
+
expect(s.audio.start).not.toHaveBeenCalled();
|
|
104
|
+
expect(s.c.getState()).toMatchObject({ phase: 'error', error: STRINGS.micDenied });
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe('what happens with the answer', () => {
|
|
109
|
+
it('test_auto_mode_shows_the_result_speaks_it_and_offers_undo', async () => {
|
|
110
|
+
const s = setup();
|
|
111
|
+
await talk(s);
|
|
112
|
+
expect(s.c.getState()).toMatchObject({ phase: 'applied', confirmation: 'Moved Send the deck to Friday.', canUndo: true, targetId: 'a', utterance: 'push this to friday' });
|
|
113
|
+
expect(s.speaker.play).toHaveBeenCalledWith({ uri: 'http://x/c.mp3' });
|
|
114
|
+
expect(s.onChanged).toHaveBeenCalledTimes(1);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('test_ask_mode_shows_what_was_understood_before_anything_is_applied_and_apply_sends_the_stored_id', async () => {
|
|
118
|
+
const s = setup({ confirm: 'ask' });
|
|
119
|
+
s.api.send.mockResolvedValueOnce(result({ kind: 'preview', needsConfirm: true, confirmation: null, results: [], undoDepth: 0, refresh: false, clientActionId: 'press-1' }));
|
|
120
|
+
await talk(s);
|
|
121
|
+
expect(s.api.send).toHaveBeenCalledWith(expect.objectContaining({ mode: 'preview' }));
|
|
122
|
+
expect(s.c.getState()).toMatchObject({ phase: 'preview', understood: 'Move Send the deck to Friday', targetId: 'a' });
|
|
123
|
+
expect(s.onChanged).not.toHaveBeenCalled();
|
|
124
|
+
await s.c.apply();
|
|
125
|
+
expect(s.api.send).toHaveBeenLastCalledWith({ briefingId: 'b1', clientActionId: 'press-1', apply: true });
|
|
126
|
+
expect(s.c.getState()).toMatchObject({ phase: 'applied', canUndo: true });
|
|
127
|
+
expect(s.onChanged).toHaveBeenCalledTimes(1);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('test_cancel_drops_a_preview_without_calling_the_server', async () => {
|
|
131
|
+
const s = setup({ confirm: 'ask' });
|
|
132
|
+
s.api.send.mockResolvedValueOnce(result({ kind: 'preview', needsConfirm: true, confirmation: null, results: [], clientActionId: 'press-1' }));
|
|
133
|
+
await talk(s);
|
|
134
|
+
s.api.send.mockClear();
|
|
135
|
+
await s.c.cancel();
|
|
136
|
+
expect(s.api.send).not.toHaveBeenCalled();
|
|
137
|
+
expect(s.c.getState().phase).toBe('idle');
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('test_a_question_is_shown_and_spoken_and_the_next_press_answers_it', async () => {
|
|
141
|
+
const s = setup();
|
|
142
|
+
s.api.send.mockResolvedValueOnce(result({ kind: 'clarify', question: 'Which one: A, or B?', confirmation: { text: 'Which one: A, or B?', audioUrl: '/q' }, results: [{ status: 'asked', spoken: 'Which one: A, or B?' }], actions: [{ type: 'clarify', question: 'Which one: A, or B?' }], refresh: false, undoDepth: 0, clientActionId: 'press-1' }));
|
|
143
|
+
await talk(s);
|
|
144
|
+
expect(s.c.getState()).toMatchObject({ phase: 'asked', question: 'Which one: A, or B?', awaitingAnswer: true, targetId: null });
|
|
145
|
+
expect(s.speaker.play).toHaveBeenCalled();
|
|
146
|
+
expect(s.onChanged).not.toHaveBeenCalled();
|
|
147
|
+
await talk(s);
|
|
148
|
+
expect(s.api.send).toHaveBeenLastCalledWith(expect.objectContaining({ clientActionId: 'press-2', inReplyTo: 'press-1' }));
|
|
149
|
+
expect(s.c.getState().awaitingAnswer).toBe(false);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('test_undo_button_sends_undo_and_shows_the_result', async () => {
|
|
153
|
+
const s = setup();
|
|
154
|
+
await talk(s);
|
|
155
|
+
s.api.send.mockResolvedValueOnce(result({ confirmation: { text: 'Undid it. Send the deck is back to Wednesday.', audioUrl: null }, actions: [{ type: 'undo' }], undoDepth: 0 }));
|
|
156
|
+
await s.c.undo();
|
|
157
|
+
expect(s.api.send).toHaveBeenLastCalledWith({ briefingId: 'b1', clientActionId: 'press-2', undo: true });
|
|
158
|
+
expect(s.c.getState()).toMatchObject({ phase: 'applied', confirmation: 'Undid it. Send the deck is back to Wednesday.', canUndo: false });
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('test_text_survives_when_the_spoken_confirmation_cannot_play', async () => {
|
|
162
|
+
const s = setup();
|
|
163
|
+
s.speaker.play.mockRejectedValueOnce(new Error('no audio'));
|
|
164
|
+
await talk(s);
|
|
165
|
+
expect(s.c.getState()).toMatchObject({ phase: 'applied', confirmation: 'Moved Send the deck to Friday.' });
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe('when it goes wrong', () => {
|
|
170
|
+
it('test_stt_failure_keeps_the_recording_and_retry_resends_the_same_press', async () => {
|
|
171
|
+
const s = setup();
|
|
172
|
+
s.api.send.mockRejectedValueOnce(Object.assign(new Error('x'), { status: 502, code: 'transcription_failed' }));
|
|
173
|
+
await talk(s);
|
|
174
|
+
expect(s.c.getState()).toMatchObject({ phase: 'error', error: STRINGS.notHeard, retryable: true });
|
|
175
|
+
expect(s.removeFile).not.toHaveBeenCalled();
|
|
176
|
+
await s.c.retry();
|
|
177
|
+
expect(s.api.send).toHaveBeenCalledTimes(2);
|
|
178
|
+
expect(s.api.send.mock.calls[1][0]).toMatchObject({ clientActionId: 'press-1', recording: { uri: 'file:///r.m4a', durationMs: 1800 } });
|
|
179
|
+
expect(s.c.getState().phase).toBe('applied');
|
|
180
|
+
expect(s.removeFile).toHaveBeenCalledWith('file:///r.m4a');
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('test_cancel_after_a_failure_deletes_the_recording', async () => {
|
|
184
|
+
const s = setup();
|
|
185
|
+
s.api.send.mockRejectedValueOnce(Object.assign(new Error('offline'), { status: 0 }));
|
|
186
|
+
await talk(s);
|
|
187
|
+
expect(s.c.getState()).toMatchObject({ phase: 'error', error: STRINGS.failed, retryable: true });
|
|
188
|
+
await s.c.cancel();
|
|
189
|
+
expect(s.removeFile).toHaveBeenCalledWith('file:///r.m4a');
|
|
190
|
+
expect(s.c.getState().phase).toBe('idle');
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('test_a_failed_apply_or_undo_can_be_tried_again', async () => {
|
|
194
|
+
const s = setup({ confirm: 'ask' });
|
|
195
|
+
s.api.send.mockResolvedValueOnce(result({ kind: 'preview', needsConfirm: true, confirmation: null, results: [], clientActionId: 'press-1' }));
|
|
196
|
+
await talk(s);
|
|
197
|
+
s.api.send.mockRejectedValueOnce(Object.assign(new Error('offline'), { status: 0 }));
|
|
198
|
+
await s.c.apply();
|
|
199
|
+
expect(s.c.getState()).toMatchObject({ phase: 'error', retryable: true });
|
|
200
|
+
await s.c.retry();
|
|
201
|
+
expect(s.c.getState().phase).toBe('applied');
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('test_a_conflict_on_apply_says_to_try_again_from_the_top', async () => {
|
|
205
|
+
const s = setup({ confirm: 'ask' });
|
|
206
|
+
s.api.send.mockResolvedValueOnce(result({ kind: 'preview', needsConfirm: true, confirmation: null, results: [], clientActionId: 'press-1' }));
|
|
207
|
+
await talk(s);
|
|
208
|
+
s.api.send.mockRejectedValueOnce(Object.assign(new Error('That reply is no longer waiting. Say it again.'), { status: 409 }));
|
|
209
|
+
await s.c.apply();
|
|
210
|
+
expect(s.c.getState()).toMatchObject({ phase: 'error', error: 'That reply is no longer waiting. Say it again.', retryable: false });
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
describe('carrying on', () => {
|
|
215
|
+
it('test_continue_resumes_the_briefing_after_the_answered_item_and_clears_the_reply', async () => {
|
|
216
|
+
const s = setup();
|
|
217
|
+
await talk(s);
|
|
218
|
+
await s.c.continueBriefing();
|
|
219
|
+
expect(s.speaker.stop).toHaveBeenCalled();
|
|
220
|
+
expect(s.briefing.resumeAfter).toHaveBeenCalledWith('a');
|
|
221
|
+
expect(s.c.getState().phase).toBe('idle');
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('test_pressing_again_cuts_off_the_spoken_confirmation_first', async () => {
|
|
225
|
+
const s = setup();
|
|
226
|
+
await talk(s);
|
|
227
|
+
await s.c.pressStart();
|
|
228
|
+
expect(s.speaker.stop).toHaveBeenCalled();
|
|
229
|
+
});
|
|
230
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import type { BriefingResult } from '../../../corpus/briefing';
|
|
3
|
+
import { createBriefingController } from '../controller';
|
|
4
|
+
import { createAudioPlayer, type AudioPlayerDriver } from '../audioPlayer';
|
|
5
|
+
import type { PlayerState } from '../audioPlayer';
|
|
6
|
+
|
|
7
|
+
const TEXT = 'Good morning. Send the deck. Call Dana. That is everything.';
|
|
8
|
+
const result: BriefingResult = {
|
|
9
|
+
briefingId: 'b1', text: TEXT, audioUrl: '/a',
|
|
10
|
+
items: [{ id: 'a', title: 'Send the deck', kind: 'due_today', group: 'L', dueDate: null }, { id: 'b', title: 'Call Dana', kind: 'due_today', group: 'L', dueDate: null }],
|
|
11
|
+
remaining: 0, context: { itemIds: ['a', 'b'], localDate: '2026-11-05', timeZone: 'UTC', offsets: [{ id: 'a', start: 14, end: 28 }, { id: 'b', start: 29, end: 39 }] }, scriptSource: 'llm', cached: false, ms: 1,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function setup() {
|
|
15
|
+
let ps: PlayerState = { phase: 'idle', positionMillis: 0, durationMillis: 0 };
|
|
16
|
+
const ls = new Set<(s: PlayerState) => void>();
|
|
17
|
+
const emit = (p: Partial<PlayerState>) => { ps = { ...ps, ...p }; ls.forEach((l) => l(ps)); };
|
|
18
|
+
const player = {
|
|
19
|
+
getState: () => ps, subscribe: (cb: (s: PlayerState) => void) => { ls.add(cb); return () => ls.delete(cb); },
|
|
20
|
+
play: vi.fn(async (_s: unknown, _o?: unknown) => { emit({ phase: 'playing', durationMillis: 10_000, positionMillis: 0 }); }),
|
|
21
|
+
stop: vi.fn(async () => { emit({ phase: 'idle' }); }),
|
|
22
|
+
handoffToRecording: vi.fn(async () => { emit({ phase: 'idle', positionMillis: 0 }); }),
|
|
23
|
+
};
|
|
24
|
+
const controller = createBriefingController({
|
|
25
|
+
api: { fetch: async () => result, audioSource: async () => ({ uri: 'http://x/a' }) } as never, player: player as never,
|
|
26
|
+
messages: { failed: 'f', empty: 'e', textOnly: 't', audioFailed: 'a' },
|
|
27
|
+
});
|
|
28
|
+
return { controller, player, emit };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('where the briefing was at the press', () => {
|
|
32
|
+
it('test_the_briefing_id_is_in_the_state_for_the_reply', async () => {
|
|
33
|
+
const s = setup();
|
|
34
|
+
expect(s.controller.getState().briefingId).toBeNull();
|
|
35
|
+
await s.controller.start();
|
|
36
|
+
expect(s.controller.getState().briefingId).toBe('b1');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('test_position_is_taken_from_the_player_and_kept_after_the_handoff_resets_it', async () => {
|
|
40
|
+
const s = setup();
|
|
41
|
+
await s.controller.start();
|
|
42
|
+
s.emit({ positionMillis: 5200 });
|
|
43
|
+
expect(s.controller.snapshotPosition()).toEqual({ seconds: 5.2, durationSeconds: 10 });
|
|
44
|
+
await s.controller.handoffToRecording();
|
|
45
|
+
expect(s.controller.snapshotPosition()).toEqual({ seconds: 5.2, durationSeconds: 10 });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('test_no_position_before_anything_has_played', () => {
|
|
49
|
+
expect(setup().controller.snapshotPosition()).toBeNull();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('test_continue_plays_from_the_item_after_the_answered_one', async () => {
|
|
53
|
+
const s = setup();
|
|
54
|
+
await s.controller.start();
|
|
55
|
+
s.emit({ positionMillis: 3000 });
|
|
56
|
+
s.controller.snapshotPosition();
|
|
57
|
+
await s.controller.handoffToRecording();
|
|
58
|
+
expect(await s.controller.resumeAfter('a')).toBe(true);
|
|
59
|
+
// item b starts at char 29 of 59 -> 49% of 10 s
|
|
60
|
+
expect(s.player.play).toHaveBeenLastCalledWith({ uri: 'http://x/a' }, { startAtMillis: Math.round((29 / 59) * 10_000) });
|
|
61
|
+
expect(s.controller.getState().phase).toBe('playing');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('test_continue_after_the_last_item_has_nothing_left_to_read', async () => {
|
|
65
|
+
const s = setup();
|
|
66
|
+
await s.controller.start();
|
|
67
|
+
s.emit({ positionMillis: 8000 });
|
|
68
|
+
s.controller.snapshotPosition();
|
|
69
|
+
await s.controller.handoffToRecording();
|
|
70
|
+
const calls = s.player.play.mock.calls.length;
|
|
71
|
+
expect(await s.controller.resumeAfter('b')).toBe(false);
|
|
72
|
+
expect(s.player.play.mock.calls.length).toBe(calls);
|
|
73
|
+
expect(s.controller.getState().phase).toBe('ended');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('test_continue_with_no_item_resumes_where_it_was', async () => {
|
|
77
|
+
const s = setup();
|
|
78
|
+
await s.controller.start();
|
|
79
|
+
s.emit({ positionMillis: 3000 });
|
|
80
|
+
s.controller.snapshotPosition();
|
|
81
|
+
await s.controller.handoffToRecording();
|
|
82
|
+
await s.controller.resumeAfter(null);
|
|
83
|
+
expect(s.player.play).toHaveBeenLastCalledWith({ uri: 'http://x/a' }, { startAtMillis: 3000 });
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('the player can start part-way in', () => {
|
|
88
|
+
function player(seek: boolean) {
|
|
89
|
+
const order: string[] = [];
|
|
90
|
+
const driver: AudioPlayerDriver = {
|
|
91
|
+
configureSession: async () => { order.push('configure'); }, load: () => { order.push('load'); },
|
|
92
|
+
play: () => { order.push('play'); }, pause: () => undefined, release: async () => undefined,
|
|
93
|
+
status: () => ({ playing: true, loaded: true, positionMillis: 1, durationMillis: 10_000, ended: false }),
|
|
94
|
+
...(seek ? { seekTo: async (ms: number) => { order.push(`seek ${ms}`); } } : {}),
|
|
95
|
+
};
|
|
96
|
+
const p = createAudioPlayer({
|
|
97
|
+
driver, session: { info: async () => ({ category: 'playback', mode: 'default', options: [], sampleRate: 48000, inputs: [] }), onInterruption: () => () => undefined, onRouteChange: () => () => undefined },
|
|
98
|
+
poll: () => () => undefined, sleep: async () => undefined, diag: { log: () => undefined }, stepTimeoutMs: 30,
|
|
99
|
+
});
|
|
100
|
+
return { p, order };
|
|
101
|
+
}
|
|
102
|
+
it('test_seeks_after_load_and_before_play', async () => {
|
|
103
|
+
const { p, order } = player(true);
|
|
104
|
+
await p.play({ uri: 'x' }, { startAtMillis: 4900 });
|
|
105
|
+
expect(order).toEqual(['configure', 'load', 'seek 4900', 'play']);
|
|
106
|
+
});
|
|
107
|
+
it('test_without_a_start_it_does_not_seek', async () => {
|
|
108
|
+
const { p, order } = player(true);
|
|
109
|
+
await p.play({ uri: 'x' });
|
|
110
|
+
expect(order).toEqual(['configure', 'load', 'play']);
|
|
111
|
+
});
|
|
112
|
+
it('test_a_driver_that_cannot_seek_fails_loudly_rather_than_replaying_from_the_top', async () => {
|
|
113
|
+
const { p } = player(false);
|
|
114
|
+
await expect(p.play({ uri: 'x' }, { startAtMillis: 4900 })).rejects.toThrow(/part-way/);
|
|
115
|
+
});
|
|
116
|
+
});
|