@tagma/sdk 0.6.0 → 0.6.2
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 -21
- package/README.md +573 -573
- package/dist/bootstrap.d.ts +11 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +18 -9
- package/dist/bootstrap.js.map +1 -1
- package/dist/drivers/opencode.d.ts.map +1 -1
- package/dist/drivers/opencode.js +47 -17
- package/dist/drivers/opencode.js.map +1 -1
- package/dist/engine.d.ts +8 -0
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +17 -16
- package/dist/engine.js.map +1 -1
- package/dist/plugin-registry.test.d.ts +2 -0
- package/dist/plugin-registry.test.d.ts.map +1 -0
- package/dist/plugin-registry.test.js +188 -0
- package/dist/plugin-registry.test.js.map +1 -0
- package/dist/registry.d.ts +52 -28
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +126 -91
- package/dist/registry.js.map +1 -1
- package/dist/sdk.d.ts +1 -1
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +1 -1
- package/dist/sdk.js.map +1 -1
- package/package.json +2 -2
- package/src/bootstrap.ts +46 -37
- package/src/completions/output-check.ts +92 -92
- package/src/dag.ts +245 -245
- package/src/drivers/opencode.ts +410 -371
- package/src/engine.ts +1228 -1220
- package/src/hooks.ts +193 -193
- package/src/middlewares/static-context.ts +49 -49
- package/src/pipeline-runner.ts +173 -173
- package/src/plugin-registry.test.ts +230 -0
- package/src/prompt-doc.ts +49 -49
- package/src/registry.ts +316 -267
- package/src/runner.ts +460 -460
- package/src/schema.test.ts +101 -101
- package/src/schema.ts +338 -338
- package/src/sdk.ts +120 -118
- package/src/task-ref.test.ts +401 -401
- package/src/task-ref.ts +120 -120
- package/src/validate-raw.ts +412 -412
- package/dist/drivers/claude-code.d.ts +0 -3
- package/dist/drivers/claude-code.d.ts.map +0 -1
- package/dist/drivers/claude-code.js +0 -225
- package/dist/drivers/claude-code.js.map +0 -1
package/src/task-ref.test.ts
CHANGED
|
@@ -1,401 +1,401 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
import type { PipelineConfig, RawPipelineConfig } from './types';
|
|
3
|
-
import {
|
|
4
|
-
TASK_ID_RE,
|
|
5
|
-
isValidTaskId,
|
|
6
|
-
qualifyTaskId,
|
|
7
|
-
isQualifiedRef,
|
|
8
|
-
buildTaskIndex,
|
|
9
|
-
resolveTaskRef,
|
|
10
|
-
AMBIGUOUS,
|
|
11
|
-
} from './task-ref';
|
|
12
|
-
import { buildDag, buildRawDag } from './dag';
|
|
13
|
-
import { validateRaw } from './validate-raw';
|
|
14
|
-
|
|
15
|
-
// ═══ Low-level helpers ═══
|
|
16
|
-
|
|
17
|
-
describe('isValidTaskId', () => {
|
|
18
|
-
test('accepts letter-led ids with letters, digits, underscores, hyphens', () => {
|
|
19
|
-
for (const id of ['a', 'A', '_', 'task_1', 'Task-2', '_private', 'a_b-c_1']) {
|
|
20
|
-
expect(isValidTaskId(id)).toBe(true);
|
|
21
|
-
expect(TASK_ID_RE.test(id)).toBe(true);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('rejects empty, digit-led, dot-bearing, and whitespace forms', () => {
|
|
26
|
-
for (const id of ['', '1task', 'a.b', 'foo bar', '-leading', 'has/slash', 'dot.']) {
|
|
27
|
-
expect(isValidTaskId(id)).toBe(false);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('rejects non-string values', () => {
|
|
32
|
-
expect(isValidTaskId(null as unknown as string)).toBe(false);
|
|
33
|
-
expect(isValidTaskId(undefined as unknown as string)).toBe(false);
|
|
34
|
-
expect(isValidTaskId(42 as unknown as string)).toBe(false);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe('qualifyTaskId + isQualifiedRef', () => {
|
|
39
|
-
test('qualifyTaskId joins with dot; isQualifiedRef detects dotted form', () => {
|
|
40
|
-
expect(qualifyTaskId('alpha', 'review')).toBe('alpha.review');
|
|
41
|
-
expect(isQualifiedRef('alpha.review')).toBe(true);
|
|
42
|
-
expect(isQualifiedRef('review')).toBe(false);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// ═══ Index build ═══
|
|
47
|
-
|
|
48
|
-
describe('buildTaskIndex', () => {
|
|
49
|
-
test('collects all qualified ids and unique bare ids', () => {
|
|
50
|
-
const cfg: RawPipelineConfig = {
|
|
51
|
-
name: 'T',
|
|
52
|
-
tracks: [
|
|
53
|
-
{ id: 'alpha', name: 'A', tasks: [{ id: 'plan', prompt: 'p' }] },
|
|
54
|
-
{ id: 'beta', name: 'B', tasks: [{ id: 'ship', prompt: 'p' }] },
|
|
55
|
-
],
|
|
56
|
-
};
|
|
57
|
-
const idx = buildTaskIndex(cfg);
|
|
58
|
-
expect(idx.allQualified.has('alpha.plan')).toBe(true);
|
|
59
|
-
expect(idx.allQualified.has('beta.ship')).toBe(true);
|
|
60
|
-
expect(idx.bareToQualified.get('plan')).toBe('alpha.plan');
|
|
61
|
-
expect(idx.bareToQualified.get('ship')).toBe('beta.ship');
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test('marks bare ids shared across tracks as ambiguous', () => {
|
|
65
|
-
const cfg: RawPipelineConfig = {
|
|
66
|
-
name: 'T',
|
|
67
|
-
tracks: [
|
|
68
|
-
{ id: 'alpha', name: 'A', tasks: [{ id: 'review', prompt: 'p' }] },
|
|
69
|
-
{ id: 'beta', name: 'B', tasks: [{ id: 'review', prompt: 'p' }] },
|
|
70
|
-
],
|
|
71
|
-
};
|
|
72
|
-
const idx = buildTaskIndex(cfg);
|
|
73
|
-
expect(idx.bareToQualified.get('review')).toBe(AMBIGUOUS);
|
|
74
|
-
expect(idx.allQualified.has('alpha.review')).toBe(true);
|
|
75
|
-
expect(idx.allQualified.has('beta.review')).toBe(true);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('tolerates tracks/tasks missing ids (editor in-progress state)', () => {
|
|
79
|
-
const cfg = {
|
|
80
|
-
name: 'T',
|
|
81
|
-
tracks: [
|
|
82
|
-
{ id: '', name: 'half-typed', tasks: [{ id: 'x', prompt: 'p' }] },
|
|
83
|
-
{ id: 'ok', name: 'OK', tasks: [{ id: '', prompt: 'p' }, { id: 'y', prompt: 'p' }] },
|
|
84
|
-
],
|
|
85
|
-
} as unknown as RawPipelineConfig;
|
|
86
|
-
const idx = buildTaskIndex(cfg);
|
|
87
|
-
expect(idx.allQualified.size).toBe(1);
|
|
88
|
-
expect(idx.allQualified.has('ok.y')).toBe(true);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// ═══ Ref resolution ═══
|
|
93
|
-
|
|
94
|
-
describe('resolveTaskRef', () => {
|
|
95
|
-
const cfg: RawPipelineConfig = {
|
|
96
|
-
name: 'T',
|
|
97
|
-
tracks: [
|
|
98
|
-
{
|
|
99
|
-
id: 'alpha',
|
|
100
|
-
name: 'A',
|
|
101
|
-
tasks: [
|
|
102
|
-
{ id: 'plan', prompt: 'p' },
|
|
103
|
-
{ id: 'review', prompt: 'p' },
|
|
104
|
-
],
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
id: 'beta',
|
|
108
|
-
name: 'B',
|
|
109
|
-
tasks: [
|
|
110
|
-
{ id: 'review', prompt: 'p' },
|
|
111
|
-
{ id: 'ship', prompt: 'p' },
|
|
112
|
-
],
|
|
113
|
-
},
|
|
114
|
-
],
|
|
115
|
-
};
|
|
116
|
-
const idx = buildTaskIndex(cfg);
|
|
117
|
-
|
|
118
|
-
test('fully qualified ref resolves when it exists', () => {
|
|
119
|
-
expect(resolveTaskRef('alpha.plan', 'beta', idx)).toEqual({
|
|
120
|
-
kind: 'resolved',
|
|
121
|
-
qid: 'alpha.plan',
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
test('fully qualified ref that does not exist is not_found', () => {
|
|
126
|
-
expect(resolveTaskRef('alpha.ghost', 'beta', idx)).toEqual({
|
|
127
|
-
kind: 'not_found',
|
|
128
|
-
ref: 'alpha.ghost',
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
test('bare ref prefers same-track shorthand', () => {
|
|
133
|
-
// "review" exists in both tracks — from beta's perspective, the same-
|
|
134
|
-
// track shadow must win over the cross-track ambiguous pool.
|
|
135
|
-
expect(resolveTaskRef('review', 'beta', idx)).toEqual({
|
|
136
|
-
kind: 'resolved',
|
|
137
|
-
qid: 'beta.review',
|
|
138
|
-
});
|
|
139
|
-
expect(resolveTaskRef('review', 'alpha', idx)).toEqual({
|
|
140
|
-
kind: 'resolved',
|
|
141
|
-
qid: 'alpha.review',
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
test('bare ref not in current track is ambiguous when multiple tracks have it', () => {
|
|
146
|
-
const twoForeign: RawPipelineConfig = {
|
|
147
|
-
name: 'T',
|
|
148
|
-
tracks: [
|
|
149
|
-
{ id: 'a', name: 'A', tasks: [{ id: 'review', prompt: 'p' }] },
|
|
150
|
-
{ id: 'b', name: 'B', tasks: [{ id: 'review', prompt: 'p' }] },
|
|
151
|
-
{ id: 'c', name: 'C', tasks: [{ id: 'other', prompt: 'p' }] },
|
|
152
|
-
],
|
|
153
|
-
};
|
|
154
|
-
const idx2 = buildTaskIndex(twoForeign);
|
|
155
|
-
expect(resolveTaskRef('review', 'c', idx2)).toEqual({ kind: 'ambiguous', ref: 'review' });
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
test('bare ref unique in the pool resolves cross-track', () => {
|
|
159
|
-
expect(resolveTaskRef('ship', 'alpha', idx)).toEqual({
|
|
160
|
-
kind: 'resolved',
|
|
161
|
-
qid: 'beta.ship',
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
test('bare ref nobody has is not_found', () => {
|
|
166
|
-
expect(resolveTaskRef('nowhere', 'alpha', idx)).toEqual({
|
|
167
|
-
kind: 'not_found',
|
|
168
|
-
ref: 'nowhere',
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
// ═══ Regression: bug #2 — same bare task id in multiple tracks ═══
|
|
174
|
-
|
|
175
|
-
describe('regression: continue_from across same-named tasks (bug #2)', () => {
|
|
176
|
-
test('bare continue_from resolves via same-track shadow — qualified id handed downstream', () => {
|
|
177
|
-
// Two tracks, each with a "review" task and a follower that continues
|
|
178
|
-
// from it. The follower MUST bind to its own track's review via the
|
|
179
|
-
// same-track shorthand, not to the other track's review.
|
|
180
|
-
const resolved: PipelineConfig = {
|
|
181
|
-
name: 'Same-Bare',
|
|
182
|
-
tracks: [
|
|
183
|
-
{
|
|
184
|
-
id: 'alpha',
|
|
185
|
-
name: 'Alpha',
|
|
186
|
-
tasks: [
|
|
187
|
-
{ id: 'review', name: 'Review', prompt: 'do A' },
|
|
188
|
-
{
|
|
189
|
-
id: 'ship',
|
|
190
|
-
name: 'Ship',
|
|
191
|
-
prompt: 'ship A',
|
|
192
|
-
depends_on: ['review'],
|
|
193
|
-
continue_from: 'review',
|
|
194
|
-
},
|
|
195
|
-
],
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
id: 'beta',
|
|
199
|
-
name: 'Beta',
|
|
200
|
-
tasks: [
|
|
201
|
-
{ id: 'review', name: 'Review', prompt: 'do B' },
|
|
202
|
-
{
|
|
203
|
-
id: 'ship',
|
|
204
|
-
name: 'Ship',
|
|
205
|
-
prompt: 'ship B',
|
|
206
|
-
depends_on: ['review'],
|
|
207
|
-
continue_from: 'review',
|
|
208
|
-
},
|
|
209
|
-
],
|
|
210
|
-
},
|
|
211
|
-
],
|
|
212
|
-
};
|
|
213
|
-
const dag = buildDag(resolved);
|
|
214
|
-
const alphaShip = dag.nodes.get('alpha.ship')!;
|
|
215
|
-
const betaShip = dag.nodes.get('beta.ship')!;
|
|
216
|
-
expect(alphaShip.resolvedContinueFrom).toBe('alpha.review');
|
|
217
|
-
expect(betaShip.resolvedContinueFrom).toBe('beta.review');
|
|
218
|
-
// And the dep edges get qualified too, preventing engine map-key misses.
|
|
219
|
-
expect(alphaShip.dependsOn).toContain('alpha.review');
|
|
220
|
-
expect(betaShip.dependsOn).toContain('beta.review');
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
test('bare continue_from pointing at a foreign ambiguous task throws', () => {
|
|
224
|
-
const resolved: PipelineConfig = {
|
|
225
|
-
name: 'Ambiguous',
|
|
226
|
-
tracks: [
|
|
227
|
-
{
|
|
228
|
-
id: 'alpha',
|
|
229
|
-
name: 'Alpha',
|
|
230
|
-
tasks: [
|
|
231
|
-
{ id: 'review', name: 'Review', prompt: 'p' },
|
|
232
|
-
// ship has no local "review" so bare "review" is ambiguous.
|
|
233
|
-
{ id: 'filler', name: 'Filler', prompt: 'p' },
|
|
234
|
-
],
|
|
235
|
-
},
|
|
236
|
-
{
|
|
237
|
-
id: 'beta',
|
|
238
|
-
name: 'Beta',
|
|
239
|
-
tasks: [{ id: 'review', name: 'Review', prompt: 'p' }],
|
|
240
|
-
},
|
|
241
|
-
{
|
|
242
|
-
id: 'gamma',
|
|
243
|
-
name: 'Gamma',
|
|
244
|
-
tasks: [
|
|
245
|
-
{
|
|
246
|
-
id: 'ship',
|
|
247
|
-
name: 'Ship',
|
|
248
|
-
prompt: 'ship',
|
|
249
|
-
continue_from: 'review',
|
|
250
|
-
},
|
|
251
|
-
],
|
|
252
|
-
},
|
|
253
|
-
],
|
|
254
|
-
};
|
|
255
|
-
expect(() => buildDag(resolved)).toThrow(/ambiguous/i);
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
test('qualified continue_from always wins — no same-track-shadow risk', () => {
|
|
259
|
-
const resolved: PipelineConfig = {
|
|
260
|
-
name: 'Qualified',
|
|
261
|
-
tracks: [
|
|
262
|
-
{
|
|
263
|
-
id: 'alpha',
|
|
264
|
-
name: 'Alpha',
|
|
265
|
-
tasks: [
|
|
266
|
-
{ id: 'plan', name: 'Plan', prompt: 'p' },
|
|
267
|
-
{
|
|
268
|
-
id: 'plan_v2',
|
|
269
|
-
name: 'Plan v2',
|
|
270
|
-
prompt: 'p2',
|
|
271
|
-
continue_from: 'plan',
|
|
272
|
-
},
|
|
273
|
-
],
|
|
274
|
-
},
|
|
275
|
-
{
|
|
276
|
-
id: 'beta',
|
|
277
|
-
name: 'Beta',
|
|
278
|
-
tasks: [
|
|
279
|
-
{ id: 'plan', name: 'Plan B', prompt: 'p' },
|
|
280
|
-
{
|
|
281
|
-
id: 'cross',
|
|
282
|
-
name: 'Cross',
|
|
283
|
-
prompt: 'x',
|
|
284
|
-
continue_from: 'alpha.plan',
|
|
285
|
-
},
|
|
286
|
-
],
|
|
287
|
-
},
|
|
288
|
-
],
|
|
289
|
-
};
|
|
290
|
-
const dag = buildDag(resolved);
|
|
291
|
-
expect(dag.nodes.get('alpha.plan_v2')!.resolvedContinueFrom).toBe('alpha.plan');
|
|
292
|
-
expect(dag.nodes.get('beta.cross')!.resolvedContinueFrom).toBe('alpha.plan');
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
// ═══ Regression: bug #10 — editor-generated ids always pass validate-raw ═══
|
|
297
|
-
|
|
298
|
-
describe('regression: TASK_ID_RE is the single source of truth (bug #10)', () => {
|
|
299
|
-
test('validateRaw rejects exactly what isValidTaskId rejects', () => {
|
|
300
|
-
// Any string the helper says is invalid must be flagged by validateRaw
|
|
301
|
-
// as an "invalid characters" error — proving they read from the same
|
|
302
|
-
// regex rather than two drifted copies.
|
|
303
|
-
const invalids = ['1bad', 'has.dot', 'with space', '-leading', 'q?mark', ''];
|
|
304
|
-
for (const badId of invalids) {
|
|
305
|
-
const cfg: RawPipelineConfig = {
|
|
306
|
-
name: 'T',
|
|
307
|
-
tracks: [
|
|
308
|
-
{
|
|
309
|
-
id: 'ok',
|
|
310
|
-
name: 'OK',
|
|
311
|
-
tasks: [{ id: badId, prompt: 'p' }],
|
|
312
|
-
},
|
|
313
|
-
],
|
|
314
|
-
};
|
|
315
|
-
const errs = validateRaw(cfg);
|
|
316
|
-
expect(errs.length).toBeGreaterThan(0);
|
|
317
|
-
expect(isValidTaskId(badId)).toBe(false);
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
// ═══ Regression: buildDag topo sort is deterministic (bug #13) ═══
|
|
323
|
-
|
|
324
|
-
describe('regression: buildDag topo sort is deterministic', () => {
|
|
325
|
-
const base = (trackOrder: readonly string[]): PipelineConfig => ({
|
|
326
|
-
name: 'Determinism',
|
|
327
|
-
tracks: trackOrder.map((id) => ({
|
|
328
|
-
id,
|
|
329
|
-
name: id,
|
|
330
|
-
tasks: [
|
|
331
|
-
{ id: 'a', name: 'A', prompt: 'p' },
|
|
332
|
-
{ id: 'b', name: 'B', prompt: 'p', depends_on: ['a'] },
|
|
333
|
-
],
|
|
334
|
-
})),
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
test('parallel tasks with equal depth sort by qid, independent of YAML order', () => {
|
|
338
|
-
const forward = buildDag(base(['alpha', 'beta', 'gamma']));
|
|
339
|
-
const reversed = buildDag(base(['gamma', 'beta', 'alpha']));
|
|
340
|
-
expect(forward.sorted).toEqual(reversed.sorted);
|
|
341
|
-
// And the actual order is alphabetical by qid — every "a" before every "b".
|
|
342
|
-
expect(forward.sorted).toEqual([
|
|
343
|
-
'alpha.a',
|
|
344
|
-
'beta.a',
|
|
345
|
-
'gamma.a',
|
|
346
|
-
'alpha.b',
|
|
347
|
-
'beta.b',
|
|
348
|
-
'gamma.b',
|
|
349
|
-
]);
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
test('diamond dependency still produces a unique sorted order', () => {
|
|
353
|
-
// root -> left, right -> join
|
|
354
|
-
const cfg: PipelineConfig = {
|
|
355
|
-
name: 'Diamond',
|
|
356
|
-
tracks: [
|
|
357
|
-
{
|
|
358
|
-
id: 't',
|
|
359
|
-
name: 't',
|
|
360
|
-
tasks: [
|
|
361
|
-
{ id: 'root', name: 'r', prompt: 'p' },
|
|
362
|
-
{ id: 'left', name: 'l', prompt: 'p', depends_on: ['root'] },
|
|
363
|
-
{ id: 'right', name: 'r', prompt: 'p', depends_on: ['root'] },
|
|
364
|
-
{ id: 'join', name: 'j', prompt: 'p', depends_on: ['left', 'right'] },
|
|
365
|
-
],
|
|
366
|
-
},
|
|
367
|
-
],
|
|
368
|
-
};
|
|
369
|
-
const first = buildDag(cfg).sorted;
|
|
370
|
-
const second = buildDag(cfg).sorted;
|
|
371
|
-
expect(first).toEqual(second);
|
|
372
|
-
// root first, join last; left/right in alphabetical order between.
|
|
373
|
-
expect(first[0]).toBe('t.root');
|
|
374
|
-
expect(first[first.length - 1]).toBe('t.join');
|
|
375
|
-
expect(first.indexOf('t.left')).toBeLessThan(first.indexOf('t.right'));
|
|
376
|
-
});
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
// ═══ Regression: buildRawDag stays lenient (editor real-time view) ═══
|
|
380
|
-
|
|
381
|
-
describe('buildRawDag tolerates unresolved refs', () => {
|
|
382
|
-
test('ambiguous bare continue_from is silently skipped (no edge, no throw)', () => {
|
|
383
|
-
const cfg: RawPipelineConfig = {
|
|
384
|
-
name: 'T',
|
|
385
|
-
tracks: [
|
|
386
|
-
{ id: 'a', name: 'A', tasks: [{ id: 'review', prompt: 'p' }] },
|
|
387
|
-
{ id: 'b', name: 'B', tasks: [{ id: 'review', prompt: 'p' }] },
|
|
388
|
-
{
|
|
389
|
-
id: 'c',
|
|
390
|
-
name: 'C',
|
|
391
|
-
tasks: [{ id: 'use', prompt: 'p', continue_from: 'review' }],
|
|
392
|
-
},
|
|
393
|
-
],
|
|
394
|
-
};
|
|
395
|
-
const raw = buildRawDag(cfg);
|
|
396
|
-
expect(raw.nodes.size).toBe(3);
|
|
397
|
-
// No edge for the ambiguous ref — the editor panel should prompt the
|
|
398
|
-
// user to qualify it instead of silently linking to the wrong track.
|
|
399
|
-
expect(raw.edges.find((e) => e.to === 'c.use')).toBeUndefined();
|
|
400
|
-
});
|
|
401
|
-
});
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import type { PipelineConfig, RawPipelineConfig } from './types';
|
|
3
|
+
import {
|
|
4
|
+
TASK_ID_RE,
|
|
5
|
+
isValidTaskId,
|
|
6
|
+
qualifyTaskId,
|
|
7
|
+
isQualifiedRef,
|
|
8
|
+
buildTaskIndex,
|
|
9
|
+
resolveTaskRef,
|
|
10
|
+
AMBIGUOUS,
|
|
11
|
+
} from './task-ref';
|
|
12
|
+
import { buildDag, buildRawDag } from './dag';
|
|
13
|
+
import { validateRaw } from './validate-raw';
|
|
14
|
+
|
|
15
|
+
// ═══ Low-level helpers ═══
|
|
16
|
+
|
|
17
|
+
describe('isValidTaskId', () => {
|
|
18
|
+
test('accepts letter-led ids with letters, digits, underscores, hyphens', () => {
|
|
19
|
+
for (const id of ['a', 'A', '_', 'task_1', 'Task-2', '_private', 'a_b-c_1']) {
|
|
20
|
+
expect(isValidTaskId(id)).toBe(true);
|
|
21
|
+
expect(TASK_ID_RE.test(id)).toBe(true);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('rejects empty, digit-led, dot-bearing, and whitespace forms', () => {
|
|
26
|
+
for (const id of ['', '1task', 'a.b', 'foo bar', '-leading', 'has/slash', 'dot.']) {
|
|
27
|
+
expect(isValidTaskId(id)).toBe(false);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('rejects non-string values', () => {
|
|
32
|
+
expect(isValidTaskId(null as unknown as string)).toBe(false);
|
|
33
|
+
expect(isValidTaskId(undefined as unknown as string)).toBe(false);
|
|
34
|
+
expect(isValidTaskId(42 as unknown as string)).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('qualifyTaskId + isQualifiedRef', () => {
|
|
39
|
+
test('qualifyTaskId joins with dot; isQualifiedRef detects dotted form', () => {
|
|
40
|
+
expect(qualifyTaskId('alpha', 'review')).toBe('alpha.review');
|
|
41
|
+
expect(isQualifiedRef('alpha.review')).toBe(true);
|
|
42
|
+
expect(isQualifiedRef('review')).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// ═══ Index build ═══
|
|
47
|
+
|
|
48
|
+
describe('buildTaskIndex', () => {
|
|
49
|
+
test('collects all qualified ids and unique bare ids', () => {
|
|
50
|
+
const cfg: RawPipelineConfig = {
|
|
51
|
+
name: 'T',
|
|
52
|
+
tracks: [
|
|
53
|
+
{ id: 'alpha', name: 'A', tasks: [{ id: 'plan', prompt: 'p' }] },
|
|
54
|
+
{ id: 'beta', name: 'B', tasks: [{ id: 'ship', prompt: 'p' }] },
|
|
55
|
+
],
|
|
56
|
+
};
|
|
57
|
+
const idx = buildTaskIndex(cfg);
|
|
58
|
+
expect(idx.allQualified.has('alpha.plan')).toBe(true);
|
|
59
|
+
expect(idx.allQualified.has('beta.ship')).toBe(true);
|
|
60
|
+
expect(idx.bareToQualified.get('plan')).toBe('alpha.plan');
|
|
61
|
+
expect(idx.bareToQualified.get('ship')).toBe('beta.ship');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('marks bare ids shared across tracks as ambiguous', () => {
|
|
65
|
+
const cfg: RawPipelineConfig = {
|
|
66
|
+
name: 'T',
|
|
67
|
+
tracks: [
|
|
68
|
+
{ id: 'alpha', name: 'A', tasks: [{ id: 'review', prompt: 'p' }] },
|
|
69
|
+
{ id: 'beta', name: 'B', tasks: [{ id: 'review', prompt: 'p' }] },
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
const idx = buildTaskIndex(cfg);
|
|
73
|
+
expect(idx.bareToQualified.get('review')).toBe(AMBIGUOUS);
|
|
74
|
+
expect(idx.allQualified.has('alpha.review')).toBe(true);
|
|
75
|
+
expect(idx.allQualified.has('beta.review')).toBe(true);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('tolerates tracks/tasks missing ids (editor in-progress state)', () => {
|
|
79
|
+
const cfg = {
|
|
80
|
+
name: 'T',
|
|
81
|
+
tracks: [
|
|
82
|
+
{ id: '', name: 'half-typed', tasks: [{ id: 'x', prompt: 'p' }] },
|
|
83
|
+
{ id: 'ok', name: 'OK', tasks: [{ id: '', prompt: 'p' }, { id: 'y', prompt: 'p' }] },
|
|
84
|
+
],
|
|
85
|
+
} as unknown as RawPipelineConfig;
|
|
86
|
+
const idx = buildTaskIndex(cfg);
|
|
87
|
+
expect(idx.allQualified.size).toBe(1);
|
|
88
|
+
expect(idx.allQualified.has('ok.y')).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// ═══ Ref resolution ═══
|
|
93
|
+
|
|
94
|
+
describe('resolveTaskRef', () => {
|
|
95
|
+
const cfg: RawPipelineConfig = {
|
|
96
|
+
name: 'T',
|
|
97
|
+
tracks: [
|
|
98
|
+
{
|
|
99
|
+
id: 'alpha',
|
|
100
|
+
name: 'A',
|
|
101
|
+
tasks: [
|
|
102
|
+
{ id: 'plan', prompt: 'p' },
|
|
103
|
+
{ id: 'review', prompt: 'p' },
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: 'beta',
|
|
108
|
+
name: 'B',
|
|
109
|
+
tasks: [
|
|
110
|
+
{ id: 'review', prompt: 'p' },
|
|
111
|
+
{ id: 'ship', prompt: 'p' },
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
};
|
|
116
|
+
const idx = buildTaskIndex(cfg);
|
|
117
|
+
|
|
118
|
+
test('fully qualified ref resolves when it exists', () => {
|
|
119
|
+
expect(resolveTaskRef('alpha.plan', 'beta', idx)).toEqual({
|
|
120
|
+
kind: 'resolved',
|
|
121
|
+
qid: 'alpha.plan',
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('fully qualified ref that does not exist is not_found', () => {
|
|
126
|
+
expect(resolveTaskRef('alpha.ghost', 'beta', idx)).toEqual({
|
|
127
|
+
kind: 'not_found',
|
|
128
|
+
ref: 'alpha.ghost',
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('bare ref prefers same-track shorthand', () => {
|
|
133
|
+
// "review" exists in both tracks — from beta's perspective, the same-
|
|
134
|
+
// track shadow must win over the cross-track ambiguous pool.
|
|
135
|
+
expect(resolveTaskRef('review', 'beta', idx)).toEqual({
|
|
136
|
+
kind: 'resolved',
|
|
137
|
+
qid: 'beta.review',
|
|
138
|
+
});
|
|
139
|
+
expect(resolveTaskRef('review', 'alpha', idx)).toEqual({
|
|
140
|
+
kind: 'resolved',
|
|
141
|
+
qid: 'alpha.review',
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('bare ref not in current track is ambiguous when multiple tracks have it', () => {
|
|
146
|
+
const twoForeign: RawPipelineConfig = {
|
|
147
|
+
name: 'T',
|
|
148
|
+
tracks: [
|
|
149
|
+
{ id: 'a', name: 'A', tasks: [{ id: 'review', prompt: 'p' }] },
|
|
150
|
+
{ id: 'b', name: 'B', tasks: [{ id: 'review', prompt: 'p' }] },
|
|
151
|
+
{ id: 'c', name: 'C', tasks: [{ id: 'other', prompt: 'p' }] },
|
|
152
|
+
],
|
|
153
|
+
};
|
|
154
|
+
const idx2 = buildTaskIndex(twoForeign);
|
|
155
|
+
expect(resolveTaskRef('review', 'c', idx2)).toEqual({ kind: 'ambiguous', ref: 'review' });
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test('bare ref unique in the pool resolves cross-track', () => {
|
|
159
|
+
expect(resolveTaskRef('ship', 'alpha', idx)).toEqual({
|
|
160
|
+
kind: 'resolved',
|
|
161
|
+
qid: 'beta.ship',
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test('bare ref nobody has is not_found', () => {
|
|
166
|
+
expect(resolveTaskRef('nowhere', 'alpha', idx)).toEqual({
|
|
167
|
+
kind: 'not_found',
|
|
168
|
+
ref: 'nowhere',
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// ═══ Regression: bug #2 — same bare task id in multiple tracks ═══
|
|
174
|
+
|
|
175
|
+
describe('regression: continue_from across same-named tasks (bug #2)', () => {
|
|
176
|
+
test('bare continue_from resolves via same-track shadow — qualified id handed downstream', () => {
|
|
177
|
+
// Two tracks, each with a "review" task and a follower that continues
|
|
178
|
+
// from it. The follower MUST bind to its own track's review via the
|
|
179
|
+
// same-track shorthand, not to the other track's review.
|
|
180
|
+
const resolved: PipelineConfig = {
|
|
181
|
+
name: 'Same-Bare',
|
|
182
|
+
tracks: [
|
|
183
|
+
{
|
|
184
|
+
id: 'alpha',
|
|
185
|
+
name: 'Alpha',
|
|
186
|
+
tasks: [
|
|
187
|
+
{ id: 'review', name: 'Review', prompt: 'do A' },
|
|
188
|
+
{
|
|
189
|
+
id: 'ship',
|
|
190
|
+
name: 'Ship',
|
|
191
|
+
prompt: 'ship A',
|
|
192
|
+
depends_on: ['review'],
|
|
193
|
+
continue_from: 'review',
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
id: 'beta',
|
|
199
|
+
name: 'Beta',
|
|
200
|
+
tasks: [
|
|
201
|
+
{ id: 'review', name: 'Review', prompt: 'do B' },
|
|
202
|
+
{
|
|
203
|
+
id: 'ship',
|
|
204
|
+
name: 'Ship',
|
|
205
|
+
prompt: 'ship B',
|
|
206
|
+
depends_on: ['review'],
|
|
207
|
+
continue_from: 'review',
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
};
|
|
213
|
+
const dag = buildDag(resolved);
|
|
214
|
+
const alphaShip = dag.nodes.get('alpha.ship')!;
|
|
215
|
+
const betaShip = dag.nodes.get('beta.ship')!;
|
|
216
|
+
expect(alphaShip.resolvedContinueFrom).toBe('alpha.review');
|
|
217
|
+
expect(betaShip.resolvedContinueFrom).toBe('beta.review');
|
|
218
|
+
// And the dep edges get qualified too, preventing engine map-key misses.
|
|
219
|
+
expect(alphaShip.dependsOn).toContain('alpha.review');
|
|
220
|
+
expect(betaShip.dependsOn).toContain('beta.review');
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test('bare continue_from pointing at a foreign ambiguous task throws', () => {
|
|
224
|
+
const resolved: PipelineConfig = {
|
|
225
|
+
name: 'Ambiguous',
|
|
226
|
+
tracks: [
|
|
227
|
+
{
|
|
228
|
+
id: 'alpha',
|
|
229
|
+
name: 'Alpha',
|
|
230
|
+
tasks: [
|
|
231
|
+
{ id: 'review', name: 'Review', prompt: 'p' },
|
|
232
|
+
// ship has no local "review" so bare "review" is ambiguous.
|
|
233
|
+
{ id: 'filler', name: 'Filler', prompt: 'p' },
|
|
234
|
+
],
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
id: 'beta',
|
|
238
|
+
name: 'Beta',
|
|
239
|
+
tasks: [{ id: 'review', name: 'Review', prompt: 'p' }],
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
id: 'gamma',
|
|
243
|
+
name: 'Gamma',
|
|
244
|
+
tasks: [
|
|
245
|
+
{
|
|
246
|
+
id: 'ship',
|
|
247
|
+
name: 'Ship',
|
|
248
|
+
prompt: 'ship',
|
|
249
|
+
continue_from: 'review',
|
|
250
|
+
},
|
|
251
|
+
],
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
};
|
|
255
|
+
expect(() => buildDag(resolved)).toThrow(/ambiguous/i);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test('qualified continue_from always wins — no same-track-shadow risk', () => {
|
|
259
|
+
const resolved: PipelineConfig = {
|
|
260
|
+
name: 'Qualified',
|
|
261
|
+
tracks: [
|
|
262
|
+
{
|
|
263
|
+
id: 'alpha',
|
|
264
|
+
name: 'Alpha',
|
|
265
|
+
tasks: [
|
|
266
|
+
{ id: 'plan', name: 'Plan', prompt: 'p' },
|
|
267
|
+
{
|
|
268
|
+
id: 'plan_v2',
|
|
269
|
+
name: 'Plan v2',
|
|
270
|
+
prompt: 'p2',
|
|
271
|
+
continue_from: 'plan',
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
id: 'beta',
|
|
277
|
+
name: 'Beta',
|
|
278
|
+
tasks: [
|
|
279
|
+
{ id: 'plan', name: 'Plan B', prompt: 'p' },
|
|
280
|
+
{
|
|
281
|
+
id: 'cross',
|
|
282
|
+
name: 'Cross',
|
|
283
|
+
prompt: 'x',
|
|
284
|
+
continue_from: 'alpha.plan',
|
|
285
|
+
},
|
|
286
|
+
],
|
|
287
|
+
},
|
|
288
|
+
],
|
|
289
|
+
};
|
|
290
|
+
const dag = buildDag(resolved);
|
|
291
|
+
expect(dag.nodes.get('alpha.plan_v2')!.resolvedContinueFrom).toBe('alpha.plan');
|
|
292
|
+
expect(dag.nodes.get('beta.cross')!.resolvedContinueFrom).toBe('alpha.plan');
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
// ═══ Regression: bug #10 — editor-generated ids always pass validate-raw ═══
|
|
297
|
+
|
|
298
|
+
describe('regression: TASK_ID_RE is the single source of truth (bug #10)', () => {
|
|
299
|
+
test('validateRaw rejects exactly what isValidTaskId rejects', () => {
|
|
300
|
+
// Any string the helper says is invalid must be flagged by validateRaw
|
|
301
|
+
// as an "invalid characters" error — proving they read from the same
|
|
302
|
+
// regex rather than two drifted copies.
|
|
303
|
+
const invalids = ['1bad', 'has.dot', 'with space', '-leading', 'q?mark', ''];
|
|
304
|
+
for (const badId of invalids) {
|
|
305
|
+
const cfg: RawPipelineConfig = {
|
|
306
|
+
name: 'T',
|
|
307
|
+
tracks: [
|
|
308
|
+
{
|
|
309
|
+
id: 'ok',
|
|
310
|
+
name: 'OK',
|
|
311
|
+
tasks: [{ id: badId, prompt: 'p' }],
|
|
312
|
+
},
|
|
313
|
+
],
|
|
314
|
+
};
|
|
315
|
+
const errs = validateRaw(cfg);
|
|
316
|
+
expect(errs.length).toBeGreaterThan(0);
|
|
317
|
+
expect(isValidTaskId(badId)).toBe(false);
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
// ═══ Regression: buildDag topo sort is deterministic (bug #13) ═══
|
|
323
|
+
|
|
324
|
+
describe('regression: buildDag topo sort is deterministic', () => {
|
|
325
|
+
const base = (trackOrder: readonly string[]): PipelineConfig => ({
|
|
326
|
+
name: 'Determinism',
|
|
327
|
+
tracks: trackOrder.map((id) => ({
|
|
328
|
+
id,
|
|
329
|
+
name: id,
|
|
330
|
+
tasks: [
|
|
331
|
+
{ id: 'a', name: 'A', prompt: 'p' },
|
|
332
|
+
{ id: 'b', name: 'B', prompt: 'p', depends_on: ['a'] },
|
|
333
|
+
],
|
|
334
|
+
})),
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
test('parallel tasks with equal depth sort by qid, independent of YAML order', () => {
|
|
338
|
+
const forward = buildDag(base(['alpha', 'beta', 'gamma']));
|
|
339
|
+
const reversed = buildDag(base(['gamma', 'beta', 'alpha']));
|
|
340
|
+
expect(forward.sorted).toEqual(reversed.sorted);
|
|
341
|
+
// And the actual order is alphabetical by qid — every "a" before every "b".
|
|
342
|
+
expect(forward.sorted).toEqual([
|
|
343
|
+
'alpha.a',
|
|
344
|
+
'beta.a',
|
|
345
|
+
'gamma.a',
|
|
346
|
+
'alpha.b',
|
|
347
|
+
'beta.b',
|
|
348
|
+
'gamma.b',
|
|
349
|
+
]);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
test('diamond dependency still produces a unique sorted order', () => {
|
|
353
|
+
// root -> left, right -> join
|
|
354
|
+
const cfg: PipelineConfig = {
|
|
355
|
+
name: 'Diamond',
|
|
356
|
+
tracks: [
|
|
357
|
+
{
|
|
358
|
+
id: 't',
|
|
359
|
+
name: 't',
|
|
360
|
+
tasks: [
|
|
361
|
+
{ id: 'root', name: 'r', prompt: 'p' },
|
|
362
|
+
{ id: 'left', name: 'l', prompt: 'p', depends_on: ['root'] },
|
|
363
|
+
{ id: 'right', name: 'r', prompt: 'p', depends_on: ['root'] },
|
|
364
|
+
{ id: 'join', name: 'j', prompt: 'p', depends_on: ['left', 'right'] },
|
|
365
|
+
],
|
|
366
|
+
},
|
|
367
|
+
],
|
|
368
|
+
};
|
|
369
|
+
const first = buildDag(cfg).sorted;
|
|
370
|
+
const second = buildDag(cfg).sorted;
|
|
371
|
+
expect(first).toEqual(second);
|
|
372
|
+
// root first, join last; left/right in alphabetical order between.
|
|
373
|
+
expect(first[0]).toBe('t.root');
|
|
374
|
+
expect(first[first.length - 1]).toBe('t.join');
|
|
375
|
+
expect(first.indexOf('t.left')).toBeLessThan(first.indexOf('t.right'));
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
// ═══ Regression: buildRawDag stays lenient (editor real-time view) ═══
|
|
380
|
+
|
|
381
|
+
describe('buildRawDag tolerates unresolved refs', () => {
|
|
382
|
+
test('ambiguous bare continue_from is silently skipped (no edge, no throw)', () => {
|
|
383
|
+
const cfg: RawPipelineConfig = {
|
|
384
|
+
name: 'T',
|
|
385
|
+
tracks: [
|
|
386
|
+
{ id: 'a', name: 'A', tasks: [{ id: 'review', prompt: 'p' }] },
|
|
387
|
+
{ id: 'b', name: 'B', tasks: [{ id: 'review', prompt: 'p' }] },
|
|
388
|
+
{
|
|
389
|
+
id: 'c',
|
|
390
|
+
name: 'C',
|
|
391
|
+
tasks: [{ id: 'use', prompt: 'p', continue_from: 'review' }],
|
|
392
|
+
},
|
|
393
|
+
],
|
|
394
|
+
};
|
|
395
|
+
const raw = buildRawDag(cfg);
|
|
396
|
+
expect(raw.nodes.size).toBe(3);
|
|
397
|
+
// No edge for the ambiguous ref — the editor panel should prompt the
|
|
398
|
+
// user to qualify it instead of silently linking to the wrong track.
|
|
399
|
+
expect(raw.edges.find((e) => e.to === 'c.use')).toBeUndefined();
|
|
400
|
+
});
|
|
401
|
+
});
|