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

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,284 @@ 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
+ const tagged = await post("72", {
646
+ channel: sandboxChannel,
647
+ isSandbox: true,
648
+ sandboxUrlScheme: "acme-preview"
649
+ });
650
+ expect(tagged.status).toBe(201);
651
+ const sandboxBuild = (await tagged.json()).data;
652
+ const plain = await post("73", {
653
+ channel,
654
+ isSandbox: false
655
+ });
656
+ expect(plain.status).toBe(201);
657
+ const plainBuild = (await plain.json()).data;
658
+ expect(sandboxBuild).toMatchObject({
659
+ is_sandbox: true,
660
+ is_store_build: false,
661
+ sandbox_url_scheme: "acme-preview"
662
+ });
663
+ expect(plainBuild).toMatchObject({
664
+ is_sandbox: false,
665
+ is_store_build: false,
666
+ sandbox_url_scheme: null,
667
+ export_method: null
668
+ });
669
+ expect((await adminJson(`/native-builds/${sandboxBuild.id}`)).data).toEqual(sandboxBuild);
670
+ expect((await adminJson(`/native-builds/${plainBuild.id}`)).data).toEqual(plainBuild);
671
+ expect((await adminJson(`/native-builds/latest?platform=ios&channel=${encodeURIComponent(sandboxChannel)}&fingerprintHash=sandbox-fingerprint`)).data).toEqual(sandboxBuild);
672
+ const marked = await admin(`/native-builds/${sandboxBuild.id}/store-build`, jsonRequest("POST", { storeBuild: true }));
673
+ expect(marked.status).toBe(400);
674
+ await marked.text();
675
+ });
676
+ it("requests, approves, renames, records, and removes iOS devices", async () => {
677
+ const udid = namespace.replaceAll("-", "").padEnd(40, "0");
678
+ const device = async (path, init) => (await adminJson(path, init)).data;
679
+ const requested = await adminJson("/ios-devices", jsonRequest("POST", {
680
+ udid: udid.toUpperCase(),
681
+ name: "Kim's iPhone",
682
+ requestedBy: "kim@team.dev"
683
+ }));
684
+ expect(requested.data.created).toBe(true);
685
+ const { id } = requested.data.device;
686
+ expect(requested.data.device).toMatchObject({
687
+ udid,
688
+ status: "pending",
689
+ requested_by: "kim@team.dev"
690
+ });
691
+ try {
692
+ const again = await adminJson("/ios-devices", jsonRequest("POST", {
693
+ udid,
694
+ name: "Other",
695
+ requestedBy: null
696
+ }));
697
+ expect(again.data).toEqual({
698
+ device: requested.data.device,
699
+ created: false
700
+ });
701
+ const raced = `${udid.slice(0, 39)}f`;
702
+ const racing = await Promise.all(["Other", "Another"].map((name) => adminJson("/ios-devices", jsonRequest("POST", {
703
+ udid: raced,
704
+ name,
705
+ requestedBy: null
706
+ }))));
707
+ expect(racing.map(({ data }) => data.created).sort()).toEqual([false, true]);
708
+ expect(racing[0].data.device.id).toBe(racing[1].data.device.id);
709
+ await adminJson(`/ios-devices/${racing[0].data.device.id}`, jsonRequest("DELETE"));
710
+ expect(await device(`/ios-devices/udid/${udid}`)).toEqual(requested.data.device);
711
+ const pending = await adminJson("/ios-devices?status=pending&limit=500");
712
+ expect(pending.data.map((row) => row.id)).toContain(id);
713
+ const approval = await device(`/ios-devices/${id}/approval`, jsonRequest("POST", { approvedBy: "lead@team.dev" }));
714
+ expect(approval).toMatchObject({
715
+ status: "approved",
716
+ approved_by: "lead@team.dev"
717
+ });
718
+ expect(await device(`/ios-devices/${id}`, jsonRequest("PATCH", { name: "Kim's work iPhone" }))).toMatchObject({
719
+ name: "Kim's work iPhone",
720
+ status: "approved"
721
+ });
722
+ const registered = await device(`/ios-devices/${id}/outcome`, jsonRequest("POST", {
723
+ seen: {
724
+ status: "approved",
725
+ approvedAtMs: approval.approved_at_ms
726
+ },
727
+ issuerId: "issuer-a",
728
+ outcome: "registered"
729
+ }));
730
+ expect(registered).toMatchObject({
731
+ status: "registered",
732
+ apple_issuer_id: "issuer-a"
733
+ });
734
+ expect(await device(`/ios-devices/${id}/outcome`, jsonRequest("POST", {
735
+ seen: {
736
+ status: "approved",
737
+ approvedAtMs: 1
738
+ },
739
+ issuerId: "issuer-a",
740
+ outcome: "missing"
741
+ }))).toBeNull();
742
+ const claims = await Promise.all(["issuer-a", "issuer-b"].map((issuerId) => adminJson("/ios-devices/account", jsonRequest("POST", { issuerId }))));
743
+ const owner = claims.find(({ data }) => data.claimed)?.data.issuerId;
744
+ expect(claims.filter(({ data }) => data.claimed)).toHaveLength(1);
745
+ expect(claims.map(({ data }) => data.issuerId)).toEqual([owner, owner]);
746
+ const buildId = bundleRow("90").id;
747
+ const marked = await admin("/ios-devices/in-build", jsonRequest("POST", {
748
+ buildId,
749
+ ids: [id]
750
+ }));
751
+ expect(marked.status).toBe(204);
752
+ expect((await device(`/ios-devices/udid/${udid}`))?.build_id).toBe(buildId);
753
+ const refused = await admin("/ios-devices", jsonRequest("POST", {
754
+ udid: "1234",
755
+ name: "x",
756
+ requestedBy: null
757
+ }));
758
+ expect(refused.status).toBe(400);
759
+ await refused.text();
760
+ } finally {
761
+ await adminJson(`/ios-devices/${id}`, jsonRequest("DELETE"));
762
+ }
763
+ expect(await device(`/ios-devices/udid/${udid}`)).toBeNull();
764
+ expect(await device(`/ios-devices/${id}`, jsonRequest("DELETE"))).toBeNull();
765
+ });
458
766
  it("lists the patches that start from a bundle", async () => {
459
767
  const base = bundleRow("50");
460
768
  const target = bundleRow("51");
@@ -1554,6 +1862,15 @@ const conformanceItems = {
1554
1862
  type: "string",
1555
1863
  nullable: true
1556
1864
  },
1865
+ (
1866
+ /** A unique slot only some rows hold, as long as a scope key. */
1867
+ {
1868
+ name: "slot",
1869
+ type: "string",
1870
+ nullable: true,
1871
+ maxLength: 2048,
1872
+ ascii: true
1873
+ }),
1557
1874
  {
1558
1875
  name: "_v",
1559
1876
  type: "integer",
@@ -1587,6 +1904,12 @@ const conformanceItems = {
1587
1904
  name: "byTag",
1588
1905
  eq: ["tags"],
1589
1906
  sort: ["score"]
1907
+ },
1908
+ {
1909
+ name: "bySlot",
1910
+ eq: ["slot"],
1911
+ sort: [],
1912
+ unique: true
1590
1913
  }
1591
1914
  ]
1592
1915
  };
@@ -1697,6 +2020,7 @@ const item = (id, values = {}) => ({
1697
2020
  tags: null,
1698
2021
  payload: null,
1699
2022
  note: null,
2023
+ slot: null,
1700
2024
  _v: 0,
1701
2025
  ...values
1702
2026
  });
@@ -2007,6 +2331,37 @@ const setupDatabaseAdapterConformanceSuite = (options) => {
2007
2331
  eq: ["L"]
2008
2332
  }))).toEqual(["f"]);
