11167: Re-added jobs integration test, adjusted to work with keep-web.
[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     token = api_fixture('api_client_authorizations')['active']['api_token']
49     logdata = fakepipe_with_log_data.read
50     logblock = `echo -n #{logdata.shellescape} | ARVADOS_API_TOKEN=#{token.shellescape} arv-put --no-progress --raw -`.strip
51     assert $?.success?, $?
52
53     job = nil
54     use_token 'active' do
55       job = Job.find api_fixture('jobs')['running']['uuid']
56       mtxt = ". #{logblock} 0:#{logdata.length}:#{job.uuid}.log.txt\n"
57       logcollection = Collection.create(manifest_text: mtxt)
58       job.update_attributes log: logcollection.portable_data_hash
59     end
60     visit page_with_token 'active', '/jobs/'+job.uuid
61     find('a[href="#Log"]').click
62     wait_for_ajax
63     assert_text 'Showing only 100 bytes of this log'
64   end
65
66   test 'view log via keep-web redirect' do
67     use_keep_web_config
68
69     token = api_fixture('api_client_authorizations')['active']['api_token']
70     logdata = fakepipe_with_log_data.read
71     logblock = `echo -n #{logdata.shellescape} | ARVADOS_API_TOKEN=#{token.shellescape} arv-put --no-progress --raw -`.strip
72     assert $?.success?, $?
73
74     job = nil
75     use_token 'active' do
76       job = Job.find api_fixture('jobs')['running']['uuid']
77       mtxt = ". #{logblock} 0:#{logdata.length}:#{job.uuid}.log.txt\n"
78       logcollection = Collection.create(manifest_text: mtxt)
79       job.update_attributes log: logcollection.portable_data_hash
80     end
81     visit page_with_token 'active', '/jobs/'+job.uuid
82     find('a[href="#Log"]').click
83     assert_text 'log message 1'
84   end
85
86   [
87     ['foobar', false, false],
88     ['job_with_latest_version', true, false],
89     ['job_with_latest_version', true, true],
90   ].each do |job_name, expect_options, use_latest|
91     test "Rerun #{job_name} job, expect options #{expect_options},
92           and use latest version option #{use_latest}" do
93       job = api_fixture('jobs')[job_name]
94       visit page_with_token 'active', '/jobs/'+job['uuid']
95
96       if expect_options
97         assert_text 'supplied_script_version: master'
98       else
99         assert_no_text 'supplied_script_version'
100       end
101
102       assert_triggers_dom_event 'shown.bs.modal' do
103         find('a,button', text: 'Re-run job...').click
104       end
105       within('.modal-dialog') do
106         assert_selector 'a,button', text: 'Cancel'
107         if use_latest
108           page.choose("job_script_version_#{job['supplied_script_version']}")
109         end
110         click_on "Run now"
111       end
112
113       # Re-running jobs doesn't currently work because the test API
114       # server has no git repository to check against.  For now, check
115       # that the error message says something appropriate for that
116       # situation.
117       if expect_options && use_latest
118         assert_text "077ba2ad3ea24a929091a9e6ce545c93199b8e57"
119       else
120         assert_text "Script version #{job['script_version']} does not resolve to a commit"
121       end
122     end
123   end
124
125   [
126     ['active', true],
127     ['job_reader2', false],
128   ].each do |user, readable|
129     test "view job with components as #{user} user" do
130       job = api_fixture('jobs')['running_job_with_components']
131       component1 = api_fixture('jobs')['completed_job_in_publicly_accessible_project']
132       component2 = api_fixture('pipeline_instances')['running_pipeline_with_complete_job']
133       component2_child1 = api_fixture('jobs')['previous_job_run']
134       component2_child2 = api_fixture('jobs')['running']
135
136       visit page_with_token(user, "/jobs/#{job['uuid']}")
137       assert page.has_text? job['script_version']
138       assert page.has_no_text? 'script_parameters'
139
140       # The job_reader2 is allowed to read job, component2, and component2_child1,
141       # and component2_child2 only as a component of the pipeline component2
142       if readable
143         assert page.has_link? 'component1'
144         assert page.has_link? 'component2'
145       else
146         assert page.has_no_link? 'component1'
147         assert page.has_link? 'component2'
148       end
149
150       if readable
151         click_link('component1')
152         within('.panel-collapse') do
153           assert(has_text? component1['uuid'])
154           assert(has_text? component1['script_version'])
155           assert(has_text? 'script_parameters')
156         end
157         click_link('component1')
158       end
159
160       click_link('component2')
161       within('.panel-collapse') do
162         assert(has_text? component2['uuid'])
163         assert(has_text? component2['script_version'])
164         assert(has_no_text? 'script_parameters')
165         assert(has_link? 'previous')
166         assert(has_link? 'running')
167
168         click_link('previous')
169         within('.panel-collapse') do
170           assert(has_text? component2_child1['uuid'])
171           assert(has_text? component2_child1['script_version'])
172         end
173         click_link('previous')
174
175         click_link('running')
176         within('.panel-collapse') do
177           assert(has_text? component2_child2['uuid'])
178           if readable
179             assert(has_text? component2_child2['script_version'])
180           else
181             assert(has_no_text? component2_child2['script_version'])
182           end
183         end
184       end
185     end
186   end
187 end