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

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,342 @@ 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 on any channel, finds it through its sandbox scope, and refuses one its artifact doesn't describe", async () => {
584
+ const sandboxChannel = `pr-${namespace}`;
585
+ const channel = `plain-${namespace}`;
586
+ const sandboxFields = {
587
+ isSandbox: true,
588
+ sandboxUrlScheme: "acme-preview",
589
+ sandboxAppId: "com.example.app",
590
+ exportMethod: "ad-hoc"
591
+ };
592
+ const post = (suffix, body) => {
593
+ const builtIn = bundleRow(suffix);
594
+ return admin("/native-builds", jsonRequest("POST", {
595
+ id: bundleRow(`8${suffix}`).id,
596
+ platform: "ios",
597
+ fingerprintHash: "sandbox-fingerprint",
598
+ appVersion: null,
599
+ minBundleId: builtIn.id,
600
+ gitCommitHash: null,
601
+ buildKey: null,
602
+ artifact: {
603
+ kind: "ipa",
604
+ storageUri: `storage://native-builds/ios/${suffix}/App.ipa`,
605
+ byteSize: 1e3
606
+ },
607
+ embeddedBundle: {
608
+ manifestStorageUri: builtIn.manifest_storage_uri,
609
+ manifestFileHash: builtIn.manifest_file_hash,
610
+ assetBaseStorageUri: builtIn.asset_base_storage_uri
611
+ },
612
+ ...body
613
+ }));
614
+ };
615
+ const refusal = async (suffix, body) => {
616
+ const response = await post(suffix, body);
617
+ await response.text();
618
+ return response.status;
619
+ };
620
+ expect(await refusal("74", {
621
+ channel,
622
+ isSandbox: true
623
+ })).toBe(400);
624
+ expect(await refusal("74", {
625
+ channel,
626
+ ...sandboxFields,
627
+ sandboxAppId: void 0
628
+ })).toBe(400);
629
+ expect(await refusal("74", {
630
+ channel,
631
+ sandboxAppId: "com.example.app"
632
+ })).toBe(400);
633
+ expect(await refusal("74", {
634
+ channel: sandboxChannel,
635
+ isSandbox: null
636
+ })).toBe(400);
637
+ expect(await refusal("74", {
638
+ channel: sandboxChannel,
639
+ isSandbox: "yes"
640
+ })).toBe(400);
641
+ expect(await refusal("74", {
642
+ channel,
643
+ sandboxUrlScheme: "acme-preview"
644
+ })).toBe(400);
645
+ expect(await refusal("74", {
646
+ channel: sandboxChannel,
647
+ ...sandboxFields,
648
+ sandboxUrlScheme: "Acme"
649
+ })).toBe(400);
650
+ expect(await refusal("74", {
651
+ channel: sandboxChannel,
652
+ ...sandboxFields,
653
+ sandboxUrlScheme: 42
654
+ })).toBe(400);
655
+ expect(await refusal("74", {
656
+ channel,
657
+ nativeAppVersion: 42
658
+ })).toBe(400);
659
+ expect(await refusal("74", {
660
+ channel,
661
+ nativeAppVersion: " "
662
+ })).toBe(400);
663
+ const tagged = await post("72", {
664
+ channel: sandboxChannel,
665
+ ...sandboxFields,
666
+ nativeAppVersion: "1.6.0"
667
+ });
668
+ expect(tagged.status).toBe(201);
669
+ const sandboxBuild = (await tagged.json()).data;
670
+ const plain = await post("73", {
671
+ channel: sandboxChannel,
672
+ isSandbox: false
673
+ });
674
+ expect(plain.status).toBe(201);
675
+ const plainBuild = (await plain.json()).data;
676
+ expect(sandboxBuild).toMatchObject({
677
+ is_sandbox: true,
678
+ is_store_build: false,
679
+ sandbox_url_scheme: "acme-preview",
680
+ native_app_version: "1.6.0"
681
+ });
682
+ expect(plainBuild).toMatchObject({
683
+ is_sandbox: false,
684
+ is_store_build: false,
685
+ sandbox_url_scheme: null,
686
+ export_method: null,
687
+ native_app_version: null
688
+ });
689
+ const sandboxLookup = "sandboxAppId=com.example.app&sandboxUrlScheme=acme-preview&artifactKind=ipa&distribution=direct";
690
+ expect((await adminJson(`/native-builds/${sandboxBuild.id}`)).data).toEqual(sandboxBuild);
691
+ expect((await adminJson(`/native-builds/${plainBuild.id}`)).data).toEqual(plainBuild);
692
+ expect((await adminJson(`/native-builds/latest?platform=ios&channel=other-${namespace}&fingerprintHash=sandbox-fingerprint&${sandboxLookup}`)).data).toEqual(sandboxBuild);
693
+ expect((await adminJson(`/native-builds/latest?platform=ios&channel=${encodeURIComponent(sandboxChannel)}&fingerprintHash=sandbox-fingerprint`)).data).toEqual(plainBuild);
694
+ const partial = await admin(`/native-builds/latest?platform=ios&channel=${encodeURIComponent(sandboxChannel)}&fingerprintHash=sandbox-fingerprint&sandboxAppId=com.example.app`);
695
+ expect(partial.status).toBe(400);
696
+ await partial.text();
697
+ const invalid = await admin(`/native-builds/latest?platform=ios&channel=${encodeURIComponent(sandboxChannel)}&fingerprintHash=sandbox-fingerprint&${sandboxLookup.replace("artifactKind=ipa", "artifactKind=apk")}`);
698
+ expect(invalid.status).toBe(400);
699
+ await invalid.text();
700
+ expect((await adminJson(`/native-builds/latest?platform=ios&channel=${encodeURIComponent(sandboxChannel)}&fingerprintHash=sandbox-fingerprint&${sandboxLookup}&builtInOlderThan=ffffffff-ffff-7fff-bfff-ffffffffffff`)).data).toBeNull();
701
+ const patched = await admin(`/bundles/${plainBuild.min_bundle_id}`, jsonRequest("PATCH", { patches: [{
702
+ baseBundleId: sandboxBuild.min_bundle_id,
703
+ baseFileHash: "base-hash",
704
+ byteSize: 42,
705
+ patchFileHash: "patch-hash",
706
+ patchStorageUri: "storage://patches/sandbox.patch"
707
+ }] }));
708
+ expect(patched.status).toBe(400);
709
+ expect(await patched.text()).toContain("A sandbox build's built-in bundle is no patch base.");
710
+ const deployed = await admin("/releases", jsonRequest("POST", { deployments: [{
711
+ bundle: {
712
+ ...toDeployBundle(bundleRow("76")),
713
+ patches: [{
714
+ baseBundleId: sandboxBuild.min_bundle_id,
715
+ baseFileHash: "base-hash",
716
+ byteSize: 42,
717
+ patchFileHash: "patch-hash",
718
+ patchStorageUri: "storage://patches/sandbox-deploy.patch"
719
+ }]
720
+ },
721
+ release: policy("sandbox-patch")
722
+ }] }));
723
+ expect(deployed.status).toBe(400);
724
+ expect(await deployed.text()).toContain("A sandbox build's built-in bundle is no patch base.");
725
+ const notDeployed = await admin(`/bundles/${bundleRow("76").id}`);
726
+ expect(notDeployed.status).toBe(404);
727
+ await notDeployed.text();
728
+ const marked = await admin(`/native-builds/${sandboxBuild.id}/store-build`, jsonRequest("POST", { storeBuild: true }));
729
+ expect(marked.status).toBe(400);
730
+ await marked.text();
731
+ });
732
+ it("requests, approves, renames, records, and removes iOS devices", async () => {
733
+ const udid = namespace.replaceAll("-", "").padEnd(40, "0");
734
+ const device = async (path, init) => (await adminJson(path, init)).data;
735
+ const requested = await adminJson("/ios-devices", jsonRequest("POST", {
736
+ udid: udid.toUpperCase(),
737
+ name: "Kim's iPhone",
738
+ requestedBy: "kim@team.dev"
739
+ }));
740
+ expect(requested.data.created).toBe(true);
741
+ const { id } = requested.data.device;
742
+ expect(requested.data.device).toMatchObject({
743
+ udid,
744
+ status: "pending",
745
+ requested_by: "kim@team.dev"
746
+ });
747
+ try {
748
+ const again = await adminJson("/ios-devices", jsonRequest("POST", {
749
+ udid,
750
+ name: "Other",
751
+ requestedBy: null
752
+ }));
753
+ expect(again.data).toEqual({
754
+ device: requested.data.device,
755
+ created: false
756
+ });
757
+ const raced = `${udid.slice(0, 39)}f`;
758
+ const racing = await Promise.all(["Other", "Another"].map((name) => adminJson("/ios-devices", jsonRequest("POST", {
759
+ udid: raced,
760
+ name,
761
+ requestedBy: null
762
+ }))));
763
+ expect(racing.map(({ data }) => data.created).sort()).toEqual([false, true]);
764
+ expect(racing[0].data.device.id).toBe(racing[1].data.device.id);
765
+ await adminJson(`/ios-devices/${racing[0].data.device.id}`, jsonRequest("DELETE"));
766
+ expect(await device(`/ios-devices/udid/${udid}`)).toEqual(requested.data.device);
767
+ const pending = await adminJson("/ios-devices?status=pending&limit=500");
768
+ expect(pending.data.map((row) => row.id)).toContain(id);
769
+ const approval = await device(`/ios-devices/${id}/approval`, jsonRequest("POST", { approvedBy: "lead@team.dev" }));
770
+ expect(approval).toMatchObject({
771
+ status: "approved",
772
+ approved_by: "lead@team.dev"
773
+ });
774
+ expect(await device(`/ios-devices/${id}`, jsonRequest("PATCH", { name: "Kim's work iPhone" }))).toMatchObject({
775
+ name: "Kim's work iPhone",
776
+ status: "approved"
777
+ });
778
+ const registered = await device(`/ios-devices/${id}/outcome`, jsonRequest("POST", {
779
+ seen: {
780
+ status: "approved",
781
+ approvedAtMs: approval.approved_at_ms
782
+ },
783
+ issuerId: "issuer-a",
784
+ outcome: "registered"
785
+ }));
786
+ expect(registered).toMatchObject({
787
+ status: "registered",
788
+ apple_issuer_id: "issuer-a"
789
+ });
790
+ expect(await device(`/ios-devices/${id}/outcome`, jsonRequest("POST", {
791
+ seen: {
792
+ status: "approved",
793
+ approvedAtMs: 1
794
+ },
795
+ issuerId: "issuer-a",
796
+ outcome: "missing"
797
+ }))).toBeNull();
798
+ const claims = await Promise.all(["issuer-a", "issuer-b"].map((issuerId) => adminJson("/ios-devices/account", jsonRequest("POST", { issuerId }))));
799
+ const owner = claims.find(({ data }) => data.claimed)?.data.issuerId;
800
+ expect(claims.filter(({ data }) => data.claimed)).toHaveLength(1);
801
+ expect(claims.map(({ data }) => data.issuerId)).toEqual([owner, owner]);
802
+ expect(await adminJson("/ios-devices/account")).toEqual({ data: { issuerId: owner } });
803
+ const buildId = bundleRow("90").id;
804
+ const marked = await admin("/ios-devices/in-build", jsonRequest("POST", {
805
+ buildId,
806
+ ids: [id]
807
+ }));
808
+ expect(marked.status).toBe(204);
809
+ expect((await device(`/ios-devices/udid/${udid}`))?.build_id).toBe(buildId);
810
+ const refused = await admin("/ios-devices", jsonRequest("POST", {
811
+ udid: "1234",
812
+ name: "x",
813
+ requestedBy: null
814
+ }));
815
+ expect(refused.status).toBe(400);
816
+ await refused.text();
817
+ } finally {
818
+ await adminJson(`/ios-devices/${id}`, jsonRequest("DELETE"));
819
+ }
820
+ expect(await device(`/ios-devices/udid/${udid}`)).toBeNull();
821
+ expect(await device(`/ios-devices/${id}`, jsonRequest("DELETE"))).toBeNull();
822
+ expect((await adminJson("/ios-devices/account")).data).toMatchObject({ issuerId: expect.any(String) });
823
+ });
458
824
  it("lists the patches that start from a bundle", async () => {
459
825
  const base = bundleRow("50");
460
826
  const target = bundleRow("51");
@@ -1554,6 +1920,15 @@ const conformanceItems = {
1554
1920
  type: "string",
1555
1921
  nullable: true
1556
1922
  },
1923
+ (
1924
+ /** A unique slot only some rows hold, as long as a scope key. */
1925
+ {
1926
+ name: "slot",
1927
+ type: "string",
1928
+ nullable: true,
1929
+ maxLength: 2048,
1930
+ ascii: true
1931
+ }),
1557
1932
  {
1558
1933
  name: "_v",
1559
1934
  type: "integer",
@@ -1587,6 +1962,12 @@ const conformanceItems = {
1587
1962
  name: "byTag",
1588
1963
  eq: ["tags"],
1589
1964
  sort: ["score"]
1965
+ },
1966
+ {
1967
+ name: "bySlot",
1968
+ eq: ["slot"],
1969
+ sort: [],
1970
+ unique: true
1590
1971
  }
1591
1972
  ]
1592
1973
  };
@@ -1697,6 +2078,7 @@ const item = (id, values = {}) => ({
1697
2078
  tags: null,
1698
2079
  payload: null,
1699
2080
  note: null,
2081
+ slot: null,
1700
2082
  _v: 0,
1701
2083
  ...values
1702
2084
  });
@@ -2007,6 +2389,37 @@ const setupDatabaseAdapterConformanceSuite = (options) => {
2007
2389
  eq: ["L"]
2008
2390
  }))).toEqual(["f"]);
