@hot-updater/test-utils 1.2.0-rc.50 → 1.2.0-rc.51
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/README.md +5 -1
- package/dist/index.d.mts +134 -106
- package/dist/index.mjs +357 -67
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ test executors of `@hot-updater/test-utils/node` take `pg`, `mysql2` or
|
|
|
17
17
|
|
|
18
18
|
## Database adapters and providers
|
|
19
19
|
|
|
20
|
-
Register
|
|
20
|
+
Register four suites against a disposable test database:
|
|
21
21
|
|
|
22
22
|
- `setupDatabaseAdapterConformanceSuite` runs the database adapter contract case
|
|
23
23
|
by case: value round-trips, ordering, guards, all-or-nothing writes, unique
|
|
@@ -28,6 +28,10 @@ Register three suites against a disposable test database:
|
|
|
28
28
|
over `meterReads({ name, adapter: verifyAdapter(adapter) })` from
|
|
29
29
|
`@hot-updater/plugin-core`. `postgresRowsExamined` and `mysqlRowsExamined`
|
|
30
30
|
also count the rows a SQL database examined.
|
|
31
|
+
Register `setupReleaseLabelEngineTestSuite` beside it with the same options:
|
|
32
|
+
it writes releases as a server of an earlier release left them, without
|
|
33
|
+
labels, and checks the label fill, its catalog rebuilds, concurrent fills,
|
|
34
|
+
and the label index's uniqueness on your adapter.
|
|
31
35
|
- `setupDatabaseTestSuite` runs core, Bundles and the Release Catalog contract
|
|
32
36
|
through the admin and client HTTP APIs of `createHotUpdater`, then the suites
|
|
33
37
|
of the server plugins listed in `plugins`, such as the Insights plugin's
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ArtifactFiles, ArtifactInfo, Bundle } from "@hot-updater/protocol";
|
|
2
1
|
import { AnyHotUpdaterPlugin, BundlePatchRow, BundleRow, ChannelRow, ClientAuth, DatabaseAdapter, DeployReleasePolicy, EngineDatabase, HotUpdaterCoreApi, HotUpdaterDatabase, KeyValueStore, ModuleSchema, PhysicalTable, PluginApis, ReadMeasurement, ReleaseRow, StorageAdapter, StorageOperation } from "@hot-updater/plugin-core";
|
|
2
|
+
import { ArtifactFiles, ArtifactInfo, Bundle } from "@hot-updater/protocol";
|
|
3
3
|
import { BundleEventRow, InsightsModel } from "@hot-updater/plugin-insights/server";
|
|
4
4
|
//#region src/httpTestClient.d.ts
|
|
5
5
|
type HttpTestRequestInit = NonNullable<ConstructorParameters<typeof Request>[1]>;
|
|
@@ -73,6 +73,138 @@ declare const setupCoreAdminTestSuite: (options: {
|
|
|
73
73
|
readonly getClient: () => HttpTestClient;
|
|
74
74
|
}) => void;
|
|
75
75
|
//#endregion
|
|
76
|
+
//#region src/sqlRowsExamined.d.ts
|
|
77
|
+
/**
|
|
78
|
+
* Rows a SQL database examined for the reads a database adapter made: what
|
|
79
|
+
* read-budget suites compare with the rows the adapter read.
|
|
80
|
+
*/
|
|
81
|
+
interface RowsExamined {
|
|
82
|
+
/** Counts the reads from now on, and only those. */
|
|
83
|
+
reset(): void;
|
|
84
|
+
/** Rows examined for the reads since `reset`. */
|
|
85
|
+
total(): Promise<number>;
|
|
86
|
+
/** Rows the backend examines natively for each row it returns (default 1). */
|
|
87
|
+
readonly perRow?: number;
|
|
88
|
+
/** Rows the backend examines natively for each read beyond those (default 0). */
|
|
89
|
+
readonly perRead?: number;
|
|
90
|
+
}
|
|
91
|
+
/** A statement as the SQL core runs it. */
|
|
92
|
+
interface SqlStatementLike {
|
|
93
|
+
readonly sql: string;
|
|
94
|
+
readonly params: readonly unknown[];
|
|
95
|
+
}
|
|
96
|
+
/** A SQL core executor: its top-level `execute` runs the adapter's reads. */
|
|
97
|
+
interface SqlExecutorLike {
|
|
98
|
+
execute(statement: SqlStatementLike): Promise<unknown>;
|
|
99
|
+
}
|
|
100
|
+
/** Runs one statement on the session reads are explained on. */
|
|
101
|
+
type SqlQuery = (sql: string, params: readonly unknown[]) => Promise<readonly Record<string, unknown>[]>;
|
|
102
|
+
/**
|
|
103
|
+
* Rows examined on PostgreSQL (PGlite or a server). Each SELECT a wrapped
|
|
104
|
+
* executor runs is first run under `EXPLAIN (ANALYZE, FORMAT JSON)` on
|
|
105
|
+
* `query`, one session with the planner settings above; each `reset` first
|
|
106
|
+
* vacuums and analyzes, as autovacuum keeps a production database. A plan
|
|
107
|
+
* then takes the index path a production-sized table takes, and a read no
|
|
108
|
+
* index serves still scans. A statement counts the rows its busiest table
|
|
109
|
+
* read examined, so an exact plan counts the rows it returns, a multi-valued
|
|
110
|
+
* index's own table included.
|
|
111
|
+
*/
|
|
112
|
+
declare const postgresRowsExamined: (query: SqlQuery) => {
|
|
113
|
+
/** The executor, examining each SELECT it runs outside a transaction. */
|
|
114
|
+
wrap: <T extends SqlExecutorLike>(executor: T) => T;
|
|
115
|
+
examined: {
|
|
116
|
+
reset(): void;
|
|
117
|
+
total(): Promise<number>;
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Rows examined on MySQL. Each SELECT a wrapped executor runs is first run
|
|
122
|
+
* under `EXPLAIN ANALYZE` on `query`, one session, after `ANALYZE TABLE` of
|
|
123
|
+
* the tables it reads once per `reset`, and with multi-range reads always
|
|
124
|
+
* on, so a secondary index's range is costed with sorted row reads, as a
|
|
125
|
+
* production-sized table's is. A statement counts the rows its busiest table
|
|
126
|
+
* read examined; a filter above a table read drops rows that read produced.
|
|
127
|
+
*/
|
|
128
|
+
declare const mysqlRowsExamined: (query: SqlQuery) => {
|
|
129
|
+
/** The executor, examining each SELECT it runs outside a transaction. */
|
|
130
|
+
wrap: <T extends SqlExecutorLike>(executor: T) => T;
|
|
131
|
+
examined: {
|
|
132
|
+
reset(): void;
|
|
133
|
+
total(): Promise<number>;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/setupReadBudgetTestSuite.d.ts
|
|
138
|
+
interface ReadBudgetAdapterContext {
|
|
139
|
+
/**
|
|
140
|
+
* Core's tables, those of the plugins the suite measures, and the settings
|
|
141
|
+
* table, where the retention passes keep their lease.
|
|
142
|
+
*/
|
|
143
|
+
readonly tables: readonly PhysicalTable[];
|
|
144
|
+
/** Test-only: the adapter must fetch at most this many rows per native page. */
|
|
145
|
+
readonly nativePageSize: number;
|
|
146
|
+
}
|
|
147
|
+
interface ReadBudgetSuiteOptions {
|
|
148
|
+
readonly name: string;
|
|
149
|
+
/** Returns an adapter over freshly created, empty tables. */
|
|
150
|
+
readonly createAdapter: (context: ReadBudgetAdapterContext) => Promise<{
|
|
151
|
+
readonly adapter: DatabaseAdapter;
|
|
152
|
+
readonly cleanup?: () => Promise<void>;
|
|
153
|
+
/** SQL backends: the rows the database examined for the adapter's reads. */
|
|
154
|
+
readonly examined?: RowsExamined;
|
|
155
|
+
/**
|
|
156
|
+
* The rows each statement of the adapter's writes and prunes read, as D1
|
|
157
|
+
* bills them, since `reset`.
|
|
158
|
+
*/
|
|
159
|
+
readonly written?: {
|
|
160
|
+
reset(): void;
|
|
161
|
+
rows(): Promise<readonly number[]>;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Index reads return row copies without `_v`, as the key-value adapter's
|
|
165
|
+
* do, so a transaction reads the rows it guards again, whole.
|
|
166
|
+
*/
|
|
167
|
+
readonly indexCopies?: boolean;
|
|
168
|
+
}>;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The read-budget suite (PRD S4) on one backend: core and the server's
|
|
172
|
+
* built-in plugins on `createMeasuredDatabase` over the backend's adapter,
|
|
173
|
+
* native pages capped at two rows. Every API in the read-budget list reads
|
|
174
|
+
* exactly its budget at the adapter and at the engine; with `examined`, the
|
|
175
|
+
* database examines no more rows than the adapter read, within the backend's
|
|
176
|
+
* native multipliers. It loads `@hot-updater/server`, an optional peer.
|
|
177
|
+
*/
|
|
178
|
+
declare const setupReadBudgetTestSuite: (options: ReadBudgetSuiteOptions) => void;
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/setupReleaseLabelEngineTestSuite.d.ts
|
|
181
|
+
/** The backend under test, as `setupReadBudgetTestSuite` takes it. */
|
|
182
|
+
type ReleaseLabelEngineSuiteOptions = Pick<ReadBudgetSuiteOptions, "name" | "createAdapter">;
|
|
183
|
+
/**
|
|
184
|
+
* Release labels on a backend's own rows, which no HTTP API writes: the
|
|
185
|
+
* releases a server of an earlier release left without labels and without
|
|
186
|
+
* counters, which the fill labels per channel and platform in ID order,
|
|
187
|
+
* concurrent fills and a deploy included, rebuilding the catalogs compiled
|
|
188
|
+
* without them; and the label index, which refuses a second row with a label
|
|
189
|
+
* and holds any number without one. Rows are written as an earlier server
|
|
190
|
+
* wrote them through a second engine on the same adapter. Register it beside
|
|
191
|
+
* `setupReadBudgetTestSuite`, with the same options.
|
|
192
|
+
*/
|
|
193
|
+
declare const setupReleaseLabelEngineTestSuite: (options: ReleaseLabelEngineSuiteOptions) => void;
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region src/setupReleaseLabelTestSuite.d.ts
|
|
196
|
+
/**
|
|
197
|
+
* Release labels through a provider's admin and client HTTP APIs: deploys
|
|
198
|
+
* take each channel and platform's next label, concurrent ones never the
|
|
199
|
+
* same, a promotion takes the target's next, a delete leaves a gap, the
|
|
200
|
+
* list, detail and label lookup answer it, and the scope's catalog serves
|
|
201
|
+
* it. The backfill and the label index's uniqueness, which need rows an
|
|
202
|
+
* earlier server wrote, are `setupReleaseLabelEngineTestSuite`'s.
|
|
203
|
+
*/
|
|
204
|
+
declare const setupReleaseLabelTestSuite: (options: {
|
|
205
|
+
readonly getClient: () => HttpTestClient;
|
|
206
|
+
}) => void;
|
|
207
|
+
//#endregion
|
|
76
208
|
//#region src/setupSemverSatisfiesTestSuite.d.ts
|
|
77
209
|
/**
|
|
78
210
|
*
|
|
@@ -212,110 +344,6 @@ interface StorageAdapterTestSuiteOptions {
|
|
|
212
344
|
*/
|
|
213
345
|
declare const setupStorageAdapterTestSuite: (options: StorageAdapterTestSuiteOptions) => void;
|
|
214
346
|
//#endregion
|
|
215
|
-
//#region src/sqlRowsExamined.d.ts
|
|
216
|
-
/**
|
|
217
|
-
* Rows a SQL database examined for the reads a database adapter made: what
|
|
218
|
-
* read-budget suites compare with the rows the adapter read.
|
|
219
|
-
*/
|
|
220
|
-
interface RowsExamined {
|
|
221
|
-
/** Counts the reads from now on, and only those. */
|
|
222
|
-
reset(): void;
|
|
223
|
-
/** Rows examined for the reads since `reset`. */
|
|
224
|
-
total(): Promise<number>;
|
|
225
|
-
/** Rows the backend examines natively for each row it returns (default 1). */
|
|
226
|
-
readonly perRow?: number;
|
|
227
|
-
/** Rows the backend examines natively for each read beyond those (default 0). */
|
|
228
|
-
readonly perRead?: number;
|
|
229
|
-
}
|
|
230
|
-
/** A statement as the SQL core runs it. */
|
|
231
|
-
interface SqlStatementLike {
|
|
232
|
-
readonly sql: string;
|
|
233
|
-
readonly params: readonly unknown[];
|
|
234
|
-
}
|
|
235
|
-
/** A SQL core executor: its top-level `execute` runs the adapter's reads. */
|
|
236
|
-
interface SqlExecutorLike {
|
|
237
|
-
execute(statement: SqlStatementLike): Promise<unknown>;
|
|
238
|
-
}
|
|
239
|
-
/** Runs one statement on the session reads are explained on. */
|
|
240
|
-
type SqlQuery = (sql: string, params: readonly unknown[]) => Promise<readonly Record<string, unknown>[]>;
|
|
241
|
-
/**
|
|
242
|
-
* Rows examined on PostgreSQL (PGlite or a server). Each SELECT a wrapped
|
|
243
|
-
* executor runs is first run under `EXPLAIN (ANALYZE, FORMAT JSON)` on
|
|
244
|
-
* `query`, one session with the planner settings above; each `reset` first
|
|
245
|
-
* vacuums and analyzes, as autovacuum keeps a production database. A plan
|
|
246
|
-
* then takes the index path a production-sized table takes, and a read no
|
|
247
|
-
* index serves still scans. A statement counts the rows its busiest table
|
|
248
|
-
* read examined, so an exact plan counts the rows it returns, a multi-valued
|
|
249
|
-
* index's own table included.
|
|
250
|
-
*/
|
|
251
|
-
declare const postgresRowsExamined: (query: SqlQuery) => {
|
|
252
|
-
/** The executor, examining each SELECT it runs outside a transaction. */
|
|
253
|
-
wrap: <T extends SqlExecutorLike>(executor: T) => T;
|
|
254
|
-
examined: {
|
|
255
|
-
reset(): void;
|
|
256
|
-
total(): Promise<number>;
|
|
257
|
-
};
|
|
258
|
-
};
|
|
259
|
-
/**
|
|
260
|
-
* Rows examined on MySQL. Each SELECT a wrapped executor runs is first run
|
|
261
|
-
* under `EXPLAIN ANALYZE` on `query`, one session, after `ANALYZE TABLE` of
|
|
262
|
-
* the tables it reads once per `reset`, and with multi-range reads always
|
|
263
|
-
* on, so a secondary index's range is costed with sorted row reads, as a
|
|
264
|
-
* production-sized table's is. A statement counts the rows its busiest table
|
|
265
|
-
* read examined; a filter above a table read drops rows that read produced.
|
|
266
|
-
*/
|
|
267
|
-
declare const mysqlRowsExamined: (query: SqlQuery) => {
|
|
268
|
-
/** The executor, examining each SELECT it runs outside a transaction. */
|
|
269
|
-
wrap: <T extends SqlExecutorLike>(executor: T) => T;
|
|
270
|
-
examined: {
|
|
271
|
-
reset(): void;
|
|
272
|
-
total(): Promise<number>;
|
|
273
|
-
};
|
|
274
|
-
};
|
|
275
|
-
//#endregion
|
|
276
|
-
//#region src/setupReadBudgetTestSuite.d.ts
|
|
277
|
-
interface ReadBudgetAdapterContext {
|
|
278
|
-
/**
|
|
279
|
-
* Core's tables, those of the plugins the suite measures, and the settings
|
|
280
|
-
* table, where the retention passes keep their lease.
|
|
281
|
-
*/
|
|
282
|
-
readonly tables: readonly PhysicalTable[];
|
|
283
|
-
/** Test-only: the adapter must fetch at most this many rows per native page. */
|
|
284
|
-
readonly nativePageSize: number;
|
|
285
|
-
}
|
|
286
|
-
interface ReadBudgetSuiteOptions {
|
|
287
|
-
readonly name: string;
|
|
288
|
-
/** Returns an adapter over freshly created, empty tables. */
|
|
289
|
-
readonly createAdapter: (context: ReadBudgetAdapterContext) => Promise<{
|
|
290
|
-
readonly adapter: DatabaseAdapter;
|
|
291
|
-
readonly cleanup?: () => Promise<void>;
|
|
292
|
-
/** SQL backends: the rows the database examined for the adapter's reads. */
|
|
293
|
-
readonly examined?: RowsExamined;
|
|
294
|
-
/**
|
|
295
|
-
* The rows each statement of the adapter's writes and prunes read, as D1
|
|
296
|
-
* bills them, since `reset`.
|
|
297
|
-
*/
|
|
298
|
-
readonly written?: {
|
|
299
|
-
reset(): void;
|
|
300
|
-
rows(): Promise<readonly number[]>;
|
|
301
|
-
};
|
|
302
|
-
/**
|
|
303
|
-
* Index reads return row copies without `_v`, as the key-value adapter's
|
|
304
|
-
* do, so a transaction reads the rows it guards again, whole.
|
|
305
|
-
*/
|
|
306
|
-
readonly indexCopies?: boolean;
|
|
307
|
-
}>;
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* The read-budget suite (PRD S4) on one backend: core and the server's
|
|
311
|
-
* built-in plugins on `createMeasuredDatabase` over the backend's adapter,
|
|
312
|
-
* native pages capped at two rows. Every API in the read-budget list reads
|
|
313
|
-
* exactly its budget at the adapter and at the engine; with `examined`, the
|
|
314
|
-
* database examines no more rows than the adapter read, within the backend's
|
|
315
|
-
* native multipliers. It loads `@hot-updater/server`, an optional peer.
|
|
316
|
-
*/
|
|
317
|
-
declare const setupReadBudgetTestSuite: (options: ReadBudgetSuiteOptions) => void;
|
|
318
|
-
//#endregion
|
|
319
347
|
//#region src/setupAggregateBatchingTestSuite.d.ts
|
|
320
348
|
interface AggregateBatchingSuiteOptions {
|
|
321
349
|
readonly name: string;
|
|
@@ -546,4 +574,4 @@ declare const RELEASE_CATALOG_STORAGE_FIXTURES: Readonly<Record<string, string>>
|
|
|
546
574
|
/** Storage boundary shared by provider and separately spawned server tests. */
|
|
547
575
|
declare const createReleaseCatalogTestStorage: () => StorageAdapter;
|
|
548
576
|
//#endregion
|
|
549
|
-
export { AdminApiTestClient, AggregateBatchingSuiteOptions, ContentionOptions, ContentionReport, DatabaseAdapterConformanceContext, DatabaseAdapterConformanceOptions, DatabasePluginTestSuite, type DatabaseTestLifecycle, DatabaseTestSuiteOptions, HttpTestClient, HttpTestHandlers, HttpTestRequest, HttpTestRequestInit, HttpTestServer, MeasuredDatabase, MeasuredDatabaseOptions, MeasuredDatabaseStorage, MemoryKeyValueStoreOptions, PluginTestHarnessOptions, RELEASE_CATALOG_DOWNLOAD_HASH, RELEASE_CATALOG_MANIFEST_URIS, RELEASE_CATALOG_STORAGE_FIXTURES, ReadBudgetAdapterContext, ReadBudgetSuiteOptions, RowsExamined, SqlExecutorLike, SqlQuery, SqlStatementLike, StorageAdapterTestSuiteOptions, conformanceCounters, conformanceExpiring, conformanceItems, createAdminApiTestClient, createBundleEventRowFixture, createBundleFixture, createBundlePatchRowFixture, createBundleRowFixture, createChannelRowFixture, createHandlerHttpTestClient, createHttpTestClient, createMeasuredDatabase, createMemoryKeyValueStore, createPluginTestHarness, createReleaseCatalogTestStorage, createReleaseRowFixture, expectInsightsIndex, insightsTestSuite, jsonRequest, mysqlRowsExamined, postgresRowsExamined, releaseCatalogArtifact, releaseCatalogArtifactFiles, releaseCatalogDownloadUrl, runContentionHarness, setupAggregateBatchingTestSuite, setupBundleMethodsTestSuite, setupCoreAdminTestSuite, setupDatabaseAdapterConformanceSuite, setupDatabaseTestSuite, setupInsightsHttpTestSuite, setupInsightsModelTestSuite, setupReadBudgetTestSuite, setupReleaseCatalogTestSuite, setupSemverSatisfiesTestSuite, setupStorageAdapterTestSuite, startHttpTestServer, storeBundles, toDeployBundle, withAdapterLatency };
|
|
577
|
+
export { AdminApiTestClient, AggregateBatchingSuiteOptions, ContentionOptions, ContentionReport, DatabaseAdapterConformanceContext, DatabaseAdapterConformanceOptions, DatabasePluginTestSuite, type DatabaseTestLifecycle, DatabaseTestSuiteOptions, HttpTestClient, HttpTestHandlers, HttpTestRequest, HttpTestRequestInit, HttpTestServer, 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, createChannelRowFixture, createHandlerHttpTestClient, createHttpTestClient, createMeasuredDatabase, createMemoryKeyValueStore, createPluginTestHarness, createReleaseCatalogTestStorage, createReleaseRowFixture, expectInsightsIndex, 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 };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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
3
|
import { NIL_UUID, createReleaseCatalogScopeKey, encodeChannelKey, selectDesiredRelease } from "@hot-updater/protocol";
|
|
3
|
-
import { DATABASE_VERSION_COLUMN, DatabaseAdapterContractError, 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";
|
|
4
4
|
import { createServer } from "node:http";
|
|
5
5
|
//#region src/adminApiTestClient.ts
|
|
6
6
|
const jsonRequest = (method, body) => ({
|
|
@@ -128,7 +128,8 @@ const createReleaseRowFixture = (suffix, bundle, channel) => ({
|
|
|
128
128
|
source_release_id: null,
|
|
129
129
|
revision: 1,
|
|
130
130
|
created_at_ms: Number(suffix),
|
|
131
|
-
updated_at_ms: Number(suffix)
|
|
131
|
+
updated_at_ms: Number(suffix),
|
|
132
|
+
label: null
|
|
132
133
|
});
|
|
133
134
|
const createBundleFixture = (suffix, _channel = "production") => ({
|
|
134
135
|
id: fixtureId$1(suffix),
|
|
@@ -969,6 +970,338 @@ const setupCoreAdminTestSuite = (options) => {
|
|
|
969
970
|
});
|
|
970
971
|
};
|
|
971
972
|
//#endregion
|
|
973
|
+
//#region src/createMeasuredDatabase.ts
|
|
974
|
+
const storageOf = (storage) => ({
|
|
975
|
+
name: "measuredStorage",
|
|
976
|
+
protocol: "storage",
|
|
977
|
+
get: async ({ storageUri }) => {
|
|
978
|
+
const text = await storage.readStorageText?.(storageUri) ?? null;
|
|
979
|
+
return { response: text === null ? null : new Response(text) };
|
|
980
|
+
},
|
|
981
|
+
getDownloadUrl: async ({ storageUri }) => ({ url: await storage.resolveFileUrl(storageUri) })
|
|
982
|
+
});
|
|
983
|
+
/**
|
|
984
|
+
* Core and the plugins over `adapter` as `createHotUpdater` runs them: what
|
|
985
|
+
* read-budget suites measure. The database is `meterReads` over
|
|
986
|
+
* `verifyAdapter(adapter)`, so every adapter call is checked against the
|
|
987
|
+
* contract and `measureReads` reports each call's reads; the adapter runs
|
|
988
|
+
* as given, without the schema fence. It loads `@hot-updater/server`, an
|
|
989
|
+
* optional peer, when called.
|
|
990
|
+
*/
|
|
991
|
+
const createMeasuredDatabase = async (adapter, plugins, options = {}) => {
|
|
992
|
+
const { createHotUpdater } = await import("@hot-updater/server");
|
|
993
|
+
let clientAuth;
|
|
994
|
+
const observed = plugins.map((plugin) => Object.defineProperties({}, {
|
|
995
|
+
...Object.getOwnPropertyDescriptors(plugin),
|
|
996
|
+
init: {
|
|
997
|
+
configurable: true,
|
|
998
|
+
enumerable: true,
|
|
999
|
+
writable: true,
|
|
1000
|
+
value: (context) => {
|
|
1001
|
+
const instance = plugin.init(options.now === void 0 ? context : {
|
|
1002
|
+
...context,
|
|
1003
|
+
now: options.now
|
|
1004
|
+
});
|
|
1005
|
+
if (instance.clientAuth !== void 0) clientAuth = instance.clientAuth;
|
|
1006
|
+
return instance;
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
}));
|
|
1010
|
+
const database = meterReads({
|
|
1011
|
+
name: "measured",
|
|
1012
|
+
adapter: verifyAdapter(adapter)
|
|
1013
|
+
});
|
|
1014
|
+
const hotUpdater = createHotUpdater({
|
|
1015
|
+
database,
|
|
1016
|
+
storage: options.storage === void 0 ? {
|
|
1017
|
+
name: "measuredStorage",
|
|
1018
|
+
protocol: "none"
|
|
1019
|
+
} : storageOf(options.storage),
|
|
1020
|
+
plugins: observed,
|
|
1021
|
+
...plugins.some((plugin) => plugin.provides?.clientAuth === true) ? {} : { clientAccess: "public" }
|
|
1022
|
+
});
|
|
1023
|
+
return {
|
|
1024
|
+
core: hotUpdater.core,
|
|
1025
|
+
api: hotUpdater.api,
|
|
1026
|
+
...clientAuth === void 0 ? {} : { clientAuth },
|
|
1027
|
+
measureReads: database.measureReads
|
|
1028
|
+
};
|
|
1029
|
+
};
|
|
1030
|
+
//#endregion
|
|
1031
|
+
//#region src/setupReleaseLabelEngineTestSuite.ts
|
|
1032
|
+
const NATIVE_PAGE_SIZE$1 = 2;
|
|
1033
|
+
/**
|
|
1034
|
+
* Release labels on a backend's own rows, which no HTTP API writes: the
|
|
1035
|
+
* releases a server of an earlier release left without labels and without
|
|
1036
|
+
* counters, which the fill labels per channel and platform in ID order,
|
|
1037
|
+
* concurrent fills and a deploy included, rebuilding the catalogs compiled
|
|
1038
|
+
* without them; and the label index, which refuses a second row with a label
|
|
1039
|
+
* and holds any number without one. Rows are written as an earlier server
|
|
1040
|
+
* wrote them through a second engine on the same adapter. Register it beside
|
|
1041
|
+
* `setupReadBudgetTestSuite`, with the same options.
|
|
1042
|
+
*/
|
|
1043
|
+
const setupReleaseLabelEngineTestSuite = (options) => {
|
|
1044
|
+
describe(`${options.name} release labels`, () => {
|
|
1045
|
+
let created;
|
|
1046
|
+
let core;
|
|
1047
|
+
let raw;
|
|
1048
|
+
beforeAll(async () => {
|
|
1049
|
+
created = await options.createAdapter({
|
|
1050
|
+
tables: [...toolingTargetOf([]).schema.tables, SETTINGS_TABLE],
|
|
1051
|
+
nativePageSize: NATIVE_PAGE_SIZE$1
|
|
1052
|
+
});
|
|
1053
|
+
({core} = await createMeasuredDatabase(created.adapter, []));
|
|
1054
|
+
raw = createEngine({
|
|
1055
|
+
name: "raw",
|
|
1056
|
+
adapter: created.adapter
|
|
1057
|
+
}).core;
|
|
1058
|
+
}, 18e4);
|
|
1059
|
+
afterAll(async () => {
|
|
1060
|
+
await created?.cleanup?.();
|
|
1061
|
+
}, 6e4);
|
|
1062
|
+
let suffix = 0;
|
|
1063
|
+
let namespace = 0;
|
|
1064
|
+
const channel = (name) => `${name}-${namespace}`;
|
|
1065
|
+
const deploy = async (name, { platform = "ios", fingerprintHash = null } = {}) => {
|
|
1066
|
+
suffix += 1;
|
|
1067
|
+
const deployment = {
|
|
1068
|
+
bundle: {
|
|
1069
|
+
...createBundleFixture(String(9e3 + suffix)),
|
|
1070
|
+
platform
|
|
1071
|
+
},
|
|
1072
|
+
release: {
|
|
1073
|
+
channel: channel(name),
|
|
1074
|
+
enabled: true,
|
|
1075
|
+
fingerprintHash,
|
|
1076
|
+
message: null,
|
|
1077
|
+
shouldForceUpdate: false,
|
|
1078
|
+
targetAppVersion: fingerprintHash === null ? "1.0.x" : null
|
|
1079
|
+
}
|
|
1080
|
+
};
|
|
1081
|
+
const [result] = await core.deploy([deployment]);
|
|
1082
|
+
return result.release;
|
|
1083
|
+
};
|
|
1084
|
+
/** Takes the labels off `releases` and drops their pairs' counters, as an earlier server left them. */
|
|
1085
|
+
const asBeforeLabels = async (releases) => {
|
|
1086
|
+
await raw.transaction(async (tx) => {
|
|
1087
|
+
const counters = /* @__PURE__ */ new Set();
|
|
1088
|
+
for (const { id } of releases) {
|
|
1089
|
+
const row = await tx.findOne("releases", { id });
|
|
1090
|
+
tx.update("releases", row, { label: null });
|
|
1091
|
+
counters.add(`releases/${row.platform}/${row.channel_id}`);
|
|
1092
|
+
}
|
|
1093
|
+
for (const id of counters) {
|
|
1094
|
+
const counter = await tx.findOne("label_sequences", { id });
|
|
1095
|
+
if (counter !== null) await tx.delete("label_sequences", counter);
|
|
1096
|
+
}
|
|
1097
|
+
});
|
|
1098
|
+
};
|
|
1099
|
+
const labelOf = async (id) => (await core.getRelease(id))?.label;
|
|
1100
|
+
it("labels releases an earlier server wrote in ID order per channel and platform, rebuilds their catalogs, and a deploy then takes the next", async () => {
|
|
1101
|
+
namespace += 1;
|
|
1102
|
+
const releases = [
|
|
1103
|
+
await deploy("fill"),
|
|
1104
|
+
await deploy("fill", { fingerprintHash: "fp-a" }),
|
|
1105
|
+
await deploy("fill"),
|
|
1106
|
+
await deploy("fill", { platform: "android" }),
|
|
1107
|
+
await deploy("fill", { fingerprintHash: "fp-b" })
|
|
1108
|
+
];
|
|
1109
|
+
await asBeforeLabels(releases);
|
|
1110
|
+
for (const scope of new Set(releases.map((row) => row.scope_key))) await core.rebuildReleaseCatalog(scope);
|
|
1111
|
+
await expect(core.fillReleaseLabels({ dryRun: true })).resolves.toEqual({
|
|
1112
|
+
releases: 5,
|
|
1113
|
+
catalogs: 0
|
|
1114
|
+
});
|
|
1115
|
+
await expect(core.fillReleaseLabels()).resolves.toEqual({
|
|
1116
|
+
releases: 5,
|
|
1117
|
+
catalogs: 4
|
|
1118
|
+
});
|
|
1119
|
+
const inIdOrder = (rows) => rows.map(({ id }) => id).sort();
|
|
1120
|
+
const ios = inIdOrder(releases.filter(({ platform }) => platform === "ios"));
|
|
1121
|
+
const labels = {};
|
|
1122
|
+
for (const { id } of releases) labels[id] = await labelOf(id);
|
|
1123
|
+
expect(labels).toEqual({
|
|
1124
|
+
...Object.fromEntries(ios.map((id, index) => [id, index + 1])),
|
|
1125
|
+
[releases[3].id]: 1
|
|
1126
|
+
});
|
|
1127
|
+
const served = JSON.parse((await core.getReleaseCatalogRow(releases[0].scope_key)).payload).releaseDescriptors;
|
|
1128
|
+
expect(Object.fromEntries(served.map(({ releaseId, label }) => [releaseId, label]))).toEqual({
|
|
1129
|
+
[releases[0].id]: labels[releases[0].id],
|
|
1130
|
+
[releases[2].id]: labels[releases[2].id]
|
|
1131
|
+
});
|
|
1132
|
+
await expect(core.fillReleaseLabels({ dryRun: true })).resolves.toEqual({
|
|
1133
|
+
releases: 0,
|
|
1134
|
+
catalogs: 0
|
|
1135
|
+
});
|
|
1136
|
+
await expect(deploy("fill")).resolves.toMatchObject({ label: 5 });
|
|
1137
|
+
});
|
|
1138
|
+
it("labels each release once when fills run beside a deploy that needs one", async () => {
|
|
1139
|
+
namespace += 1;
|
|
1140
|
+
const releases = [];
|
|
1141
|
+
for (let index = 0; index < 5; index += 1) releases.push(await deploy("race"));
|
|
1142
|
+
await asBeforeLabels(releases);
|
|
1143
|
+
const [, , deployed] = await Promise.all([
|
|
1144
|
+
core.fillReleaseLabels(),
|
|
1145
|
+
core.fillReleaseLabels(),
|
|
1146
|
+
deploy("race")
|
|
1147
|
+
]);
|
|
1148
|
+
const labels = {};
|
|
1149
|
+
for (const { id } of releases) labels[id] = await labelOf(id);
|
|
1150
|
+
expect(labels).toEqual(Object.fromEntries(releases.map(({ id }) => id).sort().map((id, index) => [id, index + 1])));
|
|
1151
|
+
expect(deployed.label).toBe(6);
|
|
1152
|
+
});
|
|
1153
|
+
it("refuses a second release with a label in its channel and platform, and holds any number without one", async () => {
|
|
1154
|
+
namespace += 1;
|
|
1155
|
+
const releases = [
|
|
1156
|
+
await deploy("unique"),
|
|
1157
|
+
await deploy("unique"),
|
|
1158
|
+
await deploy("unique")
|
|
1159
|
+
];
|
|
1160
|
+
const set = (id, label) => raw.transaction(async (tx) => {
|
|
1161
|
+
const row = await tx.findOne("releases", { id });
|
|
1162
|
+
tx.update("releases", row, { label });
|
|
1163
|
+
});
|
|
1164
|
+
await set(releases[0].id, null);
|
|
1165
|
+
await set(releases[1].id, null);
|
|
1166
|
+
await expect(set(releases[2].id, 2)).resolves.toBeUndefined();
|
|
1167
|
+
await expect(set(releases[0].id, 2)).rejects.toBeInstanceOf(DatabaseConstraintError);
|
|
1168
|
+
const other = await deploy("unique-other");
|
|
1169
|
+
expect(other.label).toBe(1);
|
|
1170
|
+
await expect(set(other.id, 2)).resolves.toBeUndefined();
|
|
1171
|
+
await set(other.id, 1);
|
|
1172
|
+
await set(releases[2].id, 3);
|
|
1173
|
+
await set(releases[1].id, 2);
|
|
1174
|
+
await set(releases[0].id, 1);
|
|
1175
|
+
await expect(core.getReleaseByLabel({
|
|
1176
|
+
channel: channel("unique"),
|
|
1177
|
+
platform: "ios",
|
|
1178
|
+
label: 3
|
|
1179
|
+
})).resolves.toMatchObject({ id: releases[2].id });
|
|
1180
|
+
});
|
|
1181
|
+
});
|
|
1182
|
+
};
|
|
1183
|
+
//#endregion
|
|
1184
|
+
//#region src/setupReleaseLabelTestSuite.ts
|
|
1185
|
+
/**
|
|
1186
|
+
* Release labels through a provider's admin and client HTTP APIs: deploys
|
|
1187
|
+
* take each channel and platform's next label, concurrent ones never the
|
|
1188
|
+
* same, a promotion takes the target's next, a delete leaves a gap, the
|
|
1189
|
+
* list, detail and label lookup answer it, and the scope's catalog serves
|
|
1190
|
+
* it. The backfill and the label index's uniqueness, which need rows an
|
|
1191
|
+
* earlier server wrote, are `setupReleaseLabelEngineTestSuite`'s.
|
|
1192
|
+
*/
|
|
1193
|
+
const setupReleaseLabelTestSuite = (options) => {
|
|
1194
|
+
describe("Release labels", () => {
|
|
1195
|
+
const api = createAdminApiTestClient(options.getClient);
|
|
1196
|
+
const { adminJson } = api;
|
|
1197
|
+
let namespace;
|
|
1198
|
+
beforeEach(() => {
|
|
1199
|
+
namespace = crypto.randomUUID();
|
|
1200
|
+
});
|
|
1201
|
+
afterEach(async () => {
|
|
1202
|
+
await api.cleanup();
|
|
1203
|
+
});
|
|
1204
|
+
const bundleRow = (suffix) => ({
|
|
1205
|
+
...createBundleRowFixture(suffix),
|
|
1206
|
+
id: `${namespace.slice(0, 8)}-0000-7000-8000-${suffix.padStart(12, "0")}`
|
|
1207
|
+
});
|
|
1208
|
+
const channel = (name = "labels") => `${name}-${namespace}`;
|
|
1209
|
+
const deploy = (suffix, { fingerprintHash = null, platform = "ios", channelName = channel() } = {}) => api.deploy({
|
|
1210
|
+
bundle: {
|
|
1211
|
+
...toDeployBundle(bundleRow(suffix)),
|
|
1212
|
+
platform
|
|
1213
|
+
},
|
|
1214
|
+
release: {
|
|
1215
|
+
channel: channelName,
|
|
1216
|
+
enabled: true,
|
|
1217
|
+
fingerprintHash,
|
|
1218
|
+
message: null,
|
|
1219
|
+
shouldForceUpdate: false,
|
|
1220
|
+
targetAppVersion: fingerprintHash === null ? "1.0.x" : null
|
|
1221
|
+
}
|
|
1222
|
+
});
|
|
1223
|
+
const byLabel = async (label, { platform = "ios", channelName = channel() } = {}) => (await adminJson(`/release-labels?channel=${encodeURIComponent(channelName)}&platform=${platform}&label=${label}`)).data;
|
|
1224
|
+
const detail = async (id) => (await adminJson(`/releases/${encodeURIComponent(id)}`)).data;
|
|
1225
|
+
it("labels each channel and platform's deploys in order, and answers the label in the list, the detail and the lookup", async () => {
|
|
1226
|
+
const first = await deploy("1");
|
|
1227
|
+
const second = await deploy("2");
|
|
1228
|
+
const android = await deploy("3", { platform: "android" });
|
|
1229
|
+
expect([
|
|
1230
|
+
first.label,
|
|
1231
|
+
second.label,
|
|
1232
|
+
android.label
|
|
1233
|
+
]).toEqual([
|
|
1234
|
+
1,
|
|
1235
|
+
2,
|
|
1236
|
+
1
|
|
1237
|
+
]);
|
|
1238
|
+
const { data: listed } = await adminJson(`/releases?channelId=${encodeURIComponent(first.channel_id)}&platform=ios&limit=10`);
|
|
1239
|
+
expect(Object.fromEntries(listed.map(({ id, label }) => [id, label]))).toEqual({
|
|
1240
|
+
[first.id]: 1,
|
|
1241
|
+
[second.id]: 2
|
|
1242
|
+
});
|
|
1243
|
+
await expect(detail(second.id)).resolves.toMatchObject({ label: 2 });
|
|
1244
|
+
await expect(byLabel(2)).resolves.toMatchObject({
|
|
1245
|
+
id: second.id,
|
|
1246
|
+
label: 2
|
|
1247
|
+
});
|
|
1248
|
+
await expect(byLabel(1, { platform: "android" })).resolves.toMatchObject({ id: android.id });
|
|
1249
|
+
await expect(byLabel(3)).resolves.toBeNull();
|
|
1250
|
+
});
|
|
1251
|
+
it("never gives concurrent deploys one label", async () => {
|
|
1252
|
+
await deploy("10");
|
|
1253
|
+
const releases = await Promise.all([
|
|
1254
|
+
"11",
|
|
1255
|
+
"12",
|
|
1256
|
+
"13",
|
|
1257
|
+
"14"
|
|
1258
|
+
].map((suffix) => deploy(suffix, { fingerprintHash: `fingerprint-${suffix}` })));
|
|
1259
|
+
expect(releases.map(({ label }) => label).sort()).toEqual([
|
|
1260
|
+
2,
|
|
1261
|
+
3,
|
|
1262
|
+
4,
|
|
1263
|
+
5
|
|
1264
|
+
]);
|
|
1265
|
+
});
|
|
1266
|
+
it("keeps a label through disable and enable, leaves a gap on delete, and gives a promotion the target's next label", async () => {
|
|
1267
|
+
const first = await deploy("21");
|
|
1268
|
+
const second = await deploy("22");
|
|
1269
|
+
await adminJson(`/releases/${encodeURIComponent(first.id)}`, jsonRequest("PATCH", { patch: { enabled: false } }));
|
|
1270
|
+
await adminJson(`/releases/${encodeURIComponent(first.id)}`, jsonRequest("PATCH", { patch: { enabled: true } }));
|
|
1271
|
+
await expect(detail(first.id)).resolves.toMatchObject({ label: 1 });
|
|
1272
|
+
await api.removeRelease(second.id);
|
|
1273
|
+
api.forget(second.id);
|
|
1274
|
+
await expect(deploy("23")).resolves.toMatchObject({ label: 3 });
|
|
1275
|
+
await deploy("24", { channelName: channel("target") });
|
|
1276
|
+
const { data: promoted } = await adminJson(`/releases/${encodeURIComponent(first.id)}/promote`, jsonRequest("POST", {
|
|
1277
|
+
targetChannel: channel("target"),
|
|
1278
|
+
action: "copy"
|
|
1279
|
+
}));
|
|
1280
|
+
api.track(promoted.target.release.id);
|
|
1281
|
+
expect(promoted.target.release).toMatchObject({ label: 2 });
|
|
1282
|
+
await expect(detail(first.id)).resolves.toMatchObject({ label: 1 });
|
|
1283
|
+
});
|
|
1284
|
+
it("serves each release's label in its scope's catalog", async () => {
|
|
1285
|
+
const first = await deploy("31");
|
|
1286
|
+
const second = await deploy("32");
|
|
1287
|
+
const response = await options.getClient().client(`/release-catalogs/app-version/ios/${encodeChannelKey(channel())}/1.0.0`);
|
|
1288
|
+
expect(response.status).toBe(200);
|
|
1289
|
+
const catalog = await response.json();
|
|
1290
|
+
expect(Object.fromEntries(catalog.releases.map(({ releaseId, label }) => [releaseId, label]))).toEqual({
|
|
1291
|
+
[first.id]: 1,
|
|
1292
|
+
[second.id]: 2
|
|
1293
|
+
});
|
|
1294
|
+
});
|
|
1295
|
+
it("has nothing to fill on a database whose releases all have labels", async () => {
|
|
1296
|
+
await deploy("41");
|
|
1297
|
+
await expect(adminJson("/release-labels/fill", jsonRequest("POST", { dryRun: true }))).resolves.toEqual({ data: {
|
|
1298
|
+
releases: 0,
|
|
1299
|
+
catalogs: 0
|
|
1300
|
+
} });
|
|
1301
|
+
});
|
|
1302
|
+
});
|
|
1303
|
+
};
|
|
1304
|
+
//#endregion
|
|
972
1305
|
//#region src/setupSemverSatisfiesTestSuite.ts
|
|
973
1306
|
/**
|
|
974
1307
|
*
|
|
@@ -1974,6 +2307,7 @@ const setupDatabaseTestSuite = (options) => {
|
|
|
1974
2307
|
setupCoreAdminTestSuite({ getClient });
|
|
1975
2308
|
setupBundleMethodsTestSuite({ getClient });
|
|
1976
2309
|
setupReleaseCatalogTestSuite({ getClient });
|
|
2310
|
+
setupReleaseLabelTestSuite({ getClient });
|
|
1977
2311
|
for (const suite of options.plugins ?? []) describe(suite.name, () => {
|
|
1978
2312
|
suite.register({
|
|
1979
2313
|
getClient,
|
|
@@ -3443,64 +3777,6 @@ const setupStorageAdapterTestSuite = (options) => {
|
|
|
3443
3777
|
});
|
|
3444
3778
|
};
|
|
3445
3779
|
//#endregion
|
|
3446
|
-
//#region src/createMeasuredDatabase.ts
|
|
3447
|
-
const storageOf = (storage) => ({
|
|
3448
|
-
name: "measuredStorage",
|
|
3449
|
-
protocol: "storage",
|
|
3450
|
-
get: async ({ storageUri }) => {
|
|
3451
|
-
const text = await storage.readStorageText?.(storageUri) ?? null;
|
|
3452
|
-
return { response: text === null ? null : new Response(text) };
|
|
3453
|
-
},
|
|
3454
|
-
getDownloadUrl: async ({ storageUri }) => ({ url: await storage.resolveFileUrl(storageUri) })
|
|
3455
|
-
});
|
|
3456
|
-
/**
|
|
3457
|
-
* Core and the plugins over `adapter` as `createHotUpdater` runs them: what
|
|
3458
|
-
* read-budget suites measure. The database is `meterReads` over
|
|
3459
|
-
* `verifyAdapter(adapter)`, so every adapter call is checked against the
|
|
3460
|
-
* contract and `measureReads` reports each call's reads; the adapter runs
|
|
3461
|
-
* as given, without the schema fence. It loads `@hot-updater/server`, an
|
|
3462
|
-
* optional peer, when called.
|
|
3463
|
-
*/
|
|
3464
|
-
const createMeasuredDatabase = async (adapter, plugins, options = {}) => {
|
|
3465
|
-
const { createHotUpdater } = await import("@hot-updater/server");
|
|
3466
|
-
let clientAuth;
|
|
3467
|
-
const observed = plugins.map((plugin) => Object.defineProperties({}, {
|
|
3468
|
-
...Object.getOwnPropertyDescriptors(plugin),
|
|
3469
|
-
init: {
|
|
3470
|
-
configurable: true,
|
|
3471
|
-
enumerable: true,
|
|
3472
|
-
writable: true,
|
|
3473
|
-
value: (context) => {
|
|
3474
|
-
const instance = plugin.init(options.now === void 0 ? context : {
|
|
3475
|
-
...context,
|
|
3476
|
-
now: options.now
|
|
3477
|
-
});
|
|
3478
|
-
if (instance.clientAuth !== void 0) clientAuth = instance.clientAuth;
|
|
3479
|
-
return instance;
|
|
3480
|
-
}
|
|
3481
|
-
}
|
|
3482
|
-
}));
|
|
3483
|
-
const database = meterReads({
|
|
3484
|
-
name: "measured",
|
|
3485
|
-
adapter: verifyAdapter(adapter)
|
|
3486
|
-
});
|
|
3487
|
-
const hotUpdater = createHotUpdater({
|
|
3488
|
-
database,
|
|
3489
|
-
storage: options.storage === void 0 ? {
|
|
3490
|
-
name: "measuredStorage",
|
|
3491
|
-
protocol: "none"
|
|
3492
|
-
} : storageOf(options.storage),
|
|
3493
|
-
plugins: observed,
|
|
3494
|
-
...plugins.some((plugin) => plugin.provides?.clientAuth === true) ? {} : { clientAccess: "public" }
|
|
3495
|
-
});
|
|
3496
|
-
return {
|
|
3497
|
-
core: hotUpdater.core,
|
|
3498
|
-
api: hotUpdater.api,
|
|
3499
|
-
...clientAuth === void 0 ? {} : { clientAuth },
|
|
3500
|
-
measureReads: database.measureReads
|
|
3501
|
-
};
|
|
3502
|
-
};
|
|
3503
|
-
//#endregion
|
|
3504
3780
|
//#region src/setupReadBudgetTestSuite.ts
|
|
3505
3781
|
/** A published template: a greeting that beta devices get another value of. */
|
|
3506
3782
|
const remoteConfigTemplate = (greeting) => ({
|
|
@@ -4571,13 +4847,27 @@ const READ_BUDGETS = [
|
|
|
4571
4847
|
bundle: bundleOf("107"),
|
|
4572
4848
|
release: production
|
|
4573
4849
|
}]),
|
|
4574
|
-
adapter: (copies) => reads(copies ?
|
|
4850
|
+
adapter: (copies) => reads(copies ? 6 : 4, copies ? 9 : 4, 3, 6),
|
|
4575
4851
|
engine: {
|
|
4576
|
-
calls:
|
|
4577
|
-
rows:
|
|
4852
|
+
calls: 7,
|
|
4853
|
+
rows: 10
|
|
4578
4854
|
},
|
|
4579
4855
|
writes: 1
|
|
4580
4856
|
}),
|
|
4857
|
+
budget({
|
|
4858
|
+
api: "release by label: its unique index, then the release",
|
|
4859
|
+
read: ({ core }) => core.getReleaseByLabel({
|
|
4860
|
+
channel: "production",
|
|
4861
|
+
platform: "ios",
|
|
4862
|
+
label: 2
|
|
4863
|
+
}),
|
|
4864
|
+
adapter: reads(1, 1, 1, 1),
|
|
4865
|
+
engine: {
|
|
4866
|
+
calls: 2,
|
|
4867
|
+
rows: 2
|
|
4868
|
+
},
|
|
4869
|
+
check: (release) => expect(release).toMatchObject({ label: 2 })
|
|
4870
|
+
}),
|
|
4581
4871
|
budget({
|
|
4582
4872
|
api: "channel insert: 1 write, after the name's read finds nothing",
|
|
4583
4873
|
read: ({ core }) => core.ensureChannel("read-budgets"),
|
|
@@ -4589,11 +4879,11 @@ const READ_BUDGETS = [
|
|
|
4589
4879
|
writes: 1
|
|
4590
4880
|
}),
|
|
4591
4881
|
budget({
|
|
4592
|
-
api: "channel delete: the channel, its native builds under it, and 1 write",
|
|
4882
|
+
api: "channel delete: the channel, its native builds under it, its label counters, and 1 write",
|
|
4593
4883
|
read: ({ core, nightlyId }) => core.deleteChannel(nightlyId),
|
|
4594
|
-
adapter: reads(
|
|
4884
|
+
adapter: reads(4, 4, 1, 0),
|
|
4595
4885
|
engine: {
|
|
4596
|
-
calls:
|
|
4886
|
+
calls: 5,
|
|
4597
4887
|
rows: 2
|
|
4598
4888
|
},
|
|
4599
4889
|
writes: 1,
|
|
@@ -6771,4 +7061,4 @@ async function startHttpTestServer(handlers) {
|
|
|
6771
7061
|
};
|
|
6772
7062
|
}
|
|
6773
7063
|
//#endregion
|
|
6774
|
-
export { RELEASE_CATALOG_DOWNLOAD_HASH, RELEASE_CATALOG_MANIFEST_URIS, RELEASE_CATALOG_STORAGE_FIXTURES, conformanceCounters, conformanceExpiring, conformanceItems, createAdminApiTestClient, createBundleEventRowFixture, createBundleFixture, createBundlePatchRowFixture, createBundleRowFixture, createChannelRowFixture, createHandlerHttpTestClient, createHttpTestClient, createMeasuredDatabase, createMemoryKeyValueStore, createPluginTestHarness, createReleaseCatalogTestStorage, createReleaseRowFixture, expectInsightsIndex, insightsTestSuite, jsonRequest, mysqlRowsExamined, postgresRowsExamined, releaseCatalogArtifact, releaseCatalogArtifactFiles, releaseCatalogDownloadUrl, runContentionHarness, setupAggregateBatchingTestSuite, setupBundleMethodsTestSuite, setupCoreAdminTestSuite, setupDatabaseAdapterConformanceSuite, setupDatabaseTestSuite, setupInsightsHttpTestSuite, setupInsightsModelTestSuite, setupReadBudgetTestSuite, setupReleaseCatalogTestSuite, setupSemverSatisfiesTestSuite, setupStorageAdapterTestSuite, startHttpTestServer, storeBundles, toDeployBundle, withAdapterLatency };
|
|
7064
|
+
export { RELEASE_CATALOG_DOWNLOAD_HASH, RELEASE_CATALOG_MANIFEST_URIS, RELEASE_CATALOG_STORAGE_FIXTURES, conformanceCounters, conformanceExpiring, conformanceItems, createAdminApiTestClient, createBundleEventRowFixture, createBundleFixture, createBundlePatchRowFixture, createBundleRowFixture, createChannelRowFixture, createHandlerHttpTestClient, createHttpTestClient, createMeasuredDatabase, createMemoryKeyValueStore, createPluginTestHarness, createReleaseCatalogTestStorage, createReleaseRowFixture, expectInsightsIndex, 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 };
|
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.51",
|
|
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/
|
|
56
|
-
"@hot-updater/
|
|
53
|
+
"@hot-updater/plugin-insights": "^1.2.0-rc.51",
|
|
54
|
+
"@hot-updater/protocol": "^1.2.0-rc.51",
|
|
55
|
+
"@hot-updater/server": "^1.2.0-rc.51",
|
|
56
|
+
"@hot-updater/plugin-core": "^1.2.0-rc.51"
|
|
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/
|
|
88
|
-
"@hot-updater/plugin-
|
|
89
|
-
"@hot-updater/
|
|
90
|
-
"@hot-updater/server": "1.2.0-rc.
|
|
87
|
+
"@hot-updater/plugin-insights": "1.2.0-rc.51",
|
|
88
|
+
"@hot-updater/plugin-core": "1.2.0-rc.51",
|
|
89
|
+
"@hot-updater/protocol": "1.2.0-rc.51",
|
|
90
|
+
"@hot-updater/server": "1.2.0-rc.51"
|
|
91
91
|
},
|
|
92
92
|
"inlinedDependencies": {
|
|
93
93
|
"@clack/core": "1.4.3",
|