Merge branch '20899-wf-delete' refs #20899
[arvados.git] / src / store / processes / process-copy-actions.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from 'react';
6 import { configure } from 'enzyme';
7 import Adapter from 'enzyme-adapter-react-16';
8 import { copyProcess } from './process-copy-actions';
9 import { CommonService } from 'services/common-service/common-service';
10 import { snakeCase } from 'lodash';
11
12 configure({ adapter: new Adapter() });
13
14 describe('ProcessCopyAction', () => {
15     // let props;
16     let dispatch: any, getState: any, services: any;
17
18     let sampleFailedProcess = {
19         command: [
20         "arvados-cwl-runner",
21         "--api=containers",
22         "--local",
23         "--project-uuid=zzzzz-j7d0g-yr18k784zplfeza",
24         "/var/lib/cwl/workflow.json#main",
25         "/var/lib/cwl/cwl.input.json",
26         ],
27         container_count: 1,
28         container_count_max: 10,
29         container_image: "arvados/jobs",
30         container_uuid: "zzzzz-dz642-b9j9dtk1yikp9h0",
31         created_at: "2023-01-23T22:50:50.788284000Z",
32         cumulative_cost: 0.00120553009559028,
33         cwd: "/var/spool/cwl",
34         description: "test decsription",
35         environment: {},
36         etag: "2es6px6q7uo0yqi2i291x8gd6",
37         expires_at: null,
38         filters: null,
39         href: "/container_requests/zzzzz-xvhdp-111111111111111",
40         kind: "arvados#containerRequest",
41         log_uuid: "zzzzz-4zz18-a1gxqy9o6zyrdy8",
42         modified_at: "2023-01-24T21:13:54.772612000Z",
43         modified_by_client_uuid: "zzzzz-ozdt8-q6dzdi1lcc03155",
44         modified_by_user_uuid: "jutro-tpzed-vllbpebicy84rd5",
45         mounts: {
46         "/var/lib/cwl/cwl.input.json": {
47             capacity: 0,
48             commit: "",
49             content: {
50             input: {
51                 basename: "logo.ai.no.whitespace.png",
52                 class: "File",
53                 location:
54                 "keep:5d3238c4db721a92c98b0305a47b0485+75/logo.ai.no.whitespace.png",
55             },
56             reverse_sort: true,
57             },
58             device_type: "",
59             exclude_from_output: false,
60             git_url: "",
61             kind: "json",
62             path: "",
63             portable_data_hash: "",
64             repository_name: "",
65             uuid: "",
66             writable: false,
67         },
68         "/var/lib/cwl/workflow.json": {
69             capacity: 0,
70             commit: "",
71             content: {
72             $graph: [
73                 {
74                 class: "Workflow",
75                 doc: "Reverse the lines in a document, then sort those lines.",
76                 id: "#main",
77                 inputs: [
78                     {
79                     default: null,
80                     doc: "The input file to be processed.",
81                     id: "#main/input",
82                     type: "File",
83                     },
84                     {
85                     default: true,
86                     doc: "If true, reverse (decending) sort",
87                     id: "#main/reverse_sort",
88                     type: "boolean",
89                     },
90                 ],
91                 outputs: [
92                     {
93                     doc: "The output with the lines reversed and sorted.",
94                     id: "#main/output",
95                     outputSource: "#main/sorted/output",
96                     type: "File",
97                     },
98                 ],
99                 steps: [
100                     {
101                     id: "#main/rev",
102                     in: [{ id: "#main/rev/input", source: "#main/input" }],
103                     out: ["#main/rev/output"],
104                     run: "#revtool.cwl",
105                     },
106                     {
107                     id: "#main/sorted",
108                     in: [
109                         { id: "#main/sorted/input", source: "#main/rev/output" },
110                         {
111                         id: "#main/sorted/reverse",
112                         source: "#main/reverse_sort",
113                         },
114                     ],
115                     out: ["#main/sorted/output"],
116                     run: "#sorttool.cwl",
117                     },
118                 ],
119                 },
120                 {
121                 baseCommand: "rev",
122                 class: "CommandLineTool",
123                 doc: "Reverse each line using the `rev` command",
124                 hints: [{ class: "ResourceRequirement", ramMin: 8 }],
125                 id: "#revtool.cwl",
126                 inputs: [
127                     { id: "#revtool.cwl/input", inputBinding: {}, type: "File" },
128                 ],
129                 outputs: [
130                     {
131                     id: "#revtool.cwl/output",
132                     outputBinding: { glob: "output.txt" },
133                     type: "File",
134                     },
135                 ],
136                 stdout: "output.txt",
137                 },
138                 {
139                 baseCommand: "sort",
140                 class: "CommandLineTool",
141                 doc: "Sort lines using the `sort` command",
142                 hints: [{ class: "ResourceRequirement", ramMin: 8 }],
143                 id: "#sorttool.cwl",
144                 inputs: [
145                     {
146                     id: "#sorttool.cwl/reverse",
147                     inputBinding: { position: 1, prefix: "-r" },
148                     type: "boolean",
149                     },
150                     {
151                     id: "#sorttool.cwl/input",
152                     inputBinding: { position: 2 },
153                     type: "File",
154                     },
155                 ],
156                 outputs: [
157                     {
158                     id: "#sorttool.cwl/output",
159                     outputBinding: { glob: "output.txt" },
160                     type: "File",
161                     },
162                 ],
163                 stdout: "output.txt",
164                 },
165             ],
166             cwlVersion: "v1.0",
167             },
168             device_type: "",
169             exclude_from_output: false,
170             git_url: "",
171             kind: "json",
172             path: "",
173             portable_data_hash: "",
174             repository_name: "",
175             uuid: "",
176             writable: false,
177         },
178         "/var/spool/cwl": {
179             capacity: 0,
180             commit: "",
181             content: null,
182             device_type: "",
183             exclude_from_output: false,
184             git_url: "",
185             kind: "collection",
186             path: "",
187             portable_data_hash: "",
188             repository_name: "",
189             uuid: "",
190             writable: true,
191         },
192         stdout: {
193             capacity: 0,
194             commit: "",
195             content: null,
196             device_type: "",
197             exclude_from_output: false,
198             git_url: "",
199             kind: "file",
200             path: "/var/spool/cwl/cwl.output.json",
201             portable_data_hash: "",
202             repository_name: "",
203             uuid: "",
204             writable: false,
205         },
206         },
207         name: "Copy of: Copy of: Copy of: revsort.cwl",
208         output_name: "Output from revsort.cwl",
209         output_path: "/var/spool/cwl",
210         output_properties: { key: "val" },
211         output_storage_classes: ["default"],
212         output_ttl: 999999,
213         output_uuid: "zzzzz-4zz18-wolwlyfxmlhmgd4",
214         owner_uuid: "zzzzz-j7d0g-yr18k784zplfeza",
215         priority: 500,
216         properties: {
217         template_uuid: "zzzzz-7fd4e-7xsza0vgfe785cy",
218         workflowName: "revsort.cwl",
219         },
220         requesting_container_uuid: null,
221         runtime_constraints: {
222         API: true,
223         cuda: { device_count: 0, driver_version: "", hardware_capability: "" },
224         keep_cache_disk: 0,
225         keep_cache_ram: 0,
226         ram: 1342177280,
227         vcpus: 1,
228         },
229         runtime_token: "",
230         scheduling_parameters: {
231         max_run_time: 0,
232         partitions: [],
233         preemptible: false,
234         },
235         state: "Final",
236         use_existing: false,
237         uuid: "zzzzz-xvhdp-111111111111111",
238     };
239
240     let expectedContainerRequest = {
241         command: [
242         "arvados-cwl-runner",
243         "--api=containers",
244         "--local",
245         "--project-uuid=zzzzz-j7d0g-yr18k784zplfeza",
246         "/var/lib/cwl/workflow.json#main",
247         "/var/lib/cwl/cwl.input.json",
248         ],
249         container_count_max: 10,
250         container_image: "arvados/jobs",
251         cwd: "/var/spool/cwl",
252         description: "test decsription",
253         environment: {},
254         kind: "arvados#containerRequest",
255         mounts: {
256         "/var/lib/cwl/cwl.input.json": {
257             capacity: 0,
258             commit: "",
259             content: {
260             input: {
261                 basename: "logo.ai.no.whitespace.png",
262                 class: "File",
263                 location:
264                 "keep:5d3238c4db721a92c98b0305a47b0485+75/logo.ai.no.whitespace.png",
265             },
266             reverse_sort: true,
267             },
268             device_type: "",
269             exclude_from_output: false,
270             git_url: "",
271             kind: "json",
272             path: "",
273             portable_data_hash: "",
274             repository_name: "",
275             uuid: "",
276             writable: false,
277         },
278         "/var/lib/cwl/workflow.json": {
279             capacity: 0,
280             commit: "",
281             content: {
282             $graph: [
283                 {
284                 class: "Workflow",
285                 doc: "Reverse the lines in a document, then sort those lines.",
286                 id: "#main",
287                 inputs: [
288                     {
289                     default: null,
290                     doc: "The input file to be processed.",
291                     id: "#main/input",
292                     type: "File",
293                     },
294                     {
295                     default: true,
296                     doc: "If true, reverse (decending) sort",
297                     id: "#main/reverse_sort",
298                     type: "boolean",
299                     },
300                 ],
301                 outputs: [
302                     {
303                     doc: "The output with the lines reversed and sorted.",
304                     id: "#main/output",
305                     outputSource: "#main/sorted/output",
306                     type: "File",
307                     },
308                 ],
309                 steps: [
310                     {
311                     id: "#main/rev",
312                     in: [{ id: "#main/rev/input", source: "#main/input" }],
313                     out: ["#main/rev/output"],
314                     run: "#revtool.cwl",
315                     },
316                     {
317                     id: "#main/sorted",
318                     in: [
319                         {
320                         id: "#main/sorted/input",
321                         source: "#main/rev/output",
322                         },
323                         {
324                         id: "#main/sorted/reverse",
325                         source: "#main/reverse_sort",
326                         },
327                     ],
328                     out: ["#main/sorted/output"],
329                     run: "#sorttool.cwl",
330                     },
331                 ],
332                 },
333                 {
334                 baseCommand: "rev",
335                 class: "CommandLineTool",
336                 doc: "Reverse each line using the `rev` command",
337                 hints: [{ class: "ResourceRequirement", ramMin: 8 }],
338                 id: "#revtool.cwl",
339                 inputs: [
340                     {
341                     id: "#revtool.cwl/input",
342                     inputBinding: {},
343                     type: "File",
344                     },
345                 ],
346                 outputs: [
347                     {
348                     id: "#revtool.cwl/output",
349                     outputBinding: { glob: "output.txt" },
350                     type: "File",
351                     },
352                 ],
353                 stdout: "output.txt",
354                 },
355                 {
356                 baseCommand: "sort",
357                 class: "CommandLineTool",
358                 doc: "Sort lines using the `sort` command",
359                 hints: [{ class: "ResourceRequirement", ramMin: 8 }],
360                 id: "#sorttool.cwl",
361                 inputs: [
362                     {
363                     id: "#sorttool.cwl/reverse",
364                     inputBinding: { position: 1, prefix: "-r" },
365                     type: "boolean",
366                     },
367                     {
368                     id: "#sorttool.cwl/input",
369                     inputBinding: { position: 2 },
370                     type: "File",
371                     },
372                 ],
373                 outputs: [
374                     {
375                     id: "#sorttool.cwl/output",
376                     outputBinding: { glob: "output.txt" },
377                     type: "File",
378                     },
379                 ],
380                 stdout: "output.txt",
381                 },
382             ],
383             cwlVersion: "v1.0",
384             },
385             device_type: "",
386             exclude_from_output: false,
387             git_url: "",
388             kind: "json",
389             path: "",
390             portable_data_hash: "",
391             repository_name: "",
392             uuid: "",
393             writable: false,
394         },
395         "/var/spool/cwl": {
396             capacity: 0,
397             commit: "",
398             content: null,
399             device_type: "",
400             exclude_from_output: false,
401             git_url: "",
402             kind: "collection",
403             path: "",
404             portable_data_hash: "",
405             repository_name: "",
406             uuid: "",
407             writable: true,
408         },
409         stdout: {
410             capacity: 0,
411             commit: "",
412             content: null,
413             device_type: "",
414             exclude_from_output: false,
415             git_url: "",
416             kind: "file",
417             path: "/var/spool/cwl/cwl.output.json",
418             portable_data_hash: "",
419             repository_name: "",
420             uuid: "",
421             writable: false,
422         },
423         },
424         name: "newname.cwl",
425         output_name: "Output from revsort.cwl",
426         output_path: "/var/spool/cwl",
427         output_properties: { key: "val" },
428         output_storage_classes: ["default"],
429         output_ttl: 999999,
430         owner_uuid: "zzzzz-j7d0g-000000000000000",
431         priority: 500,
432         properties: {
433         template_uuid: "zzzzz-7fd4e-7xsza0vgfe785cy",
434         workflowName: "revsort.cwl",
435         },
436         runtime_constraints: {
437         API: true,
438         cuda: {
439             device_count: 0,
440             driver_version: "",
441             hardware_capability: "",
442         },
443         keep_cache_disk: 0,
444         keep_cache_ram: 0,
445         ram: 1342177280,
446         vcpus: 1,
447         },
448         scheduling_parameters: {
449         max_run_time: 0,
450         partitions: [],
451         preemptible: false,
452         },
453         state: "Uncommitted",
454         use_existing: false,
455     };
456
457     beforeEach(() => {
458         dispatch = jest.fn();
459         services = {
460             containerRequestService: {
461                 get: jest.fn().mockImplementation(async () => (CommonService.mapResponseKeys({data: sampleFailedProcess}))),
462                 create: jest.fn().mockImplementation(async (data) => (CommonService.mapKeys(snakeCase)(data))),
463             },
464         };
465         getState = () => ({
466             auth: {},
467         });
468     });
469
470     it("should request the failed process and return a copy with the proper fields", async () => {
471         // when
472         const newprocess = await copyProcess({
473             name: "newname.cwl",
474             uuid: "zzzzz-xvhdp-111111111111111",
475             ownerUuid: "zzzzz-j7d0g-000000000000000",
476         })(dispatch, getState, services);
477
478         // then
479         expect(services.containerRequestService.get).toHaveBeenCalledWith("zzzzz-xvhdp-111111111111111");
480         expect(newprocess).toEqual(expectedContainerRequest);
481
482     });
483 });