@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
|
@@ -4,14 +4,14 @@ import {
|
|
|
4
4
|
} from "@hot-updater/plugin-core/internal";
|
|
5
5
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import { createHotUpdater } from "
|
|
9
|
-
import { insights } from "../plugins/insights";
|
|
7
|
+
import { toolingTargetOf } from "../../db/coreDatabase";
|
|
8
|
+
import { createHotUpdater } from "../../index";
|
|
10
9
|
import {
|
|
11
10
|
createFencedDatabase,
|
|
12
11
|
createRuntimeDatabase,
|
|
13
|
-
} from "
|
|
12
|
+
} from "../../runtime.testFixtures";
|
|
14
13
|
import { EVENT_BODY_MAX_BYTES } from "./eventInput";
|
|
14
|
+
import { insights } from "./index";
|
|
15
15
|
|
|
16
16
|
/** A server with the Insights plugin on an empty in-memory database. */
|
|
17
17
|
const start = () =>
|
|
@@ -35,7 +35,6 @@ const event = {
|
|
|
35
35
|
type: "UNCHANGED",
|
|
36
36
|
updateStrategy: null,
|
|
37
37
|
userId: "user-1",
|
|
38
|
-
username: "Jane",
|
|
39
38
|
sdkVersion: "2.0.0",
|
|
40
39
|
} as const;
|
|
41
40
|
|
|
@@ -105,7 +104,7 @@ describe("createHotUpdater Insights", () => {
|
|
|
105
104
|
).toBe(400);
|
|
106
105
|
});
|
|
107
106
|
|
|
108
|
-
it("
|
|
107
|
+
it("keeps an UNCHANGED report as the installation's latest event, not a listed event, and serves the lean Insights views", async () => {
|
|
109
108
|
vi.useFakeTimers();
|
|
110
109
|
vi.setSystemTime(new Date("2026-08-12T00:00:00.000Z"));
|
|
111
110
|
const receivedAtMs = Date.now();
|
|
@@ -138,24 +137,18 @@ describe("createHotUpdater Insights", () => {
|
|
|
138
137
|
type: "UNCHANGED",
|
|
139
138
|
}),
|
|
140
139
|
);
|
|
140
|
+
// A launch without an update is no event of its own.
|
|
141
141
|
expect(events.status).toBe(200);
|
|
142
|
-
await expect(events.json()).resolves.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
id: expect.any(String),
|
|
146
|
-
installId: "install-1",
|
|
147
|
-
receivedAtMs,
|
|
148
|
-
type: "UNCHANGED",
|
|
149
|
-
userId: "user-1",
|
|
150
|
-
username: "Jane",
|
|
151
|
-
},
|
|
152
|
-
],
|
|
142
|
+
await expect(events.json()).resolves.toEqual({
|
|
143
|
+
beforeReceivedAtMs: expect.any(Number),
|
|
144
|
+
data: [],
|
|
153
145
|
nextCursor: null,
|
|
154
146
|
});
|
|
155
147
|
expect(installation.status).toBe(200);
|
|
156
148
|
await expect(installation.json()).resolves.toMatchObject({
|
|
157
149
|
installId: "install-1",
|
|
158
150
|
latestStatus: "UNCHANGED",
|
|
151
|
+
receivedAtMs,
|
|
159
152
|
userId: "user-1",
|
|
160
153
|
});
|
|
161
154
|
expect(matches.status).toBe(200);
|
|
@@ -164,13 +157,12 @@ describe("createHotUpdater Insights", () => {
|
|
|
164
157
|
nextCursor: null,
|
|
165
158
|
});
|
|
166
159
|
expect(active.status).toBe(200);
|
|
167
|
-
//
|
|
168
|
-
const end = Date.parse("2026-08-12T01:00:00.000Z");
|
|
160
|
+
// Ending with the current hour, from the UTC day the window reaches into.
|
|
169
161
|
await expect(active.json()).resolves.toEqual({
|
|
170
162
|
platform: "ios",
|
|
171
163
|
channel: "production",
|
|
172
|
-
sinceMs:
|
|
173
|
-
beforeReceivedAtMs:
|
|
164
|
+
sinceMs: Date.parse("2026-08-11T00:00:00.000Z"),
|
|
165
|
+
beforeReceivedAtMs: Date.parse("2026-08-12T01:00:00.000Z"),
|
|
174
166
|
reportingInstallations: { count: 1, measuredAtMs: Date.now() },
|
|
175
167
|
window: "24h",
|
|
176
168
|
});
|
|
@@ -220,16 +212,22 @@ describe("createHotUpdater Insights", () => {
|
|
|
220
212
|
),
|
|
221
213
|
);
|
|
222
214
|
expect(overview.status).toBe(200);
|
|
223
|
-
|
|
215
|
+
// install-2's UNCHANGED report counts it among the bundle's latest
|
|
216
|
+
// events, and in no event count.
|
|
217
|
+
await expect(overview.json()).resolves.toEqual({
|
|
218
|
+
platform: "ios",
|
|
219
|
+
channel: "production",
|
|
220
|
+
window: "24h",
|
|
224
221
|
sinceMs: 0,
|
|
225
222
|
beforeReceivedAtMs: 60 * 60 * 1_000,
|
|
226
|
-
reportingInstallations: { count: 2 },
|
|
223
|
+
reportingInstallations: { count: 2, measuredAtMs: 500 },
|
|
227
224
|
bundle: {
|
|
228
225
|
bundleId: "B",
|
|
229
|
-
reportingInstallations: { count: 1 },
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
226
|
+
reportingInstallations: { count: 1, measuredAtMs: 500 },
|
|
227
|
+
downloadedReports: { count: 0, measuredAtMs: 500 },
|
|
228
|
+
appliedReports: { count: 1, measuredAtMs: 500 },
|
|
229
|
+
recoveredReports: { count: 1, measuredAtMs: 500 },
|
|
230
|
+
failedReports: { count: 0, measuredAtMs: 500 },
|
|
233
231
|
},
|
|
234
232
|
});
|
|
235
233
|
const drilldown = await hotUpdater.handlers.admin(
|
|
@@ -264,6 +262,8 @@ describe("createHotUpdater Insights", () => {
|
|
|
264
262
|
"/overview?platform=ios&channel=production&platform=android",
|
|
265
263
|
"/events?bundleId=B",
|
|
266
264
|
"/events?platform=ios&channel=production&bundleId=B&outcome=UNCHANGED",
|
|
265
|
+
// UNCHANGED reports are kept as no events, so no list holds them.
|
|
266
|
+
"/events?platform=ios&channel=production&bundleId=B&outcome=unchanged",
|
|
267
267
|
"/events?sinceMs=20&beforeReceivedAtMs=10",
|
|
268
268
|
// 90 days and 1 ms, longer than a bundle list covers.
|
|
269
269
|
"/events?platform=ios&channel=production&bundleId=B&outcome=applied&sinceMs=0&beforeReceivedAtMs=7776000001",
|
|
@@ -307,7 +307,10 @@ describe("createHotUpdater Insights", () => {
|
|
|
307
307
|
clientAccess: "public",
|
|
308
308
|
});
|
|
309
309
|
const migrated = createHotUpdater({
|
|
310
|
-
database: await createFencedDatabase(
|
|
310
|
+
database: await createFencedDatabase(
|
|
311
|
+
"kysely",
|
|
312
|
+
toolingTargetOf([insights()]).settings,
|
|
313
|
+
),
|
|
311
314
|
plugins: [insights()],
|
|
312
315
|
clientAccess: "public",
|
|
313
316
|
});
|
|
@@ -476,18 +479,30 @@ describe("createHotUpdater Insights", () => {
|
|
|
476
479
|
|
|
477
480
|
it("records a report with fields it does not know and still checks the ones it does", async () => {
|
|
478
481
|
const hotUpdater = start();
|
|
479
|
-
const
|
|
482
|
+
const recordEvent = vi.spyOn(hotUpdater.api.insights, "recordEvent");
|
|
483
|
+
// `username` left the contract; an older client's is ignored like any other.
|
|
484
|
+
const newer = {
|
|
485
|
+
...event,
|
|
486
|
+
networkType: "wifi",
|
|
487
|
+
screen: { width: 390 },
|
|
488
|
+
username: "Jane",
|
|
489
|
+
};
|
|
480
490
|
|
|
481
491
|
expect((await hotUpdater.handlers.client(eventRequest(newer))).status).toBe(
|
|
482
492
|
204,
|
|
483
493
|
);
|
|
494
|
+
expect(recordEvent.mock.calls[0]![0].metadata).not.toHaveProperty(
|
|
495
|
+
"username",
|
|
496
|
+
);
|
|
484
497
|
const installation = await hotUpdater.handlers.admin(
|
|
485
498
|
new Request("https://example.com/installations/install-1"),
|
|
486
499
|
);
|
|
487
|
-
await
|
|
500
|
+
const found = await installation.json();
|
|
501
|
+
expect(found).toMatchObject({
|
|
488
502
|
installId: "install-1",
|
|
489
503
|
latestStatus: "UNCHANGED",
|
|
490
504
|
});
|
|
505
|
+
expect(found).not.toHaveProperty("username");
|
|
491
506
|
const invalid = await hotUpdater.handlers.client(
|
|
492
507
|
eventRequest({ ...newer, channel: 7 }),
|
|
493
508
|
);
|
|
@@ -501,10 +516,253 @@ describe("createHotUpdater Insights", () => {
|
|
|
501
516
|
expect(tooLarge.status).toBe(413);
|
|
502
517
|
});
|
|
503
518
|
|
|
519
|
+
it("records every update failure, reading unknown or malformed parts as unknown, and lists it with what failed", async () => {
|
|
520
|
+
vi.useFakeTimers();
|
|
521
|
+
vi.setSystemTime(Date.UTC(2026, 8, 20, 10));
|
|
522
|
+
const hotUpdater = start();
|
|
523
|
+
const failed = {
|
|
524
|
+
...event,
|
|
525
|
+
type: "UPDATE_FAILED",
|
|
526
|
+
fromBundleId: "bundle-1",
|
|
527
|
+
toBundleId: "bundle-2",
|
|
528
|
+
toReleaseId: "release-2",
|
|
529
|
+
updateStrategy: "appVersion",
|
|
530
|
+
};
|
|
531
|
+
const report = async (metadata: unknown) => {
|
|
532
|
+
const response = await hotUpdater.handlers.client(
|
|
533
|
+
eventRequest({ ...failed, metadata }),
|
|
534
|
+
);
|
|
535
|
+
expect(response.status).toBe(204);
|
|
536
|
+
vi.advanceTimersByTime(1);
|
|
537
|
+
};
|
|
538
|
+
await report({
|
|
539
|
+
failure: {
|
|
540
|
+
stage: "download",
|
|
541
|
+
reason: "http",
|
|
542
|
+
resource: "artifact",
|
|
543
|
+
httpStatus: 403,
|
|
544
|
+
originCode: "AccessDenied",
|
|
545
|
+
},
|
|
546
|
+
});
|
|
547
|
+
// A newer client's stage, reason, resource, and transport.
|
|
548
|
+
await report({
|
|
549
|
+
failure: {
|
|
550
|
+
stage: "verify",
|
|
551
|
+
reason: "quantum",
|
|
552
|
+
resource: "shard",
|
|
553
|
+
transport: "carrier-pigeon",
|
|
554
|
+
},
|
|
555
|
+
});
|
|
556
|
+
// No failure, one that is not an object, and malformed optional fields.
|
|
557
|
+
await report(undefined);
|
|
558
|
+
await report({ failure: "broken" });
|
|
559
|
+
await report({
|
|
560
|
+
failure: {
|
|
561
|
+
stage: "install",
|
|
562
|
+
reason: "storage",
|
|
563
|
+
httpStatus: "403",
|
|
564
|
+
originCode: "not a code",
|
|
565
|
+
previousProcessExit: "x".repeat(65),
|
|
566
|
+
},
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
const events = await hotUpdater.handlers.admin(
|
|
570
|
+
new Request(
|
|
571
|
+
`https://example.com/events?platform=ios&channel=production&bundleId=bundle-2&outcome=failed&beforeReceivedAtMs=${Date.now()}`,
|
|
572
|
+
),
|
|
573
|
+
);
|
|
574
|
+
expect(events.status).toBe(200);
|
|
575
|
+
const { data } = (await events.json()) as {
|
|
576
|
+
data: { type: string; failure: unknown }[];
|
|
577
|
+
};
|
|
578
|
+
expect(data.map(({ type }) => type)).toEqual(
|
|
579
|
+
Array(5).fill("UPDATE_FAILED"),
|
|
580
|
+
);
|
|
581
|
+
expect(data.map(({ failure }) => failure)).toEqual([
|
|
582
|
+
{ stage: "install", reason: "storage" },
|
|
583
|
+
{ stage: "unknown", reason: "unknown" },
|
|
584
|
+
{ stage: "unknown", reason: "unknown" },
|
|
585
|
+
{
|
|
586
|
+
stage: "unknown",
|
|
587
|
+
reason: "unknown",
|
|
588
|
+
resource: "unknown",
|
|
589
|
+
transport: "unknown",
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
stage: "download",
|
|
593
|
+
reason: "http",
|
|
594
|
+
resource: "artifact",
|
|
595
|
+
httpStatus: 403,
|
|
596
|
+
originCode: "AccessDenied",
|
|
597
|
+
},
|
|
598
|
+
]);
|
|
599
|
+
// A failure moves no installation: none has reported a launch.
|
|
600
|
+
expect(
|
|
601
|
+
(
|
|
602
|
+
await hotUpdater.handlers.admin(
|
|
603
|
+
new Request("https://example.com/installations/install-1"),
|
|
604
|
+
)
|
|
605
|
+
).status,
|
|
606
|
+
).toBe(404);
|
|
607
|
+
// Only a structurally invalid report is refused.
|
|
608
|
+
for (const invalid of [
|
|
609
|
+
{ ...failed, fromBundleId: null },
|
|
610
|
+
{ ...failed, updateStrategy: null },
|
|
611
|
+
{ ...failed, eventId: "not-a-uuid" },
|
|
612
|
+
]) {
|
|
613
|
+
expect(
|
|
614
|
+
(await hotUpdater.handlers.client(eventRequest(invalid))).status,
|
|
615
|
+
).toBe(400);
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
it("keeps how a bundle arrived and why a crashed process exited", async () => {
|
|
620
|
+
const hotUpdater = start();
|
|
621
|
+
const movement = {
|
|
622
|
+
...event,
|
|
623
|
+
fromBundleId: "bundle-1",
|
|
624
|
+
toBundleId: "bundle-2",
|
|
625
|
+
toReleaseId: "release-2",
|
|
626
|
+
updateStrategy: "appVersion",
|
|
627
|
+
};
|
|
628
|
+
for (const body of [
|
|
629
|
+
{
|
|
630
|
+
...movement,
|
|
631
|
+
type: "UPDATE_DOWNLOADED",
|
|
632
|
+
metadata: { delivery: "archive", patchFallback: true },
|
|
633
|
+
},
|
|
634
|
+
{
|
|
635
|
+
...movement,
|
|
636
|
+
type: "RECOVERED",
|
|
637
|
+
installId: "install-2",
|
|
638
|
+
metadata: { previousProcessExit: "CRASH_NATIVE" },
|
|
639
|
+
},
|
|
640
|
+
{
|
|
641
|
+
...movement,
|
|
642
|
+
type: "UPDATE_DOWNLOADED",
|
|
643
|
+
installId: "install-3",
|
|
644
|
+
metadata: { delivery: "teleport", patchFallback: "yes" },
|
|
645
|
+
},
|
|
646
|
+
]) {
|
|
647
|
+
expect(
|
|
648
|
+
(await hotUpdater.handlers.client(eventRequest(body))).status,
|
|
649
|
+
).toBe(204);
|
|
650
|
+
}
|
|
651
|
+
const events = await hotUpdater.handlers.admin(
|
|
652
|
+
new Request(
|
|
653
|
+
`https://example.com/events?beforeReceivedAtMs=${Date.now() + 1}`,
|
|
654
|
+
),
|
|
655
|
+
);
|
|
656
|
+
const { data } = (await events.json()) as {
|
|
657
|
+
data: Record<string, unknown>[];
|
|
658
|
+
};
|
|
659
|
+
const byInstall = Object.fromEntries(
|
|
660
|
+
data.map((row) => [row.installId, row]),
|
|
661
|
+
);
|
|
662
|
+
expect(byInstall["install-1"]).toMatchObject({
|
|
663
|
+
delivery: "archive",
|
|
664
|
+
patchFallback: true,
|
|
665
|
+
});
|
|
666
|
+
expect(byInstall["install-2"]).toMatchObject({
|
|
667
|
+
previousProcessExit: "CRASH_NATIVE",
|
|
668
|
+
});
|
|
669
|
+
expect(byInstall["install-3"]).toMatchObject({ delivery: "unknown" });
|
|
670
|
+
expect(byInstall["install-3"]).not.toHaveProperty("patchFallback");
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
it("serves a release's and a channel's update failures to admins", async () => {
|
|
674
|
+
vi.useFakeTimers();
|
|
675
|
+
const at = Date.UTC(2026, 8, 20, 10, 30);
|
|
676
|
+
vi.setSystemTime(at);
|
|
677
|
+
const hotUpdater = start();
|
|
678
|
+
const failed = (installId: string, failure: Record<string, unknown>) =>
|
|
679
|
+
hotUpdater.handlers.client(
|
|
680
|
+
eventRequest({
|
|
681
|
+
...event,
|
|
682
|
+
installId,
|
|
683
|
+
type: "UPDATE_FAILED",
|
|
684
|
+
fromBundleId: "bundle-1",
|
|
685
|
+
toBundleId: failure.stage === "check" ? "bundle-1" : "bundle-2",
|
|
686
|
+
toReleaseId: failure.stage === "check" ? null : "release-2",
|
|
687
|
+
updateStrategy: "appVersion",
|
|
688
|
+
metadata: { failure },
|
|
689
|
+
}),
|
|
690
|
+
);
|
|
691
|
+
await failed("install-1", {
|
|
692
|
+
stage: "download",
|
|
693
|
+
reason: "http",
|
|
694
|
+
httpStatus: 403,
|
|
695
|
+
});
|
|
696
|
+
await failed("install-2", { stage: "check", reason: "http" });
|
|
697
|
+
const hour = at - (at % 3_600_000);
|
|
698
|
+
const range = `start=${hour}&end=${hour + 3_600_000}`;
|
|
699
|
+
const read = (query: string) =>
|
|
700
|
+
hotUpdater.handlers.admin(
|
|
701
|
+
new Request(`https://example.com/failures?${query}`),
|
|
702
|
+
);
|
|
703
|
+
|
|
704
|
+
const release = await read(
|
|
705
|
+
`platform=ios&channel=production&releaseId=release-2&${range}`,
|
|
706
|
+
);
|
|
707
|
+
expect(release.status).toBe(200);
|
|
708
|
+
await expect(release.json()).resolves.toMatchObject({
|
|
709
|
+
failedUpdates: 1,
|
|
710
|
+
failedInstallations: 1,
|
|
711
|
+
downloads: 0,
|
|
712
|
+
breakdown: [
|
|
713
|
+
{
|
|
714
|
+
stage: "download",
|
|
715
|
+
reason: "http",
|
|
716
|
+
events: 1,
|
|
717
|
+
details: [
|
|
718
|
+
{
|
|
719
|
+
resource: null,
|
|
720
|
+
httpStatus: 403,
|
|
721
|
+
originCode: null,
|
|
722
|
+
transport: null,
|
|
723
|
+
events: 1,
|
|
724
|
+
},
|
|
725
|
+
],
|
|
726
|
+
},
|
|
727
|
+
],
|
|
728
|
+
recoveries: { failedLaunches: 0, byExitReason: [] },
|
|
729
|
+
});
|
|
730
|
+
await expect(
|
|
731
|
+
(
|
|
732
|
+
await read("platform=ios&channel=production&releaseId=release-2")
|
|
733
|
+
).json(),
|
|
734
|
+
).resolves.toMatchObject({ failedUpdates: 1, failedInstallations: 1 });
|
|
735
|
+
const channel = await read(`platform=ios&channel=production&${range}`);
|
|
736
|
+
await expect(channel.json()).resolves.toMatchObject({
|
|
737
|
+
failedUpdates: 1,
|
|
738
|
+
checks: { failures: 1, failedInstallations: 1 },
|
|
739
|
+
breakdown: [
|
|
740
|
+
{ stage: "check", reason: "http", events: 1 },
|
|
741
|
+
{ stage: "download", reason: "http", events: 1 },
|
|
742
|
+
],
|
|
743
|
+
});
|
|
744
|
+
for (const invalid of [
|
|
745
|
+
"channel=production&releaseId=release-2",
|
|
746
|
+
"platform=ios&channel=production",
|
|
747
|
+
`platform=ios&channel=production&start=${hour}`,
|
|
748
|
+
"platform=ios&channel=production&start=a&end=b",
|
|
749
|
+
// Over 30 days, the console's longest period.
|
|
750
|
+
`platform=ios&channel=production&start=${hour - 30 * 86_400_000}&end=${hour + 1}`,
|
|
751
|
+
]) {
|
|
752
|
+
expect((await read(invalid)).status).toBe(400);
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
|
|
504
756
|
it("counts a retried report once under its client event ID, whichever installation repeats it", async () => {
|
|
505
757
|
const hotUpdater = start();
|
|
506
758
|
const eventId = "01987a6e-4c00-7abc-8def-0123456789ab";
|
|
507
|
-
const
|
|
759
|
+
const applied = {
|
|
760
|
+
...event,
|
|
761
|
+
type: "UPDATE_APPLIED",
|
|
762
|
+
fromBundleId: "bundle-0",
|
|
763
|
+
updateStrategy: "appVersion",
|
|
764
|
+
} as const;
|
|
765
|
+
const report = { ...applied, eventId };
|
|
508
766
|
const counts = async () => {
|
|
509
767
|
const overview = await hotUpdater.handlers.admin(
|
|
510
768
|
new Request(
|
|
@@ -513,9 +771,9 @@ describe("createHotUpdater Insights", () => {
|
|
|
513
771
|
);
|
|
514
772
|
return (
|
|
515
773
|
(await overview.json()) as {
|
|
516
|
-
readonly bundle: { readonly
|
|
774
|
+
readonly bundle: { readonly appliedReports: { count: number } };
|
|
517
775
|
}
|
|
518
|
-
).bundle.
|
|
776
|
+
).bundle.appliedReports.count;
|
|
519
777
|
};
|
|
520
778
|
|
|
521
779
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
@@ -553,12 +811,50 @@ describe("createHotUpdater Insights", () => {
|
|
|
553
811
|
// Without an ID the server creates one, so each report counts.
|
|
554
812
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
555
813
|
expect(
|
|
556
|
-
(await hotUpdater.handlers.client(eventRequest(
|
|
814
|
+
(await hotUpdater.handlers.client(eventRequest(applied))).status,
|
|
557
815
|
).toBe(204);
|
|
558
816
|
}
|
|
559
817
|
await expect(counts()).resolves.toBe(3);
|
|
560
818
|
});
|
|
561
819
|
|
|
820
|
+
it("counts an installation's UNCHANGED reports once a UTC day, retried or repeated", async () => {
|
|
821
|
+
vi.useFakeTimers();
|
|
822
|
+
vi.setSystemTime(new Date("2026-08-12T10:00:00.000Z"));
|
|
823
|
+
const hotUpdater = start();
|
|
824
|
+
const append = vi.spyOn(hotUpdater.api.insights, "recordEvent");
|
|
825
|
+
const launches = async () => {
|
|
826
|
+
const {
|
|
827
|
+
data: [activity],
|
|
828
|
+
} = await hotUpdater.api.insights.getReleaseActivity({
|
|
829
|
+
scope: { platform: "ios", channel: "production" },
|
|
830
|
+
timeRange: {
|
|
831
|
+
start: Date.parse("2026-08-12T00:00:00.000Z"),
|
|
832
|
+
end: Date.parse("2026-08-14T00:00:00.000Z"),
|
|
833
|
+
},
|
|
834
|
+
});
|
|
835
|
+
return activity!.metrics.launches;
|
|
836
|
+
};
|
|
837
|
+
const report = {
|
|
838
|
+
...event,
|
|
839
|
+
eventId: "01987a6e-4c00-7abc-8def-0123456789ab",
|
|
840
|
+
};
|
|
841
|
+
|
|
842
|
+
// A retry, then relaunches later that day, with and without an ID.
|
|
843
|
+
for (const body of [report, report, event, event]) {
|
|
844
|
+
expect(
|
|
845
|
+
(await hotUpdater.handlers.client(eventRequest(body))).status,
|
|
846
|
+
).toBe(204);
|
|
847
|
+
vi.advanceTimersByTime(60 * 60 * 1_000);
|
|
848
|
+
}
|
|
849
|
+
expect(append).toHaveBeenCalledTimes(4);
|
|
850
|
+
await expect(launches()).resolves.toBe(1);
|
|
851
|
+
|
|
852
|
+
// The next UTC day counts the installation again.
|
|
853
|
+
vi.setSystemTime(new Date("2026-08-13T09:00:00.000Z"));
|
|
854
|
+
expect((await hotUpdater.handlers.client(eventRequest())).status).toBe(204);
|
|
855
|
+
await expect(launches()).resolves.toBe(2);
|
|
856
|
+
});
|
|
857
|
+
|
|
562
858
|
it.each([
|
|
563
859
|
"event-1",
|
|
564
860
|
"01987A6E-4C00-7ABC-8DEF-0123456789AB",
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
|
|
4
|
-
import type { BundleEventRow } from "@hot-updater/plugin-core";
|
|
5
4
|
import {
|
|
6
5
|
runContentionHarness,
|
|
7
6
|
withAdapterLatency,
|
|
@@ -17,6 +16,7 @@ import { resolveSchema } from "../../database/resolveSchema";
|
|
|
17
16
|
import { createSqlAdapter } from "../../database/sql/sqlAdapter";
|
|
18
17
|
import { pgExecutor } from "../../database/sql/sqlTestExecutors";
|
|
19
18
|
import type { CoreReader } from "../definePlugin";
|
|
19
|
+
import type { BundleEventRow } from "./eventRow";
|
|
20
20
|
import { insights, insightsSchema } from "./index";
|
|
21
21
|
|
|
22
22
|
assertDockerComposeAvailable(
|
|
@@ -68,7 +68,6 @@ const move = (
|
|
|
68
68
|
app_version: "1.0.0",
|
|
69
69
|
channel: "production",
|
|
70
70
|
metadata: {
|
|
71
|
-
username: null,
|
|
72
71
|
cohort: "1",
|
|
73
72
|
update_strategy: "appVersion",
|
|
74
73
|
fingerprint_hash: null,
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import { PGlite } from "@electric-sql/pglite";
|
|
2
|
-
import type { InsightsModel } from "@hot-updater/plugin-core";
|
|
3
2
|
import {
|
|
4
3
|
createMemoryAdapter,
|
|
5
4
|
type DatabaseAdapter,
|
|
6
5
|
} from "@hot-updater/plugin-core/internal";
|
|
7
|
-
import {
|
|
8
|
-
createPluginTestHarness,
|
|
9
|
-
setupInsightsModelTestSuite,
|
|
10
|
-
} from "@hot-updater/test-utils";
|
|
6
|
+
import { createPluginTestHarness } from "@hot-updater/test-utils";
|
|
11
7
|
import { afterAll } from "vitest";
|
|
12
8
|
|
|
13
9
|
import * as engine from "../../database";
|
|
14
10
|
import { createSqlAdapter } from "../../database/sql/sqlAdapter";
|
|
15
11
|
import { pgliteExecutor } from "../../database/sql/sqlTestExecutors";
|
|
16
12
|
import { createInsightsModel, insights } from "./index";
|
|
13
|
+
import type { InsightsModel } from "./modelTypes";
|
|
14
|
+
import { setupInsightsModelTestSuite } from "./testing";
|
|
17
15
|
|
|
18
16
|
/** The plugin's model on a fresh adapter per test, behind one stable model. */
|
|
19
17
|
const onFreshAdapter = (adapter: () => DatabaseAdapter) => {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createValidatedInsightsModel } from "@hot-updater/plugin-core/internal";
|
|
3
|
-
|
|
1
|
+
import { createValidatedInsightsModel } from "./contract";
|
|
4
2
|
import type { InsightsApi } from "./index";
|
|
3
|
+
import type { InsightsModel } from "./modelTypes";
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* The plugin's API as `InsightsModel`, validated at its boundary: what the
|