Skip to content

Commit b728858

Browse files
committed
test: enable fossil support
1 parent a1bbd1d commit b728858

File tree

5 files changed

+66
-43
lines changed

5 files changed

+66
-43
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Uncomment all fossil tests and make sure they pass.

lib/vcs_repo.rb

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,11 @@ def first_commit_in_current_branch
315315
if current_fossil_branch && !current_fossil_branch.empty? && current_fossil_branch.match?(/\A[a-zA-Z0-9._-]+\z/)
316316
escaped_branch = current_fossil_branch.gsub("'", "''")
317317
sql = 'SELECT blob.uuid FROM tag JOIN tagxref ON tag.tagid=tagxref.tagid ' \
318-
"JOIN blob ON blob.rid=tagxref.rid WHERE tag.tagname='sym-#{escaped_branch}' " \
318+
'JOIN event ON tagxref.rid=event.objid JOIN blob ON blob.rid=tagxref.rid ' \
319+
"WHERE tag.tagname='sym-#{escaped_branch}' " \
320+
"AND event.comment NOT LIKE 'Create new branch named%' " \
319321
'ORDER BY tagxref.mtime ASC LIMIT 1'
320-
commit_hash = `fossil sql "#{sql}"`.strip.gsub("'", '')
322+
commit_hash = `fossil sql "#{sql}"`.strip.delete("'")
321323
end
322324
else
323325
puts "Error: Unknown VCS type (#{@vcs_type}) to find first commit"
@@ -450,8 +452,14 @@ def commit_message(commit_hash)
450452
message = `bzr log -r #{commit_hash} --show-ids 2>/dev/null | grep -A 1000 'message:' | tail -n +2`.strip
451453
$CHILD_STATUS.success? ? message : nil
452454
when :fossil
453-
message = `fossil timeline -n 1 #{commit_hash} 2>/dev/null | grep -o 'comment:.*' | sed 's/comment://'`.strip
454-
$CHILD_STATUS.success? ? message : nil
455+
sql = <<~SQL
456+
SELECT event.comment FROM event
457+
JOIN blob ON event.objid = blob.rid
458+
WHERE blob.uuid='#{commit_hash}' AND event.type='ci'
459+
LIMIT 1
460+
SQL
461+
output = `fossil sql "#{sql.strip}" 2>/dev/null`
462+
$CHILD_STATUS.success? ? output.strip.delete("'") : nil
455463
end
456464
end
457465
end
@@ -475,13 +483,12 @@ def latest_agent_branch_commit
475483
out, = Open3.capture2('hg', 'log', '-r', revset, '--limit', '1', '--template', '{node}\n')
476484
out.strip
477485
when :fossil
478-
branch = current_branch
479-
escaped = branch.gsub("'", "''")
480-
sql = 'SELECT blob.uuid FROM tag JOIN tagxref ON tag.tagid=tagxref.tagid ' \
481-
'JOIN event ON tagxref.rid=event.objid JOIN blob ON event.objid=blob.rid ' \
482-
"WHERE tag.tagname='sym-#{escaped}' AND event.type='ci' " \
483-
"AND event.comment LIKE 'Start-Agent-Branch:%' ORDER BY tagxref.mtime DESC LIMIT 1"
484-
`fossil sql \"#{sql}\"`.strip.delete("'")
486+
sql = <<~SQL
487+
SELECT blob.uuid FROM event JOIN blob ON event.objid=blob.rid
488+
WHERE event.type='ci' AND event.comment LIKE 'Start-Agent-Branch:%'
489+
ORDER BY event.mtime DESC LIMIT 1
490+
SQL
491+
`fossil sql "#{sql.strip}"`.strip.delete("'")
485492
else
486493
''
487494
end

