forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_message_content_blocks_test.dart
More file actions
270 lines (246 loc) · 8.68 KB
/
Copy pathserver_message_content_blocks_test.dart
File metadata and controls
270 lines (246 loc) · 8.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import 'package:flutter_test/flutter_test.dart';
import 'package:omi/backend/schema/chat_content_block.dart';
import 'package:omi/backend/schema/message.dart';
void main() {
Map<String, dynamic> messageJson({
required String text,
Object? contentBlocks,
String? metadata,
}) {
return {
'id': 'message-1',
'created_at': '2026-08-18T12:00:00Z',
'text': text,
'sender': 'ai',
'type': 'text',
if (contentBlocks != null) 'content_blocks': contentBlocks,
if (metadata != null) 'metadata': metadata,
};
}
test(
'uses first-class conversation block fallback instead of a blank bubble',
() {
final message = ServerMessage.fromJson(
messageJson(
text: '',
contentBlocks: [
{
'type': 'conversationLink',
'conversationId': 'conversation-1',
'summary': 'Founders explore AI memory',
},
],
),
);
expect(message.text, 'Meeting notes ready - Founders explore AI memory');
expect(message.contentBlocks.single['conversationId'], 'conversation-1');
},
);
test('keeps legacy metadata blocks readable during wire migration', () {
final message = ServerMessage.fromJson(
messageJson(
text: '',
metadata:
'{"content_blocks":[{"type":"conversationLink","conversationId":"conversation-legacy","summary":"Legacy weekly planning"}]}',
),
);
expect(message.text, 'Meeting notes ready - Legacy weekly planning');
expect(
message.contentBlocks.single['conversationId'],
'conversation-legacy',
);
});
test(
'preserves canonical backend fallback text when the client knows the block',
() {
final message = ServerMessage.fromJson(
messageJson(
text: 'Meeting notes ready - Canonical title',
contentBlocks: [
{
'type': 'conversationLink',
'summary': 'Different local rendering',
},
],
),
);
expect(message.text, 'Meeting notes ready - Canonical title');
expect(message.textIsStructuredFallback, isFalse);
},
);
test(
'keeps desktop goal and task chrome on the mobile timeline',
() {
final message = ServerMessage.fromJson(
messageJson(
text: '',
contentBlocks: [
{
'type': 'goalLink',
'id': 'block-goal',
'goalId': 'goal-1',
'summary': 'Make Omi Great Again',
},
{'type': 'taskCard', 'id': 'block-task-1', 'taskId': 'task-1'},
{'type': 'taskCard', 'id': 'block-task-2', 'taskId': 'task-2'},
{'type': 'taskCard', 'id': 'block-task-3', 'taskId': 'task-3'},
],
),
);
expect(message.text, 'Goal - Make Omi Great Again\nTask\nTask\nTask');
// The body is nothing but the synthesized fallback, so the interactive
// components replace it instead of repeating it.
expect(message.textIsStructuredFallback, isTrue);
expect(message.typedContentBlocks, hasLength(4));
expect(message.typedContentBlocks.first, isA<GoalLinkContentBlock>());
expect(message.typedContentBlocks.last, isA<TaskCardContentBlock>());
},
);
test('keeps stored one-line goal/task fallback dumps renderable', () {
final message = ServerMessage.fromJson(
messageJson(
text: 'Goal - Make Omi Great Again Task Task Task',
contentBlocks: [
{'type': 'goalLink', 'id': 'block-goal', 'goalId': 'goal-1', 'summary': 'Make Omi Great Again'},
{'type': 'taskCard', 'id': 'block-task-1', 'taskId': 'task-1'},
{'type': 'taskCard', 'id': 'block-task-2', 'taskId': 'task-2'},
{'type': 'taskCard', 'id': 'block-task-3', 'taskId': 'task-3'},
],
),
);
expect(message.textIsStructuredFallback, isTrue);
expect(message.typedContentBlocks, hasLength(4));
});
test('keeps question cards that have no other content', () {
final message = ServerMessage.fromJson(
messageJson(
text: 'What should we focus on?',
contentBlocks: [
{
'type': 'questionCard',
'id': 'block-question',
'questionId': 'question-1',
'text': 'What should we focus on?',
'subject': {'kind': 'goal', 'id': 'goal-1'},
'options': [
{'optionId': 'a', 'label': 'Ship', 'preparedAnswer': 'Ship'},
],
},
],
),
);
expect(message.textIsStructuredFallback, isTrue);
expect(message.typedContentBlocks.single, isA<QuestionCardContentBlock>());
});
test('keeps meeting-note cards and mixed useful blocks', () {
final meeting = ServerMessage.fromJson(
messageJson(
text: '',
contentBlocks: [
{
'type': 'conversationLink',
'id': 'block-conversation',
'conversationId': 'conversation-1',
'summary': 'Founders explore AI memory',
},
],
),
);
final mixed = ServerMessage.fromJson(
messageJson(
text: 'I started tracking this.',
contentBlocks: [
{'type': 'text', 'id': 'block-text', 'text': 'I started tracking this.'},
{'type': 'goalLink', 'id': 'block-goal', 'goalId': 'goal-1', 'summary': 'Make Omi Great Again'},
],
),
);
final prose = ServerMessage.fromJson(
messageJson(
text: 'Here is a real reply about the weather.',
contentBlocks: [
{'type': 'goalLink', 'id': 'block-goal', 'goalId': 'goal-1', 'summary': 'Make Omi Great Again'},
],
),
);
expect(meeting.typedContentBlocks.single, isA<ConversationLinkContentBlock>());
expect(mixed.typedContentBlocks, hasLength(2));
expect(prose.textIsStructuredFallback, isFalse);
});
test('decodes optional evidence envelope without changing the answer text', () {
final json = messageJson(text: 'The answer stays readable.');
json['evidence'] = {
'schema_version': 1,
'request_id': 'request-1',
'references': [
{
'id': 'summary-1',
'kind': 'conversation_summary',
'state': 'available',
'conversation_id': 'conversation-1',
'title': 'Weekly summary',
},
{
'id': 'frame-1',
'kind': 'keyframe',
'state': 'pruned',
'frame_id': 'frame-1',
},
],
};
final message = ServerMessage.fromJson(json);
expect(message.text, 'The answer stays readable.');
expect(message.evidenceEnvelope?.requestId, 'request-1');
expect(message.evidenceEnvelope?.references, hasLength(2));
expect(message.evidenceEnvelope?.references.last.canOpen, isFalse);
expect(message.toJson()['evidence'], isA<Map<String, dynamic>>());
});
test(
'keeps text readable for loading and offline frame requests',
() {
for (final state in ['loading', 'offline']) {
final json = messageJson(text: 'The answer remains available.');
json['evidence'] = {
'schema_version': 1,
'request_id': 'request-$state',
'references': [
{
'id': 'request-$state',
'kind': 'request',
'state': state,
'request_id': 'request-$state',
},
],
};
expect(() => ServerMessage.fromJson(json), returnsNormally);
final message = ServerMessage.fromJson(json);
expect(message.text, 'The answer remains available.');
expect(message.evidenceEnvelope?.references.single.kind.wireValue, 'request');
expect(message.evidenceEnvelope?.references.single.state.wireValue, state);
expect(message.evidenceEnvelope?.references.single.canOpen, isFalse);
}
},
);
test('ignores malformed or future evidence while preserving legacy text', () {
final malformed = messageJson(text: 'Legacy answer');
malformed['evidence'] = {'schema_version': 1, 'references': 'not-a-list'};
final future = messageJson(text: 'Future answer');
future['evidence'] = {
'schema_version': 99,
'references': [
{
'id': 'future-1',
'kind': 'conversation_summary',
'state': 'available',
'conversation_id': 'conversation-1',
},
],
};
final malformedMessage = ServerMessage.fromJson(malformed);
final futureMessage = ServerMessage.fromJson(future);
expect(malformedMessage.text, 'Legacy answer');
expect(malformedMessage.evidenceEnvelope?.isEmpty, isTrue);
expect(futureMessage.text, 'Future answer');
expect(futureMessage.evidenceEnvelope?.references.single.canOpen, isFalse);
});
}