@hot-updater/test-utils 1.2.0-rc.4 → 1.2.0-rc.40

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,323 @@ 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
+ expect((await adminJson(`/native-builds/latest?platform=ios&channel=${encodeURIComponent(sandboxChannel)}&fingerprintHash=sandbox-fingerprint&builtInOlderThan=ffffffff-ffff-7fff-bfff-ffffffffffff`)).data).toBeNull();
684
+ const patched = await admin(`/bundles/${plainBuild.min_bundle_id}`, jsonRequest("PATCH", { patches: [{
685
+ baseBundleId: sandboxBuild.min_bundle_id,
686
+ baseFileHash: "base-hash",
687
+ byteSize: 42,
688
+ patchFileHash: "patch-hash",
689
+ patchStorageUri: "storage://patches/sandbox.patch"
690
+ }] }));
691
+ expect(patched.status).toBe(400);
692
+ expect(await patched.text()).toContain("A sandbox build's built-in bundle is no patch base.");
693
+ const deployed = await admin("/releases", jsonRequest("POST", { deployments: [{
694
+ bundle: {
695
+ ...toDeployBundle(bundleRow("76")),
696
+ patches: [{
697
+ baseBundleId: sandboxBuild.min_bundle_id,
698
+ baseFileHash: "base-hash",
699
+ byteSize: 42,
700
+ patchFileHash: "patch-hash",
701
+ patchStorageUri: "storage://patches/sandbox-deploy.patch"
702
+ }]
703
+ },
704
+ release: policy("sandbox-patch")
705
+ }] }));
706
+ expect(deployed.status).toBe(400);
707
+ expect(await deployed.text()).toContain("A sandbox build's built-in bundle is no patch base.");
708
+ const notDeployed = await admin(`/bundles/${bundleRow("76").id}`);
709
+ expect(notDeployed.status).toBe(404);
710
+ await notDeployed.text();
711
+ const marked = await admin(`/native-builds/${sandboxBuild.id}/store-build`, jsonRequest("POST", { storeBuild: true }));
712
+ expect(marked.status).toBe(400);
713
+ await marked.text();
714
+ });
715
+ it("requests, approves, renames, records, and removes iOS devices", async () => {
716
+ const udid = namespace.replaceAll("-", "").padEnd(40, "0");
717
+ const device = async (path, init) => (await adminJson(path, init)).data;
718
+ const requested = await adminJson("/ios-devices", jsonRequest("POST", {
719
+ udid: udid.toUpperCase(),
720
+ name: "Kim's iPhone",
721
+ requestedBy: "kim@team.dev"
722
+ }));
723
+ expect(requested.data.created).toBe(true);
724
+ const { id } = requested.data.device;
725
+ expect(requested.data.device).toMatchObject({
726
+ udid,
727
+ status: "pending",
728
+ requested_by: "kim@team.dev"
729
+ });
730
+ try {
731
+ const again = await adminJson("/ios-devices", jsonRequest("POST", {
732
+ udid,
733
+ name: "Other",
734
+ requestedBy: null
735
+ }));
736
+ expect(again.data).toEqual({
737
+ device: requested.data.device,
738
+ created: false
739
+ });
740
+ const raced = `${udid.slice(0, 39)}f`;
741
+ const racing = await Promise.all(["Other", "Another"].map((name) => adminJson("/ios-devices", jsonRequest("POST", {
742
+ udid: raced,
743
+ name,
744
+ requestedBy: null
745
+ }))));
746
+ expect(racing.map(({ data }) => data.created).sort()).toEqual([false, true]);
747
+ expect(racing[0].data.device.id).toBe(racing[1].data.device.id);
748
+ await adminJson(`/ios-devices/${racing[0].data.device.id}`, jsonRequest("DELETE"));
749
+ expect(await device(`/ios-devices/udid/${udid}`)).toEqual(requested.data.device);
750
+ const pending = await adminJson("/ios-devices?status=pending&limit=500");
751
+ expect(pending.data.map((row) => row.id)).toContain(id);
752
+ const approval = await device(`/ios-devices/${id}/approval`, jsonRequest("POST", { approvedBy: "lead@team.dev" }));
753
+ expect(approval).toMatchObject({
754
+ status: "approved",
755
+ approved_by: "lead@team.dev"
756
+ });
757
+ expect(await device(`/ios-devices/${id}`, jsonRequest("PATCH", { name: "Kim's work iPhone" }))).toMatchObject({
758
+ name: "Kim's work iPhone",
759
+ status: "approved"
760
+ });
761
+ const registered = await device(`/ios-devices/${id}/outcome`, jsonRequest("POST", {
762
+ seen: {
763
+ status: "approved",
764
+ approvedAtMs: approval.approved_at_ms
765
+ },
766
+ issuerId: "issuer-a",
767
+ outcome: "registered"
768
+ }));
769
+ expect(registered).toMatchObject({
770
+ status: "registered",
771
+ apple_issuer_id: "issuer-a"
772
+ });
773
+ expect(await device(`/ios-devices/${id}/outcome`, jsonRequest("POST", {
774
+ seen: {
775
+ status: "approved",
776
+ approvedAtMs: 1
777
+ },
778
+ issuerId: "issuer-a",
779
+ outcome: "missing"
780
+ }))).toBeNull();
781
+ const claims = await Promise.all(["issuer-a", "issuer-b"].map((issuerId) => adminJson("/ios-devices/account", jsonRequest("POST", { issuerId }))));
782
+ const owner = claims.find(({ data }) => data.claimed)?.data.issuerId;
783
+ expect(claims.filter(({ data }) => data.claimed)).toHaveLength(1);
784
+ expect(claims.map(({ data }) => data.issuerId)).toEqual([owner, owner]);
785
+ const buildId = bundleRow("90").id;
786
+ const marked = await admin("/ios-devices/in-build", jsonRequest("POST", {
787
+ buildId,
788
+ ids: [id]
789
+ }));
790
+ expect(marked.status).toBe(204);
791
+ expect((await device(`/ios-devices/udid/${udid}`))?.build_id).toBe(buildId);
792
+ const refused = await admin("/ios-devices", jsonRequest("POST", {
793
+ udid: "1234",
794
+ name: "x",
795
+ requestedBy: null
796
+ }));
797
+ expect(refused.status).toBe(400);
798
+ await refused.text();
799
+ } finally {
800
+ await adminJson(`/ios-devices/${id}`, jsonRequest("DELETE"));
801
+ }
802
+ expect(await device(`/ios-devices/udid/${udid}`)).toBeNull();
803
+ expect(await device(`/ios-devices/${id}`, jsonRequest("DELETE"))).toBeNull();
804
+ });
458
805
  it("lists the patches that start from a bundle", async () => {
459
806
  const base = bundleRow("50");
460
807
  const target = bundleRow("51");
@@ -1554,6 +1901,15 @@ const conformanceItems = {
1554
1901
  type: "string",
1555
1902
  nullable: true
1556
1903
  },
1904
+ (
1905
+ /** A unique slot only some rows hold, as long as a scope key. */
1906
+ {
1907
+ name: "slot",
1908
+ type: "string",
1909
+ nullable: true,
1910
+ maxLength: 2048,
1911
+ ascii: true
1912
+ }),
1557
1913
  {
1558
1914
  name: "_v",
1559
1915
  type: "integer",
@@ -1587,6 +1943,12 @@ const conformanceItems = {
1587
1943
  name: "byTag",
1588
1944
  eq: ["tags"],
1589
1945
  sort: ["score"]
1946
+ },
1947
+ {
1948
+ name: "bySlot",
1949
+ eq: ["slot"],
1950
+ sort: [],
1951
+ unique: true
1590
1952
  }
1591
1953
  ]
1592
1954
  };
@@ -1697,6 +2059,7 @@ const item = (id, values = {}) => ({
1697
2059
  tags: null,
1698
2060
  payload: null,
1699
2061
  note: null,
2062
+ slot: null,
1700
2063
  _v: 0,
1701
2064
  ...values
1702
2065
  });
@@ -2007,6 +2370,37 @@ const setupDatabaseAdapterConformanceSuite = (options) => {
2007
2370
  eq: ["L"]
2008
2371
  }))).toEqual(["f"]);