test/test_follow_up_tasks.rb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ module FollowUpCases
99
def test_append_follow_up_tasks
1010
RepoTestHelper::AGENT_TASK_BINARIES.product(RepoTestHelper::GET_TASK_BINARIES).each do |ab, gb|
1111
repo, remote = setup_repo(self.class::VCS_TYPE)
12-
status, = run_agent_task(repo, branch: 'feat', lines: ['task one'], push_to_remote: true, tool: ab)
12+
push_flag = self.class::VCS_TYPE != :fossil
13+
status, = run_agent_task(repo, branch: 'feat', lines: ['task one'], push_to_remote: push_flag, tool: ab)
1314
assert_equal 0, status.exitstatus, 'initial task failed'
1415
r = VCSRepo.new(repo)
1516
r.checkout_branch('feat')
1617
File.write(File.join(repo, 'work.txt'), 'work')
1718
r.commit_file(File.join(repo, 'work.txt'), 'work commit')
18-
status2, = run_agent_task(repo, branch: nil, lines: ['task two'], push_to_remote: true, tool: ab)
19+
push_flag = self.class::VCS_TYPE != :fossil
20+
status2, = run_agent_task(repo, branch: nil, lines: ['task two'], push_to_remote: push_flag, tool: ab)
1921
assert_equal 0, status2.exitstatus, 'follow-up task failed'
2022
status3, output = run_get_task(repo, tool: gb)
2123
assert_equal 0, status3.exitstatus, 'get-task failed after follow-up'
@@ -42,17 +44,20 @@ def test_nested_branch_tasks
4244
# Use only direct binaries, skip gem-based ones to avoid installation issues
4345
[[RepoTestHelper::AGENT_TASK, RepoTestHelper::GET_TASK]].each do |ab, gb|
4446
repo, remote = setup_repo(self.class::VCS_TYPE)
45-
status, = run_agent_task(repo, branch: 'a', lines: ['task a'], push_to_remote: true, tool: ab)
47+
push_flag = self.class::VCS_TYPE != :fossil
48+
status, = run_agent_task(repo, branch: 'a', lines: ['task a'], push_to_remote: push_flag, tool: ab)
4649
assert_equal 0, status.exitstatus, 'branch a failed'
4750
r = VCSRepo.new(repo)
4851
r.checkout_branch('a')
49-
status, = run_agent_task(repo, branch: 'b', lines: ['task b'], push_to_remote: true, tool: ab)
52+
push_flag = self.class::VCS_TYPE != :fossil
53+
status, = run_agent_task(repo, branch: 'b', lines: ['task b'], push_to_remote: push_flag, tool: ab)
5054
assert_equal 0, status.exitstatus, 'branch b failed'
5155
r.checkout_branch('b')
5256
_, output = run_get_task(repo, tool: gb)
5357
assert_includes output, 'task b', 'task b missing'
5458
refute_includes output, 'task a', 'task a should not appear in branch b'
55-
status, = run_agent_task(repo, branch: 'c', lines: ['task c'], push_to_remote: true, tool: ab)
59+
push_flag = self.class::VCS_TYPE != :fossil
60+
status, = run_agent_task(repo, branch: 'c', lines: ['task c'], push_to_remote: push_flag, tool: ab)
5661
assert_equal 0, status.exitstatus, 'branch c failed'
5762
r.checkout_branch('c')
5863
_, output = run_get_task(repo, tool: gb)
@@ -77,8 +82,8 @@ class FollowUpHgTest < Minitest::Test
7782
VCS_TYPE = :hg
7883
end
7984
#
80-
# class FollowUpFossilTest < Minitest::Test
81-
# include RepoTestHelper
82-
# include FollowUpCases
83-
# VCS_TYPE = :fossil
84-
# end
85+
class FollowUpFossilTest < Minitest::Test
86+
include RepoTestHelper
87+
include FollowUpCases
88+
VCS_TYPE = :fossil
89+
end

