@hot-updater/test-utils 1.2.0-rc.42 → 1.2.0-rc.44

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 CHANGED
@@ -291,6 +291,14 @@ interface ReadBudgetSuiteOptions {
291
291
  readonly cleanup?: () => Promise<void>;
292
292
  /** SQL backends: the rows the database examined for the adapter's reads. */
293
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
+ };
294
302
  /**
295
303
  * Index reads return row copies without `_v`, as the key-value adapter's
296
304
  * do, so a transaction reads the rows it guards again, whole.
package/dist/index.mjs CHANGED
@@ -729,6 +729,55 @@ const setupCoreAdminTestSuite = (options) => {
729
729
  expect(marked.status).toBe(400);
730
730
  await marked.text();
731
731
  });
732
+ it("finds a scope's build of one kind, and a sandbox build's other install target", async () => {
733
+ const channel = `kinds-${namespace}`;
734
+ const register = async (suffix, kind, body = {}) => {
735
+ const builtIn = bundleRow(suffix);
736
+ const response = await admin("/native-builds", jsonRequest("POST", {
737
+ id: bundleRow(`8${suffix}`).id,
738
+ platform: "ios",
739
+ channel,
740
+ fingerprintHash: "kind-fingerprint",
741
+ appVersion: null,
742
+ minBundleId: builtIn.id,
743
+ gitCommitHash: null,
744
+ buildKey: null,
745
+ artifact: {
746
+ kind,
747
+ storageUri: `storage://native-builds/ios/${suffix}/App.${kind === "ipa" ? "ipa" : "app.zip"}`,
748
+ byteSize: 1e3
749
+ },
750
+ embeddedBundle: {
751
+ manifestStorageUri: builtIn.manifest_storage_uri,
752
+ manifestFileHash: builtIn.manifest_file_hash,
753
+ assetBaseStorageUri: builtIn.asset_base_storage_uri
754
+ },
755
+ ...body
756
+ }));
757
+ expect(response.status).toBe(201);
758
+ return (await response.json()).data;
759
+ };
760
+ const sandbox = (exportMethod) => ({
761
+ isSandbox: true,
762
+ sandboxUrlScheme: "acme-preview",
763
+ sandboxAppId: "com.example.app",
764
+ exportMethod
765
+ });
766
+ const ipa = await register("81", "ipa");
767
+ const app = await register("82", "app");
768
+ const latest = `/native-builds/latest?platform=ios&channel=${encodeURIComponent(channel)}&fingerprintHash=kind-fingerprint`;
769
+ expect((await adminJson(latest)).data).toEqual(app);
770
+ expect((await adminJson(`${latest}&kind=ipa`)).data).toEqual(ipa);
771
+ const refused = await admin(`${latest}&kind=apk`);
772
+ expect(refused.status).toBe(400);
773
+ await refused.text();
774
+ const sandboxIpa = await register("83", "ipa", sandbox("ad-hoc"));
775
+ const sandboxApp = await register("84", "app", sandbox(null));
776
+ expect((await adminJson(`/native-builds/${sandboxIpa.id}/sibling`)).data).toEqual(sandboxApp);
777
+ expect((await adminJson(`/native-builds/${sandboxApp.id}/sibling`)).data).toEqual(sandboxIpa);
778
+ expect((await adminJson(`/native-builds/${ipa.id}/sibling`)).data).toBeNull();
779
+ expect((await adminJson(`/native-builds/${bundleRow("899").id}/sibling`)).data).toBeNull();
780
+ });
732
781
  it("requests, approves, renames, records, and removes iOS devices", async () => {
733
782
  const udid = namespace.replaceAll("-", "").padEnd(40, "0");
734
783
  const device = async (path, init) => (await adminJson(path, init)).data;
@@ -3448,6 +3497,34 @@ const nativeBuildSandboxScope = {
3448
3497
  artifactKind: "ipa",
3449
3498
  distribution: "direct"
3450
3499
  };
3500
+ /**
3501
+ * A sandbox ad hoc .ipa of `nativeBuildScope`'s fingerprint, as a build page
3502
+ * holds its row: the source of a sibling read.
3503
+ */
3504
+ const sandboxIpaRow = {
3505
+ id: "01ffffff-ffff-7fff-bfff-ffffffffffff",
3506
+ scope_key: `v1:sandbox:ios:${nativeBuildSandboxScope.appId}:${nativeBuildSandboxScope.urlScheme}:ipa:direct:fingerprint:${nativeBuildScope.fingerprintHash}`,
3507
+ platform: "ios",
3508
+ channel_id: "channel:pr-140",
3509
+ fingerprint_hash: nativeBuildScope.fingerprintHash,
3510
+ app_version: null,
3511
+ min_bundle_id: "01ffffff-ffff-7fff-bfff-fffffffffffe",
3512
+ artifact_kind: "ipa",
3513
+ artifact_storage_uri: "storage://read-budgets/native-builds/ipa/App.ipa",
3514
+ byte_size: 1e3,
3515
+ git_commit_hash: null,
3516
+ created_at_ms: 0,
3517
+ build_key: null,
3518
+ build_number: null,
3519
+ submitted_to: null,
3520
+ submitted_at_ms: null,
3521
+ submitted_version: null,
3522
+ is_store_build: false,
3523
+ is_sandbox: true,
3524
+ sandbox_url_scheme: nativeBuildSandboxScope.urlScheme,
3525
+ export_method: "ad-hoc",
3526
+ native_app_version: null
3527
+ };
3451
3528
  /** The native build key the older of the two native builds is registered with. */
