task-pipeliner 0.1.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/LICENSE +21 -0
- package/README.ko.md +1034 -0
- package/README.md +1031 -0
- package/dist/cli/index.d.ts +19 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +147 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/prompts.d.ts +48 -0
- package/dist/cli/prompts.d.ts.map +1 -0
- package/dist/cli/prompts.js +75 -0
- package/dist/cli/prompts.js.map +1 -0
- package/dist/cli/ui.d.ts +39 -0
- package/dist/cli/ui.d.ts.map +1 -0
- package/dist/cli/ui.js +84 -0
- package/dist/cli/ui.js.map +1 -0
- package/dist/core/__tests__/actual-execution.test.d.ts +2 -0
- package/dist/core/__tests__/actual-execution.test.d.ts.map +1 -0
- package/dist/core/__tests__/actual-execution.test.js +140 -0
- package/dist/core/__tests__/actual-execution.test.js.map +1 -0
- package/dist/core/__tests__/base-dir.test.d.ts +2 -0
- package/dist/core/__tests__/base-dir.test.d.ts.map +1 -0
- package/dist/core/__tests__/base-dir.test.js +146 -0
- package/dist/core/__tests__/base-dir.test.js.map +1 -0
- package/dist/core/__tests__/built-code-execution.test.d.ts +2 -0
- package/dist/core/__tests__/built-code-execution.test.d.ts.map +1 -0
- package/dist/core/__tests__/built-code-execution.test.js +48 -0
- package/dist/core/__tests__/built-code-execution.test.js.map +1 -0
- package/dist/core/__tests__/choose-as-var-condition.test.d.ts +2 -0
- package/dist/core/__tests__/choose-as-var-condition.test.d.ts.map +1 -0
- package/dist/core/__tests__/choose-as-var-condition.test.js +308 -0
- package/dist/core/__tests__/choose-as-var-condition.test.js.map +1 -0
- package/dist/core/__tests__/cli-integration.test.d.ts +2 -0
- package/dist/core/__tests__/cli-integration.test.d.ts.map +1 -0
- package/dist/core/__tests__/cli-integration.test.js +83 -0
- package/dist/core/__tests__/cli-integration.test.js.map +1 -0
- package/dist/core/__tests__/comprehensive-basic-yaml.test.d.ts +2 -0
- package/dist/core/__tests__/comprehensive-basic-yaml.test.d.ts.map +1 -0
- package/dist/core/__tests__/comprehensive-basic-yaml.test.js +111 -0
- package/dist/core/__tests__/comprehensive-basic-yaml.test.js.map +1 -0
- package/dist/core/__tests__/condition-evaluator.test.d.ts +2 -0
- package/dist/core/__tests__/condition-evaluator.test.d.ts.map +1 -0
- package/dist/core/__tests__/condition-evaluator.test.js +170 -0
- package/dist/core/__tests__/condition-evaluator.test.js.map +1 -0
- package/dist/core/__tests__/debug-basic-yaml.test.d.ts +2 -0
- package/dist/core/__tests__/debug-basic-yaml.test.d.ts.map +1 -0
- package/dist/core/__tests__/debug-basic-yaml.test.js +128 -0
- package/dist/core/__tests__/debug-basic-yaml.test.js.map +1 -0
- package/dist/core/__tests__/example-files.test.d.ts +2 -0
- package/dist/core/__tests__/example-files.test.d.ts.map +1 -0
- package/dist/core/__tests__/example-files.test.js +200 -0
- package/dist/core/__tests__/example-files.test.js.map +1 -0
- package/dist/core/__tests__/executor-choice-integration.test.d.ts +2 -0
- package/dist/core/__tests__/executor-choice-integration.test.d.ts.map +1 -0
- package/dist/core/__tests__/executor-choice-integration.test.js +171 -0
- package/dist/core/__tests__/executor-choice-integration.test.js.map +1 -0
- package/dist/core/__tests__/executor-choice.test.d.ts +2 -0
- package/dist/core/__tests__/executor-choice.test.d.ts.map +1 -0
- package/dist/core/__tests__/executor-choice.test.js +174 -0
- package/dist/core/__tests__/executor-choice.test.js.map +1 -0
- package/dist/core/__tests__/executor-parallel.test.d.ts +2 -0
- package/dist/core/__tests__/executor-parallel.test.d.ts.map +1 -0
- package/dist/core/__tests__/executor-parallel.test.js +136 -0
- package/dist/core/__tests__/executor-parallel.test.js.map +1 -0
- package/dist/core/__tests__/executor-prompt.test.d.ts +2 -0
- package/dist/core/__tests__/executor-prompt.test.d.ts.map +1 -0
- package/dist/core/__tests__/executor-prompt.test.js +149 -0
- package/dist/core/__tests__/executor-prompt.test.js.map +1 -0
- package/dist/core/__tests__/executor-real-scenario.test.d.ts +2 -0
- package/dist/core/__tests__/executor-real-scenario.test.d.ts.map +1 -0
- package/dist/core/__tests__/executor-real-scenario.test.js +169 -0
- package/dist/core/__tests__/executor-real-scenario.test.js.map +1 -0
- package/dist/core/__tests__/file-condition.test.d.ts +2 -0
- package/dist/core/__tests__/file-condition.test.d.ts.map +1 -0
- package/dist/core/__tests__/file-condition.test.js +182 -0
- package/dist/core/__tests__/file-condition.test.js.map +1 -0
- package/dist/core/__tests__/final-verification.test.d.ts +2 -0
- package/dist/core/__tests__/final-verification.test.d.ts.map +1 -0
- package/dist/core/__tests__/final-verification.test.js +59 -0
- package/dist/core/__tests__/final-verification.test.js.map +1 -0
- package/dist/core/__tests__/parallel-when-condition.test.d.ts +2 -0
- package/dist/core/__tests__/parallel-when-condition.test.d.ts.map +1 -0
- package/dist/core/__tests__/parallel-when-condition.test.js +155 -0
- package/dist/core/__tests__/parallel-when-condition.test.js.map +1 -0
- package/dist/core/__tests__/parser.test.d.ts +2 -0
- package/dist/core/__tests__/parser.test.d.ts.map +1 -0
- package/dist/core/__tests__/parser.test.js +94 -0
- package/dist/core/__tests__/parser.test.js.map +1 -0
- package/dist/core/__tests__/real-inquirer-test.test.d.ts +2 -0
- package/dist/core/__tests__/real-inquirer-test.test.d.ts.map +1 -0
- package/dist/core/__tests__/real-inquirer-test.test.js +20 -0
- package/dist/core/__tests__/real-inquirer-test.test.js.map +1 -0
- package/dist/core/__tests__/reproduce-bug.test.d.ts +2 -0
- package/dist/core/__tests__/reproduce-bug.test.d.ts.map +1 -0
- package/dist/core/__tests__/reproduce-bug.test.js +84 -0
- package/dist/core/__tests__/reproduce-bug.test.js.map +1 -0
- package/dist/core/__tests__/timeout-retry.test.d.ts +2 -0
- package/dist/core/__tests__/timeout-retry.test.d.ts.map +1 -0
- package/dist/core/__tests__/timeout-retry.test.js +184 -0
- package/dist/core/__tests__/timeout-retry.test.js.map +1 -0
- package/dist/core/__tests__/workflow-validation.test.d.ts +2 -0
- package/dist/core/__tests__/workflow-validation.test.d.ts.map +1 -0
- package/dist/core/__tests__/workflow-validation.test.js +120 -0
- package/dist/core/__tests__/workflow-validation.test.js.map +1 -0
- package/dist/core/__tests__/workspace.test.d.ts +2 -0
- package/dist/core/__tests__/workspace.test.d.ts.map +1 -0
- package/dist/core/__tests__/workspace.test.js +29 -0
- package/dist/core/__tests__/workspace.test.js.map +1 -0
- package/dist/core/__tests__/yaml-integration.test.d.ts +2 -0
- package/dist/core/__tests__/yaml-integration.test.d.ts.map +1 -0
- package/dist/core/__tests__/yaml-integration.test.js +114 -0
- package/dist/core/__tests__/yaml-integration.test.js.map +1 -0
- package/dist/core/__tests__/yaml-scenarios.test.d.ts +2 -0
- package/dist/core/__tests__/yaml-scenarios.test.d.ts.map +1 -0
- package/dist/core/__tests__/yaml-scenarios.test.js +199 -0
- package/dist/core/__tests__/yaml-scenarios.test.js.map +1 -0
- package/dist/core/condition-evaluator.d.ts +44 -0
- package/dist/core/condition-evaluator.d.ts.map +1 -0
- package/dist/core/condition-evaluator.js +121 -0
- package/dist/core/condition-evaluator.js.map +1 -0
- package/dist/core/executor.d.ts +172 -0
- package/dist/core/executor.d.ts.map +1 -0
- package/dist/core/executor.js +579 -0
- package/dist/core/executor.js.map +1 -0
- package/dist/core/parser.d.ts +41 -0
- package/dist/core/parser.d.ts.map +1 -0
- package/dist/core/parser.js +202 -0
- package/dist/core/parser.js.map +1 -0
- package/dist/core/rust-task-runner.d.ts +14 -0
- package/dist/core/rust-task-runner.d.ts.map +1 -0
- package/dist/core/rust-task-runner.js +34 -0
- package/dist/core/rust-task-runner.js.map +1 -0
- package/dist/core/task-runner.d.ts +63 -0
- package/dist/core/task-runner.d.ts.map +1 -0
- package/dist/core/task-runner.js +252 -0
- package/dist/core/task-runner.js.map +1 -0
- package/dist/core/template.d.ts +11 -0
- package/dist/core/template.d.ts.map +1 -0
- package/dist/core/template.js +36 -0
- package/dist/core/template.js.map +1 -0
- package/dist/core/workflow-schema.d.ts +31 -0
- package/dist/core/workflow-schema.d.ts.map +1 -0
- package/dist/core/workflow-schema.js +125 -0
- package/dist/core/workflow-schema.js.map +1 -0
- package/dist/core/workspace.d.ts +90 -0
- package/dist/core/workspace.d.ts.map +1 -0
- package/dist/core/workspace.js +143 -0
- package/dist/core/workspace.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/task-pipeliner-rs.node +0 -0
- package/dist/types/condition.d.ts +62 -0
- package/dist/types/condition.d.ts.map +1 -0
- package/dist/types/condition.js +6 -0
- package/dist/types/condition.js.map +1 -0
- package/dist/types/workflow.d.ts +69 -0
- package/dist/types/workflow.d.ts.map +1 -0
- package/dist/types/workflow.js +2 -0
- package/dist/types/workflow.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { Executor } from '../executor.js';
|
|
3
|
+
// Mock ChoicePrompt, TextPrompt
|
|
4
|
+
vi.mock('../../cli/prompts.js', () => {
|
|
5
|
+
return {
|
|
6
|
+
ChoicePrompt: vi.fn().mockImplementation(() => {
|
|
7
|
+
return {
|
|
8
|
+
prompt: vi.fn(),
|
|
9
|
+
};
|
|
10
|
+
}),
|
|
11
|
+
TextPrompt: vi.fn().mockImplementation(() => {
|
|
12
|
+
return {
|
|
13
|
+
prompt: vi.fn(),
|
|
14
|
+
};
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
// Mock TaskRunner
|
|
19
|
+
const mockRun = vi.fn().mockResolvedValue(true);
|
|
20
|
+
vi.mock('../task-runner.js', () => {
|
|
21
|
+
return {
|
|
22
|
+
TaskRunner: vi.fn().mockImplementation(() => {
|
|
23
|
+
return {
|
|
24
|
+
run: mockRun,
|
|
25
|
+
displayBufferedOutput: vi.fn(),
|
|
26
|
+
};
|
|
27
|
+
}),
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
describe('YAML Scenario Tests', () => {
|
|
31
|
+
let executor;
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
vi.clearAllMocks();
|
|
34
|
+
executor = new Executor();
|
|
35
|
+
});
|
|
36
|
+
describe('basic.yaml', () => {
|
|
37
|
+
it('should execute basic workflow with choice', async () => {
|
|
38
|
+
const workflow = {
|
|
39
|
+
steps: [
|
|
40
|
+
{ run: 'echo "Building..."' },
|
|
41
|
+
{
|
|
42
|
+
choose: {
|
|
43
|
+
message: 'Deploy to which environment?',
|
|
44
|
+
options: [
|
|
45
|
+
{ id: 'staging', label: 'Staging' },
|
|
46
|
+
{ id: 'prod', label: 'Production' },
|
|
47
|
+
],
|
|
48
|
+
as: 'env',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
when: {
|
|
53
|
+
var: {
|
|
54
|
+
env: 'staging'
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
run: 'echo "Deploying to staging..."',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
when: {
|
|
61
|
+
var: {
|
|
62
|
+
env: 'prod'
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
run: 'echo "Deploying to production..."',
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
const choicePrompt = executor.choicePrompt;
|
|
70
|
+
choicePrompt.prompt = vi.fn().mockResolvedValue({ id: 'staging', label: 'Staging' });
|
|
71
|
+
await executor.execute(workflow);
|
|
72
|
+
const calls = mockRun.mock.calls.map(call => call[0]);
|
|
73
|
+
expect(calls).toContain('echo "Deploying to staging..."');
|
|
74
|
+
expect(calls).not.toContain('echo "Deploying to production..."');
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
describe('prompt.yaml', () => {
|
|
78
|
+
it('should execute prompt workflow with variables', async () => {
|
|
79
|
+
const workflow = {
|
|
80
|
+
steps: [
|
|
81
|
+
{
|
|
82
|
+
prompt: {
|
|
83
|
+
message: 'What is your name?',
|
|
84
|
+
as: 'user_name',
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
when: { var: 'user_name' },
|
|
89
|
+
run: 'echo "Hello, {{user_name}}!"',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
prompt: {
|
|
93
|
+
message: 'Enter version number:',
|
|
94
|
+
as: 'version',
|
|
95
|
+
default: '1.0.0',
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
when: { var: 'version' },
|
|
100
|
+
run: 'echo "Building version {{version}}..."',
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
};
|
|
104
|
+
const textPrompt = executor.textPrompt;
|
|
105
|
+
textPrompt.prompt = vi.fn()
|
|
106
|
+
.mockResolvedValueOnce('John')
|
|
107
|
+
.mockResolvedValueOnce('2.0.0');
|
|
108
|
+
await executor.execute(workflow);
|
|
109
|
+
const calls = mockRun.mock.calls.map(call => call[0]);
|
|
110
|
+
expect(calls).toContain('echo "Hello, John!"');
|
|
111
|
+
expect(calls).toContain('echo "Building version 2.0.0..."');
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
describe('parallel.yaml', () => {
|
|
115
|
+
it('should execute parallel steps', async () => {
|
|
116
|
+
const workflow = {
|
|
117
|
+
steps: [
|
|
118
|
+
{
|
|
119
|
+
parallel: [
|
|
120
|
+
{ run: 'echo "Running web tests..."' },
|
|
121
|
+
{ run: 'echo "Running API tests..."' },
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
choose: {
|
|
126
|
+
message: 'Deploy strategy?',
|
|
127
|
+
options: [
|
|
128
|
+
{ id: 'blue_green', label: 'Blue-Green' },
|
|
129
|
+
{ id: 'rolling', label: 'Rolling' },
|
|
130
|
+
],
|
|
131
|
+
as: 'strategy',
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
when: {
|
|
136
|
+
var: {
|
|
137
|
+
strategy: 'blue_green'
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
run: 'echo "Deploying with blue-green strategy..."',
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
};
|
|
144
|
+
const choicePrompt = executor.choicePrompt;
|
|
145
|
+
choicePrompt.prompt = vi.fn().mockResolvedValue({ id: 'blue_green', label: 'Blue-Green' });
|
|
146
|
+
await executor.execute(workflow);
|
|
147
|
+
const calls = mockRun.mock.calls.map(call => call[0]);
|
|
148
|
+
expect(calls).toContain('echo "Running web tests..."');
|
|
149
|
+
expect(calls).toContain('echo "Running API tests..."');
|
|
150
|
+
expect(calls).toContain('echo "Deploying with blue-green strategy..."');
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
describe('conditions.yaml', () => {
|
|
154
|
+
it('should check file existence', async () => {
|
|
155
|
+
const workflow = {
|
|
156
|
+
steps: [
|
|
157
|
+
{
|
|
158
|
+
when: { file: 'package.json' },
|
|
159
|
+
run: 'echo "Package.json exists"',
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
when: {
|
|
163
|
+
not: { file: 'nonexistent.txt' },
|
|
164
|
+
},
|
|
165
|
+
run: 'echo "File does not exist"',
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
};
|
|
169
|
+
await executor.execute(workflow);
|
|
170
|
+
const calls = mockRun.mock.calls.map(call => call[0]);
|
|
171
|
+
expect(calls).toContain('echo "Package.json exists"');
|
|
172
|
+
expect(calls).toContain('echo "File does not exist"');
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
describe('variables.yaml', () => {
|
|
176
|
+
it('should use variables from prompts', async () => {
|
|
177
|
+
const workflow = {
|
|
178
|
+
steps: [
|
|
179
|
+
{
|
|
180
|
+
prompt: {
|
|
181
|
+
message: 'Enter project name:',
|
|
182
|
+
as: 'project_name',
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
when: { var: 'project_name' },
|
|
187
|
+
run: 'echo "Building {{project_name}}..."',
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
};
|
|
191
|
+
const textPrompt = executor.textPrompt;
|
|
192
|
+
textPrompt.prompt = vi.fn().mockResolvedValue('my-app');
|
|
193
|
+
await executor.execute(workflow);
|
|
194
|
+
const calls = mockRun.mock.calls.map(call => call[0]);
|
|
195
|
+
expect(calls).toContain('echo "Building my-app..."');
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
//# sourceMappingURL=yaml-scenarios.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml-scenarios.test.js","sourceRoot":"","sources":["../../../src/core/__tests__/yaml-scenarios.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAE9D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,gCAAgC;AAChC,EAAE,CAAC,IAAI,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACnC,OAAO;QACL,YAAY,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE;YAC5C,OAAO;gBACL,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE;aAChB,CAAC;QACJ,CAAC,CAAC;QACF,UAAU,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE;YAC1C,OAAO;gBACL,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE;aAChB,CAAC;QACJ,CAAC,CAAC;KACH,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,kBAAkB;AAClB,MAAM,OAAO,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;AAChD,EAAE,CAAC,IAAI,C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a;gBACzB,KAAK,EAAE;oBACL;wBACE,MAAM,EAAE;4BACN,OAAO,EAAE,qBAAqB;4BAC9B,EAAE,EAAE,cAAc;yBACnB;qBACF;oBACD;wBACE,IAAI,EAAE,EAAE,GAAG,EAAE,cAAc,EAAE;wBAC7B,GAAG,EAAE,qCAAqC;qBAC3C;iBACF;aACF,CAAC;YAEF,MAAM,UAAU,GAAI,QAAgB,CAAC,UAAU,CAAC;YAChD,UAAU,CAAC,MAAM,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;YAExD,MAAM,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAEjC,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YACtD,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,2BAA2B,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Condition } from '../types/condition.js';
|
|
2
|
+
import type { Workspace } from './workspace.js';
|
|
3
|
+
/**
|
|
4
|
+
* Condition Evaluator
|
|
5
|
+
* Evaluates conditions as questions about the workspace
|
|
6
|
+
*/
|
|
7
|
+
export declare class ConditionEvaluator {
|
|
8
|
+
private workspace;
|
|
9
|
+
constructor(workspace: Workspace);
|
|
10
|
+
/**
|
|
11
|
+
* Evaluate condition as a question about the workspace
|
|
12
|
+
* Returns true if condition is met, false otherwise
|
|
13
|
+
*/
|
|
14
|
+
evaluate(condition: Condition): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Check if a variable or fact exists in workspace, or compare variable value
|
|
17
|
+
*
|
|
18
|
+
* Supports two formats:
|
|
19
|
+
* 1. { var: 'name' } - Check if variable exists
|
|
20
|
+
* 2. { var: { name: 'value' } } - Check if variable equals specific value
|
|
21
|
+
*/
|
|
22
|
+
private evaluateVarExists;
|
|
23
|
+
/**
|
|
24
|
+
* Check if a file or directory exists
|
|
25
|
+
*/
|
|
26
|
+
private evaluateFileExists;
|
|
27
|
+
/**
|
|
28
|
+
* Check if user made a specific choice
|
|
29
|
+
*/
|
|
30
|
+
private evaluateChoice;
|
|
31
|
+
/**
|
|
32
|
+
* Check if all conditions are true (AND logic)
|
|
33
|
+
*/
|
|
34
|
+
private evaluateAll;
|
|
35
|
+
/**
|
|
36
|
+
* Check if any condition is true (OR logic)
|
|
37
|
+
*/
|
|
38
|
+
private evaluateAny;
|
|
39
|
+
/**
|
|
40
|
+
* Negate a condition (NOT logic)
|
|
41
|
+
*/
|
|
42
|
+
private evaluateNot;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=condition-evaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition-evaluator.d.ts","sourceRoot":"","sources":["../../src/core/condition-evaluator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;GAGG;AAEH,qBAAa,kBAAkB;IACjB,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,SAAS;IAExC;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO;IAoCvC;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;IAqCzB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAU1B;;OAEG;IACH,OAAO,CAAC,cAAc;IAItB;;OAEG;IACH,OAAO,CAAC,WAAW;IAInB;;OAEG;IACH,OAAO,CAAC,WAAW;IAInB;;OAEG;IACH,OAAO,CAAC,WAAW;CAGpB"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
/**
|
|
4
|
+
* Condition Evaluator
|
|
5
|
+
* Evaluates conditions as questions about the workspace
|
|
6
|
+
*/
|
|
7
|
+
export class ConditionEvaluator {
|
|
8
|
+
workspace;
|
|
9
|
+
constructor(workspace) {
|
|
10
|
+
this.workspace = workspace;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Evaluate condition as a question about the workspace
|
|
14
|
+
* Returns true if condition is met, false otherwise
|
|
15
|
+
*/
|
|
16
|
+
evaluate(condition) {
|
|
17
|
+
// Check if variable or fact exists, or compare variable value
|
|
18
|
+
// This should be checked before 'choice' to support var value comparison
|
|
19
|
+
if ('var' in condition || 'has' in condition) {
|
|
20
|
+
return this.evaluateVarExists(condition);
|
|
21
|
+
}
|
|
22
|
+
// Check if file exists
|
|
23
|
+
if ('file' in condition) {
|
|
24
|
+
return this.evaluateFileExists(condition);
|
|
25
|
+
}
|
|
26
|
+
// Check if user made a specific choice (deprecated, use var instead)
|
|
27
|
+
// Kept for backward compatibility
|
|
28
|
+
if ('choice' in condition) {
|
|
29
|
+
return this.evaluateChoice(condition);
|
|
30
|
+
}
|
|
31
|
+
// All conditions must be true (AND)
|
|
32
|
+
if ('all' in condition) {
|
|
33
|
+
return this.evaluateAll(condition);
|
|
34
|
+
}
|
|
35
|
+
// Any condition can be true (OR)
|
|
36
|
+
if ('any' in condition) {
|
|
37
|
+
return this.evaluateAny(condition);
|
|
38
|
+
}
|
|
39
|
+
// Negate a condition (NOT)
|
|
40
|
+
if ('not' in condition) {
|
|
41
|
+
return this.evaluateNot(condition);
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if a variable or fact exists in workspace, or compare variable value
|
|
47
|
+
*
|
|
48
|
+
* Supports two formats:
|
|
49
|
+
* 1. { var: 'name' } - Check if variable exists
|
|
50
|
+
* 2. { var: { name: 'value' } } - Check if variable equals specific value
|
|
51
|
+
*/
|
|
52
|
+
evaluateVarExists(condition) {
|
|
53
|
+
// Handle 'has' alias (existence check only)
|
|
54
|
+
if (condition.has) {
|
|
55
|
+
return this.workspace.hasVariable(condition.has) || this.workspace.hasFact(condition.has);
|
|
56
|
+
}
|
|
57
|
+
if (!condition.var) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
// If var is an object, it's a value comparison: { var: { env: 'dev' } }
|
|
61
|
+
if (typeof condition.var === 'object') {
|
|
62
|
+
// Check each variable-value pair
|
|
63
|
+
for (const [variableName, expectedValue] of Object.entries(condition.var)) {
|
|
64
|
+
// Get variable value (prefer variable over fact)
|
|
65
|
+
const variableValue = this.workspace.getVariable(variableName);
|
|
66
|
+
const factValue = this.workspace.getFact(variableName);
|
|
67
|
+
const actualValue = variableValue ?? (factValue !== undefined ? factValue.toString() : undefined);
|
|
68
|
+
// If variable doesn't exist, condition is false
|
|
69
|
+
if (actualValue === undefined) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
// Compare values (both should be strings for comparison)
|
|
73
|
+
if (actualValue !== expectedValue) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
// If var is a string, it's an existence check: { var: 'name' }
|
|
80
|
+
const variableName = condition.var;
|
|
81
|
+
return this.workspace.hasVariable(variableName) || this.workspace.hasFact(variableName);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Check if a file or directory exists
|
|
85
|
+
*/
|
|
86
|
+
evaluateFileExists(condition) {
|
|
87
|
+
try {
|
|
88
|
+
const filePath = condition.file.trim();
|
|
89
|
+
const absolutePath = resolve(process.cwd(), filePath);
|
|
90
|
+
return existsSync(absolutePath);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Check if user made a specific choice
|
|
98
|
+
*/
|
|
99
|
+
evaluateChoice(condition) {
|
|
100
|
+
return this.workspace.hasChoice(condition.choice);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Check if all conditions are true (AND logic)
|
|
104
|
+
*/
|
|
105
|
+
evaluateAll(condition) {
|
|
106
|
+
return condition.all.every((subCondition) => this.evaluate(subCondition));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Check if any condition is true (OR logic)
|
|
110
|
+
*/
|
|
111
|
+
evaluateAny(condition) {
|
|
112
|
+
return condition.any.some((subCondition) => this.evaluate(subCondition));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Negate a condition (NOT logic)
|
|
116
|
+
*/
|
|
117
|
+
evaluateNot(condition) {
|
|
118
|
+
return !this.evaluate(condition.not);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=condition-evaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition-evaluator.js","sourceRoot":"","sources":["../../src/core/condition-evaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAI/B;;;GAGG;AAEH,MAAM,OAAO,kBAAkB;IACT;IAApB,YAAoB,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAG,CAAC;IAE5C;;;OAGG;IACH,QAAQ,CAAC,SAAoB;QAC3B,8DAA8D;QAC9D,yEAAyE;QACzE,IAAI,KAAK,IAAI,SAAS,IAAI,KAAK,IAAI,SAAS,EAAE,CAAC;YAC7C,OAAO,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAC3C,CAAC;QAED,uBAAuB;QACvB,IAAI,MAAM,IAAI,SAAS,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;QAC5C,CAAC;QAED,qEAAqE;QACrE,kCAAkC;QAClC,I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ACjD,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED;;OAEG;IACK,WAAW,CAAC,SAA6B;QAC/C,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import type { Workflow } from '../types/workflow.js';
|
|
2
|
+
import { Workspace } from './workspace.js';
|
|
3
|
+
/**
|
|
4
|
+
* Workflow Executor
|
|
5
|
+
*
|
|
6
|
+
* This class executes workflow steps sequentially, handling:
|
|
7
|
+
* - Step execution (run, choose, prompt, parallel, fail)
|
|
8
|
+
* - Condition evaluation (when clauses)
|
|
9
|
+
* - Variable substitution
|
|
10
|
+
* - Parallel execution with workspace cloning
|
|
11
|
+
* - Error handling and reporting
|
|
12
|
+
*/
|
|
13
|
+
export interface ExecutionContext {
|
|
14
|
+
workspace: Workspace;
|
|
15
|
+
stepIndex: number;
|
|
16
|
+
branchIndex?: number;
|
|
17
|
+
lineNumber?: number;
|
|
18
|
+
fileName?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare class Executor {
|
|
21
|
+
private static readonly PARALLEL_STEP_INDEX_MULTIPLIER;
|
|
22
|
+
private workspace;
|
|
23
|
+
private taskRunner;
|
|
24
|
+
private choicePrompt;
|
|
25
|
+
private textPrompt;
|
|
26
|
+
private baseDir?;
|
|
27
|
+
constructor();
|
|
28
|
+
/**
|
|
29
|
+
* Resolve baseDir path from workflow configuration
|
|
30
|
+
*
|
|
31
|
+
* baseDir determines where commands will be executed:
|
|
32
|
+
* - If absolute path: use as-is
|
|
33
|
+
* - If relative path: resolve relative to YAML file location
|
|
34
|
+
* - If no _filePath: resolve relative to current working directory
|
|
35
|
+
*/
|
|
36
|
+
private resolveBaseDir;
|
|
37
|
+
/**
|
|
38
|
+
* Create execution context for a step
|
|
39
|
+
*
|
|
40
|
+
* Context contains information needed to execute a step:
|
|
41
|
+
* - Workspace reference (for storing/reading state)
|
|
42
|
+
* - Step index (for tracking which step we're on)
|
|
43
|
+
* - Line number and file name (for error reporting)
|
|
44
|
+
*/
|
|
45
|
+
private createStepContext;
|
|
46
|
+
/**
|
|
47
|
+
* Evaluate step condition and return whether step should execute
|
|
48
|
+
*/
|
|
49
|
+
private evaluateStepCondition;
|
|
50
|
+
/**
|
|
51
|
+
* Calculate base step index for parallel execution
|
|
52
|
+
* When in parallel, stepIndex is encoded as: baseStepIndex * MULTIPLIER + branchIndex
|
|
53
|
+
* So we divide by MULTIPLIER to get the original step index
|
|
54
|
+
*/
|
|
55
|
+
private calculateBaseStepIndex;
|
|
56
|
+
/**
|
|
57
|
+
* Execute workflow steps sequentially
|
|
58
|
+
*
|
|
59
|
+
* Main entry point for workflow execution:
|
|
60
|
+
* 1. Resolve baseDir for command execution
|
|
61
|
+
* 2. Loop through each step
|
|
62
|
+
* 3. Evaluate conditions (when clauses)
|
|
63
|
+
* 4. Execute step if condition passes
|
|
64
|
+
* 5. Check for failures and handle errors
|
|
65
|
+
*/
|
|
66
|
+
execute(workflow: Workflow): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Check if step result indicates success
|
|
69
|
+
*/
|
|
70
|
+
private isStepSuccessful;
|
|
71
|
+
/**
|
|
72
|
+
* Fix malformed step (YAML indentation issue)
|
|
73
|
+
* When choose/prompt is null but properties exist at step level
|
|
74
|
+
* This happens when YAML is incorrectly indented
|
|
75
|
+
*/
|
|
76
|
+
private fixMalformedStep;
|
|
77
|
+
/**
|
|
78
|
+
* Execute a single step based on its type
|
|
79
|
+
*
|
|
80
|
+
* Steps can be:
|
|
81
|
+
* - run: Execute a shell command
|
|
82
|
+
* - choose: Show user a choice menu
|
|
83
|
+
* - prompt: Ask user for text input
|
|
84
|
+
* - parallel: Execute multiple steps in parallel
|
|
85
|
+
* - fail: Intentionally fail with a message
|
|
86
|
+
*
|
|
87
|
+
* @param bufferOutput - If true, collect output instead of displaying immediately (for parallel)
|
|
88
|
+
* @param hasWhenCondition - If true, step has a condition (affects UI color)
|
|
89
|
+
*/
|
|
90
|
+
private executeStep;
|
|
91
|
+
/**
|
|
92
|
+
* Execute a run step (shell command)
|
|
93
|
+
*
|
|
94
|
+
* Steps:
|
|
95
|
+
* 1. Calculate base step index (for parallel execution)
|
|
96
|
+
* 2. Substitute variables in command ({{variable}} syntax)
|
|
97
|
+
* 3. Run command via TaskRunner (with retry logic if specified)
|
|
98
|
+
* 4. Store result in workspace
|
|
99
|
+
*/
|
|
100
|
+
private executeRunStep;
|
|
101
|
+
/**
|
|
102
|
+
* Execute a choose step (show user a selection menu)
|
|
103
|
+
*
|
|
104
|
+
* User selects from options, and the choice is stored:
|
|
105
|
+
* - As a choice (for when: { choice: 'id' } conditions) - uses choice id
|
|
106
|
+
* - As a variable (for {{variable}} substitution) - uses 'as' field if provided, otherwise choice id
|
|
107
|
+
*/
|
|
108
|
+
private executeChooseStep;
|
|
109
|
+
/**
|
|
110
|
+
* Execute a prompt step (ask user for text input)
|
|
111
|
+
*
|
|
112
|
+
* User enters text, which is stored:
|
|
113
|
+
* - As a variable (for {{variable}} substitution)
|
|
114
|
+
* - As a fact (for when: { var: 'name' } conditions)
|
|
115
|
+
*/
|
|
116
|
+
private executePromptStep;
|
|
117
|
+
/**
|
|
118
|
+
* Create execution contexts for parallel branches
|
|
119
|
+
* Encodes branch index into stepIndex: baseStepIndex * MULTIPLIER + branchIndex
|
|
120
|
+
* Each branch inherits line number and file name from the parallel step
|
|
121
|
+
*/
|
|
122
|
+
private createParallelContexts;
|
|
123
|
+
/**
|
|
124
|
+
* Get display name for a parallel branch step
|
|
125
|
+
*/
|
|
126
|
+
private getBranchDisplayName;
|
|
127
|
+
/**
|
|
128
|
+
* Execute all parallel branches simultaneously
|
|
129
|
+
*
|
|
130
|
+
* Each branch:
|
|
131
|
+
* 1. Has its own workspace clone (isolated state)
|
|
132
|
+
* 2. Evaluates its own conditions
|
|
133
|
+
* 3. Executes in buffer mode (collects output, don't display yet)
|
|
134
|
+
* 4. Returns result or error
|
|
135
|
+
*
|
|
136
|
+
* All branches run at the same time using Promise.all()
|
|
137
|
+
* Uses log-update to show all branch statuses in real-time
|
|
138
|
+
*/
|
|
139
|
+
private executeParallelBranches;
|
|
140
|
+
/**
|
|
141
|
+
* Update parallel branches display using log-update
|
|
142
|
+
*/
|
|
143
|
+
private updateParallelBranchesDisplay;
|
|
144
|
+
/**
|
|
145
|
+
* Display parallel execution results
|
|
146
|
+
* Status display is already done, now we show the detailed output
|
|
147
|
+
*/
|
|
148
|
+
private displayParallelResults;
|
|
149
|
+
/**
|
|
150
|
+
* Merge facts and variables from parallel branches
|
|
151
|
+
*/
|
|
152
|
+
private mergeParallelResults;
|
|
153
|
+
/**
|
|
154
|
+
* Count how many branches will actually execute (after when condition evaluation)
|
|
155
|
+
*/
|
|
156
|
+
private countExecutableBranches;
|
|
157
|
+
/**
|
|
158
|
+
* Execute a parallel step (run multiple steps simultaneously)
|
|
159
|
+
*
|
|
160
|
+
* Process:
|
|
161
|
+
* 1. Create isolated contexts for each branch (with cloned workspaces)
|
|
162
|
+
* 2. Count how many branches will actually execute
|
|
163
|
+
* 3. Show header box with actual executable branch count
|
|
164
|
+
* 4. Execute all branches in parallel
|
|
165
|
+
* 5. Display results
|
|
166
|
+
* 6. Merge facts and variables from all branches back to main workspace
|
|
167
|
+
* 7. Throw error if any branch failed
|
|
168
|
+
*/
|
|
169
|
+
private executeParallelStep;
|
|
170
|
+
private executeFailStep;
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/core/executor.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAQ,QAAQ,EAA0B,MAAM,sBAAsB,CAAC;AAInF,OAAO,EAAE,SAAS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