2009
2372
  });
2373
+ it("moves a unique slot between rows in one write, and holds a long ASCII value", async () => {
2374
+ const adapter = await setup();
2375
+ const slot = `s:${"a".repeat(998)}`;
2376
+ await ok(adapter, [
2377
+ insert(item("a", { slot })),
2378
+ insert(item("b")),
2379
+ insert(item("c"))
2380
+ ]);
2381
+ expect(await adapter.write([insert(item("d", { slot }))])).toEqual({
2382
+ ok: false,
2383
+ failedOp: 0
2384
+ });
2385
+ const patch = (id, from, to) => ({
2386
+ type: "patch",
2387
+ table: conformanceItems,
2388
+ key: [id],
2389
+ set: { slot: to },
2390
+ guard: { v: 0 },
2391
+ previous: item(id, { slot: from })
2392
+ });
2393
+ expect(await adapter.write([patch("b", null, slot)])).toEqual({
2394
+ ok: false,
2395
+ failedOp: 0
2396
+ });
2397
+ await ok(adapter, [patch("a", slot, null), patch("b", null, slot)]);
2398
+ expect(ids(await query(adapter, {
2399
+ index: "bySlot",
2400
+ eq: [slot]
2401
+ }))).toEqual(["b"]);
2402
+ expect(await one(adapter, "a")).toMatchObject({ slot: null });
2403
+ });
2010
2404
  it("orders strings by UTF-8 bytes and numbers numerically", async () => {
2011
2405
  const adapter = await setup();
2012
2406
  const names = [
@@ -3109,6 +3503,18 @@ const seed = async (database) => {
3109
3503
  assetBaseStorageUri: "storage://read-budgets/assets"
3110
3504
  }
3111
3505
  });
3506
+ await core.markNativeBuild(createBundleFixture("8011").id, { storeBuild: true });
3507
+ const pendingDevice = (await core.requestIosDevice({
3508
+ udid: BUDGET_PENDING_UDID,
3509
+ name: "Pending iPhone",
3510
+ requestedBy: "kim@team.dev"
3511
+ })).device;
3512
+ const { device: requestedDevice } = await core.requestIosDevice({
3513
+ udid: BUDGET_APPROVED_UDID,
3514
+ name: "Approved iPhone",
3515
+ requestedBy: "kim@team.dev"
3516
+ });
3517
+ const approvedDevice = await core.approveIosDevice(requestedDevice.id, { approvedBy: "lead@team.dev" });
3112
3518
  const { apiKey } = await api.apiKeys.create({ name: "Read budgets" });
3113
3519
  for (let n = 1; n <= 24; n += 1) await api.insights.recordEvent(eventOf(n));
3114
3520
  await api.insights.recordEvent(eventOf(25, {
@@ -3146,6 +3552,8 @@ const seed = async (database) => {
3146
3552
  apiKey,
3147
3553
  productionId,
3148
3554
  nightlyId: (await channel("nightly")).id,
3555
+ pendingDevice,
3556
+ approvedDevice,
3149
3557
  /** The auto-patch base key of a new production iOS 1.0.0 bundle. */
3150
3558
  candidateKey: targetBaseCandidateKey({
3151
3559
  channel: "production",
@@ -3156,6 +3564,8 @@ const seed = async (database) => {
3156
3564
  };
3157
3565
  };
3158
3566
  const budget = (entry) => entry;
3567
+ const BUDGET_PENDING_UDID = "00008030-000000000000000a";
3568
+ const BUDGET_APPROVED_UDID = "00008030-000000000000000b";
3159
3569
  const reads = (gets, keys, queries, rows) => ({
3160
3570
  gets,
3161
3571
  keys,
@@ -3356,6 +3766,65 @@ const READ_BUDGETS = [
3356
3766
  },
3357
3767
  check: (build) => expect(build).toMatchObject({ min_bundle_id: createBundleFixture("012").id })
3358
3768
  }),
3769
+ budget({
3770
+ api: "native build store mark: byStoreBuild, 1 row",
3771
+ read: ({ core }) => core.findNativeBuild(nativeBuildScope, { storeBuild: true }),
3772
+ adapter: reads(0, 0, 1, 1),
3773
+ engine: {
3774
+ calls: 1,
3775
+ rows: 1
3776
+ },
3777
+ check: (build) => expect(build).toMatchObject({
3778
+ min_bundle_id: createBundleFixture("011").id,
3779
+ is_store_build: true
3780
+ })
3781
+ }),
3782
+ budget({
3783
+ api: "native build store mark of a scope with none: byStoreBuild, no row",
3784
+ read: ({ core }) => core.findNativeBuild({
3785
+ ...nativeBuildScope,
3786
+ channel: "no-such-channel"
3787
+ }, { storeBuild: true }),
3788
+ adapter: reads(0, 0, 1, 0),
3789
+ engine: {
3790
+ calls: 1,
3791
+ rows: 0
3792
+ },
3793
+ check: (build) => expect(build).toBeNull()
3794
+ }),
3795
+ budget({
3796
+ api: "native build older than a bundle, the newest is: byScope, limit 1",
3797
+ read: ({ core }) => core.findNativeBuild(nativeBuildScope, { builtInOlderThan: "ffffffff-ffff-7fff-bfff-ffffffffffff" }),
3798
+ adapter: reads(0, 0, 1, 1),
3799
+ engine: {
3800
+ calls: 1,
3801
+ rows: 1
3802
+ },
3803
+ check: (build) => expect(build).toMatchObject({ min_bundle_id: createBundleFixture("012").id })
3804
+ }),
3805
+ budget({
3806
+ api: "native build older than a bundle, past the newest: byScope twice",
3807
+ read: ({ core }) => core.findNativeBuild(nativeBuildScope, { builtInOlderThan: createBundleFixture("012").id }),
3808
+ adapter: reads(0, 0, 2, 2),
3809
+ engine: {
3810
+ calls: 2,
3811
+ rows: 2
3812
+ },
3813
+ check: (build) => expect(build).toMatchObject({ min_bundle_id: createBundleFixture("011").id })
3814
+ }),
3815
+ budget({
3816
+ api: "native build older than a bundle in a sandbox scope: no read",
3817
+ read: ({ core }) => core.findNativeBuild({
3818
+ ...nativeBuildScope,
3819
+ channel: "sandbox-release"
3820
+ }, { builtInOlderThan: "ffffffff-ffff-7fff-bfff-ffffffffffff" }),
3821
+ adapter: reads(0, 0, 0, 0),
3822
+ engine: {
3823
+ calls: 0,
3824
+ rows: 0
3825
+ },
3826
+ check: (build) => expect(build).toBeNull()
3827
+ }),
3359
3828
  budget({
3360
3829
  api: "native build by key: byBuildKey descending, limit 1",
3361
3830
  read: ({ core }) => core.findNativeBuild(nativeBuildScope, { buildKey: nativeBuildKey }),
@@ -3692,6 +4161,23 @@ const READ_BUDGETS = [
3692
4161
  submitted_version: "1.0.0 (12)"
3693
4162
  })
3694
4163
  }),
4164
+ budget({
4165
+ api: "native build store mark write: the build, the holder, and 1 write",
4166
+ read: ({ core }) => core.markNativeBuild(createBundleFixture("8012").id, { storeBuild: true }),
4167
+ adapter: (indexCopies) => indexCopies ? reads(2, 2, 1, 1) : reads(1, 1, 1, 1),
4168
+ engine: {
4169
+ calls: 2,
4170
+ rows: 2
4171
+ },
4172
+ writes: 1,
4173
+ check: (result) => expect(result).toMatchObject({
4174
+ nativeBuild: {
4175
+ min_bundle_id: createBundleFixture("012").id,
4176
+ is_store_build: true
4177
+ },
4178
+ previous: { min_bundle_id: createBundleFixture("011").id }
4179
+ })
4180
+ }),
3695
4181
  budget({
3696
4182
  api: "native build delete: the build, its built-in bundle, and 1 write",
3697
4183
  read: ({ core }) => core.deleteNativeBuild(createBundleFixture("8011").id),
@@ -3706,6 +4192,126 @@ const READ_BUDGETS = [
3706
4192
  nativeBuild: { min_bundle_id: createBundleFixture("011").id }
3707
4193
  })
3708
4194
  }),
4195
+ budget({
4196
+ api: "iOS devices by status: 1 query, the rows used",
4197
+ read: ({ core }) => core.listIosDevices({
4198
+ status: "approved",
4199
+ limit: 50
4200
+ }),
4201
+ adapter: reads(0, 0, 1, 1),
4202
+ engine: {
4203
+ calls: 1,
4204
+ rows: 1
4205
+ },
4206
+ returned: (rows) => rows.length,
4207
+ check: (rows) => expect(rows.map((row) => row.udid)).toEqual([BUDGET_APPROVED_UDID])
4208
+ }),
4209
+ budget({
4210
+ api: "iOS device by UDID: 1 unique read",
4211
+ read: ({ core }) => core.findIosDevice(BUDGET_PENDING_UDID.toUpperCase()),
4212
+ adapter: reads(0, 0, 1, 1),
4213
+ engine: {
4214
+ calls: 1,
4215
+ rows: 1
4216
+ },
4217
+ check: (device) => expect(device?.status).toBe("pending")
4218
+ }),
4219
+ budget({
4220
+ api: "iOS device request: the UDID's read and 1 write",
4221
+ read: ({ core }) => core.requestIosDevice({
4222
+ udid: "00008030-000000000000000c",
4223
+ name: "New iPhone",
4224
+ requestedBy: null
4225
+ }),
4226
+ adapter: reads(0, 0, 1, 0),
4227
+ engine: {
4228
+ calls: 1,
4229
+ rows: 0
4230
+ },
4231
+ writes: 1,
4232
+ check: (result) => expect(result.created).toBe(true)
4233
+ }),
4234
+ budget({
4235
+ api: "iOS device approval: the row and 1 write",
4236
+ read: ({ core, pendingDevice }) => core.approveIosDevice(pendingDevice.id, { approvedBy: null }),
4237
+ adapter: reads(1, 1, 0, 0),
4238
+ engine: {
4239
+ calls: 1,
4240
+ rows: 1
4241
+ },
4242
+ writes: 1,
4243
+ check: (device) => expect(device?.status).toBe("approved")
4244
+ }),
4245
+ budget({
4246
+ api: "iOS device outcome: the row and 1 write",
4247
+ read: ({ core, approvedDevice }) => core.recordIosDeviceOutcome({
4248
+ id: approvedDevice.id,
4249
+ seen: {
4250
+ status: "approved",
4251
+ approvedAtMs: approvedDevice.approved_at_ms
4252
+ },
4253
+ issuerId: "issuer-a",
4254
+ outcome: "registered"
4255
+ }),
4256
+ adapter: reads(1, 1, 0, 0),
4257
+ engine: {
4258
+ calls: 1,
4259
+ rows: 1
4260
+ },
4261
+ writes: 1,
4262
+ check: (device) => expect(device?.status).toBe("registered")
4263
+ }),
4264
+ budget({
4265
+ api: "iOS devices in a build: the row and 1 write each",
4266
+ read: ({ core, approvedDevice }) => core.markIosDevicesInBuild({
4267
+ buildId: createBundleFixture("8012").id,
4268
+ ids: [approvedDevice.id]
4269
+ }),
4270
+ adapter: reads(1, 1, 0, 0),
4271
+ engine: {
4272
+ calls: 1,
4273
+ rows: 1
4274
+ },
4275
+ writes: 1
4276
+ }),
4277
+ budget({
4278
+ api: "iOS device delete: the row and 1 write",
4279
+ read: ({ core, pendingDevice }) => core.deleteIosDevice(pendingDevice.id),
4280
+ adapter: reads(1, 1, 0, 0),
4281
+ engine: {
4282
+ calls: 1,
4283
+ rows: 1
4284
+ },
4285
+ writes: 1,
4286
+ check: (device) => expect(device?.udid).toBe(BUDGET_PENDING_UDID)
4287
+ }),
4288
+ budget({
4289
+ api: "iOS device account, first claim: its one row's read, the registry's rows once, and 1 write",
4290
+ read: ({ core }) => core.claimIosDeviceAccount("issuer-a"),
4291
+ adapter: reads(1, 1, 1, 2),
4292
+ engine: {
4293
+ calls: 2,
4294
+ rows: 2
4295
+ },
4296
+ writes: 1,
4297
+ check: (claim) => expect(claim).toEqual({
4298
+ issuerId: "issuer-a",
4299
+ claimed: true
4300
+ })
4301
+ }),
4302
+ budget({
4303
+ api: "iOS device account, claimed: its one row's read",
4304
+ read: ({ core }) => core.claimIosDeviceAccount("issuer-b"),
4305
+ adapter: reads(1, 1, 0, 0),
4306
+ engine: {
4307
+ calls: 1,
4308
+ rows: 1
4309
+ },
4310
+ check: (claim) => expect(claim).toEqual({
4311
+ issuerId: "issuer-a",
4312
+ claimed: false
4313
+ })
4314
+ }),
3709
4315
  budget({
3710
4316
  api: "record an insights event: 2 dependent rounds of batch gets and 1 write",
3711
4317
  read: ({ insights }) => insights.recordEvent(eventOf(27, {
@@ -3970,8 +4576,8 @@ const snapshot = async (db) => {
3970
4576
  };
3971
4577
  /**
3972
4578
  * 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.
4579
+ * writes with each transaction and a compaction merges once, read back
4580
+ * exactly as transactional writes read.
3975
4581
  */
3976
4582
  const setupAggregateBatchingTestSuite = ({ name, createAdapter, oversizedRows }) => {
3977
4583
  const tables = [...toolingTargetOf([plugin]).schema.tables, ...aggregateBatchingTables];
@@ -4007,21 +4613,15 @@ const setupAggregateBatchingTestSuite = ({ name, createAdapter, oversizedRows })
4007
4613
  afterEach(async () => {
4008
4614
  for (const cleanup of cleanups.splice(0)) await cleanup();
4009
4615
  });
4010
- for (const mode of ["log", "memory"]) it(`reads what transactional writes read, in ${mode} mode`, async () => {
4011
- const { db } = server(await store(), { mode });
4616
+ it("reads what transactional writes read", async () => {
4617
+ const { db } = server(await store(), {});
4012
4618
  for (let step = 0; step < 36; step += 1) await open(db, step);
4013
4619
  expect(await snapshot(db)).toEqual(await expected(36));
4014
4620
  }, 12e4);
4015
4621
  it("applies each log row once when two servers compact while 16 writers commit", async () => {
4016
4622
  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
- });
4623
+ const first = server(adapter, { windowMs: 0 });
4624
+ const second = server(adapter, { windowMs: 0 });
4025
4625
  const report = await runContentionHarness({
4026
4626
  transactions: 12,
4027
4627
  ratePerSecond: 1e3,
@@ -4039,7 +4639,7 @@ const setupAggregateBatchingTestSuite = ({ name, createAdapter, oversizedRows })
4039
4639
  expect(await snapshot(second.db)).toEqual(await expected(48));
4040
4640
  }, 3e5);
4041
4641
  it("applies a log row larger than one write in parts, each change once", async () => {
4042
- const { db, flush } = server(await store(), { mode: "log" });
4642
+ const { db, flush } = server(await store(), {});
4043
4643
  await db.transaction(async (tx) => {
4044
4644
  for (let day = 1; day <= oversizedRows; day += 1) tx.aggregate("opens", { day }, { opens: day }, { shardBy: "i" });
4045
4645
  });
@@ -4231,18 +4831,13 @@ const createPluginTestHarness = async (plugin, options = {}) => {
4231
4831
  * bundles through the engine. A patch's base comes before it in `bundles`.
4232
4832
  */
4233
4833
  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
- }
4834
+ await createEngine(database).core.transaction(async (tx) => {
4835
+ for (const bundle of bundles) {
4836
+ tx.create("bundles", bundleToRow(bundle));
4837
+ for (const platformKey of [bundle.platform, "*"]) tx.aggregate("bundle_totals", { platform_key: platformKey }, { bundles: 1 });
4838
+ for (const row of bundleToPatchRows(bundle)) tx.create("bundle_patches", row);
4839
+ }
4840
+ });
4246
4841
  };
4247
4842
  //#endregion
4248
4843
  //#region src/insights/expectInsightsIndex.ts