@outputai/cli 0.1.13-dev.01b8dea.0 → 0.1.13-dev.59a1b6d.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.
@@ -0,0 +1,202 @@
1
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
+ import { mkdtemp, rm, writeFile, readFile, mkdir } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
+ import { tmpdir } from 'node:os';
5
+ import yaml from 'js-yaml';
6
+ import { readDatasetFile, readAllDatasets, writeDataset, listDatasets } from './datasets.js';
7
+ const ctx = { tmpDir: '' };
8
+ beforeEach(async () => {
9
+ ctx.tmpDir = await mkdtemp(join(tmpdir(), 'output-datasets-test-'));
10
+ });
11
+ afterEach(async () => {
12
+ await rm(ctx.tmpDir, { recursive: true, force: true });
13
+ });
14
+ function writeYaml(filePath, obj) {
15
+ return writeFile(filePath, yaml.dump(obj, { lineWidth: 120, noRefs: true, sortKeys: false }), 'utf-8');
16
+ }
17
+ // ---------------------------------------------------------------------------
18
+ // readDatasetFile
19
+ // ---------------------------------------------------------------------------
20
+ describe('readDatasetFile', () => {
21
+ it('parses a multi-case file and returns all cases', async () => {
22
+ const filePath = join(ctx.tmpDir, 'cases.yml');
23
+ await writeYaml(filePath, {
24
+ case_a: { input: { query: 'foo' }, ground_truth: { expected: 1 } },
25
+ case_b: { input: { query: 'bar' } },
26
+ case_c: { input: { query: 'baz' }, ground_truth: { expected: 3 } }
27
+ });
28
+ const datasets = await readDatasetFile(filePath);
29
+ expect(datasets).toHaveLength(3);
30
+ expect(datasets.map(d => d.name)).toEqual(['case_a', 'case_b', 'case_c']);
31
+ expect(datasets[0].input).toEqual({ query: 'foo' });
32
+ expect(datasets[0].ground_truth).toEqual({ expected: 1 });
33
+ });
34
+ it('attaches _source with the absolute file path to each dataset', async () => {
35
+ const filePath = join(ctx.tmpDir, 'cases.yml');
36
+ await writeYaml(filePath, {
37
+ my_case: { input: { x: 1 } }
38
+ });
39
+ const [dataset] = await readDatasetFile(filePath);
40
+ expect(dataset._source).toBe(filePath);
41
+ });
42
+ it('throws when a case is missing input', async () => {
43
+ const filePath = join(ctx.tmpDir, 'bad.yml');
44
+ await writeYaml(filePath, {
45
+ good_case: { input: { x: 1 } },
46
+ bad_case: { ground_truth: { expected: 42 } }
47
+ });
48
+ await expect(readDatasetFile(filePath)).rejects.toThrow('Dataset case "bad_case" in');
49
+ });
50
+ it('throws when file content is not an object', async () => {
51
+ const filePath = join(ctx.tmpDir, 'bad.yml');
52
+ await writeFile(filePath, 'just a string', 'utf-8');
53
+ await expect(readDatasetFile(filePath)).rejects.toThrow('Invalid dataset file');
54
+ });
55
+ it('throws with clear message when file content is a YAML array', async () => {
56
+ const filePath = join(ctx.tmpDir, 'bad.yml');
57
+ await writeFile(filePath, '- foo\n- bar\n', 'utf-8');
58
+ await expect(readDatasetFile(filePath)).rejects.toThrow('Invalid dataset file');
59
+ });
60
+ it('preserves last_output and last_eval fields', async () => {
61
+ const filePath = join(ctx.tmpDir, 'cases.yml');
62
+ await writeYaml(filePath, {
63
+ cached_case: {
64
+ input: { q: 'hello' },
65
+ last_output: { output: { result: 42 }, executionTimeMs: 100, date: '2026-01-01T00:00:00.000Z' }
66
+ }
67
+ });
68
+ const [dataset] = await readDatasetFile(filePath);
69
+ expect(dataset.last_output?.output).toEqual({ result: 42 });
70
+ expect(dataset.last_output?.executionTimeMs).toBe(100);
71
+ });
72
+ });
73
+ // ---------------------------------------------------------------------------
74
+ // readAllDatasets
75
+ // ---------------------------------------------------------------------------
76
+ describe('readAllDatasets', () => {
77
+ it('flattens cases from multiple files', async () => {
78
+ const datasetsDir = join(ctx.tmpDir, 'src', 'workflows', 'my_workflow', 'tests', 'datasets');
79
+ await mkdir(datasetsDir, { recursive: true });
80
+ await writeYaml(join(datasetsDir, 'group_a.yml'), {
81
+ case_1: { input: { x: 1 } },
82
+ case_2: { input: { x: 2 } }
83
+ });
84
+ await writeYaml(join(datasetsDir, 'group_b.yml'), {
85
+ case_3: { input: { x: 3 } }
86
+ });
87
+ const { datasets } = await readAllDatasets('my_workflow', undefined, ctx.tmpDir);
88
+ expect(datasets).toHaveLength(3);
89
+ expect(datasets.map(d => d.name).sort()).toEqual(['case_1', 'case_2', 'case_3']);
90
+ });
91
+ it('filters by case name across files', async () => {
92
+ const datasetsDir = join(ctx.tmpDir, 'src', 'workflows', 'my_workflow', 'tests', 'datasets');
93
+ await mkdir(datasetsDir, { recursive: true });
94
+ await writeYaml(join(datasetsDir, 'group_a.yml'), {
95
+ case_1: { input: { x: 1 } },
96
+ case_2: { input: { x: 2 } }
97
+ });
98
+ await writeYaml(join(datasetsDir, 'group_b.yml'), {
99
+ case_3: { input: { x: 3 } }
100
+ });
101
+ const { datasets } = await readAllDatasets('my_workflow', ['case_2', 'case_3'], ctx.tmpDir);
102
+ expect(datasets).toHaveLength(2);
103
+ expect(datasets.map(d => d.name).sort()).toEqual(['case_2', 'case_3']);
104
+ });
105
+ it('returns empty datasets and a default dir when workflow has no datasets dir', async () => {
106
+ const { datasets, dir } = await readAllDatasets('nonexistent_workflow', undefined, ctx.tmpDir);
107
+ expect(datasets).toHaveLength(0);
108
+ expect(dir).toContain('nonexistent_workflow');
109
+ });
110
+ it('throws when the same case name appears in two different files', async () => {
111
+ const datasetsDir = join(ctx.tmpDir, 'src', 'workflows', 'my_workflow', 'tests', 'datasets');
112
+ await mkdir(datasetsDir, { recursive: true });
113
+ await writeYaml(join(datasetsDir, 'group_a.yml'), { case_1: { input: { x: 1 } } });
114
+ await writeYaml(join(datasetsDir, 'group_b.yml'), { case_1: { input: { x: 2 } } });
115
+ await expect(readAllDatasets('my_workflow', undefined, ctx.tmpDir)).rejects.toThrow('Duplicate dataset case name "case_1"');
116
+ });
117
+ });
118
+ // ---------------------------------------------------------------------------
119
+ // writeDataset
120
+ // ---------------------------------------------------------------------------
121
+ describe('writeDataset', () => {
122
+ it('creates a new file with one case keyed by name', async () => {
123
+ const filePath = join(ctx.tmpDir, 'cases.yml');
124
+ const dataset = { name: 'new_case', input: { q: 'hello' } };
125
+ await writeDataset(dataset, filePath);
126
+ const raw = yaml.load(await readFile(filePath, 'utf-8'));
127
+ expect(raw).toHaveProperty('new_case');
128
+ expect(raw.new_case.input).toEqual({ q: 'hello' });
129
+ expect(raw.new_case).not.toHaveProperty('name');
130
+ });
131
+ it('does not write _source into the file', async () => {
132
+ const filePath = join(ctx.tmpDir, 'cases.yml');
133
+ const dataset = { name: 'my_case', input: { q: 'x' }, _source: '/some/path.yml' };
134
+ await writeDataset(dataset, filePath);
135
+ const raw = yaml.load(await readFile(filePath, 'utf-8'));
136
+ expect(raw.my_case).not.toHaveProperty('_source');
137
+ });
138
+ it('updates only the target case, leaving other cases untouched', async () => {
139
+ const filePath = join(ctx.tmpDir, 'cases.yml');
140
+ await writeYaml(filePath, {
141
+ case_a: { input: { x: 1 }, ground_truth: { expected: 1 } },
142
+ case_b: { input: { x: 2 }, ground_truth: { expected: 2 } }
143
+ });
144
+ await writeDataset({ name: 'case_a', input: { x: 1 }, last_output: { output: { result: 1 }, date: '2026-01-01T00:00:00.000Z' } }, filePath);
145
+ const raw = yaml.load(await readFile(filePath, 'utf-8'));
146
+ expect(raw).toHaveProperty('case_b');
147
+ expect(raw.case_b.ground_truth).toEqual({ expected: 2 });
148
+ });
149
+ it('preserves existing fields when writing last_output then last_eval', async () => {
150
+ const filePath = join(ctx.tmpDir, 'cases.yml');
151
+ await writeYaml(filePath, {
152
+ my_case: { input: { q: 'hello' }, ground_truth: { expected: 42 } }
153
+ });
154
+ await writeDataset({ name: 'my_case', input: { q: 'hello' }, last_output: { output: { result: 42 }, executionTimeMs: 50, date: '2026-01-01T00:00:00.000Z' } }, filePath);
155
+ await writeDataset({
156
+ name: 'my_case', input: { q: 'hello' },
157
+ last_eval: { output: { datasetName: 'my_case', verdict: 'pass', evaluators: [] }, date: '2026-01-01T00:01:00.000Z' }
158
+ }, filePath);
159
+ const raw = yaml.load(await readFile(filePath, 'utf-8'));
160
+ const caseObj = raw.my_case;
161
+ expect(caseObj).toHaveProperty('last_output');
162
+ expect(caseObj).toHaveProperty('last_eval');
163
+ expect(caseObj).toHaveProperty('ground_truth');
164
+ });
165
+ it('creates parent directories if they do not exist', async () => {
166
+ const filePath = join(ctx.tmpDir, 'deep', 'nested', 'cases.yml');
167
+ await writeDataset({ name: 'my_case', input: { q: 'x' } }, filePath);
168
+ const raw = yaml.load(await readFile(filePath, 'utf-8'));
169
+ expect(raw).toHaveProperty('my_case');
170
+ });
171
+ it('recovers gracefully when existing file contains non-object YAML', async () => {
172
+ const filePath = join(ctx.tmpDir, 'cases.yml');
173
+ await writeFile(filePath, 'just a string', 'utf-8');
174
+ await writeDataset({ name: 'my_case', input: { q: 'x' } }, filePath);
175
+ const raw = yaml.load(await readFile(filePath, 'utf-8'));
176
+ expect(raw).toHaveProperty('my_case');
177
+ });
178
+ });
179
+ // ---------------------------------------------------------------------------
180
+ // listDatasets
181
+ // ---------------------------------------------------------------------------
182
+ describe('listDatasets', () => {
183
+ it('returns one DatasetInfo per case across all files', async () => {
184
+ const datasetsDir = join(ctx.tmpDir, 'src', 'workflows', 'my_workflow', 'tests', 'datasets');
185
+ await mkdir(datasetsDir, { recursive: true });
186
+ await writeYaml(join(datasetsDir, 'core.yml'), {
187
+ case_1: { input: { x: 1 }, last_output: { output: { r: 1 }, date: '2026-01-01T00:00:00.000Z' } },
188
+ case_2: { input: { x: 2 } }
189
+ });
190
+ const infos = await listDatasets('my_workflow', ctx.tmpDir);
191
+ expect(infos).toHaveLength(2);
192
+ const case1 = infos.find(i => i.name === 'case_1');
193
+ expect(case1.hasLastOutput).toBe(true);
194
+ expect(case1.path).toContain('core.yml');
195
+ const case2 = infos.find(i => i.name === 'case_2');
196
+ expect(case2.hasLastOutput).toBe(false);
197
+ });
198
+ it('returns empty array when no datasets directory exists', async () => {
199
+ const infos = await listDatasets('nonexistent_workflow', ctx.tmpDir);
200
+ expect(infos).toHaveLength(0);
201
+ });
202
+ });
@@ -9,6 +9,7 @@ export interface WorkflowRunsResult {
9
9
  }
