@_nazmiforreal/flutter-ota 0.1.2 → 0.1.4
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/dart-src/packages/cli-tools/.dart_tool/package_config.json +496 -0
- package/dart-src/packages/cli-tools/.dart_tool/package_graph.json +743 -0
- package/dart-src/packages/cli-tools/lib/src/cli_base.dart +7 -6
- package/dart-src/packages/cli-tools/lib/src/commands/build.dart +46 -49
- package/dart-src/packages/cli-tools/lib/src/commands/bundle.dart +44 -23
- package/dart-src/packages/cli-tools/lib/src/commands/channel.dart +27 -17
- package/dart-src/packages/cli-tools/lib/src/commands/console.dart +11 -6
- package/dart-src/packages/cli-tools/lib/src/commands/deploy.dart +39 -22
- package/dart-src/packages/cli-tools/lib/src/commands/doctor.dart +22 -13
- package/dart-src/packages/cli-tools/lib/src/commands/init.dart +117 -36
- package/dart-src/packages/cli-tools/lib/src/commands/keys.dart +15 -9
- package/dart-src/packages/cli-tools/lib/src/commands/migrate.dart +14 -8
- package/dart-src/packages/cli-tools/lib/src/commands/rollback.dart +37 -12
- package/dart-src/packages/cli-tools/lib/src/config.dart +13 -3
- package/dart-src/packages/cli-tools/lib/src/operations.dart +45 -0
- package/dart-src/packages/cli-tools/lib/src/pack.dart +9 -0
- package/dart-src/packages/cli-tools/lib/src/ui/ui.dart +234 -0
- package/dart-src/packages/cli-tools/pubspec.lock +638 -0
- package/dart-src/packages/cli-tools/test/backends_test.dart +207 -0
- package/dart-src/packages/cli-tools/test/build_pack_test.dart +101 -0
- package/dart-src/packages/cli-tools/test/cli_test.dart +442 -0
- package/dart-src/packages/cli-tools/test/mocks/mock_aws_s3_client.dart +83 -0
- package/dart-src/packages/cli-tools/test/mocks/mock_d1_client.dart +256 -0
- package/dart-src/packages/cli-tools/test/mocks/mock_postgres_client.dart +347 -0
- package/dart-src/packages/cli-tools/test/standalone_backend_test.dart +315 -0
- package/dart-src/packages/core/test/rollout_test.dart +128 -0
- package/dart-src/packages/core/test/semver_test.dart +52 -0
- package/dart-src/packages/core/test/semver_vectors.json +1 -0
- package/dart-src/packages/core/test/types_test.dart +129 -0
- package/dart-src/packages/core/test/uuid_test.dart +38 -0
- package/dart-src/plugins/aws/test/aws_database_test.dart +167 -0
- package/dart-src/plugins/aws/test/aws_lambda_edge_storage_test.dart +190 -0
- package/dart-src/plugins/aws/test/aws_storage_test.dart +73 -0
- package/dart-src/plugins/aws/test/mock_aws_s3_client.dart +83 -0
- package/dart-src/plugins/cloudflare/test/cloudflare_worker_database_test.dart +122 -0
- package/dart-src/plugins/cloudflare/test/d1_bundle_mapper_test.dart +106 -0
- package/dart-src/plugins/cloudflare/test/d1_database_test.dart +190 -0
- package/dart-src/plugins/cloudflare/test/mock_d1_client.dart +256 -0
- package/dart-src/plugins/cloudflare/test/mock_r2_client.dart +83 -0
- package/dart-src/plugins/cloudflare/test/r2_storage_test.dart +77 -0
- package/dart-src/plugins/plugin-core/test/asset_storage_layout_test.dart +166 -0
- package/dart-src/plugins/plugin-core/test/bundle_unit_of_work_store_test.dart +74 -0
- package/dart-src/plugins/plugin-core/test/bundle_unit_of_work_test.dart +332 -0
- package/dart-src/plugins/plugin-core/test/create_blob_database_plugin_test.dart +711 -0
- package/dart-src/plugins/plugin-core/test/create_database_plugin_test.dart +294 -0
- package/dart-src/plugins/plugin-core/test/create_storage_plugin_test.dart +192 -0
- package/dart-src/plugins/plugin-core/test/generate_min_bundle_id_test.dart +51 -0
- package/dart-src/plugins/plugin-core/test/get_update_info_test.dart +1600 -0
- package/dart-src/plugins/plugin-core/test/helpers_test.dart +259 -0
- package/dart-src/plugins/plugin-core/test/query_bundles_test.dart +139 -0
- package/dart-src/plugins/plugin-core/test/request_update_bundle_state_test.dart +86 -0
- package/dart-src/plugins/plugin-core/test/uuidv7_test.dart +77 -0
- package/dart-src/plugins/postgres/test/mock_postgres_client.dart +297 -0
- package/dart-src/plugins/postgres/test/postgres_bundle_mapper_test.dart +140 -0
- package/dart-src/plugins/postgres/test/postgres_database_test.dart +181 -0
- package/dart-src/plugins/standalone/test/standalone_test.dart +264 -0
- package/dart-src/plugins/supabase/test/mock_supabase_client.dart +654 -0
- package/dart-src/plugins/supabase/test/supabase_bundle_mapper_test.dart +112 -0
- package/dart-src/plugins/supabase/test/supabase_database_test.dart +207 -0
- package/dart-src/plugins/supabase/test/supabase_storage_test.dart +175 -0
- package/package.json +1 -1
- package/scripts/vendor.sh +29 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import 'package:flutter_patcher_core/flutter_patcher_core.dart'
|
|
2
|
+
show Bundle, BundleMetadata, Platform;
|
|
3
|
+
import 'package:flutter_patcher_plugin_core/flutter_patcher_plugin_core.dart';
|
|
4
|
+
import 'package:test/test.dart';
|
|
5
|
+
|
|
6
|
+
void main() {
|
|
7
|
+
group('paginateBundles', () {
|
|
8
|
+
List<Bundle> makeBundles(int count) =>
|
|
9
|
+
List.generate(count, (i) => _testBundle(id: 'b-${i.toString().padLeft(3, '0')}'));
|
|
10
|
+
|
|
11
|
+
test('offset-based first page', () {
|
|
12
|
+
final result = paginateBundles(bundles: makeBundles(25), limit: 10, offset: 0);
|
|
13
|
+
expect(result.data.length, 10);
|
|
14
|
+
expect(result.pagination.total, 25);
|
|
15
|
+
expect(result.pagination.hasNextPage, isTrue);
|
|
16
|
+
expect(result.pagination.hasPreviousPage, isFalse);
|
|
17
|
+
expect(result.pagination.currentPage, 1);
|
|
18
|
+
expect(result.pagination.nextCursor, isNotNull);
|
|
19
|
+
expect(result.pagination.previousCursor, isNull);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('offset-based last page', () {
|
|
23
|
+
final result = paginateBundles(bundles: makeBundles(25), limit: 10, offset: 20);
|
|
24
|
+
expect(result.data.length, 5);
|
|
25
|
+
expect(result.pagination.hasNextPage, isFalse);
|
|
26
|
+
expect(result.pagination.hasPreviousPage, isTrue);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('cursor-based after', () {
|
|
30
|
+
final result = paginateBundles(
|
|
31
|
+
bundles: makeBundles(10),
|
|
32
|
+
limit: 3,
|
|
33
|
+
cursor: const DatabaseBundleCursor(after: 'b-004'),
|
|
34
|
+
);
|
|
35
|
+
// Sorted desc: b-009..b-000. After b-004 (id < 'b-004'): b-003, b-002, b-001, b-000
|
|
36
|
+
expect(result.data.length, 3);
|
|
37
|
+
expect(result.data.first.id, 'b-003');
|
|
38
|
+
expect(result.data.last.id, 'b-001');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('cursor-based before', () {
|
|
42
|
+
final result = paginateBundles(
|
|
43
|
+
bundles: makeBundles(10),
|
|
44
|
+
limit: 3,
|
|
45
|
+
cursor: const DatabaseBundleCursor(before: 'b-005'),
|
|
46
|
+
);
|
|
47
|
+
// Before b-005 in desc: candidates id > b-005 = [b-009, b-008, b-007, b-006]
|
|
48
|
+
// Take last 3 (closest to cursor): b-008, b-007, b-006
|
|
49
|
+
expect(result.data.length, 3);
|
|
50
|
+
expect(result.data.first.id, 'b-008');
|
|
51
|
+
expect(result.data.last.id, 'b-006');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('empty result preserves cursor', () {
|
|
55
|
+
final result = paginateBundles(
|
|
56
|
+
bundles: makeBundles(5),
|
|
57
|
+
limit: 10,
|
|
58
|
+
cursor: const DatabaseBundleCursor(after: 'b-000'),
|
|
59
|
+
);
|
|
60
|
+
// Desc sorted: b-004, b-003, b-002, b-001, b-000
|
|
61
|
+
// after 'b-000': nothing has id < 'b-000' → empty, previousCursor preserved
|
|
62
|
+
expect(result.data, isEmpty);
|
|
63
|
+
expect(result.pagination.previousCursor, 'b-000');
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
group('filterCompatibleAppVersions', () {
|
|
68
|
+
test('filters and sorts descending', () {
|
|
69
|
+
final result = filterCompatibleAppVersions(
|
|
70
|
+
['^1.0.0', '^2.0.0', '^0.5.0'],
|
|
71
|
+
'1.3.0',
|
|
72
|
+
);
|
|
73
|
+
expect(result, ['^1.0.0']);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('multiple compatible versions sorted desc', () {
|
|
77
|
+
final result = filterCompatibleAppVersions(
|
|
78
|
+
['>=1.0.0', '>=1.2.0', '>=2.0.0'],
|
|
79
|
+
'1.5.0',
|
|
80
|
+
);
|
|
81
|
+
expect(result, ['>=1.2.0', '>=1.0.0']);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
group('parseStorageUri', () {
|
|
86
|
+
test('parses supabase-storage URI', () {
|
|
87
|
+
final result = parseStorageUri(
|
|
88
|
+
'supabase-storage://bucket/path/to/file.zip',
|
|
89
|
+
'supabase-storage',
|
|
90
|
+
);
|
|
91
|
+
expect(result.protocol, 'supabase-storage');
|
|
92
|
+
expect(result.bucket, 'bucket');
|
|
93
|
+
expect(result.key, 'path/to/file.zip');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('parses s3 URI', () {
|
|
97
|
+
final result = parseStorageUri('s3://my-bucket/key.zip', 's3');
|
|
98
|
+
expect(result.bucket, 'my-bucket');
|
|
99
|
+
expect(result.key, 'key.zip');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('decodes percent-encoded keys', () {
|
|
103
|
+
final result = parseStorageUri(
|
|
104
|
+
'supabase-storage://bucket/path%20with%20spaces/file.zip',
|
|
105
|
+
'supabase-storage',
|
|
106
|
+
);
|
|
107
|
+
expect(result.key, 'path with spaces/file.zip');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('throws on wrong protocol', () {
|
|
111
|
+
expect(
|
|
112
|
+
() => parseStorageUri('s3://bucket/key', 'supabase-storage'),
|
|
113
|
+
throwsFormatException,
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
group('contentAddressedAssets', () {
|
|
119
|
+
test('builds sha256 path with extension', () {
|
|
120
|
+
final path = getContentAddressedAssetStoragePath(
|
|
121
|
+
assetPath: 'index.android.bundle',
|
|
122
|
+
fileHash: 'abcdef1234567890',
|
|
123
|
+
);
|
|
124
|
+
expect(path, 'sha256/ab/abcdef1234567890.bundle');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('preserves .br extension', () {
|
|
128
|
+
final path = getContentAddressedAssetStoragePath(
|
|
129
|
+
assetPath: 'index.android.bundle.br',
|
|
130
|
+
fileHash: 'abcdef1234567890',
|
|
131
|
+
);
|
|
132
|
+
expect(path, 'sha256/ab/abcdef1234567890.br');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('handles no extension', () {
|
|
136
|
+
final path = getContentAddressedAssetStoragePath(
|
|
137
|
+
assetPath: 'manifest',
|
|
138
|
+
fileHash: 'abcdef1234567890',
|
|
139
|
+
);
|
|
140
|
+
expect(path, 'sha256/ab/abcdef1234567890');
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
group('compressionFormat', () {
|
|
145
|
+
test('detects zip', () {
|
|
146
|
+
expect(detectCompressionFormat('bundle.zip').format, CompressionFormat.zip);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('detects tar.br', () {
|
|
150
|
+
expect(detectCompressionFormat('bundle.tar.br').format, CompressionFormat.tarBr);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('detects tar.gz', () {
|
|
154
|
+
expect(detectCompressionFormat('bundle.tar.gz').format, CompressionFormat.tarGz);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test('defaults to zip', () {
|
|
158
|
+
expect(detectCompressionFormat('bundle.xyz').format, CompressionFormat.zip);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('getContentType returns mime type for zip', () {
|
|
162
|
+
expect(getContentType('bundle.zip'), 'application/zip');
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
group('storageProfile', () {
|
|
167
|
+
test('isNodeStoragePlugin checks profiles.node', () {
|
|
168
|
+
final plugin = _DummyStoragePlugin(node: true, runtime: false);
|
|
169
|
+
expect(isNodeStoragePlugin(plugin), isTrue);
|
|
170
|
+
expect(isRuntimeStoragePlugin(plugin), isFalse);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('isRuntimeStoragePlugin checks profiles.runtime', () {
|
|
174
|
+
final plugin = _DummyStoragePlugin(node: false, runtime: true);
|
|
175
|
+
expect(isNodeStoragePlugin(plugin), isFalse);
|
|
176
|
+
expect(isRuntimeStoragePlugin(plugin), isTrue);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('assertNodeStoragePlugin throws if missing', () {
|
|
180
|
+
final plugin = _DummyStoragePlugin(node: false, runtime: true);
|
|
181
|
+
expect(() => assertNodeStoragePlugin(plugin), throwsStateError);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
group('createStorageKeyBuilder', () {
|
|
186
|
+
test('with base path', () {
|
|
187
|
+
final getKey = createStorageKeyBuilder('bundles');
|
|
188
|
+
expect(getKey('v1', 'patch.zip'), 'bundles/v1/patch.zip');
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('without base path', () {
|
|
192
|
+
final getKey = createStorageKeyBuilder(null);
|
|
193
|
+
expect(getKey('v1', 'file.zip'), 'v1/file.zip');
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
Bundle _testBundle({String id = 'test-bundle-id'}) {
|
|
199
|
+
return Bundle(
|
|
200
|
+
id: id,
|
|
201
|
+
channel: 'production',
|
|
202
|
+
platform: Platform.android,
|
|
203
|
+
enabled: true,
|
|
204
|
+
shouldForceUpdate: false,
|
|
205
|
+
fileHash: 'abc123',
|
|
206
|
+
gitCommitHash: null,
|
|
207
|
+
message: null,
|
|
208
|
+
targetAppVersion: '1.0.0',
|
|
209
|
+
fingerprintHash: null,
|
|
210
|
+
storageUri: 'supabase-storage://bucket/path',
|
|
211
|
+
metadata: const BundleMetadata(),
|
|
212
|
+
patches: const [],
|
|
213
|
+
rolloutCohortCount: 1000,
|
|
214
|
+
targetCohorts: null,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
class _DummyStoragePlugin extends StoragePlugin {
|
|
219
|
+
_DummyStoragePlugin({required bool node, required bool runtime})
|
|
220
|
+
: _node = node,
|
|
221
|
+
_runtime = runtime;
|
|
222
|
+
|
|
223
|
+
final bool _node;
|
|
224
|
+
final bool _runtime;
|
|
225
|
+
|
|
226
|
+
@override
|
|
227
|
+
String get name => 'dummy';
|
|
228
|
+
|
|
229
|
+
@override
|
|
230
|
+
String get supportedProtocol => 'dummy';
|
|
231
|
+
|
|
232
|
+
@override
|
|
233
|
+
StoragePluginProfiles get profiles => StoragePluginProfiles(
|
|
234
|
+
node: _node ? _DummyNodeStorageProfile() : null,
|
|
235
|
+
runtime: _runtime ? _DummyRuntimeStorageProfile() : null,
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
class _DummyNodeStorageProfile extends NodeStorageProfile {
|
|
240
|
+
@override
|
|
241
|
+
Future<Map<String, String>> upload(String key, String filePath) async => {};
|
|
242
|
+
@override
|
|
243
|
+
Future<bool> exists(String storageUri) async => false;
|
|
244
|
+
@override
|
|
245
|
+
Future<void> delete(String storageUri) async {}
|
|
246
|
+
@override
|
|
247
|
+
Future<void> downloadFile(String storageUri, String filePath) async {}
|
|
248
|
+
@override
|
|
249
|
+
Future<List<StorageObject>> listObjects([String? prefix]) async => [];
|
|
250
|
+
@override
|
|
251
|
+
Future<void> deleteObjects(List<String> keys) async {}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
class _DummyRuntimeStorageProfile extends RuntimeStorageProfile {
|
|
255
|
+
@override
|
|
256
|
+
Future<Map<String, String>> getDownloadUrl(String storageUri) async => {};
|
|
257
|
+
@override
|
|
258
|
+
Future<String?> readText(String storageUri) async => null;
|
|
259
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import 'package:flutter_patcher_core/flutter_patcher_core.dart'
|
|
2
|
+
show Bundle, BundleMetadata, Platform;
|
|
3
|
+
import 'package:flutter_patcher_plugin_core/flutter_patcher_plugin_core.dart';
|
|
4
|
+
import 'package:test/test.dart';
|
|
5
|
+
|
|
6
|
+
void main() {
|
|
7
|
+
group('calculatePagination', () {
|
|
8
|
+
test('empty total', () {
|
|
9
|
+
final p = calculatePagination(0, limit: 10, offset: 0);
|
|
10
|
+
expect(p.total, 0);
|
|
11
|
+
expect(p.hasNextPage, isFalse);
|
|
12
|
+
expect(p.hasPreviousPage, isFalse);
|
|
13
|
+
expect(p.currentPage, 1);
|
|
14
|
+
expect(p.totalPages, 0);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('first page', () {
|
|
18
|
+
final p = calculatePagination(25, limit: 10, offset: 0);
|
|
19
|
+
expect(p.total, 25);
|
|
20
|
+
expect(p.hasNextPage, isTrue);
|
|
21
|
+
expect(p.hasPreviousPage, isFalse);
|
|
22
|
+
expect(p.currentPage, 1);
|
|
23
|
+
expect(p.totalPages, 3);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('middle page', () {
|
|
27
|
+
final p = calculatePagination(25, limit: 10, offset: 10);
|
|
28
|
+
expect(p.currentPage, 2);
|
|
29
|
+
expect(p.hasNextPage, isTrue);
|
|
30
|
+
expect(p.hasPreviousPage, isTrue);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('last page', () {
|
|
34
|
+
final p = calculatePagination(25, limit: 10, offset: 20);
|
|
35
|
+
expect(p.currentPage, 3);
|
|
36
|
+
expect(p.hasNextPage, isFalse);
|
|
37
|
+
expect(p.hasPreviousPage, isTrue);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
group('bundleIdMatchesFilter', () {
|
|
42
|
+
test('null filter matches all', () {
|
|
43
|
+
expect(bundleIdMatchesFilter('abc', null), isTrue);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('eq match', () {
|
|
47
|
+
expect(bundleIdMatchesFilter('abc', const DatabaseBundleIdFilter(eq: 'abc')), isTrue);
|
|
48
|
+
expect(bundleIdMatchesFilter('abc', const DatabaseBundleIdFilter(eq: 'def')), isFalse);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('gt match', () {
|
|
52
|
+
expect(bundleIdMatchesFilter('b', const DatabaseBundleIdFilter(gt: 'a')), isTrue);
|
|
53
|
+
expect(bundleIdMatchesFilter('a', const DatabaseBundleIdFilter(gt: 'b')), isFalse);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('in match', () {
|
|
57
|
+
expect(bundleIdMatchesFilter('a', const DatabaseBundleIdFilter(ins: ['a', 'b'])), isTrue);
|
|
58
|
+
expect(bundleIdMatchesFilter('c', const DatabaseBundleIdFilter(ins: ['a', 'b'])), isFalse);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('combined filters', () {
|
|
62
|
+
final f = DatabaseBundleIdFilter(gte: 'a', lte: 'z');
|
|
63
|
+
expect(bundleIdMatchesFilter('m', f), isTrue);
|
|
64
|
+
expect(bundleIdMatchesFilter('0', f), isFalse);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
group('bundleMatchesQueryWhere', () {
|
|
69
|
+
test('null where matches all', () {
|
|
70
|
+
final bundle = _testBundle(channel: 'prod');
|
|
71
|
+
expect(bundleMatchesQueryWhere(bundle, null), isTrue);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('filters by channel', () {
|
|
75
|
+
final bundle = _testBundle(channel: 'prod');
|
|
76
|
+
expect(bundleMatchesQueryWhere(bundle, const DatabaseBundleQueryWhere(channel: 'prod')), isTrue);
|
|
77
|
+
expect(bundleMatchesQueryWhere(bundle, const DatabaseBundleQueryWhere(channel: 'dev')), isFalse);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('filters by enabled', () {
|
|
81
|
+
final bundle = _testBundle(enabled: true);
|
|
82
|
+
expect(bundleMatchesQueryWhere(bundle, const DatabaseBundleQueryWhere(enabled: true)), isTrue);
|
|
83
|
+
expect(bundleMatchesQueryWhere(bundle, const DatabaseBundleQueryWhere(enabled: false)), isFalse);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('filters by targetAppVersion null', () {
|
|
87
|
+
final bundle = _testBundle(targetAppVersion: null);
|
|
88
|
+
expect(bundleMatchesQueryWhere(bundle, const DatabaseBundleQueryWhere(targetAppVersionNotNull: true)), isFalse);
|
|
89
|
+
expect(bundleMatchesQueryWhere(bundle, const DatabaseBundleQueryWhere(targetAppVersionNotNull: false)), isTrue);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
group('sortBundles', () {
|
|
94
|
+
test('sorts descending by default', () {
|
|
95
|
+
final bundles = [
|
|
96
|
+
_testBundle(id: 'c'),
|
|
97
|
+
_testBundle(id: 'a'),
|
|
98
|
+
_testBundle(id: 'b'),
|
|
99
|
+
];
|
|
100
|
+
final sorted = sortBundles(bundles, null);
|
|
101
|
+
expect(sorted.map((b) => b.id).toList(), ['c', 'b', 'a']);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('sorts ascending', () {
|
|
105
|
+
final bundles = [
|
|
106
|
+
_testBundle(id: 'c'),
|
|
107
|
+
_testBundle(id: 'a'),
|
|
108
|
+
_testBundle(id: 'b'),
|
|
109
|
+
];
|
|
110
|
+
final sorted = sortBundles(bundles, const DatabaseBundleQueryOrder(direction: 'asc'));
|
|
111
|
+
expect(sorted.map((b) => b.id).toList(), ['a', 'b', 'c']);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
Bundle _testBundle({
|
|
117
|
+
String id = 'test-bundle-id',
|
|
118
|
+
String channel = 'production',
|
|
119
|
+
bool enabled = true,
|
|
120
|
+
String? targetAppVersion = '1.0.0',
|
|
121
|
+
}) {
|
|
122
|
+
return Bundle(
|
|
123
|
+
id: id,
|
|
124
|
+
channel: channel,
|
|
125
|
+
platform: Platform.android,
|
|
126
|
+
enabled: enabled,
|
|
127
|
+
shouldForceUpdate: false,
|
|
128
|
+
fileHash: 'abc123',
|
|
129
|
+
gitCommitHash: null,
|
|
130
|
+
message: null,
|
|
131
|
+
targetAppVersion: targetAppVersion,
|
|
132
|
+
fingerprintHash: null,
|
|
133
|
+
storageUri: 'supabase-storage://bucket/path',
|
|
134
|
+
metadata: const BundleMetadata(),
|
|
135
|
+
patches: const [],
|
|
136
|
+
rolloutCohortCount: 1000,
|
|
137
|
+
targetCohorts: null,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import 'package:flutter_patcher_core/flutter_patcher_core.dart';
|
|
2
|
+
import 'package:flutter_patcher_plugin_core/src/bundle_unit_of_work_store.dart';
|
|
3
|
+
import 'package:flutter_patcher_plugin_core/src/request_update_bundle_state.dart';
|
|
4
|
+
import 'package:test/test.dart';
|
|
5
|
+
|
|
6
|
+
Bundle _bundle(String id) => Bundle(
|
|
7
|
+
id: id,
|
|
8
|
+
platform: Platform.android,
|
|
9
|
+
shouldForceUpdate: false,
|
|
10
|
+
enabled: true,
|
|
11
|
+
fileHash: 'hash_$id',
|
|
12
|
+
storageUri: 's3://bucket/$id.zip',
|
|
13
|
+
channel: 'production',
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
void main() {
|
|
17
|
+
setUp(() {
|
|
18
|
+
clearUnitOfWorkStore();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
group('seedRequestUpdateBundles', () {
|
|
22
|
+
test('seeds bundles into context UoW', () {
|
|
23
|
+
final context = <String, Object?>{};
|
|
24
|
+
seedRequestUpdateBundles(context, [_bundle('a'), _bundle('b')]);
|
|
25
|
+
final seeds = getRequestUpdateBundleSeeds(context);
|
|
26
|
+
expect(seeds.length, 2);
|
|
27
|
+
expect(seeds.map((b) => b.id).toSet(), {'a', 'b'});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('ignores null context', () {
|
|
31
|
+
seedRequestUpdateBundles(null, [_bundle('a')]);
|
|
32
|
+
// Should not throw
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('ignores empty seeds', () {
|
|
36
|
+
final context = <String, Object?>{};
|
|
37
|
+
seedRequestUpdateBundles(context, [null]);
|
|
38
|
+
final seeds = getRequestUpdateBundleSeeds(context);
|
|
39
|
+
expect(seeds, isEmpty);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('filters out null seeds', () {
|
|
43
|
+
final context = <String, Object?>{};
|
|
44
|
+
seedRequestUpdateBundles(context, [_bundle('a'), null, _bundle('b')]);
|
|
45
|
+
final seeds = getRequestUpdateBundleSeeds(context);
|
|
46
|
+
expect(seeds.length, 2);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
group('getRequestUpdateBundleSeeds', () {
|
|
51
|
+
test('returns empty for null context', () {
|
|
52
|
+
expect(getRequestUpdateBundleSeeds(null), isEmpty);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('returns empty for unseeded context', () {
|
|
56
|
+
expect(getRequestUpdateBundleSeeds(<String, Object?>{}), isEmpty);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
group('createRequestUpdateBundleResolver', () {
|
|
61
|
+
test('creates resolver for valid context', () async {
|
|
62
|
+
final context = <String, Object?>{};
|
|
63
|
+
seedRequestUpdateBundles(context, [_bundle('x')]);
|
|
64
|
+
final resolver = createRequestUpdateBundleResolver(context);
|
|
65
|
+
|
|
66
|
+
expect(resolver.hasSeededBundles, isTrue);
|
|
67
|
+
expect(resolver.peek('x'), isNotNull);
|
|
68
|
+
expect(resolver.peek('missing'), isNull);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('creates standalone resolver for null context', () async {
|
|
72
|
+
final resolver = createRequestUpdateBundleResolver(null);
|
|
73
|
+
expect(resolver.hasSeededBundles, isFalse);
|
|
74
|
+
expect(resolver.peek('anything'), isNull);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('getById delegates to underlying UoW', () async {
|
|
78
|
+
final context = <String, Object?>{};
|
|
79
|
+
final resolver = createRequestUpdateBundleResolver(context);
|
|
80
|
+
|
|
81
|
+
final result = await resolver.getById('y', () async => _bundle('y'));
|
|
82
|
+
expect(result, isNotNull);
|
|
83
|
+
expect(result!.id, 'y');
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import 'package:flutter_patcher_plugin_core/src/uuidv7.dart';
|
|
2
|
+
import 'package:test/test.dart';
|
|
3
|
+
|
|
4
|
+
void main() {
|
|
5
|
+
group('extractTimestampFromUUIDv7', () {
|
|
6
|
+
test('extracts timestamp from known UUID', () {
|
|
7
|
+
// Timestamp hex = 01894f2e3a00 = 1737105248768
|
|
8
|
+
final uuid = '01894f2e-3a00-7000-8000-000000000000';
|
|
9
|
+
final ts = extractTimestampFromUUIDv7(uuid);
|
|
10
|
+
expect(ts, 0x01894f2e3a00);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('round-trips createUUIDv7 timestamp', () {
|
|
14
|
+
final uuid = createUUIDv7();
|
|
15
|
+
final ts = extractTimestampFromUUIDv7(uuid);
|
|
16
|
+
final now = DateTime.now().millisecondsSinceEpoch;
|
|
17
|
+
// Should be within 50ms of now
|
|
18
|
+
expect((now - ts).abs(), lessThan(50));
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
group('createUUIDv7', () {
|
|
23
|
+
test('produces valid UUID v7 format', () {
|
|
24
|
+
final uuid = createUUIDv7();
|
|
25
|
+
// 8-4-4-4-12 format
|
|
26
|
+
expect(uuid, matches(RegExp(
|
|
27
|
+
r'^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$',
|
|
28
|
+
)));
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('generates unique UUIDs', () {
|
|
32
|
+
final ids = <String>{};
|
|
33
|
+
for (var i = 0; i < 100; i++) {
|
|
34
|
+
ids.add(createUUIDv7());
|
|
35
|
+
}
|
|
36
|
+
expect(ids.length, 100);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('UUIDs with different timestamps are ordered correctly', () {
|
|
40
|
+
// Create two UUIDs with known timestamps
|
|
41
|
+
final uuid1 = createUUIDv7WithSameTimestamp(
|
|
42
|
+
'01900000-0001-7000-8000-000000000000',
|
|
43
|
+
);
|
|
44
|
+
final uuid2 = createUUIDv7WithSameTimestamp(
|
|
45
|
+
'01900000-0002-7000-8000-000000000000',
|
|
46
|
+
);
|
|
47
|
+
expect(uuid2.compareTo(uuid1), greaterThan(0));
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
group('createUUIDv7WithSameTimestamp', () {
|
|
52
|
+
test('preserves timestamp from original UUID', () {
|
|
53
|
+
final original = createUUIDv7();
|
|
54
|
+
final originalTs = extractTimestampFromUUIDv7(original);
|
|
55
|
+
final derived = createUUIDv7WithSameTimestamp(original);
|
|
56
|
+
final derivedTs = extractTimestampFromUUIDv7(derived);
|
|
57
|
+
expect(derivedTs, originalTs);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('produces different random bits', () {
|
|
61
|
+
final original = createUUIDv7();
|
|
62
|
+
// Generate a few — at least one should differ in random part
|
|
63
|
+
final differentFound = List.generate(10, (_) =>
|
|
64
|
+
createUUIDv7WithSameTimestamp(original))
|
|
65
|
+
.any((u) => u != original);
|
|
66
|
+
expect(differentFound, isTrue);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('derived UUID still has version 7 and correct variant', () {
|
|
70
|
+
final original = createUUIDv7();
|
|
71
|
+
final derived = createUUIDv7WithSameTimestamp(original);
|
|
72
|
+
expect(derived, matches(RegExp(
|
|
73
|
+
r'^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$',
|
|
74
|
+
)));
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|