@nagi-js/core 0.1.1-rc.24 → 0.1.1-rc.27

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/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { P as Millis, aY as Store, b7 as Tx, ax as StandardSchemaV1 } from './types-B5LHEF3v.js';
1
+ import { P as Millis, aY as Store, b7 as Tx, ax as StandardSchemaV1 } from './types-D2xR9diE.js';
2
2
 
3
3
  declare function passthroughSchema<T>(): StandardSchemaV1<T, T>;
4
4
  interface StoreContractHarness {
package/dist/testing.js CHANGED
@@ -1,4 +1,4 @@
1
- import { InMemoryQueue, Facts, isRunEnd, stepStateOf, stepStatusOf, NagiConcurrencyConflictError } from './chunk-TXWUVL6W.js';
1
+ import { InMemoryQueue, Facts, isRunEnd, stepStateOf, stepStatusOf, NagiConcurrencyConflictError } from './chunk-7SKD73QT.js';
2
2
 
3
3
  // src/testing.ts
4
4
  function passthroughSchema() {
@@ -110,6 +110,13 @@ async function claimableAgain(s, runId, stepId, what) {
110
110
  `${what} must release the lease: claimStep at the same attempt still returns null`
111
111
  );
112
112
  }
113
+ async function leaseReleased(s, runId, stepId, what) {
114
+ eq(
115
+ (await stepView(s, runId, stepId))?.lease,
116
+ void 0,
117
+ `${what} must release the lease`
118
+ );
119
+ }
113
120
  var TRANSPORT_WAIT_MS = 5e3;
114
121
  async function eventually(cond, msg) {
115
122
  const deadline = Date.now() + TRANSPORT_WAIT_MS;
@@ -488,6 +495,33 @@ var storeContract = [
488
495
  ok(await s.claimStep(runId, "s", A2) !== null, "attempt 2");
489
496
  }
490
497
  },
498
+ {
499
+ name: "claimStep: returns null once the step has settled, at any attempt, and leaves no lease",
500
+ async run(h) {
501
+ const s = await h.makeStore({ leaseMs: LEASE_MS });
502
+ const runId = rid();
503
+ await startRun(s, runId);
504
+ const at = /* @__PURE__ */ new Date();
505
+ const settles = [
506
+ Facts.stepCompleted(runId, "done", A1, { v: 1 }, at),
507
+ Facts.stepFailed(runId, "bad", A1, { name: "E", message: "x" }, at),
508
+ Facts.stepCanceled(runId, "gone", A1, at)
509
+ ];
510
+ for (const fact of settles) {
511
+ await startStep(s, runId, fact.stepId);
512
+ await s.appendFact(runId, fact);
513
+ }
514
+ await s.appendFact(
515
+ runId,
516
+ Facts.stepSkipped({ runId, stepId: "never", reason: "when-false", at })
517
+ );
518
+ for (const stepId of ["done", "bad", "gone", "never"]) {
519
+ eq(await s.claimStep(runId, stepId, A1), null, `${stepId}: attempt 1`);
520
+ eq(await s.claimStep(runId, stepId, A2), null, `${stepId}: attempt 2`);
521
+ await leaseReleased(s, runId, stepId, `${stepId}: refused claim`);
522
+ }
523
+ }
524
+ },
491
525
  {
492
526
  name: "extendLease: keeps a live lease claimed past its original expiry",
493
527
  async run(h) {
@@ -509,7 +543,7 @@ var storeContract = [
509
543
  }
510
544
  },
511
545
  {
512
- name: "appendFact(step.completed): releases the lease \u2014 describe() drops lease.expiresAt and claimStep re-acquires",
546
+ name: "appendFact(step.completed): releases the lease \u2014 describe() drops lease.expiresAt",
513
547
  async run(h) {
514
548
  const s = await h.makeStore({ leaseMs: LEASE_MS });
515
549
  const runId = rid();
@@ -526,7 +560,6 @@ var storeContract = [
526
560
  eq(done?.status, "completed", "status");
527
561
  eq(done?.output, { ok: 1 }, "output");
528
562
  eq(done?.lease, void 0, "lease gone from describe()");
529
- await claimableAgain(s, runId, "s", "appendFact(step.completed)");
530
563
  }
531
564
  },
532
565
  {
@@ -549,7 +582,6 @@ var storeContract = [
549
582
  );
550
583
  eq(await stepStatus(s, runId, "s"), "failed", "status");
551
584
  eq((await stepView(s, runId, "s"))?.lease, void 0, "lease");
552
- await claimableAgain(s, runId, "s", "appendFact(step.failed)");
553
585
  }
554
586
  },
555
587
  {
@@ -595,7 +627,7 @@ var storeContract = [
595
627
  c.status,
596
628
  `${c.stepId}: status`
597
629
  );
598
- await claimableAgain(s, runId, c.stepId, `runStep(${c.fact.kind})`);
630
+ await leaseReleased(s, runId, c.stepId, `runStep(${c.fact.kind})`);
599
631
  }
600
632
  }
601
633
  },
@@ -623,6 +655,44 @@ var storeContract = [
623
655
  );
