@entifix/testing-unit 0.14.0 → 0.16.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.
- package/dist/contracts/flow-engine.contract.d.ts.map +1 -1
- package/dist/contracts/flow-engine.contract.js +158 -5
- package/dist/contracts/flow-engine.contract.js.map +1 -1
- package/dist/contracts/index.d.ts +0 -1
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +0 -1
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/transaction-ports.contract.d.ts +1 -15
- package/dist/contracts/transaction-ports.contract.d.ts.map +1 -1
- package/dist/contracts/transaction-ports.contract.js +1 -87
- package/dist/contracts/transaction-ports.contract.js.map +1 -1
- package/dist/doubles/flow-engine.d.ts +5 -2
- package/dist/doubles/flow-engine.d.ts.map +1 -1
- package/dist/doubles/flow-engine.js +77 -18
- package/dist/doubles/flow-engine.js.map +1 -1
- package/dist/doubles/transaction-ports.d.ts +1 -42
- package/dist/doubles/transaction-ports.d.ts.map +1 -1
- package/dist/doubles/transaction-ports.js +1 -134
- package/dist/doubles/transaction-ports.js.map +1 -1
- package/dist/drivers/fake-redis.d.ts +4 -6
- package/dist/drivers/fake-redis.d.ts.map +1 -1
- package/dist/drivers/fake-redis.js +4 -6
- package/dist/drivers/fake-redis.js.map +1 -1
- package/package.json +5 -5
- package/dist/contracts/saga-store.contract.d.ts +0 -13
- package/dist/contracts/saga-store.contract.d.ts.map +0 -1
- package/dist/contracts/saga-store.contract.js +0 -142
- package/dist/contracts/saga-store.contract.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-engine.contract.d.ts","sourceRoot":"","sources":["../../src/contracts/flow-engine.contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,eAAe,EAKrB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAIxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"flow-engine.contract.d.ts","sourceRoot":"","sources":["../../src/contracts/flow-engine.contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,eAAe,EAKrB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAIxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAsCjE,sDAAsD;AACtD,eAAO,MAAM,yBAAyB,EAAE,eAQtC,CAAC;AA4EH;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,GACrC,MAAM,MAAM,EACZ,MAAM,CACJ,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,eAAe,KACzB,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,KACpC,IAqPF,CAAC"}
|
|
@@ -31,11 +31,22 @@ const hold = fragment('hold', 'compensatable');
|
|
|
31
31
|
const take = fragment('take', 'pivot');
|
|
32
32
|
const settle = fragment('settle', 'retriable');
|
|
33
33
|
const wait = fragment('await', 'wait');
|
|
34
|
+
/** A wait that declares what it is answered with, for guards to branch on. */ const report = defineFragment(_extends({}, fragment('report', 'wait'), {
|
|
35
|
+
outcomes: [
|
|
36
|
+
'delivered',
|
|
37
|
+
'refused'
|
|
38
|
+
]
|
|
39
|
+
}));
|
|
40
|
+
const close = fragment('close', 'retriable');
|
|
41
|
+
const restore = fragment('restore', 'retriable');
|
|
34
42
|
/** The catalog every case composes its slips from. */ export const flowEngineContractCatalog = defineCatalog([
|
|
35
43
|
hold,
|
|
36
44
|
take,
|
|
37
45
|
settle,
|
|
38
|
-
wait
|
|
46
|
+
wait,
|
|
47
|
+
report,
|
|
48
|
+
close,
|
|
49
|
+
restore
|
|
39
50
|
]);
|
|
40
51
|
const stepOf = (descriptor)=>({
|
|
41
52
|
ref: fragmentRef(descriptor),
|
|
@@ -55,6 +66,67 @@ const slipOf = (flowId, steps)=>({
|
|
|
55
66
|
resolution: [],
|
|
56
67
|
composedAt: '2026-01-01T00:00:00.000Z'
|
|
57
68
|
});
|
|
69
|
+
/**
|
|
70
|
+
* take ▸ report ▸ close (on `delivered`) ▸ restore (on `refused` or the
|
|
71
|
+
* timeout's `unanswered`): the one branch a slip can take, on a wait's answer.
|
|
72
|
+
*/ const branchingSlip = (flowId, report = {})=>_extends({}, slipOf(flowId, []), {
|
|
73
|
+
stages: [
|
|
74
|
+
{
|
|
75
|
+
name: 'main',
|
|
76
|
+
steps: [
|
|
77
|
+
{
|
|
78
|
+
ref: fragmentRef(take),
|
|
79
|
+
step: 'take',
|
|
80
|
+
cardinality: 'one'
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
ref: 'contract.report@1',
|
|
84
|
+
step: 'report',
|
|
85
|
+
cardinality: 'one',
|
|
86
|
+
parameters: _extends({
|
|
87
|
+
correlation: `parcel-${flowId}`
|
|
88
|
+
}, report)
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
ref: fragmentRef(close),
|
|
92
|
+
step: 'close',
|
|
93
|
+
cardinality: 'one',
|
|
94
|
+
guard: {
|
|
95
|
+
wait: 'report',
|
|
96
|
+
outcomes: [
|
|
97
|
+
'delivered'
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
ref: fragmentRef(restore),
|
|
103
|
+
step: 'restore',
|
|
104
|
+
cardinality: 'one',
|
|
105
|
+
guard: {
|
|
106
|
+
wait: 'report',
|
|
107
|
+
outcomes: [
|
|
108
|
+
'refused',
|
|
109
|
+
'unanswered'
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
});
|
|
117
|
+
/** A participant that succeeds, remembering every step it was called for. */ const recording = ()=>{
|
|
118
|
+
const called = [];
|
|
119
|
+
const participant = (step)=>{
|
|
120
|
+
called.push(step.step);
|
|
121
|
+
return Effect.succeed({
|
|
122
|
+
ok: true
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
return {
|
|
126
|
+
called,
|
|
127
|
+
participant
|
|
128
|
+
};
|
|
129
|
+
};
|
|
58
130
|
const failing = (failAt)=>(step)=>step.step === failAt ? Effect.fail(new Declined({
|
|
59
131
|
reason: 'refused'
|
|
60
132
|
})) : Effect.succeed({
|
|
@@ -167,10 +239,12 @@ const succeeding = ()=>Effect.succeed({
|
|
|
167
239
|
});
|
|
168
240
|
await run(engine.start(correlated, 'k'));
|
|
169
241
|
expect(await state(engine, 'flow-1')).toBe('waiting');
|
|
170
|
-
const stranger = await run(Effect.flip(engine.signalCorrelated('order-8',
|
|
242
|
+
const stranger = await run(Effect.flip(engine.signalCorrelated('order-8', {
|
|
243
|
+
outcome: 'any'
|
|
244
|
+
})));
|
|
171
245
|
expect(stranger._tag).toBe('FlowNotFound');
|
|
172
|
-
await run(engine.signalCorrelated('order-7',
|
|
173
|
-
|
|
246
|
+
await run(engine.signalCorrelated('order-7', {
|
|
247
|
+
outcome: 'delivered'
|
|
174
248
|
}));
|
|
175
249
|
expect(await state(engine, 'flow-1')).toBe('completed');
|
|
176
250
|
});
|
|
@@ -196,6 +270,83 @@ const succeeding = ()=>Effect.succeed({
|
|
|
196
270
|
const states = await Promise.all(flowIds.map((flowId)=>state(engine, flowId)));
|
|
197
271
|
expect(states.filter((next)=>next !== 'completed')).toEqual([]);
|
|
198
272
|
});
|
|
273
|
+
it('runs only the steps guarded on the outcome a wait was answered with', async ()=>{
|
|
274
|
+
const { called, participant } = recording();
|
|
275
|
+
const engine = await make(flowEngineContractCatalog, participant);
|
|
276
|
+
await run(engine.start(branchingSlip('flow-1'), 'k'));
|
|
277
|
+
expect(await state(engine, 'flow-1')).toBe('waiting');
|
|
278
|
+
await run(engine.signalCorrelated('parcel-flow-1', {
|
|
279
|
+
outcome: 'refused'
|
|
280
|
+
}));
|
|
281
|
+
expect(await state(engine, 'flow-1')).toBe('completed');
|
|
282
|
+
expect(called).toEqual([
|
|
283
|
+
'take',
|
|
284
|
+
'restore'
|
|
285
|
+
]);
|
|
286
|
+
});
|
|
287
|
+
it('refuses a correlated signal its wait is not answered with', async ()=>{
|
|
288
|
+
const engine = await make(flowEngineContractCatalog, succeeding);
|
|
289
|
+
await run(engine.start(branchingSlip('flow-1'), 'k'));
|
|
290
|
+
expect(await state(engine, 'flow-1')).toBe('waiting');
|
|
291
|
+
const stray = await run(Effect.flip(engine.signalCorrelated('parcel-flow-1', {
|
|
292
|
+
outcome: 'returned'
|
|
293
|
+
})));
|
|
294
|
+
expect(stray._tag).toBe('FlowSignalRejected');
|
|
295
|
+
expect(await state(engine, 'flow-1')).toBe('waiting');
|
|
296
|
+
});
|
|
297
|
+
it('answers FlowNotFound to a correlated signal once nothing is parked on it', async ()=>{
|
|
298
|
+
const engine = await make(flowEngineContractCatalog, succeeding);
|
|
299
|
+
await run(engine.start(branchingSlip('flow-1'), 'k'));
|
|
300
|
+
await settled(engine, 'flow-1');
|
|
301
|
+
await run(engine.signalCorrelated('parcel-flow-1', {
|
|
302
|
+
outcome: 'delivered'
|
|
303
|
+
}));
|
|
304
|
+
expect(await state(engine, 'flow-1')).toBe('completed');
|
|
305
|
+
const again = await run(Effect.flip(engine.signalCorrelated('parcel-flow-1', {
|
|
306
|
+
outcome: 'delivered'
|
|
307
|
+
})));
|
|
308
|
+
expect(again._tag).toBe('FlowNotFound');
|
|
309
|
+
});
|
|
310
|
+
it('answers a timed-out wait with the outcome its onTimeout names', async ()=>{
|
|
311
|
+
const { called, participant } = recording();
|
|
312
|
+
const engine = await make(flowEngineContractCatalog, participant);
|
|
313
|
+
await run(engine.start(branchingSlip('flow-1', {
|
|
314
|
+
timeoutMs: 20,
|
|
315
|
+
onTimeout: {
|
|
316
|
+
outcome: 'unanswered'
|
|
317
|
+
}
|
|
318
|
+
}), 'k'));
|
|
319
|
+
const status = await run(engine.status('flow-1').pipe(Effect.repeat({
|
|
320
|
+
until: (next)=>next.state === 'completed',
|
|
321
|
+
schedule: Schedule.spaced('10 millis'),
|
|
322
|
+
times: 200
|
|
323
|
+
})));
|
|
324
|
+
expect(status.state).toBe('completed');
|
|
325
|
+
expect(called).toEqual([
|
|
326
|
+
'take',
|
|
327
|
+
'restore'
|
|
328
|
+
]);
|
|
329
|
+
});
|
|
330
|
+
it('strands a flow whose wait runs out and strands on its timeout', async ()=>{
|
|
331
|
+
const { called, participant } = recording();
|
|
332
|
+
const engine = await make(flowEngineContractCatalog, participant);
|
|
333
|
+
await run(engine.start(branchingSlip('flow-1', {
|
|
334
|
+
timeoutMs: 20,
|
|
335
|
+
onTimeout: 'strand'
|
|
336
|
+
}), 'k'));
|
|
337
|
+
const status = await run(engine.status('flow-1').pipe(Effect.repeat({
|
|
338
|
+
until: (next)=>next.state === 'stranded',
|
|
339
|
+
schedule: Schedule.spaced('10 millis'),
|
|
340
|
+
times: 200
|
|
341
|
+
})));
|
|
342
|
+
expect(status).toMatchObject({
|
|
343
|
+
state: 'stranded',
|
|
344
|
+
step: 'report'
|
|
345
|
+
});
|
|
346
|
+
expect(called).toEqual([
|
|
347
|
+
'take'
|
|
348
|
+
]);
|
|
349
|
+
});
|
|
199
350
|
it('interrupts a waiting flow', async ()=>{
|
|
200
351
|
const engine = await make(flowEngineContractCatalog, succeeding);
|
|
201
352
|
await run(engine.start(slipOf('flow-1', [
|
|
@@ -211,7 +362,9 @@ const succeeding = ()=>Effect.succeed({
|
|
|
211
362
|
for (const effect of [
|
|
212
363
|
engine.status('nope'),
|
|
213
364
|
engine.signal('nope', 'await', {}),
|
|
214
|
-
engine.signalCorrelated('nope',
|
|
365
|
+
engine.signalCorrelated('nope', {
|
|
366
|
+
outcome: 'any'
|
|
367
|
+
}),
|
|
215
368
|
engine.interrupt('nope')
|
|
216
369
|
])expect((await run(Effect.flip(effect)))._tag).toBe('FlowNotFound');
|
|
217
370
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/contracts/flow-engine.contract.ts"],"sourcesContent":["import {\n defineCatalog,\n defineFragment,\n type FragmentCatalog,\n type FragmentDescriptor,\n fragmentRef,\n type Slip,\n type SlipStep,\n} from '@entifix/business/flow';\nimport { Declined } from '@entifix/core';\nimport type { FlowEngine } from '@entifix/transactions';\nimport { Effect, Schedule, Schema } from 'effect';\nimport { describe, expect, it } from 'vitest';\n\nimport type { FakeParticipant } from '../doubles/flow-engine.js';\n\nconst contract = {\n input: Schema.Unknown,\n output: Schema.Unknown,\n failure: Schema.Unknown,\n};\n\nconst fragment = (\n id: string,\n kind: FragmentDescriptor['kind'],\n): FragmentDescriptor =>\n defineFragment({\n id: `contract.${id}`,\n version: 1,\n module: 'contract',\n kind,\n participant: 'contract',\n call: { method: 'POST', path: `/api/${id}` },\n ...(kind === 'compensatable'\n ? { compensation: { method: 'DELETE', path: `/api/${id}/:id` } as const }\n : {}),\n cardinality: 'one',\n contract,\n });\n\nconst hold = fragment('hold', 'compensatable');\nconst take = fragment('take', 'pivot');\nconst settle = fragment('settle', 'retriable');\nconst wait = fragment('await', 'wait');\n\n/** The catalog every case composes its slips from. */\nexport const flowEngineContractCatalog: FragmentCatalog = defineCatalog([\n hold,\n take,\n settle,\n wait,\n]);\n\nconst stepOf = (descriptor: FragmentDescriptor): SlipStep => ({\n ref: fragmentRef(descriptor),\n step: descriptor.id.replace('contract.', ''),\n cardinality: 'one',\n});\n\nconst slipOf = (\n flowId: string,\n steps: readonly FragmentDescriptor[],\n): Slip => ({\n slipVersion: 1,\n flowId,\n recipe: 'contract',\n stages: [{ name: 'main', steps: steps.map(stepOf) }],\n resolution: [],\n composedAt: '2026-01-01T00:00:00.000Z',\n});\n\nconst failing =\n (failAt: string): FakeParticipant =>\n step =>\n step.step === failAt\n ? Effect.fail(new Declined({ reason: 'refused' }))\n : Effect.succeed({ ok: true });\n\nconst succeeding: FakeParticipant = () => Effect.succeed({ ok: true });\n\n/**\n * What every {@link FlowEngine} must guarantee, whatever runs it: a start is\n * idempotent on its key, a failure before the commit point compensates and one\n * after it suspends, a wait takes the signal it waits for and no other, and an\n * unknown flow is a typed `FlowNotFound`.\n *\n * `make` builds a fresh engine over the contract's catalog and the participant\n * a case supplies.\n */\nexport const describeFlowEngineContract = (\n name: string,\n make: (\n catalog: FragmentCatalog,\n participant: FakeParticipant,\n ) => FlowEngine | Promise<FlowEngine>,\n): void => {\n const run = <A, E>(effect: Effect.Effect<A, E>) => Effect.runPromise(effect);\n /**\n * The flow's status once it has stopped moving. A start answers the flow id,\n * never the outcome — a durable engine runs the slip detached — so a case\n * reads the state the flow comes to rest in, a wait included.\n */\n const settled = (engine: FlowEngine, flowId: string) =>\n run(\n engine.status(flowId).pipe(\n Effect.repeat({\n until: status => status.state !== 'running',\n schedule: Schedule.spaced('10 millis'),\n times: 200,\n }),\n ),\n );\n const state = async (engine: FlowEngine, flowId: string) =>\n (await settled(engine, flowId)).state;\n\n describe(`FlowEngine contract: ${name}`, () => {\n it('answers the slip’s flow id, and the same one for a repeated key', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n const slip = slipOf('flow-1', [hold, take, settle]);\n\n const first = await run(engine.start(slip, 'key-1'));\n const again = await run(engine.start(slipOf('flow-2', [hold]), 'key-1'));\n\n expect(first).toEqual({ flowId: 'flow-1' });\n expect(again).toEqual({ flowId: 'flow-1' });\n });\n\n it('completes a flow whose every step succeeds', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n await run(engine.start(slipOf('flow-1', [hold, take, settle]), 'k'));\n\n expect(await state(engine, 'flow-1')).toBe('completed');\n });\n\n it('compensates a failure before the commit point', async () => {\n const engine = await make(flowEngineContractCatalog, failing('take'));\n await run(engine.start(slipOf('flow-1', [hold, take, settle]), 'k'));\n\n expect(await state(engine, 'flow-1')).toBe('compensated');\n });\n\n it('suspends a failure after the commit point, at that step', async () => {\n const engine = await make(flowEngineContractCatalog, failing('settle'));\n await run(engine.start(slipOf('flow-1', [hold, take, settle]), 'k'));\n\n expect(await settled(engine, 'flow-1')).toMatchObject({\n state: 'suspended',\n step: 'settle',\n });\n });\n\n it('waits for the signal it waits for, and refuses any other', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n await run(engine.start(slipOf('flow-1', [take, wait, settle]), 'k'));\n\n expect(await state(engine, 'flow-1')).toBe('waiting');\n const wrong = await run(\n Effect.flip(engine.signal('flow-1', 'elsewhere', {})),\n );\n expect(wrong._tag).toBe('FlowSignalRejected');\n\n await run(engine.signal('flow-1', 'await', { delivered: true }));\n expect(await state(engine, 'flow-1')).toBe('completed');\n\n const late = await run(Effect.flip(engine.signal('flow-1', 'await', {})));\n expect(late._tag).toBe('FlowSignalRejected');\n });\n\n it('completes a wait by what it is correlated with', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n const slip = slipOf('flow-1', [take, wait, settle]);\n const correlated: Slip = {\n ...slip,\n stages: slip.stages.map(stage => ({\n ...stage,\n steps: stage.steps.map(step =>\n step.step === 'await'\n ? { ...step, parameters: { correlation: 'order-7' } }\n : step,\n ),\n })),\n };\n await run(engine.start(correlated, 'k'));\n expect(await state(engine, 'flow-1')).toBe('waiting');\n\n const stranger = await run(\n Effect.flip(engine.signalCorrelated('order-8', 'await', {})),\n );\n expect(stranger._tag).toBe('FlowNotFound');\n\n await run(\n engine.signalCorrelated('order-7', 'await', { delivered: true }),\n );\n expect(await state(engine, 'flow-1')).toBe('completed');\n });\n\n it('leaves every flow a signal resumed finished, however many resume at once', async () => {\n // A wait resumed as its last step finishes almost at once, so nothing\n // the signal records may land after the resume: a `running` written\n // behind the flow's own `completed` would pin it there. A burst rather\n // than one flow, because an ordering fault shows up only under load.\n const engine = await make(flowEngineContractCatalog, succeeding);\n const flowIds = Array.from({ length: 20 }, (_, n) => `burst-${n}`);\n for (const flowId of flowIds)\n await run(engine.start(slipOf(flowId, [take, wait]), flowId));\n for (const flowId of flowIds)\n expect(await state(engine, flowId)).toBe('waiting');\n\n await run(\n Effect.forEach(\n flowIds,\n flowId => engine.signal(flowId, 'await', { delivered: true }),\n { concurrency: 'unbounded' },\n ),\n );\n\n const states = await Promise.all(\n flowIds.map(flowId => state(engine, flowId)),\n );\n expect(states.filter(next => next !== 'completed')).toEqual([]);\n });\n\n it('interrupts a waiting flow', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n await run(engine.start(slipOf('flow-1', [take, wait]), 'k'));\n expect(await state(engine, 'flow-1')).toBe('waiting');\n\n await run(engine.interrupt('flow-1'));\n\n expect(await state(engine, 'flow-1')).toBe('interrupted');\n });\n\n it('answers FlowNotFound for a flow it never started', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n\n for (const effect of [\n engine.status('nope'),\n engine.signal('nope', 'await', {}),\n engine.signalCorrelated('nope', 'await', {}),\n engine.interrupt('nope'),\n ])\n expect((await run(Effect.flip(effect)))._tag).toBe('FlowNotFound');\n });\n });\n};\n"],"names":["defineCatalog","defineFragment","fragmentRef","Declined","Effect","Schedule","Schema","describe","expect","it","contract","input","Unknown","output","failure","fragment","id","kind","version","module","participant","call","method","path","compensation","cardinality","hold","take","settle","wait","flowEngineContractCatalog","stepOf","descriptor","ref","step","replace","slipOf","flowId","steps","slipVersion","recipe","stages","name","map","resolution","composedAt","failing","failAt","fail","reason","succeed","ok","succeeding","describeFlowEngineContract","make","run","effect","runPromise","settled","engine","status","pipe","repeat","until","state","schedule","spaced","times","slip","first","start","again","toEqual","toBe","toMatchObject","wrong","flip","signal","_tag","delivered","late","correlated","stage","parameters","correlation","stranger","signalCorrelated","flowIds","Array","from","length","_","n","forEach","concurrency","states","Promise","all","filter","next","interrupt"],"mappings":";AAAA,SACEA,aAAa,EACbC,cAAc,EAGdC,WAAW,QAGN,yBAAyB;AAChC,SAASC,QAAQ,QAAQ,gBAAgB;AAEzC,SAASC,MAAM,EAAEC,QAAQ,EAAEC,MAAM,QAAQ,SAAS;AAClD,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAS;AAI9C,MAAMC,WAAW;IAC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AA,SAAU2B,MAAML,QAAQtB;YAEtC7B,OAAOuF,OAAOG,MAAM,CAACC,CAAAA,OAAQA,SAAS,cAAc3B,OAAO,CAAC,EAAE;QAChE;QAEA/D,GAAG,6BAA6B;YAC9B,MAAMkD,SAAS,MAAML,KAAKxB,2BAA2BsB;YACrD,MAAMG,IAAII,OAAOW,KAAK,CAAClC,OAAO,UAAU;gBAACT;gBAAME;aAAK,GAAG;YACvDrB,OAAO,MAAMwD,MAAML,QAAQ,WAAWc,IAAI,CAAC;YAE3C,MAAMlB,IAAII,OAAOyC,SAAS,CAAC;YAE3B5F,OAAO,MAAMwD,MAAML,QAAQ,WAAWc,IAAI,CAAC;QAC7C;QAEAhE,GAAG,oDAAoD;YACrD,MAAMkD,SAAS,MAAML,KAAKxB,2BAA2BsB;YAErD,KAAK,MAAMI,UAAU;gBACnBG,OAAOC,MAAM,CAAC;gBACdD,OAAOkB,MAAM,CAAC,QAAQ,SAAS,CAAC;gBAChClB,OAAO2B,gBAAgB,CAAC,QAAQ,SAAS,CAAC;gBAC1C3B,OAAOyC,SAAS,CAAC;aAClB,CACC5F,OAAO,AAAC,CAAA,MAAM+C,IAAInD,OAAOwE,IAAI,CAACpB,QAAO,EAAGsB,IAAI,EAAEL,IAAI,CAAC;QACvD;IACF;AACF,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../src/contracts/flow-engine.contract.ts"],"sourcesContent":["import {\n defineCatalog,\n defineFragment,\n type FragmentCatalog,\n type FragmentDescriptor,\n fragmentRef,\n type Slip,\n type SlipStep,\n} from '@entifix/business/flow';\nimport { Declined } from '@entifix/core';\nimport type { FlowEngine } from '@entifix/transactions';\nimport { Effect, Schedule, Schema } from 'effect';\nimport { describe, expect, it } from 'vitest';\n\nimport type { FakeParticipant } from '../doubles/flow-engine.js';\n\nconst contract = {\n input: Schema.Unknown,\n output: Schema.Unknown,\n failure: Schema.Unknown,\n};\n\nconst fragment = (\n id: string,\n kind: FragmentDescriptor['kind'],\n): FragmentDescriptor =>\n defineFragment({\n id: `contract.${id}`,\n version: 1,\n module: 'contract',\n kind,\n participant: 'contract',\n call: { method: 'POST', path: `/api/${id}` },\n ...(kind === 'compensatable'\n ? { compensation: { method: 'DELETE', path: `/api/${id}/:id` } as const }\n : {}),\n cardinality: 'one',\n contract,\n });\n\nconst hold = fragment('hold', 'compensatable');\nconst take = fragment('take', 'pivot');\nconst settle = fragment('settle', 'retriable');\nconst wait = fragment('await', 'wait');\n/** A wait that declares what it is answered with, for guards to branch on. */\nconst report = defineFragment({\n ...fragment('report', 'wait'),\n outcomes: ['delivered', 'refused'],\n});\nconst close = fragment('close', 'retriable');\nconst restore = fragment('restore', 'retriable');\n\n/** The catalog every case composes its slips from. */\nexport const flowEngineContractCatalog: FragmentCatalog = defineCatalog([\n hold,\n take,\n settle,\n wait,\n report,\n close,\n restore,\n]);\n\nconst stepOf = (descriptor: FragmentDescriptor): SlipStep => ({\n ref: fragmentRef(descriptor),\n step: descriptor.id.replace('contract.', ''),\n cardinality: 'one',\n});\n\nconst slipOf = (\n flowId: string,\n steps: readonly FragmentDescriptor[],\n): Slip => ({\n slipVersion: 1,\n flowId,\n recipe: 'contract',\n stages: [{ name: 'main', steps: steps.map(stepOf) }],\n resolution: [],\n composedAt: '2026-01-01T00:00:00.000Z',\n});\n\n/**\n * take ▸ report ▸ close (on `delivered`) ▸ restore (on `refused` or the\n * timeout's `unanswered`): the one branch a slip can take, on a wait's answer.\n */\nconst branchingSlip = (\n flowId: string,\n report: Readonly<Record<string, unknown>> = {},\n): Slip => ({\n ...slipOf(flowId, []),\n stages: [\n {\n name: 'main',\n steps: [\n { ref: fragmentRef(take), step: 'take', cardinality: 'one' },\n {\n ref: 'contract.report@1',\n step: 'report',\n cardinality: 'one',\n parameters: { correlation: `parcel-${flowId}`, ...report },\n },\n {\n ref: fragmentRef(close),\n step: 'close',\n cardinality: 'one',\n guard: { wait: 'report', outcomes: ['delivered'] },\n },\n {\n ref: fragmentRef(restore),\n step: 'restore',\n cardinality: 'one',\n guard: { wait: 'report', outcomes: ['refused', 'unanswered'] },\n },\n ],\n },\n ],\n});\n\n/** A participant that succeeds, remembering every step it was called for. */\nconst recording = () => {\n const called: string[] = [];\n const participant: FakeParticipant = step => {\n called.push(step.step);\n return Effect.succeed({ ok: true });\n };\n return { called, participant };\n};\n\nconst failing =\n (failAt: string): FakeParticipant =>\n step =>\n step.step === failAt\n ? Effect.fail(new Declined({ reason: 'refused' }))\n : Effect.succeed({ ok: true });\n\nconst succeeding: FakeParticipant = () => Effect.succeed({ ok: true });\n\n/**\n * What every {@link FlowEngine} must guarantee, whatever runs it: a start is\n * idempotent on its key, a failure before the commit point compensates and one\n * after it suspends, a wait takes the signal it waits for and no other, and an\n * unknown flow is a typed `FlowNotFound`.\n *\n * `make` builds a fresh engine over the contract's catalog and the participant\n * a case supplies.\n */\nexport const describeFlowEngineContract = (\n name: string,\n make: (\n catalog: FragmentCatalog,\n participant: FakeParticipant,\n ) => FlowEngine | Promise<FlowEngine>,\n): void => {\n const run = <A, E>(effect: Effect.Effect<A, E>) => Effect.runPromise(effect);\n /**\n * The flow's status once it has stopped moving. A start answers the flow id,\n * never the outcome — a durable engine runs the slip detached — so a case\n * reads the state the flow comes to rest in, a wait included.\n */\n const settled = (engine: FlowEngine, flowId: string) =>\n run(\n engine.status(flowId).pipe(\n Effect.repeat({\n until: status => status.state !== 'running',\n schedule: Schedule.spaced('10 millis'),\n times: 200,\n }),\n ),\n );\n const state = async (engine: FlowEngine, flowId: string) =>\n (await settled(engine, flowId)).state;\n\n describe(`FlowEngine contract: ${name}`, () => {\n it('answers the slip’s flow id, and the same one for a repeated key', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n const slip = slipOf('flow-1', [hold, take, settle]);\n\n const first = await run(engine.start(slip, 'key-1'));\n const again = await run(engine.start(slipOf('flow-2', [hold]), 'key-1'));\n\n expect(first).toEqual({ flowId: 'flow-1' });\n expect(again).toEqual({ flowId: 'flow-1' });\n });\n\n it('completes a flow whose every step succeeds', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n await run(engine.start(slipOf('flow-1', [hold, take, settle]), 'k'));\n\n expect(await state(engine, 'flow-1')).toBe('completed');\n });\n\n it('compensates a failure before the commit point', async () => {\n const engine = await make(flowEngineContractCatalog, failing('take'));\n await run(engine.start(slipOf('flow-1', [hold, take, settle]), 'k'));\n\n expect(await state(engine, 'flow-1')).toBe('compensated');\n });\n\n it('suspends a failure after the commit point, at that step', async () => {\n const engine = await make(flowEngineContractCatalog, failing('settle'));\n await run(engine.start(slipOf('flow-1', [hold, take, settle]), 'k'));\n\n expect(await settled(engine, 'flow-1')).toMatchObject({\n state: 'suspended',\n step: 'settle',\n });\n });\n\n it('waits for the signal it waits for, and refuses any other', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n await run(engine.start(slipOf('flow-1', [take, wait, settle]), 'k'));\n\n expect(await state(engine, 'flow-1')).toBe('waiting');\n const wrong = await run(\n Effect.flip(engine.signal('flow-1', 'elsewhere', {})),\n );\n expect(wrong._tag).toBe('FlowSignalRejected');\n\n await run(engine.signal('flow-1', 'await', { delivered: true }));\n expect(await state(engine, 'flow-1')).toBe('completed');\n\n const late = await run(Effect.flip(engine.signal('flow-1', 'await', {})));\n expect(late._tag).toBe('FlowSignalRejected');\n });\n\n it('completes a wait by what it is correlated with', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n const slip = slipOf('flow-1', [take, wait, settle]);\n const correlated: Slip = {\n ...slip,\n stages: slip.stages.map(stage => ({\n ...stage,\n steps: stage.steps.map(step =>\n step.step === 'await'\n ? { ...step, parameters: { correlation: 'order-7' } }\n : step,\n ),\n })),\n };\n await run(engine.start(correlated, 'k'));\n expect(await state(engine, 'flow-1')).toBe('waiting');\n\n const stranger = await run(\n Effect.flip(engine.signalCorrelated('order-8', { outcome: 'any' })),\n );\n expect(stranger._tag).toBe('FlowNotFound');\n\n await run(engine.signalCorrelated('order-7', { outcome: 'delivered' }));\n expect(await state(engine, 'flow-1')).toBe('completed');\n });\n\n it('leaves every flow a signal resumed finished, however many resume at once', async () => {\n // A wait resumed as its last step finishes almost at once, so nothing\n // the signal records may land after the resume: a `running` written\n // behind the flow's own `completed` would pin it there. A burst rather\n // than one flow, because an ordering fault shows up only under load.\n const engine = await make(flowEngineContractCatalog, succeeding);\n const flowIds = Array.from({ length: 20 }, (_, n) => `burst-${n}`);\n for (const flowId of flowIds)\n await run(engine.start(slipOf(flowId, [take, wait]), flowId));\n for (const flowId of flowIds)\n expect(await state(engine, flowId)).toBe('waiting');\n\n await run(\n Effect.forEach(\n flowIds,\n flowId => engine.signal(flowId, 'await', { delivered: true }),\n { concurrency: 'unbounded' },\n ),\n );\n\n const states = await Promise.all(\n flowIds.map(flowId => state(engine, flowId)),\n );\n expect(states.filter(next => next !== 'completed')).toEqual([]);\n });\n\n it('runs only the steps guarded on the outcome a wait was answered with', async () => {\n const { called, participant } = recording();\n const engine = await make(flowEngineContractCatalog, participant);\n await run(engine.start(branchingSlip('flow-1'), 'k'));\n expect(await state(engine, 'flow-1')).toBe('waiting');\n\n await run(\n engine.signalCorrelated('parcel-flow-1', { outcome: 'refused' }),\n );\n\n expect(await state(engine, 'flow-1')).toBe('completed');\n expect(called).toEqual(['take', 'restore']);\n });\n\n it('refuses a correlated signal its wait is not answered with', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n await run(engine.start(branchingSlip('flow-1'), 'k'));\n expect(await state(engine, 'flow-1')).toBe('waiting');\n\n const stray = await run(\n Effect.flip(\n engine.signalCorrelated('parcel-flow-1', { outcome: 'returned' }),\n ),\n );\n\n expect(stray._tag).toBe('FlowSignalRejected');\n expect(await state(engine, 'flow-1')).toBe('waiting');\n });\n\n it('answers FlowNotFound to a correlated signal once nothing is parked on it', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n await run(engine.start(branchingSlip('flow-1'), 'k'));\n await settled(engine, 'flow-1');\n await run(\n engine.signalCorrelated('parcel-flow-1', { outcome: 'delivered' }),\n );\n expect(await state(engine, 'flow-1')).toBe('completed');\n\n const again = await run(\n Effect.flip(\n engine.signalCorrelated('parcel-flow-1', { outcome: 'delivered' }),\n ),\n );\n\n expect(again._tag).toBe('FlowNotFound');\n });\n\n it('answers a timed-out wait with the outcome its onTimeout names', async () => {\n const { called, participant } = recording();\n const engine = await make(flowEngineContractCatalog, participant);\n await run(\n engine.start(\n branchingSlip('flow-1', {\n timeoutMs: 20,\n onTimeout: { outcome: 'unanswered' },\n }),\n 'k',\n ),\n );\n\n const status = await run(\n engine.status('flow-1').pipe(\n Effect.repeat({\n until: next => next.state === 'completed',\n schedule: Schedule.spaced('10 millis'),\n times: 200,\n }),\n ),\n );\n\n expect(status.state).toBe('completed');\n expect(called).toEqual(['take', 'restore']);\n });\n\n it('strands a flow whose wait runs out and strands on its timeout', async () => {\n const { called, participant } = recording();\n const engine = await make(flowEngineContractCatalog, participant);\n await run(\n engine.start(\n branchingSlip('flow-1', { timeoutMs: 20, onTimeout: 'strand' }),\n 'k',\n ),\n );\n\n const status = await run(\n engine.status('flow-1').pipe(\n Effect.repeat({\n until: next => next.state === 'stranded',\n schedule: Schedule.spaced('10 millis'),\n times: 200,\n }),\n ),\n );\n\n expect(status).toMatchObject({ state: 'stranded', step: 'report' });\n expect(called).toEqual(['take']);\n });\n\n it('interrupts a waiting flow', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n await run(engine.start(slipOf('flow-1', [take, wait]), 'k'));\n expect(await state(engine, 'flow-1')).toBe('waiting');\n\n await run(engine.interrupt('flow-1'));\n\n expect(await state(engine, 'flow-1')).toBe('interrupted');\n });\n\n it('answers FlowNotFound for a flow it never started', async () => {\n const engine = await make(flowEngineContractCatalog, succeeding);\n\n for (const effect of [\n engine.status('nope'),\n engine.signal('nope', 'await', {}),\n engine.signalCorrelated('nope', { outcome: 'any' }),\n engine.interrupt('nope'),\n ])\n expect((await run(Effect.flip(effect)))._tag).toBe('FlowNotFound');\n });\n });\n};\n"],"names":["defineCatalog","defineFragment","fragmentRef","Declined","Effect","Schedule","Schema","describe","expect","it","contract","input","Unknown","output","failure","fragment","id","kind","version","module","participant","call","method","path","compensation","cardinality","hold","take","settle","wait","report","outcomes","close","restore","flowEngineContractCatalog","stepOf","descriptor","ref","step","replace","slipOf","flowId","steps","slipVersion","recipe","stages","name","map","resolution","composedAt","branchingSlip","parameters","correlation","guard","recording","called","push","succeed","ok","failing","failAt","fail","reason","succeeding","describeFlowEngineContract","make","run","effect","runPromise","settled","engine","status","pipe","repeat","until","state","schedule","spaced","times","slip","first","start","again","toEqual","toBe","toMatchObject","wrong","flip","signal","_tag","delivered","late","correlated","stage","stranger","signalCorrelated","outcome","flowIds","Array","from","length","_","n","forEach","concurrency","states","Promise","all","filter","next","stray","timeoutMs","onTimeout","interrupt"],"mappings":";AAAA,SACEA,aAAa,EACbC,cAAc,EAGdC,WAAW,QAGN,yBAAyB;AAChC,SAASC,QAAQ,QAAQ,gBAAgB;AAEzC,SAASC,MAAM,EAAEC,QAAQ,EAAEC,MAAM,QAAQ,SAAS;AAClD,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAS;AAI9C,MAAMC,WAAW;IACfC,OAAOL,OAAOM,OAAO;IACrBC,QAAQP,OAAOM,OAAO;IACtBE,SAASR,OAAOM,OAAO;AACzB;AAEA,MAAMG,WAAW,CACfC,IACAC,OAEAhB,eAAe;QACbe,IAAI,CAAC,SAAS,EAAEA,IAAI;QACpBE,SAAS;QACTC,QAAQ;QACRF;QACAG,aAAa;QACbC,MAAM;YAAEC,QAAQ;YAAQC,MAAM,CAAC,KAAK,EAAEP,IAAI;QAAC;OACvCC,SAAS,kBACT;QAAEO,cAAc;YAAEF,QAAQ;YAAUC,MAAM,CAAC,KAAK,EAAEP,GAAG,IAAI,CAAC;QAAC;IAAW,IACtE,CAAC;QACLS,aAAa;QACbf;;AAGJ,MAAMgB,OAAOX,SAAS,QAAQ;AAC9B,MAAMY,OAAOZ,SAAS,QAAQ;AAC9B,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ACpB,QAAO,EAAGsB,IAAI,EAAEL,IAAI,CAAC;QACvD;IACF;AACF,EAAE"}
|
|
@@ -6,7 +6,6 @@ export * from './flow-engine.contract.js';
|
|
|
6
6
|
export * from './idempotency-store.contract.js';
|
|
7
7
|
export * from './outbox.contract.js';
|
|
8
8
|
export * from './push-channel.contract.js';
|
|
9
|
-
export * from './saga-store.contract.js';
|
|
10
9
|
export * from './server-push.contract.js';
|
|
11
10
|
export * from './transaction-ports.contract.js';
|
|
12
11
|
export * from './unit-of-work.contract.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC"}
|
package/dist/contracts/index.js
CHANGED
|
@@ -6,7 +6,6 @@ export * from './flow-engine.contract.js';
|
|
|
6
6
|
export * from './idempotency-store.contract.js';
|
|
7
7
|
export * from './outbox.contract.js';
|
|
8
8
|
export * from './push-channel.contract.js';
|
|
9
|
-
export * from './saga-store.contract.js';
|
|
10
9
|
export * from './server-push.contract.js';
|
|
11
10
|
export * from './transaction-ports.contract.js';
|
|
12
11
|
export * from './unit-of-work.contract.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/contracts/index.ts"],"sourcesContent":["export * from './breaker.contract.js';\nexport * from './entity-facet-counter.contract.js';\nexport * from './entity-repository.contract.js';\nexport * from './failure.contract.js';\nexport * from './flow-engine.contract.js';\nexport * from './idempotency-store.contract.js';\nexport * from './outbox.contract.js';\nexport * from './push-channel.contract.js';\nexport * from './
|
|
1
|
+
{"version":3,"sources":["../../src/contracts/index.ts"],"sourcesContent":["export * from './breaker.contract.js';\nexport * from './entity-facet-counter.contract.js';\nexport * from './entity-repository.contract.js';\nexport * from './failure.contract.js';\nexport * from './flow-engine.contract.js';\nexport * from './idempotency-store.contract.js';\nexport * from './outbox.contract.js';\nexport * from './push-channel.contract.js';\nexport * from './server-push.contract.js';\nexport * from './transaction-ports.contract.js';\nexport * from './unit-of-work.contract.js';\nexport * from './variants.contract.js';\n"],"names":[],"mappings":"AAAA,cAAc,wBAAwB;AACtC,cAAc,qCAAqC;AACnD,cAAc,kCAAkC;AAChD,cAAc,wBAAwB;AACtC,cAAc,4BAA4B;AAC1C,cAAc,kCAAkC;AAChD,cAAc,uBAAuB;AACrC,cAAc,6BAA6B;AAC3C,cAAc,4BAA4B;AAC1C,cAAc,kCAAkC;AAChD,cAAc,6BAA6B;AAC3C,cAAc,yBAAyB"}
|
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
import { type DomainEvent } from '@entifix/core';
|
|
2
|
-
import type { EventBus,
|
|
3
|
-
/**
|
|
4
|
-
* What every {@link LockService} must guarantee: exclusivity while held,
|
|
5
|
-
* availability after release, and a release that only frees the caller's own
|
|
6
|
-
* lock. The last one is why `release` takes a handle rather than a key — a lock
|
|
7
|
-
* that lapsed and was re-acquired by someone else must not be freed by the
|
|
8
|
-
* previous holder.
|
|
9
|
-
*/
|
|
10
|
-
export declare const describeLockServiceContract: (name: string, makeLockService: () => LockService | Promise<LockService>) => void;
|
|
11
|
-
/**
|
|
12
|
-
* What every {@link SequenceService} must guarantee: strictly increasing values
|
|
13
|
-
* per name, never repeating, with names independent of one another. This is the
|
|
14
|
-
* property incremental codes rest on.
|
|
15
|
-
*/
|
|
16
|
-
export declare const describeSequenceServiceContract: (name: string, makeSequenceService: () => SequenceService | Promise<SequenceService>) => void;
|
|
2
|
+
import type { EventBus, TransactionInbox } from '@entifix/transactions';
|
|
17
3
|
export interface EventBusContractHarness {
|
|
18
4
|
bus: EventBus;
|
|
19
5
|
/** Delivers `event` to whatever subscribed, as the broker would. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-ports.contract.d.ts","sourceRoot":"","sources":["../../src/contracts/transaction-ports.contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAiB,MAAM,eAAe,CAAC;AAChE,OAAO,KAAK,EACV,QAAQ,
|
|
1
|
+
{"version":3,"file":"transaction-ports.contract.d.ts","sourceRoot":"","sources":["../../src/contracts/transaction-ports.contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAiB,MAAM,eAAe,CAAC;AAChE,OAAO,KAAK,EACV,QAAQ,EAER,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAO/B,MAAM,WAAW,uBAAuB;IACtC,GAAG,EAAE,QAAQ,CAAC;IACd,oEAAoE;IACpE,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,8DAA8D;IAC9D,SAAS,IAAI,WAAW,EAAE,CAAC;CAC5B;AAiDD;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GACnC,MAAM,MAAM,EACZ,aAAa,MAAM,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,CAAC,KAC5E,IAkDF,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gCAAgC,GAC3C,MAAM,MAAM,EACZ,WAAW,CAAC,QAAQ,EAAE,MAAM,KAAK,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,KAC5E,IAyCF,CAAC"}
|
|
@@ -1,93 +1,7 @@
|
|
|
1
1
|
import { registerEvent } from '@entifix/core';
|
|
2
|
-
import {
|
|
3
|
-
import { TestClock } from 'effect/testing';
|
|
2
|
+
import { Effect, Schema } from 'effect';
|
|
4
3
|
import { describe, expect, it } from 'vitest';
|
|
5
|
-
/**
|
|
6
|
-
* Runs an Effect test on a `TestClock`, so a retry budget measured in seconds
|
|
7
|
-
* costs none of the wall clock.
|
|
8
|
-
*/ const effectIt = {
|
|
9
|
-
effect: (name, body)=>it(name, ()=>Effect.runPromise(body().pipe(Effect.provide(TestClock.layer()), Effect.scoped)))
|
|
10
|
-
};
|
|
11
4
|
const run = (effect)=>Effect.runPromise(effect);
|
|
12
|
-
/**
|
|
13
|
-
* What every {@link LockService} must guarantee: exclusivity while held,
|
|
14
|
-
* availability after release, and a release that only frees the caller's own
|
|
15
|
-
* lock. The last one is why `release` takes a handle rather than a key — a lock
|
|
16
|
-
* that lapsed and was re-acquired by someone else must not be freed by the
|
|
17
|
-
* previous holder.
|
|
18
|
-
*/ export const describeLockServiceContract = (name, makeLockService)=>{
|
|
19
|
-
describe(`LockService contract: ${name}`, ()=>{
|
|
20
|
-
it('acquires an uncontended key', async ()=>{
|
|
21
|
-
const locks = await makeLockService();
|
|
22
|
-
const handle = await run(locks.acquire('contract:free'));
|
|
23
|
-
expect(handle.key).toBe('contract:free');
|
|
24
|
-
expect(handle.token).toBeTruthy();
|
|
25
|
-
});
|
|
26
|
-
// An implementation may retry before giving up (the Redis adapter waits out
|
|
27
|
-
// a bounded budget), so this runs on a TestClock: the assertion is about
|
|
28
|
-
// exclusivity, and it should not cost seconds of wall clock to make.
|
|
29
|
-
effectIt.effect('refuses a key that is already held', ()=>Effect.gen(function*() {
|
|
30
|
-
const locks = yield* Effect.promise(async ()=>makeLockService());
|
|
31
|
-
yield* locks.acquire('contract:taken');
|
|
32
|
-
const fiber = yield* Effect.forkChild(locks.acquire('contract:taken'));
|
|
33
|
-
yield* TestClock.adjust(Duration.minutes(1));
|
|
34
|
-
const exit = yield* Fiber.await(fiber);
|
|
35
|
-
expect(Exit.isFailure(exit)).toBe(true);
|
|
36
|
-
}));
|
|
37
|
-
it('makes the key available again after release', async ()=>{
|
|
38
|
-
const locks = await makeLockService();
|
|
39
|
-
const handle = await run(locks.acquire('contract:cycle'));
|
|
40
|
-
await run(locks.release(handle));
|
|
41
|
-
const reacquired = await run(locks.acquire('contract:cycle'));
|
|
42
|
-
expect(reacquired.key).toBe('contract:cycle');
|
|
43
|
-
});
|
|
44
|
-
effectIt.effect('ignores a release whose token does not match', ()=>Effect.gen(function*() {
|
|
45
|
-
const locks = yield* Effect.promise(async ()=>makeLockService());
|
|
46
|
-
const handle = yield* locks.acquire('contract:stolen');
|
|
47
|
-
yield* locks.release({
|
|
48
|
-
key: handle.key,
|
|
49
|
-
token: 'not-mine'
|
|
50
|
-
});
|
|
51
|
-
// Still held, so a fresh acquisition must fail.
|
|
52
|
-
const fiber = yield* Effect.forkChild(locks.acquire('contract:stolen'));
|
|
53
|
-
yield* TestClock.adjust(Duration.minutes(1));
|
|
54
|
-
const exit = yield* Fiber.await(fiber);
|
|
55
|
-
expect(Exit.isFailure(exit)).toBe(true);
|
|
56
|
-
}));
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* What every {@link SequenceService} must guarantee: strictly increasing values
|
|
61
|
-
* per name, never repeating, with names independent of one another. This is the
|
|
62
|
-
* property incremental codes rest on.
|
|
63
|
-
*/ export const describeSequenceServiceContract = (name, makeSequenceService)=>{
|
|
64
|
-
describe(`SequenceService contract: ${name}`, ()=>{
|
|
65
|
-
it('starts at 1', async ()=>{
|
|
66
|
-
const sequences = await makeSequenceService();
|
|
67
|
-
expect(await run(sequences.next('contract:fresh'))).toBe(1);
|
|
68
|
-
});
|
|
69
|
-
it('never returns the same value twice for a name', async ()=>{
|
|
70
|
-
const sequences = await makeSequenceService();
|
|
71
|
-
const drawn = [
|
|
72
|
-
await run(sequences.next('contract:codes')),
|
|
73
|
-
await run(sequences.next('contract:codes')),
|
|
74
|
-
await run(sequences.next('contract:codes'))
|
|
75
|
-
];
|
|
76
|
-
expect(drawn).toEqual([
|
|
77
|
-
1,
|
|
78
|
-
2,
|
|
79
|
-
3
|
|
80
|
-
]);
|
|
81
|
-
expect(new Set(drawn).size).toBe(drawn.length);
|
|
82
|
-
});
|
|
83
|
-
it('keeps separate names independent', async ()=>{
|
|
84
|
-
const sequences = await makeSequenceService();
|
|
85
|
-
await run(sequences.next('contract:a'));
|
|
86
|
-
await run(sequences.next('contract:a'));
|
|
87
|
-
expect(await run(sequences.next('contract:b'))).toBe(1);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
5
|
/** Every subscription in this contract, unless a test says otherwise. */ const ANY_WIDGET_EVENT = 'contract.widget.*';
|
|
92
6
|
/**
|
|
93
7
|
* A `work` subscription for `pattern`. The mode and the ceiling are broker
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/contracts/transaction-ports.contract.ts"],"sourcesContent":["import { type DomainEvent, registerEvent } from '@entifix/core';\nimport type {\n EventBus,\n LockService,\n SequenceService,\n Subscription,\n TransactionInbox,\n} from '@entifix/transactions';\nimport { Duration, Effect, Exit, Fiber, Schema } from 'effect';\nimport { TestClock } from 'effect/testing';\nimport { describe, expect, it } from 'vitest';\n\n/**\n * Runs an Effect test on a `TestClock`, so a retry budget measured in seconds\n * costs none of the wall clock.\n */\nconst effectIt = {\n effect: (name: string, body: () => Effect.Effect<unknown, unknown>) =>\n it(name, () =>\n Effect.runPromise(\n body().pipe(Effect.provide(TestClock.layer()), Effect.scoped),\n ),\n ),\n};\n\nconst run = <TValue, TError>(effect: Effect.Effect<TValue, TError>) =>\n Effect.runPromise(effect);\n\n/**\n * What every {@link LockService} must guarantee: exclusivity while held,\n * availability after release, and a release that only frees the caller's own\n * lock. The last one is why `release` takes a handle rather than a key — a lock\n * that lapsed and was re-acquired by someone else must not be freed by the\n * previous holder.\n */\nexport const describeLockServiceContract = (\n name: string,\n makeLockService: () => LockService | Promise<LockService>,\n): void => {\n describe(`LockService contract: ${name}`, () => {\n it('acquires an uncontended key', async () => {\n const locks = await makeLockService();\n\n const handle = await run(locks.acquire('contract:free'));\n\n expect(handle.key).toBe('contract:free');\n expect(handle.token).toBeTruthy();\n });\n\n // An implementation may retry before giving up (the Redis adapter waits out\n // a bounded budget), so this runs on a TestClock: the assertion is about\n // exclusivity, and it should not cost seconds of wall clock to make.\n effectIt.effect('refuses a key that is already held', () =>\n Effect.gen(function* () {\n const locks = yield* Effect.promise(async () => makeLockService());\n yield* locks.acquire('contract:taken');\n\n const fiber = yield* Effect.forkChild(locks.acquire('contract:taken'));\n yield* TestClock.adjust(Duration.minutes(1));\n const exit = yield* Fiber.await(fiber);\n\n expect(Exit.isFailure(exit)).toBe(true);\n }),\n );\n\n it('makes the key available again after release', async () => {\n const locks = await makeLockService();\n const handle = await run(locks.acquire('contract:cycle'));\n\n await run(locks.release(handle));\n const reacquired = await run(locks.acquire('contract:cycle'));\n\n expect(reacquired.key).toBe('contract:cycle');\n });\n\n effectIt.effect('ignores a release whose token does not match', () =>\n Effect.gen(function* () {\n const locks = yield* Effect.promise(async () => makeLockService());\n const handle = yield* locks.acquire('contract:stolen');\n\n yield* locks.release({ key: handle.key, token: 'not-mine' });\n\n // Still held, so a fresh acquisition must fail.\n const fiber = yield* Effect.forkChild(locks.acquire('contract:stolen'));\n yield* TestClock.adjust(Duration.minutes(1));\n const exit = yield* Fiber.await(fiber);\n\n expect(Exit.isFailure(exit)).toBe(true);\n }),\n );\n });\n};\n\n/**\n * What every {@link SequenceService} must guarantee: strictly increasing values\n * per name, never repeating, with names independent of one another. This is the\n * property incremental codes rest on.\n */\nexport const describeSequenceServiceContract = (\n name: string,\n makeSequenceService: () => SequenceService | Promise<SequenceService>,\n): void => {\n describe(`SequenceService contract: ${name}`, () => {\n it('starts at 1', async () => {\n const sequences = await makeSequenceService();\n\n expect(await run(sequences.next('contract:fresh'))).toBe(1);\n });\n\n it('never returns the same value twice for a name', async () => {\n const sequences = await makeSequenceService();\n\n const drawn = [\n await run(sequences.next('contract:codes')),\n await run(sequences.next('contract:codes')),\n await run(sequences.next('contract:codes')),\n ];\n\n expect(drawn).toEqual([1, 2, 3]);\n expect(new Set(drawn).size).toBe(drawn.length);\n });\n\n it('keeps separate names independent', async () => {\n const sequences = await makeSequenceService();\n await run(sequences.next('contract:a'));\n await run(sequences.next('contract:a'));\n\n expect(await run(sequences.next('contract:b'))).toBe(1);\n });\n });\n};\n\nexport interface EventBusContractHarness {\n bus: EventBus;\n /** Delivers `event` to whatever subscribed, as the broker would. */\n deliver(event: DomainEvent): Promise<void>;\n /** Everything the bus published, decoded back into events. */\n published(): DomainEvent[];\n}\n\n/** Every subscription in this contract, unless a test says otherwise. */\nconst ANY_WIDGET_EVENT = 'contract.widget.*';\n\n/**\n * A `work` subscription for `pattern`. The mode and the ceiling are broker\n * facts with no bearing on routing, so a test about routing states them once\n * here rather than repeating them at every call.\n */\nconst on = (pattern: string): Subscription => ({\n slice: 'contract',\n pattern,\n mode: 'work',\n maxAttempts: 5,\n});\n\n/**\n * A handler that records what it is given. Shared by both routing tests so the\n * \"nothing was delivered\" case asserts on the *same* handler the positive case\n * proves works — otherwise it could pass against a handler that was simply\n * never wired up.\n */\nconst collectInto = (sink: DomainEvent[]) => (event: DomainEvent) =>\n Effect.sync(() => {\n sink.push(event);\n });\n\n// A transport encodes and decodes through the registry, so the suite's own\n// event is registered like any other — audience-free, since nothing here\n// delivers to a person.\nregisterEvent(\n 'contract.widget.created',\n Schema.Struct({ entity: Schema.String }),\n { audience: 'none' },\n);\n\nconst anEvent = (\n id: string,\n name = 'contract.widget.created',\n): DomainEvent => ({\n name,\n id,\n source: 'contract-slice',\n at: new Date('2026-01-01T00:00:00.000Z').toISOString(),\n correlationId: id,\n data: { entity: 'contract-widget' },\n});\n\n/**\n * What every {@link EventBus} must guarantee: what goes out comes back\n * unchanged, subscribers receive deliveries, and a subscriber receives only what\n * its pattern matches. The transports differ wildly (an array here, a topic\n * exchange in RabbitMQ) — the observable contract does not.\n */\nexport const describeEventBusContract = (\n name: string,\n makeHarness: () => EventBusContractHarness | Promise<EventBusContractHarness>,\n): void => {\n describe(`EventBus contract: ${name}`, () => {\n it('publishes an event verbatim', async () => {\n const harness = await makeHarness();\n const event = anEvent('tx-1');\n\n await run(harness.bus.publish(event));\n\n expect(harness.published()).toEqual([event]);\n });\n\n it('delivers published events to a subscriber', async () => {\n const harness = await makeHarness();\n const received: DomainEvent[] = [];\n await run(\n harness.bus.subscribe(on(ANY_WIDGET_EVENT), collectInto(received)),\n );\n\n await harness.deliver(anEvent('tx-2'));\n\n expect(received.map(event => event.id)).toEqual(['tx-2']);\n });\n\n // Routing is the transport's job. A bus that hands every subscriber every\n // event lets a consumer pass while receiving traffic it never bound to —\n // which is precisely the fault the fanout exchange had.\n it('delivers nothing to a subscriber whose pattern does not match', async () => {\n const harness = await makeHarness();\n const received: DomainEvent[] = [];\n await run(\n harness.bus.subscribe(on('contract.other.*'), collectInto(received)),\n );\n\n await harness.deliver(anEvent('tx-5'));\n\n expect(received).toEqual([]);\n });\n\n it('preserves publication order', async () => {\n const harness = await makeHarness();\n\n await run(harness.bus.publish(anEvent('tx-3')));\n await run(harness.bus.publish(anEvent('tx-4')));\n\n expect(harness.published().map(event => event.id)).toEqual([\n 'tx-3',\n 'tx-4',\n ]);\n });\n });\n};\n\n/**\n * What every {@link TransactionInbox} must guarantee: a first claim is granted,\n * every repeat of it is refused, and one consumer's claim says nothing about\n * another's.\n *\n * That last one is the property with teeth. Two consumers legitimately process\n * the same event — the saga tracker's fold and the SSE hub both bind\n * `transaction.*` — so an implementation keyed on `eventId` alone passes the\n * first two cases and silently starves every consumer but the first. It looks\n * like exactly-once from inside one consumer, which is why it is asserted here\n * rather than left to each adapter's own spec.\n */\nexport const describeTransactionInboxContract = (\n name: string,\n makeInbox: (consumer: string) => TransactionInbox | Promise<TransactionInbox>,\n): void => {\n describe(`TransactionInbox contract: ${name}`, () => {\n it('grants a first claim', async () => {\n const inbox = await makeInbox('contract.consumer');\n\n expect(await run(inbox.claim('tx-1:completed'))).toBe('claimed');\n });\n\n it('refuses a redelivery of the same event', async () => {\n const inbox = await makeInbox('contract.consumer');\n await run(inbox.claim('tx-2:completed'));\n\n expect(await run(inbox.claim('tx-2:completed'))).toBe('duplicate');\n });\n\n it('refuses every repeat, not only the second', async () => {\n const inbox = await makeInbox('contract.consumer');\n await run(inbox.claim('tx-3:completed'));\n\n expect(await run(inbox.claim('tx-3:completed'))).toBe('duplicate');\n expect(await run(inbox.claim('tx-3:completed'))).toBe('duplicate');\n });\n\n it('claims each step of one transaction separately', async () => {\n // `<transactionId>:<step>`, never the transaction id alone: one\n // transaction emits up to three messages, and keying on the correlation\n // id would make `completed` read as a redelivery of `accepted`.\n const inbox = await makeInbox('contract.consumer');\n\n expect(await run(inbox.claim('tx-4:accepted'))).toBe('claimed');\n expect(await run(inbox.claim('tx-4:completed'))).toBe('claimed');\n });\n\n it('does not let one consumer consume another consumer’s claim', async () => {\n const first = await makeInbox('contract.first');\n const second = await makeInbox('contract.second');\n await run(first.claim('tx-5:completed'));\n\n expect(await run(second.claim('tx-5:completed'))).toBe('claimed');\n });\n });\n};\n"],"names":["registerEvent","Duration","Effect","Exit","Fiber","Schema","TestClock","describe","expect","it","effectIt","effect","name","body","runPromise","pipe","provide","layer","scoped","run","describeLockServiceContract","makeLockService","locks","handle","acquire","key","toBe","token","toBeTruthy","gen","promise","fiber","forkChild","adjust","minutes","exit","await","isFailure","release","reacquired","describeSequenceServiceContract","makeSequenceService","sequences","next","drawn","toEqual","Set","size","length","ANY_WIDGET_EVENT","on","pattern","slice","mode","maxAttempts","collectInto","sink","event","sync","push","Struct","entity","String","audience","anEvent","id","source","at","Date","toISOString","correlationId","data","describeEventBusContract","makeHarness","harness","bus","publish","published","received","subscribe","deliver","map","describeTransactionInboxContract","makeInbox","inbox","claim","first","second"],"mappings":"AAAA,SAA2BA,aAAa,QAAQ,gBAAgB;AAQhE,SAASC,QAAQ,EAAEC,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,MAAM,QAAQ,SAAS;AAC/D,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAS;AAE9C;;;CAGC,GACD,MAAMC,WAAW;IACfC,QAAQ,CAACC,MAAcC,OACrBJ,GAAGG,MAAM,IACPV,OAAOY,UAAU,CACfD,OAAOE,IAAI,CAACb,OAAOc,OAAO,CAACV,UAAUW,KAAK,KAAKf,OAAOgB,MAAM;AAGpE;AAEA,MAAMC,MAAM,CAAiBR,SAC3BT,OAAOY,UAAU,CAACH;AAEpB;;;;;;CAMC,GACD,OAAO,MAAMS,8BAA8B,CACzCR,MACAS;IAEAd,SAAS,CAAC,sBAAsB,EAAEK,MAAM,EAAE;QACxCH,GAAG,+BAA+B;YAChC,MAAMa,QAAQ,MAAMD;YAEpB,MAAME,SAAS,MAAMJ,IAAIG,MAAME,OAAO,CAAC;YAEvChB,OAAOe,OAAOE,GAAG,EAAEC,IAAI,CAAC;YACxBlB,OAAOe,OAAOI,KAAK,EAAEC,UAAU;QACjC;QAEA,4EAA4E;QAC5E,yEAAyE;QACzE,qEAAqE;QACrElB,SAASC,MAAM,CAAC,sCAAsC,IACpDT,OAAO2B,GAAG,CAAC;gBACT,MAAMP,QAAQ,OAAOpB,OAAO4B,OAAO,CAAC,UAAYT;gBAChD,OAAOC,MAAME,OAAO,CAAC;gBAErB,MAAMO,QAAQ,OAAO7B,OAAO8B,SAAS,CAACV,MAAME,OAAO,CAAC;gBACpD,OAAOlB,UAAU2B,MAAM,CAAChC,SAASiC,OAAO,CAAC;gBAC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Q,MAAMD,UAAU;YAE9B3E,OAAO,MAAMW,IAAIiE,MAAMC,KAAK,CAAC,oBAAoB3D,IAAI,CAAC;QACxD;QAEAjB,GAAG,0CAA0C;YAC3C,MAAM2E,QAAQ,MAAMD,UAAU;YAC9B,MAAMhE,IAAIiE,MAAMC,KAAK,CAAC;YAEtB7E,OAAO,MAAMW,IAAIiE,MAAMC,KAAK,CAAC,oBAAoB3D,IAAI,CAAC;QACxD;QAEAjB,GAAG,6CAA6C;YAC9C,MAAM2E,QAAQ,MAAMD,UAAU;YAC9B,MAAMhE,IAAIiE,MAAMC,KAAK,CAAC;YAEtB7E,OAAO,MAAMW,IAAIiE,MAAMC,KAAK,CAAC,oBAAoB3D,IAAI,CAAC;YACtDlB,OAAO,MAAMW,IAAIiE,MAAMC,KAAK,CAAC,oBAAoB3D,IAAI,CAAC;QACxD;QAEAjB,GAAG,kDAAkD;YACnD,gEAAgE;YAChE,wEAAwE;YACxE,gEAAgE;YAChE,MAAM2E,QAAQ,MAAMD,UAAU;YAE9B3E,OAAO,MAAMW,IAAIiE,MAAMC,KAAK,CAAC,mBAAmB3D,IAAI,CAAC;YACrDlB,OAAO,MAAMW,IAAIiE,MAAMC,KAAK,CAAC,oBAAoB3D,IAAI,CAAC;QACxD;QAEAjB,GAAG,8DAA8D;YAC/D,MAAM6E,QAAQ,MAAMH,UAAU;YAC9B,MAAMI,SAAS,MAAMJ,UAAU;YAC/B,MAAMhE,IAAImE,MAAMD,KAAK,CAAC;YAEtB7E,OAAO,MAAMW,IAAIoE,OAAOF,KAAK,CAAC,oBAAoB3D,IAAI,CAAC;QACzD;IACF;AACF,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../src/contracts/transaction-ports.contract.ts"],"sourcesContent":["import { type DomainEvent, registerEvent } from '@entifix/core';\nimport type {\n EventBus,\n Subscription,\n TransactionInbox,\n} from '@entifix/transactions';\nimport { Effect, Schema } from 'effect';\nimport { describe, expect, it } from 'vitest';\n\nconst run = <TValue, TError>(effect: Effect.Effect<TValue, TError>) =>\n Effect.runPromise(effect);\n\nexport interface EventBusContractHarness {\n bus: EventBus;\n /** Delivers `event` to whatever subscribed, as the broker would. */\n deliver(event: DomainEvent): Promise<void>;\n /** Everything the bus published, decoded back into events. */\n published(): DomainEvent[];\n}\n\n/** Every subscription in this contract, unless a test says otherwise. */\nconst ANY_WIDGET_EVENT = 'contract.widget.*';\n\n/**\n * A `work` subscription for `pattern`. The mode and the ceiling are broker\n * facts with no bearing on routing, so a test about routing states them once\n * here rather than repeating them at every call.\n */\nconst on = (pattern: string): Subscription => ({\n slice: 'contract',\n pattern,\n mode: 'work',\n maxAttempts: 5,\n});\n\n/**\n * A handler that records what it is given. Shared by both routing tests so the\n * \"nothing was delivered\" case asserts on the *same* handler the positive case\n * proves works — otherwise it could pass against a handler that was simply\n * never wired up.\n */\nconst collectInto = (sink: DomainEvent[]) => (event: DomainEvent) =>\n Effect.sync(() => {\n sink.push(event);\n });\n\n// A transport encodes and decodes through the registry, so the suite's own\n// event is registered like any other — audience-free, since nothing here\n// delivers to a person.\nregisterEvent(\n 'contract.widget.created',\n Schema.Struct({ entity: Schema.String }),\n { audience: 'none' },\n);\n\nconst anEvent = (\n id: string,\n name = 'contract.widget.created',\n): DomainEvent => ({\n name,\n id,\n source: 'contract-slice',\n at: new Date('2026-01-01T00:00:00.000Z').toISOString(),\n correlationId: id,\n data: { entity: 'contract-widget' },\n});\n\n/**\n * What every {@link EventBus} must guarantee: what goes out comes back\n * unchanged, subscribers receive deliveries, and a subscriber receives only what\n * its pattern matches. The transports differ wildly (an array here, a topic\n * exchange in RabbitMQ) — the observable contract does not.\n */\nexport const describeEventBusContract = (\n name: string,\n makeHarness: () => EventBusContractHarness | Promise<EventBusContractHarness>,\n): void => {\n describe(`EventBus contract: ${name}`, () => {\n it('publishes an event verbatim', async () => {\n const harness = await makeHarness();\n const event = anEvent('tx-1');\n\n await run(harness.bus.publish(event));\n\n expect(harness.published()).toEqual([event]);\n });\n\n it('delivers published events to a subscriber', async () => {\n const harness = await makeHarness();\n const received: DomainEvent[] = [];\n await run(\n harness.bus.subscribe(on(ANY_WIDGET_EVENT), collectInto(received)),\n );\n\n await harness.deliver(anEvent('tx-2'));\n\n expect(received.map(event => event.id)).toEqual(['tx-2']);\n });\n\n // Routing is the transport's job. A bus that hands every subscriber every\n // event lets a consumer pass while receiving traffic it never bound to —\n // which is precisely the fault the fanout exchange had.\n it('delivers nothing to a subscriber whose pattern does not match', async () => {\n const harness = await makeHarness();\n const received: DomainEvent[] = [];\n await run(\n harness.bus.subscribe(on('contract.other.*'), collectInto(received)),\n );\n\n await harness.deliver(anEvent('tx-5'));\n\n expect(received).toEqual([]);\n });\n\n it('preserves publication order', async () => {\n const harness = await makeHarness();\n\n await run(harness.bus.publish(anEvent('tx-3')));\n await run(harness.bus.publish(anEvent('tx-4')));\n\n expect(harness.published().map(event => event.id)).toEqual([\n 'tx-3',\n 'tx-4',\n ]);\n });\n });\n};\n\n/**\n * What every {@link TransactionInbox} must guarantee: a first claim is granted,\n * every repeat of it is refused, and one consumer's claim says nothing about\n * another's.\n *\n * That last one is the property with teeth. Two consumers legitimately process\n * the same event — the saga tracker's fold and the SSE hub both bind\n * `transaction.*` — so an implementation keyed on `eventId` alone passes the\n * first two cases and silently starves every consumer but the first. It looks\n * like exactly-once from inside one consumer, which is why it is asserted here\n * rather than left to each adapter's own spec.\n */\nexport const describeTransactionInboxContract = (\n name: string,\n makeInbox: (consumer: string) => TransactionInbox | Promise<TransactionInbox>,\n): void => {\n describe(`TransactionInbox contract: ${name}`, () => {\n it('grants a first claim', async () => {\n const inbox = await makeInbox('contract.consumer');\n\n expect(await run(inbox.claim('tx-1:completed'))).toBe('claimed');\n });\n\n it('refuses a redelivery of the same event', async () => {\n const inbox = await makeInbox('contract.consumer');\n await run(inbox.claim('tx-2:completed'));\n\n expect(await run(inbox.claim('tx-2:completed'))).toBe('duplicate');\n });\n\n it('refuses every repeat, not only the second', async () => {\n const inbox = await makeInbox('contract.consumer');\n await run(inbox.claim('tx-3:completed'));\n\n expect(await run(inbox.claim('tx-3:completed'))).toBe('duplicate');\n expect(await run(inbox.claim('tx-3:completed'))).toBe('duplicate');\n });\n\n it('claims each step of one transaction separately', async () => {\n // `<transactionId>:<step>`, never the transaction id alone: one\n // transaction emits up to three messages, and keying on the correlation\n // id would make `completed` read as a redelivery of `accepted`.\n const inbox = await makeInbox('contract.consumer');\n\n expect(await run(inbox.claim('tx-4:accepted'))).toBe('claimed');\n expect(await run(inbox.claim('tx-4:completed'))).toBe('claimed');\n });\n\n it('does not let one consumer consume another consumer’s claim', async () => {\n const first = await makeInbox('contract.first');\n const second = await makeInbox('contract.second');\n await run(first.claim('tx-5:completed'));\n\n expect(await run(second.claim('tx-5:completed'))).toBe('claimed');\n });\n });\n};\n"],"names":["registerEvent","Effect","Schema","describe","expect","it","run","effect","runPromise","ANY_WIDGET_EVENT","on","pattern","slice","mode","maxAttempts","collectInto","sink","event","sync","push","Struct","entity","String","audience","anEvent","id","name","source","at","Date","toISOString","correlationId","data","describeEventBusContract","makeHarness","harness","bus","publish","published","toEqual","received","subscribe","deliver","map","describeTransactionInboxContract","makeInbox","inbox","claim","toBe","first","second"],"mappings":"AAAA,SAA2BA,aAAa,QAAQ,gBAAgB;AAMhE,SAASC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AACxC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAS;AAE9C,MAAMC,MAAM,CAAiBC,SAC3BN,OAAOO,UAAU,CAACD;AAUpB,uEAAuE,GACvE,MAAME,mBAAmB;AAEzB;;;;CAIC,GACD,MAAMC,KAAK,CAACC,UAAmC,CAAA;QAC7CC,OAAO;QACPD;QACAE,MAAM;QACNC,aAAa;IACf,CAAA;AAEA;;;;;CAKC,GACD,MAAMC,cAAc,CAACC,OAAwB,CAACC,QAC5ChB,OAAOiB,IAAI,CAAC;YACVF,KAAKG,IAAI,CAACF;QACZ;AAEF,2EAA2E;AAC3E,yEAA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AEA3C,GAAG,8DAA8D;YAC/D,MAAM4C,QAAQ,MAAMJ,UAAU;YAC9B,MAAMK,SAAS,MAAML,UAAU;YAC/B,MAAMvC,IAAI2C,MAAMF,KAAK,CAAC;YAEtB3C,OAAO,MAAME,IAAI4C,OAAOH,KAAK,CAAC,oBAAoBC,IAAI,CAAC;QACzD;IACF;AACF,EAAE"}
|
|
@@ -15,8 +15,11 @@ export interface FakeFlowEngine extends FlowEngine {
|
|
|
15
15
|
* ([ADR 0016](../../../../../docs/adr/0016-a-flow-engine-port-and-a-durable-workflow-adapter.md)):
|
|
16
16
|
* a failure before the commit point — the pivot's own included — compensates
|
|
17
17
|
* the steps that succeeded, in reverse; a failure after it suspends the flow;
|
|
18
|
-
* a `wait` parks it until a signal names that step
|
|
19
|
-
*
|
|
18
|
+
* a `wait` parks it until a signal names that step, or until its `timeoutMs`
|
|
19
|
+
* runs out and its `onTimeout` answers an outcome or strands the flow; a step
|
|
20
|
+
* guarded on a wait's answer runs only on the outcomes it names. It runs
|
|
21
|
+
* synchronously but for a timeout, and durably remembers nothing, which is
|
|
22
|
+
* what makes it a fake.
|
|
20
23
|
*/
|
|
21
24
|
export declare const makeFakeFlowEngine: (catalog: FragmentCatalog, participant: FakeParticipant) => FakeFlowEngine;
|
|
22
25
|
//# sourceMappingURL=flow-engine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-engine.d.ts","sourceRoot":"","sources":["../../src/doubles/flow-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAQ,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAE9E,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EACL,KAAK,UAAU,EAEf,KAAK,aAAa,EAInB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,mFAAmF;AACnF,MAAM,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