@startsimpli/integrations 0.2.144 → 0.2.146
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 +4 -4
- 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 +102 -0
- 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__/roster.test.ts +27 -0
- package/src/__tests__/tracker-sort.test.ts +28 -0
- package/src/components/index.ts +1 -0
- package/src/components/pages/TaskDetailPage.tsx +33 -2
- package/src/components/pages/TrackerPage.tsx +47 -9
- 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 +16 -18
- package/src/corpus/entities.ts +4 -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 +13 -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
|
@@ -38,6 +38,20 @@ export interface FoundryStrings {
|
|
|
38
38
|
briefingEmpty: string;
|
|
39
39
|
briefingTextOnly: string;
|
|
40
40
|
briefingAudioFailed: string;
|
|
41
|
+
replyTalk: string;
|
|
42
|
+
replyListening: string;
|
|
43
|
+
replySending: string;
|
|
44
|
+
replyApply: string;
|
|
45
|
+
replyCancel: string;
|
|
46
|
+
replyUndo: string;
|
|
47
|
+
replyContinue: string;
|
|
48
|
+
replyHoldToAnswer: string;
|
|
49
|
+
replyTooShort: string;
|
|
50
|
+
replyNotHeard: string;
|
|
51
|
+
replyFailed: string;
|
|
52
|
+
replyRetry: string;
|
|
53
|
+
replyNoAudio: string;
|
|
54
|
+
replyDone: string;
|
|
41
55
|
waiting(n: number): string;
|
|
42
56
|
offlineWaiting(n: number): string;
|
|
43
57
|
}
|
|
@@ -84,6 +98,20 @@ export function foundryStrings(config: Pick<FoundryAppConfig, 'app' | 'brand' |
|
|
|
84
98
|
briefingEmpty: 'Nothing on your plate today.',
|
|
85
99
|
briefingTextOnly: 'The voice is unavailable right now. Here it is as text.',
|
|
86
100
|
briefingAudioFailed: 'Could not play the audio. Here it is as text.',
|
|
101
|
+
replyTalk: 'Hold to reply',
|
|
102
|
+
replyListening: 'Listening... let go to send',
|
|
103
|
+
replySending: 'Understanding...',
|
|
104
|
+
replyApply: 'Do it',
|
|
105
|
+
replyCancel: 'Cancel',
|
|
106
|
+
replyUndo: 'Undo',
|
|
107
|
+
replyContinue: 'Continue',
|
|
108
|
+
replyHoldToAnswer: 'Hold to answer',
|
|
109
|
+
replyTooShort: 'Hold the button while you speak, then let go.',
|
|
110
|
+
replyNotHeard: 'I could not make that out. Try again.',
|
|
111
|
+
replyFailed: 'The reply did not go through. Try again.',
|
|
112
|
+
replyRetry: 'Try again',
|
|
113
|
+
replyNoAudio: 'No audio detected. Check the microphone is not covered.',
|
|
114
|
+
replyDone: 'Done',
|
|
87
115
|
waiting: (n) => `${n} waiting to send`,
|
|
88
116
|
offlineWaiting: (n) => `You are offline. ${n} waiting to send.`,
|
|
89
117
|
};
|
|
@@ -2,19 +2,30 @@ import { View } from 'react-native';
|
|
|
2
2
|
import { Alert, Button, Card, CardContent, Spinner, Text, useHaptics, useTheme } from '@startsimpli/ui-native';
|
|
3
3
|
import { useControllerState } from '../components/useControllerState';
|
|
4
4
|
import type { FoundryStrings } from '../app/strings';
|
|
5
|
+
import { BriefingReply } from './BriefingReply';
|
|
5
6
|
import { transcriptParts, type BriefingController } from './controller';
|
|
7
|
+
import type { BriefingReplyController } from './reply';
|
|
8
|
+
|
|
9
|
+
const NO_STATE = { targetId: null as string | null };
|
|
10
|
+
const NO_REPLY = {
|
|
11
|
+
getState: () => NO_STATE,
|
|
12
|
+
subscribe: () => () => undefined,
|
|
13
|
+
};
|
|
6
14
|
|
|
7
15
|
/**
|
|
8
16
|
* 'What's on the plate' on the GO screen: one button that plays today's spoken briefing, with the transcript while it
|
|
9
17
|
* plays (the item being spoken emphasised), stop and replay, and a plain message instead of a blank card on any failure.
|
|
10
18
|
*/
|
|
11
|
-
export function BriefingCard({ controller, strings }: { controller: BriefingController; strings: FoundryStrings }) {
|
|
19
|
+
export function BriefingCard({ controller, reply, strings }: { controller: BriefingController; /** Hold-to-talk reply; omit for a briefing you can only listen to. */ reply?: BriefingReplyController | null; strings: FoundryStrings }) {
|
|
12
20
|
const theme = useTheme();
|
|
13
21
|
const haptic = useHaptics();
|
|
14
22
|
const s = useControllerState(controller);
|
|
23
|
+
const r = useControllerState(reply ?? NO_REPLY);
|
|
15
24
|
const live = s.phase === 'playing' || s.phase === 'paused';
|
|
16
25
|
const loading = s.phase === 'loading';
|
|
17
26
|
const hasText = s.text.length > 0;
|
|
27
|
+
// While the briefing is silent, the item a reply was about stays marked.
|
|
28
|
+
const marked = s.phase === 'playing' ? s.currentId : (r.targetId ?? s.currentId);
|
|
18
29
|
|
|
19
30
|
return (
|
|
20
31
|
<View style={{ gap: theme.spacing.sm }}>
|
|
@@ -43,7 +54,7 @@ export function BriefingCard({ controller, strings }: { controller: BriefingCont
|
|
|
43
54
|
{s.note ? <Text variant="muted" testID="briefing-note">{s.note}</Text> : null}
|
|
44
55
|
{hasText ? (
|
|
45
56
|
<Text testID="briefing-transcript" accessibilityLabel={s.text}>
|
|
46
|
-
{transcriptParts(s.text, s.offsets,
|
|
57
|
+
{transcriptParts(s.text, s.offsets, marked).map((p, i) => (
|
|
47
58
|
p.current
|
|
48
59
|
? <Text key={i} testID="briefing-current" style={{ fontWeight: '700', color: theme.colors.primary }}>{p.text}</Text>
|
|
49
60
|
: p.text
|
|
@@ -59,6 +70,7 @@ export function BriefingCard({ controller, strings }: { controller: BriefingCont
|
|
|
59
70
|
onPress={() => { haptic('light', 'briefing.replay'); void (s.phase === 'text' ? controller.start() : controller.replay()); }}
|
|
60
71
|
/>
|
|
61
72
|
) : null}
|
|
73
|
+
{reply && hasText && s.briefingId && (live || s.phase === 'ended') ? <BriefingReply controller={reply} strings={strings} /> : null}
|
|
62
74
|
</CardContent>
|
|
63
75
|
</Card>
|
|
64
76
|
)}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { View } from 'react-native';
|
|
2
|
+
import { Alert, Button, Spinner, Text, useHaptics, useTheme } from '@startsimpli/ui-native';
|
|
3
|
+
import { useControllerState } from '../components/useControllerState';
|
|
4
|
+
import type { FoundryStrings } from '../app/strings';
|
|
5
|
+
import type { BriefingReplyController } from './reply';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The reply under the briefing: hold the button to talk, let go to send. Then what it understood (and Do it / Cancel in
|
|
9
|
+
* ask mode), or what it did with Undo and Continue, or the question it needs answered (the next hold answers it).
|
|
10
|
+
*/
|
|
11
|
+
export function BriefingReply({ controller, strings }: { controller: BriefingReplyController; strings: FoundryStrings }) {
|
|
12
|
+
const theme = useTheme();
|
|
13
|
+
const haptic = useHaptics();
|
|
14
|
+
const s = useControllerState(controller);
|
|
15
|
+
const held = s.phase === 'starting' || s.phase === 'recording';
|
|
16
|
+
const busy = s.phase === 'sending';
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<View style={{ gap: theme.spacing.sm }} testID="briefing-reply">
|
|
20
|
+
{busy ? (
|
|
21
|
+
<View style={{ flexDirection: 'row', alignItems: 'center', gap: theme.spacing.sm }} testID="briefing-reply-sending">
|
|
22
|
+
<Spinner />
|
|
23
|
+
<Text variant="muted">{strings.replySending}</Text>
|
|
24
|
+
</View>
|
|
25
|
+
) : (
|
|
26
|
+
<Button
|
|
27
|
+
testID="briefing-talk"
|
|
28
|
+
title={held ? strings.replyListening : s.awaitingAnswer ? strings.replyHoldToAnswer : strings.replyTalk}
|
|
29
|
+
variant={held ? 'primary' : 'outline'}
|
|
30
|
+
size="lg"
|
|
31
|
+
accessibilityLabel={held ? strings.replyListening : s.awaitingAnswer ? strings.replyHoldToAnswer : strings.replyTalk}
|
|
32
|
+
accessibilityHint={strings.replyTooShort}
|
|
33
|
+
onPressIn={() => { haptic('medium', 'briefing.talk'); void controller.pressStart(); }}
|
|
34
|
+
onPressOut={() => { void controller.pressEnd(); }}
|
|
35
|
+
/>
|
|
36
|
+
)}
|
|
37
|
+
{s.utterance && !held ? <Text variant="muted" testID="briefing-heard">{`"${s.utterance}"`}</Text> : null}
|
|
38
|
+
{s.error ? (
|
|
39
|
+
<View style={{ gap: theme.spacing.sm }} testID="briefing-reply-error">
|
|
40
|
+
<Alert variant="destructive">{s.error}</Alert>
|
|
41
|
+
<View style={{ flexDirection: 'row', gap: theme.spacing.sm }}>
|
|
42
|
+
{s.retryable ? <Button testID="briefing-reply-retry" title={strings.replyRetry} variant="outline" onPress={() => { haptic('light', 'briefing.reply-retry'); void controller.retry(); }} /> : null}
|
|
43
|
+
<Button testID="briefing-reply-dismiss" title={strings.replyCancel} variant="outline" onPress={() => { void controller.cancel(); }} />
|
|
44
|
+
</View>
|
|
45
|
+
</View>
|
|
46
|
+
) : null}
|
|
47
|
+
{s.phase === 'preview' ? (
|
|
48
|
+
<View style={{ gap: theme.spacing.sm }} testID="briefing-preview">
|
|
49
|
+
<Text testID="briefing-understood" style={{ fontWeight: '700' }}>{`${s.understood}?`}</Text>
|
|
50
|
+
<View style={{ flexDirection: 'row', gap: theme.spacing.sm }}>
|
|
51
|
+
<Button testID="briefing-apply" title={strings.replyApply} onPress={() => { haptic('success', 'briefing.apply'); void controller.apply(); }} />
|
|
52
|
+
<Button testID="briefing-cancel" title={strings.replyCancel} variant="outline" onPress={() => { void controller.cancel(); }} />
|
|
53
|
+
</View>
|
|
54
|
+
</View>
|
|
55
|
+
) : null}
|
|
56
|
+
{s.phase === 'asked' && s.question ? <Text testID="briefing-question" style={{ fontWeight: '700' }}>{s.question}</Text> : null}
|
|
57
|
+
{s.phase === 'applied' ? (
|
|
58
|
+
<View style={{ gap: theme.spacing.sm }} testID="briefing-applied">
|
|
59
|
+
{s.confirmation ? <Text testID="briefing-confirmation" style={{ fontWeight: '700' }}>{s.confirmation}</Text> : null}
|
|
60
|
+
<View style={{ flexDirection: 'row', gap: theme.spacing.sm }}>
|
|
61
|
+
{s.canUndo ? <Button testID="briefing-undo" title={strings.replyUndo} variant="outline" onPress={() => { haptic('warning', 'briefing.undo'); void controller.undo(); }} /> : null}
|
|
62
|
+
<Button testID="briefing-continue" title={strings.replyContinue} variant="outline" onPress={() => { haptic('light', 'briefing.continue'); void controller.continueBriefing(); }} />
|
|
63
|
+
</View>
|
|
64
|
+
</View>
|
|
65
|
+
) : null}
|
|
66
|
+
</View>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
@@ -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
|
+
});
|