eas-cli 24.1.2 → 24.3.0

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 (80) hide show
  1. package/README.md +237 -131
  2. package/build/channel/insights/formatInsights.js +1 -5
  3. package/build/commandUtils/EasCommand.d.ts +2 -1
  4. package/build/commandUtils/EasCommand.js +2 -1
  5. package/build/commandUtils/context/ContextField.d.ts +2 -0
  6. package/build/commandUtils/context/ProjectIdContextField.d.ts +1 -1
  7. package/build/commandUtils/context/ProjectIdContextField.js +4 -1
  8. package/build/commandUtils/flags.d.ts +3 -0
  9. package/build/commandUtils/flags.js +6 -1
  10. package/build/commandUtils/pagination.js +2 -2
  11. package/build/commandUtils/planGating.d.ts +2 -0
  12. package/build/commandUtils/planGating.js +10 -0
  13. package/build/commands/channel/insights.d.ts +2 -2
  14. package/build/commands/channel/insights.js +1 -13
  15. package/build/commands/observe/errors.d.ts +0 -1
  16. package/build/commands/observe/errors.js +3 -10
  17. package/build/commands/observe/event.d.ts +0 -1
  18. package/build/commands/observe/event.js +3 -11
  19. package/build/commands/observe/events.d.ts +0 -1
  20. package/build/commands/observe/events.js +3 -10
  21. package/build/commands/observe/metrics-summary.d.ts +0 -1
  22. package/build/commands/observe/metrics-summary.js +3 -10
  23. package/build/commands/observe/metrics.d.ts +0 -1
  24. package/build/commands/observe/metrics.js +3 -10
  25. package/build/commands/observe/routes.d.ts +0 -1
  26. package/build/commands/observe/routes.js +3 -10
  27. package/build/commands/observe/session.d.ts +0 -1
  28. package/build/commands/observe/session.js +3 -10
  29. package/build/commands/observe/versions.d.ts +0 -1
  30. package/build/commands/observe/versions.js +3 -10
  31. package/build/commands/update/insights.d.ts +1 -1
  32. package/build/commands/update/insights.js +1 -13
  33. package/build/commands/workflow/insights/index.d.ts +23 -0
  34. package/build/commands/workflow/insights/index.js +80 -0
  35. package/build/commands/workflow/insights/maestro.d.ts +26 -0
  36. package/build/commands/workflow/insights/maestro.js +140 -0
  37. package/build/graphql/generated.d.ts +261 -0
  38. package/build/graphql/generated.js +2 -0
  39. package/build/graphql/queries/AppQuery.d.ts +4 -0
  40. package/build/graphql/queries/AppQuery.js +19 -0
  41. package/build/graphql/queries/WorkflowDeviceTestCaseInsightsQuery.d.ts +27 -0
  42. package/build/graphql/queries/WorkflowDeviceTestCaseInsightsQuery.js +173 -0
  43. package/build/graphql/queries/WorkflowsInsightsQuery.d.ts +13 -0
  44. package/build/graphql/queries/WorkflowsInsightsQuery.js +84 -0
  45. package/build/insights/formatFilters.d.ts +2 -0
  46. package/build/insights/formatFilters.js +10 -0
  47. package/build/insights/formatRunsOverTime.d.ts +13 -0
  48. package/build/insights/formatRunsOverTime.js +49 -0
  49. package/build/insights/formatTimespan.d.ts +5 -1
  50. package/build/insights/formatTimespan.js +12 -0
  51. package/build/insights/metrics.d.ts +22 -0
  52. package/build/insights/metrics.js +48 -0
  53. package/build/insights/timeRange.d.ts +5 -0
  54. package/build/insights/timeRange.js +17 -1
  55. package/build/observe/flags.d.ts +0 -3
  56. package/build/observe/flags.js +1 -6
  57. package/build/observe/formatErrors.js +3 -5
  58. package/build/observe/planGating.js +2 -5
  59. package/build/observe/startAndEndTime.js +9 -0
  60. package/build/update/insights/formatInsights.js +1 -5
  61. package/build/utils/terminalText.d.ts +1 -0
  62. package/build/utils/terminalText.js +4 -0
  63. package/build/workflow/insights/filters.d.ts +30 -0
  64. package/build/workflow/insights/filters.js +79 -0
  65. package/build/workflow/insights/formatInsights.d.ts +44 -0
  66. package/build/workflow/insights/formatInsights.js +155 -0
  67. package/build/workflow/insights/formatMaestroInsights.d.ts +105 -0
  68. package/build/workflow/insights/formatMaestroInsights.js +298 -0
  69. package/build/workflow/insights/granularity.d.ts +27 -0
  70. package/build/workflow/insights/granularity.js +79 -0
  71. package/build/workflow/insights/maestroFilters.d.ts +23 -0
  72. package/build/workflow/insights/maestroFilters.js +47 -0
  73. package/build/workflow/insights/maestroSort.d.ts +7 -0
  74. package/build/workflow/insights/maestroSort.js +27 -0
  75. package/build/workflow/insights/planGating.d.ts +6 -0
  76. package/build/workflow/insights/planGating.js +33 -0
  77. package/oclif.manifest.json +2341 -1961
  78. package/package.json +5 -5
  79. package/build/observe/resolveProjectContext.d.ts +0 -22
  80. package/build/observe/resolveProjectContext.js +0 -21
