diff --git a/packages/cli/src/util/load-plan.ts b/packages/cli/src/util/load-plan.ts index 9c41550ed..d0d3545d0 100644 --- a/packages/cli/src/util/load-plan.ts +++ b/packages/cli/src/util/load-plan.ts @@ -19,6 +19,7 @@ const loadPlan = async ( | 'adaptors' | 'baseDir' | 'expandAdaptors' + | 'statePath' >, logger: Logger ): Promise => { @@ -203,6 +204,9 @@ const importExpressions = async ( typeof job.expression === 'string' && job.expression?.trim(); const configurationStr = typeof job.configuration === 'string' && job.configuration?.trim(); + const stateStr = + typeof job.state === 'string' && job.state?.trim(); + if (expressionStr && isPath(expressionStr)) { job.expression = await fetchFile( job.id || `${idx}`, @@ -220,6 +224,27 @@ const importExpressions = async ( ); job.configuration = JSON.parse(configString!); } + + if (stateStr && isPath(stateStr)) { + const stateString = await fetchFile( + job.id || `${idx}`, + rootDir, + stateStr, + log + ); + job.state = JSON.parse(stateString!); + } + + const state = job.state + if (typeof state === 'object' && state !== null) { + const keys = Object.keys(state); + for (const key of keys) { + if (typeof state[key] === 'string' && isPath(state[key])) { + const fileContent = await fetchFile(job.id || `${idx}`, rootDir, state[key], log); + state[key] = JSON.parse(fileContent); + } + } + } } }; diff --git a/packages/cli/test/util/load-plan.test.ts b/packages/cli/test/util/load-plan.test.ts index caadaad71..a4473061b 100644 --- a/packages/cli/test/util/load-plan.test.ts +++ b/packages/cli/test/util/load-plan.test.ts @@ -48,7 +48,7 @@ test.serial('expression: load a plan from an expression.js', async (t) => { plan: {}, }; - const plan = await loadPlan(opts as Opts, logger); + const plan = await loadPlan(opts as unknown as Opts, logger); t.truthy(plan); t.deepEqual(plan.options, {}); @@ -118,7 +118,7 @@ test.serial('xplan: load a plan from workflow path', async (t) => { plan: {}, }; - const plan = await loadPlan(opts as Opts, logger); + const plan = await loadPlan(opts as unknown as Opts, logger); t.truthy(plan); t.deepEqual(plan, sampleXPlan); @@ -143,7 +143,7 @@ test.serial('xplan: expand adaptors', async (t) => { 'test/wf.json': JSON.stringify(plan), }); - const result = await loadPlan(opts as Opts, logger); + const result = await loadPlan(opts as unknown as Opts, logger); t.truthy(result); const step = result.workflow.steps[0] as Job; @@ -169,7 +169,7 @@ test.serial('xplan: do not expand adaptors', async (t) => { 'test/wf.json': JSON.stringify(plan), }); - const result = await loadPlan(opts as Opts, logger); + const result = await loadPlan(opts as unknown as Opts, logger); t.truthy(result); const step = result.workflow.steps[0] as Job; @@ -197,7 +197,7 @@ test.serial('xplan: set timeout from CLI', async (t) => { 'test/wf.json': JSON.stringify(plan), }); - const { options } = await loadPlan(opts as Opts, logger); + const { options } = await loadPlan(opts as unknown as Opts, logger); t.is(options.timeout, 666); }); @@ -222,7 +222,7 @@ test.serial('xplan: set start from CLI', async (t) => { 'test/wf.json': JSON.stringify(plan), }); - const { options } = await loadPlan(opts as Opts, logger); + const { options } = await loadPlan(opts as unknown as Opts, logger); t.is(options.start, 'b'); }); @@ -259,7 +259,7 @@ test.serial('old-workflow: load a plan from workflow path', async (t) => { plan: {}, }; - const plan = await loadPlan(opts as Opts, logger); + const plan = await loadPlan(opts as unknown as Opts, logger); t.deepEqual(plan.options, { start: 'a', @@ -271,3 +271,35 @@ test.serial('old-workflow: load a plan from workflow path', async (t) => { expression: 'x()', }); }); + +test.serial('step: allow file paths for state and data', async (t) => { + const opts = { + workflowPath: 'test/wf.json', + plan: {}, + }; + + const plan = createPlan([ + { + id: 'a', + expression: '.', + state: './state.json', + }, + ]); + + mock({ + 'test/data.json': JSON.stringify({ x: 1 }), + 'test/state.json': JSON.stringify({ + data: "./data.json" + }), + 'test/wf.json': JSON.stringify(plan), + }); + const result = await loadPlan(opts as unknown as Opts, logger); + t.truthy(result); + + const step = result.workflow.steps[0] as Job; + t.deepEqual(step.state, { + data: { + x: 1 + } + }); +}); \ No newline at end of file