@hot-updater/test-utils 1.2.0-rc.5 → 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 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 three suites against a disposable test database:
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]>;
@@ -65,14 +65,146 @@ declare const setupBundleMethodsTestSuite: (options: {
65
65
  /**
66
66
  * Core's operations through admin API protocol 2 that the bundle and catalog
67
67
  * suites leave out: channels, deploy refusals, promotion, preflights, a
68
- * bundle's patch children, and the native build registry. Each test deletes
69
- * what it wrote, except a native build, which the registry keeps: its IDs
70
- * and channel are the test's own.
68
+ * bundle's patch children, the native build registry, and the iOS device
69
+ * registry. Each test deletes what it wrote, except a native build, which the
70
+ * registry keeps: its IDs and channel are the test's own.
71
71
  */
72
72
  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,102 +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
- * Index reads return row copies without `_v`, as the key-value adapter's
296
- * do, so a transaction reads the rows it guards again, whole.
297
- */
298
- readonly indexCopies?: boolean;
299
- }>;
300
- }
301
- /**
302
- * The read-budget suite (PRD S4) on one backend: core and the server's
303
- * built-in plugins on `createMeasuredDatabase` over the backend's adapter,
304
- * native pages capped at two rows. Every API in the read-budget list reads
305
- * exactly its budget at the adapter and at the engine; with `examined`, the
306
- * database examines no more rows than the adapter read, within the backend's
307
- * native multipliers. It loads `@hot-updater/server`, an optional peer.
308
- */
309
- declare const setupReadBudgetTestSuite: (options: ReadBudgetSuiteOptions) => void;
310
- //#endregion
311
347
  //#region src/setupAggregateBatchingTestSuite.d.ts
312
348
  interface AggregateBatchingSuiteOptions {
313
349
  readonly name: string;
@@ -321,8 +357,8 @@ interface AggregateBatchingSuiteOptions {
321
357
  }
322
358
  /**
323
359
  * Aggregates declared `batched` on a key-value store: log rows the store
324
- * writes with each transaction and a compaction merges once, and a memory
325
- * buffer, read back exactly as transactional writes read.
360
+ * writes with each transaction and a compaction merges once, read back
361
+ * exactly as transactional writes read.
326
362
  */
327
363
  declare const setupAggregateBatchingTestSuite: ({ name, createAdapter, oversizedRows }: AggregateBatchingSuiteOptions) => void;
328
364
  //#endregion
@@ -538,4 +574,4 @@ declare const RELEASE_CATALOG_STORAGE_FIXTURES: Readonly<Record<string, string>>
538
574
  /** Storage boundary shared by provider and separately spawned server tests. */
539
575
  declare const createReleaseCatalogTestStorage: () => StorageAdapter;
540
576
  //#endregion
541
- 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 };