@output.ai/core 0.5.6 → 0.5.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@output.ai/core",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
4
4
  "description": "The core module of the output framework",
5
5
  "type": "module",
6
6
  "exports": {
@@ -158,3 +158,16 @@ export class EvaluationBooleanResult extends EvaluationResult {
158
158
  */
159
159
  constructor( args: EvaluationResultArgs<boolean> );
160
160
  }
161
+
162
+ /**
163
+ * An evaluation result where the value is a verdict (pass, partial, fail)
164
+ * @extends EvaluationResult
165
+ */
166
+ export class EvaluationVerdictResult extends EvaluationResult {
167
+ /**
168
+ * @constructor
169
+ * @param args - See {@link EvaluationResultArgs} for full parameter documentation.
170
+ * @param args.value - The verdict: 'pass', 'partial', or 'fail'.
171
+ */
172
+ constructor( args: EvaluationResultArgs<'pass' | 'partial' | 'fail'> );
173
+ }
@@ -200,3 +200,16 @@ export class EvaluationBooleanResult extends EvaluationResult {
200
200
  export class EvaluationNumberResult extends EvaluationResult {
201
201
  static valueSchema = z.number();
202
202
  };
203
+
204
+ /**
205
+ * An evaluation result that uses a verdict value (pass, partial, fail)
206
+ * @extends EvaluationResult
207
+ * @property {'pass' | 'partial' | 'fail'} value - The evaluation verdict
208
+ * @constructor
209
+ * @param {object} args
210
+ * @param {'pass' | 'partial' | 'fail'} args.value - The verdict value
211
+ * @see EvaluationResult#constructor for other parameters (confidence, reasoning)
212
+ */
213
+ export class EvaluationVerdictResult extends EvaluationResult {
214
+ static valueSchema = z.enum( [ 'pass', 'partial', 'fail' ] );
215
+ };
@@ -1,4 +1,10 @@
1
- import { EvaluationStringResult, EvaluationNumberResult, EvaluationBooleanResult, EvaluationFeedback } from './evaluation_result.js';
1
+ import {
2
+ EvaluationStringResult,
3
+ EvaluationNumberResult,
4
+ EvaluationBooleanResult,
5
+ EvaluationVerdictResult,
6
+ EvaluationFeedback
7
+ } from './evaluation_result.js';
2
8
  import { evaluator } from './evaluator.js';
3
9
  import { step } from './step.js';
4
10
  import { workflow } from './workflow.js';
@@ -12,6 +18,7 @@ export {
12
18
  EvaluationNumberResult,
13
19
  EvaluationStringResult,
14
20
  EvaluationBooleanResult,
21
+ EvaluationVerdictResult,
15
22
  EvaluationFeedback,
16
23
  executeInParallel,
17
24
  sendHttpRequest,
@@ -51,7 +51,7 @@ export type WorkflowContext<
51
51
  *
52
52
  * @returns True if a continue-as-new is suggested for the current run; otherwise false.
53
53
  */
54
- isContinueAsNewSuggested: () => boolean
54
+ isContinueAsNewSuggested: () => boolean,
55
55
  },
56
56
 
57
57
  /**
@@ -75,8 +75,7 @@ export function workflow( { name, description, inputSchema, outputSchema, fn, op
75
75
  // validation comes after setting memo to have that info already set for interceptor even if validations fail
76
76
  validateWithSchema( inputSchema, input, `Workflow ${name} input` );
77
77
 
78
- // binds the methods called in the code that Webpack loader will add, they will exposed via "this"
79
- const output = await fn.call( {
78
+ const dispatchers = {
80
79
  invokeStep: async ( stepName, input, options ) => steps[`${name}#${stepName}`]( input, options ),
81
80
  invokeSharedStep: async ( stepName, input, options ) => steps[`${SHARED_STEP_PREFIX}#${stepName}`]( input, options ),
82
81
  invokeEvaluator: async ( evaluatorName, input, options ) => steps[`${name}#${evaluatorName}`]( input, options ),
@@ -90,7 +89,7 @@ export function workflow( { name, description, inputSchema, outputSchema, fn, op
90
89
  * @param {object} extra
91
90
  * @param {boolean} extra.detached
92
91
  * @param {import('@temporalio/workflow').ActivityOptions} extra.options
93
- * @returns
92
+ * @returns {Promise<unknown>}
94
93
  */
95
94
  startWorkflow: async ( childName, input, extra = {} ) =>
96
95
  executeChild( childName, {
@@ -100,11 +99,12 @@ export function workflow( { name, description, inputSchema, outputSchema, fn, op
100
99
  memo: {
101
100
  executionContext,
102
101
  parentId: workflowId,
103
- // new configuration for activities of the child workflow, this will be omitted so it will use what that workflow have defined
104
102
  ...( extra?.options?.activityOptions && { activityOptions: deepMerge( activityOptions, extra.options.activityOptions ) } )
105
103
  }
106
104
  } )
107
- }, input, context );
105
+ };
106
+
107
+ const output = await fn.call( dispatchers, input, context );
108
108
 
109
109
  validateWithSchema( outputSchema, output, `Workflow ${name} output` );
110
110
 
@@ -447,34 +447,6 @@ describe( 'workflow()', () => {
447
447
  } );
448
448
  } );
