@hot-updater/test-utils 1.2.0-rc.57 → 1.2.0-rc.59
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/index.d.mts +52 -4
- package/dist/index.mjs +577 -102
- package/dist/react-native.d.cts +5 -1
- package/dist/react-native.d.mts +5 -1
- package/package.json +9 -9
package/dist/index.d.mts
CHANGED
|
@@ -502,6 +502,21 @@ declare const createBundleEventRowFixture: (suffix: string, receivedAtMs: number
|
|
|
502
502
|
type: "UPDATE_APPLIED" | "RECOVERED";
|
|
503
503
|
}>;
|
|
504
504
|
//#endregion
|
|
505
|
+
//#region src/insights/insights11.d.ts
|
|
506
|
+
/**
|
|
507
|
+
* A 1.1 server's `insights()` as far as the release-ref backfill reads it:
|
|
508
|
+
* its API's `record(row)` stores an event and counts its outcome hours by
|
|
509
|
+
* artifact, as 1.1's `countOutcome` did, to test the backfill and `db
|
|
510
|
+
* migrate` on rows a 1.1 server wrote. It stands in for the official
|
|
511
|
+
* plugin, so it takes its id and brand; serve it over a database whose
|
|
512
|
+
* Insights tables `insights()` created.
|
|
513
|
+
*/
|
|
514
|
+
declare const insights11TestPlugin: () => AnyHotUpdaterPlugin;
|
|
515
|
+
/** What `insights11TestPlugin()` serves as `api.insights`. */
|
|
516
|
+
type Insights11TestApi = {
|
|
517
|
+
readonly record: (event: BundleEventRow) => Promise<void>;
|
|
518
|
+
};
|
|
519
|
+
//#endregion
|
|
505
520
|
//#region src/insights/setupInsightsHttpTestSuite.d.ts
|
|
506
521
|
/**
|
|
507
522
|
* The Insights plugin's routes on a database: a client reports an event, and
|
|
@@ -523,13 +538,17 @@ declare const setupInsightsModelTestSuite: (lifecycle: DatabaseTestLifecycle<Ins
|
|
|
523
538
|
//#region src/insights/index.d.ts
|
|
524
539
|
/**
|
|
525
540
|
* The Insights plugin's tests, for `setupDatabaseTestSuite`'s `plugins`: its
|
|
526
|
-
* HTTP routes on the provider's server, which must run `insights()
|
|
527
|
-
*
|
|
541
|
+
* HTTP routes on the provider's server, which must run `insights()`; with
|
|
542
|
+
* `createModel` its report contract on the provider's database, such as
|
|
528
543
|
* `(database) => createInsightsModel(createHotUpdater({ database, storage,
|
|
529
|
-
* plugins: [insights()], clientAccess: "public" }).api.insights)
|
|
544
|
+
* plugins: [insights()], clientAccess: "public" }).api.insights)`; and with
|
|
545
|
+
* `createApi` the backfill of a 1.1 server's rows, such as `(database,
|
|
546
|
+
* plugin = insights()) => createHotUpdater({ database, storage, plugins:
|
|
547
|
+
* [plugin], clientAccess: "public" }).api.insights`.
|
|
530
548
|
*/
|
|
531
549
|
declare const insightsTestSuite: <TDatabase = EngineDatabase>(options?: {
|
|
532
550
|
readonly createModel?: (database: TDatabase) => InsightsModel;
|
|
551
|
+
readonly createApi?: (database: TDatabase, plugin?: AnyHotUpdaterPlugin) => unknown;
|
|
533
552
|
}) => {
|
|
534
553
|
name: string;
|
|
535
554
|
register: (context: {
|
|
@@ -586,4 +605,33 @@ declare const RELEASE_CATALOG_STORAGE_FIXTURES: Readonly<Record<string, string>>
|
|
|
586
605
|
/** Storage boundary shared by provider and separately spawned server tests. */
|
|
587
606
|
declare const createReleaseCatalogTestStorage: () => StorageAdapter;
|
|
588
607
|
//#endregion
|
|
589
|
-
|
|
608
|
+
//#region src/capacityCappedStore.d.ts
|
|
609
|
+
interface CapacityCappedStoreOptions {
|
|
610
|
+
/** The write units the store admits a second, as DynamoDB's `MaxWriteRequestUnits`. */
|
|
611
|
+
readonly unitsPerSecond: number;
|
|
612
|
+
/** Virtual time an admitted write takes; 300 ms by default. */
|
|
613
|
+
readonly writeMs?: number;
|
|
614
|
+
/**
|
|
615
|
+
* Virtual time a throttled write takes before the store reports it: the
|
|
616
|
+
* client's own throttling retries; 3 s by default.
|
|
617
|
+
*/
|
|
618
|
+
readonly throttledMs?: number;
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* `store` behind a strict write-capacity cap: a token bucket refilled at
|
|
622
|
+
* `unitsPerSecond` on a virtual clock, holding one second of units, with
|
|
623
|
+
* writes priced as DynamoDB prices transactional ones. A write that costs
|
|
624
|
+
* more than the bucket holds is refused as DynamoDB's store reports a
|
|
625
|
+
* throttle, `{ ok: false, retry: true }`, so one costing more than a second
|
|
626
|
+
* of capacity is never admitted. DynamoDB with
|
|
627
|
+
* `OnDemandThroughput.MaxWriteRequestUnits` is looser, since it admits such a
|
|
628
|
+
* write from burst capacity when it has some and refuses by time window
|
|
629
|
+
* otherwise; the strict cap makes a transaction too large for the cap fail
|
|
630
|
+
* every time instead of by chance. Reads and `deleteConsumed` are not capped.
|
|
631
|
+
*/
|
|
632
|
+
declare const createCapacityCappedStore: (store: KeyValueStore, { unitsPerSecond, writeMs, throttledMs }: CapacityCappedStoreOptions) => KeyValueStore & {
|
|
633
|
+
/** Writes refused for capacity so far. */
|
|
634
|
+
readonly throttles: () => number;
|
|
635
|
+
};
|
|
636
|
+
//#endregion
|
|
637
|
+
export { AdminApiTestClient, AggregateBatchingSuiteOptions, CapacityCappedStoreOptions, ContentionOptions, ContentionReport, DatabaseAdapterConformanceContext, DatabaseAdapterConformanceOptions, DatabasePluginTestSuite, type DatabaseTestLifecycle, DatabaseTestSuiteOptions, HttpTestClient, HttpTestHandlers, HttpTestRequest, HttpTestRequestInit, HttpTestServer, type Insights11TestApi, LATER_RELEASE_CATALOG_FIELD, MeasuredDatabase, MeasuredDatabaseOptions, MeasuredDatabaseStorage, MemoryKeyValueStoreOptions, PluginTestHarnessOptions, RELEASE_CATALOG_DOWNLOAD_HASH, RELEASE_CATALOG_MANIFEST_URIS, RELEASE_CATALOG_STORAGE_FIXTURES, ReadBudgetAdapterContext, ReadBudgetSuiteOptions, ReleaseLabelEngineSuiteOptions, RowsExamined, SqlExecutorLike, SqlQuery, SqlStatementLike, StorageAdapterTestSuiteOptions, conformanceCounters, conformanceExpiring, conformanceItems, createAdminApiTestClient, createBundleEventRowFixture, createBundleFixture, createBundlePatchRowFixture, createBundleRowFixture, createCapacityCappedStore, createChannelRowFixture, createHandlerHttpTestClient, createHttpTestClient, createMeasuredDatabase, createMemoryKeyValueStore, createPluginTestHarness, createReleaseCatalogTestStorage, createReleaseRowFixture, expectInsightsIndex, insights11TestPlugin, insightsTestSuite, jsonRequest, mysqlRowsExamined, postgresRowsExamined, releaseCatalogArtifact, releaseCatalogArtifactFiles, releaseCatalogDownloadUrl, runContentionHarness, setupAggregateBatchingTestSuite, setupBundleMethodsTestSuite, setupCoreAdminTestSuite, setupDatabaseAdapterConformanceSuite, setupDatabaseTestSuite, setupInsightsHttpTestSuite, setupInsightsModelTestSuite, setupReadBudgetTestSuite, setupReleaseCatalogTestSuite, setupReleaseLabelEngineTestSuite, setupReleaseLabelTestSuite, setupSemverSatisfiesTestSuite, setupStorageAdapterTestSuite, startHttpTestServer, storeBundles, toDeployBundle, withAdapterLatency, writeCatalogFromLaterRelease };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
|
2
|
-
import { DATABASE_VERSION_COLUMN, DatabaseAdapterContractError, DatabaseConstraintError, SETTINGS_TABLE, addDistinct, aggregateBatchingTables, assertStorageOperations, bundleToPatchRows, bundleToRow, compareUtf8, coreSchema, countDistinct, createBundleStorageKey, createEngine, createMemoryAdapter, createStorageKeyBuilder, createStorageRootUriWithPath, createStorageUri, createStorageUriWithRelativePath, findPhysicalIndex, getBundleArchiveStorageUri, getContentAddressedAssetStoragePath, indexOrderColumns, meterReads, parseStorageUri, targetBaseCandidateKey, toolingTargetOf, verifyAdapter } from "@hot-updater/plugin-core";
|
|
2
|
+
import { DATABASE_VERSION_COLUMN, DatabaseAdapterContractError, DatabaseConstraintError, SETTINGS_TABLE, addDistinct, aggregateBatchingTables, assertStorageOperations, bundleToPatchRows, bundleToRow, compareUtf8, coreSchema, countDistinct, createBundleStorageKey, createEngine, createMemoryAdapter, createStorageKeyBuilder, createStorageRootUriWithPath, createStorageUri, createStorageUriWithRelativePath, defineAggregate, definePlugin, defineTable, findPhysicalIndex, getBundleArchiveStorageUri, getContentAddressedAssetStoragePath, indexOrderColumns, meterReads, parseStorageUri, targetBaseCandidateKey, toolingTargetOf, verifyAdapter } from "@hot-updater/plugin-core";
|
|
3
3
|
import { NIL_UUID, createReleaseCatalogScopeKey, encodeChannelKey, selectDesiredRelease } from "@hot-updater/protocol";
|
|
4
4
|
import { createServer } from "node:http";
|
|
5
5
|
//#region src/adminApiTestClient.ts
|
|
@@ -1680,11 +1680,11 @@ const createReleaseCatalogTestStorage = () => ({
|
|
|
1680
1680
|
//#endregion
|
|
1681
1681
|
//#region src/releaseCatalogLifecycleTests.ts
|
|
1682
1682
|
function setupReleaseCatalogLifecycleTests(options) {
|
|
1683
|
-
const device = (
|
|
1684
|
-
builtInBundleId:
|
|
1685
|
-
currentBundleId:
|
|
1683
|
+
const device = (minBundleId = NIL_UUID) => ({
|
|
1684
|
+
builtInBundleId: minBundleId,
|
|
1685
|
+
currentBundleId: minBundleId,
|
|
1686
1686
|
activeReleaseId: null,
|
|
1687
|
-
|
|
1687
|
+
minBundleId,
|
|
1688
1688
|
cohort: "1",
|
|
1689
1689
|
crashedBundleIds: []
|
|
1690
1690
|
});
|
|
@@ -3876,8 +3876,8 @@ const remoteConfigTemplate = (greeting) => ({
|
|
|
3876
3876
|
conditionalValues: { Beta: { value: `${greeting}, tester` } }
|
|
3877
3877
|
} }
|
|
3878
3878
|
});
|
|
3879
|
-
const DAY = 864e5;
|
|
3880
|
-
const HOUR = 36e5;
|
|
3879
|
+
const DAY$2 = 864e5;
|
|
3880
|
+
const HOUR$2 = 36e5;
|
|
3881
3881
|
/** The UTC midnight Insights events start at. */
|
|
3882
3882
|
const T0 = Date.UTC(2026, 8, 20);
|
|
3883
3883
|
const NATIVE_PAGE_SIZE = 2;
|
|
@@ -3938,13 +3938,13 @@ const failureOf = (n, install, check = false) => eventOf(200 + n, {
|
|
|
3938
3938
|
http_status: 403
|
|
3939
3939
|
}
|
|
3940
3940
|
},
|
|
3941
|
-
received_at_ms: T0 + 3 * DAY + n * 10 * 6e4
|
|
3941
|
+
received_at_ms: T0 + 3 * DAY$2 + n * 10 * 6e4
|
|
3942
3942
|
});
|
|
3943
3943
|
/** Where a client floods update failures: Android `flood`, day 5. */
|
|
3944
3944
|
const FLOOD = {
|
|
3945
3945
|
platform: "android",
|
|
3946
3946
|
channel: "flood",
|
|
3947
|
-
start: T0 + 5 * DAY
|
|
3947
|
+
start: T0 + 5 * DAY$2
|
|
3948
3948
|
};
|
|
3949
3949
|
/** The flood's failed checks: more breakdown rows than a read takes from an hour. */
|
|
3950
3950
|
const FLOOD_CHECKS = 24;
|
|
@@ -3980,7 +3980,7 @@ const floodFailureOf = (n) => {
|
|
|
3980
3980
|
http_status: 100 + Math.floor(n / 8)
|
|
3981
3981
|
}
|
|
3982
3982
|
},
|
|
3983
|
-
received_at_ms: FLOOD.start + (real ? HOUR : n * 1e3)
|
|
3983
|
+
received_at_ms: FLOOD.start + (real ? HOUR$2 : n * 1e3)
|
|
3984
3984
|
});
|
|
3985
3985
|
};
|
|
3986
3986
|
/**
|
|
@@ -3993,7 +3993,7 @@ const historyOf = (n) => eventOf(100 + n, {
|
|
|
3993
3993
|
from_bundle_id: "bundle-history-a",
|
|
3994
3994
|
to_release_id: "release-history",
|
|
3995
3995
|
to_bundle_id: "bundle-history-b",
|
|
3996
|
-
received_at_ms: T0 - DAY + Math.floor((n - 1) / 3) * HOUR + (n - 1) % 3 * 6e5
|
|
3996
|
+
received_at_ms: T0 - DAY$2 + Math.floor((n - 1) / 3) * HOUR$2 + (n - 1) % 3 * 6e5
|
|
3997
3997
|
});
|
|
3998
3998
|
const production = {
|
|
3999
3999
|
channel: "production",
|
|
@@ -4056,7 +4056,7 @@ const bundleEvents = {
|
|
|
4056
4056
|
platform: "ios",
|
|
4057
4057
|
channel: "production",
|
|
4058
4058
|
type: "UPDATE_APPLIED",
|
|
4059
|
-
|
|
4059
|
+
toReleaseId: "release-b"
|
|
4060
4060
|
};
|
|
4061
4061
|
/** The target bundle's manifest, which artifact resolution reads from storage. */
|
|
4062
4062
|
const storage = {
|
|
@@ -4171,12 +4171,12 @@ const seed = async (database) => {
|
|
|
4171
4171
|
from_bundle_id: "bundle-b",
|
|
4172
4172
|
to_release_id: "release-a",
|
|
4173
4173
|
to_bundle_id: "bundle-a",
|
|
4174
|
-
received_at_ms: T0 + 2 * DAY
|
|
4174
|
+
received_at_ms: T0 + 2 * DAY$2
|
|
4175
4175
|
}));
|
|
4176
4176
|
await api.insights.recordEvent(eventOf(26, {
|
|
4177
4177
|
install_id: "install-1",
|
|
4178
4178
|
user_id: "user-odd",
|
|
4179
|
-
received_at_ms: T0 + 2 * DAY + 6e5
|
|
4179
|
+
received_at_ms: T0 + 2 * DAY$2 + 6e5
|
|
4180
4180
|
}));
|
|
4181
4181
|
for (let n = 1; n <= 72; n += 1) await api.insights.recordEvent(historyOf(n));
|
|
4182
4182
|
await api.insights.recordEvent(failureOf(1, 3));
|
|
@@ -4668,7 +4668,7 @@ const READ_BUDGETS = [
|
|
|
4668
4668
|
api: "list events of a dense day: limit rows from one query",
|
|
4669
4669
|
read: ({ insights }) => insights.listEvents({
|
|
4670
4670
|
filter: { kind: "all" },
|
|
4671
|
-
sinceMs: T0 - DAY,
|
|
4671
|
+
sinceMs: T0 - DAY$2,
|
|
4672
4672
|
beforeReceivedAtMs: T0,
|
|
4673
4673
|
limit: 5
|
|
4674
4674
|
}),
|
|
@@ -4684,7 +4684,7 @@ const READ_BUDGETS = [
|
|
|
4684
4684
|
read: ({ insights }) => insights.listEvents({
|
|
4685
4685
|
filter: bundleEvents,
|
|
4686
4686
|
sinceMs: T0,
|
|
4687
|
-
beforeReceivedAtMs: T0 + 3 * DAY,
|
|
4687
|
+
beforeReceivedAtMs: T0 + 3 * DAY$2,
|
|
4688
4688
|
limit: 5
|
|
4689
4689
|
}),
|
|
4690
4690
|
adapter: reads(1, 7, 4, 6),
|
|
@@ -4698,8 +4698,8 @@ const READ_BUDGETS = [
|
|
|
4698
4698
|
api: "list events over an empty range: its top day and one outcome read, both empty",
|
|
4699
4699
|
read: ({ insights }) => insights.listEvents({
|
|
4700
4700
|
filter: { kind: "all" },
|
|
4701
|
-
sinceMs: T0 - 91 * DAY,
|
|
4702
|
-
beforeReceivedAtMs: T0 - DAY,
|
|
4701
|
+
sinceMs: T0 - 91 * DAY$2,
|
|
4702
|
+
beforeReceivedAtMs: T0 - DAY$2,
|
|
4703
4703
|
limit: 5
|
|
4704
4704
|
}),
|
|
4705
4705
|
adapter: reads(0, 0, 2, 0),
|
|
@@ -4737,7 +4737,7 @@ const READ_BUDGETS = [
|
|
|
4737
4737
|
read: ({ insights }) => insights.countEvents({
|
|
4738
4738
|
filter: bundleEvents,
|
|
4739
4739
|
sinceMs: T0,
|
|
4740
|
-
beforeReceivedAtMs: T0 + 2 * HOUR
|
|
4740
|
+
beforeReceivedAtMs: T0 + 2 * HOUR$2
|
|
4741
4741
|
}),
|
|
4742
4742
|
adapter: reads(0, 0, 1, 11),
|
|
4743
4743
|
engine: {
|
|
@@ -4752,9 +4752,9 @@ const READ_BUDGETS = [
|
|
|
4752
4752
|
filter: bundleEvents,
|
|
4753
4753
|
timeRange: {
|
|
4754
4754
|
start: T0,
|
|
4755
|
-
end: T0 + 3 * DAY
|
|
4755
|
+
end: T0 + 3 * DAY$2
|
|
4756
4756
|
},
|
|
4757
|
-
intervalMs: DAY
|
|
4757
|
+
intervalMs: DAY$2
|
|
4758
4758
|
}),
|
|
4759
4759
|
adapter: reads(0, 0, 1, 25),
|
|
4760
4760
|
engine: {
|
|
@@ -4782,23 +4782,22 @@ const READ_BUDGETS = [
|
|
|
4782
4782
|
check: (count) => expect(count).toBe(24)
|
|
4783
4783
|
}),
|
|
4784
4784
|
budget({
|
|
4785
|
-
api: "
|
|
4786
|
-
read: ({ insights }) => insights.
|
|
4785
|
+
api: "countReleaseInstallations: the scope's rows, read once for both counts",
|
|
4786
|
+
read: ({ insights }) => insights.countReleaseInstallations({
|
|
4787
4787
|
platform: "ios",
|
|
4788
4788
|
channel: "production",
|
|
4789
4789
|
sinceMs: T0,
|
|
4790
|
-
|
|
4791
|
-
field: "to_bundle_id",
|
|
4792
|
-
value: "bundle-b",
|
|
4793
|
-
types: ["UPDATE_APPLIED"]
|
|
4794
|
-
}]
|
|
4790
|
+
releaseId: "release-b"
|
|
4795
4791
|
}),
|
|
4796
4792
|
adapter: reads(0, 0, 1, 15),
|
|
4797
4793
|
engine: {
|
|
4798
4794
|
calls: 1,
|
|
4799
4795
|
rows: 2
|
|
4800
4796
|
},
|
|
4801
|
-
check: (
|
|
4797
|
+
check: (counts) => expect(counts).toEqual({
|
|
4798
|
+
installations: 24,
|
|
4799
|
+
release: 24
|
|
4800
|
+
})
|
|
4802
4801
|
}),
|
|
4803
4802
|
budget({
|
|
4804
4803
|
api: "release activity: buckets × shards, all used",
|
|
@@ -4821,9 +4820,9 @@ const READ_BUDGETS = [
|
|
|
4821
4820
|
platform: "all",
|
|
4822
4821
|
timeRange: {
|
|
4823
4822
|
start: T0,
|
|
4824
|
-
end: T0 + 3 * DAY
|
|
4823
|
+
end: T0 + 3 * DAY$2
|
|
4825
4824
|
},
|
|
4826
|
-
intervalMs: DAY
|
|
4825
|
+
intervalMs: DAY$2
|
|
4827
4826
|
}),
|
|
4828
4827
|
adapter: reads(0, 0, 6, 30),
|
|
4829
4828
|
engine: {
|
|
@@ -4842,8 +4841,8 @@ const READ_BUDGETS = [
|
|
|
4842
4841
|
channel: "production",
|
|
4843
4842
|
releaseId: "release-b",
|
|
4844
4843
|
timeRange: {
|
|
4845
|
-
start: T0 + 3 * DAY,
|
|
4846
|
-
end: T0 + 4 * DAY
|
|
4844
|
+
start: T0 + 3 * DAY$2,
|
|
4845
|
+
end: T0 + 4 * DAY$2
|
|
4847
4846
|
}
|
|
4848
4847
|
}),
|
|
4849
4848
|
adapter: reads(0, 0, 3, 5),
|
|
@@ -4867,8 +4866,8 @@ const READ_BUDGETS = [
|
|
|
4867
4866
|
platform: "ios",
|
|
4868
4867
|
channel: "production",
|
|
4869
4868
|
timeRange: {
|
|
4870
|
-
start: T0 + 3 * DAY,
|
|
4871
|
-
end: T0 + 4 * DAY
|
|
4869
|
+
start: T0 + 3 * DAY$2,
|
|
4870
|
+
end: T0 + 4 * DAY$2
|
|
4872
4871
|
}
|
|
4873
4872
|
}),
|
|
4874
4873
|
adapter: reads(0, 0, 5, 6),
|
|
@@ -4888,7 +4887,7 @@ const READ_BUDGETS = [
|
|
|
4888
4887
|
channel: FLOOD.channel,
|
|
4889
4888
|
timeRange: {
|
|
4890
4889
|
start: FLOOD.start,
|
|
4891
|
-
end: FLOOD.start + 2 * HOUR
|
|
4890
|
+
end: FLOOD.start + 2 * HOUR$2
|
|
4892
4891
|
}
|
|
4893
4892
|
}),
|
|
4894
4893
|
adapter: reads(1, 1, 5, 177),
|
|
@@ -5170,9 +5169,9 @@ const READ_BUDGETS = [
|
|
|
5170
5169
|
from_bundle_id: "bundle-b",
|
|
5171
5170
|
to_release_id: "release-c",
|
|
5172
5171
|
to_bundle_id: "bundle-c",
|
|
5173
|
-
received_at_ms: T0 + 3 * HOUR
|
|
5172
|
+
received_at_ms: T0 + 3 * HOUR$2
|
|
5174
5173
|
})),
|
|
5175
|
-
adapter: reads(
|
|
5174
|
+
adapter: reads(5, 8, 0, 0),
|
|
5176
5175
|
engine: {
|
|
5177
5176
|
calls: 2,
|
|
5178
5177
|
rows: 1
|
|
@@ -5215,7 +5214,7 @@ const setupReadBudgetTestSuite = (options) => {
|
|
|
5215
5214
|
return adapter.write(ops);
|
|
5216
5215
|
}
|
|
5217
5216
|
}, plugins, {
|
|
5218
|
-
now: () => T0 + 10 * DAY,
|
|
5217
|
+
now: () => T0 + 10 * DAY$2,
|
|
5219
5218
|
storage
|
|
5220
5219
|
});
|
|
5221
5220
|
seeded = await seed(database);
|
|
@@ -5248,7 +5247,7 @@ const setupReadBudgetTestSuite = (options) => {
|
|
|
5248
5247
|
const newInstall = (n) => eventOf(400 + n, {
|
|
5249
5248
|
install_id: `new-install-${n}`,
|
|
5250
5249
|
user_id: null,
|
|
5251
|
-
received_at_ms: T0 + 4 * DAY + n * 1e3
|
|
5250
|
+
received_at_ms: T0 + 4 * DAY$2 + n * 1e3
|
|
5252
5251
|
});
|
|
5253
5252
|
/** Events of later days, which no prune below reaches. */
|
|
5254
5253
|
const store = async (from, count) => {
|
|
@@ -5273,7 +5272,7 @@ const setupReadBudgetTestSuite = (options) => {
|
|
|
5273
5272
|
const events = tables.find(({ name }) => name === "bundle_events");
|
|
5274
5273
|
const prune = async () => {
|
|
5275
5274
|
written.reset();
|
|
5276
|
-
expect(await adapter.prune(events, T0 - DAY, 5)).toBe(5);
|
|
5275
|
+
expect(await adapter.prune(events, T0 - DAY$2, 5)).toBe(5);
|
|
5277
5276
|
return (await written.rows()).reduce((sum, rows) => sum + rows, 0);
|
|
5278
5277
|
};
|
|
5279
5278
|
const before = await prune();
|
|
@@ -5767,6 +5766,336 @@ const createBundleEventRowFixture = (suffix, receivedAtMs) => ({
|
|
|
5767
5766
|
received_at_ms: receivedAtMs
|
|
5768
5767
|
});
|
|
5769
5768
|
//#endregion
|
|
5769
|
+
//#region src/insights/insights11.ts
|
|
5770
|
+
const HOUR$1 = 36e5;
|
|
5771
|
+
const DAY$1 = 864e5;
|
|
5772
|
+
/**
|
|
5773
|
+
* The refs a 1.1 server wrote: each names the artifact. A frozen copy of
|
|
5774
|
+
* 1.1's `bundleRefsOf`, so the fixture writes rows as 1.1 did.
|
|
5775
|
+
*/
|
|
5776
|
+
const artifactRefsOf = (row) => {
|
|
5777
|
+
const metadata = row.metadata;
|
|
5778
|
+
if (metadata.late === true) return [];
|
|
5779
|
+
if (row.type === "UPDATE_FAILED" && metadata.failure?.stage === "check") return [];
|
|
5780
|
+
if (row.type === "RECOVERED") return [`from:${row.from_bundle_id}`];
|
|
5781
|
+
if (row.type === "UNCHANGED") {
|
|
5782
|
+
const kinds = metadata.change?.kinds ?? [];
|
|
5783
|
+
return kinds.includes("bundle") && !kinds.includes("first_seen") && row.to_release_id !== null ? [`on:${row.to_bundle_id}`] : [];
|
|
5784
|
+
}
|
|
5785
|
+
return [`to:${row.to_bundle_id}`];
|
|
5786
|
+
};
|
|
5787
|
+
/**
|
|
5788
|
+
* Insights' raw events and outcome counters as 1.1 declared them, which a
|
|
5789
|
+
* 1.1 server writes: the same tables, columns, and indexes, with refs that
|
|
5790
|
+
* name the artifact.
|
|
5791
|
+
*/
|
|
5792
|
+
const insights11Schema = {
|
|
5793
|
+
bundle_events: defineTable({
|
|
5794
|
+
id: {
|
|
5795
|
+
type: "string",
|
|
5796
|
+
maxLength: 36
|
|
5797
|
+
},
|
|
5798
|
+
type: {
|
|
5799
|
+
type: "string",
|
|
5800
|
+
maxLength: 32
|
|
5801
|
+
},
|
|
5802
|
+
install_id: {
|
|
5803
|
+
type: "string",
|
|
5804
|
+
maxLength: 255
|
|
5805
|
+
},
|
|
5806
|
+
user_id: {
|
|
5807
|
+
type: "string",
|
|
5808
|
+
maxLength: 255,
|
|
5809
|
+
required: false
|
|
5810
|
+
},
|
|
5811
|
+
from_release_id: {
|
|
5812
|
+
type: "string",
|
|
5813
|
+
maxLength: 36,
|
|
5814
|
+
required: false
|
|
5815
|
+
},
|
|
5816
|
+
from_bundle_id: {
|
|
5817
|
+
type: "string",
|
|
5818
|
+
maxLength: 36,
|
|
5819
|
+
required: false
|
|
5820
|
+
},
|
|
5821
|
+
to_release_id: {
|
|
5822
|
+
type: "string",
|
|
5823
|
+
maxLength: 36,
|
|
5824
|
+
required: false
|
|
5825
|
+
},
|
|
5826
|
+
to_bundle_id: {
|
|
5827
|
+
type: "string",
|
|
5828
|
+
maxLength: 36
|
|
5829
|
+
},
|
|
5830
|
+
platform: {
|
|
5831
|
+
type: "string",
|
|
5832
|
+
maxLength: 16
|
|
5833
|
+
},
|
|
5834
|
+
app_version: { type: "string" },
|
|
5835
|
+
channel: { type: "string" },
|
|
5836
|
+
metadata: { type: "json" },
|
|
5837
|
+
received_at_ms: { type: "integer" }
|
|
5838
|
+
}, {
|
|
5839
|
+
key: ["id"],
|
|
5840
|
+
derived: {
|
|
5841
|
+
day: {
|
|
5842
|
+
type: "integer",
|
|
5843
|
+
compute: (row) => row.received_at_ms - row.received_at_ms % DAY$1
|
|
5844
|
+
},
|
|
5845
|
+
movement_install_id: {
|
|
5846
|
+
type: "string",
|
|
5847
|
+
compute: (row) => row.install_id
|
|
5848
|
+
},
|
|
5849
|
+
bundle_ref: {
|
|
5850
|
+
type: "string",
|
|
5851
|
+
multi: true,
|
|
5852
|
+
compute: (row) => artifactRefsOf(row)
|
|
5853
|
+
}
|
|
5854
|
+
},
|
|
5855
|
+
indexes: {
|
|
5856
|
+
movementsByInstall: {
|
|
5857
|
+
eq: ["movement_install_id"],
|
|
5858
|
+
sort: ["received_at_ms"]
|
|
5859
|
+
},
|
|
5860
|
+
byBundle: {
|
|
5861
|
+
eq: [
|
|
5862
|
+
"platform",
|
|
5863
|
+
"channel",
|
|
5864
|
+
"type",
|
|
5865
|
+
"bundle_ref",
|
|
5866
|
+
"day"
|
|
5867
|
+
],
|
|
5868
|
+
sort: ["received_at_ms"]
|
|
5869
|
+
},
|
|
5870
|
+
byDay: {
|
|
5871
|
+
eq: ["day"],
|
|
5872
|
+
sort: ["received_at_ms"]
|
|
5873
|
+
}
|
|
5874
|
+
},
|
|
5875
|
+
retention: {
|
|
5876
|
+
field: "day",
|
|
5877
|
+
days: 90
|
|
5878
|
+
}
|
|
5879
|
+
}),
|
|
5880
|
+
insights_outcomes: defineAggregate({
|
|
5881
|
+
platform: {
|
|
5882
|
+
type: "string",
|
|
5883
|
+
maxLength: 16
|
|
5884
|
+
},
|
|
5885
|
+
channel: { type: "string" },
|
|
5886
|
+
type: {
|
|
5887
|
+
type: "string",
|
|
5888
|
+
maxLength: 32
|
|
5889
|
+
},
|
|
5890
|
+
bundle_ref: {
|
|
5891
|
+
type: "string",
|
|
5892
|
+
maxLength: 41
|
|
5893
|
+
},
|
|
5894
|
+
bucket_start_ms: { type: "integer" }
|
|
5895
|
+
}, {
|
|
5896
|
+
key: [
|
|
5897
|
+
"platform",
|
|
5898
|
+
"channel",
|
|
5899
|
+
"type",
|
|
5900
|
+
"bundle_ref",
|
|
5901
|
+
"bucket_start_ms"
|
|
5902
|
+
],
|
|
5903
|
+
counters: ["events"],
|
|
5904
|
+
shards: 8,
|
|
5905
|
+
batched: true,
|
|
5906
|
+
indexes: { byRef: {
|
|
5907
|
+
eq: [
|
|
5908
|
+
"platform",
|
|
5909
|
+
"channel",
|
|
5910
|
+
"type",
|
|
5911
|
+
"bundle_ref"
|
|
5912
|
+
],
|
|
5913
|
+
sort: ["bucket_start_ms"]
|
|
5914
|
+
} },
|
|
5915
|
+
retention: {
|
|
5916
|
+
field: "bucket_start_ms",
|
|
5917
|
+
days: 90
|
|
5918
|
+
}
|
|
5919
|
+
})
|
|
5920
|
+
};
|
|
5921
|
+
/**
|
|
5922
|
+
* A 1.1 server's `insights()` as far as the release-ref backfill reads it:
|
|
5923
|
+
* its API's `record(row)` stores an event and counts its outcome hours by
|
|
5924
|
+
* artifact, as 1.1's `countOutcome` did, to test the backfill and `db
|
|
5925
|
+
* migrate` on rows a 1.1 server wrote. It stands in for the official
|
|
5926
|
+
* plugin, so it takes its id and brand; serve it over a database whose
|
|
5927
|
+
* Insights tables `insights()` created.
|
|
5928
|
+
*/
|
|
5929
|
+
const insights11TestPlugin = () => Object.defineProperty(definePlugin({
|
|
5930
|
+
id: "insights",
|
|
5931
|
+
namespace: false,
|
|
5932
|
+
schemaVersion: "1.0.0",
|
|
5933
|
+
schema: insights11Schema,
|
|
5934
|
+
init: ({ db }) => ({ api: { record: (event) => db.transaction(async (tx) => {
|
|
5935
|
+
tx.create("bundle_events", event);
|
|
5936
|
+
const hour = (type, ref) => tx.aggregate("insights_outcomes", {
|
|
5937
|
+
platform: event.platform,
|
|
5938
|
+
channel: event.channel,
|
|
5939
|
+
type,
|
|
5940
|
+
bundle_ref: ref,
|
|
5941
|
+
bucket_start_ms: event.received_at_ms - event.received_at_ms % HOUR$1
|
|
5942
|
+
}, { events: 1 }, { shardBy: event.install_id });
|
|
5943
|
+
for (const ref of artifactRefsOf(event)) hour(event.type, ref);
|
|
5944
|
+
if (event.metadata.implied_download === true) hour("UPDATE_DOWNLOADED", `to:${event.type === "RECOVERED" ? event.from_bundle_id : event.to_bundle_id}`);
|
|
5945
|
+
tx.aggregate("insights_outcomes", {
|
|
5946
|
+
platform: "*",
|
|
5947
|
+
channel: "",
|
|
5948
|
+
type: "",
|
|
5949
|
+
bundle_ref: "",
|
|
5950
|
+
bucket_start_ms: event.received_at_ms - event.received_at_ms % DAY$1
|
|
5951
|
+
}, { events: 1 }, { shardBy: event.install_id });
|
|
5952
|
+
}) } })
|
|
5953
|
+
}), Symbol.for("@hot-updater/server/official-plugin"), { value: true });
|
|
5954
|
+
//#endregion
|
|
5955
|
+
//#region src/insights/insightsBackfillTests.ts
|
|
5956
|
+
const HOUR = 36e5;
|
|
5957
|
+
const DAY = 864e5;
|
|
5958
|
+
/**
|
|
5959
|
+
* The backfill of a 1.1 server's rows, on one database: `createApi(database,
|
|
5960
|
+
* plugin)` serves `plugin`, `insights()` when omitted, over it, and returns
|
|
5961
|
+
* its API.
|
|
5962
|
+
*/
|
|
5963
|
+
const registerInsightsBackfillTests = (context) => {
|
|
5964
|
+
describe("Insights release-ref backfill", () => {
|
|
5965
|
+
it("moves a 1.1 server's artifact-keyed events and counts to their releases, once, and again after a 1.1 server writes more", async () => {
|
|
5966
|
+
const database = context.getDatabase();
|
|
5967
|
+
const legacy = context.createApi(database, insights11TestPlugin());
|
|
5968
|
+
const api = context.createApi(database);
|
|
5969
|
+
const base = Date.now() - Date.now() % HOUR - 6 * HOUR;
|
|
5970
|
+
const artifactA = createBundleEventRowFixture("9850", 0).to_bundle_id;
|
|
5971
|
+
const artifactB = createBundleEventRowFixture("9851", 0).to_bundle_id;
|
|
5972
|
+
const builtin = createBundleEventRowFixture("9852", 0).to_bundle_id;
|
|
5973
|
+
const v3 = "00000000-0000-7000-8000-000000009853";
|
|
5974
|
+
const v4 = "00000000-0000-7000-8000-000000009854";
|
|
5975
|
+
const v5 = "00000000-0000-7000-8000-000000009855";
|
|
5976
|
+
const event = (suffix, at, installId, fields) => ({
|
|
5977
|
+
...createBundleEventRowFixture(suffix, base + at),
|
|
5978
|
+
install_id: installId,
|
|
5979
|
+
...fields
|
|
5980
|
+
});
|
|
5981
|
+
const crash = (suffix, at, installId) => event(suffix, at, installId, {
|
|
5982
|
+
type: "RECOVERED",
|
|
5983
|
+
from_bundle_id: artifactA,
|
|
5984
|
+
from_release_id: v3,
|
|
5985
|
+
to_bundle_id: artifactB,
|
|
5986
|
+
to_release_id: v4
|
|
5987
|
+
});
|
|
5988
|
+
const onV3 = {
|
|
5989
|
+
to_bundle_id: artifactA,
|
|
5990
|
+
to_release_id: v3
|
|
5991
|
+
};
|
|
5992
|
+
const onV5 = {
|
|
5993
|
+
to_bundle_id: artifactA,
|
|
5994
|
+
to_release_id: v5
|
|
5995
|
+
};
|
|
5996
|
+
const events = [
|
|
5997
|
+
event("9860", 0, "backfill-1", onV3),
|
|
5998
|
+
event("9861", 1, "backfill-2", onV3),
|
|
5999
|
+
crash("9862", HOUR, "backfill-1"),
|
|
6000
|
+
{
|
|
6001
|
+
...crash("9863", 3600001, "backfill-2"),
|
|
6002
|
+
metadata: {
|
|
6003
|
+
...createBundleEventRowFixture("9863", 0).metadata,
|
|
6004
|
+
implied_download: true
|
|
6005
|
+
}
|
|
6006
|
+
},
|
|
6007
|
+
event("9864", 2 * HOUR, "backfill-3", onV5),
|
|
6008
|
+
event("9865", 7200001, "backfill-4", onV5),
|
|
6009
|
+
event("9866", 7200002, "backfill-5", onV5),
|
|
6010
|
+
event("9867", 3 * HOUR, "backfill-6", { to_bundle_id: builtin })
|
|
6011
|
+
];
|
|
6012
|
+
for (const row of events) await legacy.record(row);
|
|
6013
|
+
const scope = {
|
|
6014
|
+
platform: "ios",
|
|
6015
|
+
channel: "production"
|
|
6016
|
+
};
|
|
6017
|
+
const count = (filter) => api.countEvents({
|
|
6018
|
+
filter,
|
|
6019
|
+
sinceMs: base - DAY,
|
|
6020
|
+
beforeReceivedAtMs: base + DAY
|
|
6021
|
+
});
|
|
6022
|
+
const launched = (id) => ({
|
|
6023
|
+
...scope,
|
|
6024
|
+
type: "UPDATE_APPLIED",
|
|
6025
|
+
toReleaseId: id
|
|
6026
|
+
});
|
|
6027
|
+
const crashed = (id) => ({
|
|
6028
|
+
...scope,
|
|
6029
|
+
type: "RECOVERED",
|
|
6030
|
+
fromReleaseId: id
|
|
6031
|
+
});
|
|
6032
|
+
const downloaded = (id) => ({
|
|
6033
|
+
...scope,
|
|
6034
|
+
type: "UPDATE_DOWNLOADED",
|
|
6035
|
+
toReleaseId: id
|
|
6036
|
+
});
|
|
6037
|
+
await expectInsightsIndex(() => count(launched(artifactA)), 5);
|
|
6038
|
+
await expect(count(launched(v3))).resolves.toBe(0);
|
|
6039
|
+
await expectInsightsIndex(() => api.backfillReleaseRefs({ dryRun: true }), { events: 7 });
|
|
6040
|
+
await expect(api.backfillReleaseRefs()).resolves.toEqual({ events: 7 });
|
|
6041
|
+
await expectInsightsIndex(() => count(launched(v3)), 2);
|
|
6042
|
+
await expectInsightsIndex(() => count(launched(v5)), 3);
|
|
6043
|
+
await expectInsightsIndex(() => count(crashed(v3)), 2);
|
|
6044
|
+
await expectInsightsIndex(() => count(crashed(v5)), 0);
|
|
6045
|
+
await expectInsightsIndex(() => count(downloaded(v3)), 1);
|
|
6046
|
+
await expectInsightsIndex(() => count(launched(builtin)), 1);
|
|
6047
|
+
await expectInsightsIndex(() => count(launched(artifactA)), 0);
|
|
6048
|
+
await expectInsightsIndex(() => count(crashed(artifactA)), 0);
|
|
6049
|
+
await expectInsightsIndex(() => count(downloaded(artifactA)), 0);
|
|
6050
|
+
await expectInsightsIndex(() => api.listEvents({
|
|
6051
|
+
filter: {
|
|
6052
|
+
kind: "bundle",
|
|
6053
|
+
...crashed(v3)
|
|
6054
|
+
},
|
|
6055
|
+
sinceMs: base - DAY,
|
|
6056
|
+
beforeReceivedAtMs: base + DAY,
|
|
6057
|
+
limit: 10
|
|
6058
|
+
}).then((rows) => rows.map(({ install_id }) => install_id)), ["backfill-2", "backfill-1"]);
|
|
6059
|
+
await expectInsightsIndex(() => api.backfillReleaseRefs({ dryRun: true }), { events: 0 });
|
|
6060
|
+
await expect(api.backfillReleaseRefs()).resolves.toEqual({ events: 0 });
|
|
6061
|
+
await legacy.record(event("9868", 4 * HOUR, "backfill-7", onV5));
|
|
6062
|
+
await expectInsightsIndex(() => count(launched(artifactA)), 1);
|
|
6063
|
+
await expect(count(launched(v5))).resolves.toBe(3);
|
|
6064
|
+
await expectInsightsIndex(() => api.backfillReleaseRefs({ dryRun: true }), { events: 1 });
|
|
6065
|
+
await expect(api.backfillReleaseRefs()).resolves.toEqual({ events: 1 });
|
|
6066
|
+
await expectInsightsIndex(() => count(launched(v5)), 4);
|
|
6067
|
+
await expectInsightsIndex(() => count(launched(artifactA)), 0);
|
|
6068
|
+
});
|
|
6069
|
+
it("moves a day of more stale events than one transaction of the store holds", async () => {
|
|
6070
|
+
const database = context.getDatabase();
|
|
6071
|
+
const legacy = context.createApi(database, insights11TestPlugin());
|
|
6072
|
+
const api = context.createApi(database);
|
|
6073
|
+
const base = Date.now() - Date.now() % HOUR - 2 * HOUR;
|
|
6074
|
+
const release = "00000000-0000-7000-8000-000000009880";
|
|
6075
|
+
const artifact = createBundleEventRowFixture("9881", 0).to_bundle_id;
|
|
6076
|
+
const count = 40;
|
|
6077
|
+
for (let n = 0; n < count; n += 1) await legacy.record({
|
|
6078
|
+
...createBundleEventRowFixture(String(9900 + n), base + n),
|
|
6079
|
+
install_id: `backfill-day-${n}`,
|
|
6080
|
+
to_bundle_id: artifact,
|
|
6081
|
+
to_release_id: release
|
|
6082
|
+
});
|
|
6083
|
+
await expect(api.backfillReleaseRefs()).resolves.toEqual({ events: count });
|
|
6084
|
+
await expectInsightsIndex(() => api.countEvents({
|
|
6085
|
+
filter: {
|
|
6086
|
+
platform: "ios",
|
|
6087
|
+
channel: "production",
|
|
6088
|
+
type: "UPDATE_APPLIED",
|
|
6089
|
+
toReleaseId: release
|
|
6090
|
+
},
|
|
6091
|
+
sinceMs: base - DAY,
|
|
6092
|
+
beforeReceivedAtMs: base + DAY
|
|
6093
|
+
}), count);
|
|
6094
|
+
await expect(api.backfillReleaseRefs({ dryRun: true })).resolves.toEqual({ events: 0 });
|
|
6095
|
+
});
|
|
6096
|
+
});
|
|
6097
|
+
};
|
|
6098
|
+
//#endregion
|
|
5770
6099
|
//#region src/insights/insightsModelTests.ts
|
|
5771
6100
|
const record = (model, event) => model.recordEvent({ event });
|
|
5772
6101
|
const createMovementEvent = (suffix, receivedAtMs, type, installId) => {
|
|
@@ -5834,7 +6163,7 @@ const registerInsightsModelTests = (state) => {
|
|
|
5834
6163
|
filter: {
|
|
5835
6164
|
kind: "bundle",
|
|
5836
6165
|
type: "UPDATE_DOWNLOADED",
|
|
5837
|
-
|
|
6166
|
+
toReleaseId: download.to_release_id,
|
|
5838
6167
|
platform: "ios",
|
|
5839
6168
|
channel: "production"
|
|
5840
6169
|
},
|
|
@@ -6051,12 +6380,12 @@ const registerInsightsModelTests = (state) => {
|
|
|
6051
6380
|
platform: "ios",
|
|
6052
6381
|
channel: "production",
|
|
6053
6382
|
type: "UPDATE_APPLIED",
|
|
6054
|
-
|
|
6383
|
+
toReleaseId: bundleB
|
|
6055
6384
|
}, applied], [{
|
|
6056
6385
|
platform: "ios",
|
|
6057
6386
|
channel: "production",
|
|
6058
6387
|
type: "RECOVERED",
|
|
6059
|
-
|
|
6388
|
+
fromReleaseId: bundleB
|
|
6060
6389
|
}, recovered]];
|
|
6061
6390
|
for (const [filter, expected] of cases) {
|
|
6062
6391
|
await expectInsightsIndex(() => model.countEvents({
|
|
@@ -6103,25 +6432,11 @@ const registerInsightsModelTests = (state) => {
|
|
|
6103
6432
|
platform: "ios",
|
|
6104
6433
|
channel: "production",
|
|
6105
6434
|
type: "UNCHANGED",
|
|
6106
|
-
|
|
6435
|
+
toReleaseId: bundleB
|
|
6107
6436
|
},
|
|
6108
6437
|
sinceMs: 100,
|
|
6109
6438
|
beforeReceivedAtMs: 200
|
|
6110
6439
|
}), 0);
|
|
6111
|
-
await expectInsightsIndex(() => model.countLatestEvents({
|
|
6112
|
-
platform: "ios",
|
|
6113
|
-
channel: "production",
|
|
6114
|
-
sinceMs: 0,
|
|
6115
|
-
bundle: [{
|
|
6116
|
-
field: "to_bundle_id",
|
|
6117
|
-
value: bundleA,
|
|
6118
|
-
types: [
|
|
6119
|
-
"UNCHANGED",
|
|
6120
|
-
"UPDATE_APPLIED",
|
|
6121
|
-
"RECOVERED"
|
|
6122
|
-
]
|
|
6123
|
-
}]
|
|
6124
|
-
}), 1);
|
|
6125
6440
|
await expectInsightsIndex(() => model.countLatestEvents({
|
|
6126
6441
|
platform: "ios",
|
|
6127
6442
|
channel: "production",
|
|
@@ -6186,40 +6501,127 @@ const registerInsightsModelTests = (state) => {
|
|
|
6186
6501
|
await expect(model.findLatestEvents({ installId: "install-a " })).resolves.toEqual([events[3]]);
|
|
6187
6502
|
await expect(model.findLatestEvents({ installId: "install-a" })).resolves.toEqual([events[2]]);
|
|
6188
6503
|
});
|
|
6189
|
-
it("counts
|
|
6504
|
+
it("counts one release's latest installations: a download's source, and the target of anything else", async () => {
|
|
6190
6505
|
const model = state.getDatabase();
|
|
6191
|
-
const
|
|
6192
|
-
|
|
6193
|
-
const
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
types: [event.type]
|
|
6506
|
+
const releaseA = "00000000-0000-7000-8000-000000009702";
|
|
6507
|
+
const releaseB = "00000000-0000-7000-8000-000000009703";
|
|
6508
|
+
const applied = {
|
|
6509
|
+
...createBundleEventRowFixture("9700", 100),
|
|
6510
|
+
to_release_id: releaseA
|
|
6197
6511
|
};
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
}
|
|
6512
|
+
const downloaded = {
|
|
6513
|
+
...createBundleEventRowFixture("9701", 100),
|
|
6514
|
+
type: "UPDATE_DOWNLOADED",
|
|
6515
|
+
from_release_id: releaseA,
|
|
6516
|
+
to_release_id: releaseB
|
|
6517
|
+
};
|
|
6518
|
+
await record(model, applied);
|
|
6519
|
+
await record(model, downloaded);
|
|
6520
|
+
const scope = {
|
|
6521
|
+
platform: "ios",
|
|
6522
|
+
channel: "production",
|
|
6523
|
+
sinceMs: 0
|
|
6524
|
+
};
|
|
6525
|
+
const count = (releaseId) => releaseId === void 0 ? model.countLatestEvents(scope) : model.countReleaseInstallations({
|
|
6526
|
+
...scope,
|
|
6527
|
+
releaseId
|
|
6528
|
+
}).then(({ release }) => release);
|
|
6529
|
+
await expectInsightsIndex(() => count(releaseA), 2);
|
|
6530
|
+
await expectInsightsIndex(() => count(releaseB), 0);
|
|
6531
|
+
await expectInsightsIndex(() => count(), 2);
|
|
6204
6532
|
});
|
|
6205
|
-
it("
|
|
6533
|
+
it("keeps two releases of one artifact in one scope apart, as a promote back into the channel makes them", async () => {
|
|
6206
6534
|
const model = state.getDatabase();
|
|
6207
|
-
const
|
|
6208
|
-
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6535
|
+
const artifactA = createBundleEventRowFixture("9750", 0).to_bundle_id;
|
|
6536
|
+
const artifactB = createBundleEventRowFixture("9751", 0).to_bundle_id;
|
|
6537
|
+
const v3 = "00000000-0000-7000-8000-000000009753";
|
|
6538
|
+
const v4 = "00000000-0000-7000-8000-000000009754";
|
|
6539
|
+
const v5 = "00000000-0000-7000-8000-000000009755";
|
|
6540
|
+
const event = (suffix, receivedAtMs, installId, fields) => ({
|
|
6541
|
+
...createBundleEventRowFixture(suffix, receivedAtMs),
|
|
6542
|
+
install_id: installId,
|
|
6543
|
+
...fields
|
|
6544
|
+
});
|
|
6545
|
+
const onV3 = {
|
|
6546
|
+
to_bundle_id: artifactA,
|
|
6547
|
+
to_release_id: v3
|
|
6548
|
+
};
|
|
6549
|
+
const onV5 = {
|
|
6550
|
+
to_bundle_id: artifactA,
|
|
6551
|
+
to_release_id: v5
|
|
6552
|
+
};
|
|
6553
|
+
const events = [
|
|
6554
|
+
event("9760", 100, "abba-1", onV3),
|
|
6555
|
+
event("9761", 110, "abba-2", onV3),
|
|
6556
|
+
event("9762", 120, "abba-1", {
|
|
6557
|
+
type: "RECOVERED",
|
|
6558
|
+
from_bundle_id: artifactA,
|
|
6559
|
+
from_release_id: v3,
|
|
6560
|
+
to_bundle_id: artifactB,
|
|
6561
|
+
to_release_id: v4
|
|
6562
|
+
}),
|
|
6563
|
+
event("9763", 130, "abba-2", {
|
|
6564
|
+
type: "RECOVERED",
|
|
6565
|
+
from_bundle_id: artifactA,
|
|
6566
|
+
from_release_id: v3,
|
|
6567
|
+
to_bundle_id: artifactB,
|
|
6568
|
+
to_release_id: v4
|
|
6569
|
+
}),
|
|
6570
|
+
event("9764", 200, "abba-3", onV5),
|
|
6571
|
+
event("9765", 210, "abba-4", onV5),
|
|
6572
|
+
event("9766", 220, "abba-5", onV5)
|
|
6573
|
+
];
|
|
6574
|
+
for (const row of events) await record(model, row);
|
|
6575
|
+
const scope = {
|
|
6576
|
+
platform: "ios",
|
|
6577
|
+
channel: "production"
|
|
6578
|
+
};
|
|
6579
|
+
const count = (filter) => model.countEvents({
|
|
6580
|
+
filter,
|
|
6212
6581
|
sinceMs: 0,
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
})
|
|
6582
|
+
beforeReceivedAtMs: 1e3
|
|
6583
|
+
});
|
|
6584
|
+
const series = (filter) => model.countEventSeries({
|
|
6585
|
+
filter,
|
|
6586
|
+
timeRange: {
|
|
6587
|
+
start: 0,
|
|
6588
|
+
end: 36e5
|
|
6589
|
+
},
|
|
6590
|
+
intervalMs: 36e5
|
|
6591
|
+
}).then((points) => points.map(({ events }) => events));
|
|
6592
|
+
const launched = (release) => ({
|
|
6593
|
+
...scope,
|
|
6594
|
+
type: "UPDATE_APPLIED",
|
|
6595
|
+
toReleaseId: release
|
|
6596
|
+
});
|
|
6597
|
+
const crashed = (release) => ({
|
|
6598
|
+
...scope,
|
|
6599
|
+
type: "RECOVERED",
|
|
6600
|
+
fromReleaseId: release
|
|
6601
|
+
});
|
|
6602
|
+
await expectInsightsIndex(() => count(launched(v3)), 2);
|
|
6603
|
+
await expectInsightsIndex(() => count(launched(v5)), 3);
|
|
6604
|
+
await expectInsightsIndex(() => count(crashed(v3)), 2);
|
|
6605
|
+
await expectInsightsIndex(() => count(crashed(v5)), 0);
|
|
6606
|
+
await expectInsightsIndex(() => series(launched(v5)), [3]);
|
|
6607
|
+
await expectInsightsIndex(() => series(crashed(v5)), [0]);
|
|
6608
|
+
await expectInsightsIndex(() => series(crashed(v3)), [2]);
|
|
6609
|
+
const installations = (releaseId) => model.countReleaseInstallations({
|
|
6610
|
+
...scope,
|
|
6611
|
+
sinceMs: 0,
|
|
6612
|
+
releaseId
|
|
6613
|
+
}).then(({ release }) => release);
|
|
6614
|
+
await expectInsightsIndex(() => installations(v5), 3);
|
|
6615
|
+
await expectInsightsIndex(() => installations(v4), 2);
|
|
6616
|
+
await expectInsightsIndex(() => installations(v3), 0);
|
|
6617
|
+
await expectInsightsIndex(() => model.listEvents({
|
|
6618
|
+
filter: {
|
|
6619
|
+
kind: "bundle",
|
|
6620
|
+
...crashed(v3)
|
|
6621
|
+
},
|
|
6622
|
+
beforeReceivedAtMs: 1e3,
|
|
6623
|
+
limit: 10
|
|
6624
|
+
}).then((rows) => rows.map(({ install_id }) => install_id)), ["abba-2", "abba-1"]);
|
|
6223
6625
|
});
|
|
6224
6626
|
it("returns zero for successful empty scalar queries", async () => {
|
|
6225
6627
|
const model = state.getDatabase();
|
|
@@ -6233,7 +6635,7 @@ const registerInsightsModelTests = (state) => {
|
|
|
6233
6635
|
platform: "ios",
|
|
6234
6636
|
channel: "production",
|
|
6235
6637
|
type: "RECOVERED",
|
|
6236
|
-
|
|
6638
|
+
fromReleaseId: "00000000-0000-7000-8000-000000003001"
|
|
6237
6639
|
},
|
|
6238
6640
|
sinceMs: 0,
|
|
6239
6641
|
beforeReceivedAtMs: 100
|
|
@@ -6318,12 +6720,12 @@ const registerInsightsModelTests = (state) => {
|
|
|
6318
6720
|
await expectInsightsIndex(() => hourly({
|
|
6319
6721
|
...scope,
|
|
6320
6722
|
type: "UPDATE_APPLIED",
|
|
6321
|
-
|
|
6723
|
+
toReleaseId: releaseB
|
|
6322
6724
|
}), points(2, 0, 0));
|
|
6323
6725
|
await expectInsightsIndex(() => hourly({
|
|
6324
6726
|
...scope,
|
|
6325
6727
|
type: "RECOVERED",
|
|
6326
|
-
|
|
6728
|
+
fromReleaseId: releaseB
|
|
6327
6729
|
}), points(1, 0, 0));
|
|
6328
6730
|
const usage = await model.getAppUsage({
|
|
6329
6731
|
channel: "production",
|
|
@@ -6398,6 +6800,14 @@ const registerInsightsModelTests = (state) => {
|
|
|
6398
6800
|
installations: 1
|
|
6399
6801
|
}]));
|
|
6400
6802
|
expect(usage.bundleDistribution).toHaveLength(2);
|
|
6803
|
+
const installations = (releaseId) => model.countReleaseInstallations({
|
|
6804
|
+
channel,
|
|
6805
|
+
platform: "ios",
|
|
6806
|
+
sinceMs: 0,
|
|
6807
|
+
releaseId
|
|
6808
|
+
}).then(({ release }) => release);
|
|
6809
|
+
await expectInsightsIndex(() => installations(builtin), 2);
|
|
6810
|
+
await expect(installations(createBundleEventRowFixture("9905", 0).id)).resolves.toBe(0);
|
|
6401
6811
|
});
|
|
6402
6812
|
it("pages insights events newest first with a stable cursor", async () => {
|
|
6403
6813
|
const model = state.getDatabase();
|
|
@@ -6541,7 +6951,7 @@ const registerInsightsModelTests = (state) => {
|
|
|
6541
6951
|
platform: "ios",
|
|
6542
6952
|
channel: "production",
|
|
6543
6953
|
type: "UNCHANGED",
|
|
6544
|
-
|
|
6954
|
+
toReleaseId: releaseB
|
|
6545
6955
|
},
|
|
6546
6956
|
sinceMs: 0,
|
|
6547
6957
|
beforeReceivedAtMs: 2 * day
|
|
@@ -6650,11 +7060,11 @@ const registerInsightsModelTests = (state) => {
|
|
|
6650
7060
|
await expectInsightsIndex(async () => await count({
|
|
6651
7061
|
...scope,
|
|
6652
7062
|
type: "UPDATE_APPLIED",
|
|
6653
|
-
|
|
7063
|
+
toReleaseId: releaseB
|
|
6654
7064
|
}) + await count({
|
|
6655
7065
|
...scope,
|
|
6656
7066
|
type: "UNCHANGED",
|
|
6657
|
-
|
|
7067
|
+
toReleaseId: releaseB
|
|
6658
7068
|
}), metrics.applies);
|
|
6659
7069
|
const implied = (await model.listEvents({
|
|
6660
7070
|
filter: { kind: "all" },
|
|
@@ -6664,7 +7074,7 @@ const registerInsightsModelTests = (state) => {
|
|
|
6664
7074
|
await expectInsightsIndex(() => count({
|
|
6665
7075
|
...scope,
|
|
6666
7076
|
type: "UPDATE_DOWNLOADED",
|
|
6667
|
-
|
|
7077
|
+
toReleaseId: releaseB
|
|
6668
7078
|
}), metrics.downloads);
|
|
6669
7079
|
expect(implied).toBe(2);
|
|
6670
7080
|
expect(metrics.downloads).toBeGreaterThanOrEqual(metrics.applies + metrics.failedLaunches);
|
|
@@ -6725,11 +7135,11 @@ const registerInsightsModelTests = (state) => {
|
|
|
6725
7135
|
platform: "ios",
|
|
6726
7136
|
channel: "production"
|
|
6727
7137
|
};
|
|
6728
|
-
for (const [
|
|
7138
|
+
for (const [toReleaseId, listed] of [[download.to_bundle_id, [download]], [check.to_bundle_id, []]]) {
|
|
6729
7139
|
const filter = {
|
|
6730
7140
|
...scope,
|
|
6731
7141
|
type: "UPDATE_FAILED",
|
|
6732
|
-
|
|
7142
|
+
toReleaseId
|
|
6733
7143
|
};
|
|
6734
7144
|
await expectInsightsIndex(() => model.listEvents({
|
|
6735
7145
|
filter: {
|
|
@@ -6791,6 +7201,7 @@ const setupInsightsHttpTestSuite = (options) => {
|
|
|
6791
7201
|
installId,
|
|
6792
7202
|
latestStatus: "UNCHANGED",
|
|
6793
7203
|
lastKnownBundleId: event.toBundleId,
|
|
7204
|
+
lastKnownReleaseId: null,
|
|
6794
7205
|
channel
|
|
6795
7206
|
});
|
|
6796
7207
|
await expectInsightsIndex(async () => {
|
|
@@ -6972,19 +7383,26 @@ const setupInsightsModelTestSuite = (lifecycle) => {
|
|
|
6972
7383
|
//#region src/insights/index.ts
|
|
6973
7384
|
/**
|
|
6974
7385
|
* The Insights plugin's tests, for `setupDatabaseTestSuite`'s `plugins`: its
|
|
6975
|
-
* HTTP routes on the provider's server, which must run `insights()
|
|
6976
|
-
*
|
|
7386
|
+
* HTTP routes on the provider's server, which must run `insights()`; with
|
|
7387
|
+
* `createModel` its report contract on the provider's database, such as
|
|
6977
7388
|
* `(database) => createInsightsModel(createHotUpdater({ database, storage,
|
|
6978
|
-
* plugins: [insights()], clientAccess: "public" }).api.insights)
|
|
7389
|
+
* plugins: [insights()], clientAccess: "public" }).api.insights)`; and with
|
|
7390
|
+
* `createApi` the backfill of a 1.1 server's rows, such as `(database,
|
|
7391
|
+
* plugin = insights()) => createHotUpdater({ database, storage, plugins:
|
|
7392
|
+
* [plugin], clientAccess: "public" }).api.insights`.
|
|
6979
7393
|
*/
|
|
6980
7394
|
const insightsTestSuite = (options = {}) => ({
|
|
6981
7395
|
name: "Insights plugin",
|
|
6982
7396
|
register: (context) => {
|
|
6983
7397
|
setupInsightsHttpTestSuite({ getClient: context.getClient });
|
|
6984
|
-
const { createModel } = options;
|
|
7398
|
+
const { createModel, createApi } = options;
|
|
6985
7399
|
if (createModel !== void 0) describe("Insights model", () => {
|
|
6986
7400
|
registerInsightsModelTests({ getDatabase: () => createModel(context.getDatabase()) });
|
|
6987
7401
|
});
|
|
7402
|
+
if (createApi !== void 0) registerInsightsBackfillTests({
|
|
7403
|
+
getDatabase: context.getDatabase,
|
|
7404
|
+
createApi: (database, plugin) => createApi(database, plugin)
|
|
7405
|
+
});
|
|
6988
7406
|
}
|
|
6989
7407
|
});
|
|
6990
7408
|
//#endregion
|
|
@@ -7144,4 +7562,61 @@ async function startHttpTestServer(handlers) {
|
|
|
7144
7562
|
};
|
|
7145
7563
|
}
|
|
7146
7564
|
//#endregion
|
|
7147
|
-
|
|
7565
|
+
//#region src/capacityCappedStore.ts
|
|
7566
|
+
/**
|
|
7567
|
+
* DynamoDB's price of one op in `TransactWriteItems`: 2 write units per
|
|
7568
|
+
* started KB of the item.
|
|
7569
|
+
*/
|
|
7570
|
+
const unitsOf = (op) => {
|
|
7571
|
+
const item = op.type === "put" ? op.value : op.type === "add" ? {
|
|
7572
|
+
...op.init,
|
|
7573
|
+
...op.by
|
|
7574
|
+
} : {};
|
|
7575
|
+
const bytes = new TextEncoder().encode(JSON.stringify([
|
|
7576
|
+
op.key.pk,
|
|
7577
|
+
op.key.sk,
|
|
7578
|
+
item
|
|
7579
|
+
])).length;
|
|
7580
|
+
return 2 * Math.max(1, Math.ceil(bytes / 1024));
|
|
7581
|
+
};
|
|
7582
|
+
/**
|
|
7583
|
+
* `store` behind a strict write-capacity cap: a token bucket refilled at
|
|
7584
|
+
* `unitsPerSecond` on a virtual clock, holding one second of units, with
|
|
7585
|
+
* writes priced as DynamoDB prices transactional ones. A write that costs
|
|
7586
|
+
* more than the bucket holds is refused as DynamoDB's store reports a
|
|
7587
|
+
* throttle, `{ ok: false, retry: true }`, so one costing more than a second
|
|
7588
|
+
* of capacity is never admitted. DynamoDB with
|
|
7589
|
+
* `OnDemandThroughput.MaxWriteRequestUnits` is looser, since it admits such a
|
|
7590
|
+
* write from burst capacity when it has some and refuses by time window
|
|
7591
|
+
* otherwise; the strict cap makes a transaction too large for the cap fail
|
|
7592
|
+
* every time instead of by chance. Reads and `deleteConsumed` are not capped.
|
|
7593
|
+
*/
|
|
7594
|
+
const createCapacityCappedStore = (store, { unitsPerSecond, writeMs = 300, throttledMs = 3e3 }) => {
|
|
7595
|
+
let clock = 0;
|
|
7596
|
+
let filledAt = 0;
|
|
7597
|
+
let units = unitsPerSecond;
|
|
7598
|
+
let throttles = 0;
|
|
7599
|
+
return {
|
|
7600
|
+
...store,
|
|
7601
|
+
throttles: () => throttles,
|
|
7602
|
+
async write(ops) {
|
|
7603
|
+
units = Math.min(unitsPerSecond, units + (clock - filledAt) / 1e3 * unitsPerSecond);
|
|
7604
|
+
filledAt = clock;
|
|
7605
|
+
const cost = ops.reduce((sum, op) => sum + unitsOf(op), 0);
|
|
7606
|
+
if (cost > units) {
|
|
7607
|
+
throttles += 1;
|
|
7608
|
+
clock += throttledMs;
|
|
7609
|
+
return {
|
|
7610
|
+
ok: false,
|
|
7611
|
+
retry: true
|
|
7612
|
+
};
|
|
7613
|
+
}
|
|
7614
|
+
const result = await store.write(ops);
|
|
7615
|
+
units -= cost;
|
|
7616
|
+
clock += writeMs;
|
|
7617
|
+
return result;
|
|
7618
|
+
}
|
|
7619
|
+
};
|
|
7620
|
+
};
|
|
7621
|
+
//#endregion
|
|
7622
|
+
export { LATER_RELEASE_CATALOG_FIELD, RELEASE_CATALOG_DOWNLOAD_HASH, RELEASE_CATALOG_MANIFEST_URIS, RELEASE_CATALOG_STORAGE_FIXTURES, conformanceCounters, conformanceExpiring, conformanceItems, createAdminApiTestClient, createBundleEventRowFixture, createBundleFixture, createBundlePatchRowFixture, createBundleRowFixture, createCapacityCappedStore, createChannelRowFixture, createHandlerHttpTestClient, createHttpTestClient, createMeasuredDatabase, createMemoryKeyValueStore, createPluginTestHarness, createReleaseCatalogTestStorage, createReleaseRowFixture, expectInsightsIndex, insights11TestPlugin, insightsTestSuite, jsonRequest, mysqlRowsExamined, postgresRowsExamined, releaseCatalogArtifact, releaseCatalogArtifactFiles, releaseCatalogDownloadUrl, runContentionHarness, setupAggregateBatchingTestSuite, setupBundleMethodsTestSuite, setupCoreAdminTestSuite, setupDatabaseAdapterConformanceSuite, setupDatabaseTestSuite, setupInsightsHttpTestSuite, setupInsightsModelTestSuite, setupReadBudgetTestSuite, setupReleaseCatalogTestSuite, setupReleaseLabelEngineTestSuite, setupReleaseLabelTestSuite, setupSemverSatisfiesTestSuite, setupStorageAdapterTestSuite, startHttpTestServer, storeBundles, toDeployBundle, withAdapterLatency, writeCatalogFromLaterRelease };
|
package/dist/react-native.d.cts
CHANGED
|
@@ -24,7 +24,11 @@ interface ClientPluginTestOptions {
|
|
|
24
24
|
readonly sdkVersion?: string;
|
|
25
25
|
/** Default: false. */
|
|
26
26
|
readonly isDebugBuild?: boolean;
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* What `context.getBundleId()` returns: the selected release's ID, as
|
|
29
|
+
* `hotUpdater.getBundleId()` returns it. Default:
|
|
30
|
+
* `00000000-0000-0000-0000-000000000000`.
|
|
31
|
+
*/
|
|
28
32
|
readonly bundleId?: TestValue<string>;
|
|
29
33
|
/**
|
|
30
34
|
* The native build's built-in bundle. Default:
|
package/dist/react-native.d.mts
CHANGED
|
@@ -24,7 +24,11 @@ interface ClientPluginTestOptions {
|
|
|
24
24
|
readonly sdkVersion?: string;
|
|
25
25
|
/** Default: false. */
|
|
26
26
|
readonly isDebugBuild?: boolean;
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* What `context.getBundleId()` returns: the selected release's ID, as
|
|
29
|
+
* `hotUpdater.getBundleId()` returns it. Default:
|
|
30
|
+
* `00000000-0000-0000-0000-000000000000`.
|
|
31
|
+
*/
|
|
28
32
|
readonly bundleId?: TestValue<string>;
|
|
29
33
|
/**
|
|
30
34
|
* The native build's built-in bundle. Default:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/test-utils",
|
|
3
|
-
"version": "1.2.0-rc.
|
|
3
|
+
"version": "1.2.0-rc.59",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Test utilities for Hot Updater packages",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"mysql2": "*",
|
|
51
51
|
"pg": "*",
|
|
52
52
|
"vitest": "^4.0.0",
|
|
53
|
-
"@hot-updater/plugin-insights": "^1.2.0-rc.
|
|
54
|
-
"@hot-updater/protocol": "^1.2.0-rc.
|
|
55
|
-
"@hot-updater/plugin-core": "^1.2.0-rc.
|
|
56
|
-
"@hot-updater/server": "^1.2.0-rc.
|
|
53
|
+
"@hot-updater/plugin-insights": "^1.2.0-rc.59",
|
|
54
|
+
"@hot-updater/protocol": "^1.2.0-rc.59",
|
|
55
|
+
"@hot-updater/plugin-core": "^1.2.0-rc.59",
|
|
56
|
+
"@hot-updater/server": "^1.2.0-rc.59"
|
|
57
57
|
},
|
|
58
58
|
"peerDependenciesMeta": {
|
|
59
59
|
"@electric-sql/pglite": {
|
|
@@ -84,10 +84,10 @@
|
|
|
84
84
|
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
85
85
|
"vitest": "4.1.4",
|
|
86
86
|
"workspace-tools": "^0.42.3",
|
|
87
|
-
"@hot-updater/plugin-insights": "1.2.0-rc.
|
|
88
|
-
"@hot-updater/protocol": "1.2.0-rc.
|
|
89
|
-
"@hot-updater/
|
|
90
|
-
"@hot-updater/
|
|
87
|
+
"@hot-updater/plugin-insights": "1.2.0-rc.59",
|
|
88
|
+
"@hot-updater/protocol": "1.2.0-rc.59",
|
|
89
|
+
"@hot-updater/plugin-core": "1.2.0-rc.59",
|
|
90
|
+
"@hot-updater/server": "1.2.0-rc.59"
|
|
91
91
|
},
|
|
92
92
|
"inlinedDependencies": {
|
|
93
93
|
"@clack/core": "1.4.3",
|