@@ -0,0 +1,298 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toMaestroInsightsSummary = toMaestroInsightsSummary;
4
+ exports.toMaestroFlowHistorySummary = toMaestroFlowHistorySummary;
5
+ exports.buildMaestroInsightsJson = buildMaestroInsightsJson;
6
+ exports.buildMaestroFlowHistoryJson = buildMaestroFlowHistoryJson;
7
+ exports.buildMaestroInsightsTable = buildMaestroInsightsTable;
8
+ exports.buildMaestroFlowHistoryTable = buildMaestroFlowHistoryTable;
9
+ exports.formatDurationMs = formatDurationMs;
10
+ const tslib_1 = require("tslib");
11
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
12
+ const indent_string_1 = tslib_1.__importDefault(require("indent-string"));
13
+ const formatRunsOverTime_1 = require("../../insights/formatRunsOverTime");
14
+ const formatTimespan_1 = require("../../insights/formatTimespan");
15
+ const formatFilters_1 = require("../../insights/formatFilters");
16
+ const formatFields_1 = tslib_1.__importDefault(require("../../utils/formatFields"));
17
+ const renderTextTable_1 = tslib_1.__importDefault(require("../../utils/renderTextTable"));
18
+ const terminalText_1 = require("../../utils/terminalText");
19
+ const metrics_1 = require("../../insights/metrics");
20
+ function toMaestroInsightsSummary(app, { timespan, granularity, filters, sort, }) {
21
+ const { totals, timeSeries, tests } = app.workflowDeviceTestCaseInsights;
22
+ return {
23
+ appFullName: app.fullName,
24
+ ...timespan,
25
+ granularity,
26
+ filters,
27
+ totals: toOverviewTotals(totals),
28
+ runsOverTime: timeSeries.map(toBucket),
29
+ flows: tests.edges.map(({ node }) => ({
30
+ path: node.path,
31
+ name: node.name,
32
+ totalRuns: node.totalRuns,
33
+ passRatePercent: (0, metrics_1.ratePercent)(node.passedCleanCount + node.flakyCount, node.totalRuns),
34
+ failed: node.failedCount,
35
+ flakeRatePercent: (0, metrics_1.ratePercent)(node.flakyCount, node.totalRuns),
36
+ p90DurationMs: node.p90DurationMs ?? null,
37
+ lastRunAt: node.lastRunAt,
38
+ lastRunStatus: node.lastRunStatus,
39
+ lastRunIsFlaky: node.lastRunIsFlaky,
40
+ })),
41
+ totalFlows: tests.totalCount,
42
+ hasMoreFlows: tests.pageInfo.hasNextPage,
43
+ sort,
44
+ };
45
+ }
46
+ function toMaestroFlowHistorySummary(app, { flowPath, timespan, granularity, filters, }) {
47
+ const { totals, timeSeries, errorPatterns, recentRuns } = app.workflowDeviceTestCaseHistory;
48
+ return {
49
+ appFullName: app.fullName,
50
+ flowPath,
51
+ ...timespan,
52
+ granularity,
53
+ filters,
54
+ totals: toFlowTotals(totals),
55
+ runsOverTime: timeSeries.map(toBucket),
56
+ errorPatterns: errorPatterns.map(pattern => ({
57
+ count: pattern.count,
58
+ sampleMessage: pattern.sampleMessage,
59
+ })),
60
+ recentRuns: recentRuns.edges.map(({ node }) => ({
61
+ id: node.id,
62
+ status: node.status,
63
+ isFlaky: node.isFlaky,
64
+ durationMs: node.durationMs ?? null,
65
+ createdAt: node.createdAt,
66
+ workflowRunId: node.workflowRunId,
67
+ workflowRunName: node.workflowRunName,
68
+ gitRef: node.gitRef ?? null,
69
+ commitSha: node.commitSha ?? null,
70
+ })),
71
+ totalRecentRuns: recentRuns.totalCount,
72
+ hasMoreRecentRuns: recentRuns.pageInfo.hasNextPage,
73
+ };
74
+ }
75
+ function toOverviewTotals(totals) {
76
+ const totalRuns = (0, metrics_1.toMetricSummary)(totals.totalRuns);
77
+ const passedClean = (0, metrics_1.toMetricSummary)(totals.passedCleanCount);
78
+ const flaky = (0, metrics_1.toMetricSummary)(totals.flakyCount);
79
+ return {
80
+ totalRuns,
81
+ passRatePercent: {
82
+ current: (0, metrics_1.ratePercent)(passedClean.current + flaky.current, totalRuns.current),
83
+ previous: (0, metrics_1.ratePercent)(passedClean.previous + flaky.previous, totalRuns.previous),
84
+ },
85
+ distinctFlakyFlows: (0, metrics_1.toMetricSummary)(totals.distinctFlakyTestCount),
86
+ avgDurationMs: {
87
+ current: totals.avgDurationMs.currentValue ?? null,
88
+ previous: totals.avgDurationMs.previousValue ?? null,
89
+ },
90
+ };
91
+ }
92
+ function toFlowTotals(totals) {
93
+ const totalRuns = totals.totalRuns.currentValue;
94
+ const flakyRuns = totals.flakyCount.currentValue;
95
+ return {
96
+ totalRuns,
97
+ passRatePercent: (0, metrics_1.ratePercent)(totals.passedCleanCount.currentValue + flakyRuns, totalRuns),
98
+ flakyRuns,
99
+ p90DurationMs: totals.p90DurationMs.currentValue ?? null,
100
+ };
101
+ }
102
+ function toBucket(bucket) {
103
+ return {
104
+ start: bucket.bucketStartAt,
105
+ passedClean: bucket.passedClean,
106
+ flaky: bucket.flaky,
107
+ failed: bucket.failed,
108
+ };
109
+ }
110
+ function buildMaestroInsightsJson(summary) {
111
+ return {
112
+ project: summary.appFullName,
113
+ timespan: (0, formatTimespan_1.toTimespanJson)(summary),
114
+ ...(summary.filters ? { filters: summary.filters } : {}),
115
+ totals: summary.totals,
116
+ runsOverTime: { granularity: summary.granularity, buckets: summary.runsOverTime },
117
+ flows: summary.flows,
118
+ totalFlows: summary.totalFlows,
119
+ hasMoreFlows: summary.hasMoreFlows,
120
+ sort: summary.sort,
121
+ };
122
+ }
123
+ function buildMaestroFlowHistoryJson(summary) {
124
+ return {
125
+ project: summary.appFullName,
126
+ flow: summary.flowPath,
127
+ timespan: (0, formatTimespan_1.toTimespanJson)(summary),
128
+ ...(summary.filters ? { filters: summary.filters } : {}),
129
+ totals: summary.totals,
130
+ runsOverTime: { granularity: summary.granularity, buckets: summary.runsOverTime },
131
+ errorPatterns: summary.errorPatterns,
132
+ recentRuns: summary.recentRuns,
133
+ totalRecentRuns: summary.totalRecentRuns,
134
+ hasMoreRecentRuns: summary.hasMoreRecentRuns,
135
+ };
136
+ }
137
+ function buildMaestroInsightsTable(summary) {
138
+ const sections = [];
139
+ sections.push(chalk_1.default.bold('Maestro insights:'));
140
+ sections.push((0, formatFields_1.default)([
141
+ { label: 'Project', value: summary.appFullName },
142
+ { label: 'Time range', value: (0, formatTimespan_1.formatTimespan)(summary) },
143
+ ...(summary.filters ? [{ label: 'Filters', value: formatFilters(summary.filters) }] : []),
144
+ ]));
145
+ sections.push('');
146
+ sections.push(chalk_1.default.bold('Overview (compared with the previous period):'));
147
+ sections.push((0, formatFields_1.default)(buildOverviewTotalsFields(summary.totals)));
148
+ sections.push(...buildMaestroRunsOverTimeSection(summary.runsOverTime, summary.granularity));
149
+ sections.push('');
150
+ if (summary.flows.length === 0) {
151
+ sections.push(chalk_1.default.bold('Flows:'));
152
+ sections.push(chalk_1.default.dim(' No flows matched in this time range.'));
153
+ }
154
+ else {
155
+ const scope = formatListScope(summary.flows.length, summary.totalFlows, summary.hasMoreFlows);
156
+ sections.push(chalk_1.default.bold(`Flows (${scope}, sorted by ${summary.sort.field} ${summary.sort.direction}):`));
157
+ sections.push('');
158
+ sections.push((0, indent_string_1.default)(renderFlowsTable(summary.flows), 2));
159
+ }
160
+ return sections.join('\n');
161
+ }
162
+ function buildMaestroFlowHistoryTable(summary) {
163
+ const sections = [];
164
+ sections.push(chalk_1.default.bold('Maestro flow insights:'));
165
+ sections.push((0, formatFields_1.default)([
166
+ { label: 'Project', value: summary.appFullName },
167
+ { label: 'Flow', value: summary.flowPath },
168
+ { label: 'Time range', value: (0, formatTimespan_1.formatTimespan)(summary) },
169
+ ...(summary.filters ? [{ label: 'Filters', value: formatFilters(summary.filters) }] : []),
170
+ ]));
171
+ sections.push('');
172
+ sections.push(chalk_1.default.bold('Overview:'));
173
+ sections.push((0, formatFields_1.default)(buildFlowTotalsFields(summary.totals)));
174
+ sections.push(...buildMaestroRunsOverTimeSection(summary.runsOverTime, summary.granularity));
175
+ sections.push('');
176
+ if (summary.errorPatterns.length === 0) {
177
+ sections.push(chalk_1.default.bold('Error patterns:'));
178
+ sections.push(chalk_1.default.dim(' No failures in this time range.'));
179
+ }
180
+ else {
181
+ sections.push(chalk_1.default.bold(`Error patterns (top ${summary.errorPatterns.length}):`));
182
+ sections.push('');
183
+ sections.push((0, indent_string_1.default)(renderErrorPatternsTable(summary.errorPatterns), 2));
184
+ }
185
+ sections.push('');
186
+ if (summary.recentRuns.length === 0) {
187
+ sections.push(chalk_1.default.bold('Recent runs:'));
188
+ sections.push(chalk_1.default.dim(' No runs of this flow in this time range. The flow path must match the overview.'));
189
+ }
190
+ else {
191
+ const scope = formatListScope(summary.recentRuns.length, summary.totalRecentRuns, summary.hasMoreRecentRuns);
192
+ sections.push(chalk_1.default.bold(`Recent runs (${scope}):`));
193
+ sections.push('');
194
+ sections.push((0, indent_string_1.default)(renderRecentRunsTable(summary.recentRuns), 2));
195
+ }
196
+ return sections.join('\n');
197
+ }
198
+ function buildOverviewTotalsFields(totals) {
199
+ return [
200
+ { label: 'Maestro runs', value: (0, metrics_1.formatCountWithTrend)(totals.totalRuns) },
201
+ { label: 'Pass rate', value: (0, metrics_1.formatRateWithDelta)(totals.passRatePercent, totals.totalRuns) },
202
+ {
203
+ label: 'Flaky flows',
204
+ value: (0, metrics_1.formatCountWithTrend)(totals.distinctFlakyFlows, { lowerIsBetter: true }),
205
+ },
206
+ { label: 'Avg duration', value: formatDurationWithTrend(totals.avgDurationMs) },
207
+ ];
208
+ }
209
+ function buildFlowTotalsFields(totals) {
210
+ return [
211
+ { label: 'Maestro runs', value: totals.totalRuns.toLocaleString() },
212
+ {
213
+ label: 'Pass rate',
214
+ value: totals.totalRuns === 0 ? chalk_1.default.dim('n/a') : (0, metrics_1.formatPercent)(totals.passRatePercent),
215
+ },
216
+ { label: 'Flaky runs', value: totals.flakyRuns.toLocaleString() },
217
+ {
218
+ label: 'P90 duration',
219
+ value: totals.p90DurationMs === null ? chalk_1.default.dim('n/a') : formatDurationMs(totals.p90DurationMs),
220
+ },
221
+ ];
222
+ }
223
+ function formatListScope(shown, total, hasMore) {
224
+ return hasMore ? `showing ${shown} of ${total.toLocaleString()}` : `${shown}`;
225
+ }
226
+ function buildMaestroRunsOverTimeSection(buckets, granularity) {
227
+ return (0, formatRunsOverTime_1.buildRunsOverTimeSection)(buckets, granularity, {
228
+ runs: bucket => bucket.passedClean + bucket.flaky + bucket.failed,
229
+ columns: ['Passed', 'Flaky', 'Failed'],
230
+ toRow: bucket => [
231
+ bucket.passedClean.toLocaleString(),
232
+ bucket.flaky.toLocaleString(),
233
+ bucket.failed.toLocaleString(),
234
+ ],
235
+ });
236
+ }
237
+ function renderFlowsTable(flows) {
238
+ return (0, renderTextTable_1.default)(['Flow', 'Runs', 'Pass rate', 'Fails', 'Flake rate', 'P90', 'Last run', 'Last status'], flows.map(flow => [
239
+ flow.path,
240
+ flow.totalRuns.toLocaleString(),
241
+ (0, metrics_1.formatPercent)(flow.passRatePercent),
242
+ flow.failed.toLocaleString(),
243
+ (0, metrics_1.formatPercent)(flow.flakeRatePercent),
244
+ formatDurationMs(flow.p90DurationMs),
245
+ (0, formatTimespan_1.toDateTime)(flow.lastRunAt),
246
+ formatRunStatus(flow.lastRunStatus, flow.lastRunIsFlaky),
247
+ ]));
248
+ }
249
+ function renderErrorPatternsTable(patterns) {
250
+ const SAMPLE_MESSAGE_MAX_LENGTH = 100;
251
+ return (0, renderTextTable_1.default)(['Count', 'Sample message'], patterns.map(pattern => [
252
+ pattern.count.toLocaleString(),
253
+ (0, terminalText_1.truncate)((0, terminalText_1.sanitizeTerminalText)(pattern.sampleMessage), SAMPLE_MESSAGE_MAX_LENGTH),
254
+ ]));
255
+ }
256
+ function renderRecentRunsTable(runs) {
257
+ return (0, renderTextTable_1.default)(['Started', 'Status', 'Duration', 'Branch', 'Commit', 'Workflow run'], runs.map(run => [
258
+ (0, formatTimespan_1.toDateTime)(run.createdAt),
259
+ formatRunStatus(run.status, run.isFlaky),
260
+ formatDurationMs(run.durationMs),
261
+ run.gitRef ?? '',
262
+ run.commitSha?.slice(0, 7) ?? '',
263
+ `${run.workflowRunName} (${run.workflowRunId})`,
264
+ ]));
265
+ }
266
+ function formatFilters(filters) {
267
+ return (0, formatFilters_1.formatAppliedFilters)([
268
+ ['workflows', filters.workflows],
269
+ ['statuses', filters.statuses],
270
+ ['tags', filters.tags],
271
+ ['search', filters.search],
272
+ ['git ref', filters.gitRef],
273
+ ]);
274
+ }
275
+ /** A flaky run passed only after a retry, so it is shown as its own state. */
276
+ function formatRunStatus(status, isFlaky) {
277
+ return isFlaky ? 'FLAKY' : status;
278
+ }
279
+ /** Matches the dashboard's duration format. */
280
+ function formatDurationMs(ms) {
281
+ if (ms === null) {
282
+ // Plain text: this lands in table cells, which renderTextTable pads by string length.
283
+ return 'n/a';
284
+ }
285
+ if (ms < 1000) {
286
+ return `${Math.round(ms)}ms`;
287
+ }
288
+ return `${(ms / 1000).toFixed(1)}s`;
289
+ }
290
+ function formatDurationWithTrend(metric) {
291
+ if (metric.current === null) {
292
+ return chalk_1.default.dim('n/a');
293
+ }
294
+ const trend = metric.previous === null
295
+ ? chalk_1.default.dim('n/a')
296
+ : (0, metrics_1.formatTrend)({ current: metric.current, previous: metric.previous }, { lowerIsBetter: true });
297
+ return `${formatDurationMs(metric.current)} (${trend})`;
298
+ }
@@ -0,0 +1,27 @@
1
+ import { WorkflowDeviceTestCaseInsightsTimeSeriesGranularity, WorkflowsInsightsRunsOverTimeGranularity } from '../../graphql/generated';
2
+ import { InsightsTimespanBounds } from '../../insights/formatTimespan';
3
+ export declare function granularityForTimespan(startTime: string, endTime: string): WorkflowsInsightsRunsOverTimeGranularity;
4
+ /**
5
+ * Widen a requested window out to whole buckets, and report the bucket size the widened window
6
+ * needs.
7
+ *
8
+ * The server widens only the runs-over-time query to whole buckets and leaves the overview and
9
+ * per-workflow queries on the exact bounds, so an unaligned window makes those sections count
10
+ * different runs. Sending the widened window turns that server-side widening into a no-op.
11
+ *
12
+ * Widening lengthens the window, which can push it past the threshold of the very bucket size it
13
+ * was widened by, so each candidate is only accepted if the widened window still asks for it.
14
+ * Falling through to the coarsest bucket means every finer one was ruled out, and widening by a
15
+ * coarser bucket is at least as wide, so the coarsest is always self-consistent.
16
+ *
17
+ * Widening the end past now puts unelapsed time in the current period while the previous period
18
+ * the server compares it against is complete, so count metrics span unequal exposure.
19
+ */
20
+ export declare function alignInsightsTimespan(timespan: InsightsTimespanBounds): {
21
+ timespan: InsightsTimespanBounds;
22
+ granularity: WorkflowsInsightsRunsOverTimeGranularity;
23
+ };
24
+ export declare function alignMaestroInsightsTimespan(timespan: InsightsTimespanBounds): {
25
+ timespan: InsightsTimespanBounds;
26
+ granularity: WorkflowDeviceTestCaseInsightsTimeSeriesGranularity;
27
+ };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.granularityForTimespan = granularityForTimespan;
4
+ exports.alignInsightsTimespan = alignInsightsTimespan;
5
+ exports.alignMaestroInsightsTimespan = alignMaestroInsightsTimespan;
6
+ const generated_1 = require("../../graphql/generated");
7
+ const MINUTE_MS = 60 * 1000;
8
+ const HOUR_MS = 60 * MINUTE_MS;
9
+ const DAY_MS = 24 * HOUR_MS;
10
+ // The server accepts MINUTE buckets for windows up to 2 hours and HOUR buckets
11
+ // for windows up to 4 days.
12
+ const MINUTE_GRANULARITY_MAX_HOURS = 2;
13
+ const HOUR_GRANULARITY_MAX_HOURS = 4 * 24;
14
+ const GRANULARITY_INTERVAL_MS = {
15
+ [generated_1.WorkflowsInsightsRunsOverTimeGranularity.Minute]: MINUTE_MS,
16
+ [generated_1.WorkflowsInsightsRunsOverTimeGranularity.Hour]: HOUR_MS,
17
+ [generated_1.WorkflowsInsightsRunsOverTimeGranularity.Day]: DAY_MS,
18
+ };
19
+ // Finest first, derived from the table above so a bucket size added to the generated enum cannot
20
+ // be silently skipped here.
21
+ const GRANULARITIES_FINEST_FIRST = Object.keys(GRANULARITY_INTERVAL_MS).sort((a, b) => GRANULARITY_INTERVAL_MS[a] - GRANULARITY_INTERVAL_MS[b]);
22
+ function granularityForTimespan(startTime, endTime) {
23
+ const hours = (new Date(endTime).getTime() - new Date(startTime).getTime()) / HOUR_MS;
24
+ if (hours <= MINUTE_GRANULARITY_MAX_HOURS) {
25
+ return generated_1.WorkflowsInsightsRunsOverTimeGranularity.Minute;
26
+ }
27
+ if (hours <= HOUR_GRANULARITY_MAX_HOURS) {
28
+ return generated_1.WorkflowsInsightsRunsOverTimeGranularity.Hour;
29
+ }
30
+ return generated_1.WorkflowsInsightsRunsOverTimeGranularity.Day;
31
+ }
32
+ /**
33
+ * Widen a requested window out to whole buckets, and report the bucket size the widened window
34
+ * needs.
35
+ *
36
+ * The server widens only the runs-over-time query to whole buckets and leaves the overview and
37
+ * per-workflow queries on the exact bounds, so an unaligned window makes those sections count
38
+ * different runs. Sending the widened window turns that server-side widening into a no-op.
39
+ *
40
+ * Widening lengthens the window, which can push it past the threshold of the very bucket size it
41
+ * was widened by, so each candidate is only accepted if the widened window still asks for it.
42
+ * Falling through to the coarsest bucket means every finer one was ruled out, and widening by a
43
+ * coarser bucket is at least as wide, so the coarsest is always self-consistent.
44
+ *
45
+ * Widening the end past now puts unelapsed time in the current period while the previous period
46
+ * the server compares it against is complete, so count metrics span unequal exposure.
47
+ */
48
+ function alignInsightsTimespan(timespan) {
49
+ const startMs = new Date(timespan.startTime).getTime();
50
+ const endMs = new Date(timespan.endTime).getTime();
51
+ // Every candidate widens the originally requested window, so a coarser one does not stack
52
+ // another bucket of padding onto an already widened window.
53
+ const coarsest = GRANULARITIES_FINEST_FIRST[GRANULARITIES_FINEST_FIRST.length - 1];
54
+ const granularity = GRANULARITIES_FINEST_FIRST.slice(0, -1).find(candidate => {
55
+ const widened = widenToWholeBuckets(startMs, endMs, candidate);
56
+ return granularityForTimespan(widened.startTime, widened.endTime) === candidate;
57
+ }) ?? coarsest;
58
+ return { timespan: widenToWholeBuckets(startMs, endMs, granularity), granularity };
59
+ }
60
+ function widenToWholeBuckets(startMs, endMs, granularity) {
61
+ const interval = GRANULARITY_INTERVAL_MS[granularity];
62
+ return {
63
+ startTime: new Date(Math.floor(startMs / interval) * interval).toISOString(),
64
+ endTime: new Date(Math.ceil(endMs / interval) * interval).toISOString(),
65
+ };
66
+ }
67
+ // Maestro insights use their own enum for the same three bucket sizes.
68
+ const MAESTRO_GRANULARITY = {
69
+ [generated_1.WorkflowsInsightsRunsOverTimeGranularity.Minute]: generated_1.WorkflowDeviceTestCaseInsightsTimeSeriesGranularity.Minute,
70
+ [generated_1.WorkflowsInsightsRunsOverTimeGranularity.Hour]: generated_1.WorkflowDeviceTestCaseInsightsTimeSeriesGranularity.Hour,
71
+ [generated_1.WorkflowsInsightsRunsOverTimeGranularity.Day]: generated_1.WorkflowDeviceTestCaseInsightsTimeSeriesGranularity.Day,
72
+ };
73
+ function alignMaestroInsightsTimespan(timespan) {
74
+ const aligned = alignInsightsTimespan(timespan);
75
+ return {
76
+ timespan: aligned.timespan,
77
+ granularity: MAESTRO_GRANULARITY[aligned.granularity],
78
+ };
79
+ }
@@ -0,0 +1,23 @@
1
+ import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient';
2
+ import { WorkflowDeviceTestCaseHistoryFiltersInput, WorkflowDeviceTestCaseInsightsFiltersInput } from '../../graphql/generated';
3
+ /** Statuses as the dashboard names them; `PASSED` means passed on the first attempt. */
4
+ export declare const MAESTRO_STATUS_OPTIONS: readonly ["PASSED", "FLAKY", "FAILED"];
5
+ export type MaestroStatusOption = (typeof MAESTRO_STATUS_OPTIONS)[number];
6
+ export interface MaestroInsightsFilterFlags {
7
+ workflow?: string[];
8
+ status?: MaestroStatusOption[];
9
+ tag?: string[];
10
+ search?: string;
11
+ 'git-ref'?: string;
12
+ }
13
+ /** The filters as the user typed them, before workflow file names are resolved to IDs. */
14
+ export interface AppliedMaestroInsightsFilters {
15
+ workflows?: string[];
16
+ statuses?: MaestroStatusOption[];
17
+ tags?: string[];
18
+ search?: string;
19
+ gitRef?: string;
20
+ }
21
+ export declare function resolveMaestroHistoryFiltersInputAsync(graphqlClient: ExpoGraphqlClient, appId: string, flags: Pick<MaestroInsightsFilterFlags, 'workflow' | 'git-ref'>): Promise<WorkflowDeviceTestCaseHistoryFiltersInput | undefined>;
22
+ export declare function resolveMaestroInsightsFiltersInputAsync(graphqlClient: ExpoGraphqlClient, appId: string, flags: MaestroInsightsFilterFlags): Promise<WorkflowDeviceTestCaseInsightsFiltersInput | undefined>;
23
+ export declare function getAppliedMaestroInsightsFilters(flags: MaestroInsightsFilterFlags): AppliedMaestroInsightsFilters | undefined;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAESTRO_STATUS_OPTIONS = void 0;
4
+ exports.resolveMaestroHistoryFiltersInputAsync = resolveMaestroHistoryFiltersInputAsync;
5
+ exports.resolveMaestroInsightsFiltersInputAsync = resolveMaestroInsightsFiltersInputAsync;
6
+ exports.getAppliedMaestroInsightsFilters = getAppliedMaestroInsightsFilters;
7
+ const generated_1 = require("../../graphql/generated");
8
+ const filters_1 = require("./filters");
9
+ /** Statuses as the dashboard names them; `PASSED` means passed on the first attempt. */
10
+ exports.MAESTRO_STATUS_OPTIONS = ['PASSED', 'FLAKY', 'FAILED'];
11
+ const STATUS_FILTER_BY_OPTION = {
12
+ PASSED: generated_1.WorkflowDeviceTestCaseStatusFilter.PassedClean,
13
+ FLAKY: generated_1.WorkflowDeviceTestCaseStatusFilter.Flaky,
14
+ FAILED: generated_1.WorkflowDeviceTestCaseStatusFilter.Failed,
15
+ };
16
+ async function resolveMaestroHistoryFiltersInputAsync(graphqlClient, appId, flags) {
17
+ const input = {};
18
+ if (flags.workflow?.length) {
19
+ input.workflowIds = await (0, filters_1.resolveWorkflowIdsAsync)(graphqlClient, appId, flags.workflow);
20
+ }
21
+ if (flags['git-ref']) {
22
+ input.gitRefs = [(0, filters_1.normalizeGitRef)(flags['git-ref'])];
23
+ }
24
+ return Object.keys(input).length === 0 ? undefined : input;
25
+ }
26
+ async function resolveMaestroInsightsFiltersInputAsync(graphqlClient, appId, flags) {
27
+ const input = {
28
+ ...(await resolveMaestroHistoryFiltersInputAsync(graphqlClient, appId, flags)),
29
+ };
30
+ if (flags.status?.length) {
31
+ input.statuses = flags.status.map(status => STATUS_FILTER_BY_OPTION[status]);
32
+ }
33
+ if (flags.tag?.length) {
34
+ input.tags = flags.tag;
35
+ }
36
+ return Object.keys(input).length === 0 ? undefined : input;
37
+ }
38
+ function getAppliedMaestroInsightsFilters(flags) {
39
+ const applied = {
40
+ ...(flags.workflow?.length ? { workflows: flags.workflow } : {}),
41
+ ...(flags.status?.length ? { statuses: flags.status } : {}),
42
+ ...(flags.tag?.length ? { tags: flags.tag } : {}),
43
+ ...(flags.search ? { search: flags.search } : {}),
44
+ ...(flags['git-ref'] ? { gitRef: (0, filters_1.normalizeGitRef)(flags['git-ref']) } : {}),
45
+ };
46
+ return Object.keys(applied).length === 0 ? undefined : applied;
47
+ }
@@ -0,0 +1,7 @@
1
+ import { WorkflowDeviceTestCaseSortDirection, WorkflowDeviceTestCaseStatSortField } from '../../graphql/generated';
2
+ export declare const MAESTRO_SORT_OPTIONS: readonly ["fails", "runs", "flakes", "pass-rate", "flake-rate", "p90", "last-run"];
3
+ export type MaestroSortOption = (typeof MAESTRO_SORT_OPTIONS)[number];
4
+ export declare const MAESTRO_SORT_DIRECTIONS: readonly ["asc", "desc"];
5
+ export type MaestroSortDirection = (typeof MAESTRO_SORT_DIRECTIONS)[number];
6
+ export declare const SORT_FIELD_BY_OPTION: Record<MaestroSortOption, WorkflowDeviceTestCaseStatSortField>;
7
+ export declare const SORT_DIRECTION_BY_OPTION: Record<MaestroSortDirection, WorkflowDeviceTestCaseSortDirection>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SORT_DIRECTION_BY_OPTION = exports.SORT_FIELD_BY_OPTION = exports.MAESTRO_SORT_DIRECTIONS = exports.MAESTRO_SORT_OPTIONS = void 0;
4
+ const generated_1 = require("../../graphql/generated");
5
+ exports.MAESTRO_SORT_OPTIONS = [
6
+ 'fails',
7
+ 'runs',
8
+ 'flakes',
9
+ 'pass-rate',
10
+ 'flake-rate',
11
+ 'p90',
12
+ 'last-run',
13
+ ];
14
+ exports.MAESTRO_SORT_DIRECTIONS = ['asc', 'desc'];
15
+ exports.SORT_FIELD_BY_OPTION = {
16
+ runs: generated_1.WorkflowDeviceTestCaseStatSortField.Runs,
17
+ fails: generated_1.WorkflowDeviceTestCaseStatSortField.Fails,
18
+ flakes: generated_1.WorkflowDeviceTestCaseStatSortField.Flakes,
19
+ 'pass-rate': generated_1.WorkflowDeviceTestCaseStatSortField.PassRate,
20
+ 'flake-rate': generated_1.WorkflowDeviceTestCaseStatSortField.FlakeRate,
21
+ p90: generated_1.WorkflowDeviceTestCaseStatSortField.P90Duration,
22
+ 'last-run': generated_1.WorkflowDeviceTestCaseStatSortField.LastRun,
23
+ };
24
+ exports.SORT_DIRECTION_BY_OPTION = {
25
+ asc: generated_1.WorkflowDeviceTestCaseSortDirection.Asc,
26
+ desc: generated_1.WorkflowDeviceTestCaseSortDirection.Desc,
27
+ };
@@ -0,0 +1,6 @@
1
+ export declare const EAS_WORKFLOWS_INSIGHTS_NOT_AVAILABLE_ERROR_CODE = "EAS_WORKFLOWS_INSIGHTS_NOT_AVAILABLE";
2
+ export declare const EAS_WORKFLOWS_INSIGHTS_TIMESPAN_LIMIT_EXCEEDED_ERROR_CODE = "EAS_WORKFLOWS_INSIGHTS_TIMESPAN_LIMIT_EXCEEDED";
3
+ export declare const EAS_WORKFLOW_DEVICE_TEST_CASE_INSIGHTS_NOT_AVAILABLE_ERROR_CODE = "EAS_WORKFLOW_DEVICE_TEST_CASE_INSIGHTS_NOT_AVAILABLE";
4
+ export declare const EAS_WORKFLOW_DEVICE_TEST_CASE_INSIGHTS_TIMESPAN_LIMIT_EXCEEDED_ERROR_CODE = "EAS_WORKFLOW_DEVICE_TEST_CASE_INSIGHTS_TIMESPAN_LIMIT_EXCEEDED";
5
+ /** Plan-gate rejections from either insights surface become a plain error message. */
6
+ export declare function withInsightsPlanGateHandlingAsync<T>(fn: () => Promise<T>): Promise<T>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EAS_WORKFLOW_DEVICE_TEST_CASE_INSIGHTS_TIMESPAN_LIMIT_EXCEEDED_ERROR_CODE = exports.EAS_WORKFLOW_DEVICE_TEST_CASE_INSIGHTS_NOT_AVAILABLE_ERROR_CODE = exports.EAS_WORKFLOWS_INSIGHTS_TIMESPAN_LIMIT_EXCEEDED_ERROR_CODE = exports.EAS_WORKFLOWS_INSIGHTS_NOT_AVAILABLE_ERROR_CODE = void 0;
4
+ exports.withInsightsPlanGateHandlingAsync = withInsightsPlanGateHandlingAsync;
5
+ const errors_1 = require("../../commandUtils/errors");
6
+ const planGating_1 = require("../../commandUtils/planGating");
7
+ // Must match the server's plan-gate error codes (`ExpoErrorCode`).
8
+ exports.EAS_WORKFLOWS_INSIGHTS_NOT_AVAILABLE_ERROR_CODE = 'EAS_WORKFLOWS_INSIGHTS_NOT_AVAILABLE';
9
+ exports.EAS_WORKFLOWS_INSIGHTS_TIMESPAN_LIMIT_EXCEEDED_ERROR_CODE = 'EAS_WORKFLOWS_INSIGHTS_TIMESPAN_LIMIT_EXCEEDED';
10
+ exports.EAS_WORKFLOW_DEVICE_TEST_CASE_INSIGHTS_NOT_AVAILABLE_ERROR_CODE = 'EAS_WORKFLOW_DEVICE_TEST_CASE_INSIGHTS_NOT_AVAILABLE';
11
+ exports.EAS_WORKFLOW_DEVICE_TEST_CASE_INSIGHTS_TIMESPAN_LIMIT_EXCEEDED_ERROR_CODE = 'EAS_WORKFLOW_DEVICE_TEST_CASE_INSIGHTS_TIMESPAN_LIMIT_EXCEEDED';
12
+ const PLAN_GATE_ERROR_CODES = new Set([
13
+ exports.EAS_WORKFLOWS_INSIGHTS_NOT_AVAILABLE_ERROR_CODE,
14
+ exports.EAS_WORKFLOWS_INSIGHTS_TIMESPAN_LIMIT_EXCEEDED_ERROR_CODE,
15
+ exports.EAS_WORKFLOW_DEVICE_TEST_CASE_INSIGHTS_NOT_AVAILABLE_ERROR_CODE,
16
+ exports.EAS_WORKFLOW_DEVICE_TEST_CASE_INSIGHTS_TIMESPAN_LIMIT_EXCEEDED_ERROR_CODE,
17
+ ]);
18
+ /** Plan-gate rejections from either insights surface become a plain error message. */
19
+ async function withInsightsPlanGateHandlingAsync(fn) {
20
+ try {
21
+ return await fn();
22
+ }
23
+ catch (error) {
24
+ const planGateError = (0, planGating_1.findPlanGateError)(error, PLAN_GATE_ERROR_CODES);
25
+ if (!planGateError) {
26
+ throw error;
27
+ }
28
+ const limitDays = planGateError.extensions?.metadata
29
+ ?.limitDays;
30
+ const limitText = typeof limitDays === 'number' ? ` Your plan includes the last ${limitDays} days.` : '';
31
+ throw new errors_1.EasCommandError(`${planGateError.message}${limitText}`);
32
+ }
33
+ }