@dudousxd/nestjs-durable-testing 0.1.0 → 0.2.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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/replay.d.ts +22 -0
- package/dist/replay.d.ts.map +1 -0
- package/dist/replay.js +41 -0
- package/dist/replay.js.map +1 -0
- package/dist/transport-conformance.d.ts.map +1 -1
- package/dist/transport-conformance.js +27 -9
- package/dist/transport-conformance.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./assertions"), exports);
|
|
18
18
|
__exportStar(require("./harness"), exports);
|
|
19
|
+
__exportStar(require("./replay"), exports);
|
|
19
20
|
__exportStar(require("./steps"), exports);
|
|
20
21
|
__exportStar(require("./transport-conformance"), exports);
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,4CAA0B;AAC1B,0CAAwB;AACxB,0DAAwC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,4CAA0B;AAC1B,2CAAyB;AACzB,0CAAwB;AACxB,0DAAwC"}
|
package/dist/replay.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type StepCheckpoint, WorkflowEngine, type WorkflowRun } from '@dudousxd/nestjs-durable-core';
|
|
2
|
+
export interface RunHistory {
|
|
3
|
+
run: WorkflowRun;
|
|
4
|
+
checkpoints: StepCheckpoint[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Replay a recorded run's history against the CURRENT workflow code and throw if they diverged.
|
|
8
|
+
*
|
|
9
|
+
* Capture a real (ideally in-flight or representative) run from production —
|
|
10
|
+
* `{ run: await store.getRun(id), checkpoints: await store.listCheckpoints(id) }` — commit it as a
|
|
11
|
+
* fixture, and assert here in CI. If a code change renamed/reordered/removed a step at a position the
|
|
12
|
+
* history already recorded, the engine raises a `NonDeterminismError` on replay and this rethrows it,
|
|
13
|
+
* catching the break *before* it reaches an in-flight run on deploy (the moment you'd otherwise
|
|
14
|
+
* silently replay the wrong checkpoint into the wrong step). Register the workflow exactly as the app
|
|
15
|
+
* does:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* await assertReplayable((engine) => engine.register('pipeline', '1', pipeline.run), fixture);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function assertReplayable(register: (engine: WorkflowEngine) => void, history: RunHistory): Promise<void>;
|
|
22
|
+
//# sourceMappingURL=replay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../src/replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,cAAc,EACnB,cAAc,EACd,KAAK,WAAW,EACjB,MAAM,+BAA+B,CAAC;AAEvC,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,WAAW,CAAC;IACjB,WAAW,EAAE,cAAc,EAAE,CAAC;CAC/B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,EAC1C,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,IAAI,CAAC,CAoBf"}
|
package/dist/replay.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertReplayable = assertReplayable;
|
|
4
|
+
const nestjs_durable_core_1 = require("@dudousxd/nestjs-durable-core");
|
|
5
|
+
/**
|
|
6
|
+
* Replay a recorded run's history against the CURRENT workflow code and throw if they diverged.
|
|
7
|
+
*
|
|
8
|
+
* Capture a real (ideally in-flight or representative) run from production —
|
|
9
|
+
* `{ run: await store.getRun(id), checkpoints: await store.listCheckpoints(id) }` — commit it as a
|
|
10
|
+
* fixture, and assert here in CI. If a code change renamed/reordered/removed a step at a position the
|
|
11
|
+
* history already recorded, the engine raises a `NonDeterminismError` on replay and this rethrows it,
|
|
12
|
+
* catching the break *before* it reaches an in-flight run on deploy (the moment you'd otherwise
|
|
13
|
+
* silently replay the wrong checkpoint into the wrong step). Register the workflow exactly as the app
|
|
14
|
+
* does:
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* await assertReplayable((engine) => engine.register('pipeline', '1', pipeline.run), fixture);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
async function assertReplayable(register, history) {
|
|
21
|
+
const store = new nestjs_durable_core_1.InMemoryStateStore();
|
|
22
|
+
// Seed as a suspended run with no lock so resume() replays the body against the recorded
|
|
23
|
+
// checkpoints — no transport is wired, so nothing new is dispatched.
|
|
24
|
+
await store.createRun({
|
|
25
|
+
...history.run,
|
|
26
|
+
status: 'suspended',
|
|
27
|
+
lockedBy: undefined,
|
|
28
|
+
lockedUntil: undefined,
|
|
29
|
+
});
|
|
30
|
+
for (const cp of history.checkpoints)
|
|
31
|
+
await store.saveCheckpoint(cp);
|
|
32
|
+
const engine = new nestjs_durable_core_1.WorkflowEngine({ store });
|
|
33
|
+
register(engine);
|
|
34
|
+
const result = await engine.resume(history.run.id);
|
|
35
|
+
if (result.status === 'failed' && result.error?.message?.startsWith('non-determinism')) {
|
|
36
|
+
const err = new Error(result.error.message);
|
|
37
|
+
err.name = 'NonDeterminismError';
|
|
38
|
+
throw err;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=replay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay.js","sourceRoot":"","sources":["../src/replay.ts"],"names":[],"mappings":";;AA2BA,4CAuBC;AAlDD,uEAKuC;AAOvC;;;;;;;;;;;;;;GAcG;AACI,KAAK,UAAU,gBAAgB,CACpC,QAA0C,EAC1C,OAAmB;IAEnB,MAAM,KAAK,GAAG,IAAI,wCAAkB,EAAE,CAAC;IACvC,yFAAyF;IACzF,qEAAqE;IACrE,MAAM,KAAK,CAAC,SAAS,CAAC;QACpB,GAAG,OAAO,CAAC,GAAG;QACd,MAAM,EAAE,WAAW;QACnB,QAAQ,EAAE,SAAS;QACnB,WAAW,EAAE,SAAS;KACvB,CAAC,CAAC;IACH,KAAK,MAAM,EAAE,IAAI,OAAO,CAAC,WAAW;QAAE,MAAM,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IAErE,MAAM,MAAM,GAAG,IAAI,oCAAc,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7C,QAAQ,CAAC,MAAM,CAAC,CAAC;IACjB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACnD,IAAI,MAAM,CAAC,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,iBAAiB,CAAC,EAAE,CAAC;QACvF,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC5C,GAAG,CAAC,IAAI,GAAG,qBAAqB,CAAC;QACjC,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport-conformance.d.ts","sourceRoot":"","sources":["../src/transport-conformance.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,SAAS,EAEf,MAAM,+BAA+B,CAAC;AAGvC,oFAAoF;AACpF,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG;IAC5C,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IACrE,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB,CAAC;
|
|
1
|
+
{"version":3,"file":"transport-conformance.d.ts","sourceRoot":"","sources":["../src/transport-conformance.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,SAAS,EAEf,MAAM,+BAA+B,CAAC;AAGvC,oFAAoF;AACpF,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG;IAC5C,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IACrE,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB,CAAC;AAyBF;;;;;;;GAOG;AACH,wBAAsB,0BAA0B,CAC9C,SAAS,EAAE,mBAAmB,EAC9B,QAAQ,SAAS,GAChB,OAAO,CAAC,IAAI,CAAC,CA+Bf"}
|
|
@@ -10,6 +10,21 @@ const echo = {
|
|
|
10
10
|
output: zod_1.z.object({ doubled: zod_1.z.number() }),
|
|
11
11
|
__remote: true,
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* A durable `ctx.call` suspends the run; the worker result resumes it asynchronously (on whatever
|
|
15
|
+
* tick/poll the transport delivers on). Poll the store until the run reaches a terminal state —
|
|
16
|
+
* with a generous budget so a poll-based transport (DB/SQS) has time to round-trip.
|
|
17
|
+
*/
|
|
18
|
+
async function settle(store, runId, timeoutMs = 15_000) {
|
|
19
|
+
const deadline = Date.now() + timeoutMs;
|
|
20
|
+
while (Date.now() < deadline) {
|
|
21
|
+
const run = await store.getRun(runId);
|
|
22
|
+
if (run && run.status !== 'running' && run.status !== 'suspended')
|
|
23
|
+
return run;
|
|
24
|
+
await new Promise((r) => setTimeout(r, 25));
|
|
25
|
+
}
|
|
26
|
+
throw new Error(`run ${runId} did not settle within ${timeoutMs}ms`);
|
|
27
|
+
}
|
|
13
28
|
/**
|
|
14
29
|
* The contract every `Transport` must satisfy: a remote step dispatched through it round-trips to a
|
|
15
30
|
* worker and back (success), and a throwing handler surfaces as a failed run (failure). Point it at
|
|
@@ -20,24 +35,27 @@ const echo = {
|
|
|
20
35
|
*/
|
|
21
36
|
async function assertTransportConformance(transport, idPrefix = 'conf') {
|
|
22
37
|
try {
|
|
38
|
+
// One engine/store/transport — a durable remote step routes its result back to this engine,
|
|
39
|
+
// which resumes the run. (Two engines on one transport would fight over the result stream.)
|
|
40
|
+
const store = new nestjs_durable_core_1.InMemoryStateStore();
|
|
41
|
+
const engine = new nestjs_durable_core_1.WorkflowEngine({ store, transport });
|
|
42
|
+
engine.register('conf-ok', '1', async (ctx) => (await ctx.call(echo, { n: 21 })).doubled);
|
|
43
|
+
engine.register('conf-fail', '1', async (ctx) => ctx.call(echo, { n: 1 }));
|
|
23
44
|
// success: the worker doubles the input
|
|
24
45
|
transport.handle('conformance.echo', async (input) => ({
|
|
25
46
|
doubled: input.n * 2,
|
|
26
47
|
}));
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const ok = await engine.start('conf-ok', {}, `${idPrefix}-ok`);
|
|
48
|
+
await engine.start('conf-ok', {}, `${idPrefix}-ok`);
|
|
49
|
+
const ok = await settle(store, `${idPrefix}-ok`);
|
|
30
50
|
if (ok.status !== 'completed' || ok.output !== 42) {
|
|
31
51
|
throw new Error(`expected completed/42, got ${JSON.stringify(ok)}`);
|
|
32
52
|
}
|
|
33
|
-
// failure: a throwing handler
|
|
34
|
-
|
|
35
|
-
failTransport.handle('conformance.echo', async () => {
|
|
53
|
+
// failure: a throwing handler surfaces as a failed run (re-register the same step to throw)
|
|
54
|
+
transport.handle('conformance.echo', async () => {
|
|
36
55
|
throw new Error('handler boom');
|
|
37
56
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const failed = await failEngine.start('conf-fail', {}, `${idPrefix}-fail`);
|
|
57
|
+
await engine.start('conf-fail', {}, `${idPrefix}-fail`);
|
|
58
|
+
const failed = await settle(store, `${idPrefix}-fail`);
|
|
41
59
|
if (failed.status !== 'failed') {
|
|
42
60
|
throw new Error(`expected failed, got ${JSON.stringify(failed)}`);
|
|
43
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport-conformance.js","sourceRoot":"","sources":["../src/transport-conformance.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"transport-conformance.js","sourceRoot":"","sources":["../src/transport-conformance.ts"],"names":[],"mappings":";;AA6CA,gEAkCC;AA/ED,uEAKuC;AACvC,6BAAwB;AAQxB,MAAM,IAAI,GAAsD;IAC9D,IAAI,EAAE,kBAAkB;IACxB,KAAK,EAAE,aAAa;IACpB,KAAK,EAAE,OAAC,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,CAAC;IAClC,MAAM,EAAE,OAAC,CAAC,MAAM,CA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AC5B,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dudousxd/nestjs-durable-testing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Testing utilities for nestjs-durable — a test engine harness, crash/flaky-step injection, and replay assertions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Davide Carvalho",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"typescript": "5.9.3",
|
|
23
|
-
"@dudousxd/nestjs-durable-core": "^0.
|
|
23
|
+
"@dudousxd/nestjs-durable-core": "^0.4.0"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "tsc -p tsconfig.json",
|