Skip to content

Commit

Permalink
Runtime: Fix input state assembly (#812)
Browse files Browse the repository at this point in the history
* runtime: restore logic to merge initial state.config in state assembly

* changeset

* version bumps
  • Loading branch information
josephjclark authored Nov 5, 2024
1 parent 9bab572 commit e0e19b2
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 9 deletions.
7 changes: 7 additions & 0 deletions integration-tests/execute/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @openfn/integration-tests-execute

## 1.0.7

### Patch Changes

- Updated dependencies [eeb660d]
- @openfn/runtime@1.5.1

## 1.0.6

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/execute/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@openfn/integration-tests-execute",
"private": true,
"version": "1.0.6",
"version": "1.0.7",
"description": "Job execution tests",
"author": "Open Function Group <[email protected]>",
"license": "ISC",
Expand Down
9 changes: 9 additions & 0 deletions integration-tests/worker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @openfn/integration-tests-worker

## 1.0.64

### Patch Changes

- Updated dependencies [eeb660d]
- @openfn/ws-worker@1.8.1
- @openfn/engine-multi@1.4.1
- @openfn/lightning-mock@2.0.22

## 1.0.63

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/worker/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@openfn/integration-tests-worker",
"private": true,
"version": "1.0.63",
"version": "1.0.64",
"description": "Lightning WOrker integration tests",
"author": "Open Function Group <[email protected]>",
"license": "ISC",
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @openfn/cli

## 1.8.7

### Patch Changes

- eeb660d: Fix an issue from previous patch where initial state.configuration could be lost at the start of a step
- Updated dependencies [eeb660d]
- @openfn/runtime@1.5.1

## 1.8.6

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/cli",
"version": "1.8.6",
"version": "1.8.7",
"description": "CLI devtools for the openfn toolchain.",
"engines": {
"node": ">=18",
Expand Down
7 changes: 7 additions & 0 deletions packages/engine-multi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# engine-multi

## 1.4.1

### Patch Changes

- Updated dependencies [eeb660d]
- @openfn/runtime@1.5.1

## 1.4.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-multi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/engine-multi",
"version": "1.4.0",
"version": "1.4.1",
"description": "Multi-process runtime engine",
"main": "dist/index.js",
"type": "module",
Expand Down
8 changes: 8 additions & 0 deletions packages/lightning-mock/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @openfn/lightning-mock

## 2.0.22

### Patch Changes

- Updated dependencies [eeb660d]
- @openfn/runtime@1.5.1
- @openfn/engine-multi@1.4.1

## 2.0.21

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/lightning-mock/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/lightning-mock",
"version": "2.0.21",
"version": "2.0.22",
"private": true,
"description": "A mock Lightning server",
"main": "dist/index.js",
Expand Down
6 changes: 6 additions & 0 deletions packages/runtime/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @openfn/runtime

## 1.5.1

### Patch Changes

- eeb660d: Fix an issue from previous patch where initial state.configuration could be lost at the start of a step

## 1.5.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/runtime",
"version": "1.5.0",
"version": "1.5.1",
"description": "Job processing runtime.",
"type": "module",
"exports": {
Expand Down
7 changes: 6 additions & 1 deletion packages/runtime/src/util/assemble-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ const assembleState = (
}

Object.assign(obj, {
configuration: Object.assign({}, globalCredentials, configuration),
configuration: Object.assign(
{},
globalCredentials,
initialState.configuration,
configuration
),
data: assembleData(initialState.data, defaultState.data),
});

Expand Down
33 changes: 32 additions & 1 deletion packages/runtime/test/util/assemble-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ test('Initial data does not have to be an object', (t) => {
});
});

test('does not merge default and initial config objects', (t) => {
test('merges default and initial config objects', (t) => {
const initial = { configuration: { x: 1 } };
const defaultState = undefined;
const config = { y: 1 };

const result = assembleState(initial, config, defaultState);
t.deepEqual(result, {
configuration: {
x: 1,
y: 1,
},
data: {},
Expand All @@ -95,6 +96,20 @@ test('configuration overrides initialState.configuration', (t) => {
});
});

test('initialState.configuration is preserved', (t) => {
const initial = { configuration: { x: 1 } };
const defaultState = undefined;
const config = undefined;

const result = assembleState(initial, config, defaultState);
t.deepEqual(result, {
configuration: {
x: 1,
},
data: {},
});
});

test('global credentials should be added', (t) => {
const initial = {};
const defaultState = undefined;
Expand Down Expand Up @@ -127,6 +142,21 @@ test('global credentials should be merged in', (t) => {
});

test('local credentials should override global credentials', (t) => {
const initial = { configuration: {} };
const defaultState = undefined;
const config = { collection_token: 'x.y.z' };
const global = { collection_token: 'j.w.t' };

const result = assembleState(initial, config, defaultState, global);
t.deepEqual(result, {
configuration: {
collection_token: 'x.y.z',
},
data: {},
});
});

test('local credentials should override global credentials but still preserve intial credentials', (t) => {
const initial = { configuration: { x: 1 } };
const defaultState = undefined;
const config = { collection_token: 'x.y.z' };
Expand All @@ -135,6 +165,7 @@ test('local credentials should override global credentials', (t) => {
const result = assembleState(initial, config, defaultState, global);
t.deepEqual(result, {
configuration: {
x: 1,
collection_token: 'x.y.z',
},
data: {},
Expand Down
9 changes: 9 additions & 0 deletions packages/ws-worker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# ws-worker

## 1.8.1

### Patch Changes

- eeb660d: Fix an issue from previous patch where initial state.configuration could be lost at the start of a step
- Updated dependencies [eeb660d]
- @openfn/runtime@1.5.1
- @openfn/engine-multi@1.4.1

## 1.8.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/ws-worker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/ws-worker",
"version": "1.8.0",
"version": "1.8.1",
"description": "A Websocket Worker to connect Lightning to a Runtime Engine",
"main": "dist/index.js",
"type": "module",
Expand Down

0 comments on commit e0e19b2

Please sign in to comment.