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