3452
3529
  const nativeBuildKey = `nbk1:${"0".repeat(64)}`;
3453
3530
  const bundleEvents = {
@@ -3530,6 +3607,27 @@ const seed = async (database) => {
3530
3607
  }
3531
3608
  });
3532
3609
  await core.markNativeBuild(createBundleFixture("8011").id, { storeBuild: true });
3610
+ await core.registerNativeBuild({
3611
+ ...nativeBuildScope,
3612
+ channel: "beta",
3613
+ id: createBundleFixture("8005").id,
3614
+ minBundleId: createBundleFixture("005").id,
3615
+ gitCommitHash: null,
3616
+ buildKey: null,
3617
+ isSandbox: true,
3618
+ sandboxAppId: nativeBuildSandboxScope.appId,
3619
+ sandboxUrlScheme: nativeBuildSandboxScope.urlScheme,
3620
+ artifact: {
3621
+ kind: "app",
3622
+ storageUri: "storage://read-budgets/native-builds/005/App.app.zip",
3623
+ byteSize: 1e3
3624
+ },
3625
+ embeddedBundle: {
3626
+ manifestStorageUri: "storage://bundles/005/manifest.json",
3627
+ manifestFileHash: "manifest-hash-005",
3628
+ assetBaseStorageUri: "storage://read-budgets/assets"
3629
+ }
3630
+ });
3533
3631
  const pendingDevice = (await core.requestIosDevice({
3534
3632
  udid: BUDGET_PENDING_UDID,
3535
3633
  name: "Pending iPhone",
@@ -3878,6 +3976,53 @@ const READ_BUDGETS = [
3878
3976
  build_key: nativeBuildKey
3879
3977
  })
3880
3978
  }),
