Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions integration-tests/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# @openfn/integration-tests-cli

## 1.0.38

### Patch Changes

- Updated dependencies [5f265bb]
- Updated dependencies [acb7b26]
- Updated dependencies [5f265bb]
- Updated dependencies [5f265bb]
- Updated dependencies [d52a52c]
- Updated dependencies [5f265bb]
- Updated dependencies [5f265bb]
- @openfn/project@0.23.1
- @openfn/lightning-mock@2.5.8

## 1.0.37

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@openfn/integration-tests-cli",
"private": true,
"version": "1.0.37",
"version": "1.0.38",
"description": "CLI integration tests",
"author": "Open Function Group <admin@openfn.org>",
"license": "ISC",
Expand Down
11 changes: 8 additions & 3 deletions integration-tests/cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import * as path from 'node:path';

const isProd = process.env.NODE_ENV === 'production';

const getOptions = () => ({
const getOptions = (env = {}) => ({
env: {
// there's nobody to answer a prompt (a test can override this)
OPENFN_NO_CONFIRM: 'true',
...process.env,
...env,
OPENFN_REPO_DIR: path.resolve('repo'),
// workspaces live inside the kit git repo: don't pick up its branch
OPENFN_BRANCH: 'false',
Expand All @@ -23,10 +26,12 @@ const mapOpenFnPath = (cmd) => {
};

const run = async (
cmd: string
cmd: string,
// extra environment variables for this command only
env?: Record<string, string>
): Promise<{ stdout: string; stderr?: string; err?: any }> => {
return new Promise((resolve) => {
exec(mapOpenFnPath(cmd), getOptions(), (err, stdout, stderr) => {
exec(mapOpenFnPath(cmd), getOptions(env), (err, stdout, stderr) => {
resolve({ err, stdout, stderr });
});
});
Expand Down
13 changes: 3 additions & 10 deletions integration-tests/cli/test/deploy.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Tests legacy `openfn deploy` and `openfn pull` commands against a mock Lightning

import test from 'ava';
import path from 'node:path';
import fs, { rm } from 'node:fs/promises';
Expand Down Expand Up @@ -157,7 +159,6 @@ test.serial('deploy a local project', async (t) => {
`openfn deploy \
--project-path ${tmpDir}/project.yaml \
--state-path ${tmpDir}/.state.json \
--no-confirm \
--log-json \
-l debug`
);
Expand Down Expand Up @@ -188,7 +189,6 @@ test.serial('Update a project', async (t) => {
const deployCmd = `openfn deploy \
--project-path ${projectPath} \
--state-path ${statePath} \
--no-confirm \
--log-json -l debug`;
const first = await run(deployCmd);
t.falsy(first.stderr);
Expand Down Expand Up @@ -230,7 +230,6 @@ test.serial('pull a project', async (t) => {
const deployCmd = `openfn deploy \
--project-path ${projectPath} \
--state-path ${statePath} \
--no-confirm \
--log-json -l debug`;

await run(deployCmd);
Expand Down Expand Up @@ -323,7 +322,7 @@ test.serial('redirect to v2 protocol if openfn.yaml is present', async (t) => {

// v1 deploy -> should redirect to v2
const { stdout, stderr } = await run(
`openfn deploy --workspace ${tmpDir} --no-confirm --log-json -l debug`
`openfn deploy --workspace ${tmpDir} --log-json -l debug`
);
t.falsy(stderr);
assertLog(t, extractLogs(stdout), /Detected openfn.yaml file/i);
Expand Down Expand Up @@ -364,7 +363,6 @@ workflows:
`openfn deploy \
--project-path ${tmpDir}/project.yaml \
--state-path ${tmpDir}/.state.json \
--no-confirm \
--log-json \
-l debug`
);
Expand Down Expand Up @@ -397,7 +395,6 @@ test.serial('deploy then pull, changes one workflow, deploy', async (t) => {
const deployCmd = `openfn deploy \
--project-path ${projectPath} \
--state-path ${statePath} \
--no-confirm \
--log debug \
--log-json`;
await run(deployCmd);
Expand Down Expand Up @@ -451,7 +448,6 @@ test.serial('deploy a v2 project.yaml', async (t) => {
`openfn deploy \
--project-path ${tmpDir}/project.yaml \
--state-path ${tmpDir}/.state.json \
--no-confirm \
--log-json \
-l debug`
);
Expand Down Expand Up @@ -481,7 +477,6 @@ test.serial('deploy a new v2 project.yaml with credentials', async (t) => {
const { stdout, stderr } = await run(
`openfn deploy \
--project-path ${tmpDir}/project.yaml \
--no-confirm \
--log-json \
-l debug`
);
Expand Down Expand Up @@ -526,7 +521,6 @@ collections:
const deployCmd = `openfn deploy \
--project-path ${projectPath} \
--state-path ${statePath} \
--no-confirm \
--log-json -l debug`;

// first deploy - no collections yet
Expand Down Expand Up @@ -573,7 +567,6 @@ ${collectionsWorkflow}
const deployCmd = `openfn deploy \
--project-path ${projectPath} \
--state-path ${statePath} \
--no-confirm \
--log-json -l debug`;

// first deploy - creates the collection
Expand Down
42 changes: 18 additions & 24 deletions integration-tests/cli/test/deploy.v2.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Tests v2 `openfn project pull` and `openfn project deploy` loop against a mock Lightning

import test from 'ava';
import path from 'node:path';
import fs from 'node:fs/promises';
Expand Down Expand Up @@ -71,7 +73,7 @@ test.serial('pull, change and re-deploy', async (t) => {

// deploy
const { stdout, stderr } = await run(
`openfn project deploy --no-confirm --log-json -l debug`
`openfn project deploy --log-json -l debug`
);
t.falsy(stderr);

Expand Down Expand Up @@ -99,9 +101,7 @@ test.serial('pull, change and re-deploy twice', async (t) => {

// first deploy
await fs.writeFile(exprPath, 'fn(s => ({ ...s, v: 1 }))');
const first = await run(
`openfn project deploy --no-confirm --log-json -l debug`
);
const first = await run(`openfn project deploy --log-json -l debug`);
t.falsy(first.stderr);
assertLog(t, extractLogs(first.stdout), /Updated project/);

Expand All @@ -112,7 +112,7 @@ test.serial('pull, change and re-deploy twice', async (t) => {
// second deploy after another update
await fs.writeFile(exprPath, 'fn(s => ({ ...s, v: 2 }))');
const { stdout, stderr } = await run(
`openfn project deploy --no-confirm --log-json -l debug`
`openfn project deploy --log-json -l debug`
);
t.falsy(stderr);
const logs = extractLogs(stdout);
Expand Down Expand Up @@ -140,9 +140,7 @@ test.serial('deploy and pull to check version history', async (t) => {
await fs.writeFile(exprPath, 'fn(s => ({ ...s, v: 1 }))');

// deploy then pull
const { stderr } = await run(
`openfn project deploy --no-confirm --log-json -l debug`
);
const { stderr } = await run(`openfn project deploy --log-json -l debug`);
t.falsy(stderr);
await run(`openfn project pull ${projectId} --log-json -l debug`);

Expand Down Expand Up @@ -174,7 +172,7 @@ test.serial('deploy then pull, change one workflow, deploy', async (t) => {

// deploy
const { stdout, stderr } = await run(
`openfn project deploy --no-confirm --log-json -l debug`
`openfn project deploy --log-json -l debug`
);
t.falsy(stderr);
const logs = extractLogs(stdout);
Expand Down Expand Up @@ -215,7 +213,7 @@ test.serial('Remove a whole workflow', async (t) => {

// deploy
const { stdout, stderr } = await run(
`openfn project deploy --no-confirm --log-json -l debug`
`openfn project deploy --log-json -l debug`
);
t.falsy(stderr);

Expand Down Expand Up @@ -262,7 +260,7 @@ steps:
await rimraf(path.join(tmpDir, 'workflows/my-workflow/my-job.js'));

const { stdout, stderr } = await run(
`openfn project deploy --no-confirm --log-json -l debug`
`openfn project deploy --log-json -l debug`
);
t.falsy(stderr);

Expand Down Expand Up @@ -317,7 +315,7 @@ steps:
);

const { stdout, stderr } = await run(
`openfn project deploy --no-confirm --log-json -l debug`
`openfn project deploy --log-json -l debug`
);
t.falsy(stderr);

Expand Down Expand Up @@ -372,9 +370,7 @@ test.serial.skip(
await fs.writeFile(exprPath, "post('http://success.org')");

// deploy
const { stdout, stderr } = await run(
`openfn project deploy --no-confirm -l debug`
);
const { stdout, stderr } = await run(`openfn project deploy -l debug`);
console.log(stdout);
t.falsy(stderr);
const logs = extractLogs(stdout);
Expand All @@ -400,9 +396,7 @@ test.serial('warn when local and remote workflows have diverged', async (t) => {
// base
await run(`openfn project pull ${projectId} --log-json -l debug`);
await fs.writeFile(exprPath, 'fn(s => ({ ...s, v: 1 }))');
const firstDeploy = await run(
`openfn project deploy --no-confirm --log-json -l debug`
);
const firstDeploy = await run(`openfn project deploy --log-json -l debug`);
assertLog(t, extractLogs(firstDeploy.stdout), /Updated project/);

// remote changed from base
Expand All @@ -424,7 +418,7 @@ test.serial('warn when local and remote workflows have diverged', async (t) => {

// deploy with divergence
const { stdout, err } = await run(
`openfn project deploy --no-confirm --log-json -l debug`
`openfn project deploy --log-json -l debug`
);
t.truthy(err);
const logs = extractLogs(stdout);
Expand All @@ -448,7 +442,7 @@ test.serial('deploy a pulled v2 state file as a new project', async (t) => {

// deploy that exact file back as a duplicate
const { stdout, stderr } = await run(
`openfn project deploy ${pulledPath} --new --name my-duplicate --no-confirm --log-json -l debug`
`openfn project deploy ${pulledPath} --new --name my-duplicate --log-json -l debug`
);
t.falsy(stderr);

Expand Down Expand Up @@ -506,7 +500,7 @@ test.serial(

// deploy main's pulled file, but target staging instead of main
const { stdout, stderr } = await run(
`openfn project deploy ${mainPath} staging --no-confirm --log-json -l debug`
`openfn project deploy ${mainPath} staging --log-json -l debug`
);
t.falsy(stderr);
assertLog(t, extractLogs(stdout), /Updated project/);
Expand Down Expand Up @@ -553,7 +547,7 @@ test.serial(
await fs.writeFile(resourcesPath, jsonToYaml(before));

const { stdout, stderr } = await run(
`openfn project deploy --no-confirm --log-json -l debug`
`openfn project deploy --log-json -l debug`
);
t.falsy(stderr);

Expand Down Expand Up @@ -596,7 +590,7 @@ workflows:
await fs.writeFile(exportedPath, specYaml);

const { stdout, stderr } = await run(
`openfn project deploy ${exportedPath} --name my-duplicate --no-confirm --log-json -l debug`
`openfn project deploy ${exportedPath} --name my-duplicate --log-json -l debug`
);
t.falsy(stderr);

Expand Down Expand Up @@ -659,7 +653,7 @@ test.serial(
await fs.writeFile(resourcesPath, jsonToYaml(before));

const { stdout, stderr } = await run(
`openfn project deploy --no-confirm --log-json -l debug`
`openfn project deploy --log-json -l debug`
);
t.falsy(stderr);

Expand Down
3 changes: 3 additions & 0 deletions integration-tests/cli/test/project-v1.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Tests offline `openfn checkout`, `merge` and `projects` on static legacy v1 project yaml files
// (no Lightning); see project-v2 for the same commands on v2 files

import test from 'ava';
import { rm, mkdir, writeFile, readFile } from 'node:fs/promises';
import path from 'node:path';
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/cli/test/project-v2.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Tests offline `openfn checkout`, `merge` and `projects` on static v2 project yaml files,
// plus executing a workflow from the checked out project; see project-v1 for the legacy format

import test from 'ava';
import { rm, mkdir, writeFile, readFile } from 'node:fs/promises';
import path from 'node:path';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,15 @@
import test from 'ava';
import path from 'node:path';
import fs from 'node:fs';
import run from '../src/run';
import { generateProject } from '@openfn/project';
import createLightningServer from '@openfn/lightning-mock';
import { rimraf } from 'rimraf';

let PORT = 5353;
let lightning;
const endpoint = `http://localhost:${PORT}/api/provision`;

test.before(async () => {
await rimraf('tmp/sync');

lightning = createLightningServer({
port: PORT,
});
});
// The v2 sync commands (fetch, pull and checkout) against a mock Lightning,
// asserting on what lands on disk (.projects state, checkout.yaml, workflows folder)

const initWorkspace = (t: any) => {
const id = t.title.replaceAll(' ', '_').toLowerCase();
const p = path.resolve('tmp/sync', id);

return {
workspace: p,
read: (filePath: string) => {
return fs.readFileSync(path.resolve(p, filePath), 'utf8');
},
};
};

const gen = (
name = 'patients',
workflows = ['trigger-job(expression="fn()")']
) => {
// generate a project
const project = generateProject(name, workflows, {
openfnUuid: true,
});
const state = project.serialize('state', { format: 'json' });
lightning.addProject(state);
return project;
};
import test from 'ava';
import run from '../../src/run';
import { setup } from './helpers';

const { lightning, endpoint, initWorkspace, gen } = setup(
test,
'commands',
5353
);

test('fetch a new project', async (t) => {
const { workspace, read } = initWorkspace(t);
Expand Down
9 changes: 9 additions & 0 deletions integration-tests/cli/test/sync/conflict.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Cases where the workspace and the remote project have both changed
// (not covered yet: these still need to be specified)

import test from 'ava';

test.todo('rename in the app, then deploy a local edit without pulling');
test.todo('rename a workflow differently in the app and locally');
test.todo('delete a workflow in the app, then deploy a local edit to it');
test.todo('add a workflow with the same name in the app and locally');
Loading
Loading