@react-native-harness/platform-android 1.2.0 → 1.4.0-rc.1

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.
Files changed (41) hide show
  1. package/dist/__tests__/app-monitor.test.js +180 -102
  2. package/dist/__tests__/crash-diagnostics.test.d.ts +2 -0
  3. package/dist/__tests__/crash-diagnostics.test.d.ts.map +1 -0
  4. package/dist/__tests__/crash-diagnostics.test.js +119 -0
  5. package/dist/__tests__/crash-reporter.test.d.ts +2 -0
  6. package/dist/__tests__/crash-reporter.test.d.ts.map +1 -0
  7. package/dist/__tests__/crash-reporter.test.js +150 -0
  8. package/dist/__tests__/instance.test.js +133 -24
  9. package/dist/adb.d.ts +4 -0
  10. package/dist/adb.d.ts.map +1 -1
  11. package/dist/adb.js +42 -2
  12. package/dist/app-session.d.ts +17 -0
  13. package/dist/app-session.d.ts.map +1 -0
  14. package/dist/app-session.js +209 -0
  15. package/dist/crash-diagnostics.d.ts +40 -0
  16. package/dist/crash-diagnostics.d.ts.map +1 -0
  17. package/dist/crash-diagnostics.js +256 -0
  18. package/dist/crash-reporter.d.ts +12 -0
  19. package/dist/crash-reporter.d.ts.map +1 -0
  20. package/dist/crash-reporter.js +150 -0
  21. package/dist/device-state.d.ts +6 -0
  22. package/dist/device-state.d.ts.map +1 -0
  23. package/dist/device-state.js +142 -0
  24. package/dist/instance.d.ts +1 -1
  25. package/dist/instance.d.ts.map +1 -1
  26. package/dist/instance.js +32 -59
  27. package/dist/runner.d.ts.map +1 -1
  28. package/dist/runner.js +1 -1
  29. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  30. package/package.json +4 -4
  31. package/src/__tests__/crash-diagnostics.test.ts +144 -0
  32. package/src/__tests__/crash-reporter.test.ts +167 -0
  33. package/src/__tests__/instance.test.ts +174 -31
  34. package/src/adb.ts +61 -2
  35. package/src/app-session.ts +300 -0
  36. package/src/crash-diagnostics.ts +471 -0
  37. package/src/crash-reporter.ts +263 -0
  38. package/src/instance.ts +56 -91
  39. package/src/runner.ts +7 -3
  40. package/test/setup.ts +1 -0
  41. package/src/app-monitor.ts +0 -577
