@nagi-js/core 0.1.1-rc.23 → 0.1.1-rc.25
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/{chunk-DPTPJZEG.js → chunk-TXWUVL6W.js} +102 -42
- package/dist/chunk-TXWUVL6W.js.map +1 -0
- package/dist/index.d.ts +17 -7
- package/dist/index.js +252 -92
- package/dist/index.js.map +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +303 -3
- package/dist/testing.js.map +1 -1
- package/dist/{types-CezUTCly.d.ts → types-B5LHEF3v.d.ts} +19 -10
- package/package.json +1 -1
- package/dist/chunk-DPTPJZEG.js.map +0 -1
package/dist/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as Millis,
|
|
1
|
+
import { P as Millis, aY as Store, b7 as Tx, ax as StandardSchemaV1 } from './types-B5LHEF3v.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 { Facts, isRunEnd, stepStateOf,
|
|
1
|
+
import { InMemoryQueue, Facts, isRunEnd, stepStateOf, stepStatusOf, NagiConcurrencyConflictError } from './chunk-TXWUVL6W.js';
|
|
2
2
|
|
|
3
3
|
// src/testing.ts
|
|
4
4
|
function passthroughSchema() {
|
|
@@ -261,6 +261,67 @@ var storeContract = [
|
|
|
261
261
|
);
|
|
262
262
|
}
|
|
263
263
|
},
|
|
264
|
+
{
|
|
265
|
+
name: "tryStartRun: a seed is enqueued with the start, once",
|
|
266
|
+
async run(h) {
|
|
267
|
+
const s = await h.makeStore({ leaseMs: LEASE_MS });
|
|
268
|
+
const runId = rid();
|
|
269
|
+
const flowId = fid();
|
|
270
|
+
const queue = new InMemoryQueue();
|
|
271
|
+
const fact = Facts.flowStarted({
|
|
272
|
+
runId,
|
|
273
|
+
flowId,
|
|
274
|
+
input: {},
|
|
275
|
+
at: /* @__PURE__ */ new Date()
|
|
276
|
+
});
|
|
277
|
+
const steps = ["a", "b"];
|
|
278
|
+
const res = await s.tryStartRun(runId, fact, void 0, {
|
|
279
|
+
queue,
|
|
280
|
+
flowId,
|
|
281
|
+
steps
|
|
282
|
+
});
|
|
283
|
+
ok(res.started, "start reports started");
|
|
284
|
+
const queued = await queue.dequeue({ count: 10 });
|
|
285
|
+
eq(
|
|
286
|
+
queued.map((m) => ({ runId: m.runId, stepId: m.stepId, flowId: m.flowId })).sort((x, y) => x.stepId < y.stepId ? -1 : 1),
|
|
287
|
+
[
|
|
288
|
+
{ runId, stepId: "a", flowId },
|
|
289
|
+
{ runId, stepId: "b", flowId }
|
|
290
|
+
],
|
|
291
|
+
"both seed steps are queued once, for this run and flowId"
|
|
292
|
+
);
|
|
293
|
+
const again = await s.tryStartRun(runId, fact, void 0, {
|
|
294
|
+
queue,
|
|
295
|
+
flowId,
|
|
296
|
+
steps
|
|
297
|
+
});
|
|
298
|
+
eq(again.started, false, "second identical call is refused");
|
|
299
|
+
eq(await queue.dequeue({ count: 10 }), [], "nothing more is queued");
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
name: "tryStartRun: a refused start enqueues nothing",
|
|
304
|
+
async run(h) {
|
|
305
|
+
const s = await h.makeStore({ leaseMs: LEASE_MS });
|
|
306
|
+
const runId = rid();
|
|
307
|
+
const flowId = fid();
|
|
308
|
+
await startRun(s, runId, { flowId });
|
|
309
|
+
const queue = new InMemoryQueue();
|
|
310
|
+
const fact = Facts.flowStarted({
|
|
311
|
+
runId,
|
|
312
|
+
flowId,
|
|
313
|
+
input: {},
|
|
314
|
+
at: /* @__PURE__ */ new Date()
|
|
315
|
+
});
|
|
316
|
+
const res = await s.tryStartRun(runId, fact, void 0, {
|
|
317
|
+
queue,
|
|
318
|
+
flowId,
|
|
319
|
+
steps: ["a"]
|
|
320
|
+
});
|
|
321
|
+
eq(res.started, false, "refused: runId already exists");
|
|
322
|
+
eq(await queue.dequeue({ count: 10 }), [], "the queue is empty");
|
|
323
|
+
}
|
|
324
|
+
},
|
|
264
325
|
{
|
|
265
326
|
// The third face of nagi#29, and the one the issue's hypothesis list
|
|
266
327
|
// misses: tryStartRun is atomic, but nothing keeps the superseder ALIVE.
|
|
@@ -562,6 +623,34 @@ var storeContract = [
|
|
|
562
623
|
);
|
|
563
624
|
}
|
|
564
625
|
},
|
|
626
|
+
{
|
|
627
|
+
name: "runStep: the body reads run state on its tx and sees committed facts",
|
|
628
|
+
async run(h) {
|
|
629
|
+
const s = await h.makeStore({ leaseMs: LEASE_MS });
|
|
630
|
+
const runId = rid();
|
|
631
|
+
await startRun(s, runId);
|
|
632
|
+
await startStep(s, runId, "s");
|
|
633
|
+
await s.appendFact(
|
|
634
|
+
runId,
|
|
635
|
+
Facts.stepAbortRequested({
|
|
636
|
+
runId,
|
|
637
|
+
stepId: "s",
|
|
638
|
+
attempt: A1,
|
|
639
|
+
at: /* @__PURE__ */ new Date()
|
|
640
|
+
})
|
|
641
|
+
);
|
|
642
|
+
let seenTag;
|
|
643
|
+
await s.runStep(runId, "s", A1, async (tx) => {
|
|
644
|
+
const seen = await s.loadRunState(runId, tx);
|
|
645
|
+
seenTag = stepStateOf(seen, "s").tag;
|
|
646
|
+
return {
|
|
647
|
+
output: null,
|
|
648
|
+
fact: Facts.stepCanceled(runId, "s", A1, /* @__PURE__ */ new Date())
|
|
649
|
+
};
|
|
650
|
+
});
|
|
651
|
+
eq(seenTag, "aborting", "tx read sees the abort-requested fold");
|
|
652
|
+
}
|
|
653
|
+
},
|
|
565
654
|
{
|
|
566
655
|
name: "settleSignal(deliver): releases the lease and the armed timer",
|
|
567
656
|
async run(h) {
|
|
@@ -587,6 +676,34 @@ var storeContract = [
|
|
|
587
676
|
);
|
|
588
677
|
}
|
|
589
678
|
},
|
|
679
|
+
{
|
|
680
|
+
name: "settleSignal(consume): parking an awaiting step releases its lease and keeps its timer",
|
|
681
|
+
async run(h) {
|
|
682
|
+
const s = await h.makeStore({ leaseMs: SHORT_LEASE_MS });
|
|
683
|
+
const queue = new InMemoryQueue();
|
|
684
|
+
const runId = rid();
|
|
685
|
+
await startRun(s, runId);
|
|
686
|
+
await startStep(s, runId, "gate", { kind: "signal" });
|
|
687
|
+
ok(await s.claimStep(runId, "gate", A1) !== null, "claim");
|
|
688
|
+
const fireAt = new Date(Date.now() + HOUR_MS);
|
|
689
|
+
await s.upsertTimer(runId, "gate", fireAt);
|
|
690
|
+
eq(
|
|
691
|
+
await s.settleSignal({ runId, stepId: "gate", at: /* @__PURE__ */ new Date() }),
|
|
692
|
+
{ tag: "noop" },
|
|
693
|
+
"parks"
|
|
694
|
+
);
|
|
695
|
+
await sleep(PAST_LEASE_MS);
|
|
696
|
+
eq(
|
|
697
|
+
await s.sweepLeases({ now: /* @__PURE__ */ new Date(), queue }),
|
|
698
|
+
[],
|
|
699
|
+
"nothing to reap"
|
|
700
|
+
);
|
|
701
|
+
const timedOut = await s.sweepSignalTimeouts({
|
|
702
|
+
now: new Date(fireAt.getTime() + 1)
|
|
703
|
+
});
|
|
704
|
+
eq(timedOut.length, 1, "timer survived the park");
|
|
705
|
+
}
|
|
706
|
+
},
|
|
590
707
|
{
|
|
591
708
|
name: "sweepSignalTimeouts: fails an awaiting step past its deadline with NagiSignalTimeoutError, releases its lease, consumes the timer",
|
|
592
709
|
async run(h) {
|
|
@@ -950,6 +1067,36 @@ var storeContract = [
|
|
|
950
1067
|
await claimableAgain(s, runId, "s", "sweepLeases");
|
|
951
1068
|
}
|
|
952
1069
|
},
|
|
1070
|
+
{
|
|
1071
|
+
name: "step.retried releases the failed attempt's lease, so the reaper leaves the backoff alone",
|
|
1072
|
+
async run(h) {
|
|
1073
|
+
const s = await h.makeStore({ leaseMs: SHORT_LEASE_MS });
|
|
1074
|
+
const queue = new InMemoryQueue();
|
|
1075
|
+
const runId = rid();
|
|
1076
|
+
await startRun(s, runId);
|
|
1077
|
+
await startStep(s, runId, "s");
|
|
1078
|
+
ok(await s.claimStep(runId, "s", A1) !== null, "claim");
|
|
1079
|
+
const now = Date.now();
|
|
1080
|
+
await s.appendFact(
|
|
1081
|
+
runId,
|
|
1082
|
+
Facts.stepRetried(
|
|
1083
|
+
runId,
|
|
1084
|
+
"s",
|
|
1085
|
+
A1,
|
|
1086
|
+
new Date(now + HOUR_MS),
|
|
1087
|
+
{ name: "Error", message: "boom" },
|
|
1088
|
+
new Date(now)
|
|
1089
|
+
)
|
|
1090
|
+
);
|
|
1091
|
+
await sleep(PAST_LEASE_MS);
|
|
1092
|
+
eq(
|
|
1093
|
+
await s.sweepLeases({ now: /* @__PURE__ */ new Date(), queue }),
|
|
1094
|
+
[],
|
|
1095
|
+
"nothing to reap"
|
|
1096
|
+
);
|
|
1097
|
+
await claimableAgain(s, runId, "s", "step.retried");
|
|
1098
|
+
}
|
|
1099
|
+
},
|
|
953
1100
|
{
|
|
954
1101
|
name: "sweepLeases: skips live leases and the released lease of a settled step",
|
|
955
1102
|
async run(h) {
|
|
@@ -1744,6 +1891,55 @@ var storeContract = [
|
|
|
1744
1891
|
);
|
|
1745
1892
|
}
|
|
1746
1893
|
},
|
|
1894
|
+
{
|
|
1895
|
+
name: "events: step.canceled and step.reset are events",
|
|
1896
|
+
async run(h) {
|
|
1897
|
+
const s = await h.makeStore({ leaseMs: LEASE_MS });
|
|
1898
|
+
if (s.events === void 0) return;
|
|
1899
|
+
const runId = rid();
|
|
1900
|
+
const seen = [];
|
|
1901
|
+
const off = s.events.watchRuns((e) => {
|
|
1902
|
+
if (e.runId === runId) seen.push(e);
|
|
1903
|
+
});
|
|
1904
|
+
try {
|
|
1905
|
+
await startRun(s, runId);
|
|
1906
|
+
await startStep(s, runId, "s");
|
|
1907
|
+
await s.appendFact(
|
|
1908
|
+
runId,
|
|
1909
|
+
Facts.stepCanceled(runId, "s", A1, /* @__PURE__ */ new Date())
|
|
1910
|
+
);
|
|
1911
|
+
await s.appendFact(
|
|
1912
|
+
runId,
|
|
1913
|
+
Facts.stepReset({ runId, stepId: "s", at: /* @__PURE__ */ new Date() })
|
|
1914
|
+
);
|
|
1915
|
+
const want = [
|
|
1916
|
+
"flow.started",
|
|
1917
|
+
"step.started",
|
|
1918
|
+
"step.canceled",
|
|
1919
|
+
"step.reset"
|
|
1920
|
+
];
|
|
1921
|
+
await eventually(() => seen.length >= want.length, "all four events");
|
|
1922
|
+
eq(
|
|
1923
|
+
seen.map((e) => e.type),
|
|
1924
|
+
want,
|
|
1925
|
+
"cancel and reset are observable"
|
|
1926
|
+
);
|
|
1927
|
+
eq(
|
|
1928
|
+
seen.slice(2).map((e) => ({
|
|
1929
|
+
type: e.type,
|
|
1930
|
+
stepId: e.stepId
|
|
1931
|
+
})),
|
|
1932
|
+
[
|
|
1933
|
+
{ type: "step.canceled", stepId: "s" },
|
|
1934
|
+
{ type: "step.reset", stepId: "s" }
|
|
1935
|
+
],
|
|
1936
|
+
"carry the stepId"
|
|
1937
|
+
);
|
|
1938
|
+
} finally {
|
|
1939
|
+
off();
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
},
|
|
1747
1943
|
{
|
|
1748
1944
|
name: "events: a superseded run announces flow.canceled naming its superseder",
|
|
1749
1945
|
async run(h) {
|
|
@@ -1771,6 +1967,33 @@ var storeContract = [
|
|
|
1771
1967
|
);
|
|
1772
1968
|
}
|
|
1773
1969
|
},
|
|
1970
|
+
{
|
|
1971
|
+
name: "events: a run whose outputs exceed 8 KB still commits, and its events carry no payload",
|
|
1972
|
+
async run(h) {
|
|
1973
|
+
const s = await h.makeStore({ leaseMs: LEASE_MS });
|
|
1974
|
+
if (s.events === void 0) return;
|
|
1975
|
+
const runId = rid();
|
|
1976
|
+
const seen = [];
|
|
1977
|
+
s.events.watchRun(runId, (e) => seen.push(e));
|
|
1978
|
+
await startRun(s, runId);
|
|
1979
|
+
await startStep(s, runId, "s");
|
|
1980
|
+
const big = { text: "x".repeat(2e4) };
|
|
1981
|
+
await s.appendFact(
|
|
1982
|
+
runId,
|
|
1983
|
+
Facts.stepCompleted(runId, "s", A1, big, /* @__PURE__ */ new Date())
|
|
1984
|
+
);
|
|
1985
|
+
await s.endRun(runId, Facts.flowCompleted(runId, big, /* @__PURE__ */ new Date()));
|
|
1986
|
+
await eventually(
|
|
1987
|
+
() => seen.some((e) => e.type === "flow.completed"),
|
|
1988
|
+
"flow.completed"
|
|
1989
|
+
);
|
|
1990
|
+
ok(
|
|
1991
|
+
seen.every((e) => !("output" in e) && !("error" in e)),
|
|
1992
|
+
"events carry no payload"
|
|
1993
|
+
);
|
|
1994
|
+
eq((await s.loadRunState(runId)).phase.tag, "completed", "run committed");
|
|
1995
|
+
}
|
|
1996
|
+
},
|
|
1774
1997
|
{
|
|
1775
1998
|
name: "stream: a subscriber receives published chunks, then closes on step.completed",
|
|
1776
1999
|
async run(h) {
|
|
@@ -1797,7 +2020,7 @@ var storeContract = [
|
|
|
1797
2020
|
}
|
|
1798
2021
|
},
|
|
1799
2022
|
{
|
|
1800
|
-
name: "stream: step.failed
|
|
2023
|
+
name: "stream: step.failed ends the stream with an error event; a run end closes a step that never emitted",
|
|
1801
2024
|
async run(h) {
|
|
1802
2025
|
const s = await h.makeStore({ leaseMs: LEASE_MS });
|
|
1803
2026
|
if (s.stream === void 0) return;
|
|
@@ -1812,7 +2035,7 @@ var storeContract = [
|
|
|
1812
2035
|
runId,
|
|
1813
2036
|
Facts.stepFailed(runId, "bad", A1, error, /* @__PURE__ */ new Date())
|
|
1814
2037
|
);
|
|
1815
|
-
eq(await bad, [{ kind: "error"
|
|
2038
|
+
eq(await bad, [{ kind: "error" }], "error event, then closed");
|
|
1816
2039
|
await endRun(s, runId, "canceled");
|
|
1817
2040
|
eq(await quiet, [], "closed by the run end");
|
|
1818
2041
|
}
|
|
@@ -1836,6 +2059,83 @@ var storeContract = [
|
|
|
1836
2059
|
);
|
|
1837
2060
|
}
|
|
1838
2061
|
},
|
|
2062
|
+
{
|
|
2063
|
+
name: "stream: a reset step's channel reopens for its rerun",
|
|
2064
|
+
async run(h) {
|
|
2065
|
+
const s = await h.makeStore({ leaseMs: LEASE_MS });
|
|
2066
|
+
if (s.stream === void 0) return;
|
|
2067
|
+
const runId = rid();
|
|
2068
|
+
await startRun(s, runId);
|
|
2069
|
+
await startStep(s, runId, "s", { kind: "streaming" });
|
|
2070
|
+
const first = drain(
|
|
2071
|
+
s.stream.subscribeStream(runId, "s"),
|
|
2072
|
+
"first attempt"
|
|
2073
|
+
);
|
|
2074
|
+
s.stream.publishChunk(runId, "s", "one");
|
|
2075
|
+
await s.appendFact(
|
|
2076
|
+
runId,
|
|
2077
|
+
Facts.stepCompleted(runId, "s", A1, null, /* @__PURE__ */ new Date())
|
|
2078
|
+
);
|
|
2079
|
+
eq(
|
|
2080
|
+
await first,
|
|
2081
|
+
[{ kind: "chunk", chunk: "one" }],
|
|
2082
|
+
"first attempt streamed"
|
|
2083
|
+
);
|
|
2084
|
+
await s.appendFact(
|
|
2085
|
+
runId,
|
|
2086
|
+
Facts.stepReset({ runId, stepId: "s", at: /* @__PURE__ */ new Date() })
|
|
2087
|
+
);
|
|
2088
|
+
await startStep(s, runId, "s", { attempt: A1, kind: "streaming" });
|
|
2089
|
+
const rerun = drain(
|
|
2090
|
+
s.stream.subscribeStream(runId, "s"),
|
|
2091
|
+
"rerun completed"
|
|
2092
|
+
);
|
|
2093
|
+
s.stream.publishChunk(runId, "s", "again");
|
|
2094
|
+
await s.appendFact(
|
|
2095
|
+
runId,
|
|
2096
|
+
Facts.stepCompleted(runId, "s", A1, null, /* @__PURE__ */ new Date())
|
|
2097
|
+
);
|
|
2098
|
+
eq(
|
|
2099
|
+
await rerun,
|
|
2100
|
+
[{ kind: "chunk", chunk: "again" }],
|
|
2101
|
+
"rerun chunk delivered"
|
|
2102
|
+
);
|
|
2103
|
+
}
|
|
2104
|
+
},
|
|
2105
|
+
{
|
|
2106
|
+
name: "stream: a reaped lease tells subscribers a new attempt started",
|
|
2107
|
+
async run(h) {
|
|
2108
|
+
const s = await h.makeStore({ leaseMs: SHORT_LEASE_MS });
|
|
2109
|
+
if (s.stream === void 0) return;
|
|
2110
|
+
const queue = new InMemoryQueue();
|
|
2111
|
+
const runId = rid();
|
|
2112
|
+
await startRun(s, runId);
|
|
2113
|
+
await startStep(s, runId, "s", { kind: "streaming" });
|
|
2114
|
+
ok(await s.claimStep(runId, "s", A1) !== null, "claim");
|
|
2115
|
+
const events = drain(
|
|
2116
|
+
s.stream.subscribeStream(runId, "s"),
|
|
2117
|
+
"reaped then rerun"
|
|
2118
|
+
);
|
|
2119
|
+
s.stream.publishChunk(runId, "s", "a");
|
|
2120
|
+
await sleep(PAST_LEASE_MS);
|
|
2121
|
+
await s.sweepLeases({ now: /* @__PURE__ */ new Date(), queue });
|
|
2122
|
+
await startStep(s, runId, "s", { attempt: A2, kind: "streaming" });
|
|
2123
|
+
s.stream.publishChunk(runId, "s", "b");
|
|
2124
|
+
await s.appendFact(
|
|
2125
|
+
runId,
|
|
2126
|
+
Facts.stepCompleted(runId, "s", A2, null, /* @__PURE__ */ new Date())
|
|
2127
|
+
);
|
|
2128
|
+
eq(
|
|
2129
|
+
await events,
|
|
2130
|
+
[
|
|
2131
|
+
{ kind: "chunk", chunk: "a" },
|
|
2132
|
+
{ kind: "retry", attempt: 2 },
|
|
2133
|
+
{ kind: "chunk", chunk: "b" }
|
|
2134
|
+
],
|
|
2135
|
+
"chunk, retry marker, chunk"
|
|
2136
|
+
);
|
|
2137
|
+
}
|
|
2138
|
+
},
|
|
1839
2139
|
{
|
|
1840
2140
|
name: "sweepLeases: a failing enqueue leaves nothing half-reaped \u2014 the lease stays reapable and no lease.reaped is written",
|
|
1841
2141
|
async run(h) {
|