624
656
  }
625
657
  },
658
+ {
659
+ name: "probeAbort (when implemented): agrees with the fold for live, abort-requested and ended runs",
660
+ async run(h) {
661
+ const s = await h.makeStore({ leaseMs: LEASE_MS });
662
+ if (s.probeAbort === void 0) return;
663
+ const live = rid();
664
+ await startRun(s, live);
665
+ await startStep(s, live, "s");
666
+ eq(await s.probeAbort(live, "s", A1), null, "live, no abort");
667
+ await s.appendFact(
668
+ live,
669
+ Facts.stepAbortRequested({
670
+ runId: live,
671
+ stepId: "s",
672
+ attempt: A1,
673
+ at: /* @__PURE__ */ new Date()
674
+ })
675
+ );
676
+ eq(await s.probeAbort(live, "s", A1), "step", "abort requested");
677
+ eq(
678
+ await s.probeAbort(live, "s", A2),
679
+ null,
680
+ "another attempt is not aborted"
681
+ );
682
+ const ended = rid();
683
+ await startRun(s, ended);
684
+ await startStep(s, ended, "s");
685
+ await s.endRun(
686
+ ended,
687
+ Facts.flowCanceled(
688
+ ended,
689
+ { cause: "explicit", reason: "contract" },
690
+ /* @__PURE__ */ new Date()
691
+ )
692
+ );
693
+ eq(await s.probeAbort(ended, "s", A1), "run", "ended run");
694
+ }
695
+ },
626
696
  {
627
697
  name: "runStep: the body reads run state on its tx and sees committed facts",
628
698
  async run(h) {
@@ -668,7 +738,7 @@ var storeContract = [
668
738
  });
669
739
  eq(res.tag, "delivered", "delivered");
670
740
  eq(await stepStatus(s, runId, "gate"), "completed", "status");
671
- await claimableAgain(s, runId, "gate", "settleSignal(deliver)");
741
+ await leaseReleased(s, runId, "gate", "settleSignal(deliver)");
672
742
  eq(
673
743
  await s.sweepSignalTimeouts({ now: new Date(Date.now() + HOUR_MS) }),
674
744
  [],
@@ -704,6 +774,32 @@ var storeContract = [
704
774
  eq(timedOut.length, 1, "timer survived the park");
705
775
  }
706
776
  },
777
+ {
778
+ name: "listQuietRuns: lists a live run with no lease, timer or recent fact, and only that run",
779
+ async run(h) {
780
+ const s = await h.makeStore({ leaseMs: LEASE_MS });
781
+ const quiet = rid();
782
+ const leased = rid();
783
+ const timed = rid();
784
+ for (const r of [quiet, leased, timed]) await startRun(s, r);
785
+ await startStep(s, leased, "a");
786
+ ok(await s.claimStep(leased, "a", A1) !== null, "claim");
787
+ await startStep(s, timed, "gate", { kind: "signal" });
788
+ await s.upsertTimer(timed, "gate", new Date(Date.now() + HOUR_MS));
789
+ const later = new Date(Date.now() + HOUR_MS);
790
+ const listed = await s.listQuietRuns({ quietSince: later, limit: 1e3 });
791
+ ok(listed.includes(quiet), "the quiet run is listed");
792
+ ok(!listed.includes(leased), "a leased run is not quiet");
793
+ ok(!listed.includes(timed), "a run with a timer is not quiet");
794
+ const earlier = new Date(Date.now() - HOUR_MS);
795
+ ok(
796
+ !(await s.listQuietRuns({ quietSince: earlier, limit: 1e3 })).includes(
797
+ quiet
798
+ ),
799
+ "a run with a fact after quietSince is not quiet"
800
+ );
801
+ }
802
+ },
707
803
  {
708
804
  name: "sweepSignalTimeouts: fails an awaiting step past its deadline with NagiSignalTimeoutError, releases its lease, consumes the timer",
709
805
  async run(h) {
@@ -721,7 +817,7 @@ var storeContract = [
721
817
  const step = stepStateOf(await s.loadRunState(runId), "gate");
722
818
  ok(step.tag === "failed", "step failed");
723
819
  eq(step.error.name, "NagiSignalTimeoutError", "error name");
724
- await claimableAgain(s, runId, "gate", "sweepSignalTimeouts");
820
+ await leaseReleased(s, runId, "gate", "sweepSignalTimeouts");
725
821
  eq(
726
822
  await s.sweepSignalTimeouts({ now: /* @__PURE__ */ new Date() }),
727
823
  [],
@@ -739,7 +835,7 @@ var storeContract = [
739
835
  ok(await s.claimStep(runId, "s", A1) !== null, "claim");
740
836
  await s.appendFact(runId, Facts.stepCanceled(runId, "s", A1, /* @__PURE__ */ new Date()));
741
837
  eq(await stepStatus(s, runId, "s"), "canceled", "status");
742
- await claimableAgain(s, runId, "s", "appendFact(step.canceled)");
838
+ await leaseReleased(s, runId, "s", "appendFact(step.canceled)");
743
839
  }
744
840
  },
745
841
  {