@hot-updater/plugin-insights 1.0.0-rc.20
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/LICENSE +33 -0
- package/README.md +24 -0
- package/client/package.json +7 -0
- package/dist/client/eventId.cjs +181 -0
- package/dist/client/eventId.mjs +179 -0
- package/dist/client/index.cjs +234 -0
- package/dist/client/index.d.cts +42 -0
- package/dist/client/index.d.mts +42 -0
- package/dist/client/index.mjs +233 -0
- package/dist/client/sender.cjs +103 -0
- package/dist/client/sender.mjs +103 -0
- package/dist/client/state.cjs +121 -0
- package/dist/client/state.mjs +119 -0
- package/dist/internal.cjs +9 -0
- package/dist/internal.d.cts +5 -0
- package/dist/internal.d.mts +5 -0
- package/dist/internal.mjs +5 -0
- package/dist/server/contract.cjs +193 -0
- package/dist/server/contract.mjs +189 -0
- package/dist/server/domain.d.cts +149 -0
- package/dist/server/domain.d.mts +149 -0
- package/dist/server/errors.cjs +15 -0
- package/dist/server/errors.d.cts +6 -0
- package/dist/server/errors.d.mts +6 -0
- package/dist/server/errors.mjs +14 -0
- package/dist/server/eventInput.cjs +284 -0
- package/dist/server/eventInput.d.cts +6 -0
- package/dist/server/eventInput.d.mts +6 -0
- package/dist/server/eventInput.mjs +282 -0
- package/dist/server/eventRow.cjs +49 -0
- package/dist/server/eventRow.d.cts +64 -0
- package/dist/server/eventRow.d.mts +64 -0
- package/dist/server/eventRow.mjs +47 -0
- package/dist/server/index.cjs +128 -0
- package/dist/server/index.d.cts +394 -0
- package/dist/server/index.d.mts +394 -0
- package/dist/server/index.mjs +121 -0
- package/dist/server/model.cjs +17 -0
- package/dist/server/model.d.cts +10 -0
- package/dist/server/model.d.mts +10 -0
- package/dist/server/model.mjs +17 -0
- package/dist/server/modelTypes.d.cts +176 -0
- package/dist/server/modelTypes.d.mts +176 -0
- package/dist/server/overview.cjs +109 -0
- package/dist/server/overview.d.cts +15 -0
- package/dist/server/overview.d.mts +15 -0
- package/dist/server/overview.mjs +107 -0
- package/dist/server/provider.cjs +375 -0
- package/dist/server/provider.d.cts +6 -0
- package/dist/server/provider.d.mts +6 -0
- package/dist/server/provider.mjs +374 -0
- package/dist/server/queryInput.cjs +93 -0
- package/dist/server/queryInput.mjs +91 -0
- package/dist/server/reads.cjs +681 -0
- package/dist/server/reads.d.cts +60 -0
- package/dist/server/reads.d.mts +60 -0
- package/dist/server/reads.mjs +674 -0
- package/dist/server/recordEvent.cjs +319 -0
- package/dist/server/recordEvent.d.cts +17 -0
- package/dist/server/recordEvent.d.mts +17 -0
- package/dist/server/recordEvent.mjs +316 -0
- package/dist/server/routes.cjs +96 -0
- package/dist/server/routes.d.cts +36 -0
- package/dist/server/routes.d.mts +36 -0
- package/dist/server/routes.mjs +95 -0
- package/dist/server/schema.cjs +489 -0
- package/dist/server/schema.d.cts +706 -0
- package/dist/server/schema.d.mts +706 -0
- package/dist/server/schema.mjs +483 -0
- package/dist/server/testing/eventRow.d.mts +64 -0
- package/dist/server/testing/expectInsightsIndex.mjs +18 -0
- package/dist/server/testing/fixtures.d.mts +8 -0
- package/dist/server/testing/fixtures.mjs +25 -0
- package/dist/server/testing/index.d.mts +24 -0
- package/dist/server/testing/index.mjs +25 -0
- package/dist/server/testing/insightsModelTests.mjs +714 -0
- package/dist/server/testing/modelTypes.d.mts +176 -0
- package/dist/server/testing/setupInsightsHttpTestSuite.d.mts +11 -0
- package/dist/server/testing/setupInsightsHttpTestSuite.mjs +107 -0
- package/dist/server/testing/setupInsightsModelTestSuite.d.mts +11 -0
- package/dist/server/testing/setupInsightsModelTestSuite.mjs +31 -0
- package/dist/server/testing/types.d.mts +26 -0
- package/dist/server/types.d.cts +33 -0
- package/dist/server/types.d.mts +33 -0
- package/package.json +68 -0
|
@@ -0,0 +1,714 @@
|
|
|
1
|
+
import { expectInsightsIndex } from "./expectInsightsIndex.mjs";
|
|
2
|
+
import { createBundleEventRowFixture } from "./fixtures.mjs";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
//#region src/server/testing/insightsModelTests.ts
|
|
5
|
+
const record = (model, event) => model.recordEvent({ event });
|
|
6
|
+
const createMovementEvent = (suffix, receivedAtMs, type, installId) => {
|
|
7
|
+
const row = createBundleEventRowFixture(suffix, receivedAtMs);
|
|
8
|
+
return {
|
|
9
|
+
...row,
|
|
10
|
+
type,
|
|
11
|
+
install_id: installId,
|
|
12
|
+
from_bundle_id: row.to_bundle_id,
|
|
13
|
+
metadata: {
|
|
14
|
+
...row.metadata,
|
|
15
|
+
update_strategy: "appVersion"
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The Insights report contract on `InsightsModel`: what the Insights plugin
|
|
21
|
+
* records and reads, through `createInsightsModel`, on one database.
|
|
22
|
+
*/
|
|
23
|
+
const registerInsightsModelTests = (state) => {
|
|
24
|
+
describe("Insights report contract", () => {
|
|
25
|
+
it("preserves ancillary JSON through event history and latest-event reads", async () => {
|
|
26
|
+
const model = state.getDatabase();
|
|
27
|
+
const base = createBundleEventRowFixture("979", 100);
|
|
28
|
+
const event = {
|
|
29
|
+
...base,
|
|
30
|
+
metadata: {
|
|
31
|
+
...base.metadata,
|
|
32
|
+
device: {
|
|
33
|
+
locale: "ko-KR",
|
|
34
|
+
tags: [
|
|
35
|
+
"minor",
|
|
36
|
+
null,
|
|
37
|
+
true,
|
|
38
|
+
2
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
diagnostic: null
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
await record(model, event);
|
|
45
|
+
await expect(model.findLatestEvents({ installId: event.install_id })).resolves.toEqual([event]);
|
|
46
|
+
await expectInsightsIndex(() => model.listEvents({
|
|
47
|
+
filter: { kind: "all" },
|
|
48
|
+
beforeReceivedAtMs: 101,
|
|
49
|
+
limit: 10
|
|
50
|
+
}), [event]);
|
|
51
|
+
});
|
|
52
|
+
it("selects the latest complete event across download, replacement, apply, and delayed reports", async () => {
|
|
53
|
+
const model = state.getDatabase();
|
|
54
|
+
const download = {
|
|
55
|
+
...createBundleEventRowFixture("980", 100),
|
|
56
|
+
type: "UPDATE_DOWNLOADED",
|
|
57
|
+
from_bundle_id: "00000000-0000-7000-8000-000000001980",
|
|
58
|
+
metadata: {
|
|
59
|
+
...createBundleEventRowFixture("980", 100).metadata,
|
|
60
|
+
update_strategy: "appVersion"
|
|
61
|
+
},
|
|
62
|
+
to_release_id: "00000000-0000-7000-8000-000000004980"
|
|
63
|
+
};
|
|
64
|
+
await record(model, download);
|
|
65
|
+
await record(model, download);
|
|
66
|
+
await expect(model.findLatestEvents({ installId: download.install_id })).resolves.toEqual([download]);
|
|
67
|
+
await expectInsightsIndex(() => model.listEvents({
|
|
68
|
+
filter: {
|
|
69
|
+
kind: "bundle",
|
|
70
|
+
type: "UPDATE_DOWNLOADED",
|
|
71
|
+
toBundleId: download.to_bundle_id,
|
|
72
|
+
platform: "ios",
|
|
73
|
+
channel: "production"
|
|
74
|
+
},
|
|
75
|
+
beforeReceivedAtMs: 200,
|
|
76
|
+
limit: 10
|
|
77
|
+
}), [download]);
|
|
78
|
+
const replacement = {
|
|
79
|
+
...download,
|
|
80
|
+
id: createBundleEventRowFixture("981", 110).id,
|
|
81
|
+
received_at_ms: 110,
|
|
82
|
+
to_bundle_id: "00000000-0000-7000-8000-000000002981"
|
|
83
|
+
};
|
|
84
|
+
await record(model, replacement);
|
|
85
|
+
await expect(model.findLatestEvents({ installId: download.install_id })).resolves.toEqual([replacement]);
|
|
86
|
+
const applied = {
|
|
87
|
+
...replacement,
|
|
88
|
+
type: "UPDATE_APPLIED",
|
|
89
|
+
id: createBundleEventRowFixture("982", 120).id,
|
|
90
|
+
received_at_ms: 120
|
|
91
|
+
};
|
|
92
|
+
await record(model, applied);
|
|
93
|
+
await record(model, {
|
|
94
|
+
...download,
|
|
95
|
+
id: createBundleEventRowFixture("983", 105).id,
|
|
96
|
+
received_at_ms: 105
|
|
97
|
+
});
|
|
98
|
+
await expect(model.findLatestEvents({ installId: download.install_id })).resolves.toEqual([applied]);
|
|
99
|
+
await expectInsightsIndex(() => model.listEvents({
|
|
100
|
+
filter: {
|
|
101
|
+
kind: "installationMovement",
|
|
102
|
+
installId: download.install_id
|
|
103
|
+
},
|
|
104
|
+
beforeReceivedAtMs: 200,
|
|
105
|
+
limit: 10
|
|
106
|
+
}), [
|
|
107
|
+
applied,
|
|
108
|
+
replacement,
|
|
109
|
+
{
|
|
110
|
+
...download,
|
|
111
|
+
id: createBundleEventRowFixture("983", 105).id,
|
|
112
|
+
received_at_ms: 105
|
|
113
|
+
},
|
|
114
|
+
download
|
|
115
|
+
]);
|
|
116
|
+
});
|
|
117
|
+
it("treats duplicate IDs as complete no-ops, including changed retry payloads", async () => {
|
|
118
|
+
const model = state.getDatabase();
|
|
119
|
+
const event = createBundleEventRowFixture("901", 100);
|
|
120
|
+
await Promise.all([
|
|
121
|
+
record(model, event),
|
|
122
|
+
record(model, event),
|
|
123
|
+
record(model, event)
|
|
124
|
+
]);
|
|
125
|
+
await record(model, event);
|
|
126
|
+
const changed = {
|
|
127
|
+
...event,
|
|
128
|
+
received_at_ms: 300,
|
|
129
|
+
user_id: "changed-user"
|
|
130
|
+
};
|
|
131
|
+
await record(model, changed);
|
|
132
|
+
const otherInstallation = {
|
|
133
|
+
...changed,
|
|
134
|
+
install_id: "different-install"
|
|
135
|
+
};
|
|
136
|
+
await record(model, otherInstallation);
|
|
137
|
+
await expect(model.findLatestEvents({ installId: event.install_id })).resolves.toEqual([event]);
|
|
138
|
+
await expect(model.findLatestEvents({ installId: otherInstallation.install_id })).resolves.toEqual([]);
|
|
139
|
+
await expectInsightsIndex(() => model.listEvents({
|
|
140
|
+
filter: { kind: "all" },
|
|
141
|
+
beforeReceivedAtMs: 400,
|
|
142
|
+
limit: 10
|
|
143
|
+
}), [event]);
|
|
144
|
+
});
|
|
145
|
+
it("keeps all concurrent events and the greatest timestamp/ID state, including logout", async () => {
|
|
146
|
+
const model = state.getDatabase();
|
|
147
|
+
const older = {
|
|
148
|
+
...createBundleEventRowFixture("912", 100),
|
|
149
|
+
install_id: "concurrent",
|
|
150
|
+
user_id: "previous"
|
|
151
|
+
};
|
|
152
|
+
const tied = {
|
|
153
|
+
...createBundleEventRowFixture("910", 200),
|
|
154
|
+
install_id: "concurrent",
|
|
155
|
+
user_id: "previous"
|
|
156
|
+
};
|
|
157
|
+
const newest = {
|
|
158
|
+
...createBundleEventRowFixture("911", 200),
|
|
159
|
+
install_id: "concurrent",
|
|
160
|
+
user_id: null
|
|
161
|
+
};
|
|
162
|
+
await Promise.all([
|
|
163
|
+
record(model, newest),
|
|
164
|
+
record(model, older),
|
|
165
|
+
record(model, tied)
|
|
166
|
+
]);
|
|
167
|
+
await record(model, older);
|
|
168
|
+
await expect(model.findLatestEvents({ installId: "concurrent" })).resolves.toEqual([newest]);
|
|
169
|
+
await expect(model.findLatestEvents({
|
|
170
|
+
userId: "previous",
|
|
171
|
+
limit: 10
|
|
172
|
+
})).resolves.toEqual([]);
|
|
173
|
+
await expectInsightsIndex(() => model.listEvents({
|
|
174
|
+
filter: { kind: "all" },
|
|
175
|
+
beforeReceivedAtMs: 201,
|
|
176
|
+
limit: 10
|
|
177
|
+
}), [
|
|
178
|
+
newest,
|
|
179
|
+
tied,
|
|
180
|
+
older
|
|
181
|
+
]);
|
|
182
|
+
});
|
|
183
|
+
it("rejects invalid event metadata before persisting a report", async () => {
|
|
184
|
+
const model = state.getDatabase();
|
|
185
|
+
const event = createBundleEventRowFixture("920", 100);
|
|
186
|
+
await expect(model.recordEvent({ event: {
|
|
187
|
+
...event,
|
|
188
|
+
metadata: {
|
|
189
|
+
...event.metadata,
|
|
190
|
+
cohort: 123
|
|
191
|
+
}
|
|
192
|
+
} })).rejects.toMatchObject({ code: "invalid-data" });
|
|
193
|
+
await expect(model.findLatestEvents({ installId: event.install_id })).resolves.toEqual([]);
|
|
194
|
+
await expect(model.listEvents({
|
|
195
|
+
filter: { kind: "all" },
|
|
196
|
+
beforeReceivedAtMs: 200,
|
|
197
|
+
limit: 10
|
|
198
|
+
})).resolves.toEqual([]);
|
|
199
|
+
});
|
|
200
|
+
it("shares scoped list/count predicates, recovery attribution, and half-open time bounds", async () => {
|
|
201
|
+
const model = state.getDatabase();
|
|
202
|
+
const bundleA = createBundleEventRowFixture("1", 0).to_bundle_id;
|
|
203
|
+
const bundleB = createBundleEventRowFixture("2", 0).to_bundle_id;
|
|
204
|
+
const bundleC = createBundleEventRowFixture("3", 0).to_bundle_id;
|
|
205
|
+
const applied = {
|
|
206
|
+
...createBundleEventRowFixture("930", 100),
|
|
207
|
+
install_id: "target",
|
|
208
|
+
to_bundle_id: bundleB
|
|
209
|
+
};
|
|
210
|
+
const recovered = {
|
|
211
|
+
...createBundleEventRowFixture("931", 120),
|
|
212
|
+
install_id: "target",
|
|
213
|
+
type: "RECOVERED",
|
|
214
|
+
from_bundle_id: bundleB,
|
|
215
|
+
to_bundle_id: bundleA,
|
|
216
|
+
metadata: {
|
|
217
|
+
...createBundleEventRowFixture("931", 120).metadata,
|
|
218
|
+
update_strategy: "appVersion"
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const unchanged = {
|
|
222
|
+
...createBundleEventRowFixture("932", 130),
|
|
223
|
+
type: "UNCHANGED",
|
|
224
|
+
from_bundle_id: null,
|
|
225
|
+
to_bundle_id: bundleB,
|
|
226
|
+
metadata: {
|
|
227
|
+
...createBundleEventRowFixture("932", 130).metadata,
|
|
228
|
+
update_strategy: null
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
const excluded = [
|
|
232
|
+
{
|
|
233
|
+
...applied,
|
|
234
|
+
id: createBundleEventRowFixture("933", 99).id,
|
|
235
|
+
install_id: "before",
|
|
236
|
+
received_at_ms: 99
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
...applied,
|
|
240
|
+
id: createBundleEventRowFixture("934", 200).id,
|
|
241
|
+
install_id: "after",
|
|
242
|
+
received_at_ms: 200
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
...applied,
|
|
246
|
+
id: createBundleEventRowFixture("935", 110).id,
|
|
247
|
+
install_id: "android",
|
|
248
|
+
platform: "android"
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
...applied,
|
|
252
|
+
id: createBundleEventRowFixture("936", 110).id,
|
|
253
|
+
install_id: "preview",
|
|
254
|
+
channel: "preview"
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
...recovered,
|
|
258
|
+
id: createBundleEventRowFixture("937", 125).id,
|
|
259
|
+
install_id: "other-source",
|
|
260
|
+
from_bundle_id: bundleC,
|
|
261
|
+
to_bundle_id: bundleB
|
|
262
|
+
}
|
|
263
|
+
];
|
|
264
|
+
for (const row of [
|
|
265
|
+
applied,
|
|
266
|
+
recovered,
|
|
267
|
+
unchanged,
|
|
268
|
+
...excluded
|
|
269
|
+
]) await record(model, row);
|
|
270
|
+
await expect(async () => record(model, {
|
|
271
|
+
...applied,
|
|
272
|
+
type: "RELEASE_ADOPTED"
|
|
273
|
+
})).rejects.toThrow();
|
|
274
|
+
await expect(async () => record(model, {
|
|
275
|
+
...applied,
|
|
276
|
+
type: "UNCHANGED",
|
|
277
|
+
from_bundle_id: bundleB,
|
|
278
|
+
metadata: {
|
|
279
|
+
...applied.metadata,
|
|
280
|
+
update_strategy: "appVersion"
|
|
281
|
+
}
|
|
282
|
+
})).rejects.toThrow();
|
|
283
|
+
await expect(model.findLatestEvents({ installId: "target" })).resolves.toEqual([recovered]);
|
|
284
|
+
const cases = [[{
|
|
285
|
+
platform: "ios",
|
|
286
|
+
channel: "production",
|
|
287
|
+
type: "UPDATE_APPLIED",
|
|
288
|
+
toBundleId: bundleB
|
|
289
|
+
}, applied], [{
|
|
290
|
+
platform: "ios",
|
|
291
|
+
channel: "production",
|
|
292
|
+
type: "RECOVERED",
|
|
293
|
+
fromBundleId: bundleB
|
|
294
|
+
}, recovered]];
|
|
295
|
+
for (const [filter, expected] of cases) {
|
|
296
|
+
await expectInsightsIndex(() => model.countEvents({
|
|
297
|
+
filter,
|
|
298
|
+
sinceMs: 100,
|
|
299
|
+
beforeReceivedAtMs: 200
|
|
300
|
+
}), 1);
|
|
301
|
+
await expectInsightsIndex(() => model.listEvents({
|
|
302
|
+
filter: {
|
|
303
|
+
kind: "bundle",
|
|
304
|
+
...filter
|
|
305
|
+
},
|
|
306
|
+
sinceMs: 100,
|
|
307
|
+
beforeReceivedAtMs: 200,
|
|
308
|
+
limit: 1
|
|
309
|
+
}), [expected]);
|
|
310
|
+
}
|
|
311
|
+
await expect(model.findLatestEvents({ installId: unchanged.install_id })).resolves.toEqual([unchanged]);
|
|
312
|
+
await expectInsightsIndex(() => model.listEvents({
|
|
313
|
+
filter: { kind: "all" },
|
|
314
|
+
sinceMs: 100,
|
|
315
|
+
beforeReceivedAtMs: 200,
|
|
316
|
+
limit: 10
|
|
317
|
+
}), [
|
|
318
|
+
excluded[4],
|
|
319
|
+
recovered,
|
|
320
|
+
excluded[3],
|
|
321
|
+
excluded[2],
|
|
322
|
+
applied
|
|
323
|
+
]);
|
|
324
|
+
await expect(model.countEvents({
|
|
325
|
+
filter: {
|
|
326
|
+
platform: "ios",
|
|
327
|
+
channel: "production",
|
|
328
|
+
type: "UNCHANGED",
|
|
329
|
+
toBundleId: bundleB
|
|
330
|
+
},
|
|
331
|
+
sinceMs: 100,
|
|
332
|
+
beforeReceivedAtMs: 200
|
|
333
|
+
})).rejects.toThrow();
|
|
334
|
+
await expectInsightsIndex(() => model.countLatestEvents({
|
|
335
|
+
platform: "ios",
|
|
336
|
+
channel: "production",
|
|
337
|
+
sinceMs: 0,
|
|
338
|
+
bundle: [{
|
|
339
|
+
field: "to_bundle_id",
|
|
340
|
+
value: bundleA,
|
|
341
|
+
types: [
|
|
342
|
+
"UNCHANGED",
|
|
343
|
+
"UPDATE_APPLIED",
|
|
344
|
+
"RECOVERED"
|
|
345
|
+
]
|
|
346
|
+
}]
|
|
347
|
+
}), 1);
|
|
348
|
+
await expectInsightsIndex(() => model.countLatestEvents({
|
|
349
|
+
platform: "ios",
|
|
350
|
+
channel: "production",
|
|
351
|
+
sinceMs: 0
|
|
352
|
+
}), 5);
|
|
353
|
+
await expect(model.countLatestEvents({
|
|
354
|
+
platform: "ios",
|
|
355
|
+
channel: "production",
|
|
356
|
+
sinceMs: 100
|
|
357
|
+
})).rejects.toThrow();
|
|
358
|
+
});
|
|
359
|
+
it("uses exact identity and UTF-8 cursor order for user installations", async () => {
|
|
360
|
+
const model = state.getDatabase();
|
|
361
|
+
const ids = [
|
|
362
|
+
"Install-a",
|
|
363
|
+
"é",
|
|
364
|
+
"install-a",
|
|
365
|
+
"install-a ",
|
|
366
|
+
"é",
|
|
367
|
+
"",
|
|
368
|
+
"😀"
|
|
369
|
+
];
|
|
370
|
+
const events = ids.map((install_id, index) => ({
|
|
371
|
+
...createBundleEventRowFixture(String(950 + index), 100),
|
|
372
|
+
install_id,
|
|
373
|
+
user_id: "User-é"
|
|
374
|
+
}));
|
|
375
|
+
for (const event of events.toReversed()) await record(model, event);
|
|
376
|
+
const spacedUser = {
|
|
377
|
+
...createBundleEventRowFixture("960", 100),
|
|
378
|
+
install_id: "spaced-user-install",
|
|
379
|
+
user_id: "User-é "
|
|
380
|
+
};
|
|
381
|
+
await record(model, spacedUser);
|
|
382
|
+
await expectInsightsIndex(async () => {
|
|
383
|
+
const found = [];
|
|
384
|
+
let afterInstallId;
|
|
385
|
+
for (let pageIndex = 0; pageIndex <= ids.length; pageIndex++) {
|
|
386
|
+
const page = await model.findLatestEvents({
|
|
387
|
+
userId: "User-é",
|
|
388
|
+
afterInstallId,
|
|
389
|
+
limit: 2
|
|
390
|
+
});
|
|
391
|
+
found.push(...page.map((row) => row.install_id));
|
|
392
|
+
if (page.length < 2) return found;
|
|
393
|
+
const nextCursor = page[page.length - 1].install_id;
|
|
394
|
+
expect(nextCursor, "Insights cursor must advance").not.toBe(afterInstallId);
|
|
395
|
+
afterInstallId = nextCursor;
|
|
396
|
+
}
|
|
397
|
+
throw new Error("Insights pagination did not terminate");
|
|
398
|
+
}, ids);
|
|
399
|
+
await expectInsightsIndex(() => model.findLatestEvents({
|
|
400
|
+
userId: "User-é ",
|
|
401
|
+
limit: 10
|
|
402
|
+
}), [spacedUser]);
|
|
403
|
+
await expect(model.findLatestEvents({
|
|
404
|
+
userId: "user-é",
|
|
405
|
+
limit: 10
|
|
406
|
+
})).resolves.toEqual([]);
|
|
407
|
+
await expect(model.findLatestEvents({ installId: "INSTALL-a" })).resolves.toEqual([]);
|
|
408
|
+
await expect(model.findLatestEvents({ installId: "Install-a" })).resolves.toEqual([events[0]]);
|
|
409
|
+
await expect(model.findLatestEvents({ installId: "install-a " })).resolves.toEqual([events[3]]);
|
|
410
|
+
await expect(model.findLatestEvents({ installId: "install-a" })).resolves.toEqual([events[2]]);
|
|
411
|
+
});
|
|
412
|
+
it("counts overlapping bundle predicates once per latest installation", async () => {
|
|
413
|
+
const model = state.getDatabase();
|
|
414
|
+
const event = createBundleEventRowFixture("9700", 100);
|
|
415
|
+
await record(model, event);
|
|
416
|
+
const predicate = {
|
|
417
|
+
field: "to_bundle_id",
|
|
418
|
+
value: event.to_bundle_id,
|
|
419
|
+
types: [event.type]
|
|
420
|
+
};
|
|
421
|
+
await expectInsightsIndex(() => model.countLatestEvents({
|
|
422
|
+
platform: event.platform,
|
|
423
|
+
channel: event.channel,
|
|
424
|
+
sinceMs: 0,
|
|
425
|
+
bundle: [predicate, predicate]
|
|
426
|
+
}), 1);
|
|
427
|
+
});
|
|
428
|
+
it("counts a latest installation once when a from and a to predicate both match it", async () => {
|
|
429
|
+
const model = state.getDatabase();
|
|
430
|
+
const moved = createBundleEventRowFixture("9701", 100);
|
|
431
|
+
await record(model, moved);
|
|
432
|
+
await expectInsightsIndex(() => model.countLatestEvents({
|
|
433
|
+
platform: moved.platform,
|
|
434
|
+
channel: moved.channel,
|
|
435
|
+
sinceMs: 0,
|
|
436
|
+
bundle: [{
|
|
437
|
+
field: "from_bundle_id",
|
|
438
|
+
value: moved.from_bundle_id,
|
|
439
|
+
types: [moved.type]
|
|
440
|
+
}, {
|
|
441
|
+
field: "to_bundle_id",
|
|
442
|
+
value: moved.to_bundle_id,
|
|
443
|
+
types: [moved.type]
|
|
444
|
+
}]
|
|
445
|
+
}), 1);
|
|
446
|
+
});
|
|
447
|
+
it("returns zero for successful empty scalar queries", async () => {
|
|
448
|
+
const model = state.getDatabase();
|
|
449
|
+
await expect(model.countLatestEvents({
|
|
450
|
+
platform: "ios",
|
|
451
|
+
channel: "production",
|
|
452
|
+
sinceMs: 0
|
|
453
|
+
})).resolves.toBe(0);
|
|
454
|
+
await expect(model.countEvents({
|
|
455
|
+
filter: {
|
|
456
|
+
platform: "ios",
|
|
457
|
+
channel: "production",
|
|
458
|
+
type: "RECOVERED",
|
|
459
|
+
fromBundleId: createBundleEventRowFixture("1", 0).to_bundle_id
|
|
460
|
+
},
|
|
461
|
+
sinceMs: 0,
|
|
462
|
+
beforeReceivedAtMs: 100
|
|
463
|
+
})).resolves.toBe(0);
|
|
464
|
+
});
|
|
465
|
+
it("maintains idempotent release, scope, usage, and latest-distribution summaries", async () => {
|
|
466
|
+
const model = state.getDatabase();
|
|
467
|
+
const releaseA = "00000000-0000-7000-8000-000000008001";
|
|
468
|
+
const releaseB = "00000000-0000-7000-8000-000000008002";
|
|
469
|
+
const download = {
|
|
470
|
+
...createBundleEventRowFixture("9801", 1e3),
|
|
471
|
+
type: "UPDATE_DOWNLOADED",
|
|
472
|
+
install_id: "summary-install-a",
|
|
473
|
+
from_release_id: releaseA,
|
|
474
|
+
to_release_id: releaseB
|
|
475
|
+
};
|
|
476
|
+
const appliedA = {
|
|
477
|
+
...download,
|
|
478
|
+
id: createBundleEventRowFixture("9802", 2e3).id,
|
|
479
|
+
type: "UPDATE_APPLIED",
|
|
480
|
+
received_at_ms: 2e3
|
|
481
|
+
};
|
|
482
|
+
const appliedB = {
|
|
483
|
+
...appliedA,
|
|
484
|
+
id: createBundleEventRowFixture("9803", 2100).id,
|
|
485
|
+
install_id: "summary-install-b",
|
|
486
|
+
received_at_ms: 2100
|
|
487
|
+
};
|
|
488
|
+
const recovered = {
|
|
489
|
+
...appliedA,
|
|
490
|
+
id: createBundleEventRowFixture("9804", 3e3).id,
|
|
491
|
+
type: "RECOVERED",
|
|
492
|
+
from_release_id: releaseB,
|
|
493
|
+
to_release_id: releaseA,
|
|
494
|
+
received_at_ms: 3e3
|
|
495
|
+
};
|
|
496
|
+
for (const event of [
|
|
497
|
+
download,
|
|
498
|
+
appliedA,
|
|
499
|
+
appliedB,
|
|
500
|
+
appliedB,
|
|
501
|
+
recovered
|
|
502
|
+
]) await record(model, event);
|
|
503
|
+
const releases = [{
|
|
504
|
+
releaseId: releaseA,
|
|
505
|
+
platform: "ios",
|
|
506
|
+
channel: "production"
|
|
507
|
+
}, {
|
|
508
|
+
releaseId: releaseB,
|
|
509
|
+
platform: "ios",
|
|
510
|
+
channel: "production"
|
|
511
|
+
}];
|
|
512
|
+
const lifetime = await model.getReleaseActivity({ releases });
|
|
513
|
+
expect(lifetime.data.map(({ metrics }) => metrics)).toEqual([{
|
|
514
|
+
downloads: 0,
|
|
515
|
+
launches: 1,
|
|
516
|
+
failedLaunches: 0
|
|
517
|
+
}, {
|
|
518
|
+
downloads: 1,
|
|
519
|
+
launches: 2,
|
|
520
|
+
failedLaunches: 1
|
|
521
|
+
}]);
|
|
522
|
+
const scope = await model.getReleaseActivity({
|
|
523
|
+
scope: {
|
|
524
|
+
platform: "ios",
|
|
525
|
+
channel: "production"
|
|
526
|
+
},
|
|
527
|
+
timeRange: {
|
|
528
|
+
start: 0,
|
|
529
|
+
end: 36e5
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
expect(scope.data[0]?.metrics).toMatchObject({
|
|
533
|
+
downloads: 1,
|
|
534
|
+
launches: 3,
|
|
535
|
+
failedLaunches: 1,
|
|
536
|
+
uniqueUsers: 2
|
|
537
|
+
});
|
|
538
|
+
const usage = await model.getAppUsage({
|
|
539
|
+
channel: "production",
|
|
540
|
+
platform: "all",
|
|
541
|
+
timeRange: {
|
|
542
|
+
start: 0,
|
|
543
|
+
end: 36e5
|
|
544
|
+
},
|
|
545
|
+
intervalMs: 36e5
|
|
546
|
+
});
|
|
547
|
+
expect(usage.activeInstallations).toBe(2);
|
|
548
|
+
expect(usage.points).toEqual([{
|
|
549
|
+
startMs: 0,
|
|
550
|
+
installations: 2
|
|
551
|
+
}]);
|
|
552
|
+
expect(usage.bundleDistribution).toEqual(expect.arrayContaining([{
|
|
553
|
+
appVersion: "1.0.0",
|
|
554
|
+
platform: "ios",
|
|
555
|
+
releaseId: releaseA,
|
|
556
|
+
installations: 1
|
|
557
|
+
}, {
|
|
558
|
+
appVersion: "1.0.0",
|
|
559
|
+
platform: "ios",
|
|
560
|
+
releaseId: releaseB,
|
|
561
|
+
installations: 1
|
|
562
|
+
}]));
|
|
563
|
+
});
|
|
564
|
+
it("pages insights events newest first with a stable cursor", async () => {
|
|
565
|
+
const model = state.getDatabase();
|
|
566
|
+
const first = createBundleEventRowFixture("701", 100);
|
|
567
|
+
const second = createBundleEventRowFixture("702", 100);
|
|
568
|
+
const third = createBundleEventRowFixture("703", 200);
|
|
569
|
+
await model.recordEvent({ event: third });
|
|
570
|
+
await model.recordEvent({ event: second });
|
|
571
|
+
await model.recordEvent({ event: first });
|
|
572
|
+
await expectInsightsIndex(() => model.listEvents({
|
|
573
|
+
filter: { kind: "all" },
|
|
574
|
+
beforeReceivedAtMs: 201,
|
|
575
|
+
limit: 2
|
|
576
|
+
}), [third, second]);
|
|
577
|
+
await expectInsightsIndex(() => model.listEvents({
|
|
578
|
+
filter: { kind: "all" },
|
|
579
|
+
after: {
|
|
580
|
+
receivedAtMs: second.received_at_ms,
|
|
581
|
+
id: second.id
|
|
582
|
+
},
|
|
583
|
+
beforeReceivedAtMs: 201,
|
|
584
|
+
limit: 2
|
|
585
|
+
}), [first]);
|
|
586
|
+
await expectInsightsIndex(() => model.listEvents({
|
|
587
|
+
filter: { kind: "all" },
|
|
588
|
+
beforeReceivedAtMs: 200,
|
|
589
|
+
limit: 10
|
|
590
|
+
}), [second, first]);
|
|
591
|
+
});
|
|
592
|
+
it("filters installation movements before applying the page limit", async () => {
|
|
593
|
+
const model = state.getDatabase();
|
|
594
|
+
const unchanged = {
|
|
595
|
+
...createBundleEventRowFixture("711", 300),
|
|
596
|
+
type: "UNCHANGED",
|
|
597
|
+
install_id: "install-target",
|
|
598
|
+
from_bundle_id: null,
|
|
599
|
+
metadata: {
|
|
600
|
+
...createBundleEventRowFixture("711", 300).metadata,
|
|
601
|
+
update_strategy: null
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
const unrelated = createMovementEvent("712", 250, "UPDATE_APPLIED", "install-other");
|
|
605
|
+
const applied = createMovementEvent("713", 200, "UPDATE_APPLIED", "install-target");
|
|
606
|
+
const recovered = createMovementEvent("714", 100, "RECOVERED", "install-target");
|
|
607
|
+
for (const row of [
|
|
608
|
+
unchanged,
|
|
609
|
+
unrelated,
|
|
610
|
+
applied,
|
|
611
|
+
recovered
|
|
612
|
+
]) await model.recordEvent({ event: row });
|
|
613
|
+
await expectInsightsIndex(() => model.listEvents({
|
|
614
|
+
filter: {
|
|
615
|
+
kind: "installationMovement",
|
|
616
|
+
installId: "install-target"
|
|
617
|
+
},
|
|
618
|
+
beforeReceivedAtMs: 301,
|
|
619
|
+
limit: 1
|
|
620
|
+
}), [applied]);
|
|
621
|
+
await expectInsightsIndex(() => model.listEvents({
|
|
622
|
+
filter: {
|
|
623
|
+
kind: "installationMovement",
|
|
624
|
+
installId: "install-target"
|
|
625
|
+
},
|
|
626
|
+
after: {
|
|
627
|
+
receivedAtMs: applied.received_at_ms,
|
|
628
|
+
id: applied.id
|
|
629
|
+
},
|
|
630
|
+
beforeReceivedAtMs: 301,
|
|
631
|
+
limit: 1
|
|
632
|
+
}), [recovered]);
|
|
633
|
+
});
|
|
634
|
+
it("lists an update failure where its target's list and installation history read it, and a failed check in no bundle list, moving no latest event", async () => {
|
|
635
|
+
const model = state.getDatabase();
|
|
636
|
+
const applied = createMovementEvent("721", 100, "UPDATE_APPLIED", "install-failing");
|
|
637
|
+
const failure = (suffix, receivedAtMs, failed) => ({
|
|
638
|
+
...applied,
|
|
639
|
+
id: createBundleEventRowFixture(suffix, 0).id,
|
|
640
|
+
type: "UPDATE_FAILED",
|
|
641
|
+
from_bundle_id: applied.to_bundle_id,
|
|
642
|
+
to_bundle_id: failed.stage === "check" ? applied.to_bundle_id : createBundleEventRowFixture("729", 0).to_bundle_id,
|
|
643
|
+
metadata: {
|
|
644
|
+
...applied.metadata,
|
|
645
|
+
failure: failed
|
|
646
|
+
},
|
|
647
|
+
received_at_ms: receivedAtMs
|
|
648
|
+
});
|
|
649
|
+
const download = failure("722", 200, {
|
|
650
|
+
stage: "download",
|
|
651
|
+
reason: "http",
|
|
652
|
+
http_status: 403,
|
|
653
|
+
origin_code: "AccessDenied"
|
|
654
|
+
});
|
|
655
|
+
const check = failure("723", 300, {
|
|
656
|
+
stage: "check",
|
|
657
|
+
reason: "http"
|
|
658
|
+
});
|
|
659
|
+
for (const event of [
|
|
660
|
+
applied,
|
|
661
|
+
download,
|
|
662
|
+
check
|
|
663
|
+
]) await record(model, event);
|
|
664
|
+
await expect(model.findLatestEvents({ installId: "install-failing" })).resolves.toEqual([applied]);
|
|
665
|
+
await expectInsightsIndex(() => model.listEvents({
|
|
666
|
+
filter: {
|
|
667
|
+
kind: "installationMovement",
|
|
668
|
+
installId: "install-failing"
|
|
669
|
+
},
|
|
670
|
+
beforeReceivedAtMs: 301,
|
|
671
|
+
limit: 10
|
|
672
|
+
}), [
|
|
673
|
+
check,
|
|
674
|
+
download,
|
|
675
|
+
applied
|
|
676
|
+
]);
|
|
677
|
+
await expectInsightsIndex(() => model.listEvents({
|
|
678
|
+
filter: { kind: "all" },
|
|
679
|
+
beforeReceivedAtMs: 301,
|
|
680
|
+
limit: 10
|
|
681
|
+
}), [
|
|
682
|
+
check,
|
|
683
|
+
download,
|
|
684
|
+
applied
|
|
685
|
+
]);
|
|
686
|
+
const scope = {
|
|
687
|
+
platform: "ios",
|
|
688
|
+
channel: "production"
|
|
689
|
+
};
|
|
690
|
+
for (const [toBundleId, listed] of [[download.to_bundle_id, [download]], [check.to_bundle_id, []]]) {
|
|
691
|
+
const filter = {
|
|
692
|
+
...scope,
|
|
693
|
+
type: "UPDATE_FAILED",
|
|
694
|
+
toBundleId
|
|
695
|
+
};
|
|
696
|
+
await expectInsightsIndex(() => model.listEvents({
|
|
697
|
+
filter: {
|
|
698
|
+
kind: "bundle",
|
|
699
|
+
...filter
|
|
700
|
+
},
|
|
701
|
+
beforeReceivedAtMs: 301,
|
|
702
|
+
limit: 10
|
|
703
|
+
}), listed);
|
|
704
|
+
await expect(model.countEvents({
|
|
705
|
+
filter,
|
|
706
|
+
sinceMs: 0,
|
|
707
|
+
beforeReceivedAtMs: 301
|
|
708
|
+
})).resolves.toBe(listed.length);
|
|
709
|
+
}
|
|
710
|
+
});
|
|
711
|
+
});
|
|
712
|
+
};
|
|
713
|
+
//#endregion
|
|
714
|
+
export { registerInsightsModelTests };
|