2009
2391
  });
2392
+ it("moves a unique slot between rows in one write, and holds a long ASCII value", async () => {
2393
+ const adapter = await setup();
2394
+ const slot = `s:${"a".repeat(998)}`;
2395
+ await ok(adapter, [
2396
+ insert(item("a", { slot })),
2397
+ insert(item("b")),
2398
+ insert(item("c"))
2399
+ ]);
2400
+ expect(await adapter.write([insert(item("d", { slot }))])).toEqual({
2401
+ ok: false,
2402
+ failedOp: 0
2403
+ });
2404
+ const patch = (id, from, to) => ({
2405
+ type: "patch",
2406
+ table: conformanceItems,
2407
+ key: [id],
2408
+ set: { slot: to },
2409
+ guard: { v: 0 },
2410
+ previous: item(id, { slot: from })
2411
+ });
2412
+ expect(await adapter.write([patch("b", null, slot)])).toEqual({
2413
+ ok: false,
2414
+ failedOp: 0
2415
+ });
2416
+ await ok(adapter, [patch("a", slot, null), patch("b", null, slot)]);
2417
+ expect(ids(await query(adapter, {
2418
+ index: "bySlot",
2419
+ eq: [slot]
2420
+ }))).toEqual(["b"]);
2421
+ expect(await one(adapter, "a")).toMatchObject({ slot: null });
2422
+ });
2010
2423
  it("orders strings by UTF-8 bytes and numbers numerically", async () => {
2011
2424
  const adapter = await setup();
2012
2425
  const names = [
@@ -3028,6 +3441,13 @@ const nativeBuildScope = {
3028
3441
  fingerprintHash: "native-fingerprint",
3029
3442
  appVersion: null
3030
3443
  };
3444
+ /** A sandbox scope of `nativeBuildScope`'s fingerprint, which no build has. */
3445
+ const nativeBuildSandboxScope = {
3446
+ appId: "com.example.app",
3447
+ urlScheme: "acme-preview",
3448
+ artifactKind: "ipa",
3449
+ distribution: "direct"
3450
+ };
3031
3451
  /** The native build key the older of the two native builds is registered with. */
3032
3452
  const nativeBuildKey = `nbk1:${"0".repeat(64)}`;
3033
3453
  const bundleEvents = {
@@ -3109,6 +3529,18 @@ const seed = async (database) => {
3109
3529
  assetBaseStorageUri: "storage://read-budgets/assets"
3110
3530
  }
3111
3531
  });
3532
+ await core.markNativeBuild(createBundleFixture("8011").id, { storeBuild: true });
3533
+ const pendingDevice = (await core.requestIosDevice({
3534
+ udid: BUDGET_PENDING_UDID,
3535
+ name: "Pending iPhone",
3536
+ requestedBy: "kim@team.dev"
3537
+ })).device;
3538
+ const { device: requestedDevice } = await core.requestIosDevice({
3539
+ udid: BUDGET_APPROVED_UDID,
3540
+ name: "Approved iPhone",
3541
+ requestedBy: "kim@team.dev"
3542
+ });
3543
+ const approvedDevice = await core.approveIosDevice(requestedDevice.id, { approvedBy: "lead@team.dev" });
3112
3544
  const { apiKey } = await api.apiKeys.create({ name: "Read budgets" });
3113
3545
  for (let n = 1; n <= 24; n += 1) await api.insights.recordEvent(eventOf(n));
3114
3546
  await api.insights.recordEvent(eventOf(25, {
@@ -3146,6 +3578,8 @@ const seed = async (database) => {
3146
3578
  apiKey,
3147
3579
  productionId,
3148
3580
  nightlyId: (await channel("nightly")).id,
3581
+ pendingDevice,
3582
+ approvedDevice,
3149
3583
  /** The auto-patch base key of a new production iOS 1.0.0 bundle. */
3150
3584
  candidateKey: targetBaseCandidateKey({
3151
3585
  channel: "production",
@@ -3156,6 +3590,8 @@ const seed = async (database) => {
3156
3590
  };
3157
3591
  };
3158
3592
  const budget = (entry) => entry;
3593
+ const BUDGET_PENDING_UDID = "00008030-000000000000000a";
3594
+ const BUDGET_APPROVED_UDID = "00008030-000000000000000b";
3159
3595
  const reads = (gets, keys, queries, rows) => ({
3160
3596
  gets,
3161
3597
  keys,
@@ -3356,6 +3792,79 @@ const READ_BUDGETS = [
3356
3792
  },
3357
3793
  check: (build) => expect(build).toMatchObject({ min_bundle_id: createBundleFixture("012").id })
3358
3794
  }),
3795
+ budget({
3796
+ api: "native build store mark: byStoreBuild, 1 row",
3797
+ read: ({ core }) => core.findNativeBuild(nativeBuildScope, { storeBuild: true }),
3798
+ adapter: reads(0, 0, 1, 1),
3799
+ engine: {
3800
+ calls: 1,
3801
+ rows: 1
3802
+ },
3803
+ check: (build) => expect(build).toMatchObject({
3804
+ min_bundle_id: createBundleFixture("011").id,
3805
+ is_store_build: true
3806
+ })
3807
+ }),
3808
+ budget({
3809
+ api: "native build store mark of a scope with none: byStoreBuild, no row",
3810
+ read: ({ core }) => core.findNativeBuild({
3811
+ ...nativeBuildScope,
3812
+ channel: "no-such-channel"
3813
+ }, { storeBuild: true }),
3814
+ adapter: reads(0, 0, 1, 0),
3815
+ engine: {
3816
+ calls: 1,
3817
+ rows: 0
3818
+ },
3819
+ check: (build) => expect(build).toBeNull()
3820
+ }),
3821
+ budget({
3822
+ api: "native build older than a bundle, the newest is: byScope, limit 1",
3823
+ read: ({ core }) => core.findNativeBuild(nativeBuildScope, { builtInOlderThan: "ffffffff-ffff-7fff-bfff-ffffffffffff" }),
3824
+ adapter: reads(0, 0, 1, 1),
3825
+ engine: {
3826
+ calls: 1,
3827
+ rows: 1
3828
+ },
3829
+ check: (build) => expect(build).toMatchObject({ min_bundle_id: createBundleFixture("012").id })
3830
+ }),
3831
+ budget({
3832
+ api: "native build older than a bundle, past the newest: byScope twice",
3833
+ read: ({ core }) => core.findNativeBuild(nativeBuildScope, { builtInOlderThan: createBundleFixture("012").id }),
3834
+ adapter: reads(0, 0, 2, 2),
3835
+ engine: {
3836
+ calls: 2,
3837
+ rows: 2
3838
+ },
3839
+ check: (build) => expect(build).toMatchObject({ min_bundle_id: createBundleFixture("011").id })
3840
+ }),
3841
+ budget({
3842
+ api: "native build older than a bundle in a sandbox scope: no read",
3843
+ read: ({ core }) => core.findNativeBuild({
3844
+ ...nativeBuildScope,
3845
+ sandbox: nativeBuildSandboxScope
3846
+ }, { builtInOlderThan: "ffffffff-ffff-7fff-bfff-ffffffffffff" }),
3847
+ adapter: reads(0, 0, 0, 0),
3848
+ engine: {
3849
+ calls: 0,
3850
+ rows: 0
3851
+ },
3852
+ check: (build) => expect(build).toBeNull()
3853
+ }),
3854
+ budget({
3855
+ api: "sandbox build on any channel: byScope descending, limit 1",
3856
+ read: ({ core }) => core.findNativeBuild({
3857
+ ...nativeBuildScope,
3858
+ channel: "pr-140",
3859
+ sandbox: nativeBuildSandboxScope
3860
+ }),
3861
+ adapter: reads(0, 0, 1, 0),
3862
+ engine: {
3863
+ calls: 1,
3864
+ rows: 0
3865
+ },
3866
+ check: (build) => expect(build).toBeNull()
3867
+ }),
3359
3868
  budget({
3360
3869
  api: "native build by key: byBuildKey descending, limit 1",
3361
3870
  read: ({ core }) => core.findNativeBuild(nativeBuildScope, { buildKey: nativeBuildKey }),
@@ -3692,6 +4201,23 @@ const READ_BUDGETS = [
3692
4201
  submitted_version: "1.0.0 (12)"
3693
4202
  })
3694
4203
  }),
4204
+ budget({
4205
+ api: "native build store mark write: the build, the holder, and 1 write",
4206
+ read: ({ core }) => core.markNativeBuild(createBundleFixture("8012").id, { storeBuild: true }),
4207
+ adapter: (indexCopies) => indexCopies ? reads(2, 2, 1, 1) : reads(1, 1, 1, 1),
4208
+ engine: {
4209
+ calls: 2,
4210
+ rows: 2
4211
+ },
4212
+ writes: 1,
4213
+ check: (result) => expect(result).toMatchObject({
4214
+ nativeBuild: {
4215
+ min_bundle_id: createBundleFixture("012").id,
4216
+ is_store_build: true
4217
+ },
4218
+ previous: { min_bundle_id: createBundleFixture("011").id }
4219
+ })
4220
+ }),
3695
4221
  budget({
3696
4222
  api: "native build delete: the build, its built-in bundle, and 1 write",
3697
4223
  read: ({ core }) => core.deleteNativeBuild(createBundleFixture("8011").id),
@@ -3706,6 +4232,146 @@ const READ_BUDGETS = [
3706
4232
  nativeBuild: { min_bundle_id: createBundleFixture("011").id }
3707
4233
  })
3708
4234
  }),
4235
+ budget({
4236
+ api: "iOS devices by status: 1 query, the rows used",
4237
+ read: ({ core }) => core.listIosDevices({
4238
+ status: "approved",
4239
+ limit: 50
4240
+ }),
4241
+ adapter: reads(0, 0, 1, 1),
4242
+ engine: {
4243
+ calls: 1,
4244
+ rows: 1
4245
+ },
4246
+ returned: (rows) => rows.length,
4247
+ check: (rows) => expect(rows.map((row) => row.udid)).toEqual([BUDGET_APPROVED_UDID])
4248
+ }),
4249
+ budget({
4250
+ api: "iOS device by UDID: 1 unique read",
4251
+ read: ({ core }) => core.findIosDevice(BUDGET_PENDING_UDID.toUpperCase()),
4252
+ adapter: reads(0, 0, 1, 1),
4253
+ engine: {
4254
+ calls: 1,
4255
+ rows: 1
4256
+ },
4257
+ check: (device) => expect(device?.status).toBe("pending")
4258
+ }),
4259
+ budget({
4260
+ api: "iOS device request: the UDID's read and 1 write",
4261
+ read: ({ core }) => core.requestIosDevice({
4262
+ udid: "00008030-000000000000000c",
4263
+ name: "New iPhone",
4264
+ requestedBy: null
4265
+ }),
4266
+ adapter: reads(0, 0, 1, 0),
4267
+ engine: {
4268
+ calls: 1,
4269
+ rows: 0
4270
+ },
4271
+ writes: 1,
4272
+ check: (result) => expect(result.created).toBe(true)
4273
+ }),
4274
+ budget({
4275
+ api: "iOS device approval: the row and 1 write",
4276
+ read: ({ core, pendingDevice }) => core.approveIosDevice(pendingDevice.id, { approvedBy: null }),
4277
+ adapter: reads(1, 1, 0, 0),
4278
+ engine: {
4279
+ calls: 1,
4280
+ rows: 1
4281
+ },
4282
+ writes: 1,
4283
+ check: (device) => expect(device?.status).toBe("approved")
4284
+ }),
4285
+ budget({
4286
+ api: "iOS device outcome: the row and 1 write",
4287
+ read: ({ core, approvedDevice }) => core.recordIosDeviceOutcome({
4288
+ id: approvedDevice.id,
4289
+ seen: {
4290
+ status: "approved",
4291
+ approvedAtMs: approvedDevice.approved_at_ms
4292
+ },
4293
+ issuerId: "issuer-a",
4294
+ outcome: "registered"
4295
+ }),
4296
+ adapter: reads(1, 1, 0, 0),
4297
+ engine: {
4298
+ calls: 1,
4299
+ rows: 1
4300
+ },
4301
+ writes: 1,
4302
+ check: (device) => expect(device?.status).toBe("registered")
4303
+ }),
4304
+ budget({
4305
+ api: "iOS devices in a build: the row and 1 write each",
4306
+ read: ({ core, approvedDevice }) => core.markIosDevicesInBuild({
4307
+ buildId: createBundleFixture("8012").id,
4308
+ ids: [approvedDevice.id]
4309
+ }),
4310
+ adapter: reads(1, 1, 0, 0),
4311
+ engine: {
4312
+ calls: 1,
4313
+ rows: 1
4314
+ },
4315
+ writes: 1
4316
+ }),
4317
+ budget({
4318
+ api: "iOS device delete: the row and 1 write",
4319
+ read: ({ core, pendingDevice }) => core.deleteIosDevice(pendingDevice.id),
4320
+ adapter: reads(1, 1, 0, 0),
4321
+ engine: {
4322
+ calls: 1,
4323
+ rows: 1
4324
+ },
4325
+ writes: 1,
4326
+ check: (device) => expect(device?.udid).toBe(BUDGET_PENDING_UDID)
4327
+ }),
4328
+ budget({
4329
+ api: "iOS device account read, no claim yet: its row, then the rows that name one",
4330
+ read: ({ core }) => core.findIosDeviceAccount(),
4331
+ adapter: reads(1, 1, 1, 2),
4332
+ engine: {
4333
+ calls: 2,
4334
+ rows: 2
4335
+ },
4336
+ check: (account) => expect(account).toEqual({ issuerId: "issuer-a" })
4337
+ }),
4338
+ budget({
4339
+ api: "iOS device account, first claim: its one row's read, the registry's rows once, and 1 write",
4340
+ read: ({ core }) => core.claimIosDeviceAccount("issuer-a"),
4341
+ adapter: reads(1, 1, 1, 2),
4342
+ engine: {
4343
+ calls: 2,
4344
+ rows: 2
4345
+ },
4346
+ writes: 1,
4347
+ check: (claim) => expect(claim).toEqual({
4348
+ issuerId: "issuer-a",
4349
+ claimed: true
4350
+ })
4351
+ }),
4352
+ budget({
4353
+ api: "iOS device account read, claimed: its one row's read",
4354
+ read: ({ core }) => core.findIosDeviceAccount(),
4355
+ adapter: reads(1, 1, 0, 0),
4356
+ engine: {
4357
+ calls: 1,
4358
+ rows: 1
4359
+ },
4360
+ check: (account) => expect(account).toEqual({ issuerId: "issuer-a" })
4361
+ }),
4362
+ budget({
4363
+ api: "iOS device account, claimed: its one row's read",
4364
+ read: ({ core }) => core.claimIosDeviceAccount("issuer-b"),
4365
+ adapter: reads(1, 1, 0, 0),
4366
+ engine: {
4367
+ calls: 1,
4368
+ rows: 1
4369
+ },
4370
+ check: (claim) => expect(claim).toEqual({
4371
+ issuerId: "issuer-a",
4372
+ claimed: false
4373
+ })
4374
+ }),
3709
4375
  budget({
3710
4376
  api: "record an insights event: 2 dependent rounds of batch gets and 1 write",
3711
4377
  read: ({ insights }) => insights.recordEvent(eventOf(27, {
@@ -3970,8 +4636,8 @@ const snapshot = async (db) => {
3970
4636
  };
3971
4637
  /**
3972
4638
  * 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.
4639
+ * writes with each transaction and a compaction merges once, read back
4640
+ * exactly as transactional writes read.
3975
4641
  */
3976
4642
  const setupAggregateBatchingTestSuite = ({ name, createAdapter, oversizedRows }) => {
3977
4643
  const tables = [...toolingTargetOf([plugin]).schema.tables, ...aggregateBatchingTables];
@@ -4007,21 +4673,15 @@ const setupAggregateBatchingTestSuite = ({ name, createAdapter, oversizedRows })
4007
4673
  afterEach(async () => {
4008
4674
  for (const cleanup of cleanups.splice(0)) await cleanup();
4009
4675
  });
4010
- for (const mode of ["log", "memory"]) it(`reads what transactional writes read, in ${mode} mode`, async () => {
4011
- const { db } = server(await store(), { mode });
4676
+ it("reads what transactional writes read", async () => {
4677
+ const { db } = server(await store(), {});
4012
4678
  for (let step = 0; step < 36; step += 1) await open(db, step);
4013
4679
  expect(await snapshot(db)).toEqual(await expected(36));
4014
4680
  }, 12e4);
4015
4681
  it("applies each log row once when two servers compact while 16 writers commit", async () => {
4016
4682
  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
- });
4683
+ const first = server(adapter, { windowMs: 0 });
4684
+ const second = server(adapter, { windowMs: 0 });
4025
4685
  const report = await runContentionHarness({
4026
4686
  transactions: 12,
4027
4687
  ratePerSecond: 1e3,
@@ -4039,7 +4699,7 @@ const setupAggregateBatchingTestSuite = ({ name, createAdapter, oversizedRows })
4039
4699
  expect(await snapshot(second.db)).toEqual(await expected(48));
4040
4700
  }, 3e5);
4041
4701
  it("applies a log row larger than one write in parts, each change once", async () => {
4042
- const { db, flush } = server(await store(), { mode: "log" });
4702
+ const { db, flush } = server(await store(), {});
4043
4703
  await db.transaction(async (tx) => {
4044
4704
  for (let day = 1; day <= oversizedRows; day += 1) tx.aggregate("opens", { day }, { opens: day }, { shardBy: "i" });
4045
4705
  });
@@ -4231,18 +4891,13 @@ const createPluginTestHarness = async (plugin, options = {}) => {
4231
4891
  * bundles through the engine. A patch's base comes before it in `bundles`.
4232
4892
  */
4233
4893
  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
- }
4894
+ await createEngine(database).core.transaction(async (tx) => {
4895
+ for (const bundle of bundles) {
4896
+ tx.create("bundles", bundleToRow(bundle));
4897
+ for (const platformKey of [bundle.platform, "*"]) tx.aggregate("bundle_totals", { platform_key: platformKey }, { bundles: 1 });
4898
+ for (const row of bundleToPatchRows(bundle)) tx.create("bundle_patches", row);
4899
+ }
4900
+ });
4246
4901
  };
4247
4902
  //#endregion
4248
4903
  //#region src/insights/expectInsightsIndex.ts