3979
+ budget({
3980
+ api: "native build of a kind: byScopeKind descending, limit 1",
3981
+ read: ({ core }) => core.findNativeBuild(nativeBuildScope, { artifactKind: "ipa" }),
3982
+ adapter: reads(0, 0, 1, 1),
3983
+ engine: {
3984
+ calls: 1,
3985
+ rows: 1
3986
+ },
3987
+ check: (build) => expect(build).toMatchObject({ min_bundle_id: createBundleFixture("012").id })
3988
+ }),
3989
+ budget({
3990
+ api: "native build of a kind with none: byScopeKind, then byScope, limit 1",
3991
+ read: ({ core }) => core.findNativeBuild(nativeBuildScope, { artifactKind: "app" }),
3992
+ adapter: reads(0, 0, 2, 1),
3993
+ engine: {
3994
+ calls: 2,
3995
+ rows: 1
3996
+ },
3997
+ check: (build) => expect(build).toBeNull()
3998
+ }),
3999
+ budget({
4000
+ api: "sandbox build's other install target: byScope descending, limit 1",
4001
+ read: ({ core }) => core.findNativeBuildSibling(sandboxIpaRow),
4002
+ adapter: reads(0, 0, 1, 1),
4003
+ engine: {
4004
+ calls: 1,
4005
+ rows: 1
4006
+ },
4007
+ check: (build) => expect(build).toMatchObject({
4008
+ id: createBundleFixture("8005").id,
4009
+ artifact_kind: "app"
4010
+ })
4011
+ }),
4012
+ budget({
4013
+ api: "normal build's other install target: no read",
4014
+ read: ({ core }) => core.findNativeBuildSibling({
4015
+ ...sandboxIpaRow,
4016
+ is_sandbox: false,
4017
+ scope_key: "normal"
4018
+ }),
4019
+ adapter: reads(0, 0, 0, 0),
4020
+ engine: {
4021
+ calls: 0,
4022
+ rows: 0
4023
+ },
4024
+ check: (build) => expect(build).toBeNull()
4025
+ }),
3881
4026
  budget({
3882
4027
  api: "native build list: all descending, limit rows",
3883
4028
  read: ({ core }) => core.listNativeBuilds({
@@ -4402,6 +4547,7 @@ const READ_BUDGETS = [
4402
4547
  const setupReadBudgetTestSuite = (options) => {
4403
4548
  describe(`${options.name} read budgets`, () => {
4404
4549
  let created;
4550
+ let tables;
4405
4551
  let database;
4406
4552
  let seeded;
4407
4553
  let writes = 0;
@@ -4412,8 +4558,9 @@ const setupReadBudgetTestSuite = (options) => {
4412
4558
  apiKeys(),
4413
4559
  remoteConfig()
4414
4560
  ];
4561
+ tables = [...toolingTargetOf(plugins).schema.tables, SETTINGS_TABLE];
4415
4562
  created = await options.createAdapter({
4416
- tables: [...toolingTargetOf(plugins).schema.tables, SETTINGS_TABLE],
4563
+ tables,
4417
4564
  nativePageSize: NATIVE_PAGE_SIZE
4418
4565
  });
4419
4566
  const { adapter } = created;
@@ -4453,6 +4600,42 @@ const setupReadBudgetTestSuite = (options) => {
4453
4600
  expect(await examined.total(), "rows examined").toBeLessThanOrEqual((examined.perRow ?? 1) * (keys + rows) + (examined.perRead ?? 0) * (gets + queries));
4454
4601
  }
4455
4602
  });
4603
+ /** Install `n`'s first event, all in one hour of day 4: the same rows each. */
4604
+ const newInstall = (n) => eventOf(400 + n, {
4605
+ install_id: `new-install-${n}`,
4606
+ user_id: null,
4607
+ received_at_ms: T0 + 4 * DAY + n * 1e3
4608
+ });
4609
+ /** Events of later days, which no prune below reaches. */
4610
+ const store = async (from, count) => {
4611
+ for (let n = from; n < from + count; n += 1) await seeded.insights.recordEvent(newInstall(n));
4612
+ };
4613
+ it("record an insights event: no statement reads more than its row and the write's guard row, with 60 or 120 events stored", async (context) => {
4614
+ const { written } = created;
4615
+ if (written === void 0) return context.skip();
4616
+ const most = async (n) => {
4617
+ written.reset();
4618
+ await seeded.insights.recordEvent(newInstall(n));
4619
+ return Math.max(...await written.rows());
4620
+ };
4621
+ await store(1, 60);
4622
+ expect(await most(61)).toBeLessThanOrEqual(2);
4623
+ await store(62, 60);
4624
+ expect(await most(122)).toBeLessThanOrEqual(2);
4625
+ });
4626
+ it("prune: deletes 5 expired events reading no more rows with 60 more events stored", async (context) => {
4627
+ const { adapter, written } = created;
4628
+ if (written === void 0) return context.skip();
4629
+ const events = tables.find(({ name }) => name === "bundle_events");
4630
+ const prune = async () => {
4631
+ written.reset();
4632
+ expect(await adapter.prune(events, T0 - DAY, 5)).toBe(5);
4633
+ return (await written.rows()).reduce((sum, rows) => sum + rows, 0);
4634
+ };
4635
+ const before = await prune();
4636
+ await store(200, 60);
4637
+ expect(await prune()).toBeLessThanOrEqual(before);
4638
+ });
4456
4639
  });
4457
4640
  };
4458
4641
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/test-utils",
3
- "version": "1.2.0-rc.42",
3
+ "version": "1.2.0-rc.44",
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.42",
54
- "@hot-updater/protocol": "^1.2.0-rc.42",
55
- "@hot-updater/plugin-core": "^1.2.0-rc.42",
56
- "@hot-updater/server": "^1.2.0-rc.42"
53
+ "@hot-updater/plugin-insights": "^1.2.0-rc.44",
54
+ "@hot-updater/protocol": "^1.2.0-rc.44",
55
+ "@hot-updater/server": "^1.2.0-rc.44",
56
+ "@hot-updater/plugin-core": "^1.2.0-rc.44"
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.42",
88
- "@hot-updater/protocol": "1.2.0-rc.42",
89
- "@hot-updater/plugin-core": "1.2.0-rc.42",
90
- "@hot-updater/server": "1.2.0-rc.42"
87
+ "@hot-updater/plugin-insights": "1.2.0-rc.44",
88
+ "@hot-updater/protocol": "1.2.0-rc.44",
89
+ "@hot-updater/plugin-core": "1.2.0-rc.44",
90
+ "@hot-updater/server": "1.2.0-rc.44"
91
91
  },
92
92
  "inlinedDependencies": {
93
93
  "@clack/core": "1.4.3",