@devlab.group/agent-commerce 2.8.0 → 2.9.0

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.
Files changed (67) hide show
  1. package/README.md +19 -17
  2. package/dist/ap2.js +2 -2
  3. package/dist/{chunk-WDD2ZUR3.js → chunk-46Y5M7BA.js} +3 -2
  4. package/dist/chunk-46Y5M7BA.js.map +1 -0
  5. package/dist/{chunk-QZW5YL3G.js → chunk-5Q6W7YTK.js} +3 -3
  6. package/dist/{chunk-QZW5YL3G.js.map → chunk-5Q6W7YTK.js.map} +1 -1
  7. package/dist/{chunk-ENK63GKR.js → chunk-JF45GSNA.js} +3 -3
  8. package/dist/{chunk-ENK63GKR.js.map → chunk-JF45GSNA.js.map} +1 -1
  9. package/dist/{cli/chunk-APC5BTQM.js → chunk-RF3DFVXH.js} +2 -2
  10. package/dist/{chunk-IWXVQYG5.js.map → chunk-RF3DFVXH.js.map} +1 -1
  11. package/dist/cli/{ap2-GYKFGE66.js → ap2-SJZAZQIR.js} +5 -5
  12. package/dist/cli/{ap2-GYKFGE66.js.map → ap2-SJZAZQIR.js.map} +1 -1
  13. package/dist/cli/chunk-25WJIUJU.js +8 -0
  14. package/dist/cli/{chunk-SAAT2XFX.js.map → chunk-25WJIUJU.js.map} +1 -1
  15. package/dist/cli/{chunk-DKWO6LLX.js → chunk-4WPHZLVO.js} +3 -2
  16. package/dist/cli/chunk-4WPHZLVO.js.map +1 -0
  17. package/dist/cli/chunk-IJFPWT4I.js +435 -0
  18. package/dist/cli/chunk-IJFPWT4I.js.map +1 -0
  19. package/dist/cli/{chunk-VWQMSWDF.js → chunk-K34CRXKX.js} +3 -3
  20. package/dist/cli/{chunk-VWQMSWDF.js.map → chunk-K34CRXKX.js.map} +1 -1
  21. package/dist/cli/{chunk-WFIR374D.js → chunk-L264N3ZV.js} +41 -5
  22. package/dist/cli/chunk-L264N3ZV.js.map +1 -0
  23. package/dist/cli/{chunk-SYXLQ5BS.js → chunk-NM7V2Y4I.js} +5 -5
  24. package/dist/cli/{chunk-SYXLQ5BS.js.map → chunk-NM7V2Y4I.js.map} +1 -1
  25. package/dist/cli/{chunk-3PGFOEVJ.js → chunk-SHIA2B6G.js} +32 -6
  26. package/dist/cli/chunk-SHIA2B6G.js.map +1 -0
  27. package/dist/cli/{chunk-YXXPZFWC.js → chunk-U3SEGD4H.js} +126 -18
  28. package/dist/cli/chunk-U3SEGD4H.js.map +1 -0
  29. package/dist/{chunk-IWXVQYG5.js → cli/chunk-UV23DWUY.js} +2 -2
  30. package/dist/cli/{chunk-APC5BTQM.js.map → chunk-UV23DWUY.js.map} +1 -1
  31. package/dist/cli/{config-JWMHWVRT.js → config-IBG46HTQ.js} +6 -6
  32. package/dist/cli/{config-JWMHWVRT.js.map → config-IBG46HTQ.js.map} +1 -1
  33. package/dist/cli/index.js +33 -13
  34. package/dist/cli/index.js.map +1 -1
  35. package/dist/cli/{mcp-OW5GY7TT.js → mcp-F3EQQWDZ.js} +3 -3
  36. package/dist/cli/{mcp-OW5GY7TT.js.map → mcp-F3EQQWDZ.js.map} +1 -1
  37. package/dist/cli/payment-providers-FPTGQBU7.js +6 -0
  38. package/dist/cli/{payment-providers-QL2BJYMD.js.map → payment-providers-FPTGQBU7.js.map} +1 -1
  39. package/dist/cli/{provider-3A2LVEQS.js → provider-XACFJ7MG.js} +4 -4
  40. package/dist/cli/{provider-3A2LVEQS.js.map → provider-XACFJ7MG.js.map} +1 -1
  41. package/dist/cli/receipts-AXCPPGOK.js +9 -0
  42. package/dist/cli/{receipts-FQUFGEQD.js.map → receipts-AXCPPGOK.js.map} +1 -1
  43. package/dist/cli/{run-KF5OQYPL.js → run-C3VWMM57.js} +830 -184
  44. package/dist/cli/run-C3VWMM57.js.map +1 -0
  45. package/dist/cli/{x402-5A7CVCIJ.js → x402-SUXWULOP.js} +5 -5
  46. package/dist/cli/{x402-5A7CVCIJ.js.map → x402-SUXWULOP.js.map} +1 -1
  47. package/dist/index.d.ts +74 -31
  48. package/dist/index.js +1290 -255
  49. package/dist/index.js.map +1 -1
  50. package/dist/mcp.js +1 -1
  51. package/dist/mpp.js +2 -2
  52. package/dist/{store-BzgwHOPu.d.ts → store-04pazhFP.d.ts} +52 -1
  53. package/dist/testing.js +468 -273
  54. package/dist/testing.js.map +1 -1
  55. package/dist/x402.js +3 -3
  56. package/package.json +1 -1
  57. package/dist/chunk-WDD2ZUR3.js.map +0 -1
  58. package/dist/cli/chunk-3PGFOEVJ.js.map +0 -1
  59. package/dist/cli/chunk-6BWEHQPJ.js +0 -215
  60. package/dist/cli/chunk-6BWEHQPJ.js.map +0 -1
  61. package/dist/cli/chunk-DKWO6LLX.js.map +0 -1
  62. package/dist/cli/chunk-SAAT2XFX.js +0 -8
  63. package/dist/cli/chunk-WFIR374D.js.map +0 -1
  64. package/dist/cli/chunk-YXXPZFWC.js.map +0 -1
  65. package/dist/cli/payment-providers-QL2BJYMD.js +0 -6
  66. package/dist/cli/receipts-FQUFGEQD.js +0 -9
  67. package/dist/cli/run-KF5OQYPL.js.map +0 -1
package/dist/testing.js CHANGED
@@ -1,8 +1,8 @@
1
- import { PAYMENT_KEY_ENDPOINT_PREFIX } from './chunk-IWXVQYG5.js';
2
- import { STORE_METHOD_GROUPS } from './chunk-WDD2ZUR3.js';
1
+ import { PAYMENT_KEY_ENDPOINT_PREFIX } from './chunk-RF3DFVXH.js';
2
+ import { STORE_METHOD_GROUPS } from './chunk-46Y5M7BA.js';
3
3
  import { transactionState } from './chunk-MDOGXTZD.js';
4
4
  import './chunk-2CJNA7MS.js';
5
- import assert2 from 'assert/strict';
5
+ import assert3 from 'assert/strict';
6
6
 
7
7
  var START_MS = Date.parse("2026-01-01T00:00:00.000Z");