@@ -0,0 +1,471 @@
1
+ import type {
2
+ AppCrashDetails,
3
+ CrashArtifactWriter,
4
+ CrashDetailsLookupOptions,
5
+ CrashEnrichmentArtifact,
6
+ } from '@react-native-harness/platforms';
7
+ import { escapeRegExp, logger } from '@react-native-harness/tools';
8
+ import { androidCrashParser } from './crash-parser.js';
9
+
10
+ const crashDiagnosticsLogger = logger.child('android-crash-diagnostics');
11
+
12
+ const DROPBOX_ENTRY_HEADER =
13
+ /^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d{3})?) (\S+) \(text, \d+ bytes\)/;
14
+ const DROPBOX_POLL_INTERVAL_MS = 1500;
15
+ const DROPBOX_WAIT_TIMEOUT_MS = 10000;
16
+
17
+ export const DROPBOX_CRASH_TAGS = [
18
+ 'data_app_crash',
19
+ 'data_app_native_crash',
20
+ ] as const;
21
+
22
+ export type DropboxEntry = {
23
+ tag: string;
24
+ timestamp: string;
25
+ content: string;
26
+ pid?: number;
27
+ processName?: string;
28
+ };
29
+
30
+ export type DropboxCrashArtifact = AppCrashDetails & {
31
+ artifactType: 'dropbox-crash' | 'dropbox-native-crash';
32
+ dropboxTag: string;
33
+ occurredAt: number;
34
+ score?: number;
35
+ };
36
+
37
+ type CollectDropboxArtifactsOptions = {
38
+ bundleId: string;
39
+ crashArtifactWriter?: CrashArtifactWriter;
40
+ getDropboxOutput: () => Promise<string>;
41
+ minOccurredAt?: number;
42
+ };
43
+
44
+ type WaitForDropboxArtifactsOptions = CollectDropboxArtifactsOptions &
45
+ CrashDetailsLookupOptions;
46
+
47
+ const getDropboxArtifactType = (
48
+ tag: string
49
+ ): 'dropbox-crash' | 'dropbox-native-crash' =>
50
+ tag === 'data_app_native_crash' ? 'dropbox-native-crash' : 'dropbox-crash';
51
+
52
+ const getDropboxFileName = (tag: string) =>
53
+ tag === 'data_app_native_crash'
54
+ ? 'dropbox-native-crash.txt'
55
+ : 'dropbox-crash.txt';
56
+
57
+ const parseDropboxTimestamp = (timestamp: string): number => {
58
+ const match = timestamp.match(
59
+ /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})(?:\.(\d{3}))?$/
60
+ );
61
+
62
+ if (!match) {
63
+ return 0;
64
+ }
65
+
66
+ const [, year, month, day, hour, minute, second, millis = '0'] = match;
67
+
68
+ return Date.UTC(
69
+ Number(year),
70
+ Number(month) - 1,
71
+ Number(day),
72
+ Number(hour),
73
+ Number(minute),
74
+ Number(second),
75
+ Number(millis)
76
+ );
77
+ };
78
+
79
+ const extractDropboxPid = (content: string): number | undefined => {
80
+ const match =
81
+ content.match(/^PID:\s*(\d+)/m) ?? content.match(/\bpid:\s*(\d+)/im);
82
+
83
+ return match ? Number(match[1]) : undefined;
84
+ };
85
+
86
+ const extractDropboxProcessName = (
87
+ content: string,
88
+ bundleId: string
89
+ ): string | undefined => {
90
+ const processMatch = content.match(/^Process:\s*(\S+)/m);
91
+ const packageMatch = content.match(/^Package:\s*(\S+)/m);
92
+
93
+ if (processMatch?.[1] === bundleId) {
94
+ return processMatch[1];
95
+ }
96
+
97
+ if (packageMatch?.[1]?.startsWith(bundleId)) {
98
+ return bundleId;
99
+ }
100
+
101
+ return content.includes(bundleId) ? bundleId : undefined;
102
+ };
103
+
104
+ export const parseDropboxOutput = (output: string): DropboxEntry[] => {
105
+ if (output.trim() === '') {
106
+ return [];
107
+ }
108
+
109
+ const sections = output.split(
110
+ /^={10,}\s*$/m
111
+ );
112
+ const entries: DropboxEntry[] = [];
113
+
114
+ for (const section of sections) {
115
+ const trimmedSection = section.trim();
116
+
117
+ if (trimmedSection === '') {
118
+ continue;
119
+ }
120
+
121
+ const lines = trimmedSection.split('\n');
122
+ const headerIndex = lines.findIndex((line) =>
123
+ DROPBOX_ENTRY_HEADER.test(line.trim())
124
+ );
125
+
126
+ if (headerIndex === -1) {
127
+ continue;
128
+ }
129
+
130
+ const headerMatch = lines[headerIndex].trim().match(DROPBOX_ENTRY_HEADER);
131
+
132
+ if (!headerMatch) {
133
+ continue;
134
+ }
135
+
136
+ const [, timestamp, tag] = headerMatch;
137
+ const content = lines.slice(headerIndex + 1).join('\n').trim();
138
+
139
+ if (content === '') {
140
+ continue;
141
+ }
142
+
143
+ entries.push({
144
+ tag,
145
+ timestamp,
146
+ content,
147
+ pid: extractDropboxPid(content),
148
+ });
149
+ }
150
+
151
+ return entries;
152
+ };
153
+
154
+ const matchesDropboxEntry = ({
155
+ entry,
156
+ bundleId,
157
+ pid,
158
+ }: {
159
+ entry: DropboxEntry;
160
+ bundleId: string;
161
+ pid?: number;
162
+ }) => {
163
+ const processName = extractDropboxProcessName(entry.content, bundleId);
164
+
165
+ if (!processName) {
166
+ return false;
167
+ }
168
+
169
+ if (pid !== undefined && entry.pid !== undefined && entry.pid !== pid) {
170
+ return false;
171
+ }
172
+
173
+ return true;
174
+ };
175
+
176
+ const scoreDropboxEntry = ({
177
+ entry,
178
+ bundleId,
179
+ pid,
180
+ occurredAt,
181
+ }: {
182
+ entry: DropboxEntry;
183
+ bundleId: string;
184
+ pid?: number;
185
+ occurredAt: number;
186
+ }): number => {
187
+ let score = 0;
188
+
189
+ if (extractDropboxProcessName(entry.content, bundleId) === bundleId) {
190
+ score += 100;
191
+ }
192
+
193
+ if (pid !== undefined && entry.pid === pid) {
194
+ score += 200;
195
+ }
196
+
197
+ const entryTimestamp = parseDropboxTimestamp(entry.timestamp);
198
+
199
+ if (entryTimestamp > 0) {
200
+ score -= Math.min(Math.abs(entryTimestamp - occurredAt) / 1000, 300);
201
+ }
202
+
203
+ if (entry.tag === 'data_app_native_crash') {
204
+ score += 25;
205
+ }
206
+
207
+ return score;
208
+ };
209
+
210
+ const toDropboxCrashArtifact = ({
211
+ entry,
212
+ bundleId,
213
+ pid,
214
+ occurredAt,
215
+ lookup,
216
+ }: {
217
+ entry: DropboxEntry;
218
+ bundleId: string;
219
+ pid?: number;
220
+ occurredAt: number;
221
+ lookup?: CrashDetailsLookupOptions;
222
+ }): DropboxCrashArtifact => {
223
+ const parsed = androidCrashParser.parse({
224
+ contents: entry.content,
225
+ bundleId,
226
+ pid: pid ?? entry.pid,
227
+ });
228
+ const artifactType = getDropboxArtifactType(entry.tag);
229
+
230
+ return {
231
+ ...parsed,
232
+ source: 'logs',
233
+ summary: entry.content,
234
+ rawLines: entry.content.split(/\r?\n/),
235
+ artifactType,
236
+ dropboxTag: entry.tag,
237
+ occurredAt,
238
+ score: scoreDropboxEntry({
239
+ entry,
240
+ bundleId,
241
+ pid: lookup?.pid ?? pid,
242
+ occurredAt: lookup?.occurredAt ?? occurredAt,
243
+ }),
244
+ };
245
+ };
246
+
247
+ const getMatchingDropboxEntries = ({
248
+ output,
249
+ bundleId,
250
+ pid,
251
+ occurredAt,
252
+ minOccurredAt,
253
+ }: {
254
+ output: string;
255
+ bundleId: string;
256
+ pid?: number;
257
+ occurredAt: number;
258
+ minOccurredAt?: number;
259
+ }) =>
260
+ parseDropboxOutput(output)
261
+ .filter((entry) => matchesDropboxEntry({ entry, bundleId, pid }))
262
+ .filter((entry) => {
263
+ const entryOccurredAt = parseDropboxTimestamp(entry.timestamp);
264
+
265
+ return (
266
+ minOccurredAt === undefined ||
267
+ entryOccurredAt === 0 ||
268
+ entryOccurredAt >= minOccurredAt
269
+ );
270
+ })
271
+ .map((entry) =>
272
+ toDropboxCrashArtifact({
273
+ entry,
274
+ bundleId,
275
+ pid,
276
+ occurredAt: parseDropboxTimestamp(entry.timestamp) || occurredAt,
277
+ })
278
+ )
279
+ .sort((left, right) => {
280
+ if ((right.score ?? 0) !== (left.score ?? 0)) {
281
+ return (right.score ?? 0) - (left.score ?? 0);
282
+ }
283
+
284
+ return right.occurredAt - left.occurredAt;
285
+ });
286
+
287
+ const persistDropboxArtifact = ({
288
+ artifact,
289
+ crashArtifactWriter,
290
+ testFilePath,
291
+ }: {
292
+ artifact: DropboxCrashArtifact;
293
+ crashArtifactWriter?: CrashArtifactWriter;
294
+ testFilePath?: string;
295
+ }): DropboxCrashArtifact => {
296
+ if (!crashArtifactWriter) {
297
+ return artifact;
298
+ }
299
+
300
+ return {
301
+ ...artifact,
302
+ artifactPath: crashArtifactWriter.persistArtifact({
303
+ artifactKind: artifact.artifactType,
304
+ testFilePath,
305
+ source: {
306
+ kind: 'text',
307
+ fileName: getDropboxFileName(artifact.dropboxTag),
308
+ text: `${artifact.summary ?? ''}\n`,
309
+ },
310
+ }),
311
+ };
312
+ };
313
+
314
+ export const collectDropboxArtifacts = async ({
315
+ bundleId,
316
+ crashArtifactWriter,
317
+ getDropboxOutput,
318
+ minOccurredAt,
319
+ ...lookup
320
+ }: WaitForDropboxArtifactsOptions): Promise<DropboxCrashArtifact[]> => {
321
+ crashDiagnosticsLogger.debug('collecting dropbox crash artifacts: %o', {
322
+ bundleId,
323
+ pid: lookup.pid,
324
+ occurredAt: lookup.occurredAt,
325
+ });
326
+
327
+ let output = '';
328
+
329
+ try {
330
+ output = await getDropboxOutput();
331
+ } catch (error) {
332
+ crashDiagnosticsLogger.debug('failed to read dropbox entries', error);
333
+ return [];
334
+ }
335
+
336
+ return getMatchingDropboxEntries({
337
+ output,
338
+ bundleId,
339
+ pid: lookup.pid,
340
+ occurredAt: lookup.occurredAt,
341
+ minOccurredAt,
342
+ }).map((artifact) =>
343
+ persistDropboxArtifact({
344
+ artifact,
345
+ crashArtifactWriter,
346
+ testFilePath: lookup.testFilePath,
347
+ })
348
+ );
349
+ };
350
+
351
+ export const waitForDropboxArtifacts = async (
352
+ options: WaitForDropboxArtifactsOptions
353
+ ): Promise<DropboxCrashArtifact[]> => {
354
+ const deadline = Date.now() + DROPBOX_WAIT_TIMEOUT_MS;
355
+ let latestArtifacts: DropboxCrashArtifact[] = [];
356
+
357
+ while (Date.now() < deadline) {
358
+ latestArtifacts = await collectDropboxArtifacts(options);
359
+
360
+ if (latestArtifacts.length > 0) {
361
+ return latestArtifacts;
362
+ }
363
+
364
+ if (Date.now() >= deadline) {
365
+ return latestArtifacts;
366
+ }
367
+
368
+ await new Promise((resolve) =>
369
+ setTimeout(resolve, DROPBOX_POLL_INTERVAL_MS)
370
+ );
371
+ }
372
+
373
+ return latestArtifacts;
374
+ };
375
+
376
+ export const filterExitInfo = ({
377
+ output,
378
+ bundleId,
379
+ pid,
380
+ }: {
381
+ output: string;
382
+ bundleId: string;
383
+ pid?: number;
384
+ }): string | null => {
385
+ if (output.trim() === '' || /No exit info records/i.test(output)) {
386
+ return null;
387
+ }
388
+
389
+ const packagePattern = new RegExp(
390
+ `\\bpackage=${escapeRegExp(bundleId)}\\b`,
391
+ 'i'
392
+ );
393
+
394
+ if (!packagePattern.test(output)) {
395
+ return null;
396
+ }
397
+
398
+ const sections = output.split(/(?=ApplicationExitInfo\b)/);
399
+ const matchingSections = sections.filter((section) => {
400
+ if (!packagePattern.test(section)) {
401
+ return false;
402
+ }
403
+
404
+ if (pid === undefined) {
405
+ return true;
406
+ }
407
+
408
+ return new RegExp(`\\bpid=${pid}\\b`).test(section);
409
+ });
410
+
411
+ if (matchingSections.length === 0) {
412
+ return packagePattern.test(output) ? output.trim() : null;
413
+ }
414
+
415
+ return matchingSections.join('\n').trim();
416
+ };
417
+
418
+ export const collectExitInfoArtifact = async ({
419
+ bundleId,
420
+ crashArtifactWriter,
421
+ getExitInfo,
422
+ pid,
423
+ testFilePath,
424
+ }: {
425
+ bundleId: string;
426
+ crashArtifactWriter?: CrashArtifactWriter;
427
+ getExitInfo: () => Promise<string>;
428
+ pid?: number;
429
+ testFilePath?: string;
430
+ }): Promise<CrashEnrichmentArtifact | null> => {
431
+ let output = '';
432
+
433
+ try {
434
+ output = await getExitInfo();
435
+ } catch (error) {
436
+ crashDiagnosticsLogger.debug('failed to read activity exit-info', error);
437
+ return null;
438
+ }
439
+
440
+ const filtered = filterExitInfo({ output, bundleId, pid });
441
+
442
+ if (!filtered) {
443
+ return null;
444
+ }
445
+
446
+ if (!crashArtifactWriter) {
447
+ return {
448
+ artifactType: 'exit-info',
449
+ artifactPath: filtered,
450
+ };
451
+ }
452
+
453
+ return {
454
+ artifactType: 'exit-info',
455
+ artifactPath: crashArtifactWriter.persistArtifact({
456
+ artifactKind: 'exit-info',
457
+ testFilePath,
458
+ source: {
459
+ kind: 'text',
460
+ fileName: 'exit-info.txt',
461
+ text: `${filtered}\n`,
462
+ },
463
+ }),
464
+ };
465
+ };
466
+
467
+ export const getBestDropboxArtifact = (
468
+ artifacts: DropboxCrashArtifact[]
469
+ ): DropboxCrashArtifact | null =>
470
+ [...artifacts].sort((left, right) => (right.score ?? 0) - (left.score ?? 0))[0] ??
471
+ null;
@@ -0,0 +1,263 @@
1
+ import type {
2
+ AppCrashDetails,
3
+ AppSessionLog,
4
+ CrashArtifactWriter,
5
+ CrashDetailsLookupOptions,
6
+ CrashEnrichmentArtifact,
7
+ } from '@react-native-harness/platforms';
8
+ import { androidCrashParser } from './crash-parser.js';
9
+ import {
10
+ collectExitInfoArtifact,
11
+ waitForDropboxArtifacts,
12
+ getBestDropboxArtifact,
13
+ type DropboxCrashArtifact,
14
+ } from './crash-diagnostics.js';
15
+
16
+ const CRASH_ARTIFACT_SETTLE_DELAY_MS = 100;
17
+ const CRASH_BLOCK_HEADER = '--------- beginning of crash';
18
+ const CRASH_LOG_WINDOW_MS = 5000;
19
+
20
+ const findCrashBlockStart = (lines: string[]) => {
21
+ let latestCrashHeaderIndex = -1;
22
+
23
+ for (let index = lines.length - 1; index >= 0; index -= 1) {
24
+ if (
25
+ /FATAL EXCEPTION:|Process:\s+.+,\s+PID:|>>>\s+.+\s+<<</i.test(
26
+ lines[index]
27
+ )
28
+ ) {
29
+ latestCrashHeaderIndex = index;
30
+ break;
31
+ }
32
+ }
33
+
34
+ const latestBlockHeaderIndex = lines.lastIndexOf(CRASH_BLOCK_HEADER);
35
+
36
+ return latestBlockHeaderIndex >= 0
37
+ ? latestBlockHeaderIndex
38
+ : latestCrashHeaderIndex;
39
+ };
40
+
41
+ const getCrashBlock = (logs: AppSessionLog[], occurredAt: number) => {
42
+ const nearbyLogs = logs.filter(
43
+ (log) => Math.abs(log.occurredAt - occurredAt) <= CRASH_LOG_WINDOW_MS
44
+ );
45
+ const lines =
46
+ nearbyLogs.length > 0
47
+ ? nearbyLogs.map((log) => log.line)
48
+ : logs.map((log) => log.line);
49
+ const blockStart = findCrashBlockStart(lines);
50
+
51
+ return blockStart >= 0 ? lines.slice(blockStart) : lines;
52
+ };
53
+
54
+ const hasUsefulLogcatBlock = (rawLines: string[]) =>
55
+ rawLines.some((line) =>
56
+ /FATAL EXCEPTION:|Process:\s+.+,\s+PID:|>>>\s+.+\s+<<</i.test(line)
57
+ );
58
+
59
+ const getLogcatCrashDetails = ({
60
+ rawLines,
61
+ bundleId,
62
+ pid,
63
+ }: {
64
+ rawLines: string[];
65
+ bundleId: string;
66
+ pid?: number;
67
+ }): AppCrashDetails => ({
68
+ ...androidCrashParser.parse({
69
+ contents: rawLines.join('\n'),
70
+ bundleId,
71
+ pid,
72
+ }),
73
+ artifactType: 'logcat',
74
+ rawLines,
75
+ });
76
+
77
+ const persistLogcatArtifact = ({
78
+ details,
79
+ crashArtifactWriter,
80
+ testFilePath,
81
+ }: {
82
+ details: AppCrashDetails;
83
+ crashArtifactWriter?: CrashArtifactWriter;
84
+ testFilePath?: string;
85
+ }): AppCrashDetails => {
86
+ if (!crashArtifactWriter || !details.rawLines?.length) {
87
+ return details;
88
+ }
89
+
90
+ return {
91
+ ...details,
92
+ artifactPath: crashArtifactWriter.persistArtifact({
93
+ artifactKind: 'logcat',
94
+ testFilePath,
95
+ source: {
96
+ kind: 'text',
97
+ fileName: 'logcat.txt',
98
+ text: `${details.rawLines.join('\n')}\n`,
99
+ },
100
+ }),
101
+ };
102
+ };
103
+
104
+ const getDropboxFallbackDetails = (
105
+ artifact: DropboxCrashArtifact
106
+ ): AppCrashDetails => ({
107
+ ...artifact,
108
+ artifactType: artifact.artifactType,
109
+ artifactPath: artifact.artifactPath,
110
+ });
111
+
112
+ const getEnrichmentArtifacts = async ({
113
+ bundleId,
114
+ crashArtifactWriter,
115
+ getDropboxOutput,
116
+ getExitInfo,
117
+ minOccurredAt,
118
+ occurredAt,
119
+ pid,
120
+ testFilePath,
121
+ }: {
122
+ bundleId: string;
123
+ crashArtifactWriter?: CrashArtifactWriter;
124
+ getDropboxOutput?: () => Promise<string>;
125
+ getExitInfo?: () => Promise<string>;
126
+ minOccurredAt?: number;
127
+ occurredAt: number;
128
+ pid?: number;
129
+ testFilePath?: string;
130
+ }): Promise<{
131
+ dropboxArtifacts: DropboxCrashArtifact[];
132
+ enrichmentArtifacts: CrashEnrichmentArtifact[];
133
+ }> => {
134
+ const dropboxArtifacts = getDropboxOutput
135
+ ? await waitForDropboxArtifacts({
136
+ bundleId,
137
+ crashArtifactWriter,
138
+ getDropboxOutput,
139
+ minOccurredAt,
140
+ occurredAt,
141
+ pid,
142
+ testFilePath,
143
+ })
144
+ : [];
145
+
146
+ const enrichmentArtifacts: CrashEnrichmentArtifact[] = dropboxArtifacts
147
+ .filter((artifact) => artifact.artifactPath !== undefined)
148
+ .map((artifact) => ({
149
+ artifactType: artifact.artifactType,
150
+ artifactPath: artifact.artifactPath as string,
151
+ }));
152
+
153
+ if (getExitInfo) {
154
+ const exitInfoArtifact = await collectExitInfoArtifact({
155
+ bundleId,
156
+ crashArtifactWriter,
157
+ getExitInfo,
158
+ pid,
159
+ testFilePath,
160
+ });
161
+
162
+ if (exitInfoArtifact?.artifactPath.startsWith('/')) {
163
+ enrichmentArtifacts.push({
164
+ artifactType: exitInfoArtifact.artifactType,
165
+ artifactPath: exitInfoArtifact.artifactPath,
166
+ });
167
+ }
168
+ }
169
+
170
+ return { dropboxArtifacts, enrichmentArtifacts };
171
+ };
172
+
173
+ export const createAndroidCrashReporter = ({
174
+ bundleId,
175
+ crashArtifactWriter,
176
+ getLogs,
177
+ getDropboxOutput,
178
+ getExitInfo,
179
+ minOccurredAt,
180
+ }: {
181
+ bundleId: string;
182
+ crashArtifactWriter?: CrashArtifactWriter;
183
+ getLogs: () => AppSessionLog[];
184
+ getDropboxOutput?: () => Promise<string>;
185
+ getExitInfo?: () => Promise<string>;
186
+ minOccurredAt?: number;
187
+ }) => ({
188
+ getCrashDetails: async ({
189
+ occurredAt,
190
+ pid,
191
+ testFilePath,
192
+ }: CrashDetailsLookupOptions): Promise<AppCrashDetails | null> => {
193
+ await new Promise((resolve) =>
194
+ setTimeout(resolve, CRASH_ARTIFACT_SETTLE_DELAY_MS)
195
+ );
196
+
197
+ const rawLines = getCrashBlock(getLogs(), occurredAt);
198
+ const logcatDetails =
199
+ rawLines.length > 0
200
+ ? getLogcatCrashDetails({ rawLines, bundleId, pid })
201
+ : null;
202
+
203
+ let enrichmentArtifacts: CrashEnrichmentArtifact[] = [];
204
+ let dropboxArtifacts: DropboxCrashArtifact[] = [];
205
+
206
+ if (getDropboxOutput || getExitInfo) {
207
+ ({ dropboxArtifacts, enrichmentArtifacts } =
208
+ await getEnrichmentArtifacts({
209
+ bundleId,
210
+ crashArtifactWriter,
211
+ getDropboxOutput,
212
+ getExitInfo,
213
+ minOccurredAt,
214
+ occurredAt,
215
+ pid,
216
+ testFilePath,
217
+ }));
218
+ }
219
+
220
+ if (logcatDetails && hasUsefulLogcatBlock(rawLines)) {
221
+ return {
222
+ ...persistLogcatArtifact({
223
+ details: logcatDetails,
224
+ crashArtifactWriter,
225
+ testFilePath,
226
+ }),
227
+ enrichmentArtifacts:
228
+ enrichmentArtifacts.length > 0 ? enrichmentArtifacts : undefined,
229
+ };
230
+ }
231
+
232
+ const dropboxFallback = getBestDropboxArtifact(dropboxArtifacts);
233
+
234
+ if (dropboxFallback) {
235
+ const primary = getDropboxFallbackDetails(dropboxFallback);
236
+
237
+ return {
238
+ ...primary,
239
+ enrichmentArtifacts: enrichmentArtifacts.filter(
240
+ (artifact) => artifact.artifactPath !== primary.artifactPath
241
+ ),
242
+ };
243
+ }
244
+
245
+ if (logcatDetails) {
246
+ return {
247
+ ...persistLogcatArtifact({
248
+ details: logcatDetails,
249
+ crashArtifactWriter,
250
+ testFilePath,
251
+ }),
252
+ enrichmentArtifacts:
253
+ enrichmentArtifacts.length > 0 ? enrichmentArtifacts : undefined,
254
+ };
255
+ }
256
+
257
+ return enrichmentArtifacts.length > 0
258
+ ? {
259
+ enrichmentArtifacts,
260
+ }
261
+ : null;
262
+ },
263
+ });