@@ -5,6 +5,7 @@ import run from '../src/run';
55import createLightningServer from '@openfn/lightning-mock' ;
66import { extractLogs , assertLog } from '../src/util' ;
77import { rimraf } from 'rimraf' ;
8+ import { makeProject } from './fixtures/projects' ;
89
910let server : any ;
1011const port = 8967 ;
@@ -196,6 +197,78 @@ test.serial('pull a project', async (t) => {
196197 t . is ( workflow . version_history . length , 1 ) ;
197198} ) ;
198199
200+ test . serial ( 'redirect to v2 protocol if openfn.yaml is present' , async ( t ) => {
201+ const projectId = 'redirect-test-1' ;
202+ server . addProject ( makeProject ( projectId ) as any ) ;
203+
204+ // create an empty openfn.yaml to trigger the v1 -> v2 redirect
205+ await fs . writeFile ( path . join ( tmpDir , 'openfn.yaml' ) , '' ) ;
206+
207+ const bootstrap = await run (
208+ `openfn pull ${ projectId } --workspace ${ tmpDir } --log-json -l debug`
209+ ) ;
210+ t . falsy ( bootstrap . stderr ) ;
211+ assertLog ( t , extractLogs ( bootstrap . stdout ) , / D e t e c t e d o p e n f n .y a m l f i l e / i) ;
212+
213+ const yaml = await fs . readFile ( path . join ( tmpDir , 'openfn.yaml' ) , 'utf8' ) ;
214+ t . regex ( yaml , new RegExp ( `uuid\\: ${ projectId } ` ) ) ;
215+
216+ const workflowYaml = await fs . readFile (
217+ path . join ( tmpDir , 'workflows/my-workflow/my-workflow.yaml' ) ,
218+ 'utf8'
219+ ) ;
220+ t . regex ( workflowYaml , / i d : m y - w o r k f l o w / ) ;
221+ t . regex ( workflowYaml , / n a m e : M y W o r k f l o w / ) ;
222+ t . regex ( workflowYaml , / e x p r e s s i o n : \. \/ m y - j o b \. j s / ) ;
223+
224+ const stepJs = await fs . readFile (
225+ path . join ( tmpDir , 'workflows/my-workflow/my-job.js' ) ,
226+ 'utf8'
227+ ) ;
228+ t . is ( stepJs , 'fn(s => s)' ) ;
229+
230+ // simulate a remote change
231+ const remoteProject = server . state . projects [ projectId ] ;
232+ const wf = Object . values ( remoteProject . workflows as any ) . find (
233+ ( w : any ) => w . id === 'my-workflow-1'
234+ ) as any ;
235+ server . updateWorkflow ( projectId , {
236+ ...wf ,
237+ jobs : Object . values ( wf . jobs ?? { } ) . map ( ( j : any ) =>
238+ j . id === 'my-job-1'
239+ ? { ...j , body : 'fn(s => ({ ...s, remote: true }))' }
240+ : j
241+ ) ,
242+ } ) ;
243+
244+ // v1 pull -> should redirect to v2 because openfn.yaml exists
245+ const pullResult = await run (
246+ `openfn pull ${ projectId } --workspace ${ tmpDir } --log-json -l debug`
247+ ) ;
248+ t . falsy ( pullResult . stderr ) ;
249+ assertLog ( t , extractLogs ( pullResult . stdout ) , / D e t e c t e d o p e n f n .y a m l f i l e / i) ;
250+
251+ const exprPath = path . join ( tmpDir , 'workflows/my-workflow/my-job.js' ) ;
252+ t . regex ( await fs . readFile ( exprPath , 'utf8' ) , / r e m o t e : t r u e / ) ;
253+
254+ // make a local change
255+ await fs . writeFile ( exprPath , 'fn(s => ({ ...s, local: true }))' ) ;
256+
257+ // v1 deploy -> should redirect to v2
258+ const { stdout, stderr } = await run (
259+ `openfn deploy --workspace ${ tmpDir } --no-confirm --log-json -l debug`
260+ ) ;
261+ t . falsy ( stderr ) ;
262+ assertLog ( t , extractLogs ( stdout ) , / D e t e c t e d o p e n f n .y a m l f i l e / i) ;
263+
264+ // confirm the local change made it to the server
265+ const serverProj = server . state . projects [ projectId ] ;
266+ t . regex (
267+ serverProj . workflows [ 'my-workflow-1' ] . jobs [ 'my-job' ] . body ,
268+ / l o c a l : t r u e /
269+ ) ;
270+ } ) ;
271+
199272test . serial ( 'deploy then pull, changes one workflow, deploy' , async ( t ) => {
200273 t . is ( Object . keys ( server . state . projects ) . length , 0 ) ;
201274
0 commit comments