@hot-updater/test-utils 1.2.0-rc.3 → 1.2.0-rc.31

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.mjs CHANGED
@@ -238,9 +238,9 @@ const setupBundleMethodsTestSuite = (options) => {
238
238
  /**
239
239
  * Core's operations through admin API protocol 2 that the bundle and catalog
240
240
  * suites leave out: channels, deploy refusals, promotion, preflights, a
241
- * bundle's patch children, and the native build registry. Each test deletes
242
- * what it wrote, except a native build, which the registry keeps: its IDs
243
- * and channel are the test's own.
241
+ * bundle's patch children, the native build registry, and the iOS device
242
+ * registry. Each test deletes what it wrote, except a native build, which the
243
+ * registry keeps: its IDs and channel are the test's own.
244
244
  */
245
245
  const setupCoreAdminTestSuite = (options) => {
246
246
  describe("Core admin API", () => {
@@ -434,6 +434,36 @@ const setupCoreAdminTestSuite = (options) => {
434
434
  destination: "testflight",
435
435
  version: "1.0.0 (7)"
436
436
  }))).data).toBeNull();
437
+ const androidBuiltIn = bundleRow("64");
438
+ const androidResponse = await admin("/native-builds", jsonRequest("POST", {
439
+ id: bundleRow("864").id,
440
+ platform: "android",
441
+ channel,
442
+ fingerprintHash: "android-fingerprint",
443
+ appVersion: null,
444
+ minBundleId: androidBuiltIn.id,
445
+ gitCommitHash: null,
446
+ buildKey: null,
447
+ buildNumber: "64",
448
+ artifact: {
449
+ kind: "aab",
450
+ storageUri: "storage://native-builds/android/64/app.aab",
451
+ byteSize: 1e3
452
+ },
453
+ embeddedBundle: {
454
+ manifestStorageUri: androidBuiltIn.manifest_storage_uri,
455
+ manifestFileHash: androidBuiltIn.manifest_file_hash,
456
+ assetBaseStorageUri: androidBuiltIn.asset_base_storage_uri
457
+ }
458
+ }));
459
+ expect(androidResponse.status).toBe(201);
460
+ await androidResponse.text();
461
+ const production = await admin(`/native-builds/${bundleRow("864").id}/submission`, jsonRequest("POST", {
462
+ destination: "play-production",
463
+ version: "1.0.0 (64)"
464
+ }));
465
+ expect(production.status).toBe(200);
466
+ expect((await production.json()).data.submitted_to).toBe("play-production");
437
467
  const wrongStore = await admin(`/native-builds/${newest.id}/submission`, jsonRequest("POST", {
438
468
  destination: "play-internal",
439
469
  version: "1.0.0 (7)"
@@ -455,6 +485,295 @@ const setupCoreAdminTestSuite = (options) => {
455
485
  const after = await adminJson("/bundles?limit=1&total=true");
456
486
  expect(after.total).toBe(before.total);
457
487
  });
488
+ it("marks one store build per native build scope, replacing and clearing it", async () => {
489
+ const channel = `store-build-${namespace}`;
490
+ const register = async (suffix, fingerprintHash) => {
491
+ const builtIn = bundleRow(suffix);
492
+ const response = await admin("/native-builds", jsonRequest("POST", {
493
+ id: bundleRow(`8${suffix}`).id,
494
+ platform: "ios",
495
+ channel,
496
+ fingerprintHash,
497
+ appVersion: null,
498
+ minBundleId: builtIn.id,
499
+ gitCommitHash: null,
500
+ buildKey: null,
501
+ buildNumber: suffix,
502
+ artifact: {
503
+ kind: "ipa",
504
+ storageUri: `storage://native-builds/ios/${suffix}/App.ipa`,
505
+ byteSize: 1e3
506
+ },
507
+ embeddedBundle: {
508
+ manifestStorageUri: builtIn.manifest_storage_uri,
509
+ manifestFileHash: builtIn.manifest_file_hash,
510
+ assetBaseStorageUri: builtIn.asset_base_storage_uri
511
+ }
512
+ }));
513
+ expect(response.status).toBe(201);
514
+ return (await response.json()).data;
515
+ };
516
+ const mark = (id, storeBuild) => admin(`/native-builds/${id}/store-build`, jsonRequest("POST", { storeBuild }));
517
+ const markRead = (fingerprintHash) => `/native-builds/latest?platform=ios&channel=${encodeURIComponent(channel)}&fingerprintHash=${fingerprintHash}&storeBuild=true`;
518
+ const older = await register("64", "store-fingerprint");
519
+ const newer = await register("65", "store-fingerprint");
520
+ const otherScope = await register("66", "store-fingerprint-b");
521
+ expect(older.is_store_build).toBe(false);
522
+ expect((await adminJson(markRead("store-fingerprint"))).data).toBeNull();
523
+ const marked = await mark(older.id, true);
524
+ expect(marked.status).toBe(200);
525
+ expect(await marked.json()).toMatchObject({ data: {
526
+ nativeBuild: {
527
+ id: older.id,
528
+ is_store_build: true
529
+ },
530
+ previous: null
531
+ } });
532
+ expect((await adminJson(markRead("store-fingerprint"))).data).toEqual({
533
+ ...older,
534
+ is_store_build: true
535
+ });
536
+ expect((await adminJson(`/native-builds/latest?platform=ios&channel=${encodeURIComponent(channel)}&fingerprintHash=store-fingerprint`)).data).toEqual(newer);
537
+ expect((await adminJson(markRead("store-fingerprint-b"))).data).toBeNull();
538
+ const replaced = await mark(newer.id, true);
539
+ expect(await replaced.json()).toMatchObject({ data: {
540
+ nativeBuild: {
541
+ id: newer.id,
542
+ is_store_build: true
543
+ },
544
+ previous: {
545
+ id: older.id,
546
+ is_store_build: false
547
+ }
548
+ } });
549
+ expect((await adminJson(`/native-builds/${older.id}`)).data).toEqual(older);
550
+ expect((await adminJson(markRead("store-fingerprint"))).data).toEqual({
551
+ ...newer,
552
+ is_store_build: true
553
+ });
554
+ const race = async (ids) => {
555
+ const responses = await Promise.all(ids.map((id) => mark(id, true)));
556
+ expect(responses.map(({ status }) => status)).toEqual(ids.map(() => 200));
557
+ const results = await Promise.all(responses.map((response) => response.json()));
558
+ expect(results.map(({ data }) => data.nativeBuild.is_store_build)).toEqual(ids.map(() => true));
559
+ const holders = (await Promise.all([older, newer].map(async ({ id }) => (await adminJson(`/native-builds/${id}`)).data))).filter(({ is_store_build }) => is_store_build);
560
+ expect(holders).toHaveLength(1);
561
+ expect(ids).toContain(holders[0].id);
562
+ };
563
+ await race([
564
+ older.id,
565
+ newer.id,
566
+ older.id
567
+ ]);
568
+ await mark(older.id, false).then((response) => response.text());
569
+ await mark(newer.id, false).then((response) => response.text());
570
+ expect((await adminJson(markRead("store-fingerprint"))).data).toBeNull();
571
+ await race([older.id, newer.id]);
572
+ await (await mark(newer.id, false)).text();
573
+ await mark(older.id, false).then((response) => response.text());
574
+ expect((await adminJson(markRead("store-fingerprint"))).data).toBeNull();
575
+ expect(await (await mark(bundleRow("869").id, true)).json()).toMatchObject({ data: null });
576
+ const refused = await admin(`/native-builds/${older.id}/store-build`, jsonRequest("POST", {}));
577
+ expect(refused.status).toBe(400);
578
+ await refused.text();
579
+ await mark(otherScope.id, true).then((response) => response.text());
580
+ await adminJson(`/native-builds/${otherScope.id}`, jsonRequest("DELETE"));
581
+ expect((await adminJson(markRead("store-fingerprint-b"))).data).toBeNull();
582
+ });
583
+ it("records a sandbox build, and refuses one that disagrees with its channel", async () => {
584
+ const sandboxChannel = `sandbox-${namespace}`;
585
+ const channel = `plain-${namespace}`;
586
+ const post = (suffix, body) => {
587
+ const builtIn = bundleRow(suffix);
588
+ return admin("/native-builds", jsonRequest("POST", {
589
+ id: bundleRow(`8${suffix}`).id,
590
+ platform: "ios",
591
+ fingerprintHash: "sandbox-fingerprint",
592
+ appVersion: null,
593
+ minBundleId: builtIn.id,
594
+ gitCommitHash: null,
595
+ buildKey: null,
596
+ artifact: {
597
+ kind: "ipa",
598
+ storageUri: `storage://native-builds/ios/${suffix}/App.ipa`,
599
+ byteSize: 1e3
600
+ },
601
+ embeddedBundle: {
602
+ manifestStorageUri: builtIn.manifest_storage_uri,
603
+ manifestFileHash: builtIn.manifest_file_hash,
604
+ assetBaseStorageUri: builtIn.asset_base_storage_uri
605
+ },
606
+ ...body
607
+ }));
608
+ };
609
+ const refusal = async (suffix, body) => {
610
+ const response = await post(suffix, body);
611
+ await response.text();
612
+ return response.status;
613
+ };
614
+ expect(await refusal("74", {
615
+ channel,
616
+ isSandbox: true
617
+ })).toBe(400);
618
+ expect(await refusal("74", { channel: sandboxChannel })).toBe(400);
619
+ expect(await refusal("74", {
620
+ channel: sandboxChannel,
621
+ isSandbox: false
622
+ })).toBe(400);
623
+ expect(await refusal("74", {
624
+ channel: sandboxChannel,
625
+ isSandbox: null
626
+ })).toBe(400);
627
+ expect(await refusal("74", {
628
+ channel: sandboxChannel,
629
+ isSandbox: "yes"
630
+ })).toBe(400);
631
+ expect(await refusal("74", {
632
+ channel,
633
+ sandboxUrlScheme: "acme-preview"
634
+ })).toBe(400);
635
+ expect(await refusal("74", {
636
+ channel: sandboxChannel,
637
+ isSandbox: true,
638
+ sandboxUrlScheme: "Acme"
639
+ })).toBe(400);
640
+ expect(await refusal("74", {
641
+ channel: sandboxChannel,
642
+ isSandbox: true,
643
+ sandboxUrlScheme: 42
644
+ })).toBe(400);
645
+ expect(await refusal("74", {
646
+ channel,
647
+ nativeAppVersion: 42
648
+ })).toBe(400);
649
+ expect(await refusal("74", {
650
+ channel,
651
+ nativeAppVersion: " "
652
+ })).toBe(400);
653
+ const tagged = await post("72", {
654
+ channel: sandboxChannel,
655
+ isSandbox: true,
656
+ sandboxUrlScheme: "acme-preview",
657
+ nativeAppVersion: "1.6.0"
658
+ });
659
+ expect(tagged.status).toBe(201);
660
+ const sandboxBuild = (await tagged.json()).data;
661
+ const plain = await post("73", {
662
+ channel,
663
+ isSandbox: false
664
+ });
665
+ expect(plain.status).toBe(201);
666
+ const plainBuild = (await plain.json()).data;
667
+ expect(sandboxBuild).toMatchObject({
668
+ is_sandbox: true,
669
+ is_store_build: false,
670
+ sandbox_url_scheme: "acme-preview",
671
+ native_app_version: "1.6.0"
672
+ });
673
+ expect(plainBuild).toMatchObject({
674
+ is_sandbox: false,
675
+ is_store_build: false,
676
+ sandbox_url_scheme: null,
677
+ export_method: null,
678
+ native_app_version: null
679
+ });
680
+ expect((await adminJson(`/native-builds/${sandboxBuild.id}`)).data).toEqual(sandboxBuild);
681
+ expect((await adminJson(`/native-builds/${plainBuild.id}`)).data).toEqual(plainBuild);
682
+ expect((await adminJson(`/native-builds/latest?platform=ios&channel=${encodeURIComponent(sandboxChannel)}&fingerprintHash=sandbox-fingerprint`)).data).toEqual(sandboxBuild);
683
+ const marked = await admin(`/native-builds/${sandboxBuild.id}/store-build`, jsonRequest("POST", { storeBuild: true }));
684
+ expect(marked.status).toBe(400);
685
+ await marked.text();
686
+ });
687
+ it("requests, approves, renames, records, and removes iOS devices", async () => {
688
+ const udid = namespace.replaceAll("-", "").padEnd(40, "0");
689
+ const device = async (path, init) => (await adminJson(path, init)).data;
690
+ const requested = await adminJson("/ios-devices", jsonRequest("POST", {
691
+ udid: udid.toUpperCase(),
692
+ name: "Kim's iPhone",
693
+ requestedBy: "kim@team.dev"
694
+ }));
695
+ expect(requested.data.created).toBe(true);
696
+ const { id } = requested.data.device;
697
+ expect(requested.data.device).toMatchObject({
698
+ udid,
699
+ status: "pending",
700
+ requested_by: "kim@team.dev"
701
+ });
702
+ try {
703
+ const again = await adminJson("/ios-devices", jsonRequest("POST", {
704
+ udid,
705
+ name: "Other",
706
+ requestedBy: null
707
+ }));
708
+ expect(again.data).toEqual({
709
+ device: requested.data.device,
710
+ created: false
711
+ });
712
+ const raced = `${udid.slice(0, 39)}f`;
713
+ const racing = await Promise.all(["Other", "Another"].map((name) => adminJson("/ios-devices", jsonRequest("POST", {
714
+ udid: raced,
715
+ name,
716
+ requestedBy: null
717
+ }))));
718
+ expect(racing.map(({ data }) => data.created).sort()).toEqual([false, true]);
719
+ expect(racing[0].data.device.id).toBe(racing[1].data.device.id);
720
+ await adminJson(`/ios-devices/${racing[0].data.device.id}`, jsonRequest("DELETE"));
721
+ expect(await device(`/ios-devices/udid/${udid}`)).toEqual(requested.data.device);
722
+ const pending = await adminJson("/ios-devices?status=pending&limit=500");
723
+ expect(pending.data.map((row) => row.id)).toContain(id);
724
+ const approval = await device(`/ios-devices/${id}/approval`, jsonRequest("POST", { approvedBy: "lead@team.dev" }));
725
+ expect(approval).toMatchObject({
726
+ status: "approved",
727
+ approved_by: "lead@team.dev"
728
+ });
729
+ expect(await device(`/ios-devices/${id}`, jsonRequest("PATCH", { name: "Kim's work iPhone" }))).toMatchObject({
730
+ name: "Kim's work iPhone",
731
+ status: "approved"
732
+ });
733
+ const registered = await device(`/ios-devices/${id}/outcome`, jsonRequest("POST", {
734
+ seen: {
735
+ status: "approved",
736
+ approvedAtMs: approval.approved_at_ms
737
+ },
738
+ issuerId: "issuer-a",
739
+ outcome: "registered"
740
+ }));
741
+ expect(registered).toMatchObject({
742
+ status: "registered",
743
+ apple_issuer_id: "issuer-a"
744
+ });
745
+ expect(await device(`/ios-devices/${id}/outcome`, jsonRequest("POST", {
746
+ seen: {
747
+ status: "approved",
748
+ approvedAtMs: 1
749
+ },
750
+ issuerId: "issuer-a",
751
+ outcome: "missing"
752
+ }))).toBeNull();
753
+ const claims = await Promise.all(["issuer-a", "issuer-b"].map((issuerId) => adminJson("/ios-devices/account", jsonRequest("POST", { issuerId }))));
754
+ const owner = claims.find(({ data }) => data.claimed)?.data.issuerId;
755
+ expect(claims.filter(({ data }) => data.claimed)).toHaveLength(1);
756
+ expect(claims.map(({ data }) => data.issuerId)).toEqual([owner, owner]);
757
+ const buildId = bundleRow("90").id;
758
+ const marked = await admin("/ios-devices/in-build", jsonRequest("POST", {
759
+ buildId,
760
+ ids: [id]
761
+ }));
762
+ expect(marked.status).toBe(204);
763
+ expect((await device(`/ios-devices/udid/${udid}`))?.build_id).toBe(buildId);
764
+ const refused = await admin("/ios-devices", jsonRequest("POST", {
765
+ udid: "1234",
766
+ name: "x",
767
+ requestedBy: null
768
+ }));
769
+ expect(refused.status).toBe(400);
770
+ await refused.text();
771
+ } finally {
772
+ await adminJson(`/ios-devices/${id}`, jsonRequest("DELETE"));
773
+ }
774
+ expect(await device(`/ios-devices/udid/${udid}`)).toBeNull();
775
+ expect(await device(`/ios-devices/${id}`, jsonRequest("DELETE"))).toBeNull();
776
+ });
458
777
  it("lists the patches that start from a bundle", async () => {
459
778
  const base = bundleRow("50");
460
779
  const target = bundleRow("51");
@@ -1554,6 +1873,15 @@ const conformanceItems = {
1554
1873
  type: "string",
1555
1874
  nullable: true
1556
1875
  },
1876
+ (
1877
+ /** A unique slot only some rows hold, as long as a scope key. */
1878
+ {
1879
+ name: "slot",
1880
+ type: "string",
1881
+ nullable: true,
1882
+ maxLength: 2048,
1883
+ ascii: true
1884
+ }),
1557
1885
  {
1558
1886
  name: "_v",
1559
1887
  type: "integer",
@@ -1587,6 +1915,12 @@ const conformanceItems = {
1587
1915
  name: "byTag",
1588
1916
  eq: ["tags"],
1589
1917
  sort: ["score"]
1918
+ },
1919
+ {
1920
+ name: "bySlot",
1921
+ eq: ["slot"],
1922
+ sort: [],
1923
+ unique: true
1590
1924
  }
1591
1925
  ]
1592
1926
  };
@@ -1697,6 +2031,7 @@ const item = (id, values = {}) => ({
1697
2031
  tags: null,
1698
2032
  payload: null,
1699
2033
  note: null,
2034
+ slot: null,
1700
2035
  _v: 0,
1701
2036
  ...values
1702
2037
  });
@@ -2007,6 +2342,37 @@ const setupDatabaseAdapterConformanceSuite = (options) => {
2007
2342
  eq: ["L"]
2008
2343
  }))).toEqual(["f"]);
