@tagma/sdk 0.7.4 → 0.7.6

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.
Files changed (191) hide show
  1. package/README.md +60 -53
  2. package/dist/completions/file-exists.js +1 -1
  3. package/dist/completions/file-exists.js.map +1 -1
  4. package/dist/completions/output-check.d.ts.map +1 -1
  5. package/dist/completions/output-check.js +17 -4
  6. package/dist/completions/output-check.js.map +1 -1
  7. package/dist/config.d.ts +4 -4
  8. package/dist/config.d.ts.map +1 -1
  9. package/dist/config.js +2 -2
  10. package/dist/config.js.map +1 -1
  11. package/dist/dataflow.d.ts +3 -0
  12. package/dist/dataflow.d.ts.map +1 -0
  13. package/dist/dataflow.js +2 -0
  14. package/dist/dataflow.js.map +1 -0
  15. package/dist/drivers/opencode.d.ts.map +1 -1
  16. package/dist/drivers/opencode.js +23 -71
  17. package/dist/drivers/opencode.js.map +1 -1
  18. package/dist/middlewares/static-context.d.ts.map +1 -1
  19. package/dist/middlewares/static-context.js +1 -2
  20. package/dist/middlewares/static-context.js.map +1 -1
  21. package/dist/pipeline-runner.d.ts.map +1 -1
  22. package/dist/pipeline-runner.js +2 -2
  23. package/dist/pipeline-runner.js.map +1 -1
  24. package/dist/schema.d.ts.map +1 -1
  25. package/dist/schema.js +3 -4
  26. package/dist/schema.js.map +1 -1
  27. package/dist/triggers/file.d.ts.map +1 -1
  28. package/dist/triggers/file.js +1 -2
  29. package/dist/triggers/file.js.map +1 -1
  30. package/dist/triggers/manual.d.ts.map +1 -1
  31. package/dist/triggers/manual.js +1 -2
  32. package/dist/triggers/manual.js.map +1 -1
  33. package/dist/types.d.ts +1 -2
  34. package/dist/types.d.ts.map +1 -1
  35. package/dist/types.js +1 -12
  36. package/dist/types.js.map +1 -1
  37. package/dist/utils-api.d.ts +1 -1
  38. package/dist/utils-api.d.ts.map +1 -1
  39. package/dist/utils-api.js +1 -1
  40. package/dist/utils-api.js.map +1 -1
  41. package/dist/validate-raw.d.ts +4 -4
  42. package/dist/validate-raw.d.ts.map +1 -1
  43. package/dist/validate-raw.js +45 -52
  44. package/dist/validate-raw.js.map +1 -1
  45. package/package.json +11 -24
  46. package/dist/adapters/stdin-approval.d.ts +0 -2
  47. package/dist/adapters/stdin-approval.d.ts.map +0 -1
  48. package/dist/adapters/stdin-approval.js +0 -2
  49. package/dist/adapters/stdin-approval.js.map +0 -1
  50. package/dist/adapters/websocket-approval.d.ts +0 -2
  51. package/dist/adapters/websocket-approval.d.ts.map +0 -1
  52. package/dist/adapters/websocket-approval.js +0 -2
  53. package/dist/adapters/websocket-approval.js.map +0 -1
  54. package/dist/core/dataflow.d.ts +0 -23
  55. package/dist/core/dataflow.d.ts.map +0 -1
  56. package/dist/core/dataflow.js +0 -99
  57. package/dist/core/dataflow.js.map +0 -1
  58. package/dist/core/log-prune.d.ts +0 -16
  59. package/dist/core/log-prune.d.ts.map +0 -1
  60. package/dist/core/log-prune.js +0 -34
  61. package/dist/core/log-prune.js.map +0 -1
  62. package/dist/core/preflight.d.ts +0 -13
  63. package/dist/core/preflight.d.ts.map +0 -1
  64. package/dist/core/preflight.js +0 -61
  65. package/dist/core/preflight.js.map +0 -1
  66. package/dist/core/run-context.d.ts +0 -55
  67. package/dist/core/run-context.d.ts.map +0 -1
  68. package/dist/core/run-context.js +0 -158
  69. package/dist/core/run-context.js.map +0 -1
  70. package/dist/core/run-state.d.ts +0 -25
  71. package/dist/core/run-state.d.ts.map +0 -1
  72. package/dist/core/run-state.js +0 -93
  73. package/dist/core/run-state.js.map +0 -1
  74. package/dist/core/scheduler.d.ts +0 -13
  75. package/dist/core/scheduler.d.ts.map +0 -1
  76. package/dist/core/scheduler.js +0 -35
  77. package/dist/core/scheduler.js.map +0 -1
  78. package/dist/core/task-executor.d.ts +0 -13
  79. package/dist/core/task-executor.d.ts.map +0 -1
  80. package/dist/core/task-executor.js +0 -610
  81. package/dist/core/task-executor.js.map +0 -1
  82. package/dist/core/trigger-errors.d.ts +0 -9
  83. package/dist/core/trigger-errors.d.ts.map +0 -1
  84. package/dist/core/trigger-errors.js +0 -15
  85. package/dist/core/trigger-errors.js.map +0 -1
  86. package/dist/dag.d.ts +0 -45
  87. package/dist/dag.d.ts.map +0 -1
  88. package/dist/dag.js +0 -177
  89. package/dist/dag.js.map +0 -1
  90. package/dist/hooks.d.ts +0 -73
  91. package/dist/hooks.d.ts.map +0 -1
  92. package/dist/hooks.js +0 -106
  93. package/dist/hooks.js.map +0 -1
  94. package/dist/pipeline-definition.d.ts +0 -3
  95. package/dist/pipeline-definition.d.ts.map +0 -1
  96. package/dist/pipeline-definition.js +0 -4
  97. package/dist/pipeline-definition.js.map +0 -1
  98. package/dist/ports.d.ts +0 -196
  99. package/dist/ports.d.ts.map +0 -1
  100. package/dist/ports.js +0 -688
  101. package/dist/ports.js.map +0 -1
  102. package/dist/prompt-doc.d.ts +0 -70
  103. package/dist/prompt-doc.d.ts.map +0 -1
  104. package/dist/prompt-doc.js +0 -154
  105. package/dist/prompt-doc.js.map +0 -1
  106. package/dist/registry.d.ts +0 -3
  107. package/dist/registry.d.ts.map +0 -1
  108. package/dist/registry.js +0 -2
  109. package/dist/registry.js.map +0 -1
  110. package/dist/task-ref.d.ts +0 -55
  111. package/dist/task-ref.d.ts.map +0 -1
  112. package/dist/task-ref.js +0 -103
  113. package/dist/task-ref.js.map +0 -1
  114. package/dist/utils.d.ts +0 -13
  115. package/dist/utils.d.ts.map +0 -1
  116. package/dist/utils.js +0 -177
  117. package/dist/utils.js.map +0 -1
  118. package/src/adapters/stdin-approval.ts +0 -1
  119. package/src/adapters/websocket-approval.ts +0 -1
  120. package/src/approval.ts +0 -9
  121. package/src/bootstrap.ts +0 -55
  122. package/src/completions/exit-code.ts +0 -34
  123. package/src/completions/file-exists.ts +0 -66
  124. package/src/completions/output-check.test.ts +0 -50
  125. package/src/completions/output-check.ts +0 -92
  126. package/src/config-ops.test.ts +0 -70
  127. package/src/config-ops.ts +0 -328
  128. package/src/config.ts +0 -26
  129. package/src/core/dataflow.test.ts +0 -166
  130. package/src/core/dataflow.ts +0 -161
  131. package/src/core/log-prune.test.ts +0 -58
  132. package/src/core/log-prune.ts +0 -43
  133. package/src/core/preflight.test.ts +0 -49
  134. package/src/core/preflight.ts +0 -89
  135. package/src/core/run-context.test.ts +0 -291
  136. package/src/core/run-context.ts +0 -211
  137. package/src/core/run-state.test.ts +0 -98
  138. package/src/core/run-state.ts +0 -122
  139. package/src/core/scheduler.test.ts +0 -83
  140. package/src/core/scheduler.ts +0 -42
  141. package/src/core/task-executor.ts +0 -752
  142. package/src/core/trigger-errors.ts +0 -15
  143. package/src/dag.test.ts +0 -56
  144. package/src/dag.ts +0 -245
  145. package/src/drivers/opencode.ts +0 -410
  146. package/src/engine-ports-mixed.test.ts +0 -182
  147. package/src/engine-ports.test.ts +0 -210
  148. package/src/engine-task-type.test.ts +0 -56
  149. package/src/engine.ts +0 -32
  150. package/src/hooks.ts +0 -193
  151. package/src/index.ts +0 -31
  152. package/src/logger.ts +0 -2
  153. package/src/middlewares/static-context.ts +0 -49
  154. package/src/package-split.test.ts +0 -15
  155. package/src/pipeline-definition.ts +0 -5
  156. package/src/pipeline-runner.test.ts +0 -144
  157. package/src/pipeline-runner.ts +0 -194
  158. package/src/plugin-registry.test.ts +0 -448
  159. package/src/plugins.ts +0 -21
  160. package/src/ports.test.ts +0 -678
  161. package/src/ports.ts +0 -925
  162. package/src/prompt-doc.test.ts +0 -174
  163. package/src/prompt-doc.ts +0 -169
  164. package/src/registry.ts +0 -7
  165. package/src/runner.test.ts +0 -142
  166. package/src/runner.ts +0 -1
  167. package/src/runtime/adapters/stdin-approval.ts +0 -1
  168. package/src/runtime/adapters/websocket-approval.ts +0 -1
  169. package/src/runtime/bun-process-runner.ts +0 -1
  170. package/src/runtime-adapters.test.ts +0 -10
  171. package/src/runtime.ts +0 -12
  172. package/src/schema-ports.test.ts +0 -172
  173. package/src/schema.test.ts +0 -213
  174. package/src/schema.ts +0 -379
  175. package/src/tagma.test.ts +0 -317
  176. package/src/tagma.ts +0 -67
  177. package/src/task-ref.test.ts +0 -401
  178. package/src/task-ref.ts +0 -121
  179. package/src/triggers/file.test.ts +0 -79
  180. package/src/triggers/file.ts +0 -131
  181. package/src/triggers/manual.ts +0 -86
  182. package/src/types.ts +0 -18
  183. package/src/utils-api.ts +0 -8
  184. package/src/utils.test.ts +0 -28
  185. package/src/utils.ts +0 -203
  186. package/src/validate-raw-plugin-types.test.ts +0 -60
  187. package/src/validate-raw-ports.test.ts +0 -136
  188. package/src/validate-raw.ts +0 -852
  189. package/src/yaml-compiler.test.ts +0 -108
  190. package/src/yaml-compiler.ts +0 -110
  191. package/src/yaml.ts +0 -11
