forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparity_contracts_test.dart
More file actions
211 lines (188 loc) · 9.23 KB
/
Copy pathparity_contracts_test.dart
File metadata and controls
211 lines (188 loc) · 9.23 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
import 'dart:convert';
import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:omi/backend/schema/conversation.dart';
import 'package:omi/backend/schema/gen/action_items_folders_wire.g.dart';
import 'package:omi/backend/schema/memory.dart';
import 'package:omi/backend/schema/structured.dart';
import 'package:omi/backend/schema/transcript_segment.dart';
import 'package:omi/models/chat_evidence_reference.dart';
import 'package:omi/pages/action_items/task_categorization.dart';
import 'package:omi/providers/conversation_provider.dart';
/// Flutter conformance suite for the shared cross-platform parity contracts
/// (contracts/parity/README.md). Runs the repo-root fixture vectors through the
/// REAL production rules: task bucketing (categorizeTasks, this platform's
/// separate_overdue model), local-day conversation keys
/// (conversationLocalDayKey, the #10198 contract), action item wire decode
/// (GeneratedActionItemResponse.fromJson), and conversation duration
/// (ServerConversation.getDurationInSeconds, the #4056 contract). Day-key cases execute only when the
/// fixture covers the runner's zone offset at that instant; offset 0 is always
/// present so UTC CI runs every case.
void main() {
final root = _repoRoot();
group('additive JIT mixed-version runtime contract', () {
final fixture = _fixture(root, 'jit_runtime_contract_matrix.json');
final expected = fixture['expected'] as Map<String, dynamic>;
test('mobile keeps mixed memory text readable and grants only v1 ledger authority', () {
final memories = (fixture['memory_rows'] as List<dynamic>)
.map((row) => Memory.fromJson(Map<String, dynamic>.from(row as Map)))
.toList(growable: false);
expect(memories.map((memory) => memory.id), expected['memory_ids']);
expect({for (final memory in memories) memory.id: memory.content}, expected['readable_text_by_id']);
expect(
memories.where((memory) => memory.isKnowledgeLedger).map((memory) => memory.id),
expected['authoritative_ledger_ids'],
);
});
test('mobile leaves legacy evidence optional and makes future evidence inert', () {
final records = fixture['chat_records'] as Map<String, dynamic>;
expect(
ChatEvidenceReferenceEnvelope.tryFromJson((records['legacy'] as Map<String, dynamic>)['evidence']),
isNull,
);
final current = ChatEvidenceReferenceEnvelope.tryFromJson((records['v1'] as Map<String, dynamic>)['evidence']);
final future = ChatEvidenceReferenceEnvelope.tryFromJson((records['future'] as Map<String, dynamic>)['evidence']);
expect(current?.references.single.kind.wireValue, expected['v1_evidence_kind']);
expect(future?.references.single.kind.wireValue, expected['future_evidence_kind']);
expect(future?.references.single.state.wireValue, expected['future_evidence_state']);
expect((records['future'] as Map<String, dynamic>)['text'], isNotEmpty);
});
});
group('task due buckets (separate_overdue model)', () {
final fixture = _fixture(root, 'task_due_buckets.json');
const bucketByName = {
'today': TaskCategory.today,
'tomorrow': TaskCategory.tomorrow,
'later': TaskCategory.later,
'no_deadline': TaskCategory.noDeadline,
'overdue': TaskCategory.overdue,
};
for (final raw in fixture['cases'] as List<dynamic>) {
final c = raw as Map<String, dynamic>;
test(c['name'] as String, () {
final now = _localFromComponents(c['now'] as List<dynamic>);
final due = c['due'] == null ? null : _localFromComponents(c['due'] as List<dynamic>);
final created = c['created'] == null ? null : _localFromComponents(c['created'] as List<dynamic>);
final item = _wireItem(due: due, created: created);
final categorized = categorizeTasks([item], false, now: now);
final actual = categorized.entries.where((e) => e.value.contains(item)).map((e) => e.key).toList();
final expectedName = (c['expected'] as Map<String, dynamic>)['separate_overdue'] as String;
expect(actual, [bucketByName[expectedName]!]);
});
}
});
group('local day keys', () {
final fixture = _fixture(root, 'day_keys.json');
for (final raw in fixture['cases'] as List<dynamic>) {
final c = raw as Map<String, dynamic>;
final instant = DateTime.parse(c['utc'] as String);
final offsetEast = instant.toLocal().timeZoneOffset.inMinutes;
final expected = (c['expected_by_offset'] as Map<String, dynamic>)['$offsetEast'] as String?;
test('${c['name']} (offset $offsetEast)', () {
final key = conversationLocalDayKey(instant);
expect('${key.year}-${_pad(key.month)}-${_pad(key.day)}', expected);
}, skip: expected == null ? 'fixture does not cover this zone offset' : false);
}
});
group('conversation duration (parity contract)', () {
final fixture = _fixture(root, 'conversation_duration.json');
for (final raw in fixture['cases'] as List<dynamic>) {
final c = raw as Map<String, dynamic>;
test(c['name'] as String, () {
final conversation = _durationConversation(c);
expect(conversation.getDurationInSeconds(), c['expected_seconds']);
});
}
});
group('action item wire decode (parity contract)', () {
final fixture = _fixture(root, 'wire_action_item.json');
for (final raw in fixture['cases'] as List<dynamic>) {
final c = raw as Map<String, dynamic>;
test(c['name'] as String, () {
final byModel = c['expected_by_model'] as Map<String, dynamic>?;
if (byModel != null) {
// This client is the strict_decode model: a present-but-unparseable
// due_at rejects the whole item (see the README divergence register).
final strict = byModel['strict_decode'] as Map<String, dynamic>;
expect(strict['parses'], isFalse);
expect(
() => GeneratedActionItemResponse.fromJson(c['payload'] as Map<String, dynamic>),
throwsFormatException,
);
return;
}
final expected = c['expected'] as Map<String, dynamic>;
final item = GeneratedActionItemResponse.fromJson(c['payload'] as Map<String, dynamic>);
expect(expected['parses'], isTrue);
expect(item.description, expected['description']);
expect(item.completed, expected['completed']);
final dueUtc = expected['due_utc'] as String?;
if (dueUtc == null) {
expect(item.dueAt, isNull);
} else {
expect(item.dueAt?.millisecondsSinceEpoch, DateTime.parse(dueUtc).millisecondsSinceEpoch);
}
});
}
});
}
/// Walk up from the package dir to the repo root (the dir holding
/// contracts/parity), so the suite works from either the app dir or repo root.
Directory _repoRoot() {
var dir = Directory.current.absolute;
for (var i = 0; i < 6; i++) {
if (Directory('${dir.path}${Platform.pathSeparator}contracts${Platform.pathSeparator}parity').existsSync()) {
return dir;
}
final parent = dir.parent;
if (parent.path == dir.path) break;
dir = parent;
}
throw StateError('contracts/parity not found above ${Directory.current.path}');
}
Map<String, dynamic> _fixture(Directory root, String name) {
final file = File(
'${root.path}${Platform.pathSeparator}contracts${Platform.pathSeparator}parity'
'${Platform.pathSeparator}$name',
);
return jsonDecode(file.readAsStringSync()) as Map<String, dynamic>;
}
/// Fixture local-time components [year, month, day, hour?, minute?] in the
/// runner's zone (the contracts are calendar rules, zone-independent).
DateTime _localFromComponents(List<dynamic> c) =>
DateTime(c[0] as int, c[1] as int, c[2] as int, c.length > 3 ? c[3] as int : 0, c.length > 4 ? c[4] as int : 0);
String _pad(int n) => n.toString().padLeft(2, '0');
/// Build the item through the production wire decode so bucket cases exercise
/// the same path a backend response takes.
GeneratedActionItemResponse _wireItem({DateTime? due, DateTime? created}) => GeneratedActionItemResponse.fromJson({
'id': 'parity',
'description': 'parity case',
'completed': false,
if (created != null) 'created_at': created.toUtc().toIso8601String(),
if (due != null) 'due_at': due.toUtc().toIso8601String(),
});
/// Build the conversation through the production model so duration cases
/// exercise the same getter the conversation list and detail header read.
ServerConversation _durationConversation(Map<String, dynamic> c) {
final segments = (c['segments'] as List<dynamic>).asMap().entries.map((entry) {
final segment = entry.value as Map<String, dynamic>;
return TranscriptSegment(
id: 'seg-${entry.key}',
text: segment['text'] as String,
speaker: 'SPEAKER_00',
isUser: true,
personId: null,
start: (segment['start'] as num).toDouble(),
end: (segment['end'] as num).toDouble(),
translations: [],
);
}).toList();
return ServerConversation(
id: c['name'] as String,
createdAt: DateTime.utc(2026, 1, 1),
structured: Structured('Parity', 'Parity'),
transcriptSegments: segments,
startedAt: c['started_at'] == null ? null : DateTime.parse(c['started_at'] as String),
finishedAt: c['finished_at'] == null ? null : DateTime.parse(c['finished_at'] as String),
);
}