449
449
 
450
- describe( 'context.control', () => {
451
- it( 'exposes info.workflowId and control/info namespaces when not in workflow context', async () => {
452
- inWorkflowContextMock.mockReturnValue( false );
453
- const { workflow } = await import( './workflow.js' );
454
-
455
- const wf = workflow( {
456
- name: 'control_wf',
457
- description: 'Control',
458
- inputSchema: z.object( {} ),
459
- outputSchema: z.object( {
460
- workflowId: z.string(),
461
- hasControl: z.boolean(),
462
- hasInfo: z.boolean()
463
- } ),
464
- fn: async ( _, context ) => ( {
465
- workflowId: context.info?.workflowId,
466
- hasControl: 'control' in context,
467
- hasInfo: 'info' in context
468
- } )
469
- } );
470
-
471
- const result = await wf( {} );
472
- expect( result.workflowId ).toBe( 'test-workflow' );
473
- expect( result.hasControl ).toBe( true );
474
- expect( result.hasInfo ).toBe( true );
475
- } );
476
- } );
477
-
478
450
  describe( 'error handling (root workflow)', () => {
479
451
  it( 'rethrows error from fn and rejects with same message', async () => {
480
452
  const { workflow } = await import( './workflow.js' );
@@ -33,6 +33,14 @@ export function throws( error: Error ): void;
33
33
  */
34
34
  export function setMetadata( target: object, value: object ): void;
35
35
 
36
+ /**
37
+ * Read metadata previously attached via setMetadata.
38
+ *
39
+ * @param target - The function or object to read metadata from.
40
+ * @returns The metadata object, or null if none is attached.
41
+ */
42
+ export function getMetadata( target: Function ): { name: string; description?: string; type?: string } | null;
43
+
36
44
  /** Represents a {Response} serialized to plain object */
37
45
  export type SerializedFetchResponse = {
38
46
  /** The response url */
@@ -8,8 +8,10 @@ const transformSeparators = path => path.replaceAll( '/', SEP );
8
8
  const defaultIgnorePaths = [
9
9
  '/@output.ai/core/',
10
10
  '/@output.ai/llm/',
11
+ '/@output.ai/evals/',
11
12
  '/sdk/core/',
12
13
  '/sdk/llm/',
14
+ '/sdk/evals/',
13
15
  'node:internal/',
14
16
  'evalmachine.',
15
17
  'webpack/bootstrap'
@@ -37,6 +37,13 @@ export const throws = e => {
37
37
  export const setMetadata = ( target, values ) =>
38
38
  Object.defineProperty( target, METADATA_ACCESS_SYMBOL, { value: values, writable: false, enumerable: false, configurable: false } );
39
39
 
40
+ /**
41
+ * Read metadata previously attached via setMetadata
42
+ * @param {Function} target
43
+ * @returns {object|null}
44
+ */
45
+ export const getMetadata = target => target[METADATA_ACCESS_SYMBOL] ?? null;
46
+
40
47
  /**
41
48
  * Returns true if string value is stringbool and true
42
49
  * @param {string} v
@@ -6,6 +6,17 @@ const workerDir = __dirname; // sdk/core/src/worker
6
6
  const interfaceDir = join( __dirname, '..', 'interface' );
7
7
 
8
8
  export const webpackConfigHook = config => {
9
+ // Prefer the "output-workflow-bundle" export condition when resolving packages.
10
+ // Packages that transitively depend on Node.js built-ins (which can't exist in the
11
+ // Temporal workflow bundle) can provide an alternative entry point under this condition
12
+ // that excludes the offending code paths. Packages without this condition fall through
13
+ // to the standard "import" / "module" / "default" conditions as normal.
14
+ config.resolve = config.resolve ?? {};
15
+ config.resolve.conditionNames = [
16
+ 'output-workflow-bundle',
17
+ ...( config.resolve.conditionNames ?? [ 'import', 'module', 'webpack', 'default' ] )
18
+ ];
19
+
9
20
  config.module = config.module ?? { };
10
21
  config.module.rules = config.module.rules ?? [];
11
22
 
@@ -295,19 +295,46 @@ export const resolveNameFromOptions = ( optionsNode, consts, errorMessagePrefix
295
295
  throw new Error( `${errorMessagePrefix}: Missing required name property` ); // No name field found
296
296
  };
297
297
 
298
+ /**
299
+ * Resolve a name from the first argument of a factory call.
300
+ * Handles two patterns:
301
+ * - String literal first arg: `verify('name', fn)` → returns 'name'
302
+ * - Identifier referencing top-level const: `verify(NAME, fn)` → resolves const
303
+ * - Object with name property: `evaluator({ name: '...' })` → delegates to resolveNameFromOptions
304
+ *
305
+ * @param {import('@babel/types').Expression} argNode - First argument to the factory call.
306
+ * @param {Map<string,string>} consts - Top-level const string bindings.
307
+ * @param {string} errorMessagePrefix - Prefix used when throwing validation errors.
308
+ * @returns {string} Resolved name.
309
+ * @throws {Error} When name is missing or not a supported static form.
310
+ */
311
+ export const resolveNameFromArg = ( argNode, consts, errorMessagePrefix ) => {
312
+ if ( isStringLiteral( argNode ) ) {
313
+ return argNode.value;
314
+ }
315
+ if ( isIdentifier( argNode ) && consts.has( argNode.name ) ) {
316
+ return consts.get( argNode.name );
317
+ }
318
+ return resolveNameFromOptions( argNode, consts, errorMessagePrefix );
319
+ };
320
+
298
321
  /**
299
322
  * Build a map of exported component identifiers to declared names by scanning a module.
300
- * Coerces only static, analyzable forms: `export const X = callee({ name: '...' })`.
323
+ * Matches any `export const X = identifier(...)` pattern — the callee name is intentionally
324
+ * unchecked because:
325
+ * - File path scoping (steps.js, evaluators.js) already constrains which files are parsed
326
+ * - External packages may define custom factory wrappers (e.g., verify() wraps evaluator())
327
+ * - Runtime metadata validation is the authoritative check for component type
328
+ * - Name extraction (resolveNameFromArg) rejects calls without a static name argument
301
329
  *
302
330
  * @param {object} params
303
331
  * @param {string} params.path - Absolute path to the module file.
304
332
  * @param {Map<string, Map<string,string>>} params.cache - Cache for memoizing results by file path.
305
- * @param {('step'|'evaluator')} params.calleeName - Factory function identifier to match.
306
333
  * @param {string} params.invalidMessagePrefix - Prefix used in thrown errors when name is invalid.
307
334
  * @returns {Map<string,string>} Map of `exportedIdentifier` -> `declaredName`.
308
335
  * @throws {Error} When names are missing, dynamic, or otherwise non-static.
309
336
  */
310
- const buildComponentNameMap = ( { path, cache, calleeName, invalidMessagePrefix } ) => {
337
+ const buildComponentNameMap = ( { path, cache, invalidMessagePrefix } ) => {
311
338
  if ( cache.has( path ) ) {
312
339
  return cache.get( path );
313
340
  }
@@ -319,10 +346,10 @@ const buildComponentNameMap = ( { path, cache, calleeName, invalidMessagePrefix
319
346
  .filter( node => isExportNamedDeclaration( node ) && isVariableDeclaration( node.declaration ) )
320
347
  .reduce( ( map, node ) => {
321
348
  node.declaration.declarations
322
- .filter( dec => isIdentifier( dec.id ) && isCallExpression( dec.init ) && isIdentifier( dec.init.callee, { name: calleeName } ) )
349
+ .filter( dec => isIdentifier( dec.id ) && isCallExpression( dec.init ) && isIdentifier( dec.init.callee ) )
323
350
  .map( dec => [
324
351
  dec,
325
- resolveNameFromOptions( dec.init.arguments[0], consts, `${invalidMessagePrefix} ${path} for "${dec.id.name}"` )
352
+ resolveNameFromArg( dec.init.arguments[0], consts, `${invalidMessagePrefix} ${path} for "${dec.id.name}"` )
326
353
  ] )
327
354
  .forEach( ( [ dec, name ] ) => map.set( dec.id.name, name ) );
328
355
  return map;
@@ -335,7 +362,6 @@ const buildComponentNameMap = ( { path, cache, calleeName, invalidMessagePrefix
335
362
  export const buildStepsNameMap = ( path, cache ) => buildComponentNameMap( {
336
363
  path,
337
364
  cache,
338
- calleeName: 'step',
339
365
  invalidMessagePrefix: 'Invalid step name in'
340
366
  } );
341
367
 
@@ -351,13 +377,13 @@ export const buildStepsNameMap = ( path, cache ) => buildComponentNameMap( {
351
377
  export const buildSharedStepsNameMap = ( path, cache ) => buildComponentNameMap( {
352
378
  path,
353
379
  cache,
354
- calleeName: 'step',
355
380
  invalidMessagePrefix: 'Invalid shared step name in'
356
381
  } );
357
382
 
358
383
  /**
359
384
  * Build a map from exported evaluator identifier to declared evaluator name.
360
- * Parses `evaluators.js` for `export const X = evaluator({ name: '...' })`.
385
+ * Matches `export const X = evaluator({ name: '...' })` and wrapper patterns
386
+ * like `export const X = verify('name', fn)`.
361
387
  *
362
388
  * @param {string} path - Absolute path to the evaluators module file.
363
389
  * @param {Map<string, Map<string,string>>} cache - Cache of computed evaluator name maps.
@@ -367,7 +393,6 @@ export const buildSharedStepsNameMap = ( path, cache ) => buildComponentNameMap(
367
393
  export const buildEvaluatorsNameMap = ( path, cache ) => buildComponentNameMap( {
368
394
  path,
369
395
  cache,
370
- calleeName: 'evaluator',
371
396
  invalidMessagePrefix: 'Invalid evaluator name in'
372
397
  } );
373
398
 
@@ -383,7 +408,6 @@ export const buildEvaluatorsNameMap = ( path, cache ) => buildComponentNameMap(
383
408
  export const buildSharedEvaluatorsNameMap = ( path, cache ) => buildComponentNameMap( {
384
409
  path,
385
410
  cache,
386
- calleeName: 'evaluator',
387
411
  invalidMessagePrefix: 'Invalid shared evaluator name in'
388
412
  } );
389
413
 
@@ -411,8 +435,8 @@ export const buildWorkflowNameMap = ( path, cache ) => {
411
435
  if ( isExportNamedDeclaration( node ) && isVariableDeclaration( node.declaration ) ) {
412
436
 
413
437
  for ( const d of node.declaration.declarations ) {
414
- if ( isIdentifier( d.id ) && isCallExpression( d.init ) && isIdentifier( d.init.callee, { name: 'workflow' } ) ) {
415
- const name = resolveNameFromOptions( d.init.arguments[0], consts, `Invalid workflow name in ${path} for '${d.id.name}` );
438
+ if ( isIdentifier( d.id ) && isCallExpression( d.init ) && isIdentifier( d.init.callee ) ) {
439
+ const name = resolveNameFromArg( d.init.arguments[0], consts, `Invalid workflow name in ${path} for '${d.id.name}` );
416
440
  if ( name ) {
417
441
  result.named.set( d.id.name, name );
418
442
  }
@@ -423,9 +447,9 @@ export const buildWorkflowNameMap = ( path, cache ) => {
423
447
  } else if (
424
448
  isExportDefaultDeclaration( node ) &&
425
449
  isCallExpression( node.declaration ) &&
426
- isIdentifier( node.declaration.callee, { name: 'workflow' } )
450
+ isIdentifier( node.declaration.callee )
427
451
  ) {
428
- result.default = resolveNameFromOptions( node.declaration.arguments[0], consts, `Invalid default workflow name in ${path}` );
452
+ result.default = resolveNameFromArg( node.declaration.arguments[0], consts, `Invalid default workflow name in ${path}` );
429
453
  }
430
454
  }
431
455
 
@@ -17,6 +17,7 @@ import {
17
17
  isSharedEvaluatorsPath,
18
18
  isWorkflowPath,
19
19
  createThisMethodCall,
20
+ resolveNameFromArg,
20
21
  resolveNameFromOptions,
21
22
  buildStepsNameMap,
22
23
  buildSharedStepsNameMap,
@@ -258,4 +259,72 @@ describe( 'workflow_rewriter tools', () => {
258
259
  expect( getFileKind( '/p/utils.js' ) ).toBe( null );
259
260
  expect( getFileKind( '/p/clients/api.js' ) ).toBe( null );
260
261
  } );
262
+
263
+ it( 'resolveNameFromArg: resolves string literal directly', () => {
264
+ expect( resolveNameFromArg( t.stringLiteral( 'my_name' ), new Map(), 'X' ) ).toBe( 'my_name' );
265
+ } );
266
+
267
+ it( 'resolveNameFromArg: resolves identifier from consts', () => {
268
+ const consts = new Map( [ [ 'MY_NAME', 'resolved_name' ] ] );
269
+ expect( resolveNameFromArg( t.identifier( 'MY_NAME' ), consts, 'X' ) ).toBe( 'resolved_name' );
270
+ } );
271
+
272
+ it( 'resolveNameFromArg: falls back to resolveNameFromOptions for objects', () => {
273
+ const opts = t.objectExpression( [ t.objectProperty( t.identifier( 'name' ), t.stringLiteral( 'obj_name' ) ) ] );
274
+ expect( resolveNameFromArg( opts, new Map(), 'X' ) ).toBe( 'obj_name' );
275
+ } );
276
+
277
+ it( 'buildEvaluatorsNameMap: reads names from string-arg factory pattern', () => {
278
+ const dir = mkdtempSync( join( tmpdir(), 'tools-verify-evals-' ) );
279
+ const evalsPath = join( dir, 'evaluators.js' );
280
+ writeFileSync( evalsPath, 'export const EvalA = verify( \'eval_a\', async () => {} )' );
281
+ const cache = new Map();
282
+ const map = buildEvaluatorsNameMap( evalsPath, cache );
283
+ expect( map.get( 'EvalA' ) ).toBe( 'eval_a' );
284
+ rmSync( dir, { recursive: true, force: true } );
285
+ } );
286
+
287
+ it( 'buildEvaluatorsNameMap: reads names from object-arg verify pattern', () => {
288
+ const dir = mkdtempSync( join( tmpdir(), 'tools-verify-obj-evals-' ) );
289
+ const evalsPath = join( dir, 'evaluators.js' );
290
+ writeFileSync( evalsPath, 'export const EvalA = verify( { name: \'eval_a\' }, async () => {} )' );
291
+ const cache = new Map();
292
+ const map = buildEvaluatorsNameMap( evalsPath, cache );
293
+ expect( map.get( 'EvalA' ) ).toBe( 'eval_a' );
294
+ rmSync( dir, { recursive: true, force: true } );
295
+ } );
296
+
297
+ it( 'buildEvaluatorsNameMap: reads names from mixed factory patterns', () => {
298
+ const dir = mkdtempSync( join( tmpdir(), 'tools-mixed-evals-' ) );
299
+ const evalsPath = join( dir, 'evaluators.js' );
300
+ writeFileSync( evalsPath, [
301
+ 'export const EvalA = verify( { name: \'eval_a\' }, async () => {} )',
302
+ 'export const EvalB = evaluator( { name: \'eval_b\' } )'
303
+ ].join( '\n' ) );
304
+ const cache = new Map();
305
+ const map = buildEvaluatorsNameMap( evalsPath, cache );
306
+ expect( map.get( 'EvalA' ) ).toBe( 'eval_a' );
307
+ expect( map.get( 'EvalB' ) ).toBe( 'eval_b' );
308
+ rmSync( dir, { recursive: true, force: true } );
309
+ } );
310
+
311
+ it( 'buildStepsNameMap: reads names from string-arg factory pattern', () => {
312
+ const dir = mkdtempSync( join( tmpdir(), 'tools-verify-steps-' ) );
313
+ const stepsPath = join( dir, 'steps.js' );
314
+ writeFileSync( stepsPath, 'export const StepA = myStepHelper( \'step_a\', async () => {} )' );
315
+ const cache = new Map();
316
+ const map = buildStepsNameMap( stepsPath, cache );
317
+ expect( map.get( 'StepA' ) ).toBe( 'step_a' );
318
+ rmSync( dir, { recursive: true, force: true } );
319
+ } );
320
+
321
+ it( 'buildWorkflowNameMap: reads names from string-arg factory pattern', () => {
322
+ const dir = mkdtempSync( join( tmpdir(), 'tools-verify-workflow-' ) );
323
+ const wfPath = join( dir, 'workflow.js' );
324
+ writeFileSync( wfPath, 'export default myWorkflowHelper( { name: \'my_flow\' } )' );
325
+ const cache = new Map();
326
+ const res = buildWorkflowNameMap( wfPath, cache );
327
+ expect( res.default ).toBe( 'my_flow' );
328
+ rmSync( dir, { recursive: true, force: true } );
329
+ } );
261
330
  } );
@@ -76,66 +76,70 @@ const obj = {};`;
76
76
  rmSync( dir, { recursive: true, force: true } );
77
77
  } );
78
78
 
79
- it( 'throws when ESM import from evaluators.js uses step() instead of evaluator()', () => {
79
+ it( 'resolves ESM import from evaluators.js regardless of callee name', () => {
80
80
  const dir = mkdtempSync( join( tmpdir(), 'collect-esm-mismatch-eval-' ) );
81
- writeFileSync( join( dir, 'evaluators.js' ), 'export const BadExport = step({ name: \'bad\' });' );
81
+ writeFileSync( join( dir, 'evaluators.js' ), 'export const MyExport = step({ name: \'bad\' });' );
82
82
 
83
- const source = 'import { BadExport } from \'./evaluators.js\';';
83
+ const source = 'import { MyExport } from \'./evaluators.js\';';
84
84
  const ast = makeAst( source, join( dir, 'file.js' ) );
85
85
 
86
- expect( () => collectTargetImports(
86
+ const { evaluatorImports } = collectTargetImports(
87
87
  ast,
88
88
  dir,
89
89
  { stepsNameCache: new Map(), evaluatorsNameCache: new Map(), workflowNameCache: new Map() }
90
- ) ).toThrow( /Unresolved import 'BadExport' from evaluators file/ );
90
+ );
91
+ expect( evaluatorImports ).toEqual( [ { localName: 'MyExport', evaluatorName: 'bad' } ] );
91
92
 
92
93
  rmSync( dir, { recursive: true, force: true } );
93
94
  } );
94
95
 
95
- it( 'throws when ESM import from steps.js uses evaluator() instead of step()', () => {
96
+ it( 'resolves ESM import from steps.js regardless of callee name', () => {
96
97
  const dir = mkdtempSync( join( tmpdir(), 'collect-esm-mismatch-step-' ) );
97
- writeFileSync( join( dir, 'steps.js' ), 'export const BadExport = evaluator({ name: \'bad\' });' );
98
+ writeFileSync( join( dir, 'steps.js' ), 'export const MyExport = evaluator({ name: \'bad\' });' );
98
99
 
99
- const source = 'import { BadExport } from \'./steps.js\';';
100
+ const source = 'import { MyExport } from \'./steps.js\';';
100
101
  const ast = makeAst( source, join( dir, 'file.js' ) );
101
102
 
102
- expect( () => collectTargetImports(
103
+ const { stepImports } = collectTargetImports(
103
104
  ast,
104
105
  dir,
105
106
  { stepsNameCache: new Map(), evaluatorsNameCache: new Map(), workflowNameCache: new Map() }
106
- ) ).toThrow( /Unresolved import 'BadExport' from steps file/ );
107
+ );
108
+ expect( stepImports ).toEqual( [ { localName: 'MyExport', stepName: 'bad' } ] );
107
109
 
108
110
  rmSync( dir, { recursive: true, force: true } );
109
111
  } );
110
112
 
111
- it( 'throws when CJS require from evaluators.js uses step() instead of evaluator()', () => {
113
+ it( 'resolves CJS require from evaluators.js regardless of callee name', () => {
112
114
  const dir = mkdtempSync( join( tmpdir(), 'collect-cjs-mismatch-eval-' ) );
113
- writeFileSync( join( dir, 'evaluators.js' ), 'export const BadExport = step({ name: \'bad\' });' );
115
+ writeFileSync( join( dir, 'evaluators.js' ), 'export const MyExport = step({ name: \'bad\' });' );
114
116
 
115
- const source = 'const { BadExport } = require( \'./evaluators.js\' );';
117
+ const source = 'const { MyExport } = require( \'./evaluators.js\' );';
116
118
  const ast = makeAst( source, join( dir, 'file.js' ) );
117
119
 
118
- expect( () => collectTargetImports(
120
+ const { evaluatorImports } = collectTargetImports(
119
121
  ast,
120
122
  dir,
121
123
  { stepsNameCache: new Map(), evaluatorsNameCache: new Map(), workflowNameCache: new Map() }
122
- ) ).toThrow( /Unresolved import 'BadExport' from evaluators file/ );
124
+ );
125
+ expect( evaluatorImports ).toEqual( [ { localName: 'MyExport', evaluatorName: 'bad' } ] );
123
126
 
124
127
  rmSync( dir, { recursive: true, force: true } );
125
128
  } );
126
129
 
127
- it( 'throws when CJS require from steps.js uses evaluator() instead of step()', () => {
130
+ it( 'resolves CJS require from steps.js regardless of callee name', () => {
128
131
  const dir = mkdtempSync( join( tmpdir(), 'collect-cjs-mismatch-step-' ) );
129
- writeFileSync( join( dir, 'steps.js' ), 'export const BadExport = evaluator({ name: \'bad\' });' );
132
+ writeFileSync( join( dir, 'steps.js' ), 'export const MyExport = evaluator({ name: \'bad\' });' );
130
133
 
131
- const source = 'const { BadExport } = require( \'./steps.js\' );';
134
+ const source = 'const { MyExport } = require( \'./steps.js\' );';
132
135
  const ast = makeAst( source, join( dir, 'file.js' ) );
133
136
 
134
- expect( () => collectTargetImports(
137
+ const { stepImports } = collectTargetImports(
135
138
  ast,
136
139
  dir,
137
140
  { stepsNameCache: new Map(), evaluatorsNameCache: new Map(), workflowNameCache: new Map() }
138
- ) ).toThrow( /Unresolved import 'BadExport' from steps file/ );
141
+ );
142
+ expect( stepImports ).toEqual( [ { localName: 'MyExport', stepName: 'bad' } ] );
139
143
 
140
144
  rmSync( dir, { recursive: true, force: true } );
141
145
  } );
@@ -259,19 +263,19 @@ const obj = {};`;
259
263
  rmSync( dir, { recursive: true, force: true } );
260
264
  } );
261
265
 
262
- it( 'throws when CJS shared steps require uses evaluator() instead of step()', () => {
266
+ it( 'resolves CJS shared steps require regardless of callee name', () => {
263
267
  const dir = mkdtempSync( join( tmpdir(), 'collect-cjs-shared-step-mismatch-' ) );
264
268
  mkdirSync( join( dir, 'shared', 'steps' ), { recursive: true } );
265
269
  mkdirSync( join( dir, 'workflows', 'my_workflow' ), { recursive: true } );
266
270
  writeFileSync(
267
271
  join( dir, 'shared', 'steps', 'common.js' ),
268
- 'export const BadExport = evaluator({ name: \'bad\' });'
272
+ 'export const MyExport = evaluator({ name: \'bad\' });'
269
273
  );
270
274
 
271
- const source = 'const { BadExport } = require( \'../../shared/steps/common.js\' );';
275
+ const source = 'const { MyExport } = require( \'../../shared/steps/common.js\' );';
272
276
  const ast = makeAst( source, join( dir, 'workflows', 'my_workflow', 'workflow.js' ) );
273
277
 
274
- expect( () => collectTargetImports(
278
+ const { sharedStepImports } = collectTargetImports(
275
279
  ast,
276
280
  join( dir, 'workflows', 'my_workflow' ),
277
281
  {
@@ -279,49 +283,52 @@ const obj = {};`;
279
283
  evaluatorsNameCache: new Map(), sharedEvaluatorsNameCache: new Map(),
280
284
  workflowNameCache: new Map()
281
285
  }
282
- ) ).toThrow( /Unresolved import 'BadExport' from shared steps file/ );
286
+ );
287
+ expect( sharedStepImports ).toEqual( [ { localName: 'MyExport', stepName: 'bad' } ] );
283
288
 
284
289
  rmSync( dir, { recursive: true, force: true } );
285
290
  } );
286
291
 
287
- it( 'throws when CJS shared evaluator require uses step() instead of evaluator()', () => {
292
+ it( 'resolves CJS shared evaluator require regardless of callee name', () => {
288
293
  const dir = mkdtempSync( join( tmpdir(), 'collect-cjs-shared-eval-mismatch-' ) );
289
294
  mkdirSync( join( dir, 'shared', 'evaluators' ), { recursive: true } );
290
295
  mkdirSync( join( dir, 'workflows', 'my_workflow' ), { recursive: true } );
291
296
  writeFileSync(
292
297
  join( dir, 'shared', 'evaluators', 'common.js' ),
293
- 'export const BadExport = step({ name: \'bad\' });'
298
+ 'export const MyExport = step({ name: \'bad\' });'
294
299
  );
295
300
 
296
- const source = 'const { BadExport } = require( \'../../shared/evaluators/common.js\' );';
301
+ const source = 'const { MyExport } = require( \'../../shared/evaluators/common.js\' );';
297
302
  const ast = makeAst( source, join( dir, 'workflows', 'my_workflow', 'workflow.js' ) );
298
303
 
299
- expect( () => collectTargetImports(
304
+ const { sharedEvaluatorImports } = collectTargetImports(
300
305
  ast,
301
306
  join( dir, 'workflows', 'my_workflow' ),
302
307
  { stepsNameCache: new Map(), evaluatorsNameCache: new Map(), sharedEvaluatorsNameCache: new Map(), workflowNameCache: new Map() }
303
- ) ).toThrow( /Unresolved import 'BadExport' from shared evaluators file/ );
308
+ );
309
+ expect( sharedEvaluatorImports ).toEqual( [ { localName: 'MyExport', evaluatorName: 'bad' } ] );
304
310
 
305
311
  rmSync( dir, { recursive: true, force: true } );
306
312
  } );
307
313
 
308
- it( 'throws when ESM shared evaluator import uses step() instead of evaluator()', () => {
314
+ it( 'resolves ESM shared evaluator import regardless of callee name', () => {
309
315
  const dir = mkdtempSync( join( tmpdir(), 'collect-esm-shared-eval-mismatch-' ) );
310
316
  mkdirSync( join( dir, 'shared', 'evaluators' ), { recursive: true } );
311
317
  mkdirSync( join( dir, 'workflows', 'my_workflow' ), { recursive: true } );
312
318
  writeFileSync(
313
319
  join( dir, 'shared', 'evaluators', 'common.js' ),
314
- 'export const BadExport = step({ name: \'bad\' });'
320
+ 'export const MyExport = step({ name: \'bad\' });'
315
321
  );
316
322
 
317
- const source = 'import { BadExport } from \'../../shared/evaluators/common.js\';';
323
+ const source = 'import { MyExport } from \'../../shared/evaluators/common.js\';';
318
324
  const ast = makeAst( source, join( dir, 'workflows', 'my_workflow', 'workflow.js' ) );
319
325
 
320
- expect( () => collectTargetImports(
326
+ const { sharedEvaluatorImports } = collectTargetImports(
321
327
  ast,
322
328
  join( dir, 'workflows', 'my_workflow' ),
323
329
  { stepsNameCache: new Map(), evaluatorsNameCache: new Map(), sharedEvaluatorsNameCache: new Map(), workflowNameCache: new Map() }
324
- ) ).toThrow( /Unresolved import 'BadExport' from shared evaluators file/ );
330
+ );
331
+ expect( sharedEvaluatorImports ).toEqual( [ { localName: 'MyExport', evaluatorName: 'bad' } ] );
325
332
 
326
333
  rmSync( dir, { recursive: true, force: true } );
327
334
  } );
@@ -285,12 +285,12 @@ describe( 'workflow_validator loader', () => {
285
285
  rmSync( dir, { recursive: true, force: true } );
286
286
  } );
287
287
 
288
- it( 'workflow.js: allows imports from ../../shared/clients/pokeapi.js', async () => {
289
- const dir = mkdtempSync( join( tmpdir(), 'wf-shared-clients-' ) );
288
+ it( 'workflow.js: allows imports from ../../clients/pokeapi.js', async () => {
289
+ const dir = mkdtempSync( join( tmpdir(), 'wf-clients-' ) );
290
290
  mkdirSync( join( dir, 'workflows', 'my_workflow' ), { recursive: true } );
291
- mkdirSync( join( dir, 'shared', 'clients' ), { recursive: true } );
292
- writeFileSync( join( dir, 'shared', 'clients', 'pokeapi.js' ), 'export const getPokemon = () => {};\n' );
293
- const src = 'import { getPokemon } from "../../shared/clients/pokeapi.js";';
291
+ mkdirSync( join( dir, 'clients' ), { recursive: true } );
292
+ writeFileSync( join( dir, 'clients', 'pokeapi.js' ), 'export const getPokemon = () => {};\n' );
293
+ const src = 'import { getPokemon } from "../../clients/pokeapi.js";';
294
294
  await expect( runLoader( join( dir, 'workflows', 'my_workflow', 'workflow.js' ), src ) ).resolves.toBeTruthy();
295
295
  rmSync( dir, { recursive: true, force: true } );
296
296
  } );
@@ -305,12 +305,12 @@ describe( 'workflow_validator loader', () => {
305
305
  rmSync( dir, { recursive: true, force: true } );
306
306
  } );
307
307
 
308
- it( 'steps.ts: allows imports from ../../shared/clients/redis.js', async () => {
309
- const dir = mkdtempSync( join( tmpdir(), 'steps-shared-clients-' ) );
308
+ it( 'steps.ts: allows imports from ../../clients/redis.js', async () => {
309
+ const dir = mkdtempSync( join( tmpdir(), 'steps-clients-' ) );
310
310
  mkdirSync( join( dir, 'workflows', 'my_workflow' ), { recursive: true } );
311
- mkdirSync( join( dir, 'shared', 'clients' ), { recursive: true } );
312
- writeFileSync( join( dir, 'shared', 'clients', 'redis.js' ), 'export const client = {};\n' );
313
- const src = 'import { client } from "../../shared/clients/redis.js";';
311
+ mkdirSync( join( dir, 'clients' ), { recursive: true } );
312
+ writeFileSync( join( dir, 'clients', 'redis.js' ), 'export const client = {};\n' );
313
+ const src = 'import { client } from "../../clients/redis.js";';
314
314
  await expect( runLoader( join( dir, 'workflows', 'my_workflow', 'steps.js' ), src ) ).resolves.toBeTruthy();
315
315
  rmSync( dir, { recursive: true, force: true } );
316
316
  } );