Merge branch '22693-docker-28'
[arvados.git] / services / workbench2 / src / store / run-process-panel / run-process-panel-actions.cy.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { runProcess } from "./run-process-panel-actions";
6 import { RUN_PROCESS_BASIC_FORM, RUN_PROCESS_INPUTS_FORM } from "./run-process-panel-actions";
7 import { navigateTo } from "store/navigation/navigation-action";
8
9 describe("run-process-panel-actions", () => {
10     describe("runProcess", () => {
11         const newProcessUUID = 'newProcessUUID';
12         let dispatch, getState, services;
13
14         beforeEach(() => {
15             dispatch = cy.spy();
16             services = {
17                 containerRequestService: {
18                     create: cy.stub().callsFake(async () => ({
19                         uuid: newProcessUUID,
20                     })),
21                 },
22             };
23             cy.spy(navigateTo).as('navigateTo');
24         });
25
26         it("should return when userUuid is null", async () => {
27             // given
28             getState = () => ({
29                 auth: {},
30             });
31
32             // when
33             await runProcess(dispatch, getState, services);
34
35             // then
36             expect(dispatch).not.to.be.called;
37         });
38
39         it("should run workflow with project-uuid", async () => {
40             // given
41             getState = () => ({
42                 auth: {
43                     user: {
44                         email: "test@gmail.com",
45                         firstName: "TestFirstName",
46                         lastName: "TestLastName",
47                         uuid: "zzzzz-tpzed-yid70bw31f51234",
48                         ownerUuid: "zzzzz-tpzed-000000000000000",
49                         isAdmin: false,
50                         isActive: true,
51                         username: "testfirstname",
52                         prefs: {
53                             profile: {},
54                         },
55                     },
56                 },
57                 runProcessPanel: {
58                     processPathname: "/projects/zzzzz-tpzed-yid70bw31f51234",
59                     processOwnerUuid: "zzzzz-tpzed-yid70bw31f51234",
60                     selectedWorkflow: {
61                         kind: "arvados#workflow",
62                         etag: "8gh5xlhlgo61yqscyl1spw8tc",
63                         uuid: "zzzzz-7fd4e-2tlnerdkxnl4fjt",
64                         ownerUuid: "zzzzz-tpzed-o4njwilpp4ov321",
65                         createdAt: "2020-07-15T19:40:50.296041000Z",
66                         modifiedByClientUuid: "zzzzz-ozdt8-libnr89sc5nq111",
67                         modifiedByUserUuid: "zzzzz-tpzed-o4njwilpp4ov321",
68                         modifiedAt: "2020-07-15T19:40:50.296376000Z",
69                         name: "revsort.cwl",
70                         description:
71                             "Reverse the lines in a document, then sort those lines.",
72                         definition:
73                             '{\n    "$graph": [\n        {\n            "class": "Workflow",\n            "doc": "Reverse the lines in a document, then sort those lines.",\n            "id": "#main",\n            "hints":[{"class":"http://arvados.org/cwl#WorkflowRunnerResources","acrContainerImage":"arvados/jobs:2.0.4", "ramMin": 16000}], "inputs": [\n                {\n                    "default": null,\n                    "doc": "The input file to be processed.",\n                    "id": "#main/input",\n                    "type": "File"\n                },\n                {\n                    "default": true,\n                    "doc": "If true, reverse (decending) sort",\n                    "id": "#main/reverse_sort",\n                    "type": "boolean"\n                }\n            ],\n            "outputs": [\n                {\n                    "doc": "The output with the lines reversed and sorted.",\n                    "id": "#main/output",\n                    "outputSource": "#main/sorted/output",\n                    "type": "File"\n                }\n            ],\n            "steps": [\n                {\n                    "id": "#main/rev",\n                    "in": [\n                        {\n                            "id": "#main/rev/input",\n                            "source": "#main/input"\n                        }\n                    ],\n                    "out": [\n                        "#main/rev/output"\n                    ],\n                    "run": "#revtool.cwl"\n                },\n                {\n                    "id": "#main/sorted",\n                    "in": [\n                        {\n                            "id": "#main/sorted/input",\n                            "source": "#main/rev/output"\n                        },\n                        {\n                            "id": "#main/sorted/reverse",\n                            "source": "#main/reverse_sort"\n                        }\n                    ],\n                    "out": [\n                        "#main/sorted/output"\n                    ],\n                    "run": "#sorttool.cwl"\n                }\n            ]\n        },\n        {\n            "baseCommand": "rev",\n            "class": "CommandLineTool",\n            "doc": "Reverse each line using the `rev` command",\n            "hints": [\n                {\n                    "class": "ResourceRequirement",\n                    "ramMin": 8\n                }\n            ],\n            "id": "#revtool.cwl",\n            "inputs": [\n                {\n                    "id": "#revtool.cwl/input",\n                    "inputBinding": {},\n                    "type": "File"\n                }\n            ],\n            "outputs": [\n                {\n                    "id": "#revtool.cwl/output",\n                    "outputBinding": {\n                        "glob": "output.txt"\n                    },\n                    "type": "File"\n                }\n            ],\n            "stdout": "output.txt"\n        },\n        {\n            "baseCommand": "sort",\n            "class": "CommandLineTool",\n            "doc": "Sort lines using the `sort` command",\n            "hints": [\n                {\n                    "class": "ResourceRequirement",\n                    "ramMin": 8\n                }\n            ],\n            "id": "#sorttool.cwl",\n            "inputs": [\n                {\n                    "id": "#sorttool.cwl/reverse",\n                    "inputBinding": {\n                        "position": 1,\n                        "prefix": "-r"\n                    },\n                    "type": "boolean"\n                },\n                {\n                    "id": "#sorttool.cwl/input",\n                    "inputBinding": {\n                        "position": 2\n                    },\n                    "type": "File"\n                }\n            ],\n            "outputs": [\n                {\n                    "id": "#sorttool.cwl/output",\n                    "outputBinding": {\n                        "glob": "output.txt"\n                    },\n                    "type": "File"\n                }\n            ],\n            "stdout": "output.txt"\n        }\n    ],\n    "cwlVersion": "v1.0"\n}',
74                     },
75                 },
76                 form: {
77                     [RUN_PROCESS_BASIC_FORM]: {
78                         values: {
79                             name: "basicFormTestName",
80                             description: "basicFormTestDescription",
81                         },
82                     },
83                     [RUN_PROCESS_INPUTS_FORM]: {
84                         values: {
85                             inputs: {},
86                         }
87                     }
88                 },
89             });
90
91             // when
92             await runProcess(dispatch, getState, services);
93
94             // then
95             expect(services.containerRequestService.create).to.be.calledWithMatch(testCreateArgs);
96             expect(dispatch).to.be.calledWithMatch(navigateTo(newProcessUUID));
97         });
98     });
99 });
100
101 const testMounts = {
102     '/var/spool/cwl': {
103         kind: 'collection',
104         writable: true,
105     },
106     stdout: {
107         kind: 'file',
108         path: '/var/spool/cwl/cwl.output.json',
109     },
110     '/var/lib/cwl/workflow.json': {
111         kind: 'json',
112         content: {
113             $graph: [
114                 {
115                     class: 'Workflow',
116                     doc: 'Reverse the lines in a document, then sort those lines.',
117                     id: '#main',
118                     hints: [
119                         {
120                             class: 'http://arvados.org/cwl#WorkflowRunnerResources',
121                             acrContainerImage: 'arvados/jobs:2.0.4',
122                             ramMin: 16000,
123                         },
124                     ],
125                     inputs: [
126                         {
127                             default: null,
128                             doc: 'The input file to be processed.',
129                             id: '#main/input',
130                             type: 'File',
131                         },
132                         {
133                             default: true,
134                             doc: 'If true, reverse (decending) sort',
135                             id: '#main/reverse_sort',
136                             type: 'boolean',
137                         },
138                     ],
139                     outputs: [
140                         {
141                             doc: 'The output with the lines reversed and sorted.',
142                             id: '#main/output',
143                             outputSource: '#main/sorted/output',
144                             type: 'File',
145                         },
146                     ],
147                     steps: [
148                         {
149                             id: '#main/rev',
150                             in: [
151                                 {
152                                     id: '#main/rev/input',
153                                     source: '#main/input',
154                                 },
155                             ],
156                             out: ['#main/rev/output'],
157                             run: '#revtool.cwl',
158                         },
159                         {
160                             id: '#main/sorted',
161                             in: [
162                                 {
163                                     id: '#main/sorted/input',
164                                     source: '#main/rev/output',
165                                 },
166                                 {
167                                     id: '#main/sorted/reverse',
168                                     source: '#main/reverse_sort',
169                                 },
170                             ],
171                             out: ['#main/sorted/output'],
172                             run: '#sorttool.cwl',
173                         },
174                     ],
175                 },
176                 {
177                     baseCommand: 'rev',
178                     class: 'CommandLineTool',
179                     doc: 'Reverse each line using the `rev` command',
180                     hints: [
181                         {
182                             class: 'ResourceRequirement',
183                             ramMin: 8,
184                         },
185                     ],
186                     id: '#revtool.cwl',
187                     inputs: [
188                         {
189                             id: '#revtool.cwl/input',
190                             inputBinding: {},
191                             type: 'File',
192                         },
193                     ],
194                     outputs: [
195                         {
196                             id: '#revtool.cwl/output',
197                             outputBinding: {
198                                 glob: 'output.txt',
199                             },
200                             type: 'File',
201                         },
202                     ],
203                     stdout: 'output.txt',
204                 },
205                 {
206                     baseCommand: 'sort',
207                     class: 'CommandLineTool',
208                     doc: 'Sort lines using the `sort` command',
209                     hints: [
210                         {
211                             class: 'ResourceRequirement',
212                             ramMin: 8,
213                         },
214                     ],
215                     id: '#sorttool.cwl',
216                     inputs: [
217                         {
218                             id: '#sorttool.cwl/reverse',
219                             inputBinding: {
220                                 position: 1,
221                                 prefix: '-r',
222                             },
223                             type: 'boolean',
224                         },
225                         {
226                             id: '#sorttool.cwl/input',
227                             inputBinding: {
228                                 position: 2,
229                             },
230                             type: 'File',
231                         },
232                     ],
233                     outputs: [
234                         {
235                             id: '#sorttool.cwl/output',
236                             outputBinding: {
237                                 glob: 'output.txt',
238                             },
239                             type: 'File',
240                         },
241                     ],
242                     stdout: 'output.txt',
243                 },
244             ],
245             cwlVersion: 'v1.0',
246         },
247     },
248     '/var/lib/cwl/cwl.input.json': {
249         kind: 'json',
250         content: {
251             '': {},
252         },
253     },
254 };
255
256 const testCreateArgs = {
257     command: [
258         'arvados-cwl-runner',
259         '--local',
260         '--api=containers',
261         "--no-log-timestamps",
262         "--disable-color",
263         '--project-uuid=zzzzz-tpzed-yid70bw31f51234',
264         '/var/lib/cwl/workflow.json#main',
265         '/var/lib/cwl/cwl.input.json',
266     ],
267     containerImage: 'arvados/jobs:2.0.4',
268     cwd: '/var/spool/cwl',
269     description: undefined,
270     mounts: testMounts,
271     secretMounts: undefined,
272     name: 'basicFormTestName',
273     outputName: 'Output from basicFormTestName',
274     outputPath: '/var/spool/cwl',
275     ownerUuid: 'zzzzz-tpzed-yid70bw31f51234',
276     priority: 500,
277     properties: {
278         workflowName: 'revsort.cwl',
279         template_uuid: 'zzzzz-7fd4e-2tlnerdkxnl4fjt',
280     },
281     runtimeConstraints: {
282         API: true,
283         ram: 16256 * (1024 * 1024),
284         vcpus: 1,
285     },
286     schedulingParameters: { max_run_time: undefined },
287     state: 'Committed',
288     useExisting: false,
289 };