8
8
  function createConformanceClock() {
@@ -21,7 +21,7 @@ function isoAt(offsetMs) {
21
21
  }
22
22
  async function rejectsWithCode(promise, code) {
23
23
  let caught;
24
- await assert2.rejects(promise, (error) => {
24
+ await assert3.rejects(promise, (error) => {
25
25
  caught = error;
26
26
  return typeof error === "object" && error !== null && "code" in error && error.code === code;
27
27
  });
@@ -146,23 +146,23 @@ var RESOLUTION = {
146
146
  evidence: { blockNumber: 12 }
147
147
  };
148
148
  function defined(value, what) {
149
- assert2.ok(value !== void 0, `${what} was not found`);
149
+ assert3.ok(value !== void 0, `${what} was not found`);
150
150
  return value;
151
151
  }
152
152
  function only(items, what) {
153
- assert2.equal(items.length, 1, what);
153
+ assert3.equal(items.length, 1, what);
154
154
  return defined(items[0], what);
155
155
  }
156
156
  var ids = (items) => items.map((item) => item.id);
157
157
  function assertFiltered(actual, filtered, unfiltered) {
158
158
  try {
159
- assert2.deepEqual(actual, unfiltered);
159
+ assert3.deepEqual(actual, unfiltered);
160
160
  } catch {
161
- assert2.deepEqual(actual, filtered);
161
+ assert3.deepEqual(actual, filtered);
162
162
  }
163
163
  }
164
164
  function assertIso(value) {
165
- assert2.equal(new Date(value).toISOString(), value);
165
+ assert3.equal(new Date(value).toISOString(), value);
166
166
  }
167
167
  async function attemptFor(store, replayKey) {
168
168
  const attempts = (await store.listPaymentAttempts()).filter((a) => a.replayKey === replayKey);
@@ -181,7 +181,7 @@ function reportedStatus(error) {
181
181
  }
182
182
  function assertReportedStatus(error, holder) {
183
183
  const reported = reportedStatus(error);
184
- if (reported !== void 0) assert2.equal(reported, holder);
184
+ if (reported !== void 0) assert3.equal(reported, holder);
185
185
  }
186
186
  async function expectReplayed(call, holder) {
187
187
  assertReportedStatus(await rejectsWithCode(call, "PAYMENT_REPLAYED"), holder);
@@ -196,16 +196,16 @@ async function settle(calls) {
196
196
  return { won, lost };
197
197
  }
198
198
  function soleWinner(outcome) {
199
- assert2.equal(outcome.won.length, 1, "exactly one reservation must succeed");
200
- assert2.equal(outcome.lost.length, RACERS - 1);
199
+ assert3.equal(outcome.won.length, 1, "exactly one reservation must succeed");
200
+ assert3.equal(outcome.lost.length, RACERS - 1);
201
201
  for (const error of outcome.lost) {
202
- assert2.equal(codeOf(error), "PAYMENT_REPLAYED");
202
+ assert3.equal(codeOf(error), "PAYMENT_REPLAYED");
203
203
  assertReportedStatus(error, "reserved");
204
204
  }
205
205
  return defined(outcome.won[0], "the winning reservation");
206
206
  }
207
207
  function journalOf(store) {
208
- const unsupported = (name) => assert2.fail(`the store does not implement ${name}`);
208
+ const unsupported = (name) => assert3.fail(`the store does not implement ${name}`);
209
209
  return {
210
210
  record: (step) => store.recordTransactionStep?.(step) ?? unsupported("recordTransactionStep"),
211
211
  get: (id) => store.getTransaction?.(id) ?? unsupported("getTransaction"),
@@ -222,8 +222,8 @@ async function attemptById(journal, id) {
222
222
  }
223
223
  function assertState(tx, facts, now) {
224
224
  const expected = transactionState(facts, now);
225
- assert2.equal(tx.state, expected);
226
- assert2.equal(transactionState(tx, now), expected);
225
+ assert3.equal(tx.state, expected);
226
+ assert3.equal(transactionState(tx, now), expected);
227
227
  }
228
228
  async function walk(journal, options = {}) {
229
229
  const pages = [];
@@ -233,7 +233,7 @@ async function walk(journal, options = {}) {
233
233
  pages.push(page);
234
234
  cursor = page.nextCursor;
235
235
  } while (cursor !== void 0 && pages.length < MAX_PAGES);
236
- assert2.equal(cursor, void 0, "pagination did not end");
236
+ assert3.equal(cursor, void 0, "pagination did not end");
237
237
  return pages;
238
238
  }
239
239
  async function listAll(journal, options = {}) {
@@ -253,8 +253,8 @@ var RECEIPT_CASES = [
253
253
  name: "a receipt reads back with every field it was saved with",
254
254
  async run({ store }) {
255
255
  await store.saveReceipt(FULL_RECEIPT);
256
- assert2.deepEqual(await store.getReceipt(FULL_RECEIPT.id), FULL_RECEIPT);
257
- assert2.deepEqual(await store.listReceipts(), [FULL_RECEIPT]);
256
+ assert3.deepEqual(await store.getReceipt(FULL_RECEIPT.id), FULL_RECEIPT);
257
+ assert3.deepEqual(await store.listReceipts(), [FULL_RECEIPT]);
258
258
  }
259
259
  },
260
260
  {
@@ -262,15 +262,15 @@ var RECEIPT_CASES = [
262
262
  async run({ store }) {
263
263
  const minimal = receipt("receipt_min");
264
264
  await store.saveReceipt(minimal);
265
- assert2.deepEqual(await store.getReceipt(minimal.id), minimal);
265
+ assert3.deepEqual(await store.getReceipt(minimal.id), minimal);
266
266
  }
267
267
  },
268
268
  {
269
269
  name: "a receipt id nobody saved reads back as undefined",
270
270
  async run({ store }) {
271
- assert2.equal(await store.getReceipt("receipt_missing"), void 0);
271
+ assert3.equal(await store.getReceipt("receipt_missing"), void 0);
272
272
  await store.saveReceipt(receipt("receipt_1"));
273
- assert2.equal(await store.getReceipt("receipt_missing"), void 0);
273
+ assert3.equal(await store.getReceipt("receipt_missing"), void 0);
274
274
  }
275
275
  },
276
276
  {
@@ -280,8 +280,8 @@ var RECEIPT_CASES = [
280
280
  await store.saveReceipt(receipt(id, { deliveredAt: clock.nowIso() }));
281
281
  clock.advance(1e3);
282
282
  }
283
- assert2.deepEqual(ids(await store.listReceipts()), ["r3", "r2", "r1"]);
284
- assert2.deepEqual(ids(await store.listReceipts({ limit: 2 })), ["r3", "r2"]);
283
+ assert3.deepEqual(ids(await store.listReceipts()), ["r3", "r2", "r1"]);
284
+ assert3.deepEqual(ids(await store.listReceipts({ limit: 2 })), ["r3", "r2"]);
285
285
  }
286
286
  },
287
287
  {
@@ -295,8 +295,8 @@ var RECEIPT_CASES = [
295
295
  await store.saveReceipt(receipt(id, { requestId, deliveredAt: clock.nowIso() }));
296
296
  clock.advance(1e3);
297
297
  }
298
- assert2.deepEqual(ids(await store.listReceipts({ requestId: "req_a" })), ["r3", "r1"]);
299
- assert2.deepEqual(await store.listReceipts({ requestId: "req_unknown" }), []);
298
+ assert3.deepEqual(ids(await store.listReceipts({ requestId: "req_a" })), ["r3", "r1"]);
299
+ assert3.deepEqual(await store.listReceipts({ requestId: "req_unknown" }), []);
300
300
  }
301
301
  },
302
302
  {
@@ -319,7 +319,7 @@ var RECEIPT_CASES = [
319
319
  clock.advance(1e3);
320
320
  }
321
321
  const all = ids(await store.listReceipts());
322
- assert2.equal(all.length, saved.length);
322
+ assert3.equal(all.length, saved.length);
323
323
  assertFiltered(
324
324
  ids(await store.listReceipts({ undelivered: true })),
325
325
  ["bad_500", "bad_404", "bad_300", "bad_199", "bad_0"],
@@ -335,8 +335,8 @@ var RECEIPT_CASES = [
335
335
  {
336
336
  name: "receipt counts match what was saved",
337
337
  async run({ store, clock }) {
338
- assert2.equal(await store.countReceipts(), 0);
339
- assert2.equal(await store.countUndeliveredReceipts(), 0);
338
+ assert3.equal(await store.countReceipts(), 0);
339
+ assert3.equal(await store.countUndeliveredReceipts(), 0);
340
340
  for (const [id, backendStatus] of [
341
341
  ["r1", 200],
342
342
  ["r2", 500],
@@ -345,11 +345,11 @@ var RECEIPT_CASES = [
345
345
  await store.saveReceipt(receipt(id, { backendStatus, deliveredAt: clock.nowIso() }));
346
346
  clock.advance(1e3);
347
347
  }
348
- assert2.equal(await store.countReceipts(), 3);
349
- assert2.equal(await store.countUndeliveredReceipts(), 2);
348
+ assert3.equal(await store.countReceipts(), 3);
349
+ assert3.equal(await store.countUndeliveredReceipts(), 2);
350
350
  await store.saveReceipt(receipt("r4", { backendStatus: 204, deliveredAt: clock.nowIso() }));
351
- assert2.equal(await store.countReceipts(), 4);
352
- assert2.equal(await store.countUndeliveredReceipts(), 2);
351
+ assert3.equal(await store.countReceipts(), 4);
352
+ assert3.equal(await store.countUndeliveredReceipts(), 2);
353
353
  }
354
354
  }
355
355
  ];
@@ -358,7 +358,7 @@ var EVENT_CASES = [
358
358
  name: "an event reads back with every field it was appended with",
359
359
  async run({ store }) {
360
360
  await store.appendEvent(FULL_EVENT);
361
- assert2.deepEqual(await store.listEvents(), [FULL_EVENT]);
361
+ assert3.deepEqual(await store.listEvents(), [FULL_EVENT]);
362
362
  }
363
363
  },
364
364
  {
@@ -366,7 +366,7 @@ var EVENT_CASES = [
366
366
  async run({ store }) {
367
367
  const minimal = event("event_min");
368
368
  await store.appendEvent(minimal);
369
- assert2.deepEqual(await store.listEvents(), [minimal]);
369
+ assert3.deepEqual(await store.listEvents(), [minimal]);
370
370
  }
371
371
  },
372
372
  {
@@ -376,7 +376,7 @@ var EVENT_CASES = [
376
376
  await store.appendEvent(event(id, { at: clock.nowIso() }));
377
377
  clock.advance(1e3);
378
378
  }
379
- assert2.deepEqual(ids(await store.listEvents()), ["e3", "e2", "e1"]);
379
+ assert3.deepEqual(ids(await store.listEvents()), ["e3", "e2", "e1"]);
380
380
  }
381
381
  },
382
382
  {
@@ -390,8 +390,8 @@ var EVENT_CASES = [
390
390
  await store.appendEvent(event(id, { requestId, at: clock.nowIso() }));
391
391
  clock.advance(1e3);
392
392
  }
393
- assert2.deepEqual(ids(await store.listEvents({ requestId: "req_a" })), ["e3", "e1"]);
394
- assert2.deepEqual(await store.listEvents({ requestId: "req_unknown" }), []);
393
+ assert3.deepEqual(ids(await store.listEvents({ requestId: "req_a" })), ["e3", "e1"]);
394
+ assert3.deepEqual(await store.listEvents({ requestId: "req_unknown" }), []);
395
395
  }
396
396
  },
397
397
  {
@@ -402,8 +402,8 @@ var EVENT_CASES = [
402
402
  clock.advance(1e3);
403
403
  await store.appendEvent(event("event_2", { at: clock.nowIso() }));
404
404
  const listed = ids(await store.listEvents());
405
- assert2.ok(listed.includes("event_1"));
406
- assert2.ok(listed.includes("event_2"));
405
+ assert3.ok(listed.includes("event_1"));
406
+ assert3.ok(listed.includes("event_2"));
407
407
  }
408
408
  }
409
409
  ];
@@ -414,10 +414,10 @@ var ATTEMPT_CASES = [
414
414
  const withParties = await store.reservePaymentAttempt(
415
415
  reservation(1, { payer: "0xbuyer", payee: "0xmerchant" })
416
416
  );
417
- assert2.ok(withParties.id !== "");
417
+ assert3.ok(withParties.id !== "");
418
418
  assertIso(withParties.createdAt);
419
419
  assertIso(withParties.updatedAt);
420
- assert2.deepEqual(withParties, {
420
+ assert3.deepEqual(withParties, {
421
421
  id: withParties.id,
422
422
  requestId: "req_1",
423
423
  resourceId: "resource.report",
@@ -432,7 +432,7 @@ var ATTEMPT_CASES = [
432
432
  updatedAt: withParties.updatedAt
433
433
  });
434
434
  const bare = await store.reservePaymentAttempt(reservation(2));
435
- assert2.deepEqual(bare, {
435
+ assert3.deepEqual(bare, {
436
436
  id: bare.id,
437
437
  requestId: "req_2",
438
438
  resourceId: "resource.report",
@@ -444,9 +444,9 @@ var ATTEMPT_CASES = [
444
444
  createdAt: bare.createdAt,
445
445
  updatedAt: bare.updatedAt
446
446
  });
447
- assert2.notEqual(bare.id, withParties.id);
448
- assert2.deepEqual(await attemptFor(store, "replay_1"), withParties);
449
- assert2.deepEqual(await attemptFor(store, "replay_2"), bare);
447
+ assert3.notEqual(bare.id, withParties.id);
448
+ assert3.deepEqual(await attemptFor(store, "replay_1"), withParties);
449
+ assert3.deepEqual(await attemptFor(store, "replay_2"), bare);
450
450
  }
451
451
  },
452
452
  {
@@ -461,8 +461,8 @@ var ATTEMPT_CASES = [
461
461
  clock.advance(1e3);
462
462
  }
463
463
  const listed = await store.listPaymentAttempts({ requestId: "req_a" });
464
- assert2.deepEqual(listed.map((a) => a.replayKey).sort(), ["replay_1", "replay_3"]);
465
- assert2.deepEqual(await store.listPaymentAttempts({ requestId: "req_unknown" }), []);
464
+ assert3.deepEqual(listed.map((a) => a.replayKey).sort(), ["replay_1", "replay_3"]);
465
+ assert3.deepEqual(await store.listPaymentAttempts({ requestId: "req_unknown" }), []);
466
466
  }
467
467
  },
468
468
  {
@@ -473,8 +473,8 @@ var ATTEMPT_CASES = [
473
473
  clock.advance(1e3);
474
474
  await store.updatePaymentAttempt({ replayKey: "replay_1", status: "verified" });
475
475
  const verified = await attemptFor(store, "replay_1");
476
- assert2.equal(verified.status, "verified");
477
- assert2.deepEqual(
476
+ assert3.equal(verified.status, "verified");
477
+ assert3.deepEqual(
478
478
  { ...verified, status: "reserved", updatedAt: reserved.updatedAt },
479
479
  reserved
480
480
  );
@@ -484,18 +484,18 @@ var ATTEMPT_CASES = [
484
484
  externalReference: "0xtx"
485
485
  });
486
486
  const settled = await attemptFor(store, "replay_1");
487
- assert2.equal(settled.status, "settled");
488
- assert2.equal(settled.externalReference, "0xtx");
489
- assert2.equal((await attemptFor(store, "replay_2")).status, "reserved");
487
+ assert3.equal(settled.status, "settled");
488
+ assert3.equal(settled.externalReference, "0xtx");
489
+ assert3.equal((await attemptFor(store, "replay_2")).status, "reserved");
490
490
  await store.updatePaymentAttempt({
491
491
  replayKey: "replay_2",
492
492
  status: "rejected",
493
493
  rejectionReason: "wrong_amount"
494
494
  });
495
495
  const rejected = await attemptFor(store, "replay_2");
496
- assert2.equal(rejected.status, "rejected");
497
- assert2.equal(rejected.rejectionReason, "wrong_amount");
498
- assert2.deepEqual(await attemptFor(store, "replay_1"), settled);
496
+ assert3.equal(rejected.status, "rejected");
497
+ assert3.equal(rejected.rejectionReason, "wrong_amount");
498
+ assert3.deepEqual(await attemptFor(store, "replay_1"), settled);
499
499
  }
500
500
  },
501
501
  {
@@ -509,15 +509,15 @@ var ATTEMPT_CASES = [
509
509
  });
510
510
  await store.updatePaymentAttempt({ replayKey: "replay_1", status: "settled" });
511
511
  const attempt = await attemptFor(store, "replay_1");
512
- assert2.equal(attempt.status, "settled");
513
- assert2.equal(attempt.externalReference, "0xbroadcast");
512
+ assert3.equal(attempt.status, "settled");
513
+ assert3.equal(attempt.externalReference, "0xbroadcast");
514
514
  }
515
515
  },
516
516
  {
517
517
  name: "uncertain attempts are listed and counted: settlement-uncertain and legacy failed only",
518
518
  async run({ store, clock }) {
519
- assert2.equal(await store.countUncertainPaymentAttempts(), 0);
520
- assert2.deepEqual(await store.listPaymentAttempts({ uncertain: true }), []);
519
+ assert3.equal(await store.countUncertainPaymentAttempts(), 0);
520
+ assert3.deepEqual(await store.listPaymentAttempts({ uncertain: true }), []);
521
521
  for (const [index, status] of ALL_STATUSES.entries()) {
522
522
  const n = index + 1;
523
523
  await store.reservePaymentAttempt(reservation(n, { requestId: `req_${status}` }));
@@ -528,16 +528,16 @@ var ATTEMPT_CASES = [
528
528
  }
529
529
  await store.reservePaymentAttempt(reservation(7, { requestId: "req_failed" }));
530
530
  await moveTo(store, "replay_7", "settlement-uncertain");
531
- assert2.equal(await store.countUncertainPaymentAttempts(), 3);
531
+ assert3.equal(await store.countUncertainPaymentAttempts(), 3);
532
532
  const keys = (attempts) => attempts.map((a) => a.replayKey).sort();
533
533
  const listed = await store.listPaymentAttempts({ uncertain: true });
534
- assert2.equal((await store.listPaymentAttempts()).length, 7);
534
+ assert3.equal((await store.listPaymentAttempts()).length, 7);
535
535
  assertFiltered(
536
536
  keys(listed),
537
537
  ["replay_5", "replay_6", "replay_7"],
538
538
  keys(await store.listPaymentAttempts())
539
539
  );
540
- assert2.equal(listed.find((a) => a.replayKey === "replay_6")?.externalReference, "0xhash");
540
+ assert3.equal(listed.find((a) => a.replayKey === "replay_6")?.externalReference, "0xhash");
541
541
  for (const [requestId, expected] of [
542
542
  ["req_failed", ["replay_5", "replay_7"]],
543
543
  ["req_settled", []]
@@ -563,7 +563,7 @@ var REPLAY_CASES = [
563
563
  ]) {
564
564
  await expectReplayed(store.reservePaymentAttempt(second), "reserved");
565
565
  }
566
- assert2.deepEqual(await store.listPaymentAttempts(), [first]);
566
+ assert3.deepEqual(await store.listPaymentAttempts(), [first]);
567
567
  }
568
568
  },
569
569
  {
@@ -588,28 +588,28 @@ var REPLAY_CASES = [
588
588
  (_, i) => store.reservePaymentAttempt(reservation(i, { replayKey: "replay_race" }))
589
589
  );
590
590
  const winner = soleWinner(await settle(calls));
591
- assert2.equal(winner.status, "reserved");
592
- assert2.deepEqual(await store.listPaymentAttempts(), [winner]);
591
+ assert3.equal(winner.status, "reserved");
592
+ assert3.deepEqual(await store.listPaymentAttempts(), [winner]);
593
593
  }
594
594
  },
595
595
  {
596
596
  name: "findPaymentAttemptByReplayKey reads the live attempt holding a key",
597
597
  uses: ["findPaymentAttemptByReplayKey"],
598
598
  async run({ store, clock }) {
599
- const find = (replayKey) => store.findPaymentAttemptByReplayKey?.(replayKey) ?? assert2.fail("the store does not implement findPaymentAttemptByReplayKey");
599
+ const find = (replayKey) => store.findPaymentAttemptByReplayKey?.(replayKey) ?? assert3.fail("the store does not implement findPaymentAttemptByReplayKey");
600
600
  const first = await store.reservePaymentAttempt(reservation(1));
601
601
  const second = await store.reservePaymentAttempt(reservation(2));
602
- assert2.deepEqual(await find("replay_1"), first);
603
- assert2.deepEqual(await find("replay_2"), second);
604
- assert2.equal(await find("replay_missing"), void 0);
602
+ assert3.deepEqual(await find("replay_1"), first);
603
+ assert3.deepEqual(await find("replay_2"), second);
604
+ assert3.equal(await find("replay_missing"), void 0);
605
605
  clock.advance(1e3);
606
606
  await moveTo(store, "replay_1", "settlement-uncertain");
607
- assert2.deepEqual(await find("replay_1"), await attemptFor(store, "replay_1"));
607
+ assert3.deepEqual(await find("replay_1"), await attemptFor(store, "replay_1"));
608
608
  await moveTo(store, "replay_2", "rejected", { rejectionReason: "backend_failed" });
609
609
  const reclaimed = await store.reservePaymentAttempt(
610
610
  reservation(3, { replayKey: "replay_2", reclaimRejected: true })
611
611
  );
612
- assert2.deepEqual(await find("replay_2"), reclaimed);
612
+ assert3.deepEqual(await find("replay_2"), reclaimed);
613
613
  }
614
614
  }
615
615
  ];
@@ -626,7 +626,7 @@ var RECLAIM_CASES = [
626
626
  const reclaimed = await store.reservePaymentAttempt(
627
627
  reservation(2, { replayKey: "replay_1", payer: "0xsecond", reclaimRejected: true })
628
628
  );
629
- assert2.deepEqual(reclaimed, {
629
+ assert3.deepEqual(reclaimed, {
630
630
  id: reclaimed.id,
631
631
  requestId: "req_2",
632
632
  resourceId: "resource.report",
@@ -639,7 +639,7 @@ var RECLAIM_CASES = [
639
639
  createdAt: reclaimed.createdAt,
640
640
  updatedAt: reclaimed.updatedAt
641
641
  });
642
- assert2.deepEqual(await store.listPaymentAttempts(), [reclaimed]);
642
+ assert3.deepEqual(await store.listPaymentAttempts(), [reclaimed]);
643
643
  await expectReplayed(
644
644
  store.reservePaymentAttempt(
645
645
  reservation(3, { replayKey: "replay_1", reclaimRejected: true })
@@ -650,16 +650,16 @@ var RECLAIM_CASES = [
650
650
  const again = await store.reservePaymentAttempt(
651
651
  reservation(4, { replayKey: "replay_1", reclaimRejected: true })
652
652
  );
653
- assert2.equal(again.requestId, "req_4");
654
- assert2.equal(again.status, "reserved");
653
+ assert3.equal(again.requestId, "req_4");
654
+ assert3.equal(again.status, "reserved");
655
655
  }
656
656
  },
657
657
  {
658
658
  name: "reclaimRejected on a key nobody holds reserves it as usual",
659
659
  async run({ store }) {
660
660
  const attempt = await store.reservePaymentAttempt(reservation(1, { reclaimRejected: true }));
661
- assert2.equal(attempt.status, "reserved");
662
- assert2.deepEqual(await attemptFor(store, "replay_1"), attempt);
661
+ assert3.equal(attempt.status, "reserved");
662
+ assert3.deepEqual(await attemptFor(store, "replay_1"), attempt);
663
663
  }
664
664
  },
665
665
  {
@@ -678,7 +678,7 @@ var RECLAIM_CASES = [
678
678
  store.reservePaymentAttempt(reservation(3, { replayKey: "replay_1" })),
679
679
  "rejected"
680
680
  );
681
- assert2.deepEqual(await store.listPaymentAttempts(), [rejected]);
681
+ assert3.deepEqual(await store.listPaymentAttempts(), [rejected]);
682
682
  }
683
683
  },
684
684
  {
@@ -696,7 +696,7 @@ var RECLAIM_CASES = [
696
696
  ),
697
697
  status
698
698
  );
699
- assert2.deepEqual(await attemptFor(store, `replay_${n}`), before);
699
+ assert3.deepEqual(await attemptFor(store, `replay_${n}`), before);
700
700
  }
701
701
  }
702
702
  },
@@ -712,8 +712,8 @@ var RECLAIM_CASES = [
712
712
  )
713
713
  );
714
714
  const winner = soleWinner(await settle(calls));
715
- assert2.equal(winner.status, "reserved");
716
- assert2.deepEqual(await store.listPaymentAttempts(), [winner]);
715
+ assert3.equal(winner.status, "reserved");
716
+ assert3.deepEqual(await store.listPaymentAttempts(), [winner]);
717
717
  }
718
718
  }
719
719
  ];
@@ -723,11 +723,11 @@ var JOURNAL_CASES = [
723
723
  uses: ["getTransaction"],
724
724
  async run({ store, clock }) {
725
725
  const attempt = await store.reservePaymentAttempt(fullJournaled(1));
726
- assert2.equal(attempt.transactionId, "txn_1");
726
+ assert3.equal(attempt.transactionId, "txn_1");
727
727
  const tx = await transactionOf(journalOf(store), "txn_1");
728
728
  assertIso(tx.createdAt);
729
729
  assertIso(tx.updatedAt);
730
- assert2.deepEqual(tx, {
730
+ assert3.deepEqual(tx, {
731
731
  id: "txn_1",
732
732
  requestId: "req_1",
733
733
  resourceId: "resource.report",
@@ -767,7 +767,7 @@ var JOURNAL_CASES = [
767
767
  uses: ["listTransactions"],
768
768
  async run({ store }) {
769
769
  await store.reservePaymentAttempt(reservation(1));
770
- assert2.deepEqual(await listAll(journalOf(store)), []);
770
+ assert3.deepEqual(await listAll(journalOf(store)), []);
771
771
  }
772
772
  },
773
773
  {
@@ -780,8 +780,8 @@ var JOURNAL_CASES = [
780
780
  store.reservePaymentAttempt(journaled(2, {}, { replayKey: "replay_1" })),
781
781
  "reserved"
782
782
  );
783
- assert2.equal(await journal.get("txn_2"), void 0);
784
- assert2.deepEqual(await listAll(journal), ["txn_1"]);
783
+ assert3.equal(await journal.get("txn_2"), void 0);
784
+ assert3.deepEqual(await listAll(journal), ["txn_1"]);
785
785
  }
786
786
  },
787
787
  {
@@ -793,7 +793,7 @@ var JOURNAL_CASES = [
793
793
  (_, i) => store.reservePaymentAttempt(journaled(i, {}, { replayKey: "replay_race" }))
794
794
  );
795
795
  const winner = soleWinner(await settle(calls));
796
- assert2.deepEqual(await listAll(journalOf(store)), [winner.transactionId]);
796
+ assert3.deepEqual(await listAll(journalOf(store)), [winner.transactionId]);
797
797
  }
798
798
  },
799
799
  {
@@ -808,7 +808,7 @@ var JOURNAL_CASES = [
808
808
  clock.advance(1e3);
809
809
  const settlingAt = clock.nowIso();
810
810
  await journal.record({ transactionId: "txn_1", at: settlingAt, kind: "settling" });
811
- assert2.equal((await read()).payment.settlingAt, settlingAt);
811
+ assert3.equal((await read()).payment.settlingAt, settlingAt);
812
812
  clock.advance(1e3);
813
813
  await store.updatePaymentAttempt({
814
814
  replayKey: "replay_1",
@@ -816,8 +816,8 @@ var JOURNAL_CASES = [
816
816
  externalReference: "0xtx"
817
817
  });
818
818
  let tx = await read();
819
- assert2.equal(tx.payment.status, "settled");
820
- assert2.equal(tx.payment.externalReference, "0xtx");
819
+ assert3.equal(tx.payment.status, "settled");
820
+ assert3.equal(tx.payment.externalReference, "0xtx");
821
821
  assertState(tx, factsOf("settled"), clock.nowIso());
822
822
  await journal.record({
823
823
  transactionId: "txn_1",
@@ -825,7 +825,7 @@ var JOURNAL_CASES = [
825
825
  kind: "hold",
826
826
  hold: "consumed"
827
827
  });
828
- assert2.equal((await read()).authorization?.hold, "consumed");
828
+ assert3.equal((await read()).authorization?.hold, "consumed");
829
829
  clock.advance(1e3);
830
830
  const dispatchedAt = clock.nowIso();
831
831
  await journal.record({
@@ -835,7 +835,7 @@ var JOURNAL_CASES = [
835
835
  deadlineAt
836
836
  });
837
837
  tx = await read();
838
- assert2.deepEqual(tx.backend, { dispatchedAt, deadlineAt });
838
+ assert3.deepEqual(tx.backend, { dispatchedAt, deadlineAt });
839
839
  assertState(
840
840
  tx,
841
841
  factsOf("settled", { backend: { dispatchedAt, deadlineAt } }),
@@ -850,7 +850,7 @@ var JOURNAL_CASES = [
850
850
  });
851
851
  tx = await read();
852
852
  const backend = { dispatchedAt, deadlineAt, status: 200 };
853
- assert2.deepEqual(tx.backend, backend);
853
+ assert3.deepEqual(tx.backend, backend);
854
854
  assertState(tx, factsOf("settled", { backend }), clock.nowIso());
855
855
  await journal.record({
856
856
  transactionId: "txn_1",
@@ -858,7 +858,7 @@ var JOURNAL_CASES = [
858
858
  kind: "receipt",
859
859
  receiptId: "receipt_1"
860
860
  });
861
- assert2.equal((await read()).receiptId, "receipt_1");
861
+ assert3.equal((await read()).receiptId, "receipt_1");
862
862
  clock.advance(1e3);
863
863
  const completedAt = clock.nowIso();
864
864
  await journal.record({
@@ -868,10 +868,10 @@ var JOURNAL_CASES = [
868
868
  persistenceFailures: ["journal"]
869
869
  });
870
870
  tx = await read();
871
- assert2.equal(tx.completedAt, completedAt);
872
- assert2.deepEqual(tx.persistenceFailures, ["journal"]);
871
+ assert3.equal(tx.completedAt, completedAt);
872
+ assert3.deepEqual(tx.persistenceFailures, ["journal"]);
873
873
  assertState(tx, factsOf("settled", { backend, completedAt }), clock.nowIso());
874
- assert2.equal(tx.state, "delivered");
874
+ assert3.equal(tx.state, "delivered");
875
875
  }
876
876
  },
877
877
  {
@@ -908,8 +908,8 @@ var JOURNAL_CASES = [
908
908
  await journal.record({ transactionId: `txn_${n}`, at: completedAt, kind: "completed" });
909
909
  const tx = await transactionOf(journal, `txn_${n}`);
910
910
  const backend = { dispatchedAt, deadlineAt, ...outcome };
911
- assert2.deepEqual(tx.backend, backend);
912
- assert2.equal(tx.completedAt, completedAt);
911
+ assert3.deepEqual(tx.backend, backend);
912
+ assert3.equal(tx.completedAt, completedAt);
913
913
  assertState(tx, factsOf("settled", { backend, completedAt }), clock.nowIso());
914
914
  }
915
915
  }
@@ -926,13 +926,13 @@ var JOURNAL_CASES = [
926
926
  await store.updatePaymentAttempt({ replayKey: `replay_${n}`, status });
927
927
  clock.advance(1e3);
928
928
  const tx = await transactionOf(journal, `txn_${n}`);
929
- assert2.equal(tx.payment.status, status);
929
+ assert3.equal(tx.payment.status, status);
930
930
  assertState(tx, factsOf(status), clock.nowIso());
931
931
  }
932
932
  const stateOf = (status) => transactionState(factsOf(status), clock.nowIso());
933
933
  for (const state of new Set(statuses.map(stateOf))) {
934
934
  const expected = statuses.flatMap((status, index) => stateOf(status) === state ? [`txn_${index + 1}`] : []).reverse();
935
- assert2.deepEqual(await listAll(journal, { state }), expected, state);
935
+ assert3.deepEqual(await listAll(journal, { state }), expected, state);
936
936
  }
937
937
  }
938
938
  },
@@ -946,10 +946,10 @@ var JOURNAL_CASES = [
946
946
  clock.advance(1e3);
947
947
  }
948
948
  const newestFirst = ["txn_5", "txn_4", "txn_3", "txn_2", "txn_1"];
949
- assert2.deepEqual(await listAll(journal), newestFirst);
949
+ assert3.deepEqual(await listAll(journal), newestFirst);
950
950
  const pages = await walk(journal, { limit: 2 });
951
- assert2.ok(pages.every((page) => page.transactions.length <= 2));
952
- assert2.deepEqual(
951
+ assert3.ok(pages.every((page) => page.transactions.length <= 2));
952
+ assert3.deepEqual(
953
953
  pages.flatMap((page) => ids(page.transactions)),
954
954
  newestFirst
955
955
  );
@@ -994,21 +994,21 @@ var JOURNAL_CASES = [
994
994
  completedAt: now
995
995
  });
996
996
  const stateOf = (facts) => transactionState(facts, now);
997
- assert2.deepEqual(await listAll(journal, { requestId: "req_2" }), ["txn_2"]);
998
- assert2.deepEqual(await listAll(journal, { state: stateOf(factsOf("reserved")) }), ["txn_2"]);
999
- assert2.deepEqual(await listAll(journal, { state: stateOf(factsOf("rejected")) }), ["txn_1"]);
1000
- assert2.deepEqual(
997
+ assert3.deepEqual(await listAll(journal, { requestId: "req_2" }), ["txn_2"]);
998
+ assert3.deepEqual(await listAll(journal, { state: stateOf(factsOf("reserved")) }), ["txn_2"]);
999
+ assert3.deepEqual(await listAll(journal, { state: stateOf(factsOf("rejected")) }), ["txn_1"]);
1000
+ assert3.deepEqual(
1001
1001
  await listAll(journal, { state: stateOf(factsOf("settlement-uncertain")) }),
1002
1002
  ["txn_4"]
1003
1003
  );
1004
- assert2.deepEqual(await listAll(journal, { state: stateOf(delivered) }), ["txn_3"]);
1005
- assert2.deepEqual(await listAll(journal, { unresolved: true }), ["txn_5", "txn_4", "txn_2"]);
1006
- assert2.deepEqual(await listAll(journal, { pendingHold: true }), ["txn_4", "txn_2"]);
1007
- assert2.deepEqual(await listAll(journal, { unresolved: true, pendingHold: true }), [
1004
+ assert3.deepEqual(await listAll(journal, { state: stateOf(delivered) }), ["txn_3"]);
1005
+ assert3.deepEqual(await listAll(journal, { unresolved: true }), ["txn_5", "txn_4", "txn_2"]);
1006
+ assert3.deepEqual(await listAll(journal, { pendingHold: true }), ["txn_4", "txn_2"]);
1007
+ assert3.deepEqual(await listAll(journal, { unresolved: true, pendingHold: true }), [
1008
1008
  "txn_4",
1009
1009
  "txn_2"
1010
1010
  ]);
1011
- assert2.deepEqual(await listAll(journal, { unresolved: true, limit: 1 }), [
1011
+ assert3.deepEqual(await listAll(journal, { unresolved: true, limit: 1 }), [
1012
1012
  "txn_5",
1013
1013
  "txn_4",
1014
1014
  "txn_2"
@@ -1022,12 +1022,12 @@ var JOURNAL_CASES = [
1022
1022
  const journal = journalOf(store);
1023
1023
  const first = await store.reservePaymentAttempt(reservation(1));
1024
1024
  const second = await store.reservePaymentAttempt(reservation(2));
1025
- assert2.deepEqual(await attemptById(journal, first.id), first);
1026
- assert2.deepEqual(await attemptById(journal, second.id), second);
1025
+ assert3.deepEqual(await attemptById(journal, first.id), first);
1026
+ assert3.deepEqual(await attemptById(journal, second.id), second);
1027
1027
  clock.advance(1e3);
1028
1028
  await store.updatePaymentAttempt({ replayKey: "replay_1", status: "settled" });
1029
- assert2.deepEqual(await attemptById(journal, first.id), await attemptFor(store, "replay_1"));
1030
- assert2.equal(await journal.attempt("attempt_missing"), void 0);
1029
+ assert3.deepEqual(await attemptById(journal, first.id), await attemptFor(store, "replay_1"));
1030
+ assert3.equal(await journal.attempt("attempt_missing"), void 0);
1031
1031
  }
1032
1032
  },
1033
1033
  {
@@ -1041,23 +1041,23 @@ var JOURNAL_CASES = [
1041
1041
  const reclaimed = await store.reservePaymentAttempt(
1042
1042
  journaled(2, {}, { replayKey: "replay_1", reclaimRejected: true })
1043
1043
  );
1044
- assert2.notEqual(reclaimed.id, replaced.id);
1044
+ assert3.notEqual(reclaimed.id, replaced.id);
1045
1045
  const old = await attemptById(journal, replaced.id);
1046
- assert2.equal(old.requestId, "req_1");
1047
- assert2.equal(old.status, "rejected");
1048
- assert2.equal(old.rejectionReason, "backend_failed");
1049
- assert2.deepEqual(await attemptById(journal, reclaimed.id), reclaimed);
1046
+ assert3.equal(old.requestId, "req_1");
1047
+ assert3.equal(old.status, "rejected");
1048
+ assert3.equal(old.rejectionReason, "backend_failed");
1049
+ assert3.deepEqual(await attemptById(journal, reclaimed.id), reclaimed);
1050
1050
  const oldTx = await transactionOf(journal, "txn_1");
1051
- assert2.equal(oldTx.payment.attemptId, replaced.id);
1052
- assert2.equal(oldTx.payment.status, "rejected");
1051
+ assert3.equal(oldTx.payment.attemptId, replaced.id);
1052
+ assert3.equal(oldTx.payment.status, "rejected");
1053
1053
  assertState(oldTx, factsOf("rejected"), clock.nowIso());
1054
1054
  const newTx = await transactionOf(journal, "txn_2");
1055
- assert2.equal(newTx.payment.attemptId, reclaimed.id);
1056
- assert2.equal(newTx.payment.status, "reserved");
1055
+ assert3.equal(newTx.payment.attemptId, reclaimed.id);
1056
+ assert3.equal(newTx.payment.status, "reserved");
1057
1057
  await store.updatePaymentAttempt({ replayKey: "replay_1", status: "settled" });
1058
- assert2.equal((await transactionOf(journal, "txn_2")).payment.status, "settled");
1059
- assert2.equal((await transactionOf(journal, "txn_1")).payment.status, "rejected");
1060
- assert2.equal((await attemptById(journal, replaced.id)).status, "rejected");
1058
+ assert3.equal((await transactionOf(journal, "txn_2")).payment.status, "settled");
1059
+ assert3.equal((await transactionOf(journal, "txn_1")).payment.status, "rejected");
1060
+ assert3.equal((await attemptById(journal, replaced.id)).status, "rejected");
1061
1061
  }
1062
1062
  }
1063
1063
  ];
@@ -1081,16 +1081,16 @@ var RESOLUTION_CASES = [
1081
1081
  ...outcome,
1082
1082
  resolution: RESOLUTION
1083
1083
  });
1084
- assert2.equal(won, true);
1084
+ assert3.equal(won, true);
1085
1085
  const resolved = await attemptById(journal, attempt.id);
1086
- assert2.equal(resolved.status, outcome.status);
1087
- assert2.deepEqual(resolved.resolution, RESOLUTION);
1086
+ assert3.equal(resolved.status, outcome.status);
1087
+ assert3.deepEqual(resolved.resolution, RESOLUTION);
1088
1088
  if ("rejectionReason" in outcome) {
1089
- assert2.equal(resolved.rejectionReason, outcome.rejectionReason);
1089
+ assert3.equal(resolved.rejectionReason, outcome.rejectionReason);
1090
1090
  }
1091
- assert2.deepEqual(await attemptFor(store, `replay_${n}`), resolved);
1091
+ assert3.deepEqual(await attemptFor(store, `replay_${n}`), resolved);
1092
1092
  const tx = await transactionOf(journal, `txn_${n}`);
1093
- assert2.equal(tx.payment.status, outcome.status);
1093
+ assert3.equal(tx.payment.status, outcome.status);
1094
1094
  assertState(tx, factsOf(outcome.status), clock.nowIso());
1095
1095
  }
1096
1096
  }
@@ -1108,8 +1108,8 @@ var RESOLUTION_CASES = [
1108
1108
  status: "settled",
1109
1109
  resolution: RESOLUTION
1110
1110
  });
1111
- assert2.equal(won, false);
1112
- assert2.deepEqual(await attemptById(journal, attempt.id), before);
1111
+ assert3.equal(won, false);
1112
+ assert3.deepEqual(await attemptById(journal, attempt.id), before);
1113
1113
  assertState(
1114
1114
  await transactionOf(journal, "txn_1"),
1115
1115
  factsOf("settlement-uncertain"),
@@ -1123,7 +1123,7 @@ var RESOLUTION_CASES = [
1123
1123
  async run({ store }) {
1124
1124
  const journal = journalOf(store);
1125
1125
  const attempt = await uncertain(store, 1);
1126
- assert2.equal(
1126
+ assert3.equal(
1127
1127
  await journal.resolve({
1128
1128
  attemptId: attempt.id,
1129
1129
  expectedStatus: "settlement-uncertain",
@@ -1139,8 +1139,8 @@ var RESOLUTION_CASES = [
1139
1139
  status: "rejected",
1140
1140
  resolution: { ...RESOLUTION, method: "manual", actor: "operator" }
1141
1141
  });
1142
- assert2.equal(again, false);
1143
- assert2.deepEqual(await attemptById(journal, attempt.id), resolved);
1142
+ assert3.equal(again, false);
1143
+ assert3.deepEqual(await attemptById(journal, attempt.id), resolved);
1144
1144
  }
1145
1145
  },
1146
1146
  {
@@ -1157,7 +1157,7 @@ var RESOLUTION_CASES = [
1157
1157
  });
1158
1158
  const resolved = await attemptById(journal, attempt.id);
1159
1159
  clock.advance(1e3);
1160
- await assert2.rejects(
1160
+ await assert3.rejects(
1161
1161
  store.updatePaymentAttempt({
1162
1162
  replayKey: "replay_1",
1163
1163
  status: "rejected",
@@ -1165,7 +1165,7 @@ var RESOLUTION_CASES = [
1165
1165
  externalReference: "0xother"
1166
1166
  })
1167
1167
  );
1168
- assert2.deepEqual(await attemptById(journal, attempt.id), resolved);
1168
+ assert3.deepEqual(await attemptById(journal, attempt.id), resolved);
1169
1169
  }
1170
1170
  },
1171
1171
  {
@@ -1185,11 +1185,11 @@ var RESOLUTION_CASES = [
1185
1185
  })
1186
1186
  )
1187
1187
  );
1188
- assert2.equal(results.filter((won) => won).length, 1);
1188
+ assert3.equal(results.filter((won) => won).length, 1);
1189
1189
  const winner = results.indexOf(true);
1190
1190
  const resolved = await attemptById(journal, attempt.id);
1191
- assert2.equal(resolved.resolution?.actor, `actor_${winner}`);
1192
- assert2.equal(resolved.status, winner % 2 === 0 ? "settled" : "rejected");
1191
+ assert3.equal(resolved.resolution?.actor, `actor_${winner}`);
1192
+ assert3.equal(resolved.status, winner % 2 === 0 ? "settled" : "rejected");
1193
1193
  }
1194
1194
  }
1195
1195
  ];
@@ -1212,18 +1212,18 @@ var DURABILITY_CASES = [
1212
1212
  const readAttempts = (target) => Promise.all([1, 2, 3].map((n) => attemptFor(target, `replay_${n}`)));
1213
1213
  const before = await readAttempts(store);
1214
1214
  const reopened = await reopen();
1215
- assert2.deepEqual(await reopened.getReceipt(FULL_RECEIPT.id), FULL_RECEIPT);
1216
- assert2.equal(await reopened.countReceipts(), 2);
1217
- assert2.equal(await reopened.countUndeliveredReceipts(), 1);
1218
- assert2.deepEqual(await reopened.listEvents(), [FULL_EVENT]);
1219
- assert2.deepEqual(await readAttempts(reopened), before);
1220
- assert2.equal(await reopened.countUncertainPaymentAttempts(), 1);
1215
+ assert3.deepEqual(await reopened.getReceipt(FULL_RECEIPT.id), FULL_RECEIPT);
1216
+ assert3.equal(await reopened.countReceipts(), 2);
1217
+ assert3.equal(await reopened.countUndeliveredReceipts(), 1);
1218
+ assert3.deepEqual(await reopened.listEvents(), [FULL_EVENT]);
1219
+ assert3.deepEqual(await readAttempts(reopened), before);
1220
+ assert3.equal(await reopened.countUncertainPaymentAttempts(), 1);
1221
1221
  await expectReplayed(
1222
1222
  reopened.reservePaymentAttempt(reservation(4, { replayKey: "replay_1" })),
1223
1223
  "settled"
1224
1224
  );
1225
1225
  const fresh = await reopened.reservePaymentAttempt(reservation(5));
1226
- assert2.equal(fresh.status, "reserved");
1226
+ assert3.equal(fresh.status, "reserved");
1227
1227
  }
1228
1228
  },
1229
1229
  {
@@ -1294,16 +1294,16 @@ var DURABILITY_CASES = [
1294
1294
  ];
1295
1295
  const listBefore = await listAll(journal);
1296
1296
  const reopened = journalOf(await reopen());
1297
- assert2.deepEqual(
1297
+ assert3.deepEqual(
1298
1298
  [await transactionOf(reopened, "txn_1"), await transactionOf(reopened, "txn_2")],
1299
1299
  txBefore
1300
1300
  );
1301
- assert2.deepEqual(
1301
+ assert3.deepEqual(
1302
1302
  [await attemptById(reopened, first.id), await attemptById(reopened, second.id)],
1303
1303
  attemptsBefore
1304
1304
  );
1305
- assert2.deepEqual(await listAll(reopened), listBefore);
1306
- assert2.deepEqual(listBefore, ["txn_2", "txn_1"]);
1305
+ assert3.deepEqual(await listAll(reopened), listBefore);
1306
+ assert3.deepEqual(listBefore, ["txn_2", "txn_1"]);
1307
1307
  }
1308
1308
  }
1309
1309
  ];
@@ -1321,12 +1321,14 @@ var CLAIMS = STORE_METHOD_GROUPS.idempotency_claims;
1321
1321
  var CLAIM_READS = [...CLAIMS, ...STORE_METHOD_GROUPS.response_redelivery];
1322
1322
  var HOLDS = STORE_METHOD_GROUPS.authorization_holds;
1323
1323
  var TASKS = STORE_METHOD_GROUPS.pending_tasks;
1324
+ var RECORDS = STORE_METHOD_GROUPS.task_records;
1324
1325
  var MINUTE = 6e4;
1325
1326
  var DAY = 24 * 60 * MINUTE;
1326
1327
  var claims = (store) => store;
1327
1328
  var claimReads = (store) => store;
1328
1329
  var holds = (store) => store;
1329
1330
  var tasks = (store) => store;
1331
+ var records = (store) => store;
1330
1332
  var scope = (key, endpoint = "/acp/checkout_sessions") => ({
1331
1333
  deployment: "https://gateway.example",
1332
1334
  endpoint,
@@ -1348,6 +1350,16 @@ var task = (id, fields = {}) => ({
1348
1350
  expiresAt: isoAt(10 * MINUTE),
1349
1351
  ...fields
1350
1352
  });
1353
+ var record = (id, fields = {}) => ({
1354
+ id,
1355
+ protocol: "a2a",
1356
+ groupId: "group-1",
1357
+ state: "TASK_STATE_COMPLETED",
1358
+ updatedAt: isoAt(0),
1359
+ document: { id, status: { state: "TASK_STATE_COMPLETED" }, artifacts: [{ data: { ok: true } }] },
1360
+ expiresAt: isoAt(10 * MINUTE),
1361
+ ...fields
1362
+ });
1351
1363
  var count = (values, predicate) => values.filter(predicate).length;
1352
1364
  var CLAIM_CASES = [
1353
1365
  {
@@ -1355,10 +1367,10 @@ var CLAIM_CASES = [
1355
1367
  uses: CLAIMS,
1356
1368
  async run({ store }) {
1357
1369
  const s = claims(store);
1358
- assert2.deepEqual(await s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY)), {
1370
+ assert3.deepEqual(await s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY)), {
1359
1371
  kind: "reserved"
1360
1372
  });
1361
- assert2.deepEqual(await s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY)), {
1373
+ assert3.deepEqual(await s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY)), {
1362
1374
  kind: "in-flight"
1363
1375
  });
1364
1376
  }
@@ -1374,7 +1386,7 @@ var CLAIM_CASES = [
1374
1386
  await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY));
1375
1387
  await s.updateIdempotencyKey(scope("unknown"), { kind: "unresolved" });
1376
1388
  for (const key of ["running", "done", "unknown"]) {
1377
- assert2.deepEqual(
1389
+ assert3.deepEqual(
1378
1390
  await s.claimIdempotencyKey(scope(key), "other", isoAt(DAY)),
1379
1391
  { kind: "conflict" },
1380
1392
  key
@@ -1390,7 +1402,7 @@ var CLAIM_CASES = [
1390
1402
  const body = { id: "cs_1", line_items: [{ id: "item", quantity: 2 }], note: null };
1391
1403
  await s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY));
1392
1404
  await s.updateIdempotencyKey(scope("k1"), { kind: "completed", status: 201, body });
1393
- assert2.deepEqual(await s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY)), {
1405
+ assert3.deepEqual(await s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY)), {
1394
1406
  kind: "replay",
1395
1407
  status: 201,
1396
1408
  body
@@ -1404,12 +1416,12 @@ var CLAIM_CASES = [
1404
1416
  const s = claims(store);
1405
1417
  await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY));
1406
1418
  await s.updateIdempotencyKey(scope("unknown"), { kind: "unresolved" });
1407
- assert2.deepEqual(await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY)), {
1419
+ assert3.deepEqual(await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY)), {
1408
1420
  kind: "unresolved"
1409
1421
  });
1410
1422
  await s.claimIdempotencyKey(scope("freed"), "fp", isoAt(DAY));
1411
1423
  await s.updateIdempotencyKey(scope("freed"), { kind: "released" });
1412
- assert2.deepEqual(await s.claimIdempotencyKey(scope("freed"), "other", isoAt(DAY)), {
1424
+ assert3.deepEqual(await s.claimIdempotencyKey(scope("freed"), "other", isoAt(DAY)), {
1413
1425
  kind: "reserved"
1414
1426
  });
1415
1427
  }
@@ -1426,7 +1438,7 @@ var CLAIM_CASES = [
1426
1438
  { ...base, endpoint: "/acp/checkout_sessions/cs_1" },
1427
1439
  { ...base, key: "k2" }
1428
1440
  ]) {
1429
- assert2.deepEqual(await s.claimIdempotencyKey(other, "fp", isoAt(DAY)), {
1441
+ assert3.deepEqual(await s.claimIdempotencyKey(other, "fp", isoAt(DAY)), {
1430
1442
  kind: "reserved"
1431
1443
  });
1432
1444
  }
@@ -1443,15 +1455,15 @@ var CLAIM_CASES = [
1443
1455
  await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(MINUTE));
1444
1456
  await s.updateIdempotencyKey(scope("unknown"), { kind: "unresolved" });
1445
1457
  clock.advance(MINUTE - 1);
1446
- assert2.equal((await s.claimIdempotencyKey(scope("done"), "fp", isoAt(DAY))).kind, "replay");
1458
+ assert3.equal((await s.claimIdempotencyKey(scope("done"), "fp", isoAt(DAY))).kind, "replay");
1447
1459
  clock.advance(2);
1448
- assert2.deepEqual(await s.claimIdempotencyKey(scope("done"), "other", isoAt(DAY)), {
1460
+ assert3.deepEqual(await s.claimIdempotencyKey(scope("done"), "other", isoAt(DAY)), {
1449
1461
  kind: "reserved"
1450
1462
  });
1451
- assert2.deepEqual(await s.claimIdempotencyKey(scope("running"), "fp", isoAt(DAY)), {
1463
+ assert3.deepEqual(await s.claimIdempotencyKey(scope("running"), "fp", isoAt(DAY)), {
1452
1464
  kind: "in-flight"
1453
1465
  });
1454
- assert2.deepEqual(await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY)), {
1466
+ assert3.deepEqual(await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY)), {
1455
1467
  kind: "unresolved"
1456
1468
  });
1457
1469
  }
@@ -1461,22 +1473,22 @@ var CLAIM_CASES = [
1461
1473
  uses: CLAIM_READS,
1462
1474
  async run({ store }) {
1463
1475
  const s = claimReads(store);
1464
- assert2.equal(await s.getIdempotencyKey(scope("k1"), "fp"), void 0);
1465
- assert2.deepEqual(await s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY)), {
1476
+ assert3.equal(await s.getIdempotencyKey(scope("k1"), "fp"), void 0);
1477
+ assert3.deepEqual(await s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY)), {
1466
1478
  kind: "reserved"
1467
1479
  });
1468
- assert2.deepEqual(await s.getIdempotencyKey(scope("k1"), "fp"), { kind: "in-flight" });
1469
- assert2.deepEqual(await s.getIdempotencyKey(scope("k1"), "other"), { kind: "conflict" });
1480
+ assert3.deepEqual(await s.getIdempotencyKey(scope("k1"), "fp"), { kind: "in-flight" });
1481
+ assert3.deepEqual(await s.getIdempotencyKey(scope("k1"), "other"), { kind: "conflict" });
1470
1482
  await s.updateIdempotencyKey(scope("k1"), { kind: "unresolved" });
1471
- assert2.deepEqual(await s.getIdempotencyKey(scope("k1"), "fp"), { kind: "unresolved" });
1472
- assert2.deepEqual(await s.getIdempotencyKey(scope("k1"), "other"), { kind: "conflict" });
1483
+ assert3.deepEqual(await s.getIdempotencyKey(scope("k1"), "fp"), { kind: "unresolved" });
1484
+ assert3.deepEqual(await s.getIdempotencyKey(scope("k1"), "other"), { kind: "conflict" });
1473
1485
  await s.claimIdempotencyKey(scope("k2"), "fp", isoAt(DAY));
1474
1486
  await s.updateIdempotencyKey(scope("k2"), {
1475
1487
  kind: "completed",
1476
1488
  status: 201,
1477
1489
  body: { id: "cs_1" }
1478
1490
  });
1479
- assert2.deepEqual(await s.getIdempotencyKey(scope("k2"), "fp"), {
1491
+ assert3.deepEqual(await s.getIdempotencyKey(scope("k2"), "fp"), {
1480
1492
  kind: "replay",
1481
1493
  status: 201,
1482
1494
  body: { id: "cs_1" }
@@ -1494,12 +1506,12 @@ var CLAIM_CASES = [
1494
1506
  await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(MINUTE));
1495
1507
  await s.updateIdempotencyKey(scope("unknown"), { kind: "unresolved" });
1496
1508
  clock.advance(MINUTE - 1);
1497
- assert2.equal((await s.getIdempotencyKey(scope("done"), "fp"))?.kind, "replay");
1509
+ assert3.equal((await s.getIdempotencyKey(scope("done"), "fp"))?.kind, "replay");
1498
1510
  clock.advance(1);
1499
- assert2.equal(await s.getIdempotencyKey(scope("done"), "fp"), void 0);
1500
- assert2.equal(await s.getIdempotencyKey(scope("done"), "other"), void 0);
1501
- assert2.deepEqual(await s.getIdempotencyKey(scope("running"), "fp"), { kind: "in-flight" });
1502
- assert2.deepEqual(await s.getIdempotencyKey(scope("unknown"), "fp"), { kind: "unresolved" });
1511
+ assert3.equal(await s.getIdempotencyKey(scope("done"), "fp"), void 0);
1512
+ assert3.equal(await s.getIdempotencyKey(scope("done"), "other"), void 0);
1513
+ assert3.deepEqual(await s.getIdempotencyKey(scope("running"), "fp"), { kind: "in-flight" });
1514
+ assert3.deepEqual(await s.getIdempotencyKey(scope("unknown"), "fp"), { kind: "unresolved" });
1503
1515
  }
1504
1516
  },
1505
1517
  {
@@ -1513,12 +1525,12 @@ var CLAIM_CASES = [
1513
1525
  await s.claimIdempotencyKey(scope("acp"), "fp", isoAt(MINUTE));
1514
1526
  await s.updateIdempotencyKey(scope("acp"), { kind: "unresolved" });
1515
1527
  clock.advance(MINUTE - 1);
1516
- assert2.deepEqual(await s.getIdempotencyKey(paid, "fp"), { kind: "unresolved" });
1528
+ assert3.deepEqual(await s.getIdempotencyKey(paid, "fp"), { kind: "unresolved" });
1517
1529
  clock.advance(1);
1518
- assert2.equal(await s.getIdempotencyKey(paid, "fp"), void 0);
1519
- assert2.deepEqual(await s.getIdempotencyKey(scope("acp"), "fp"), { kind: "unresolved" });
1520
- assert2.deepEqual(await s.claimIdempotencyKey(paid, "fp", isoAt(DAY)), { kind: "reserved" });
1521
- assert2.deepEqual(await s.claimIdempotencyKey(scope("acp"), "fp", isoAt(DAY)), {
1530
+ assert3.equal(await s.getIdempotencyKey(paid, "fp"), void 0);
1531
+ assert3.deepEqual(await s.getIdempotencyKey(scope("acp"), "fp"), { kind: "unresolved" });
1532
+ assert3.deepEqual(await s.claimIdempotencyKey(paid, "fp", isoAt(DAY)), { kind: "reserved" });
1533
+ assert3.deepEqual(await s.claimIdempotencyKey(scope("acp"), "fp", isoAt(DAY)), {
1522
1534
  kind: "unresolved"
1523
1535
  });
1524
1536
  }
@@ -1529,23 +1541,23 @@ var CLAIM_CASES = [
1529
1541
  async run({ store }) {
1530
1542
  const s = claimReads(store);
1531
1543
  const owned = { kind: "in-flight", owner: "proof-1" };
1532
- assert2.deepEqual(await s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY), "proof-1"), {
1544
+ assert3.deepEqual(await s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY), "proof-1"), {
1533
1545
  kind: "reserved"
1534
1546
  });
1535
- assert2.deepEqual(
1547
+ assert3.deepEqual(
1536
1548
  await s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY), "proof-2"),
1537
1549
  owned
1538
1550
  );
1539
- assert2.deepEqual(await s.getIdempotencyKey(scope("k1"), "fp"), owned);
1540
- assert2.deepEqual(await s.getIdempotencyKey(scope("k1"), "other"), { kind: "conflict" });
1541
- assert2.equal(await s.recoverIdempotencyKeys({ release: false }), 1);
1542
- assert2.deepEqual(await s.getIdempotencyKey(scope("k1"), "fp"), {
1551
+ assert3.deepEqual(await s.getIdempotencyKey(scope("k1"), "fp"), owned);
1552
+ assert3.deepEqual(await s.getIdempotencyKey(scope("k1"), "other"), { kind: "conflict" });
1553
+ assert3.equal(await s.recoverIdempotencyKeys({ release: false }), 1);
1554
+ assert3.deepEqual(await s.getIdempotencyKey(scope("k1"), "fp"), {
1543
1555
  kind: "unresolved",
1544
1556
  owner: "proof-1"
1545
1557
  });
1546
1558
  await s.claimIdempotencyKey(scope("k2"), "fp", isoAt(DAY), "proof-3");
1547
1559
  await s.updateIdempotencyKey(scope("k2"), { kind: "completed", status: 200, body: "ok" });
1548
- assert2.deepEqual(await s.getIdempotencyKey(scope("k2"), "fp"), {
1560
+ assert3.deepEqual(await s.getIdempotencyKey(scope("k2"), "fp"), {
1549
1561
  kind: "replay",
1550
1562
  status: 200,
1551
1563
  body: "ok"
@@ -1561,12 +1573,12 @@ var CLAIM_CASES = [
1561
1573
  await s.claimIdempotencyKey(scope("b"), "fp", isoAt(DAY));
1562
1574
  await s.claimIdempotencyKey(scope("done"), "fp", isoAt(DAY));
1563
1575
  await s.updateIdempotencyKey(scope("done"), { kind: "completed", status: 200, body: 1 });
1564
- assert2.equal(await s.recoverIdempotencyKeys({ release: false }), 2);
1565
- assert2.deepEqual(await s.claimIdempotencyKey(scope("a"), "fp", isoAt(DAY)), {
1576
+ assert3.equal(await s.recoverIdempotencyKeys({ release: false }), 2);
1577
+ assert3.deepEqual(await s.claimIdempotencyKey(scope("a"), "fp", isoAt(DAY)), {
1566
1578
  kind: "unresolved"
1567
1579
  });
1568
- assert2.equal((await s.claimIdempotencyKey(scope("done"), "fp", isoAt(DAY))).kind, "replay");
1569
- assert2.equal(await s.recoverIdempotencyKeys({ release: false }), 0);
1580
+ assert3.equal((await s.claimIdempotencyKey(scope("done"), "fp", isoAt(DAY))).kind, "replay");
1581
+ assert3.equal(await s.recoverIdempotencyKeys({ release: false }), 0);
1570
1582
  }
1571
1583
  },
1572
1584
  {
@@ -1577,11 +1589,11 @@ var CLAIM_CASES = [
1577
1589
  await s.claimIdempotencyKey(scope("a"), "fp", isoAt(DAY));
1578
1590
  await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY));
1579
1591
  await s.updateIdempotencyKey(scope("unknown"), { kind: "unresolved" });
1580
- assert2.equal(await s.recoverIdempotencyKeys({ release: true }), 1);
1581
- assert2.deepEqual(await s.claimIdempotencyKey(scope("a"), "fp", isoAt(DAY)), {
1592
+ assert3.equal(await s.recoverIdempotencyKeys({ release: true }), 1);
1593
+ assert3.deepEqual(await s.claimIdempotencyKey(scope("a"), "fp", isoAt(DAY)), {
1582
1594
  kind: "reserved"
1583
1595
  });
1584
- assert2.deepEqual(await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY)), {
1596
+ assert3.deepEqual(await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY)), {
1585
1597
  kind: "unresolved"
1586
1598
  });
1587
1599
  }
@@ -1594,11 +1606,11 @@ var CLAIM_CASES = [
1594
1606
  const paid = scope("b", "payment:report");
1595
1607
  await s.claimIdempotencyKey(scope("a"), "fp", isoAt(DAY));
1596
1608
  await s.claimIdempotencyKey(paid, "fp", isoAt(DAY));
1597
- assert2.equal(await s.recoverIdempotencyKeys({ release: false }), 2);
1598
- assert2.deepEqual(await s.claimIdempotencyKey(scope("a"), "fp", isoAt(DAY)), {
1609
+ assert3.equal(await s.recoverIdempotencyKeys({ release: false }), 2);
1610
+ assert3.deepEqual(await s.claimIdempotencyKey(scope("a"), "fp", isoAt(DAY)), {
1599
1611
  kind: "unresolved"
1600
1612
  });
1601
- assert2.deepEqual(await s.claimIdempotencyKey(paid, "fp", isoAt(DAY)), {
1613
+ assert3.deepEqual(await s.claimIdempotencyKey(paid, "fp", isoAt(DAY)), {
1602
1614
  kind: "unresolved"
1603
1615
  });
1604
1616
  }
@@ -1614,14 +1626,14 @@ var CLAIM_CASES = [
1614
1626
  await s.claimIdempotencyKey(checkout, "fp", isoAt(DAY));
1615
1627
  await s.claimIdempotencyKey(paid, "fp", isoAt(DAY));
1616
1628
  const marked = { release: false, endpointPrefix: "payment:" };
1617
- assert2.equal(await s.recoverIdempotencyKeys(marked), 1);
1618
- assert2.deepEqual(await s.getIdempotencyKey(paid, "fp"), { kind: "unresolved" });
1619
- assert2.deepEqual(await s.getIdempotencyKey(checkout, "fp"), { kind: "in-flight" });
1629
+ assert3.equal(await s.recoverIdempotencyKeys(marked), 1);
1630
+ assert3.deepEqual(await s.getIdempotencyKey(paid, "fp"), { kind: "unresolved" });
1631
+ assert3.deepEqual(await s.getIdempotencyKey(checkout, "fp"), { kind: "in-flight" });
1620
1632
  await s.claimIdempotencyKey(running, "fp", isoAt(DAY));
1621
- assert2.equal(await s.recoverIdempotencyKeys({ release: true, endpointPrefix: "/" }), 1);
1622
- assert2.equal(await s.getIdempotencyKey(checkout, "fp"), void 0);
1623
- assert2.deepEqual(await s.getIdempotencyKey(running, "fp"), { kind: "in-flight" });
1624
- assert2.deepEqual(await s.getIdempotencyKey(paid, "fp"), { kind: "unresolved" });
1633
+ assert3.equal(await s.recoverIdempotencyKeys({ release: true, endpointPrefix: "/" }), 1);
1634
+ assert3.equal(await s.getIdempotencyKey(checkout, "fp"), void 0);
1635
+ assert3.deepEqual(await s.getIdempotencyKey(running, "fp"), { kind: "in-flight" });
1636
+ assert3.deepEqual(await s.getIdempotencyKey(paid, "fp"), { kind: "unresolved" });
1625
1637
  }
1626
1638
  },
1627
1639
  {
@@ -1634,11 +1646,11 @@ var CLAIM_CASES = [
1634
1646
  const misses = ["%", "payment%", "pay_ent:", "PAYMENT:", "report", "payment:report_12"];
1635
1647
  for (const endpointPrefix of misses) {
1636
1648
  const changed = await s.recoverIdempotencyKeys({ release: true, endpointPrefix });
1637
- assert2.equal(changed, 0, endpointPrefix);
1649
+ assert3.equal(changed, 0, endpointPrefix);
1638
1650
  }
1639
- assert2.deepEqual(await s.getIdempotencyKey(paid, "fp"), { kind: "in-flight" });
1651
+ assert3.deepEqual(await s.getIdempotencyKey(paid, "fp"), { kind: "in-flight" });
1640
1652
  const whole = { release: true, endpointPrefix: "payment:report_1" };
1641
- assert2.equal(await s.recoverIdempotencyKeys(whole), 1);
1653
+ assert3.equal(await s.recoverIdempotencyKeys(whole), 1);
1642
1654
  }
1643
1655
  },
1644
1656
  {
@@ -1649,11 +1661,11 @@ var CLAIM_CASES = [
1649
1661
  const results = await Promise.all(
1650
1662
  Array.from({ length: 8 }, () => s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY)))
1651
1663
  );
1652
- assert2.equal(
1664
+ assert3.equal(
1653
1665
  count(results, (r) => r.kind === "reserved"),
1654
1666
  1
1655
1667
  );
1656
- assert2.equal(
1668
+ assert3.equal(
1657
1669
  count(results, (r) => r.kind === "in-flight"),
1658
1670
  7
1659
1671
  );
@@ -1670,12 +1682,12 @@ var CLAIM_CASES = [
1670
1682
  await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY));
1671
1683
  await s.updateIdempotencyKey(scope("unknown"), { kind: "unresolved" });
1672
1684
  const reopened = claims(await reopen());
1673
- assert2.deepEqual(await reopened.claimIdempotencyKey(scope("done"), "fp", isoAt(DAY)), {
1685
+ assert3.deepEqual(await reopened.claimIdempotencyKey(scope("done"), "fp", isoAt(DAY)), {
1674
1686
  kind: "replay",
1675
1687
  status: 201,
1676
1688
  body: [1]
1677
1689
  });
1678
- assert2.deepEqual(await reopened.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY)), {
1690
+ assert3.deepEqual(await reopened.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY)), {
1679
1691
  kind: "unresolved"
1680
1692
  });
1681
1693
  }
@@ -1687,9 +1699,9 @@ var HOLD_CASES = [
1687
1699
  uses: HOLDS,
1688
1700
  async run({ store }) {
1689
1701
  const s = holds(store);
1690
- assert2.equal(await s.getAuthorizationHoldState("ref1"), void 0);
1691
- assert2.deepEqual(await s.reserveAuthorizationHold(hold2("ref1")), { kind: "reserved" });
1692
- assert2.equal(await s.getAuthorizationHoldState("ref1"), "reserved");
1702
+ assert3.equal(await s.getAuthorizationHoldState("ref1"), void 0);
1703
+ assert3.deepEqual(await s.reserveAuthorizationHold(hold2("ref1")), { kind: "reserved" });
1704
+ assert3.equal(await s.getAuthorizationHoldState("ref1"), "reserved");
1693
1705
  }
1694
1706
  },
1695
1707
  {
@@ -1700,12 +1712,12 @@ var HOLD_CASES = [
1700
1712
  for (const to of ["consumed", "uncertain"]) {
1701
1713
  const ref = `ref-${to}`;
1702
1714
  await s.reserveAuthorizationHold(hold2(ref));
1703
- assert2.deepEqual(await s.reserveAuthorizationHold(hold2(ref, { requestId: "req-2" })), {
1715
+ assert3.deepEqual(await s.reserveAuthorizationHold(hold2(ref, { requestId: "req-2" })), {
1704
1716
  kind: "replayed",
1705
1717
  state: "reserved"
1706
1718
  });
1707
- assert2.equal(await s.transitionAuthorizationHold(ref, to), true);
1708
- assert2.deepEqual(await s.reserveAuthorizationHold(hold2(ref, { requestId: "req-3" })), {
1719
+ assert3.equal(await s.transitionAuthorizationHold(ref, to), true);
1720
+ assert3.deepEqual(await s.reserveAuthorizationHold(hold2(ref, { requestId: "req-3" })), {
1709
1721
  kind: "replayed",
1710
1722
  state: to
1711
1723
  });
@@ -1719,16 +1731,16 @@ var HOLD_CASES = [
1719
1731
  const s = holds(store);
1720
1732
  const shared = { bindingReference: "checkout-jti" };
1721
1733
  await s.reserveAuthorizationHold(hold2("ref1", shared));
1722
- assert2.deepEqual(await s.reserveAuthorizationHold(hold2("ref2", shared)), {
1734
+ assert3.deepEqual(await s.reserveAuthorizationHold(hold2("ref2", shared)), {
1723
1735
  kind: "replayed",
1724
1736
  state: "reserved"
1725
1737
  });
1726
- assert2.equal(await s.getAuthorizationHoldState("ref2"), void 0);
1738
+ assert3.equal(await s.getAuthorizationHoldState("ref2"), void 0);
1727
1739
  await s.transitionAuthorizationHold("ref1", "released");
1728
- assert2.deepEqual(await s.reserveAuthorizationHold(hold2("ref2", shared)), {
1740
+ assert3.deepEqual(await s.reserveAuthorizationHold(hold2("ref2", shared)), {
1729
1741
  kind: "reserved"
1730
1742
  });
1731
- assert2.deepEqual(await s.reserveAuthorizationHold(hold2("ref1", shared)), {
1743
+ assert3.deepEqual(await s.reserveAuthorizationHold(hold2("ref1", shared)), {
1732
1744
  kind: "replayed",
1733
1745
  state: "reserved"
1734
1746
  });
@@ -1741,13 +1753,13 @@ var HOLD_CASES = [
1741
1753
  const s = holds(store);
1742
1754
  await s.reserveAuthorizationHold(hold2("spent"));
1743
1755
  await s.transitionAuthorizationHold("spent", "consumed");
1744
- assert2.equal(await s.transitionAuthorizationHold("spent", "released"), false);
1745
- assert2.equal(await s.transitionAuthorizationHold("spent", "uncertain"), false);
1746
- assert2.equal(await s.getAuthorizationHoldState("spent"), "consumed");
1756
+ assert3.equal(await s.transitionAuthorizationHold("spent", "released"), false);
1757
+ assert3.equal(await s.transitionAuthorizationHold("spent", "uncertain"), false);
1758
+ assert3.equal(await s.getAuthorizationHoldState("spent"), "consumed");
1747
1759
  await s.reserveAuthorizationHold(hold2("freed"));
1748
1760
  await s.transitionAuthorizationHold("freed", "released");
1749
- assert2.equal(await s.transitionAuthorizationHold("freed", "consumed"), false);
1750
- assert2.equal(await s.getAuthorizationHoldState("freed"), "released");
1761
+ assert3.equal(await s.transitionAuthorizationHold("freed", "consumed"), false);
1762
+ assert3.equal(await s.getAuthorizationHoldState("freed"), "released");
1751
1763
  }
1752
1764
  },
1753
1765
  {
@@ -1756,9 +1768,9 @@ var HOLD_CASES = [
1756
1768
  async run({ store }) {
1757
1769
  const s = holds(store);
1758
1770
  await s.reserveAuthorizationHold(hold2("ref1"));
1759
- assert2.equal(await s.transitionAuthorizationHold("ref1", "consumed", "req-ref1"), true);
1760
- assert2.equal(await s.transitionAuthorizationHold("ref1", "consumed", "req-ref1"), true);
1761
- assert2.equal(await s.transitionAuthorizationHold("missing", "released"), false);
1771
+ assert3.equal(await s.transitionAuthorizationHold("ref1", "consumed", "req-ref1"), true);
1772
+ assert3.equal(await s.transitionAuthorizationHold("ref1", "consumed", "req-ref1"), true);
1773
+ assert3.equal(await s.transitionAuthorizationHold("missing", "released"), false);
1762
1774
  }
1763
1775
  },
1764
1776
  {
@@ -1768,9 +1780,9 @@ var HOLD_CASES = [
1768
1780
  const s = holds(store);
1769
1781
  for (const to of ["consumed", "released"]) {
1770
1782
  await s.reserveAuthorizationHold(hold2(to));
1771
- assert2.equal(await s.transitionAuthorizationHold(to, "uncertain"), true);
1772
- assert2.equal(await s.transitionAuthorizationHold(to, to), true);
1773
- assert2.equal(await s.getAuthorizationHoldState(to), to);
1783
+ assert3.equal(await s.transitionAuthorizationHold(to, "uncertain"), true);
1784
+ assert3.equal(await s.transitionAuthorizationHold(to, to), true);
1785
+ assert3.equal(await s.getAuthorizationHoldState(to), to);
1774
1786
  }
1775
1787
  }
1776
1788
  },
@@ -1780,15 +1792,15 @@ var HOLD_CASES = [
1780
1792
  async run({ store }) {
1781
1793
  const s = holds(store);
1782
1794
  await s.reserveAuthorizationHold(hold2("ref1", { requestId: "req-a" }));
1783
- assert2.equal(await s.transitionAuthorizationHold("ref1", "released", "req-a"), true);
1784
- assert2.deepEqual(await s.reserveAuthorizationHold(hold2("ref1", { requestId: "req-b" })), {
1795
+ assert3.equal(await s.transitionAuthorizationHold("ref1", "released", "req-a"), true);
1796
+ assert3.deepEqual(await s.reserveAuthorizationHold(hold2("ref1", { requestId: "req-b" })), {
1785
1797
  kind: "reserved"
1786
1798
  });
1787
- assert2.equal(await s.transitionAuthorizationHold("ref1", "consumed", "req-a"), false);
1788
- assert2.equal(await s.transitionAuthorizationHold("ref1", "uncertain", "req-a"), false);
1789
- assert2.equal(await s.transitionAuthorizationHold("ref1", "released", "req-a"), true);
1790
- assert2.equal(await s.getAuthorizationHoldState("ref1"), "reserved");
1791
- assert2.equal(await s.transitionAuthorizationHold("ref1", "consumed", "req-b"), true);
1799
+ assert3.equal(await s.transitionAuthorizationHold("ref1", "consumed", "req-a"), false);
1800
+ assert3.equal(await s.transitionAuthorizationHold("ref1", "uncertain", "req-a"), false);
1801
+ assert3.equal(await s.transitionAuthorizationHold("ref1", "released", "req-a"), true);
1802
+ assert3.equal(await s.getAuthorizationHoldState("ref1"), "reserved");
1803
+ assert3.equal(await s.transitionAuthorizationHold("ref1", "consumed", "req-b"), true);
1792
1804
  }
1793
1805
  },
1794
1806
  {
@@ -1818,7 +1830,7 @@ var HOLD_CASES = [
1818
1830
  await s.reserveAuthorizationHold(hold2("young", { requestId: "req-young" }));
1819
1831
  clock.advance(MINUTE);
1820
1832
  const orphans = await s.listOrphanAuthorizationHolds({ updatedBefore: isoAt(5 * MINUTE) });
1821
- assert2.deepEqual(orphans, [
1833
+ assert3.deepEqual(orphans, [
1822
1834
  {
1823
1835
  ...hold2("orphan", { requestId: "req-orphan", metadata }),
1824
1836
  state: "reserved",
@@ -1827,7 +1839,7 @@ var HOLD_CASES = [
1827
1839
  }
1828
1840
  ]);
1829
1841
  const all = await s.listOrphanAuthorizationHolds({ updatedBefore: isoAt(11 * MINUTE) });
1830
- assert2.deepEqual(
1842
+ assert3.deepEqual(
1831
1843
  all.map((h) => h.reference),
1832
1844
  ["orphan", "young"]
1833
1845
  );
@@ -1835,7 +1847,7 @@ var HOLD_CASES = [
1835
1847
  updatedBefore: isoAt(11 * MINUTE),
1836
1848
  limit: 1
1837
1849
  });
1838
- assert2.deepEqual(
1850
+ assert3.deepEqual(
1839
1851
  first.map((h) => h.reference),
1840
1852
  ["orphan"]
1841
1853
  );
@@ -1852,11 +1864,11 @@ var HOLD_CASES = [
1852
1864
  (_, i) => s.reserveAuthorizationHold(hold2("ref1", { requestId: `req-${i}` }))
1853
1865
  )
1854
1866
  );
1855
- assert2.equal(
1867
+ assert3.equal(
1856
1868
  count(results, (r) => r.kind === "reserved"),
1857
1869
  1
1858
1870
  );
1859
- assert2.equal(
1871
+ assert3.equal(
1860
1872
  count(results, (r) => r.kind === "replayed"),
1861
1873
  7
1862
1874
  );
@@ -1872,7 +1884,7 @@ var HOLD_CASES = [
1872
1884
  s.reserveAuthorizationHold(hold2("ref1", shared)),
1873
1885
  s.reserveAuthorizationHold(hold2("ref2", shared))
1874
1886
  ]);
1875
- assert2.equal(
1887
+ assert3.equal(
1876
1888
  count(results, (r) => r.kind === "reserved"),
1877
1889
  1
1878
1890
  );
@@ -1888,12 +1900,12 @@ var HOLD_CASES = [
1888
1900
  await s.transitionAuthorizationHold("spent", "consumed");
1889
1901
  await s.reserveAuthorizationHold(hold2("held"));
1890
1902
  const reopened = holds(await reopen());
1891
- assert2.equal(await reopened.getAuthorizationHoldState("spent"), "consumed");
1892
- assert2.deepEqual(await reopened.reserveAuthorizationHold(hold2("spent")), {
1903
+ assert3.equal(await reopened.getAuthorizationHoldState("spent"), "consumed");
1904
+ assert3.deepEqual(await reopened.reserveAuthorizationHold(hold2("spent")), {
1893
1905
  kind: "replayed",
1894
1906
  state: "consumed"
1895
1907
  });
1896
- assert2.deepEqual(
1908
+ assert3.deepEqual(
1897
1909
  await reopened.reserveAuthorizationHold(
1898
1910
  hold2("other", { bindingReference: "binding-of-held" })
1899
1911
  ),
@@ -1909,14 +1921,14 @@ var TASK_CASES = [
1909
1921
  async run({ store }) {
1910
1922
  const s = tasks(store);
1911
1923
  const stored = task("task1", { adapterData: { contextId: "ctx", network: "eip155:8453" } });
1912
- assert2.equal(await s.putPendingTask(stored, { maxTasks: 10 }), true);
1913
- assert2.deepEqual(await s.getPendingTask("task1"), stored);
1914
- assert2.deepEqual(await s.takePendingTask("task1"), stored);
1915
- assert2.equal(await s.getPendingTask("task1"), void 0);
1916
- assert2.equal(await s.takePendingTask("task1"), void 0);
1924
+ assert3.equal(await s.putPendingTask(stored, { maxTasks: 10 }), true);
1925
+ assert3.deepEqual(await s.getPendingTask("task1"), stored);
1926
+ assert3.deepEqual(await s.takePendingTask("task1"), stored);
1927
+ assert3.equal(await s.getPendingTask("task1"), void 0);
1928
+ assert3.equal(await s.takePendingTask("task1"), void 0);
1917
1929
  const plain = task("task2");
1918
1930
  await s.putPendingTask(plain, { maxTasks: 10 });
1919
- assert2.deepEqual(await s.getPendingTask("task2"), plain);
1931
+ assert3.deepEqual(await s.getPendingTask("task2"), plain);
1920
1932
  }
1921
1933
  },
1922
1934
  {
@@ -1927,7 +1939,7 @@ var TASK_CASES = [
1927
1939
  await s.putPendingTask(task("task1"), { maxTasks: 10 });
1928
1940
  const replacement = task("task1", { input: { symbol: "BTC" } });
1929
1941
  await s.putPendingTask(replacement, { maxTasks: 10 });
1930
- assert2.deepEqual(await s.getPendingTask("task1"), replacement);
1942
+ assert3.deepEqual(await s.getPendingTask("task1"), replacement);
1931
1943
  }
1932
1944
  },
1933
1945
  {
@@ -1938,10 +1950,10 @@ var TASK_CASES = [
1938
1950
  const stored = task("task1", { expiresAt: isoAt(MINUTE) });
1939
1951
  await s.putPendingTask(stored, { maxTasks: 10 });
1940
1952
  clock.advance(MINUTE - 1);
1941
- assert2.deepEqual(await s.getPendingTask("task1"), stored);
1953
+ assert3.deepEqual(await s.getPendingTask("task1"), stored);
1942
1954
  clock.advance(2);
1943
- assert2.equal(await s.getPendingTask("task1"), void 0);
1944
- assert2.equal(await s.takePendingTask("task1"), void 0);
1955
+ assert3.equal(await s.getPendingTask("task1"), void 0);
1956
+ assert3.equal(await s.takePendingTask("task1"), void 0);
1945
1957
  }
1946
1958
  },
1947
1959
  {
@@ -1950,14 +1962,14 @@ var TASK_CASES = [
1950
1962
  async run({ store, clock }) {
1951
1963
  const s = tasks(store);
1952
1964
  const soon = { expiresAt: isoAt(MINUTE) };
1953
- assert2.equal(await s.putPendingTask(task("a", soon), { maxTasks: 2 }), true);
1954
- assert2.equal(await s.putPendingTask(task("b", soon), { maxTasks: 2 }), true);
1955
- assert2.equal(await s.putPendingTask(task("c"), { maxTasks: 2 }), false);
1956
- assert2.equal(await s.getPendingTask("c"), void 0);
1965
+ assert3.equal(await s.putPendingTask(task("a", soon), { maxTasks: 2 }), true);
1966
+ assert3.equal(await s.putPendingTask(task("b", soon), { maxTasks: 2 }), true);
1967
+ assert3.equal(await s.putPendingTask(task("c"), { maxTasks: 2 }), false);
1968
+ assert3.equal(await s.getPendingTask("c"), void 0);
1957
1969
  clock.advance(MINUTE + 1);
1958
- assert2.equal(await s.putPendingTask(task("c"), { maxTasks: 2 }), true);
1959
- assert2.equal(await s.putPendingTask(task("d"), { maxTasks: 2 }), true);
1960
- assert2.equal(await s.putPendingTask(task("e"), { maxTasks: 2 }), false);
1970
+ assert3.equal(await s.putPendingTask(task("c"), { maxTasks: 2 }), true);
1971
+ assert3.equal(await s.putPendingTask(task("d"), { maxTasks: 2 }), true);
1972
+ assert3.equal(await s.putPendingTask(task("e"), { maxTasks: 2 }), false);
1961
1973
  }
1962
1974
  },
1963
1975
  {
@@ -1969,7 +1981,7 @@ var TASK_CASES = [
1969
1981
  const results = await Promise.all(
1970
1982
  Array.from({ length: 8 }, () => s.takePendingTask("task1"))
1971
1983
  );
1972
- assert2.equal(
1984
+ assert3.equal(
1973
1985
  count(results, (r) => r !== void 0),
1974
1986
  1
1975
1987
  );
@@ -1984,11 +1996,194 @@ var TASK_CASES = [
1984
1996
  const stored = task("task1", { adapterData: { contextId: "ctx" } });
1985
1997
  await s.putPendingTask(stored, { maxTasks: 10 });
1986
1998
  const reopened = tasks(await reopen());
1987
- assert2.deepEqual(await reopened.takePendingTask("task1"), stored);
1999
+ assert3.deepEqual(await reopened.takePendingTask("task1"), stored);
1988
2000
  }
1989
2001
  }
1990
2002
  ];
1991
- var RECORD_CASES = [...CLAIM_CASES, ...HOLD_CASES, ...TASK_CASES];
2003
+ var ids2 = (list) => list.map((r) => r.id);
2004
+ var TASK_RECORD_CASES = [
2005
+ {
2006
+ name: "a task record reads back by id and lists in its group",
2007
+ uses: RECORDS,
2008
+ async run({ store }) {
2009
+ const s = records(store);
2010
+ const stored = record("rec1");
2011
+ assert3.equal(await s.putTaskRecord(stored, { maxRecords: 10 }), true);
2012
+ assert3.deepEqual(await s.getTaskRecord("rec1"), stored);
2013
+ assert3.deepEqual(await s.listTaskRecords({ protocol: "a2a", groupId: "group-1" }), [stored]);
2014
+ assert3.equal(await s.getTaskRecord("rec2"), void 0);
2015
+ }
2016
+ },
2017
+ {
2018
+ name: "a task record with the same id replaces the earlier one, even at maxRecords",
2019
+ uses: RECORDS,
2020
+ async run({ store }) {
2021
+ const s = records(store);
2022
+ assert3.equal(
2023
+ await s.putTaskRecord(record("rec1", { state: "TASK_STATE_WORKING" }), { maxRecords: 1 }),
2024
+ true
2025
+ );
2026
+ const finished = record("rec1", { updatedAt: isoAt(MINUTE) });
2027
+ assert3.equal(await s.putTaskRecord(finished, { maxRecords: 1 }), true);
2028
+ assert3.deepEqual(await s.getTaskRecord("rec1"), finished);
2029
+ assert3.equal(await s.putTaskRecord(record("rec2"), { maxRecords: 1 }), false);
2030
+ assert3.deepEqual(ids2(await s.listTaskRecords({ protocol: "a2a", groupId: "group-1" })), [
2031
+ "rec1"
2032
+ ]);
2033
+ }
2034
+ },
2035
+ {
2036
+ name: "an expired task record cannot be read or listed",
2037
+ uses: RECORDS,
2038
+ async run({ store, clock }) {
2039
+ const s = records(store);
2040
+ const stored = record("rec1", { expiresAt: isoAt(MINUTE) });
2041
+ await s.putTaskRecord(stored, { maxRecords: 10 });
2042
+ clock.advance(MINUTE - 1);
2043
+ assert3.deepEqual(await s.getTaskRecord("rec1"), stored);
2044
+ clock.advance(2);
2045
+ assert3.equal(await s.getTaskRecord("rec1"), void 0);
2046
+ assert3.deepEqual(await s.listTaskRecords({ protocol: "a2a", groupId: "group-1" }), []);
2047
+ }
2048
+ },
2049
+ {
2050
+ name: "maxRecords refuses a new task record while that many are unexpired",
2051
+ uses: RECORDS,
2052
+ async run({ store, clock }) {
2053
+ const s = records(store);
2054
+ const soon = { expiresAt: isoAt(MINUTE) };
2055
+ assert3.equal(await s.putTaskRecord(record("a", soon), { maxRecords: 2 }), true);
2056
+ assert3.equal(await s.putTaskRecord(record("b", soon), { maxRecords: 2 }), true);
2057
+ assert3.equal(await s.putTaskRecord(record("c"), { maxRecords: 2 }), false);
2058
+ assert3.equal(await s.getTaskRecord("c"), void 0);
2059
+ clock.advance(MINUTE + 1);
2060
+ assert3.equal(await s.putTaskRecord(record("c"), { maxRecords: 2 }), true);
2061
+ assert3.equal(await s.putTaskRecord(record("d"), { maxRecords: 2 }), true);
2062
+ assert3.equal(await s.putTaskRecord(record("e"), { maxRecords: 2 }), false);
2063
+ }
2064
+ },
2065
+ {
2066
+ name: "at maxRecords, a new task record evicts the oldest evictable one",
2067
+ uses: RECORDS,
2068
+ async run({ store }) {
2069
+ const s = records(store);
2070
+ const put = (r) => s.putTaskRecord(r, { maxRecords: 3 });
2071
+ const paid = record("paid", { updatedAt: isoAt(0) });
2072
+ const older = record("older", { updatedAt: isoAt(1), evictable: true });
2073
+ const newer = record("newer", { updatedAt: isoAt(2), evictable: true });
2074
+ assert3.equal(await put(paid), true);
2075
+ assert3.equal(await put(newer), true);
2076
+ assert3.equal(await put(older), true);
2077
+ assert3.deepEqual(await s.getTaskRecord("older"), older);
2078
+ assert3.equal(await put(record("next", { updatedAt: isoAt(3) })), true);
2079
+ assert3.equal(await s.getTaskRecord("older"), void 0);
2080
+ assert3.equal(await put(record("last", { updatedAt: isoAt(4) })), true);
2081
+ assert3.equal(await s.getTaskRecord("newer"), void 0);
2082
+ assert3.equal(await put(record("refused", { evictable: true })), false);
2083
+ assert3.deepEqual(ids2(await s.listTaskRecords({ protocol: "a2a", groupId: "group-1" })), [
2084
+ "last",
2085
+ "next",
2086
+ "paid"
2087
+ ]);
2088
+ }
2089
+ },
2090
+ {
2091
+ name: "a lower maxRecords evicts enough evictable task records for a new one to fit",
2092
+ uses: RECORDS,
2093
+ async run({ store }) {
2094
+ const s = records(store);
2095
+ for (const [i, id] of ["e1", "e2", "e3"].entries()) {
2096
+ await s.putTaskRecord(record(id, { updatedAt: isoAt(i), evictable: true }), {
2097
+ maxRecords: 10
2098
+ });
2099
+ }
2100
+ await s.putTaskRecord(record("paid", { updatedAt: isoAt(0) }), { maxRecords: 10 });
2101
+ assert3.equal(
2102
+ await s.putTaskRecord(record("new", { updatedAt: isoAt(5) }), { maxRecords: 2 }),
2103
+ true
2104
+ );
2105
+ assert3.deepEqual(ids2(await s.listTaskRecords({ protocol: "a2a", groupId: "group-1" })), [
2106
+ "new",
2107
+ "paid"
2108
+ ]);
2109
+ }
2110
+ },
2111
+ {
2112
+ name: "replacing a task record sets whether it is evictable",
2113
+ uses: RECORDS,
2114
+ async run({ store }) {
2115
+ const s = records(store);
2116
+ const put = (r) => s.putTaskRecord(r, { maxRecords: 2 });
2117
+ await put(record("kept", { state: "TASK_STATE_WORKING" }));
2118
+ await put(record("working", { state: "TASK_STATE_WORKING", evictable: true }));
2119
+ await put(record("kept", { evictable: true }));
2120
+ await put(record("working"));
2121
+ assert3.equal(await put(record("new")), true);
2122
+ assert3.equal(await s.getTaskRecord("kept"), void 0);
2123
+ assert3.notEqual(await s.getTaskRecord("working"), void 0);
2124
+ }
2125
+ },
2126
+ {
2127
+ name: "task records list one protocol and group, by updatedAt then id, both descending",
2128
+ uses: RECORDS,
2129
+ async run({ store }) {
2130
+ const s = records(store);
2131
+ const put = (r) => s.putTaskRecord(r, { maxRecords: 10 });
2132
+ await put(record("r1", { updatedAt: isoAt(1) }));
2133
+ await put(record("r2", { updatedAt: isoAt(3) }));
2134
+ await put(record("r3", { updatedAt: isoAt(3) }));
2135
+ await put(record("r4", { updatedAt: isoAt(2), groupId: "group-2" }));
2136
+ await put(record("r5", { updatedAt: isoAt(2), protocol: "mcp" }));
2137
+ assert3.deepEqual(ids2(await s.listTaskRecords({ protocol: "a2a", groupId: "group-1" })), [
2138
+ "r3",
2139
+ "r2",
2140
+ "r1"
2141
+ ]);
2142
+ assert3.deepEqual(ids2(await s.listTaskRecords({ protocol: "a2a", groupId: "group-2" })), [
2143
+ "r4"
2144
+ ]);
2145
+ assert3.deepEqual(ids2(await s.listTaskRecords({ protocol: "mcp", groupId: "group-1" })), [
2146
+ "r5"
2147
+ ]);
2148
+ assert3.deepEqual(await s.listTaskRecords({ protocol: "a2a", groupId: "group-3" }), []);
2149
+ }
2150
+ },
2151
+ {
2152
+ name: "concurrent task record puts at maxRecords store only as many as fit",
2153
+ uses: RECORDS,
2154
+ async run({ store }) {
2155
+ const s = records(store);
2156
+ await s.putTaskRecord(record("first"), { maxRecords: 3 });
2157
+ const results = await Promise.all(
2158
+ Array.from({ length: 8 }, (_, i) => s.putTaskRecord(record(`rec${i}`), { maxRecords: 3 }))
2159
+ );
2160
+ assert3.equal(
2161
+ count(results, (r) => r),
2162
+ 2
2163
+ );
2164
+ const listed = await s.listTaskRecords({ protocol: "a2a", groupId: "group-1" });
2165
+ assert3.equal(listed.length, 3);
2166
+ }
2167
+ },
2168
+ {
2169
+ name: "task records survive a reopen",
2170
+ uses: RECORDS,
2171
+ needsReopen: true,
2172
+ async run({ store, reopen }) {
2173
+ const s = records(store);
2174
+ const stored = record("rec1");
2175
+ await s.putTaskRecord(stored, { maxRecords: 10 });
2176
+ const reopened = records(await reopen());
2177
+ assert3.deepEqual(await reopened.getTaskRecord("rec1"), stored);
2178
+ }
2179
+ }
2180
+ ];
2181
+ var RECORD_CASES = [
2182
+ ...CLAIM_CASES,
2183
+ ...HOLD_CASES,
2184
+ ...TASK_CASES,
2185
+ ...TASK_RECORD_CASES
2186
+ ];
1992
2187
 
1993
2188
  // src/testing/store-conformance.ts
1994
2189
  var METHOD_GROUPS = STORE_METHOD_GROUPS;