@hot-updater/test-utils 1.2.0-rc.43 → 1.2.0-rc.45

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
@@ -777,6 +777,8 @@ const setupCoreAdminTestSuite = (options) => {
777
777
  expect((await adminJson(`/native-builds/${sandboxApp.id}/sibling`)).data).toEqual(sandboxIpa);
778
778
  expect((await adminJson(`/native-builds/${ipa.id}/sibling`)).data).toBeNull();
779
779
  expect((await adminJson(`/native-builds/${bundleRow("899").id}/sibling`)).data).toBeNull();
780
+ expect((await adminJson(`/native-builds/built-in/${ipa.min_bundle_id}`)).data).toEqual(ipa);
781
+ expect((await adminJson(`/native-builds/built-in/${bundleRow("899").id}`)).data).toBeNull();
780
782
  });
781
783
  it("requests, approves, renames, records, and removes iOS devices", async () => {
782
784
  const udid = namespace.replaceAll("-", "").padEnd(40, "0");
@@ -3880,6 +3882,16 @@ const READ_BUDGETS = [
3880
3882
  },
3881
3883
  check: (build) => expect(build).toMatchObject({ min_bundle_id: createBundleFixture("012").id })
3882
3884
  }),
3885
+ budget({
3886
+ api: "native build by its built-in bundle: 1 unique read",
3887
+ read: ({ core }) => core.findNativeBuildByBuiltInBundle(createBundleFixture("011").id),
3888
+ adapter: reads(0, 0, 1, 1),
3889
+ engine: {
3890
+ calls: 1,
3891
+ rows: 1
3892
+ },
3893
+ check: (build) => expect(build).toMatchObject({ id: createBundleFixture("8011").id })
3894
+ }),
3883
3895
  budget({
3884
3896
  api: "native build by scope: byScope descending, limit 1",
3885
3897
  read: ({ core }) => core.findNativeBuild(nativeBuildScope),
@@ -4471,22 +4483,22 @@ const READ_BUDGETS = [
4471
4483
  check: (device) => expect(device?.udid).toBe(BUDGET_PENDING_UDID)
4472
4484
  }),
4473
4485
  budget({
4474
- api: "iOS device account read, no claim yet: its row, then the rows that name one",
4486
+ api: "iOS device account read, no claim yet: its row, then the earliest registration",
4475
4487
  read: ({ core }) => core.findIosDeviceAccount(),
4476
- adapter: reads(1, 1, 1, 2),
4488
+ adapter: reads(1, 1, 1, 1),
4477
4489
  engine: {
4478
4490
  calls: 2,
4479
- rows: 2
4491
+ rows: 1
4480
4492
  },
4481
4493
  check: (account) => expect(account).toEqual({ issuerId: "issuer-a" })
4482
4494
  }),
4483
4495
  budget({
4484
- api: "iOS device account, first claim: its one row's read, the registry's rows once, and 1 write",
4496
+ api: "iOS device account, first claim: its one row's read, the earliest registration, and 1 write",
4485
4497
  read: ({ core }) => core.claimIosDeviceAccount("issuer-a"),
4486
- adapter: reads(1, 1, 1, 2),
4498
+ adapter: reads(1, 1, 1, 1),
4487
4499
  engine: {
4488
4500
  calls: 2,
4489
- rows: 2
4501
+ rows: 1
4490
4502
  },
4491
4503
  writes: 1,
4492
4504
  check: (claim) => expect(claim).toEqual({
@@ -4547,6 +4559,7 @@ const READ_BUDGETS = [
4547
4559
  const setupReadBudgetTestSuite = (options) => {
4548
4560
  describe(`${options.name} read budgets`, () => {
4549
4561
  let created;
4562
+ let tables;
4550
4563
  let database;
4551
4564
  let seeded;
4552
4565
  let writes = 0;
@@ -4557,8 +4570,9 @@ const setupReadBudgetTestSuite = (options) => {
4557
4570
  apiKeys(),
4558
4571
  remoteConfig()
4559
4572
  ];
4573
+ tables = [...toolingTargetOf(plugins).schema.tables, SETTINGS_TABLE];
4560
4574
  created = await options.createAdapter({
4561
- tables: [...toolingTargetOf(plugins).schema.tables, SETTINGS_TABLE],
4575
+ tables,
4562
4576
  nativePageSize: NATIVE_PAGE_SIZE
4563
4577
  });
4564
4578
  const { adapter } = created;
@@ -4598,6 +4612,42 @@ const setupReadBudgetTestSuite = (options) => {
4598
4612
  expect(await examined.total(), "rows examined").toBeLessThanOrEqual((examined.perRow ?? 1) * (keys + rows) + (examined.perRead ?? 0) * (gets + queries));
4599
4613
  }
4600
4614
  });
4615
+ /** Install `n`'s first event, all in one hour of day 4: the same rows each. */
4616
+ const newInstall = (n) => eventOf(400 + n, {
4617
+ install_id: `new-install-${n}`,
4618
+ user_id: null,
4619
+ received_at_ms: T0 + 4 * DAY + n * 1e3
4620
+ });
4621
+ /** Events of later days, which no prune below reaches. */
4622
+ const store = async (from, count) => {
4623
+ for (let n = from; n < from + count; n += 1) await seeded.insights.recordEvent(newInstall(n));
4624
+ };
4625
+ 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) => {
4626
+ const { written } = created;
4627
+ if (written === void 0) return context.skip();
4628
+ const most = async (n) => {
4629
+ written.reset();
4630
+ await seeded.insights.recordEvent(newInstall(n));
4631
+ return Math.max(...await written.rows());
4632
+ };
4633
+ await store(1, 60);
4634
+ expect(await most(61)).toBeLessThanOrEqual(2);
4635
+ await store(62, 60);
4636
+ expect(await most(122)).toBeLessThanOrEqual(2);
4637
+ });
4638
+ it("prune: deletes 5 expired events reading no more rows with 60 more events stored", async (context) => {
4639
+ const { adapter, written } = created;
4640
+ if (written === void 0) return context.skip();
4641
+ const events = tables.find(({ name }) => name === "bundle_events");
4642
+ const prune = async () => {
4643
+ written.reset();
4644
+ expect(await adapter.prune(events, T0 - DAY, 5)).toBe(5);
4645
+ return (await written.rows()).reduce((sum, rows) => sum + rows, 0);
4646
+ };
4647
+ const before = await prune();
4648
+ await store(200, 60);
4649
+ expect(await prune()).toBeLessThanOrEqual(before);
4650
+ });
4601
4651
  });
4602
4652
  };
4603
4653
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/test-utils",
3
- "version": "1.2.0-rc.43",
3
+ "version": "1.2.0-rc.45",
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.43",
54
- "@hot-updater/protocol": "^1.2.0-rc.43",
55
- "@hot-updater/plugin-core": "^1.2.0-rc.43",
56
- "@hot-updater/server": "^1.2.0-rc.43"
53
+ "@hot-updater/plugin-insights": "^1.2.0-rc.45",
54
+ "@hot-updater/protocol": "^1.2.0-rc.45",
55
+ "@hot-updater/plugin-core": "^1.2.0-rc.45",
56
+ "@hot-updater/server": "^1.2.0-rc.45"
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.43",
88
- "@hot-updater/protocol": "1.2.0-rc.43",
89
- "@hot-updater/plugin-core": "1.2.0-rc.43",
90
- "@hot-updater/server": "1.2.0-rc.43"
87
+ "@hot-updater/plugin-insights": "1.2.0-rc.45",
88
+ "@hot-updater/protocol": "1.2.0-rc.45",
89
+ "@hot-updater/plugin-core": "1.2.0-rc.45",
90
+ "@hot-updater/server": "1.2.0-rc.45"
91
91
  },
92
92
  "inlinedDependencies": {
93
93
  "@clack/core": "1.4.3",