-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
374 additions
and
2 deletions.
There are no files selected for viewing
309 changes: 309 additions & 0 deletions
309
src/__tests__/__snapshots__/on-workflow-complete-cleanup.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,309 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`cancels or disables started or enabled tasks on workflow end 1`] = ` | ||
{ | ||
"conditions": [ | ||
{ | ||
"marking": 1, | ||
"name": "start", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"marking": 0, | ||
"name": "end", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"marking": 0, | ||
"name": "implicit:t1->t2", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"marking": 0, | ||
"name": "implicit:t1->t3", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"marking": 0, | ||
"name": "implicit:t1->t4", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
], | ||
"tasks": [ | ||
{ | ||
"generation": 0, | ||
"name": "t1", | ||
"state": "enabled", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"generation": 0, | ||
"name": "t2", | ||
"state": "disabled", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"generation": 0, | ||
"name": "t3", | ||
"state": "disabled", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"generation": 0, | ||
"name": "t4", | ||
"state": "disabled", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
], | ||
"workItems": [], | ||
"workflows": [ | ||
{ | ||
"context": undefined, | ||
"id": "workflow-1", | ||
"name": "activities", | ||
"parent": null, | ||
"state": "started", | ||
}, | ||
], | ||
} | ||
`; | ||
|
||
exports[`cancels or disables started or enabled tasks on workflow end 2`] = ` | ||
{ | ||
"conditions": [ | ||
{ | ||
"marking": 0, | ||
"name": "start", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"marking": 0, | ||
"name": "end", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"marking": 1, | ||
"name": "implicit:t1->t2", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"marking": 1, | ||
"name": "implicit:t1->t3", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"marking": 1, | ||
"name": "implicit:t1->t4", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
], | ||
"tasks": [ | ||
{ | ||
"generation": 1, | ||
"name": "t1", | ||
"state": "completed", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"generation": 0, | ||
"name": "t2", | ||
"state": "enabled", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"generation": 0, | ||
"name": "t3", | ||
"state": "enabled", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"generation": 0, | ||
"name": "t4", | ||
"state": "enabled", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
], | ||
"workItems": [], | ||
"workflows": [ | ||
{ | ||
"context": undefined, | ||
"id": "workflow-1", | ||
"name": "activities", | ||
"parent": null, | ||
"state": "started", | ||
}, | ||
], | ||
} | ||
`; | ||
|
||
exports[`cancels or disables started or enabled tasks on workflow end 3`] = ` | ||
{ | ||
"conditions": [ | ||
{ | ||
"marking": 0, | ||
"name": "start", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"marking": 0, | ||
"name": "end", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"marking": 0, | ||
"name": "implicit:t1->t2", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"marking": 1, | ||
"name": "implicit:t1->t3", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"marking": 1, | ||
"name": "implicit:t1->t4", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
], | ||
"tasks": [ | ||
{ | ||
"generation": 1, | ||
"name": "t1", | ||
"state": "completed", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"generation": 1, | ||
"name": "t2", | ||
"state": "started", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"generation": 0, | ||
"name": "t3", | ||
"state": "enabled", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"generation": 0, | ||
"name": "t4", | ||
"state": "enabled", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
], | ||
"workItems": [], | ||
"workflows": [ | ||
{ | ||
"context": undefined, | ||
"id": "workflow-1", | ||
"name": "activities", | ||
"parent": null, | ||
"state": "started", | ||
}, | ||
], | ||
} | ||
`; | ||
|
||
exports[`cancels or disables started or enabled tasks on workflow end 4`] = ` | ||
{ | ||
"conditions": [ | ||
{ | ||
"marking": 0, | ||
"name": "start", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"marking": 1, | ||
"name": "end", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"marking": 0, | ||
"name": "implicit:t1->t2", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"marking": 1, | ||
"name": "implicit:t1->t3", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"marking": 0, | ||
"name": "implicit:t1->t4", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
], | ||
"tasks": [ | ||
{ | ||
"generation": 1, | ||
"name": "t1", | ||
"state": "completed", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"generation": 1, | ||
"name": "t2", | ||
"state": "canceled", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"generation": 0, | ||
"name": "t3", | ||
"state": "disabled", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
{ | ||
"generation": 1, | ||
"name": "t4", | ||
"state": "completed", | ||
"workflowId": "workflow-1", | ||
"workflowName": "activities", | ||
}, | ||
], | ||
"workItems": [], | ||
"workflows": [ | ||
{ | ||
"context": undefined, | ||
"id": "workflow-1", | ||
"name": "activities", | ||
"parent": null, | ||
"state": "completed", | ||
}, | ||
], | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Effect } from 'effect'; | ||
import { expect, it } from 'vitest'; | ||
|
||
import { Builder, IdGenerator, Service } from '../index.js'; | ||
import { getEnabledTaskNames, makeIdGenerator } from './shared.js'; | ||
|
||
const workflowDefinition = Builder.workflow() | ||
.withName('activities') | ||
.startCondition('start') | ||
.task('t1', Builder.emptyTask().withSplitType('and')) | ||
.task('t2') | ||
.task('t3') | ||
.task('t4', Builder.emptyTask()) | ||
.endCondition('end') | ||
.connectCondition('start', (to) => to.task('t1')) | ||
.connectTask('t1', (to) => to.task('t2').task('t3').task('t4')) | ||
.connectTask('t2', (to) => to.condition('end')) | ||
.connectTask('t3', (to) => to.condition('end')) | ||
.connectTask('t4', (to) => to.condition('end')); | ||
|
||
it('cancels or disables started or enabled tasks on workflow end', () => { | ||
const program = Effect.gen(function* ($) { | ||
const idGenerator = makeIdGenerator(); | ||
|
||
const service = yield* $( | ||
workflowDefinition.build(), | ||
Effect.flatMap((workflow) => Service.initialize(workflow)), | ||
Effect.provideService(IdGenerator, idGenerator) | ||
); | ||
|
||
yield* $(service.start()); | ||
const state = yield* $(service.getState()); | ||
expect(state).toMatchSnapshot(); | ||
expect(getEnabledTaskNames(state)).toEqual(new Set(['t1'])); | ||
|
||
yield* $(service.startTask('t1')); | ||
const state2 = yield* $(service.getState()); | ||
expect(state2).toMatchSnapshot(); | ||
expect(getEnabledTaskNames(state2)).toEqual(new Set(['t2', 't3', 't4'])); | ||
|
||
yield* $(service.startTask('t2')); | ||
const state3 = yield* $(service.getState()); | ||
expect(state3).toMatchSnapshot(); | ||
expect(getEnabledTaskNames(state3)).toEqual(new Set(['t3', 't4'])); | ||
|
||
yield* $(service.startTask('t4')); | ||
const state4 = yield* $(service.getState()); | ||
expect(state4).toMatchSnapshot(); | ||
expect(getEnabledTaskNames(state4)).toEqual(new Set()); | ||
expect(state4.tasks.filter((t) => t.state === 'started')).toEqual([]); | ||
expect(state4.workflows[0]?.state).toEqual('completed'); | ||
}); | ||
|
||
Effect.runSync(program); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters