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