10
10
  export interface FetchWorkflowRunsOptions {
11
11
  workflowType?: string;
12
+ taskQueue?: string;
12
13
  limit?: number;
13
14
  }
14
15
  export declare function fetchWorkflowRuns(options?: FetchWorkflowRunsOptions): Promise<WorkflowRunsResult>;
@@ -10,6 +10,9 @@ export async function fetchWorkflowRuns(options = {}) {
10
10
  if (options.workflowType) {
11
11
  params.workflowType = options.workflowType;
12
12
  }
13
+ if (options.taskQueue) {
14
+ params.taskQueue = options.taskQueue;
15
+ }
13
16
  const response = await getWorkflowRuns(params);
14
17
  if (!response) {
15
18
  throw new Error('Failed to connect to API server. Is it running?');
@@ -1,5 +1,5 @@
1
- import type { GetWorkflowIdResult200, GetWorkflowIdResult200Status } from '../api/generated/api.js';
2
- type WorkflowResult = Pick<GetWorkflowIdResult200, 'workflowId' | 'output' | 'status' | 'error'>;
3
- export declare const ERROR_STATUSES: ReadonlySet<GetWorkflowIdResult200Status | undefined>;
1
+ import type { WorkflowResultResponse, WorkflowResultResponseStatus } from '../api/generated/api.js';
2
+ type WorkflowResult = Pick<WorkflowResultResponse, 'workflowId' | 'output' | 'status' | 'error'>;
3
+ export declare const ERROR_STATUSES: ReadonlySet<WorkflowResultResponseStatus | undefined>;
4
4
  export declare function formatWorkflowResult(result: WorkflowResult): string;
5
5
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@outputai/cli",
3
- "version": "0.1.13-dev.01b8dea.0",
3
+ "version": "0.1.13-dev.59a1b6d.0",
4
4
  "description": "CLI for Output.ai workflow generation",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -36,9 +36,9 @@
36
36
  "semver": "7.7.4",
37
37
  "undici": "8.0.2",
38
38
  "yaml": "^2.8.3",
39
- "@outputai/credentials": "0.1.13-dev.01b8dea.0",
40
- "@outputai/evals": "0.1.13-dev.01b8dea.0",
41
- "@outputai/llm": "0.1.13-dev.01b8dea.0"
39
+ "@outputai/credentials": "0.1.13-dev.59a1b6d.0",
40
+ "@outputai/evals": "0.1.13-dev.59a1b6d.0",
41
+ "@outputai/llm": "0.1.13-dev.59a1b6d.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/cli-progress": "3.11.6",