-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathworkflow-queue.test.ts
More file actions
222 lines (205 loc) · 6.1 KB
/
workflow-queue.test.ts
File metadata and controls
222 lines (205 loc) · 6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import {
WizardWorkflowQueue,
createInitialWizardWorkflowQueue,
createPostBootstrapQueue,
parseWorkflowStepsFromSkillMd,
type WorkflowStepSeed,
} from '../workflow-queue';
const BASIC_INTEGRATION_STEPS: WorkflowStepSeed[] = [
{
stepId: '1.0-begin',
referenceFilename: 'basic-integration-1.0-begin.md',
title: 'PostHog Setup - Begin',
},
{
stepId: '1.1-edit',
referenceFilename: 'basic-integration-1.1-edit.md',
title: 'PostHog Setup - Edit',
},
{
stepId: '1.2-revise',
referenceFilename: 'basic-integration-1.2-revise.md',
title: 'PostHog Setup - Revise',
},
{
stepId: '1.3-conclude',
referenceFilename: 'basic-integration-1.3-conclude.md',
title: 'PostHog Setup - Conclusion',
},
];
describe('WizardWorkflowQueue', () => {
it('seeds a queue from workflow steps in the expected order', () => {
const queue = createInitialWizardWorkflowQueue(BASIC_INTEGRATION_STEPS);
expect(queue.toArray()).toEqual([
{ id: 'bootstrap', kind: 'bootstrap', label: 'Preparing integration' },
{
id: 'workflow:1.0-begin',
kind: 'workflow',
referenceFilename: 'basic-integration-1.0-begin.md',
label: 'PostHog Setup - Begin',
},
{
id: 'workflow:1.1-edit',
kind: 'workflow',
referenceFilename: 'basic-integration-1.1-edit.md',
label: 'PostHog Setup - Edit',
},
{
id: 'workflow:1.2-revise',
kind: 'workflow',
referenceFilename: 'basic-integration-1.2-revise.md',
label: 'PostHog Setup - Revise',
},
{
id: 'workflow:1.3-conclude',
kind: 'workflow',
referenceFilename: 'basic-integration-1.3-conclude.md',
label: 'PostHog Setup - Conclusion',
},
{ id: 'env-vars', kind: 'env-vars', label: 'Environment variables' },
]);
});
it('builds a queue from arbitrary steps, not just basic-integration', () => {
const customSteps: WorkflowStepSeed[] = [
{
stepId: 'setup',
referenceFilename: 'feature-flags-setup.md',
title: 'Setup',
},
{
stepId: 'verify',
referenceFilename: 'feature-flags-verify.md',
title: 'Verify',
},
];
const queue = createInitialWizardWorkflowQueue(customSteps);
expect(queue.toArray()).toEqual([
{ id: 'bootstrap', kind: 'bootstrap', label: 'Preparing integration' },
{
id: 'workflow:setup',
kind: 'workflow',
referenceFilename: 'feature-flags-setup.md',
label: 'Setup',
},
{
id: 'workflow:verify',
kind: 'workflow',
referenceFilename: 'feature-flags-verify.md',
label: 'Verify',
},
{ id: 'env-vars', kind: 'env-vars', label: 'Environment variables' },
]);
});
it('createPostBootstrapQueue omits bootstrap', () => {
const queue = createPostBootstrapQueue(BASIC_INTEGRATION_STEPS);
const items = queue.toArray();
expect(items[0]).toEqual({
id: 'workflow:1.0-begin',
kind: 'workflow',
referenceFilename: 'basic-integration-1.0-begin.md',
label: 'PostHog Setup - Begin',
});
expect(items[items.length - 1]).toEqual({
id: 'env-vars',
kind: 'env-vars',
label: 'Environment variables',
});
expect(items.find((i) => i.id === 'bootstrap')).toBeUndefined();
});
it('supports enqueue and dequeue operations', () => {
const queue = new WizardWorkflowQueue();
queue.enqueue({ id: 'bootstrap', kind: 'bootstrap', label: 'Bootstrap' });
queue.enqueue({
id: 'workflow:1.0-begin',
kind: 'workflow',
referenceFilename: 'basic-integration-1.0-begin.md',
label: 'Begin',
});
expect(queue.peek()).toEqual({
id: 'bootstrap',
kind: 'bootstrap',
label: 'Bootstrap',
});
expect(queue.dequeue()).toEqual({
id: 'bootstrap',
kind: 'bootstrap',
label: 'Bootstrap',
});
expect(queue).toHaveLength(1);
expect(queue.dequeue()).toEqual({
id: 'workflow:1.0-begin',
kind: 'workflow',
referenceFilename: 'basic-integration-1.0-begin.md',
label: 'Begin',
});
expect(queue).toHaveLength(0);
});
});
describe('parseWorkflowStepsFromSkillMd', () => {
it('parses workflow steps from SKILL.md frontmatter', () => {
const skillMd = `---
name: integration-nextjs-app-router
description: PostHog integration for Next.js App Router applications
metadata:
author: PostHog
version: dev
workflow:
- step_id: 1.0-begin
reference: basic-integration-1.0-begin.md
title: PostHog Setup - Begin
next:
- basic-integration-1.1-edit.md
- step_id: 1.1-edit
reference: basic-integration-1.1-edit.md
title: PostHog Setup - Edit
next:
- basic-integration-1.2-revise.md
- step_id: 1.2-revise
reference: basic-integration-1.2-revise.md
title: PostHog Setup - Revise
next:
- basic-integration-1.3-conclude.md
- step_id: 1.3-conclude
reference: basic-integration-1.3-conclude.md
title: PostHog Setup - Conclusion
next: []
---
# PostHog integration for Next.js App Router
`;
const steps = parseWorkflowStepsFromSkillMd(skillMd);
expect(steps).toEqual([
{
stepId: '1.0-begin',
referenceFilename: 'basic-integration-1.0-begin.md',
title: 'PostHog Setup - Begin',
},
{
stepId: '1.1-edit',
referenceFilename: 'basic-integration-1.1-edit.md',
title: 'PostHog Setup - Edit',
},
{
stepId: '1.2-revise',
referenceFilename: 'basic-integration-1.2-revise.md',
title: 'PostHog Setup - Revise',
},
{
stepId: '1.3-conclude',
referenceFilename: 'basic-integration-1.3-conclude.md',
title: 'PostHog Setup - Conclusion',
},
]);
});
it('returns empty array when no frontmatter', () => {
expect(parseWorkflowStepsFromSkillMd('# No frontmatter')).toEqual([]);
});
it('returns empty array when no workflow key', () => {
const skillMd = `---
name: feature-flags-nextjs
description: docs only
---
# Feature flags
`;
expect(parseWorkflowStepsFromSkillMd(skillMd)).toEqual([]);
});
});