@auto-engineer/pipeline 0.0.1 → 0.15.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +26 -0
- package/README.md +279 -0
- package/dist/src/builder/define.d.ts +6 -2
- package/dist/src/builder/define.d.ts.map +1 -1
- package/dist/src/builder/define.js +17 -7
- package/dist/src/builder/define.js.map +1 -1
- package/dist/src/builder/define.specs.js +3 -3
- package/dist/src/builder/define.specs.js.map +1 -1
- package/dist/src/core/descriptors.d.ts +6 -2
- package/dist/src/core/descriptors.d.ts.map +1 -1
- package/dist/src/graph/filter-graph.d.ts +3 -0
- package/dist/src/graph/filter-graph.d.ts.map +1 -0
- package/dist/src/graph/filter-graph.js +80 -0
- package/dist/src/graph/filter-graph.js.map +1 -0
- package/dist/src/graph/filter-graph.specs.d.ts +2 -0
- package/dist/src/graph/filter-graph.specs.d.ts.map +1 -0
- package/dist/src/graph/filter-graph.specs.js +204 -0
- package/dist/src/graph/filter-graph.specs.js.map +1 -0
- package/dist/src/graph/types.d.ts +8 -0
- package/dist/src/graph/types.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/projections/await-tracker-projection.d.ts +31 -0
- package/dist/src/projections/await-tracker-projection.d.ts.map +1 -0
- package/dist/src/projections/await-tracker-projection.js +35 -0
- package/dist/src/projections/await-tracker-projection.js.map +1 -0
- package/dist/src/projections/index.d.ts +4 -0
- package/dist/src/projections/index.d.ts.map +1 -0
- package/dist/src/projections/index.js +4 -0
- package/dist/src/projections/index.js.map +1 -0
- package/dist/src/projections/item-status-projection.d.ts +22 -0
- package/dist/src/projections/item-status-projection.d.ts.map +1 -0
- package/dist/src/projections/item-status-projection.js +11 -0
- package/dist/src/projections/item-status-projection.js.map +1 -0
- package/dist/src/projections/item-status-projection.specs.d.ts +2 -0
- package/dist/src/projections/item-status-projection.specs.d.ts.map +1 -0
- package/dist/src/projections/item-status-projection.specs.js +119 -0
- package/dist/src/projections/item-status-projection.specs.js.map +1 -0
- package/dist/src/projections/latest-run-projection.d.ts +15 -0
- package/dist/src/projections/latest-run-projection.d.ts.map +1 -0
- package/dist/src/projections/latest-run-projection.js +7 -0
- package/dist/src/projections/latest-run-projection.js.map +1 -0
- package/dist/src/projections/latest-run-projection.specs.d.ts +2 -0
- package/dist/src/projections/latest-run-projection.specs.d.ts.map +1 -0
- package/dist/src/projections/latest-run-projection.specs.js +33 -0
- package/dist/src/projections/latest-run-projection.specs.js.map +1 -0
- package/dist/src/projections/message-log-projection.d.ts +51 -0
- package/dist/src/projections/message-log-projection.d.ts.map +1 -0
- package/dist/src/projections/message-log-projection.js +51 -0
- package/dist/src/projections/message-log-projection.js.map +1 -0
- package/dist/src/projections/message-log-projection.specs.d.ts +2 -0
- package/dist/src/projections/message-log-projection.specs.d.ts.map +1 -0
- package/dist/src/projections/message-log-projection.specs.js +101 -0
- package/dist/src/projections/message-log-projection.specs.js.map +1 -0
- package/dist/src/projections/node-status-projection.d.ts +23 -0
- package/dist/src/projections/node-status-projection.d.ts.map +1 -0
- package/dist/src/projections/node-status-projection.js +10 -0
- package/dist/src/projections/node-status-projection.js.map +1 -0
- package/dist/src/projections/node-status-projection.specs.d.ts +2 -0
- package/dist/src/projections/node-status-projection.specs.d.ts.map +1 -0
- package/dist/src/projections/node-status-projection.specs.js +116 -0
- package/dist/src/projections/node-status-projection.specs.js.map +1 -0
- package/dist/src/projections/phased-execution-projection.d.ts +77 -0
- package/dist/src/projections/phased-execution-projection.d.ts.map +1 -0
- package/dist/src/projections/phased-execution-projection.js +54 -0
- package/dist/src/projections/phased-execution-projection.js.map +1 -0
- package/dist/src/projections/phased-execution-projection.specs.d.ts +2 -0
- package/dist/src/projections/phased-execution-projection.specs.d.ts.map +1 -0
- package/dist/src/projections/phased-execution-projection.specs.js +171 -0
- package/dist/src/projections/phased-execution-projection.specs.js.map +1 -0
- package/dist/src/projections/settled-instance-projection.d.ts +67 -0
- package/dist/src/projections/settled-instance-projection.d.ts.map +1 -0
- package/dist/src/projections/settled-instance-projection.js +66 -0
- package/dist/src/projections/settled-instance-projection.js.map +1 -0
- package/dist/src/projections/settled-instance-projection.specs.d.ts +2 -0
- package/dist/src/projections/settled-instance-projection.specs.d.ts.map +1 -0
- package/dist/src/projections/settled-instance-projection.specs.js +217 -0
- package/dist/src/projections/settled-instance-projection.specs.js.map +1 -0
- package/dist/src/projections/stats-projection.d.ts +9 -0
- package/dist/src/projections/stats-projection.d.ts.map +1 -0
- package/dist/src/projections/stats-projection.js +16 -0
- package/dist/src/projections/stats-projection.js.map +1 -0
- package/dist/src/projections/stats-projection.specs.d.ts +2 -0
- package/dist/src/projections/stats-projection.specs.d.ts.map +1 -0
- package/dist/src/projections/stats-projection.specs.js +91 -0
- package/dist/src/projections/stats-projection.specs.js.map +1 -0
- package/dist/src/runtime/await-tracker.d.ts +17 -7
- package/dist/src/runtime/await-tracker.d.ts.map +1 -1
- package/dist/src/runtime/await-tracker.js +32 -29
- package/dist/src/runtime/await-tracker.js.map +1 -1
- package/dist/src/runtime/await-tracker.specs.js +56 -38
- package/dist/src/runtime/await-tracker.specs.js.map +1 -1
- package/dist/src/runtime/context.d.ts +1 -1
- package/dist/src/runtime/context.d.ts.map +1 -1
- package/dist/src/runtime/event-command-map.d.ts +3 -3
- package/dist/src/runtime/event-command-map.d.ts.map +1 -1
- package/dist/src/runtime/event-command-map.js +6 -2
- package/dist/src/runtime/event-command-map.js.map +1 -1
- package/dist/src/runtime/phased-executor.d.ts +15 -9
- package/dist/src/runtime/phased-executor.d.ts.map +1 -1
- package/dist/src/runtime/phased-executor.js +126 -104
- package/dist/src/runtime/phased-executor.js.map +1 -1
- package/dist/src/runtime/phased-executor.specs.js +243 -81
- package/dist/src/runtime/phased-executor.specs.js.map +1 -1
- package/dist/src/runtime/pipeline-runtime.d.ts.map +1 -1
- package/dist/src/runtime/pipeline-runtime.js +2 -2
- package/dist/src/runtime/pipeline-runtime.js.map +1 -1
- package/dist/src/runtime/pipeline-runtime.specs.js +35 -0
- package/dist/src/runtime/pipeline-runtime.specs.js.map +1 -1
- package/dist/src/runtime/settled-tracker.d.ts +12 -9
- package/dist/src/runtime/settled-tracker.d.ts.map +1 -1
- package/dist/src/runtime/settled-tracker.js +92 -77
- package/dist/src/runtime/settled-tracker.js.map +1 -1
- package/dist/src/runtime/settled-tracker.specs.js +568 -118
- package/dist/src/runtime/settled-tracker.specs.js.map +1 -1
- package/dist/src/server/pipeline-server.d.ts +31 -9
- package/dist/src/server/pipeline-server.d.ts.map +1 -1
- package/dist/src/server/pipeline-server.e2e.specs.js +2 -10
- package/dist/src/server/pipeline-server.e2e.specs.js.map +1 -1
- package/dist/src/server/pipeline-server.js +418 -134
- package/dist/src/server/pipeline-server.js.map +1 -1
- package/dist/src/server/pipeline-server.specs.js +777 -32
- package/dist/src/server/pipeline-server.specs.js.map +1 -1
- package/dist/src/server/sse-manager.specs.js +55 -35
- package/dist/src/server/sse-manager.specs.js.map +1 -1
- package/dist/src/store/index.d.ts +3 -0
- package/dist/src/store/index.d.ts.map +1 -0
- package/dist/src/store/index.js +3 -0
- package/dist/src/store/index.js.map +1 -0
- package/dist/src/store/pipeline-event-store.d.ts +10 -0
- package/dist/src/store/pipeline-event-store.d.ts.map +1 -0
- package/dist/src/store/pipeline-event-store.js +112 -0
- package/dist/src/store/pipeline-event-store.js.map +1 -0
- package/dist/src/store/pipeline-event-store.specs.d.ts +2 -0
- package/dist/src/store/pipeline-event-store.specs.d.ts.map +1 -0
- package/dist/src/store/pipeline-event-store.specs.js +287 -0
- package/dist/src/store/pipeline-event-store.specs.js.map +1 -0
- package/dist/src/store/pipeline-read-model.d.ts +49 -0
- package/dist/src/store/pipeline-read-model.d.ts.map +1 -0
- package/dist/src/store/pipeline-read-model.js +157 -0
- package/dist/src/store/pipeline-read-model.js.map +1 -0
- package/dist/src/store/pipeline-read-model.specs.d.ts +2 -0
- package/dist/src/store/pipeline-read-model.specs.d.ts.map +1 -0
- package/dist/src/store/pipeline-read-model.specs.js +830 -0
- package/dist/src/store/pipeline-read-model.specs.js.map +1 -0
- package/dist/src/testing/fixtures/kanban-full.pipeline.js +2 -2
- package/dist/src/testing/fixtures/kanban-full.pipeline.js.map +1 -1
- package/dist/src/testing/fixtures/kanban.pipeline.js +2 -2
- package/dist/src/testing/fixtures/kanban.pipeline.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/ketchup-plan.md +960 -0
- package/package.json +7 -3
- package/src/builder/define.specs.ts +3 -3
- package/src/builder/define.ts +24 -11
- package/src/core/descriptors.ts +7 -2
- package/src/graph/filter-graph.specs.ts +241 -0
- package/src/graph/filter-graph.ts +111 -0
- package/src/graph/types.ts +10 -0
- package/src/index.ts +1 -2
- package/src/projections/await-tracker-projection.ts +68 -0
- package/src/projections/index.ts +11 -0
- package/src/projections/item-status-projection.specs.ts +130 -0
- package/src/projections/item-status-projection.ts +32 -0
- package/src/projections/latest-run-projection.specs.ts +38 -0
- package/src/projections/latest-run-projection.ts +20 -0
- package/src/projections/message-log-projection.specs.ts +118 -0
- package/src/projections/message-log-projection.ts +113 -0
- package/src/projections/node-status-projection.specs.ts +127 -0
- package/src/projections/node-status-projection.ts +33 -0
- package/src/projections/phased-execution-projection.specs.ts +202 -0
- package/src/projections/phased-execution-projection.ts +146 -0
- package/src/projections/settled-instance-projection.specs.ts +249 -0
- package/src/projections/settled-instance-projection.ts +160 -0
- package/src/projections/stats-projection.specs.ts +105 -0
- package/src/projections/stats-projection.ts +26 -0
- package/src/runtime/await-tracker.specs.ts +57 -34
- package/src/runtime/await-tracker.ts +43 -31
- package/src/runtime/context.ts +1 -1
- package/src/runtime/event-command-map.ts +11 -4
- package/src/runtime/phased-executor.specs.ts +357 -81
- package/src/runtime/phased-executor.ts +142 -126
- package/src/runtime/pipeline-runtime.specs.ts +42 -0
- package/src/runtime/pipeline-runtime.ts +6 -4
- package/src/runtime/settled-tracker.specs.ts +716 -120
- package/src/runtime/settled-tracker.ts +104 -98
- package/src/server/pipeline-server.e2e.specs.ts +10 -16
- package/src/server/pipeline-server.specs.ts +964 -49
- package/src/server/pipeline-server.ts +522 -156
- package/src/server/sse-manager.specs.ts +67 -36
- package/src/store/index.ts +2 -0
- package/src/store/pipeline-event-store.specs.ts +309 -0
- package/src/store/pipeline-event-store.ts +156 -0
- package/src/store/pipeline-read-model.specs.ts +967 -0
- package/src/store/pipeline-read-model.ts +223 -0
- package/src/testing/fixtures/kanban-full.pipeline.ts +2 -2
- package/src/testing/fixtures/kanban.pipeline.ts +2 -2
- package/claude.md +0 -160
- package/docs/testing-analysis.md +0 -395
- package/pomodoro-plan.md +0 -651
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { evolve, type ItemStatusChangedEvent, type ItemStatusDocument } from './item-status-projection';
|
|
3
|
+
|
|
4
|
+
describe('ItemStatusProjection', () => {
|
|
5
|
+
describe('evolve', () => {
|
|
6
|
+
it('creates item document with running status when item starts', () => {
|
|
7
|
+
const event: ItemStatusChangedEvent = {
|
|
8
|
+
type: 'ItemStatusChanged',
|
|
9
|
+
data: {
|
|
10
|
+
correlationId: 'c1',
|
|
11
|
+
commandType: 'ProcessItem',
|
|
12
|
+
itemKey: 'item-1',
|
|
13
|
+
requestId: 'req-1',
|
|
14
|
+
status: 'running',
|
|
15
|
+
attemptCount: 1,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const result = evolve(null, event);
|
|
20
|
+
|
|
21
|
+
expect(result).toEqual({
|
|
22
|
+
correlationId: 'c1',
|
|
23
|
+
commandType: 'ProcessItem',
|
|
24
|
+
itemKey: 'item-1',
|
|
25
|
+
currentRequestId: 'req-1',
|
|
26
|
+
status: 'running',
|
|
27
|
+
attemptCount: 1,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('updates item document to success status when item completes', () => {
|
|
32
|
+
const existing: ItemStatusDocument = {
|
|
33
|
+
correlationId: 'c1',
|
|
34
|
+
commandType: 'ProcessItem',
|
|
35
|
+
itemKey: 'item-1',
|
|
36
|
+
currentRequestId: 'req-1',
|
|
37
|
+
status: 'running',
|
|
38
|
+
attemptCount: 1,
|
|
39
|
+
};
|
|
40
|
+
const event: ItemStatusChangedEvent = {
|
|
41
|
+
type: 'ItemStatusChanged',
|
|
42
|
+
data: {
|
|
43
|
+
correlationId: 'c1',
|
|
44
|
+
commandType: 'ProcessItem',
|
|
45
|
+
itemKey: 'item-1',
|
|
46
|
+
requestId: 'req-1',
|
|
47
|
+
status: 'success',
|
|
48
|
+
attemptCount: 1,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const result = evolve(existing, event);
|
|
53
|
+
|
|
54
|
+
expect(result).toEqual({
|
|
55
|
+
correlationId: 'c1',
|
|
56
|
+
commandType: 'ProcessItem',
|
|
57
|
+
itemKey: 'item-1',
|
|
58
|
+
currentRequestId: 'req-1',
|
|
59
|
+
status: 'success',
|
|
60
|
+
attemptCount: 1,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('updates item document to error status when item fails', () => {
|
|
65
|
+
const existing: ItemStatusDocument = {
|
|
66
|
+
correlationId: 'c1',
|
|
67
|
+
commandType: 'ProcessItem',
|
|
68
|
+
itemKey: 'item-1',
|
|
69
|
+
currentRequestId: 'req-1',
|
|
70
|
+
status: 'running',
|
|
71
|
+
attemptCount: 1,
|
|
72
|
+
};
|
|
73
|
+
const event: ItemStatusChangedEvent = {
|
|
74
|
+
type: 'ItemStatusChanged',
|
|
75
|
+
data: {
|
|
76
|
+
correlationId: 'c1',
|
|
77
|
+
commandType: 'ProcessItem',
|
|
78
|
+
itemKey: 'item-1',
|
|
79
|
+
requestId: 'req-1',
|
|
80
|
+
status: 'error',
|
|
81
|
+
attemptCount: 1,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const result = evolve(existing, event);
|
|
86
|
+
|
|
87
|
+
expect(result).toEqual({
|
|
88
|
+
correlationId: 'c1',
|
|
89
|
+
commandType: 'ProcessItem',
|
|
90
|
+
itemKey: 'item-1',
|
|
91
|
+
currentRequestId: 'req-1',
|
|
92
|
+
status: 'error',
|
|
93
|
+
attemptCount: 1,
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('increments attempt count on retry', () => {
|
|
98
|
+
const existing: ItemStatusDocument = {
|
|
99
|
+
correlationId: 'c1',
|
|
100
|
+
commandType: 'ProcessItem',
|
|
101
|
+
itemKey: 'item-1',
|
|
102
|
+
currentRequestId: 'req-1',
|
|
103
|
+
status: 'error',
|
|
104
|
+
attemptCount: 1,
|
|
105
|
+
};
|
|
106
|
+
const event: ItemStatusChangedEvent = {
|
|
107
|
+
type: 'ItemStatusChanged',
|
|
108
|
+
data: {
|
|
109
|
+
correlationId: 'c1',
|
|
110
|
+
commandType: 'ProcessItem',
|
|
111
|
+
itemKey: 'item-1',
|
|
112
|
+
requestId: 'req-2',
|
|
113
|
+
status: 'running',
|
|
114
|
+
attemptCount: 2,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const result = evolve(existing, event);
|
|
119
|
+
|
|
120
|
+
expect(result).toEqual({
|
|
121
|
+
correlationId: 'c1',
|
|
122
|
+
commandType: 'ProcessItem',
|
|
123
|
+
itemKey: 'item-1',
|
|
124
|
+
currentRequestId: 'req-2',
|
|
125
|
+
status: 'running',
|
|
126
|
+
attemptCount: 2,
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface ItemStatusDocument {
|
|
2
|
+
[key: string]: unknown;
|
|
3
|
+
correlationId: string;
|
|
4
|
+
commandType: string;
|
|
5
|
+
itemKey: string;
|
|
6
|
+
currentRequestId: string;
|
|
7
|
+
status: 'running' | 'success' | 'error';
|
|
8
|
+
attemptCount: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ItemStatusChangedEvent {
|
|
12
|
+
type: 'ItemStatusChanged';
|
|
13
|
+
data: {
|
|
14
|
+
correlationId: string;
|
|
15
|
+
commandType: string;
|
|
16
|
+
itemKey: string;
|
|
17
|
+
requestId: string;
|
|
18
|
+
status: 'running' | 'success' | 'error';
|
|
19
|
+
attemptCount: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function evolve(_document: ItemStatusDocument | null, event: ItemStatusChangedEvent): ItemStatusDocument {
|
|
24
|
+
return {
|
|
25
|
+
correlationId: event.data.correlationId,
|
|
26
|
+
commandType: event.data.commandType,
|
|
27
|
+
itemKey: event.data.itemKey,
|
|
28
|
+
currentRequestId: event.data.requestId,
|
|
29
|
+
status: event.data.status,
|
|
30
|
+
attemptCount: event.data.attemptCount,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { evolve, type LatestRunDocument } from './latest-run-projection';
|
|
3
|
+
|
|
4
|
+
describe('LatestRunProjection', () => {
|
|
5
|
+
describe('evolve', () => {
|
|
6
|
+
it('tracks latest correlationId when PipelineRunStarted applied', () => {
|
|
7
|
+
const event = {
|
|
8
|
+
type: 'PipelineRunStarted' as const,
|
|
9
|
+
data: { correlationId: 'c1', triggerCommand: 'StartPipeline' },
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const result = evolve(null, event);
|
|
13
|
+
|
|
14
|
+
expect(result).toEqual({
|
|
15
|
+
latestCorrelationId: 'c1',
|
|
16
|
+
triggerCommand: 'StartPipeline',
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('updates to newest correlationId when second PipelineRunStarted applied', () => {
|
|
21
|
+
const existing: LatestRunDocument = {
|
|
22
|
+
latestCorrelationId: 'c1',
|
|
23
|
+
triggerCommand: 'StartPipeline',
|
|
24
|
+
};
|
|
25
|
+
const event = {
|
|
26
|
+
type: 'PipelineRunStarted' as const,
|
|
27
|
+
data: { correlationId: 'c2', triggerCommand: 'StartPipeline' },
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const result = evolve(existing, event);
|
|
31
|
+
|
|
32
|
+
expect(result).toEqual({
|
|
33
|
+
latestCorrelationId: 'c2',
|
|
34
|
+
triggerCommand: 'StartPipeline',
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface LatestRunDocument {
|
|
2
|
+
[key: string]: unknown;
|
|
3
|
+
latestCorrelationId: string;
|
|
4
|
+
triggerCommand: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface PipelineRunStartedEvent {
|
|
8
|
+
type: 'PipelineRunStarted';
|
|
9
|
+
data: {
|
|
10
|
+
correlationId: string;
|
|
11
|
+
triggerCommand: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function evolve(_document: LatestRunDocument | null, event: PipelineRunStartedEvent): LatestRunDocument {
|
|
16
|
+
return {
|
|
17
|
+
latestCorrelationId: event.data.correlationId,
|
|
18
|
+
triggerCommand: event.data.triggerCommand,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
type CommandDispatchedEvent,
|
|
4
|
+
type DomainEventEmittedEvent,
|
|
5
|
+
evolve,
|
|
6
|
+
type NodeStatusChangedLogEvent,
|
|
7
|
+
type PipelineRunStartedLogEvent,
|
|
8
|
+
} from './message-log-projection';
|
|
9
|
+
|
|
10
|
+
describe('MessageLogProjection', () => {
|
|
11
|
+
describe('CommandDispatched', () => {
|
|
12
|
+
it('creates message log entry for dispatched command', () => {
|
|
13
|
+
const event: CommandDispatchedEvent = {
|
|
14
|
+
type: 'CommandDispatched',
|
|
15
|
+
data: {
|
|
16
|
+
correlationId: 'c1',
|
|
17
|
+
requestId: 'r1',
|
|
18
|
+
commandType: 'CreateUser',
|
|
19
|
+
commandData: { name: 'Alice' },
|
|
20
|
+
timestamp: new Date('2025-01-01T00:00:00Z'),
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const result = evolve(null, event);
|
|
25
|
+
|
|
26
|
+
expect(result).toEqual({
|
|
27
|
+
correlationId: 'c1',
|
|
28
|
+
requestId: 'r1',
|
|
29
|
+
messageType: 'command',
|
|
30
|
+
messageName: 'CreateUser',
|
|
31
|
+
messageData: { name: 'Alice' },
|
|
32
|
+
timestamp: new Date('2025-01-01T00:00:00Z'),
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('DomainEventEmitted', () => {
|
|
38
|
+
it('creates message log entry for emitted domain event', () => {
|
|
39
|
+
const event: DomainEventEmittedEvent = {
|
|
40
|
+
type: 'DomainEventEmitted',
|
|
41
|
+
data: {
|
|
42
|
+
correlationId: 'c1',
|
|
43
|
+
requestId: 'r2',
|
|
44
|
+
eventType: 'UserCreated',
|
|
45
|
+
eventData: { userId: '123', name: 'Alice' },
|
|
46
|
+
timestamp: new Date('2025-01-01T00:00:01Z'),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const result = evolve(null, event);
|
|
51
|
+
|
|
52
|
+
expect(result).toEqual({
|
|
53
|
+
correlationId: 'c1',
|
|
54
|
+
requestId: 'r2',
|
|
55
|
+
messageType: 'event',
|
|
56
|
+
messageName: 'UserCreated',
|
|
57
|
+
messageData: { userId: '123', name: 'Alice' },
|
|
58
|
+
timestamp: new Date('2025-01-01T00:00:01Z'),
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('PipelineRunStarted', () => {
|
|
64
|
+
it('creates message log entry for pipeline run started', () => {
|
|
65
|
+
const event: PipelineRunStartedLogEvent = {
|
|
66
|
+
type: 'PipelineRunStarted',
|
|
67
|
+
data: {
|
|
68
|
+
correlationId: 'c1',
|
|
69
|
+
triggerCommand: 'CreateUser',
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const result = evolve(null, event);
|
|
74
|
+
|
|
75
|
+
expect(result).toEqual({
|
|
76
|
+
correlationId: 'c1',
|
|
77
|
+
requestId: 'c1',
|
|
78
|
+
messageType: 'event',
|
|
79
|
+
messageName: 'PipelineRunStarted',
|
|
80
|
+
messageData: { correlationId: 'c1', triggerCommand: 'CreateUser' },
|
|
81
|
+
timestamp: expect.any(Date),
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('NodeStatusChanged', () => {
|
|
87
|
+
it('creates message log entry for node status changed', () => {
|
|
88
|
+
const event: NodeStatusChangedLogEvent = {
|
|
89
|
+
type: 'NodeStatusChanged',
|
|
90
|
+
data: {
|
|
91
|
+
correlationId: 'c1',
|
|
92
|
+
commandName: 'CreateUser',
|
|
93
|
+
status: 'running',
|
|
94
|
+
previousStatus: 'idle',
|
|
95
|
+
pendingCount: 1,
|
|
96
|
+
endedCount: 0,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const result = evolve(null, event);
|
|
101
|
+
|
|
102
|
+
expect(result).toEqual({
|
|
103
|
+
correlationId: 'c1',
|
|
104
|
+
requestId: expect.any(String),
|
|
105
|
+
messageType: 'event',
|
|
106
|
+
messageName: 'NodeStatusChanged',
|
|
107
|
+
messageData: {
|
|
108
|
+
nodeId: 'cmd:CreateUser',
|
|
109
|
+
status: 'running',
|
|
110
|
+
previousStatus: 'idle',
|
|
111
|
+
pendingCount: 1,
|
|
112
|
+
endedCount: 0,
|
|
113
|
+
},
|
|
114
|
+
timestamp: expect.any(Date),
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { nanoid } from 'nanoid';
|
|
2
|
+
import type { NodeStatus } from '../graph/types';
|
|
3
|
+
|
|
4
|
+
export interface MessageLogDocument {
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
correlationId: string;
|
|
7
|
+
requestId: string;
|
|
8
|
+
messageType: 'command' | 'event';
|
|
9
|
+
messageName: string;
|
|
10
|
+
messageData: Record<string, unknown>;
|
|
11
|
+
timestamp: Date;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface CommandDispatchedEvent {
|
|
15
|
+
type: 'CommandDispatched';
|
|
16
|
+
data: {
|
|
17
|
+
correlationId: string;
|
|
18
|
+
requestId: string;
|
|
19
|
+
commandType: string;
|
|
20
|
+
commandData: Record<string, unknown>;
|
|
21
|
+
timestamp: Date;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface DomainEventEmittedEvent {
|
|
26
|
+
type: 'DomainEventEmitted';
|
|
27
|
+
data: {
|
|
28
|
+
correlationId: string;
|
|
29
|
+
requestId: string;
|
|
30
|
+
eventType: string;
|
|
31
|
+
eventData: Record<string, unknown>;
|
|
32
|
+
timestamp: Date;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface PipelineRunStartedLogEvent {
|
|
37
|
+
type: 'PipelineRunStarted';
|
|
38
|
+
data: {
|
|
39
|
+
correlationId: string;
|
|
40
|
+
triggerCommand: string;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface NodeStatusChangedLogEvent {
|
|
45
|
+
type: 'NodeStatusChanged';
|
|
46
|
+
data: {
|
|
47
|
+
correlationId: string;
|
|
48
|
+
commandName: string;
|
|
49
|
+
status: NodeStatus;
|
|
50
|
+
previousStatus: NodeStatus;
|
|
51
|
+
pendingCount: number;
|
|
52
|
+
endedCount: number;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type MessageLogEvent =
|
|
57
|
+
| CommandDispatchedEvent
|
|
58
|
+
| DomainEventEmittedEvent
|
|
59
|
+
| PipelineRunStartedLogEvent
|
|
60
|
+
| NodeStatusChangedLogEvent;
|
|
61
|
+
|
|
62
|
+
export function evolve(_document: MessageLogDocument | null, event: MessageLogEvent): MessageLogDocument {
|
|
63
|
+
if (event.type === 'CommandDispatched') {
|
|
64
|
+
return {
|
|
65
|
+
correlationId: event.data.correlationId,
|
|
66
|
+
requestId: event.data.requestId,
|
|
67
|
+
messageType: 'command',
|
|
68
|
+
messageName: event.data.commandType,
|
|
69
|
+
messageData: event.data.commandData,
|
|
70
|
+
timestamp: event.data.timestamp,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (event.type === 'DomainEventEmitted') {
|
|
75
|
+
return {
|
|
76
|
+
correlationId: event.data.correlationId,
|
|
77
|
+
requestId: event.data.requestId,
|
|
78
|
+
messageType: 'event',
|
|
79
|
+
messageName: event.data.eventType,
|
|
80
|
+
messageData: event.data.eventData,
|
|
81
|
+
timestamp: event.data.timestamp,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (event.type === 'PipelineRunStarted') {
|
|
86
|
+
return {
|
|
87
|
+
correlationId: event.data.correlationId,
|
|
88
|
+
requestId: event.data.correlationId,
|
|
89
|
+
messageType: 'event',
|
|
90
|
+
messageName: 'PipelineRunStarted',
|
|
91
|
+
messageData: {
|
|
92
|
+
correlationId: event.data.correlationId,
|
|
93
|
+
triggerCommand: event.data.triggerCommand,
|
|
94
|
+
},
|
|
95
|
+
timestamp: new Date(),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
correlationId: event.data.correlationId,
|
|
101
|
+
requestId: nanoid(),
|
|
102
|
+
messageType: 'event',
|
|
103
|
+
messageName: 'NodeStatusChanged',
|
|
104
|
+
messageData: {
|
|
105
|
+
nodeId: `cmd:${event.data.commandName}`,
|
|
106
|
+
status: event.data.status,
|
|
107
|
+
previousStatus: event.data.previousStatus,
|
|
108
|
+
pendingCount: event.data.pendingCount,
|
|
109
|
+
endedCount: event.data.endedCount,
|
|
110
|
+
},
|
|
111
|
+
timestamp: new Date(),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { evolve, type NodeStatusChangedEvent, type NodeStatusDocument } from './node-status-projection';
|
|
3
|
+
|
|
4
|
+
describe('NodeStatusProjection', () => {
|
|
5
|
+
describe('evolve', () => {
|
|
6
|
+
it('creates node document with running status when command starts', () => {
|
|
7
|
+
const event: NodeStatusChangedEvent = {
|
|
8
|
+
type: 'NodeStatusChanged',
|
|
9
|
+
data: {
|
|
10
|
+
correlationId: 'c1',
|
|
11
|
+
commandName: 'ProcessItem',
|
|
12
|
+
nodeId: 'cmd:ProcessItem',
|
|
13
|
+
status: 'running',
|
|
14
|
+
previousStatus: 'idle',
|
|
15
|
+
pendingCount: 1,
|
|
16
|
+
endedCount: 0,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const result = evolve(null, event);
|
|
21
|
+
|
|
22
|
+
expect(result).toEqual({
|
|
23
|
+
correlationId: 'c1',
|
|
24
|
+
commandName: 'ProcessItem',
|
|
25
|
+
status: 'running',
|
|
26
|
+
pendingCount: 1,
|
|
27
|
+
endedCount: 0,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('updates node document to success status when command completes', () => {
|
|
32
|
+
const existing: NodeStatusDocument = {
|
|
33
|
+
correlationId: 'c1',
|
|
34
|
+
commandName: 'ProcessItem',
|
|
35
|
+
status: 'running',
|
|
36
|
+
pendingCount: 1,
|
|
37
|
+
endedCount: 0,
|
|
38
|
+
};
|
|
39
|
+
const event: NodeStatusChangedEvent = {
|
|
40
|
+
type: 'NodeStatusChanged',
|
|
41
|
+
data: {
|
|
42
|
+
correlationId: 'c1',
|
|
43
|
+
commandName: 'ProcessItem',
|
|
44
|
+
nodeId: 'cmd:ProcessItem',
|
|
45
|
+
status: 'success',
|
|
46
|
+
previousStatus: 'running',
|
|
47
|
+
pendingCount: 0,
|
|
48
|
+
endedCount: 1,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const result = evolve(existing, event);
|
|
53
|
+
|
|
54
|
+
expect(result).toEqual({
|
|
55
|
+
correlationId: 'c1',
|
|
56
|
+
commandName: 'ProcessItem',
|
|
57
|
+
status: 'success',
|
|
58
|
+
pendingCount: 0,
|
|
59
|
+
endedCount: 1,
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('updates node document to error status when command fails', () => {
|
|
64
|
+
const existing: NodeStatusDocument = {
|
|
65
|
+
correlationId: 'c1',
|
|
66
|
+
commandName: 'ProcessItem',
|
|
67
|
+
status: 'running',
|
|
68
|
+
pendingCount: 1,
|
|
69
|
+
endedCount: 0,
|
|
70
|
+
};
|
|
71
|
+
const event: NodeStatusChangedEvent = {
|
|
72
|
+
type: 'NodeStatusChanged',
|
|
73
|
+
data: {
|
|
74
|
+
correlationId: 'c1',
|
|
75
|
+
commandName: 'ProcessItem',
|
|
76
|
+
nodeId: 'cmd:ProcessItem',
|
|
77
|
+
status: 'error',
|
|
78
|
+
previousStatus: 'running',
|
|
79
|
+
pendingCount: 0,
|
|
80
|
+
endedCount: 1,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const result = evolve(existing, event);
|
|
85
|
+
|
|
86
|
+
expect(result).toEqual({
|
|
87
|
+
correlationId: 'c1',
|
|
88
|
+
commandName: 'ProcessItem',
|
|
89
|
+
status: 'error',
|
|
90
|
+
pendingCount: 0,
|
|
91
|
+
endedCount: 1,
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('tracks pending and ended counts for parallel items', () => {
|
|
96
|
+
const existing: NodeStatusDocument = {
|
|
97
|
+
correlationId: 'c1',
|
|
98
|
+
commandName: 'ProcessItem',
|
|
99
|
+
status: 'running',
|
|
100
|
+
pendingCount: 3,
|
|
101
|
+
endedCount: 2,
|
|
102
|
+
};
|
|
103
|
+
const event: NodeStatusChangedEvent = {
|
|
104
|
+
type: 'NodeStatusChanged',
|
|
105
|
+
data: {
|
|
106
|
+
correlationId: 'c1',
|
|
107
|
+
commandName: 'ProcessItem',
|
|
108
|
+
nodeId: 'cmd:ProcessItem',
|
|
109
|
+
status: 'running',
|
|
110
|
+
previousStatus: 'running',
|
|
111
|
+
pendingCount: 2,
|
|
112
|
+
endedCount: 3,
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const result = evolve(existing, event);
|
|
117
|
+
|
|
118
|
+
expect(result).toEqual({
|
|
119
|
+
correlationId: 'c1',
|
|
120
|
+
commandName: 'ProcessItem',
|
|
121
|
+
status: 'running',
|
|
122
|
+
pendingCount: 2,
|
|
123
|
+
endedCount: 3,
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { NodeStatus } from '../graph/types';
|
|
2
|
+
|
|
3
|
+
export interface NodeStatusDocument {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
correlationId: string;
|
|
6
|
+
commandName: string;
|
|
7
|
+
status: NodeStatus;
|
|
8
|
+
pendingCount: number;
|
|
9
|
+
endedCount: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface NodeStatusChangedEvent {
|
|
13
|
+
type: 'NodeStatusChanged';
|
|
14
|
+
data: {
|
|
15
|
+
correlationId: string;
|
|
16
|
+
commandName: string;
|
|
17
|
+
nodeId: string;
|
|
18
|
+
status: NodeStatus;
|
|
19
|
+
previousStatus: NodeStatus;
|
|
20
|
+
pendingCount: number;
|
|
21
|
+
endedCount: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function evolve(_document: NodeStatusDocument | null, event: NodeStatusChangedEvent): NodeStatusDocument {
|
|
26
|
+
return {
|
|
27
|
+
correlationId: event.data.correlationId,
|
|
28
|
+
commandName: event.data.commandName,
|
|
29
|
+
status: event.data.status,
|
|
30
|
+
pendingCount: event.data.pendingCount,
|
|
31
|
+
endedCount: event.data.endedCount,
|
|
32
|
+
};
|
|
33
|
+
}
|