2009
2333
  });
2334
+ it("moves a unique slot between rows in one write, and holds a long ASCII value", async () => {
2335
+ const adapter = await setup();
2336
+ const slot = `s:${"a".repeat(998)}`;
2337
+ await ok(adapter, [
2338
+ insert(item("a", { slot })),
2339
+ insert(item("b")),
2340
+ insert(item("c"))
2341
+ ]);
2342
+ expect(await adapter.write([insert(item("d", { slot }))])).toEqual({
2343
+ ok: false,
2344
+ failedOp: 0
2345
+ });
2346
+ const patch = (id, from, to) => ({
2347
+ type: "patch",
2348
+ table: conformanceItems,
2349
+ key: [id],
2350
+ set: { slot: to },
2351
+ guard: { v: 0 },
2352
+ previous: item(id, { slot: from })
2353
+ });
2354
+ expect(await adapter.write([patch("b", null, slot)])).toEqual({
2355
+ ok: false,
2356
+ failedOp: 0
2357
+ });
2358
+ await ok(adapter, [patch("a", slot, null), patch("b", null, slot)]);
2359
+ expect(ids(await query(adapter, {
2360
+ index: "bySlot",
2361
+ eq: [slot]
2362
+ }))).toEqual(["b"]);
2363
+ expect(await one(adapter, "a")).toMatchObject({ slot: null });
2364
+ });
2010
2365
  it("orders strings by UTF-8 bytes and numbers numerically", async () => {
2011
2366
  const adapter = await setup();
2012
2367
  const names = [
@@ -3109,6 +3464,18 @@ const seed = async (database) => {
3109
3464
  assetBaseStorageUri: "storage://read-budgets/assets"
3110
3465
  }
3111
3466
  });
3467
+ await core.markNativeBuild(createBundleFixture("8011").id, { storeBuild: true });
3468
+ const pendingDevice = (await core.requestIosDevice({
3469
+ udid: BUDGET_PENDING_UDID,
3470
+ name: "Pending iPhone",
3471
+ requestedBy: "kim@team.dev"
3472
+ })).device;
3473
+ const { device: requestedDevice } = await core.requestIosDevice({
3474
+ udid: BUDGET_APPROVED_UDID,
3475
+ name: "Approved iPhone",
3476
+ requestedBy: "kim@team.dev"
3477
+ });
3478
+ const approvedDevice = await core.approveIosDevice(requestedDevice.id, { approvedBy: "lead@team.dev" });
3112
3479
  const { apiKey } = await api.apiKeys.create({ name: "Read budgets" });
3113
3480
  for (let n = 1; n <= 24; n += 1) await api.insights.recordEvent(eventOf(n));
3114
3481
  await api.insights.recordEvent(eventOf(25, {
@@ -3146,6 +3513,8 @@ const seed = async (database) => {
3146
3513
  apiKey,
3147
3514
  productionId,
3148
3515
  nightlyId: (await channel("nightly")).id,
3516
+ pendingDevice,
3517
+ approvedDevice,
3149
3518
  /** The auto-patch base key of a new production iOS 1.0.0 bundle. */
3150
3519
  candidateKey: targetBaseCandidateKey({
3151
3520
  channel: "production",
@@ -3156,6 +3525,8 @@ const seed = async (database) => {
3156
3525
  };
3157
3526
  };
3158
3527
  const budget = (entry) => entry;
3528
+ const BUDGET_PENDING_UDID = "00008030-000000000000000a";
3529
+ const BUDGET_APPROVED_UDID = "00008030-000000000000000b";
3159
3530
  const reads = (gets, keys, queries, rows) => ({
3160
3531
  gets,
3161
3532
  keys,
@@ -3356,6 +3727,52 @@ const READ_BUDGETS = [
3356
3727
  },
3357
3728
  check: (build) => expect(build).toMatchObject({ min_bundle_id: createBundleFixture("012").id })
3358
3729
  }),
3730
+ budget({
3731
+ api: "native build store mark: byStoreBuild, 1 row",
3732
+ read: ({ core }) => core.findNativeBuild(nativeBuildScope, { storeBuild: true }),
3733
+ adapter: reads(0, 0, 1, 1),
3734
+ engine: {
3735
+ calls: 1,
3736
+ rows: 1
3737
+ },
3738
+ check: (build) => expect(build).toMatchObject({
3739
+ min_bundle_id: createBundleFixture("011").id,
3740
+ is_store_build: true
3741
+ })
3742
+ }),
3743
+ budget({
3744
+ api: "native build store mark of a scope with none: byStoreBuild, no row",
3745
+ read: ({ core }) => core.findNativeBuild({
3746
+ ...nativeBuildScope,
3747
+ channel: "no-such-channel"
3748
+ }, { storeBuild: true }),
3749
+ adapter: reads(0, 0, 1, 0),
3750
+ engine: {
3751
+ calls: 1,
3752
+ rows: 0
3753
+ },
3754
+ check: (build) => expect(build).toBeNull()
3755
+ }),
3756
+ budget({
3757
+ api: "native build older than a bundle, the newest is: byScope, limit 1",
3758
+ read: ({ core }) => core.findNativeBuild(nativeBuildScope, { builtInOlderThan: "ffffffff-ffff-7fff-bfff-ffffffffffff" }),
3759
+ adapter: reads(0, 0, 1, 1),
3760
+ engine: {
3761
+ calls: 1,
3762
+ rows: 1
3763
+ },
3764
+ check: (build) => expect(build).toMatchObject({ min_bundle_id: createBundleFixture("012").id })
3765
+ }),
3766
+ budget({
3767
+ api: "native build older than a bundle, past the newest: byScope twice",
3768
+ read: ({ core }) => core.findNativeBuild(nativeBuildScope, { builtInOlderThan: createBundleFixture("012").id }),
3769
+ adapter: reads(0, 0, 2, 2),
3770
+ engine: {
3771
+ calls: 2,
3772
+ rows: 2
3773
+ },
3774
+ check: (build) => expect(build).toMatchObject({ min_bundle_id: createBundleFixture("011").id })
3775
+ }),
3359
3776
  budget({
3360
3777
  api: "native build by key: byBuildKey descending, limit 1",
3361
3778
  read: ({ core }) => core.findNativeBuild(nativeBuildScope, { buildKey: nativeBuildKey }),
@@ -3692,6 +4109,23 @@ const READ_BUDGETS = [
3692
4109
  submitted_version: "1.0.0 (12)"
3693
4110
  })
3694
4111
  }),
4112
+ budget({
4113
+ api: "native build store mark write: the build, the holder, and 1 write",
4114
+ read: ({ core }) => core.markNativeBuild(createBundleFixture("8012").id, { storeBuild: true }),
4115
+ adapter: (indexCopies) => indexCopies ? reads(2, 2, 1, 1) : reads(1, 1, 1, 1),
4116
+ engine: {
4117
+ calls: 2,
4118
+ rows: 2
4119
+ },
4120
+ writes: 1,
4121
+ check: (result) => expect(result).toMatchObject({
4122
+ nativeBuild: {
4123
+ min_bundle_id: createBundleFixture("012").id,
4124
+ is_store_build: true
4125
+ },
4126
+ previous: { min_bundle_id: createBundleFixture("011").id }
4127
+ })
4128
+ }),
3695
4129
  budget({
3696
4130
  api: "native build delete: the build, its built-in bundle, and 1 write",
3697
4131
  read: ({ core }) => core.deleteNativeBuild(createBundleFixture("8011").id),
@@ -3706,6 +4140,126 @@ const READ_BUDGETS = [
3706
4140
  nativeBuild: { min_bundle_id: createBundleFixture("011").id }
3707
4141
  })
3708
4142
  }),
4143
+ budget({
4144
+ api: "iOS devices by status: 1 query, the rows used",
4145
+ read: ({ core }) => core.listIosDevices({
4146
+ status: "approved",
4147
+ limit: 50
4148
+ }),
4149
+ adapter: reads(0, 0, 1, 1),
4150
+ engine: {
4151
+ calls: 1,
4152
+ rows: 1
4153
+ },
4154
+ returned: (rows) => rows.length,
4155
+ check: (rows) => expect(rows.map((row) => row.udid)).toEqual([BUDGET_APPROVED_UDID])
4156
+ }),
4157
+ budget({
4158
+ api: "iOS device by UDID: 1 unique read",
4159
+ read: ({ core }) => core.findIosDevice(BUDGET_PENDING_UDID.toUpperCase()),
4160
+ adapter: reads(0, 0, 1, 1),
4161
+ engine: {
4162
+ calls: 1,
4163
+ rows: 1
4164
+ },
4165
+ check: (device) => expect(device?.status).toBe("pending")
4166
+ }),
4167
+ budget({
4168
+ api: "iOS device request: the UDID's read and 1 write",
4169
+ read: ({ core }) => core.requestIosDevice({
4170
+ udid: "00008030-000000000000000c",
4171
+ name: "New iPhone",
4172
+ requestedBy: null
4173
+ }),
4174
+ adapter: reads(0, 0, 1, 0),
4175
+ engine: {
4176
+ calls: 1,
4177
+ rows: 0
4178
+ },
4179
+ writes: 1,
4180
+ check: (result) => expect(result.created).toBe(true)
4181
+ }),
4182
+ budget({
4183
+ api: "iOS device approval: the row and 1 write",
4184
+ read: ({ core, pendingDevice }) => core.approveIosDevice(pendingDevice.id, { approvedBy: null }),
4185
+ adapter: reads(1, 1, 0, 0),
4186
+ engine: {
4187
+ calls: 1,
4188
+ rows: 1
4189
+ },
4190
+ writes: 1,
4191
+ check: (device) => expect(device?.status).toBe("approved")
4192
+ }),
4193
+ budget({
4194
+ api: "iOS device outcome: the row and 1 write",
4195
+ read: ({ core, approvedDevice }) => core.recordIosDeviceOutcome({
4196
+ id: approvedDevice.id,
4197
+ seen: {
4198
+ status: "approved",
4199
+ approvedAtMs: approvedDevice.approved_at_ms
4200
+ },
4201
+ issuerId: "issuer-a",
4202
+ outcome: "registered"
4203
+ }),
4204
+ adapter: reads(1, 1, 0, 0),
4205
+ engine: {
4206
+ calls: 1,
4207
+ rows: 1
4208
+ },
4209
+ writes: 1,
4210
+ check: (device) => expect(device?.status).toBe("registered")
4211
+ }),
4212
+ budget({
4213
+ api: "iOS devices in a build: the row and 1 write each",
4214
+ read: ({ core, approvedDevice }) => core.markIosDevicesInBuild({
4215
+ buildId: createBundleFixture("8012").id,
4216
+ ids: [approvedDevice.id]
4217
+ }),
4218
+ adapter: reads(1, 1, 0, 0),
4219
+ engine: {
4220
+ calls: 1,
4221
+ rows: 1
4222
+ },
4223
+ writes: 1
4224
+ }),
4225
+ budget({
4226
+ api: "iOS device delete: the row and 1 write",
4227
+ read: ({ core, pendingDevice }) => core.deleteIosDevice(pendingDevice.id),
4228
+ adapter: reads(1, 1, 0, 0),
4229
+ engine: {
4230
+ calls: 1,
4231
+ rows: 1
4232
+ },
4233
+ writes: 1,
4234
+ check: (device) => expect(device?.udid).toBe(BUDGET_PENDING_UDID)
4235
+ }),
4236
+ budget({
4237
+ api: "iOS device account, first claim: its one row's read, the registry's rows once, and 1 write",
4238
+ read: ({ core }) => core.claimIosDeviceAccount("issuer-a"),
4239
+ adapter: reads(1, 1, 1, 2),
4240
+ engine: {
4241
+ calls: 2,
4242
+ rows: 2
4243
+ },
4244
+ writes: 1,
4245
+ check: (claim) => expect(claim).toEqual({
4246
+ issuerId: "issuer-a",
4247
+ claimed: true
4248
+ })
4249
+ }),
4250
+ budget({
4251
+ api: "iOS device account, claimed: its one row's read",
4252
+ read: ({ core }) => core.claimIosDeviceAccount("issuer-b"),
4253
+ adapter: reads(1, 1, 0, 0),
4254
+ engine: {
4255
+ calls: 1,
4256
+ rows: 1
4257
+ },
4258
+ check: (claim) => expect(claim).toEqual({
4259
+ issuerId: "issuer-a",
4260
+ claimed: false
4261
+ })
4262
+ }),
3709
4263
  budget({
3710
4264
  api: "record an insights event: 2 dependent rounds of batch gets and 1 write",
3711
4265
  read: ({ insights }) => insights.recordEvent(eventOf(27, {
@@ -3970,8 +4524,8 @@ const snapshot = async (db) => {
3970
4524
  };
3971
4525
  /**
3972
4526
  * 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.
4527
+ * writes with each transaction and a compaction merges once, read back
4528
+ * exactly as transactional writes read.
3975
4529
  */
3976
4530
  const setupAggregateBatchingTestSuite = ({ name, createAdapter, oversizedRows }) => {
3977
4531
  const tables = [...toolingTargetOf([plugin]).schema.tables, ...aggregateBatchingTables];
@@ -4007,21 +4561,15 @@ const setupAggregateBatchingTestSuite = ({ name, createAdapter, oversizedRows })
4007
4561
  afterEach(async () => {
4008
4562
  for (const cleanup of cleanups.splice(0)) await cleanup();
4009
4563
  });
4010
- for (const mode of ["log", "memory"]) it(`reads what transactional writes read, in ${mode} mode`, async () => {
4011
- const { db } = server(await store(), { mode });
4564
+ it("reads what transactional writes read", async () => {
4565
+ const { db } = server(await store(), {});
4012
4566
  for (let step = 0; step < 36; step += 1) await open(db, step);
4013
4567
  expect(await snapshot(db)).toEqual(await expected(36));
4014
4568
  }, 12e4);
4015
4569
  it("applies each log row once when two servers compact while 16 writers commit", async () => {
4016
4570
  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
- });
4571
+ const first = server(adapter, { windowMs: 0 });
4572
+ const second = server(adapter, { windowMs: 0 });
4025
4573
  const report = await runContentionHarness({
4026
4574
  transactions: 12,
4027
4575
  ratePerSecond: 1e3,
@@ -4039,7 +4587,7 @@ const setupAggregateBatchingTestSuite = ({ name, createAdapter, oversizedRows })
4039
4587
  expect(await snapshot(second.db)).toEqual(await expected(48));
4040
4588
  }, 3e5);
4041
4589
  it("applies a log row larger than one write in parts, each change once", async () => {
4042
- const { db, flush } = server(await store(), { mode: "log" });
4590
+ const { db, flush } = server(await store(), {});
4043
4591
  await db.transaction(async (tx) => {
4044
4592
  for (let day = 1; day <= oversizedRows; day += 1) tx.aggregate("opens", { day }, { opens: day }, { shardBy: "i" });
4045
4593
  });
@@ -4231,18 +4779,13 @@ const createPluginTestHarness = async (plugin, options = {}) => {
4231
4779
  * bundles through the engine. A patch's base comes before it in `bundles`.
4232
4780
  */
4233
4781
  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
- }
4782
+ await createEngine(database).core.transaction(async (tx) => {
4783
+ for (const bundle of bundles) {
4784
+ tx.create("bundles", bundleToRow(bundle));
4785
+ for (const platformKey of [bundle.platform, "*"]) tx.aggregate("bundle_totals", { platform_key: platformKey }, { bundles: 1 });
4786
+ for (const row of bundleToPatchRows(bundle)) tx.create("bundle_patches", row);
4787
+ }
4788
+ });
4246
4789
  };
4247
4790
  //#endregion
4248
4791
  //#region src/insights/expectInsightsIndex.ts