2009
2344
  });
2345
+ it("moves a unique slot between rows in one write, and holds a long ASCII value", async () => {
2346
+ const adapter = await setup();
2347
+ const slot = `s:${"a".repeat(998)}`;
2348
+ await ok(adapter, [
2349
+ insert(item("a", { slot })),
2350
+ insert(item("b")),
2351
+ insert(item("c"))
2352
+ ]);
2353
+ expect(await adapter.write([insert(item("d", { slot }))])).toEqual({
2354
+ ok: false,
2355
+ failedOp: 0
2356
+ });
2357
+ const patch = (id, from, to) => ({
2358
+ type: "patch",
2359
+ table: conformanceItems,
2360
+ key: [id],
2361
+ set: { slot: to },
2362
+ guard: { v: 0 },
2363
+ previous: item(id, { slot: from })
2364
+ });
2365
+ expect(await adapter.write([patch("b", null, slot)])).toEqual({
2366
+ ok: false,
2367
+ failedOp: 0
2368
+ });
2369
+ await ok(adapter, [patch("a", slot, null), patch("b", null, slot)]);
2370
+ expect(ids(await query(adapter, {
2371
+ index: "bySlot",
2372
+ eq: [slot]
2373
+ }))).toEqual(["b"]);
2374
+ expect(await one(adapter, "a")).toMatchObject({ slot: null });
2375
+ });
2010
2376
  it("orders strings by UTF-8 bytes and numbers numerically", async () => {
2011
2377
  const adapter = await setup();
2012
2378
  const names = [
@@ -3109,6 +3475,18 @@ const seed = async (database) => {
3109
3475
  assetBaseStorageUri: "storage://read-budgets/assets"
3110
3476
  }
3111
3477
  });
3478
+ await core.markNativeBuild(createBundleFixture("8011").id, { storeBuild: true });
3479
+ const pendingDevice = (await core.requestIosDevice({
3480
+ udid: BUDGET_PENDING_UDID,
3481
+ name: "Pending iPhone",
3482
+ requestedBy: "kim@team.dev"
3483
+ })).device;
3484
+ const { device: requestedDevice } = await core.requestIosDevice({
3485
+ udid: BUDGET_APPROVED_UDID,
3486
+ name: "Approved iPhone",
3487
+ requestedBy: "kim@team.dev"
3488
+ });
3489
+ const approvedDevice = await core.approveIosDevice(requestedDevice.id, { approvedBy: "lead@team.dev" });
3112
3490
  const { apiKey } = await api.apiKeys.create({ name: "Read budgets" });
3113
3491
  for (let n = 1; n <= 24; n += 1) await api.insights.recordEvent(eventOf(n));
3114
3492
  await api.insights.recordEvent(eventOf(25, {
@@ -3146,6 +3524,8 @@ const seed = async (database) => {
3146
3524
  apiKey,
3147
3525
  productionId,
3148
3526
  nightlyId: (await channel("nightly")).id,
3527
+ pendingDevice,
3528
+ approvedDevice,
3149
3529
  /** The auto-patch base key of a new production iOS 1.0.0 bundle. */
3150
3530
  candidateKey: targetBaseCandidateKey({
3151
3531
  channel: "production",
@@ -3156,6 +3536,8 @@ const seed = async (database) => {
3156
3536
  };
3157
3537
  };
3158
3538
  const budget = (entry) => entry;
3539
+ const BUDGET_PENDING_UDID = "00008030-000000000000000a";
3540
+ const BUDGET_APPROVED_UDID = "00008030-000000000000000b";
3159
3541
  const reads = (gets, keys, queries, rows) => ({
3160
3542
  gets,
3161
3543
  keys,
@@ -3356,6 +3738,52 @@ const READ_BUDGETS = [
3356
3738
  },
3357
3739
  check: (build) => expect(build).toMatchObject({ min_bundle_id: createBundleFixture("012").id })
3358
3740
  }),
3741
+ budget({
3742
+ api: "native build store mark: byStoreBuild, 1 row",
3743
+ read: ({ core }) => core.findNativeBuild(nativeBuildScope, { storeBuild: true }),
3744
+ adapter: reads(0, 0, 1, 1),
3745
+ engine: {
3746
+ calls: 1,
3747
+ rows: 1
3748
+ },
3749
+ check: (build) => expect(build).toMatchObject({
3750
+ min_bundle_id: createBundleFixture("011").id,
3751
+ is_store_build: true
3752
+ })
3753
+ }),
3754
+ budget({
3755
+ api: "native build store mark of a scope with none: byStoreBuild, no row",
3756
+ read: ({ core }) => core.findNativeBuild({
3757
+ ...nativeBuildScope,
3758
+ channel: "no-such-channel"
3759
+ }, { storeBuild: true }),
3760
+ adapter: reads(0, 0, 1, 0),
3761
+ engine: {
3762
+ calls: 1,
3763
+ rows: 0
3764
+ },
3765
+ check: (build) => expect(build).toBeNull()
3766
+ }),
3767
+ budget({
3768
+ api: "native build older than a bundle, the newest is: byScope, limit 1",
3769
+ read: ({ core }) => core.findNativeBuild(nativeBuildScope, { builtInOlderThan: "ffffffff-ffff-7fff-bfff-ffffffffffff" }),
3770
+ adapter: reads(0, 0, 1, 1),
3771
+ engine: {
3772
+ calls: 1,
3773
+ rows: 1
3774
+ },
3775
+ check: (build) => expect(build).toMatchObject({ min_bundle_id: createBundleFixture("012").id })
3776
+ }),
3777
+ budget({
3778
+ api: "native build older than a bundle, past the newest: byScope twice",
3779
+ read: ({ core }) => core.findNativeBuild(nativeBuildScope, { builtInOlderThan: createBundleFixture("012").id }),
3780
+ adapter: reads(0, 0, 2, 2),
3781
+ engine: {
3782
+ calls: 2,
3783
+ rows: 2
3784
+ },
3785
+ check: (build) => expect(build).toMatchObject({ min_bundle_id: createBundleFixture("011").id })
3786
+ }),
3359
3787
  budget({
3360
3788
  api: "native build by key: byBuildKey descending, limit 1",
3361
3789
  read: ({ core }) => core.findNativeBuild(nativeBuildScope, { buildKey: nativeBuildKey }),
@@ -3692,6 +4120,23 @@ const READ_BUDGETS = [
3692
4120
  submitted_version: "1.0.0 (12)"
3693
4121
  })
3694
4122
  }),
4123
+ budget({
4124
+ api: "native build store mark write: the build, the holder, and 1 write",
4125
+ read: ({ core }) => core.markNativeBuild(createBundleFixture("8012").id, { storeBuild: true }),
4126
+ adapter: (indexCopies) => indexCopies ? reads(2, 2, 1, 1) : reads(1, 1, 1, 1),
4127
+ engine: {
4128
+ calls: 2,
4129
+ rows: 2
4130
+ },
4131
+ writes: 1,
4132
+ check: (result) => expect(result).toMatchObject({
4133
+ nativeBuild: {
4134
+ min_bundle_id: createBundleFixture("012").id,
4135
+ is_store_build: true
4136
+ },
4137
+ previous: { min_bundle_id: createBundleFixture("011").id }
4138
+ })
4139
+ }),
3695
4140
  budget({
3696
4141
  api: "native build delete: the build, its built-in bundle, and 1 write",
3697
4142
  read: ({ core }) => core.deleteNativeBuild(createBundleFixture("8011").id),
@@ -3706,6 +4151,126 @@ const READ_BUDGETS = [
3706
4151
  nativeBuild: { min_bundle_id: createBundleFixture("011").id }
3707
4152
  })
3708
4153
  }),
4154
+ budget({
4155
+ api: "iOS devices by status: 1 query, the rows used",
4156
+ read: ({ core }) => core.listIosDevices({
4157
+ status: "approved",
4158
+ limit: 50
4159
+ }),
4160
+ adapter: reads(0, 0, 1, 1),
4161
+ engine: {
4162
+ calls: 1,
4163
+ rows: 1
4164
+ },
4165
+ returned: (rows) => rows.length,
4166
+ check: (rows) => expect(rows.map((row) => row.udid)).toEqual([BUDGET_APPROVED_UDID])
4167
+ }),
4168
+ budget({
4169
+ api: "iOS device by UDID: 1 unique read",
4170
+ read: ({ core }) => core.findIosDevice(BUDGET_PENDING_UDID.toUpperCase()),
4171
+ adapter: reads(0, 0, 1, 1),
4172
+ engine: {
4173
+ calls: 1,
4174
+ rows: 1
4175
+ },
4176
+ check: (device) => expect(device?.status).toBe("pending")
4177
+ }),
4178
+ budget({
4179
+ api: "iOS device request: the UDID's read and 1 write",
4180
+ read: ({ core }) => core.requestIosDevice({
4181
+ udid: "00008030-000000000000000c",
4182
+ name: "New iPhone",
4183
+ requestedBy: null
4184
+ }),
4185
+ adapter: reads(0, 0, 1, 0),
4186
+ engine: {
4187
+ calls: 1,
4188
+ rows: 0
4189
+ },
4190
+ writes: 1,
4191
+ check: (result) => expect(result.created).toBe(true)
4192
+ }),
4193
+ budget({
4194
+ api: "iOS device approval: the row and 1 write",
4195
+ read: ({ core, pendingDevice }) => core.approveIosDevice(pendingDevice.id, { approvedBy: null }),
4196
+ adapter: reads(1, 1, 0, 0),
4197
+ engine: {
4198
+ calls: 1,
4199
+ rows: 1
4200
+ },
4201
+ writes: 1,
4202
+ check: (device) => expect(device?.status).toBe("approved")
4203
+ }),
4204
+ budget({
4205
+ api: "iOS device outcome: the row and 1 write",
4206
+ read: ({ core, approvedDevice }) => core.recordIosDeviceOutcome({
4207
+ id: approvedDevice.id,
4208
+ seen: {
4209
+ status: "approved",
4210
+ approvedAtMs: approvedDevice.approved_at_ms
4211
+ },
4212
+ issuerId: "issuer-a",
4213
+ outcome: "registered"
4214
+ }),
4215
+ adapter: reads(1, 1, 0, 0),
4216
+ engine: {
4217
+ calls: 1,
4218
+ rows: 1
4219
+ },
4220
+ writes: 1,
4221
+ check: (device) => expect(device?.status).toBe("registered")
4222
+ }),
4223
+ budget({
4224
+ api: "iOS devices in a build: the row and 1 write each",
4225
+ read: ({ core, approvedDevice }) => core.markIosDevicesInBuild({
4226
+ buildId: createBundleFixture("8012").id,
4227
+ ids: [approvedDevice.id]
4228
+ }),
4229
+ adapter: reads(1, 1, 0, 0),
4230
+ engine: {
4231
+ calls: 1,
4232
+ rows: 1
4233
+ },
4234
+ writes: 1
4235
+ }),
4236
+ budget({
4237
+ api: "iOS device delete: the row and 1 write",
4238
+ read: ({ core, pendingDevice }) => core.deleteIosDevice(pendingDevice.id),
4239
+ adapter: reads(1, 1, 0, 0),
4240
+ engine: {
4241
+ calls: 1,
4242
+ rows: 1
4243
+ },
4244
+ writes: 1,
4245
+ check: (device) => expect(device?.udid).toBe(BUDGET_PENDING_UDID)
4246
+ }),
4247
+ budget({
4248
+ api: "iOS device account, first claim: its one row's read, the registry's rows once, and 1 write",
4249
+ read: ({ core }) => core.claimIosDeviceAccount("issuer-a"),
4250
+ adapter: reads(1, 1, 1, 2),
4251
+ engine: {
4252
+ calls: 2,
4253
+ rows: 2
4254
+ },
4255
+ writes: 1,
4256
+ check: (claim) => expect(claim).toEqual({
4257
+ issuerId: "issuer-a",
4258
+ claimed: true
4259
+ })
4260
+ }),
4261
+ budget({
4262
+ api: "iOS device account, claimed: its one row's read",
4263
+ read: ({ core }) => core.claimIosDeviceAccount("issuer-b"),
4264
+ adapter: reads(1, 1, 0, 0),
4265
+ engine: {
4266
+ calls: 1,
4267
+ rows: 1
4268
+ },
4269
+ check: (claim) => expect(claim).toEqual({
4270
+ issuerId: "issuer-a",
4271
+ claimed: false
4272
+ })
4273
+ }),
3709
4274
  budget({
3710
4275
  api: "record an insights event: 2 dependent rounds of batch gets and 1 write",
3711
4276
  read: ({ insights }) => insights.recordEvent(eventOf(27, {
@@ -3970,8 +4535,8 @@ const snapshot = async (db) => {
3970
4535
  };
3971
4536
  /**
3972
4537
  * Aggregates declared `batched` on a key-value store: log rows the store
3973
- * writes with each transaction and a compaction merges once, and a memory
3974
- * buffer, read back exactly as transactional writes read.
4538
+ * writes with each transaction and a compaction merges once, read back
4539
+ * exactly as transactional writes read.
3975
4540
  */
3976
4541
  const setupAggregateBatchingTestSuite = ({ name, createAdapter, oversizedRows }) => {
3977
4542
  const tables = [...toolingTargetOf([plugin]).schema.tables, ...aggregateBatchingTables];
@@ -4007,21 +4572,15 @@ const setupAggregateBatchingTestSuite = ({ name, createAdapter, oversizedRows })
4007
4572
  afterEach(async () => {
4008
4573
  for (const cleanup of cleanups.splice(0)) await cleanup();
4009
4574
  });
4010
- for (const mode of ["log", "memory"]) it(`reads what transactional writes read, in ${mode} mode`, async () => {
4011
- const { db } = server(await store(), { mode });
4575
+ it("reads what transactional writes read", async () => {
4576
+ const { db } = server(await store(), {});
4012
4577
  for (let step = 0; step < 36; step += 1) await open(db, step);
4013
4578
  expect(await snapshot(db)).toEqual(await expected(36));
4014
4579
  }, 12e4);
4015
4580
  it("applies each log row once when two servers compact while 16 writers commit", async () => {
4016
4581
  const adapter = await store();
4017
- const first = server(adapter, {
4018
- mode: "log",
4019
- windowMs: 0
4020
- });
4021
- const second = server(adapter, {
4022
- mode: "log",
4023
- windowMs: 0
4024
- });
4582
+ const first = server(adapter, { windowMs: 0 });
4583
+ const second = server(adapter, { windowMs: 0 });
4025
4584
  const report = await runContentionHarness({
4026
4585
  transactions: 12,
4027
4586
  ratePerSecond: 1e3,
@@ -4039,7 +4598,7 @@ const setupAggregateBatchingTestSuite = ({ name, createAdapter, oversizedRows })
4039
4598
  expect(await snapshot(second.db)).toEqual(await expected(48));
4040
4599
  }, 3e5);
4041
4600
  it("applies a log row larger than one write in parts, each change once", async () => {
4042
- const { db, flush } = server(await store(), { mode: "log" });
4601
+ const { db, flush } = server(await store(), {});
4043
4602
  await db.transaction(async (tx) => {
4044
4603
  for (let day = 1; day <= oversizedRows; day += 1) tx.aggregate("opens", { day }, { opens: day }, { shardBy: "i" });
4045
4604
  });
@@ -4231,18 +4790,13 @@ const createPluginTestHarness = async (plugin, options = {}) => {
4231
4790
  * bundles through the engine. A patch's base comes before it in `bundles`.
4232
4791
  */
4233
4792
  const storeBundles = async (database, bundles) => {
4234
- const engine = createEngine(database);
4235
- try {
4236
- await engine.core.transaction(async (tx) => {
4237
- for (const bundle of bundles) {
4238
- tx.create("bundles", bundleToRow(bundle));
4239
- for (const platformKey of [bundle.platform, "*"]) tx.aggregate("bundle_totals", { platform_key: platformKey }, { bundles: 1 });
4240
- for (const row of bundleToPatchRows(bundle)) tx.create("bundle_patches", row);
4241
- }
4242
- });
4243
- } finally {
4244
- await engine.dispose();
4245
- }
4793
+ await createEngine(database).core.transaction(async (tx) => {
4794
+ for (const bundle of bundles) {
4795
+ tx.create("bundles", bundleToRow(bundle));
4796
+ for (const platformKey of [bundle.platform, "*"]) tx.aggregate("bundle_totals", { platform_key: platformKey }, { bundles: 1 });
4797
+ for (const row of bundleToPatchRows(bundle)) tx.create("bundle_patches", row);
4798
+ }
4799
+ });
4246
4800
  };
4247
4801
  //#endregion
4248
4802
  //#region src/insights/expectInsightsIndex.ts