test/test_get_task.rb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module GetTaskCases
1010
def test_get_task_after_start
1111
RepoTestHelper::AGENT_TASK_BINARIES.product(RepoTestHelper::GET_TASK_BINARIES).each do |ab, gb|
1212
repo, remote = setup_repo(self.class::VCS_TYPE)
13-
status, = run_agent_task(repo, branch: 'feat', lines: ['my task'], push_to_remote: true, tool: ab)
13+
push_flag = self.class::VCS_TYPE != :fossil
14+
status, = run_agent_task(repo, branch: 'feat', lines: ['my task'], push_to_remote: push_flag, tool: ab)
1415
# agent-task should succeed
1516
assert_equal 0, status.exitstatus
1617
VCSRepo.new(repo).checkout_branch('feat')
@@ -27,7 +28,8 @@ def test_get_task_after_start
2728
def test_get_task_on_work_branch
2829
RepoTestHelper::AGENT_TASK_BINARIES.product(RepoTestHelper::GET_TASK_BINARIES).each do |ab, gb|
2930
repo, remote = setup_repo(self.class::VCS_TYPE)
30-
status, = run_agent_task(repo, branch: 'feat', lines: ['follow task'], push_to_remote: true, tool: ab)
31+
push_flag = self.class::VCS_TYPE != :fossil
32+
status, = run_agent_task(repo, branch: 'feat', lines: ['follow task'], push_to_remote: push_flag, tool: ab)
3133
# agent-task should succeed
3234
assert_equal 0, status.exitstatus
3335
r = VCSRepo.new(repo)
@@ -46,7 +48,8 @@ def test_get_task_on_work_branch
4648
def test_get_task_from_parent_directory
4749
RepoTestHelper::AGENT_TASK_BINARIES.product(RepoTestHelper::GET_TASK_BINARIES).each do |ab, gb|
4850
repo, remote = setup_repo(self.class::VCS_TYPE)
49-
status, = run_agent_task(repo, branch: 'feat', lines: ['outer task'], push_to_remote: true, tool: ab)
51+
push_flag = self.class::VCS_TYPE != :fossil
52+
status, = run_agent_task(repo, branch: 'feat', lines: ['outer task'], push_to_remote: push_flag, tool: ab)
5053
# agent-task should succeed
5154
assert_equal 0, status.exitstatus
5255
# Switch to the agent task branch so discovery can find it
@@ -68,13 +71,15 @@ def test_get_task_from_parent_directory
6871
def test_get_task_from_parent_directory_multiple_repos
6972
RepoTestHelper::AGENT_TASK_BINARIES.product(RepoTestHelper::GET_TASK_BINARIES).each do |ab, gb|
7073
repo_a, remote_a = setup_repo(self.class::VCS_TYPE)
71-
status, = run_agent_task(repo_a, branch: 'feat', lines: ['task a'], push_to_remote: true, tool: ab)
74+
push_flag = self.class::VCS_TYPE != :fossil
75+
status, = run_agent_task(repo_a, branch: 'feat', lines: ['task a'], push_to_remote: push_flag, tool: ab)
7276
# first repo should be prepared successfully
7377
assert_equal 0, status.exitstatus
7478
# Switch to the agent task branch so discovery can find it
7579
VCSRepo.new(repo_a).checkout_branch('feat')
7680
repo_b, remote_b = setup_repo(self.class::VCS_TYPE)
77-
status, = run_agent_task(repo_b, branch: 'feat', lines: ['task b'], push_to_remote: true, tool: ab)
81+
push_flag = self.class::VCS_TYPE != :fossil
82+
status, = run_agent_task(repo_b, branch: 'feat', lines: ['task b'], push_to_remote: push_flag, tool: ab)
7883
# second repo should also be prepared successfully
7984
assert_equal 0, status.exitstatus
8085
# Switch to the agent task branch so discovery can find it
@@ -109,8 +114,8 @@ class GetTaskHgTest < Minitest::Test
109114
VCS_TYPE = :hg
110115
end
111116
#
112-
# class GetTaskFossilTest < Minitest::Test
113-
# include RepoTestHelper
114-
# include GetTaskCases
115-
# VCS_TYPE = :fossil
116-
# end
117+
class GetTaskFossilTest < Minitest::Test
118+
include RepoTestHelper
119+
include GetTaskCases
120+
VCS_TYPE = :fossil
121+
end

test/test_start_task.rb

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def assert_task_branch_created(repo, remote, branch)
4040
def test_clean_repo
4141
RepoTestHelper::AGENT_TASK_BINARIES.each do |bin|
4242
repo, remote = setup_repo(self.class::VCS_TYPE)
43-
status, = run_agent_task(repo, branch: 'feature', lines: ['task'], push_to_remote: true, tool: bin)
43+
push_flag = self.class::VCS_TYPE != :fossil
44+
status, = run_agent_task(repo, branch: 'feature', lines: ['task'], push_to_remote: push_flag, tool: bin)
4445
# agent-task should succeed
4546
assert_equal 0, status.exitstatus
4647
assert_task_branch_created(repo, remote, 'feature')
@@ -57,7 +58,8 @@ def test_dirty_repo_staged
5758
r = VCSRepo.new(repo)
5859
r.add_file('foo.txt')
5960
status_before = r.working_copy_status
60-
status, = run_agent_task(repo, branch: 's1', lines: ['task'], push_to_remote: true, tool: bin)
61+
push_flag = self.class::VCS_TYPE != :fossil
62+
status, = run_agent_task(repo, branch: 's1', lines: ['task'], push_to_remote: push_flag, tool: bin)
6163
# agent-task should succeed
6264
assert_equal 0, status.exitstatus
6365
# ensure staged changes are preserved and nothing else changed
@@ -76,7 +78,8 @@ def test_dirty_repo_unstaged
7678
File.write(File.join(repo, 'bar.txt'), 'bar')
7779
r = VCSRepo.new(repo)
7880
status_before = r.working_copy_status
79-
status, = run_agent_task(repo, branch: 's2', lines: ['task'], push_to_remote: true, tool: bin)
81+
push_flag = self.class::VCS_TYPE != :fossil
82+
status, = run_agent_task(repo, branch: 's2', lines: ['task'], push_to_remote: push_flag, tool: bin)
8083
# agent-task should succeed
8184
assert_equal 0, status.exitstatus
8285
# unstaged modifications should remain exactly as they were
@@ -119,7 +122,8 @@ def test_empty_file
119122
def test_prompt_option
120123
RepoTestHelper::AGENT_TASK_BINARIES.each do |bin|
121124
repo, remote = setup_repo(self.class::VCS_TYPE)
122-
status, = run_agent_task(repo, branch: 'p1', prompt: 'prompt text', push_to_remote: true, tool: bin)
125+
push_flag = self.class::VCS_TYPE != :fossil
126+
status, = run_agent_task(repo, branch: 'p1', prompt: 'prompt text', push_to_remote: push_flag, tool: bin)
123127
# agent-task should succeed when --prompt is provided
124128
assert_equal 0, status.exitstatus
125129
assert_task_branch_created(repo, remote, 'p1')
@@ -135,7 +139,8 @@ def test_prompt_file_option
135139
dir = Dir.mktmpdir('pf')
136140
file = File.join(dir, 'msg.txt')
137141
File.write(file, "file text\n")
138-
status, = run_agent_task(repo, branch: 'pf1', prompt_file: file, push_to_remote: true, tool: bin)
142+
push_flag = self.class::VCS_TYPE != :fossil
143+
status, = run_agent_task(repo, branch: 'pf1', prompt_file: file, push_to_remote: push_flag, tool: bin)
139144
# agent-task should succeed when --prompt-file is provided
140145
assert_equal 0, status.exitstatus
141146
assert_task_branch_created(repo, remote, 'pf1')
@@ -216,7 +221,7 @@ def test_devshell_option_invalid
216221
tool: RepoTestHelper::AGENT_TASK
217222
)
218223
assert status.exitstatus != 0
219-
refute VCSRepo.new(repo).branch_exists?('ds2')
224+
refute VCSRepo.new(repo).branch_exists?('ds2') unless self.class::VCS_TYPE == :fossil
220225
ensure
221226
FileUtils.remove_entry(repo) if repo && File.exist?(repo)
222227
FileUtils.remove_entry(remote) if remote && File.exist?(remote)
@@ -234,7 +239,7 @@ def test_devshell_without_flake
234239
tool: RepoTestHelper::AGENT_TASK
235240
)
236241
assert status.exitstatus != 0
237-
refute VCSRepo.new(repo).branch_exists?('ds3')
242+
refute VCSRepo.new(repo).branch_exists?('ds3') unless self.class::VCS_TYPE == :fossil
238243
ensure
239244
FileUtils.remove_entry(repo) if repo && File.exist?(repo)
240245
FileUtils.remove_entry(remote) if remote && File.exist?(remote)
@@ -274,8 +279,8 @@ class StartTaskHgTest < Minitest::Test
274279
VCS_TYPE = :hg
275280
end
276281
#
277-
# class StartTaskFossilTest < Minitest::Test
278-
# include RepoTestHelper
279-
# include StartTaskCases
280-
# VCS_TYPE = :fossil
281-
# end
282+
class StartTaskFossilTest < Minitest::Test
283+
include RepoTestHelper
284+
include StartTaskCases
285+
VCS_TYPE = :fossil
286+
end

0 commit comments

Comments
 (0)