@hot-updater/test-utils 1.2.0-rc.51 → 1.2.0-rc.53
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 +16 -4
- package/dist/index.mjs +86 -3
- package/package.json +9 -9
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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";
|
|
1
|
+
import { AnyHotUpdaterPlugin, BundlePatchRow, BundleRow, ChannelRow, ClientAuth, DatabaseAdapter, DeployReleasePolicy, EngineDatabase, HotUpdaterCoreApi, HotUpdaterDatabase, KeyValueStore, ModuleSchema, PhysicalTable, PluginApis, ReadMeasurement, ReleaseRow, StorageAdapter, StorageOperation, createEngine } from "@hot-updater/plugin-core";
|
|
2
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
|
|
@@ -52,6 +52,16 @@ declare const createAdminApiTestClient: (getClient: () => HttpTestClient) => {
|
|
|
52
52
|
};
|
|
53
53
|
type AdminApiTestClient = ReturnType<typeof createAdminApiTestClient>;
|
|
54
54
|
//#endregion
|
|
55
|
+
//#region src/catalogFromLaterRelease.d.ts
|
|
56
|
+
/** A field no release of Hot Updater compiles, as a later release may add one. */
|
|
57
|
+
declare const LATER_RELEASE_CATALOG_FIELD = "laterReleaseField";
|
|
58
|
+
/**
|
|
59
|
+
* Rewrites a scope's stored catalog as a later release would compile it: a
|
|
60
|
+
* field this release does not know on each release descriptor, with the
|
|
61
|
+
* payload's hash and size to match. Returns the payload it wrote.
|
|
62
|
+
*/
|
|
63
|
+
declare const writeCatalogFromLaterRelease: (core: ReturnType<typeof createEngine>["core"], scopeKey: string) => Promise<string>;
|
|
64
|
+
//#endregion
|
|
55
65
|
//#region src/setupBundleMethodsTestSuite.d.ts
|
|
56
66
|
/**
|
|
57
67
|
* Bundles through admin API protocol 2: deployed with a release, read by
|
|
@@ -187,8 +197,10 @@ type ReleaseLabelEngineSuiteOptions = Pick<ReadBudgetSuiteOptions, "name" | "cre
|
|
|
187
197
|
* concurrent fills and a deploy included, rebuilding the catalogs compiled
|
|
188
198
|
* without them; and the label index, which refuses a second row with a label
|
|
189
199
|
* and holds any number without one. Rows are written as an earlier server
|
|
190
|
-
* wrote them through a second engine on the same adapter.
|
|
191
|
-
*
|
|
200
|
+
* wrote them through a second engine on the same adapter. It also writes a
|
|
201
|
+
* catalog as a later release compiles it, with a field this one does not
|
|
202
|
+
* know, which core verifies, never rewrites, and refuses to change. Register
|
|
203
|
+
* it beside `setupReadBudgetTestSuite`, with the same options.
|
|
192
204
|
*/
|
|
193
205
|
declare const setupReleaseLabelEngineTestSuite: (options: ReleaseLabelEngineSuiteOptions) => void;
|
|
194
206
|
//#endregion
|
|
@@ -574,4 +586,4 @@ declare const RELEASE_CATALOG_STORAGE_FIXTURES: Readonly<Record<string, string>>
|
|
|
574
586
|
/** Storage boundary shared by provider and separately spawned server tests. */
|
|
575
587
|
declare const createReleaseCatalogTestStorage: () => StorageAdapter;
|
|
576
588
|
//#endregion
|
|
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 };
|
|
589
|
+
export { AdminApiTestClient, AggregateBatchingSuiteOptions, ContentionOptions, ContentionReport, DatabaseAdapterConformanceContext, DatabaseAdapterConformanceOptions, DatabasePluginTestSuite, type DatabaseTestLifecycle, DatabaseTestSuiteOptions, HttpTestClient, HttpTestHandlers, HttpTestRequest, HttpTestRequestInit, HttpTestServer, 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, 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, writeCatalogFromLaterRelease };
|
package/dist/index.mjs
CHANGED
|
@@ -79,6 +79,43 @@ const createAdminApiTestClient = (getClient) => {
|
|
|
79
79
|
};
|
|
80
80
|
};
|
|
81
81
|
//#endregion
|
|
82
|
+
//#region src/catalogFromLaterRelease.ts
|
|
83
|
+
/** A field no release of Hot Updater compiles, as a later release may add one. */
|
|
84
|
+
const LATER_RELEASE_CATALOG_FIELD = "laterReleaseField";
|
|
85
|
+
const sha256 = async (value) => {
|
|
86
|
+
const digest = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(value));
|
|
87
|
+
return `sha256:${[...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("")}`;
|
|
88
|
+
};
|
|
89
|
+
const canonical = (value) => {
|
|
90
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
91
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
92
|
+
const record = value;
|
|
93
|
+
return `{${Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${canonical(record[key])}`).join(",")}}`;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Rewrites a scope's stored catalog as a later release would compile it: a
|
|
97
|
+
* field this release does not know on each release descriptor, with the
|
|
98
|
+
* payload's hash and size to match. Returns the payload it wrote.
|
|
99
|
+
*/
|
|
100
|
+
const writeCatalogFromLaterRelease = async (core, scopeKey) => core.transaction(async (tx) => {
|
|
101
|
+
const row = await tx.findOne("release_catalogs", { scope_key: scopeKey });
|
|
102
|
+
if (row === null) throw new Error(`No catalog for ${scopeKey}.`);
|
|
103
|
+
const parsed = JSON.parse(row.payload);
|
|
104
|
+
const payload = canonical({
|
|
105
|
+
...parsed,
|
|
106
|
+
releaseDescriptors: parsed.releaseDescriptors.map((descriptor) => ({
|
|
107
|
+
...descriptor,
|
|
108
|
+
[LATER_RELEASE_CATALOG_FIELD]: `for ${String(descriptor.releaseId)}`
|
|
109
|
+
}))
|
|
110
|
+
});
|
|
111
|
+
tx.update("release_catalogs", row, {
|
|
112
|
+
payload,
|
|
113
|
+
catalog_hash: await sha256(payload),
|
|
114
|
+
byte_size: new TextEncoder().encode(payload).byteLength
|
|
115
|
+
});
|
|
116
|
+
return payload;
|
|
117
|
+
});
|
|
118
|
+
//#endregion
|
|
82
119
|
//#region src/databaseTestFixtures.ts
|
|
83
120
|
const fixtureId$1 = (suffix) => `00000000-0000-7000-8000-${suffix.padStart(12, "0")}`;
|
|
84
121
|
const channelFixtureSuffix = (name) => {
|
|
@@ -1037,8 +1074,10 @@ const NATIVE_PAGE_SIZE$1 = 2;
|
|
|
1037
1074
|
* concurrent fills and a deploy included, rebuilding the catalogs compiled
|
|
1038
1075
|
* without them; and the label index, which refuses a second row with a label
|
|
1039
1076
|
* and holds any number without one. Rows are written as an earlier server
|
|
1040
|
-
* wrote them through a second engine on the same adapter.
|
|
1041
|
-
*
|
|
1077
|
+
* wrote them through a second engine on the same adapter. It also writes a
|
|
1078
|
+
* catalog as a later release compiles it, with a field this one does not
|
|
1079
|
+
* know, which core verifies, never rewrites, and refuses to change. Register
|
|
1080
|
+
* it beside `setupReadBudgetTestSuite`, with the same options.
|
|
1042
1081
|
*/
|
|
1043
1082
|
const setupReleaseLabelEngineTestSuite = (options) => {
|
|
1044
1083
|
describe(`${options.name} release labels`, () => {
|
|
@@ -1135,6 +1174,50 @@ const setupReleaseLabelEngineTestSuite = (options) => {
|
|
|
1135
1174
|
});
|
|
1136
1175
|
await expect(deploy("fill")).resolves.toMatchObject({ label: 5 });
|
|
1137
1176
|
});
|
|
1177
|
+
it("verifies a catalog a later release compiled with a field this one doesn't know, and refuses to rewrite it without that field", async () => {
|
|
1178
|
+
namespace += 1;
|
|
1179
|
+
const first = await deploy("later");
|
|
1180
|
+
await deploy("later");
|
|
1181
|
+
const scopeKey = first.scope_key;
|
|
1182
|
+
const payload = await writeCatalogFromLaterRelease(raw, scopeKey);
|
|
1183
|
+
const counter = async () => (await raw.findOne("label_sequences", { id: `releases/ios/${first.channel_id}` })).last_label;
|
|
1184
|
+
const before = await counter();
|
|
1185
|
+
const stored = async () => await core.getReleaseCatalogRow(scopeKey);
|
|
1186
|
+
const generation = (await stored()).generation;
|
|
1187
|
+
await expect(core.preflightReleaseCatalogRebuild(scopeKey)).resolves.toMatchObject({
|
|
1188
|
+
changed: false,
|
|
1189
|
+
labelsOnly: false
|
|
1190
|
+
});
|
|
1191
|
+
await expect(core.rebuildReleaseCatalog(scopeKey)).resolves.toMatchObject({ changed: false });
|
|
1192
|
+
await expect(core.fillReleaseLabels()).resolves.toMatchObject({ catalogs: 0 });
|
|
1193
|
+
const refusal = {
|
|
1194
|
+
code: "CATALOG_FROM_LATER_RELEASE",
|
|
1195
|
+
message: "The ios release catalog of channel \"later-" + String(namespace) + "\" was written by a later Hot Updater.\nUpgrade hot-updater, then try again."
|
|
1196
|
+
};
|
|
1197
|
+
await expect(deploy("later")).rejects.toMatchObject(refusal);
|
|
1198
|
+
await expect(core.updateReleasePolicy({
|
|
1199
|
+
releaseId: first.id,
|
|
1200
|
+
patch: { message: "changed" }
|
|
1201
|
+
})).rejects.toMatchObject(refusal);
|
|
1202
|
+
await expect(core.preflightReleasePolicy({
|
|
1203
|
+
releaseId: first.id,
|
|
1204
|
+
patch: { message: "changed" }
|
|
1205
|
+
})).rejects.toMatchObject(refusal);
|
|
1206
|
+
expect(await stored()).toMatchObject({
|
|
1207
|
+
generation,
|
|
1208
|
+
payload
|
|
1209
|
+
});
|
|
1210
|
+
expect(payload).toContain(LATER_RELEASE_CATALOG_FIELD);
|
|
1211
|
+
expect(await counter()).toBe(before);
|
|
1212
|
+
await expect(core.listReleases({
|
|
1213
|
+
filter: {
|
|
1214
|
+
kind: "scope",
|
|
1215
|
+
scopeKey
|
|
1216
|
+
},
|
|
1217
|
+
limit: 10
|
|
1218
|
+
})).resolves.toHaveLength(2);
|
|
1219
|
+
expect((await core.getRelease(first.id))?.message).toBeNull();
|
|
1220
|
+
});
|
|
1138
1221
|
it("labels each release once when fills run beside a deploy that needs one", async () => {
|
|
1139
1222
|
namespace += 1;
|
|
1140
1223
|
const releases = [];
|
|
@@ -7061,4 +7144,4 @@ async function startHttpTestServer(handlers) {
|
|
|
7061
7144
|
};
|
|
7062
7145
|
}
|
|
7063
7146
|
//#endregion
|
|
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 };
|
|
7147
|
+
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, 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, writeCatalogFromLaterRelease };
|
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.53",
|
|
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.53",
|
|
54
|
+
"@hot-updater/protocol": "^1.2.0-rc.53",
|
|
55
|
+
"@hot-updater/plugin-core": "^1.2.0-rc.53",
|
|
56
|
+
"@hot-updater/server": "^1.2.0-rc.53"
|
|
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/
|
|
89
|
-
"@hot-updater/
|
|
90
|
-
"@hot-updater/server": "1.2.0-rc.
|
|
87
|
+
"@hot-updater/plugin-insights": "1.2.0-rc.53",
|
|
88
|
+
"@hot-updater/protocol": "1.2.0-rc.53",
|
|
89
|
+
"@hot-updater/plugin-core": "1.2.0-rc.53",
|
|
90
|
+
"@hot-updater/server": "1.2.0-rc.53"
|
|
91
91
|
},
|
|
92
92
|
"inlinedDependencies": {
|
|
93
93
|
"@clack/core": "1.4.3",
|