@@ -1,58 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import { mkdtempSync, mkdirSync, readdirSync, rmSync } from 'node:fs';
3
- import { tmpdir } from 'node:os';
4
- import { join } from 'node:path';
5
- import { pruneLogDirs } from './log-prune';
6
-
7
- function fixture(): string {
8
- return mkdtempSync(join(tmpdir(), 'tagma-prune-'));
9
- }
10
-
11
- describe('pruneLogDirs', () => {
12
- test('returns silently when logsDir does not exist', async () => {
13
- const root = fixture();
14
- try {
15
- await expect(
16
- pruneLogDirs(join(root, 'nope'), 5, 'run_live'),
17
- ).resolves.toBeUndefined();
18
- } finally {
19
- rmSync(root, { recursive: true, force: true });
20
- }
21
- });
22
-
23
- test('keeps the live run plus (keep-1) most recent historical runs', async () => {
24
- const root = fixture();
25
- try {
26
- for (const id of ['run_001', 'run_002', 'run_003', 'run_004', 'run_005']) {
27
- mkdirSync(join(root, id));
28
- }
29
- await pruneLogDirs(root, 3, 'run_005'); // keep=3 → 1 live + 2 historical
30
- expect(readdirSync(root).sort()).toEqual(['run_003', 'run_004', 'run_005']);
31
- } finally {
32
- rmSync(root, { recursive: true, force: true });
33
- }
34
- });
35
-
36
- test('never deletes the excluded live runId even if it would be pruned', async () => {
37
- const root = fixture();
38
- try {
39
- for (const id of ['run_001', 'run_002', 'run_003']) mkdirSync(join(root, id));
40
- await pruneLogDirs(root, 1, 'run_001');
41
- expect(readdirSync(root).sort()).toEqual(['run_001']);
42
- } finally {
43
- rmSync(root, { recursive: true, force: true });
44
- }
45
- });
46
-
47
- test('ignores entries that do not look like run dirs', async () => {
48
- const root = fixture();
49
- try {
50
- mkdirSync(join(root, 'run_001'));
51
- mkdirSync(join(root, 'not_a_run'));
52
- await pruneLogDirs(root, 1, 'run_001');
53
- expect(readdirSync(root).sort()).toEqual(['not_a_run', 'run_001']);
54
- } finally {
55
- rmSync(root, { recursive: true, force: true });
56
- }
57
- });
58
- });
@@ -1,43 +0,0 @@
1
- import { readdir, rm } from 'node:fs/promises';
2
- import { resolve } from 'node:path';
3
-
4
- /**
5
- * Delete the oldest subdirectories under `logsDir`, keeping only the
6
- * most recent `keep` total runs (including the currently-live run
7
- * identified by `excludeRunId`). Directories are sorted
8
- * lexicographically; because runIds are prefixed with a base-36
9
- * timestamp, lexicographic order equals chronological order.
10
- *
11
- * `excludeRunId` is always skipped from deletion even if it would
12
- * otherwise be pruned — this prevents a concurrent run from removing a
13
- * live log directory that is still in use.
14
- *
15
- * The live run occupies one slot out of `keep`, so the maximum number
16
- * of *historical* dirs to retain is `keep - 1`.
17
- */
18
- export async function pruneLogDirs(
19
- logsDir: string,
20
- keep: number,
21
- excludeRunId: string,
22
- ): Promise<void> {
23
- let entries: string[];
24
- try {
25
- entries = await readdir(logsDir);
26
- } catch {
27
- return; // logsDir doesn't exist yet
28
- }
29
-
30
- const runDirs = entries
31
- .filter((e) => e.startsWith('run_') && e !== excludeRunId)
32
- .sort();
33
- const historyKeep = Math.max(0, keep - 1);
34
- const toDelete = runDirs.slice(0, Math.max(0, runDirs.length - historyKeep));
35
-
36
- await Promise.all(
37
- toDelete.map((dir) =>
38
- rm(resolve(logsDir, dir), { recursive: true, force: true }).catch(() => {
39
- // Ignore deletion errors — stale dirs are better than a crash
40
- }),
41
- ),
42
- );
43
- }
@@ -1,49 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import { preflight } from './preflight';
3
- import { buildDag } from '../dag';
4
- import { PluginRegistry } from '../registry';
5
- import { bootstrapBuiltins } from '../bootstrap';
6
- import type { PipelineConfig } from '../types';
7
-
8
- function emptyConfig(overrides: Partial<PipelineConfig> = {}): PipelineConfig {
9
- return {
10
- name: 'p',
11
- tracks: [{ id: 't', name: 'T', tasks: [] }],
12
- ...overrides,
13
- };
14
- }
15
-
16
- describe('preflight', () => {
17
- test('throws when a referenced driver is not registered', () => {
18
- const reg = new PluginRegistry();
19
- const cfg = emptyConfig({
20
- tracks: [
21
- { id: 't', name: 'T', tasks: [{ id: 'a', name: 'A', prompt: 'hi' }] },
22
- ],
23
- });
24
- expect(() => preflight(cfg, buildDag(cfg), reg)).toThrow(
25
- /driver "opencode" not registered/,
26
- );
27
- });
28
-
29
- test('passes when all referenced plugins are registered', () => {
30
- const reg = new PluginRegistry();
31
- bootstrapBuiltins(reg);
32
- const cfg = emptyConfig({
33
- tracks: [
34
- { id: 't', name: 'T', tasks: [{ id: 'a', name: 'A', prompt: 'hi' }] },
35
- ],
36
- });
37
- expect(() => preflight(cfg, buildDag(cfg), reg)).not.toThrow();
38
- });
39
-
40
- test('skips driver check for command-only tasks', () => {
41
- const reg = new PluginRegistry(); // no drivers registered
42
- const cfg = emptyConfig({
43
- tracks: [
44
- { id: 't', name: 'T', tasks: [{ id: 'a', name: 'A', command: 'echo hi' }] },
45
- ],
46
- });
47
- expect(() => preflight(cfg, buildDag(cfg), reg)).not.toThrow();
48
- });
49
- });
@@ -1,89 +0,0 @@
1
- import type { PipelineConfig, TaskConfig, DriverPlugin } from '../types';
2
- import type { Dag } from '../dag';
3
- import type { PluginRegistry } from '../registry';
4
-
5
- function isCommandOnly(
6
- task: TaskConfig,
7
- ): task is TaskConfig & { readonly command: string; readonly prompt?: undefined } {
8
- return task.command !== undefined && task.prompt === undefined;
9
- }
10
-
11
- /**
12
- * Validate that every plugin referenced by the pipeline (drivers,
13
- * triggers, completions, middlewares) is registered, and that
14
- * `continue_from` is only used between drivers that can hand off via
15
- * sessionResume or text-injection. Throws with all errors aggregated
16
- * into one message so the caller sees every misconfiguration in a
17
- * single pass.
18
- */
19
- export function preflight(
20
- config: PipelineConfig,
21
- dag: Dag,
22
- registry: PluginRegistry,
23
- ): void {
24
- const errors: string[] = [];
25
-
26
- for (const [, node] of dag.nodes) {
27
- const task = node.task;
28
- const track = node.track;
29
- const driverName = task.driver ?? track.driver ?? config.driver ?? 'opencode';
30
-
31
- const isCommand = isCommandOnly(task);
32
-
33
- if (!isCommand && !registry.hasHandler('drivers', driverName)) {
34
- errors.push(`Task "${node.taskId}": driver "${driverName}" not registered`);
35
- }
36
-
37
- if (task.trigger && !registry.hasHandler('triggers', task.trigger.type)) {
38
- errors.push(
39
- `Task "${node.taskId}": trigger type "${task.trigger.type}" not registered`,
40
- );
41
- }
42
-
43
- if (task.completion && !registry.hasHandler('completions', task.completion.type)) {
44
- errors.push(
45
- `Task "${node.taskId}": completion type "${task.completion.type}" not registered`,
46
- );
47
- }
48
-
49
- const mws = task.middlewares ?? track.middlewares ?? [];
50
- for (const mw of mws) {
51
- if (!registry.hasHandler('middlewares', mw.type)) {
52
- errors.push(
53
- `Task "${node.taskId}": middleware type "${mw.type}" not registered`,
54
- );
55
- }
56
- }
57
-
58
- if (task.continue_from && registry.hasHandler('drivers', driverName)) {
59
- const driver = registry.getHandler<DriverPlugin>('drivers', driverName);
60
- if (!driver.capabilities.sessionResume) {
61
- const upstreamId = node.resolvedContinueFrom;
62
- if (upstreamId) {
63
- const upstream = dag.nodes.get(upstreamId);
64
- if (upstream) {
65
- const upstreamDriverName =
66
- upstream.task.driver ?? upstream.track.driver ?? config.driver ?? 'opencode';
67
- const upstreamDriver = registry.hasHandler('drivers', upstreamDriverName)
68
- ? registry.getHandler<DriverPlugin>('drivers', upstreamDriverName)
69
- : null;
70
- const canNormalize = typeof upstreamDriver?.parseResult === 'function';
71
-
72
- if (!canNormalize) {
73
- errors.push(
74
- `Task "${node.taskId}" uses continue_from: "${task.continue_from}", ` +
75
- `but upstream task "${upstreamId}" its driver ` +
76
- `does not implement parseResult for text-injection handoff. ` +
77
- `Use a driver with parseResult, or remove continue_from.`,
78
- );
79
- }
80
- }
81
- }
82
- }
83
- }
84
- }
85
-
86
- if (errors.length > 0) {
87
- throw new Error(`Preflight validation failed:\n - ${errors.join('\n - ')}`);
88
- }
89
- }
@@ -1,291 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import { RunContext } from './run-context';
3
- import { buildDag } from '../dag';
4
- import type { PipelineConfig, RunEventPayload } from '../types';
5
- import type { PipelineInfo } from '../hooks';
6
- import type { TagmaRuntime } from '../runtime';
7
-
8
- const fakeRuntime: TagmaRuntime = {
9
- async runCommand() {
10
- throw new Error('fakeRuntime.runCommand should not be called by RunContext tests');
11
- },
12
- async runSpawn() {
13
- throw new Error('fakeRuntime.runSpawn should not be called by RunContext tests');
14
- },
15
- async ensureDir() {
16
- /* no-op */
17
- },
18
- async fileExists() {
19
- return false;
20
- },
21
- async *watch() {
22
- /* no-op */
23
- },
24
- logStore: {
25
- openRunLog() {
26
- return {
27
- path: 'mem://pipeline.log',
28
- dir: 'mem://run',
29
- append() {
30
- /* no-op */
31
- },
32
- close() {
33
- /* no-op */
34
- },
35
- };
36
- },
37
- taskOutputPath({ taskId, stream }) {
38
- return `mem://${taskId}.${stream}`;
39
- },
40
- logsDir() {
41
- return 'mem://logs';
42
- },
43
- },
44
- now() {
45
- return new Date('2026-04-26T00:00:00.000Z');
46
- },
47
- sleep() {
48
- return Promise.resolve();
49
- },
50
- };
51
-
52
- function makeContext(overrides: Partial<{
53
- config: PipelineConfig;
54
- onEvent: (e: RunEventPayload) => void;
55
- }> = {}): { ctx: RunContext; events: RunEventPayload[] } {
56
- const config: PipelineConfig = overrides.config ?? {
57
- name: 'p',
58
- tracks: [
59
- {
60
- id: 't',
61
- name: 'T',
62
- tasks: [
63
- { id: 'a', name: 'A', command: 'echo a' },
64
- { id: 'b', name: 'B', command: 'echo b', depends_on: ['a'] },
65
- ],
66
- },
67
- ],
68
- };
69
- const events: RunEventPayload[] = [];
70
- const onEvent = overrides.onEvent ?? ((e: RunEventPayload) => { events.push(e); });
71
- const ctx = new RunContext({
72
- runId: 'run_test',
73
- dag: buildDag(config),
74
- config,
75
- workDir: '/tmp/wd',
76
- pipelineInfo: { name: config.name, run_id: 'run_test', started_at: '2026-04-26T00:00:00Z' } as PipelineInfo,
77
- onEvent,
78
- runtime: fakeRuntime,
79
- });
80
- return { ctx, events };
81
- }
82
-
83
- describe('RunContext constructor', () => {
84
- test('initializes one idle state per dag node', () => {
85
- const { ctx } = makeContext();
86
- expect(ctx.states.size).toBe(2);
87
- expect(ctx.states.get('t.a')!.status).toBe('idle');
88
- expect(ctx.states.get('t.b')!.status).toBe('idle');
89
- });
90
-
91
- test('initializes all state maps as empty', () => {
92
- const { ctx } = makeContext();
93
- expect(ctx.sessionMap.size).toBe(0);
94
- expect(ctx.normalizedMap.size).toBe(0);
95
- expect(ctx.outputValuesMap.size).toBe(0);
96
- expect(ctx.bindingDataMap.size).toBe(0);
97
- expect(ctx.resolvedInputsMap.size).toBe(0);
98
- });
99
-
100
- test('computes directDownstreams reverse adjacency from dag', () => {
101
- const { ctx } = makeContext();
102
- expect([...ctx.directDownstreams.get('t.a')!]).toEqual(['t.b']);
103
- expect([...ctx.directDownstreams.get('t.b')!]).toEqual([]);
104
- });
105
-
106
- test('starts with abortReason null and a fresh AbortController', () => {
107
- const { ctx } = makeContext();
108
- expect(ctx.abortReason).toBeNull();
109
- expect(ctx.abortController.signal.aborted).toBe(false);
110
- });
111
- });
112
-
113
- describe('RunContext.emit', () => {
114
- test('forwards events to onEvent', () => {
115
- const { ctx, events } = makeContext();
116
- ctx.emit({ type: 'run_end', runId: 'run_test', success: true, abortReason: null });
117
- expect(events).toHaveLength(1);
118
- expect(events[0]).toEqual({ type: 'run_end', runId: 'run_test', success: true, abortReason: null });
119
- });
120
-
121
- test('is a no-op when onEvent is undefined', () => {
122
- const config: PipelineConfig = {
123
- name: 'p',
124
- tracks: [{ id: 't', name: 'T', tasks: [{ id: 'a', name: 'A', command: 'echo a' }] }],
125
- };
126
- const ctx = new RunContext({
127
- runId: 'run_test',
128
- dag: buildDag(config),
129
- config,
130
- workDir: '/tmp/wd',
131
- pipelineInfo: { name: 'p', run_id: 'run_test', started_at: 'now' } as PipelineInfo,
132
- runtime: fakeRuntime,
133
- });
134
- expect(() => ctx.emit({ type: 'run_end', runId: 'run_test', success: true, abortReason: null })).not.toThrow();
135
- });
136
- });
137
-
138
- describe('RunContext.setTaskStatus', () => {
139
- test('transitions a non-terminal task and emits task_update', () => {
140
- const { ctx, events } = makeContext();
141
- ctx.setTaskStatus('t.a', 'waiting');
142
- expect(ctx.states.get('t.a')!.status).toBe('waiting');
143
- expect(events).toHaveLength(1);
144
- expect(events[0].type).toBe('task_update');
145
- if (events[0].type === 'task_update') {
146
- expect(events[0].taskId).toBe('t.a');
147
- expect(events[0].status).toBe('waiting');
148
- }
149
- });
150
-
151
- test('refuses to re-transition a terminal task (terminal lock)', () => {
152
- const { ctx, events } = makeContext();
153
- ctx.setTaskStatus('t.a', 'success');
154
- events.length = 0;
155
- ctx.setTaskStatus('t.a', 'failed');
156
- expect(ctx.states.get('t.a')!.status).toBe('success');
157
- expect(events).toHaveLength(0);
158
- });
159
-
160
- test('echoes resolvedInputs and outputs from the maps in the emitted event', () => {
161
- const { ctx, events } = makeContext();
162
- ctx.resolvedInputsMap.set('t.a', { x: 1 });
163
- ctx.outputValuesMap.set('t.a', { y: 2 });
164
- ctx.setTaskStatus('t.a', 'running');
165
- if (events[0].type === 'task_update') {
166
- expect(events[0].inputs).toEqual({ x: 1 });
167
- expect(events[0].outputs).toEqual({ y: 2 });
168
- } else {
169
- throw new Error('expected task_update');
170
- }
171
- });
172
- });
173
-
174
- describe('RunContext.getOnFailure', () => {
175
- test('returns the track-level on_failure setting', () => {
176
- const config: PipelineConfig = {
177
- name: 'p',
178
- tracks: [
179
- {
180
- id: 't',
181
- name: 'T',
182
- on_failure: 'stop_all',
183
- tasks: [{ id: 'a', name: 'A', command: 'echo a' }],
184
- },
185
- ],
186
- };
187
- const { ctx } = makeContext({ config });
188
- expect(ctx.getOnFailure('t.a')).toBe('stop_all');
189
- });
190
-
191
- test('defaults to skip_downstream when track does not specify', () => {
192
- const { ctx } = makeContext();
193
- expect(ctx.getOnFailure('t.a')).toBe('skip_downstream');
194
- });
195
- });
196
-
197
- describe('RunContext.isDependencySatisfied', () => {
198
- test('returns satisfied for success', () => {
199
- const { ctx } = makeContext();
200
- ctx.states.get('t.a')!.status = 'success';
201
- expect(ctx.isDependencySatisfied('t.a')).toBe('satisfied');
202
- });
203
-
204
- test('returns skip for skipped', () => {
205
- const { ctx } = makeContext();
206
- ctx.states.get('t.a')!.status = 'skipped';
207
- expect(ctx.isDependencySatisfied('t.a')).toBe('skip');
208
- });
209
-
210
- test('returns skip for failed under default policy, satisfied under ignore', () => {
211
- const cfgSkip: PipelineConfig = {
212
- name: 'p',
213
- tracks: [{ id: 't', name: 'T', tasks: [{ id: 'a', name: 'A', command: 'echo a' }] }],
214
- };
215
- const cfgIgnore: PipelineConfig = {
216
- name: 'p',
217
- tracks: [
218
- {
219
- id: 't',
220
- name: 'T',
221
- on_failure: 'ignore',
222
- tasks: [{ id: 'a', name: 'A', command: 'echo a' }],
223
- },
224
- ],
225
- };
226
- const a = makeContext({ config: cfgSkip }).ctx;
227
- a.states.get('t.a')!.status = 'failed';
228
- expect(a.isDependencySatisfied('t.a')).toBe('skip');
229
-
230
- const b = makeContext({ config: cfgIgnore }).ctx;
231
- b.states.get('t.a')!.status = 'failed';
232
- expect(b.isDependencySatisfied('t.a')).toBe('satisfied');
233
- });
234
-
235
- test('returns unsatisfied for non-terminal statuses', () => {
236
- const { ctx } = makeContext();
237
- ctx.states.get('t.a')!.status = 'running';
238
- expect(ctx.isDependencySatisfied('t.a')).toBe('unsatisfied');
239
- });
240
- });
241
-
242
- describe('RunContext.applyStopAll', () => {
243
- test('aborts the controller, sets abortReason, marks waiting tasks as skipped', () => {
244
- const { ctx } = makeContext();
245
- ctx.states.get('t.a')!.status = 'waiting';
246
- ctx.states.get('t.b')!.status = 'waiting';
247
- ctx.applyStopAll();
248
- expect(ctx.abortReason).toBe('stop_all');
249
- expect(ctx.abortController.signal.aborted).toBe(true);
250
- expect(ctx.states.get('t.a')!.status).toBe('skipped');
251
- expect(ctx.states.get('t.b')!.status).toBe('skipped');
252
- });
253
-
254
- test('does not overwrite an existing abortReason', () => {
255
- const { ctx } = makeContext();
256
- ctx.abortReason = 'timeout';
257
- ctx.applyStopAll();
258
- expect(ctx.abortReason).toBe('timeout');
259
- expect(ctx.abortController.signal.aborted).toBe(true);
260
- });
261
-
262
- test('leaves running and terminal tasks alone', () => {
263
- const { ctx } = makeContext();
264
- ctx.states.get('t.a')!.status = 'running';
265
- ctx.states.get('t.b')!.status = 'success';
266
- ctx.applyStopAll();
267
- expect(ctx.states.get('t.a')!.status).toBe('running');
268
- expect(ctx.states.get('t.b')!.status).toBe('success');
269
- });
270
- });
271
-
272
- describe('RunContext.buildTaskInfoObj / trackInfoOf', () => {
273
- test('buildTaskInfoObj reports type=command for command tasks', () => {
274
- const { ctx } = makeContext();
275
- expect(ctx.buildTaskInfoObj('t.a').type).toBe('command');
276
- });
277
-
278
- test('buildTaskInfoObj reports type=ai for prompt tasks', () => {
279
- const config: PipelineConfig = {
280
- name: 'p',
281
- tracks: [{ id: 't', name: 'T', tasks: [{ id: 'a', name: 'A', prompt: 'hi' }] }],
282
- };
283
- const { ctx } = makeContext({ config });
284
- expect(ctx.buildTaskInfoObj('t.a').type).toBe('ai');
285
- });
286
-
287
- test('trackInfoOf returns the track id and name', () => {
288
- const { ctx } = makeContext();
289
- expect(ctx.trackInfoOf('t.a')).toEqual({ id: 't', name: 'T' });
290
- });
291
- });