Skip to content

Commit e5e28b0

Browse files
authored
Merge pull request #475 from fractal-analytics-platform/fix-optional-task-args-version
Fixed issue in task version update with optional arguments
2 parents 7f993e2 + 754da58 commit e5e28b0

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
*Note: Numbers like (\#123) point to closed Pull Requests on the fractal-web repository.*
22

3+
# Unreleased
4+
5+
* fixed issue in task version update with optional arguments (\#475).
6+
37
# 1.0.1
48

59
* used payload containing all fields in meta properties PATCH endpoint (\#473).

src/lib/components/v2/workflow/ArgumentsSchema.svelte

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,13 @@
111111
112112
const result = await response.json();
113113
if (response.ok) {
114+
const argsNonParallel = deepCopyArgs(result.args_non_parallel);
115+
const argsParallel = deepCopyArgs(result.args_parallel);
114116
if (result.args_non_parallel) {
115-
nonParallelSchemaComponent?.setArguments(result.args_non_parallel);
117+
nonParallelSchemaComponent?.setArguments(argsNonParallel);
116118
}
117119
if (result.args_parallel) {
118-
parallelSchemaComponent?.setArguments(result.args_parallel);
120+
parallelSchemaComponent?.setArguments(argsParallel);
119121
}
120122
onWorkflowTaskUpdated(result);
121123
} else {
@@ -124,6 +126,17 @@
124126
savingChanges = false;
125127
}
126128
129+
/**
130+
* Returns a deep copy of the arguments object to avoid side effects from the JSchema component.
131+
* @param {object|null} args
132+
*/
133+
function deepCopyArgs(args) {
134+
if (typeof args === 'object') {
135+
return JSON.parse(JSON.stringify(args));
136+
}
137+
return null;
138+
}
139+
127140
/**
128141
* @param {string} argsSchemaVersion
129142
*/

tests/v2/task_version_update.spec.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { test } from './workflow_fixture.js';
1+
import { expect, test } from './workflow_fixture.js';
22
import { waitPageLoading } from '../utils.js';
33
import { createFakeTask, deleteTask } from './task_utils.js';
44

@@ -16,7 +16,10 @@ test('Task version update [v2]', async ({ page, workflow }) => {
1616
version: '0.0.1',
1717
args_schema_non_parallel: {
1818
properties: {
19-
p1: { type: 'string' }
19+
p1: { type: 'string' },
20+
// Optional arguments added to test bug #474
21+
p2: { type: 'string', title: 'p2' },
22+
p3: { type: 'string', title: 'p3' }
2023
},
2124
type: 'object'
2225
}
@@ -27,7 +30,9 @@ test('Task version update [v2]', async ({ page, workflow }) => {
2730
version: '0.0.2',
2831
args_schema_non_parallel: {
2932
properties: {
30-
p1: { type: 'string' }
33+
p1: { type: 'string' },
34+
p2: { type: 'string', title: 'p2' },
35+
p3: { type: 'string', title: 'p3' }
3136
},
3237
type: 'object',
3338
required: ['p1']
@@ -101,12 +106,19 @@ test('Task version update [v2]', async ({ page, workflow }) => {
101106
await workflow.selectTask(nonParallelTask);
102107
});
103108

109+
await test.step('Fill optional argument p2', async () => {
110+
await page.getByRole('textbox', { name: 'p2' }).fill('foo');
111+
await page.getByRole('button', { name: 'Save changes' }).click();
112+
await page.getByText('Arguments changes saved successfully').waitFor();
113+
});
114+
104115
await test.step('Update non parallel task to v2', async () => {
105116
await page.getByRole('button', { name: 'Version' }).click();
106117
await page
107118
.getByRole('combobox', { name: 'New versions of this task exist:' })
108119
.selectOption('0.0.2');
109120
await page.getByText('Following errors must be fixed before performing the update').waitFor();
121+
await expect(page.locator('.alert-danger li')).toHaveCount(1);
110122
await page
111123
.getByRole('textbox', { name: 'Fix the non parallel arguments:' })
112124
.fill('{"p1": "test"}');

tests/v2/workflow_task_meta_properties.spec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ test('Workflow task meta properties [v2]', async ({ page, workflow }) => {
2626

2727
await test.step('Add first property', async () => {
2828
await page.getByRole('button', { name: 'Add property' }).click();
29-
await page.getByPlaceholder('Arg name').fill('k1');
30-
await page.getByPlaceholder('Argument default value').fill('v1');
29+
await page.getByPlaceholder('Arg name').fill('arg-k1');
30+
await page.getByPlaceholder('Argument default value').fill('arg-v1');
3131
await page.getByLabel('Save argument').click();
3232
});
3333

3434
await test.step('Add second property', async () => {
3535
await page.getByRole('button', { name: 'Add property' }).click();
36-
await page.getByPlaceholder('Arg name').fill('k2');
37-
await page.getByPlaceholder('Argument default value').fill('v2');
36+
await page.getByPlaceholder('Arg name').fill('arg-k2');
37+
await page.getByPlaceholder('Argument default value').fill('arg-v2');
3838
await page.getByLabel('Save argument').click();
3939
});
4040

4141
await test.step('Verify that meta contains the 2 properties', async () => {
42-
await page.getByText('k1').waitFor();
43-
await page.getByText('k2').waitFor();
44-
await page.getByText('v1').waitFor();
45-
await page.getByText('v2').waitFor();
42+
await page.getByText('arg-k1').waitFor();
43+
await page.getByText('arg-k2').waitFor();
44+
await page.getByText('arg-v1').waitFor();
45+
await page.getByText('arg-v2').waitFor();
4646
});
4747

4848
await test.step('Cleanup', async () => {

0 commit comments

Comments
 (0)