@nagi-js/core 0.1.1-rc.20 → 0.1.1-rc.21
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-VQTYTI6X.js → chunk-VU2LG4VW.js} +130 -5
- package/dist/chunk-VU2LG4VW.js.map +1 -0
- package/dist/index.d.ts +47 -3
- package/dist/index.js +68 -9
- package/dist/index.js.map +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +115 -1
- package/dist/testing.js.map +1 -1
- package/dist/{types-DFSYjJE3.d.ts → types-KjCWK9pN.d.ts} +61 -7
- package/package.json +1 -1
- package/dist/chunk-VQTYTI6X.js.map +0 -1
package/dist/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as Millis,
|
|
1
|
+
import { T as Millis, b5 as Store, aI as StandardSchemaV1 } from './types-KjCWK9pN.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, stepStateOf, InMemoryQueue, stepStatusOf, NagiConcurrencyConflictError } from './chunk-
|
|
1
|
+
import { Facts, stepStateOf, InMemoryQueue, stepStatusOf, NagiConcurrencyConflictError } from './chunk-VU2LG4VW.js';
|
|
2
2
|
|
|
3
3
|
// src/testing.ts
|
|
4
4
|
function passthroughSchema() {
|
|
@@ -166,6 +166,120 @@ var storeContract = [
|
|
|
166
166
|
eq((await s.describe(a))?.run.concurrencyKey, "k", "describe(a) key");
|
|
167
167
|
}
|
|
168
168
|
},
|
|
169
|
+
{
|
|
170
|
+
// nagi#29: a phantom superseder is a canceled_by_run_id pointing at a run
|
|
171
|
+
// row that does not exist. The canonical stores cannot produce one because
|
|
172
|
+
// cancel-prior and insert-new share a transaction; this pins that property
|
|
173
|
+
// on the CONTRACT so a custom Store cannot regress into the bug silently.
|
|
174
|
+
name: "tryStartRun: a superseded run's canceledByRunId always references a run that exists",
|
|
175
|
+
async run(h) {
|
|
176
|
+
const s = await h.makeStore({ leaseMs: LEASE_MS });
|
|
177
|
+
const flowId = fid();
|
|
178
|
+
const a = rid();
|
|
179
|
+
const b = rid();
|
|
180
|
+
await startRun(s, a, { flowId, concurrencyKey: "k" });
|
|
181
|
+
await startRun(s, b, { flowId, concurrencyKey: "k" });
|
|
182
|
+
const superseder = (await s.describe(a))?.run.canceledByRunId;
|
|
183
|
+
ok(superseder !== void 0, "a records a superseder");
|
|
184
|
+
ok(
|
|
185
|
+
await s.describe(superseder) !== null,
|
|
186
|
+
"the superseder run row must exist \u2014 a dangling reference is nagi#29"
|
|
187
|
+
);
|
|
188
|
+
eq(
|
|
189
|
+
(await s.loadRunState(superseder)).facts.length > 0,
|
|
190
|
+
true,
|
|
191
|
+
"the superseder must have a durable fact log, not just a reference"
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
// The other half of the same atomicity claim: a start that does NOT happen
|
|
197
|
+
// must not cancel anything. An implementation that cancels priors before
|
|
198
|
+
// confirming its own insert leaves exactly the orphaned state nagi#29 saw.
|
|
199
|
+
name: "tryStartRun: a refused start cancels no prior run",
|
|
200
|
+
async run(h) {
|
|
201
|
+
const s = await h.makeStore({ leaseMs: LEASE_MS });
|
|
202
|
+
const flowId = fid();
|
|
203
|
+
const a = rid();
|
|
204
|
+
const b = rid();
|
|
205
|
+
await startRun(s, a, { flowId, concurrencyKey: "k" });
|
|
206
|
+
await startRun(s, b, { flowId, concurrencyKey: "k2" });
|
|
207
|
+
const refused = await startRun(s, b, { flowId, concurrencyKey: "k" });
|
|
208
|
+
eq(refused.started, false, "second start for a known runId is refused");
|
|
209
|
+
eq(refused.canceled.length, 0, "a refused start cancels nothing");
|
|
210
|
+
eq(
|
|
211
|
+
(await s.loadRunState(a)).phase.tag,
|
|
212
|
+
"running",
|
|
213
|
+
"the prior run on that key survives a refused start"
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
// The third face of nagi#29, and the one the issue's hypothesis list
|
|
219
|
+
// misses: tryStartRun is atomic, but nothing keeps the superseder ALIVE.
|
|
220
|
+
// Retention that prunes "completed" while keeping "canceled" for audit
|
|
221
|
+
// deletes the superseder and strands the victim's reference.
|
|
222
|
+
name: "pruneFacts: pruning a superseder leaves no dangling canceledByRunId",
|
|
223
|
+
async run(h) {
|
|
224
|
+
const s = await h.makeStore({ leaseMs: LEASE_MS });
|
|
225
|
+
const flowId = fid();
|
|
226
|
+
const a = rid();
|
|
227
|
+
const b = rid();
|
|
228
|
+
await startRun(s, a, { flowId, concurrencyKey: "k" });
|
|
229
|
+
await startRun(s, b, { flowId, concurrencyKey: "k" });
|
|
230
|
+
eq((await s.describe(a))?.run.canceledByRunId, b, "b superseded a");
|
|
231
|
+
await endRun(s, b, "completed");
|
|
232
|
+
await s.pruneFacts({
|
|
233
|
+
olderThan: new Date(Date.now() + 6e4),
|
|
234
|
+
statuses: ["completed"],
|
|
235
|
+
batchSize: 100,
|
|
236
|
+
keepSummary: false
|
|
237
|
+
});
|
|
238
|
+
const victim = await s.describe(a);
|
|
239
|
+
ok(victim !== null, "a canceled run survives a completed-only policy");
|
|
240
|
+
const ref = victim.run.canceledByRunId;
|
|
241
|
+
if (ref !== void 0)
|
|
242
|
+
ok(
|
|
243
|
+
await s.describe(ref) !== null,
|
|
244
|
+
"canceledByRunId must not outlive the run it names \u2014 nagi#29"
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
// NagiCanceledError is public: a handler can name any run as its canceler
|
|
250
|
+
// and classifyFailure turns that claim into a concurrency-cause fact. The
|
|
251
|
+
// fact is the record; the VIEW must not present an unresolvable claim as a
|
|
252
|
+
// reference, or every consumer's audit finds nagi#29's orphan.
|
|
253
|
+
name: "appendFact(flow.canceled): a canceler that never existed is not surfaced as a reference",
|
|
254
|
+
async run(h) {
|
|
255
|
+
const s = await h.makeStore({ leaseMs: LEASE_MS });
|
|
256
|
+
const victim = rid();
|
|
257
|
+
await startRun(s, victim);
|
|
258
|
+
await s.appendFact(
|
|
259
|
+
victim,
|
|
260
|
+
Facts.flowCanceledByConcurrency({
|
|
261
|
+
runId: victim,
|
|
262
|
+
canceledByRunId: rid(),
|
|
263
|
+
concurrencyKey: "k",
|
|
264
|
+
at: /* @__PURE__ */ new Date()
|
|
265
|
+
})
|
|
266
|
+
);
|
|
267
|
+
const d = await s.describe(victim);
|
|
268
|
+
ok(d !== null, "the canceled run is still describable");
|
|
269
|
+
eq(d.run.status, "canceled", "the cancellation itself stands");
|
|
270
|
+
eq(
|
|
271
|
+
d.run.canceledByRunId,
|
|
272
|
+
void 0,
|
|
273
|
+
"an unresolvable canceler is omitted, not surfaced \u2014 nagi#29"
|
|
274
|
+
);
|
|
275
|
+
const facts = (await s.loadRunState(victim)).facts;
|
|
276
|
+
eq(
|
|
277
|
+
facts.some((f) => f.kind === "flow.canceled"),
|
|
278
|
+
true,
|
|
279
|
+
"the fact log keeps the claim verbatim"
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
},
|
|
169
283
|
{
|
|
170
284
|
name: "tryStartRun: a different key or flowId cancels nothing",
|
|
171
285
|
async run(h) {
|