11167: Merge branch 'master' into 11167-wb-remove-arvget
[arvados.git] / apps / workbench / test / integration / jobs_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'fileutils'
6 require 'tmpdir'
7
8 require 'integration_helper'
9
10 class JobsTest < ActionDispatch::IntegrationTest
11   include KeepWebConfig
12
13   setup do
14       need_javascript
15   end
16
17   def fakepipe_with_log_data
18     content =
19       "2014-01-01_12:00:01 zzzzz-8i9sb-0vsrcqi7whchuil 0  log message 1\n" +
20       "2014-01-01_12:00:02 zzzzz-8i9sb-0vsrcqi7whchuil 0  log message 2\n" +
21       "2014-01-01_12:00:03 zzzzz-8i9sb-0vsrcqi7whchuil 0  log message 3\n"
22     StringIO.new content, 'r'
23   end
24
25   test "add job description" do
26     job = api_fixture('jobs')['nearly_finished_job']
27     visit page_with_token("active", "/jobs/#{job['uuid']}")
28
29     # edit job description
30     within('.arv-description-as-subtitle') do
31       find('.fa-pencil').click
32       find('.editable-input textarea').set('*Textile description for job* - "Go to dashboard":/')
33       find('.editable-submit').click
34     end
35
36     # Verify edited description
37     assert_no_text '*Textile description for job*'
38     assert_text 'Textile description for job'
39     assert_selector 'a[href="/"]', text: 'Go to dashboard'
40   end
41
42   test 'view partial job log' do
43     use_keep_web_config
44
45     # This config will be restored during teardown by ../test_helper.rb:
46     Rails.configuration.log_viewer_max_bytes = 100
47
48     logdata = fakepipe_with_log_data.read
49     job_uuid = api_fixture('jobs')['running']['uuid']
50     logcollection = upload_data_and_get_collection(logdata, 'active', "#{job_uuid}.log.txt")
51     job = nil
52     use_token 'active' do
53       job = Job.find job_uuid
54       job.update_attributes log: logcollection.portable_data_hash
55     end
56     visit page_with_token 'active', '/jobs/'+job.uuid
57     find('a[href="#Log"]').click
58     wait_for_ajax
59     assert_text 'Showing only 100 bytes of this log'
60   end
61
62   test 'view log via keep-web redirect' do
63     use_keep_web_config
64
65     token = api_fixture('api_client_authorizations')['active']['api_token']
66     logdata = fakepipe_with_log_data.read
67     logblock = `echo -n #{logdata.shellescape} | ARVADOS_API_TOKEN=#{token.shellescape} arv-put --no-progress --raw -`.strip
68     assert $?.success?, $?
69
70     job = nil
71     use_token 'active' do
72       job = Job.find api_fixture('jobs')['running']['uuid']
73       mtxt = ". #{logblock} 0:#{logdata.length}:#{job.uuid}.log.txt\n"
74       logcollection = Collection.create(manifest_text: mtxt)
75       job.update_attributes log: logcollection.portable_data_hash
76     end
77     visit page_with_token 'active', '/jobs/'+job.uuid
78     find('a[href="#Log"]').click
79     assert_text 'log message 1'
80   end
81
82   [
83     ['foobar', false, false],
84     ['job_with_latest_version', true, false],
85     ['job_with_latest_version', true, true],
86   ].each do |job_name, expect_options, use_latest|
87     test "Rerun #{job_name} job, expect options #{expect_options},
88           and use latest version option #{use_latest}" do
89       job = api_fixture('jobs')[job_name]
90       visit page_with_token 'active', '/jobs/'+job['uuid']
91
92       if expect_options
93         assert_text 'supplied_script_version: master'
94       else
95         assert_no_text 'supplied_script_version'
96       end
97
98       assert_triggers_dom_event 'shown.bs.modal' do
99         find('a,button', text: 'Re-run job...').click
100       end
101       within('.modal-dialog') do
102         assert_selector 'a,button', text: 'Cancel'
103         if use_latest
104           page.choose("job_script_version_#{job['supplied_script_version']}")
105         end
106         click_on "Run now"
107       end
108
109       # Re-running jobs doesn't currently work because the test API
110       # server has no git repository to check against.  For now, check
111       # that the error message says something appropriate for that
112       # situation.
113       if expect_options && use_latest
114         assert_text "077ba2ad3ea24a929091a9e6ce545c93199b8e57"
115       else
116         assert_text "Script version #{job['script_version']} does not resolve to a commit"
117       end
118     end
119   end
120
121   [
122     ['active', true],
123     ['job_reader2', false],
124   ].each do |user, readable|
125     test "view job with components as #{user} user" do
126       job = api_fixture('jobs')['running_job_with_components']
127       component1 = api_fixture('jobs')['completed_job_in_publicly_accessible_project']
128       component2 = api_fixture('pipeline_instances')['running_pipeline_with_complete_job']
129       component2_child1 = api_fixture('jobs')['previous_job_run']
130       component2_child2 = api_fixture('jobs')['running']
131
132       visit page_with_token(user, "/jobs/#{job['uuid']}")
133       assert page.has_text? job['script_version']
134       assert page.has_no_text? 'script_parameters'
135
136       # The job_reader2 is allowed to read job, component2, and component2_child1,
137       # and component2_child2 only as a component of the pipeline component2
138       if readable
139         assert page.has_link? 'component1'
140         assert page.has_link? 'component2'
141       else
142         assert page.has_no_link? 'component1'
143         assert page.has_link? 'component2'
144       end
145
146       if readable
147         click_link('component1')
148         within('.panel-collapse') do
149           assert(has_text? component1['uuid'])
150           assert(has_text? component1['script_version'])
151           assert(has_text? 'script_parameters')
152         end
153         click_link('component1')
154       end
155
156       click_link('component2')
157       within('.panel-collapse') do
158         assert(has_text? component2['uuid'])
159         assert(has_text? component2['script_version'])
160         assert(has_no_text? 'script_parameters')
161         assert(has_link? 'previous')
162         assert(has_link? 'running')
163
164         click_link('previous')
165         within('.panel-collapse') do
166           assert(has_text? component2_child1['uuid'])
167           assert(has_text? component2_child1['script_version'])
168         end
169         click_link('previous')
170
171         click_link('running')
172         within('.panel-collapse') do
173           assert(has_text? component2_child2['uuid'])
174           if readable
175             assert(has_text? component2_child2['script_version'])
176           else
177             assert(has_no_text? component2_child2['script_version'])
178           end
179         end
180       end
181     end
182   end
183 end