ruby_raider 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/ffmpeg/build.sh +208 -0
- data/.github/ffmpeg/check.sh +72 -0
- data/.github/ffmpeg/frames.rb +34 -0
- data/.github/ffmpeg/probe.sh +17 -0
- data/.github/workflows/ffmpeg.yml +160 -0
- data/README.md +226 -33
- data/RELEASE.md +19 -0
- data/lib/commands/flow_commands.rb +104 -0
- data/lib/generators/templates/common/read_me.tt +6 -7
- data/lib/generators/templates/flows/flow_helper.tt +42 -0
- data/lib/generators/templates/flows/run.tt +332 -0
- data/lib/generators/templates/helpers/video_helper.tt +1 -2
- data/lib/ruby_raider/ffmpeg.rb +38 -11
- data/lib/ruby_raider.rb +16 -0
- data/lib/utilities/flows/next_run.rb +61 -0
- data/lib/utilities/flows/notifier.rb +76 -0
- data/lib/utilities/flows/os/command_runner.rb +73 -0
- data/lib/utilities/flows/os/cron.rb +137 -0
- data/lib/utilities/flows/os/launchd.rb +164 -0
- data/lib/utilities/flows/os/linux.rb +63 -0
- data/lib/utilities/flows/os/systemd.rb +178 -0
- data/lib/utilities/flows/os/task_scheduler.rb +179 -0
- data/lib/utilities/flows/project.rb +170 -0
- data/lib/utilities/flows/run_log.rb +61 -0
- data/lib/utilities/flows/runner.rb +206 -0
- data/lib/utilities/flows/schedule.rb +221 -0
- data/lib/utilities/flows/schedule_store.rb +135 -0
- data/lib/utilities/flows/scheduler.rb +187 -0
- data/lib/version +1 -1
- data/sig/commands/flow_commands.rbs +13 -0
- data/sig/ruby_raider/ffmpeg.rbs +1 -0
- data/sig/ruby_raider.rbs +2 -0
- data/sig/utilities/flows/next_run.rbs +15 -0
- data/sig/utilities/flows/notifier.rbs +29 -0
- data/sig/utilities/flows/os/command_runner.rbs +27 -0
- data/sig/utilities/flows/os/cron.rbs +34 -0
- data/sig/utilities/flows/os/launchd.rbs +45 -0
- data/sig/utilities/flows/os/linux.rbs +27 -0
- data/sig/utilities/flows/os/systemd.rbs +43 -0
- data/sig/utilities/flows/os/task_scheduler.rbs +53 -0
- data/sig/utilities/flows/project.rbs +46 -0
- data/sig/utilities/flows/run_log.rbs +22 -0
- data/sig/utilities/flows/runner.rbs +35 -0
- data/sig/utilities/flows/schedule.rbs +61 -0
- data/sig/utilities/flows/schedule_store.rbs +34 -0
- data/sig/utilities/flows/scheduler.rbs +42 -0
- data/spec/commands/flow_commands_spec.rb +128 -0
- data/spec/generators/flow_helper_spec.rb +40 -0
- data/spec/generators/video_helper_spec.rb +21 -4
- data/spec/integration/content/gemfile_content_spec.rb +2 -2
- data/spec/integration/content/readme_content_spec.rb +7 -2
- data/spec/integration/end_to_end_spec.rb +83 -8
- data/spec/integration/flows/flow_project.rb +62 -0
- data/spec/integration/flows/run_command_spec.rb +91 -0
- data/spec/integration/flows/run_lifecycle_spec.rb +383 -0
- data/spec/utilities/ffmpeg_spec.rb +80 -7
- data/spec/utilities/flows/next_run_spec.rb +119 -0
- data/spec/utilities/flows/notifier_spec.rb +121 -0
- data/spec/utilities/flows/os/command_runner_spec.rb +56 -0
- data/spec/utilities/flows/os/cron_spec.rb +287 -0
- data/spec/utilities/flows/os/launchd_spec.rb +293 -0
- data/spec/utilities/flows/os/linux_spec.rb +149 -0
- data/spec/utilities/flows/os/systemd_spec.rb +329 -0
- data/spec/utilities/flows/os/task_scheduler_spec.rb +505 -0
- data/spec/utilities/flows/project_spec.rb +178 -0
- data/spec/utilities/flows/run_log_spec.rb +47 -0
- data/spec/utilities/flows/runner_spec.rb +313 -0
- data/spec/utilities/flows/schedule_spec.rb +233 -0
- data/spec/utilities/flows/schedule_store_spec.rb +137 -0
- data/spec/utilities/flows/scheduler_spec.rb +329 -0
- data/spec/utilities/video_command_spec.rb +13 -0
- metadata +58 -7
- data/docs/superpowers/plans/2026-10-25-failure-video-replay.md +0 -400
- data/docs/superpowers/plans/2026-10-26-parity-cleanup.md +0 -233
- data/docs/superpowers/plans/2026-10-28-failure-card.md +0 -295
- data/docs/superpowers/specs/2026-10-25-failure-video-replay-design.md +0 -214
- data/docs/superpowers/specs/2026-10-28-failure-card-design.md +0 -210
|
@@ -41,11 +41,51 @@ describe RubyRaider::Ffmpeg do
|
|
|
41
41
|
expect(described_class.platform(host_os: 'linux-gnu', host_cpu: 'aarch64')).to be_nil
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
it '
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
expect(assets.
|
|
48
|
-
|
|
44
|
+
it 'pins a SHA-256 and the ffmpeg-7.1 release url for each of the four platforms', :aggregate_failures do
|
|
45
|
+
expect(described_class::MANIFEST[:version]).to eq('7.1')
|
|
46
|
+
base = 'https://github.com/RaiderHQ/ruby_raider/releases/download/ffmpeg-7.1/ffmpeg-7.1-'
|
|
47
|
+
expect(described_class::MANIFEST[:assets].transform_values { |a| a[:url] }).to eq(
|
|
48
|
+
'darwin-arm64' => "#{base}darwin-arm64", 'darwin-x64' => "#{base}darwin-x64",
|
|
49
|
+
'linux-x64' => "#{base}linux-x64", 'windows-x64' => "#{base}windows-x64.exe"
|
|
50
|
+
)
|
|
51
|
+
shas = described_class::MANIFEST[:assets].values.map { |a| a[:sha256] }
|
|
52
|
+
expect(shas).to all(match(/\A\h{64}\z/))
|
|
53
|
+
expect(shas.uniq.size).to eq(4)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe 'the pinned checksums' do
|
|
57
|
+
let(:real) { described_class::MANIFEST }
|
|
58
|
+
|
|
59
|
+
it 'is obtainable on every supported platform without an override' do
|
|
60
|
+
described_class::PLATFORMS.each do |p|
|
|
61
|
+
expect(described_class.obtainable?(env: {}, platform: p)).to be(true)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'discards a download whose bytes do not match the pinned checksum', :aggregate_failures do
|
|
66
|
+
described_class::PLATFORMS.each do |p|
|
|
67
|
+
result = described_class.ensure!(env:, manifest: real, fetch:, warn: warner, platform: p)
|
|
68
|
+
expect(result).to be_nil
|
|
69
|
+
end
|
|
70
|
+
expect(calls).to eq(real[:assets].values.map { |a| a[:url] })
|
|
71
|
+
expect(warnings).to all(include('checksum mismatch'))
|
|
72
|
+
expect(Dir.glob(File.join(cache, '**', '*'))).to be_empty
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# FFMPEG_ARTIFACTS=<dir> holding ffmpeg-7.1-<platform>[.exe] (the build workflow's artifacts
|
|
76
|
+
# or the release assets) proves those exact bytes pass verification and get cached.
|
|
77
|
+
it 'accepts the built binaries', unless: ENV.fetch('FFMPEG_ARTIFACTS', '').empty? do
|
|
78
|
+
described_class::PLATFORMS.each do |p|
|
|
79
|
+
name = File.basename(real[:assets][p][:url])
|
|
80
|
+
source = File.join(ENV.fetch('FFMPEG_ARTIFACTS'), name)
|
|
81
|
+
copy = ->(_url, dest) { FileUtils.cp(source, dest) }
|
|
82
|
+
own = { 'RAIDER_CACHE_DIR' => File.join(cache, p) }
|
|
83
|
+
path = described_class.ensure!(env: own, manifest: real, fetch: copy, warn: warner, platform: p)
|
|
84
|
+
expect(path).to eq(described_class.cached_path(env: own, manifest: real, platform: p))
|
|
85
|
+
expect(File.executable?(path)).to be(true)
|
|
86
|
+
end
|
|
87
|
+
expect(warnings).to be_empty
|
|
88
|
+
end
|
|
49
89
|
end
|
|
50
90
|
|
|
51
91
|
it 'derives the cache dir from RAIDER_CACHE_DIR or the home cache', :aggregate_failures do
|
|
@@ -254,6 +294,39 @@ describe RubyRaider::Ffmpeg do
|
|
|
254
294
|
expect(warnings).to eq(['cached ffmpeg failed checksum; video disabled'])
|
|
255
295
|
end
|
|
256
296
|
|
|
297
|
+
describe 'download size cap' do
|
|
298
|
+
let(:dest) { File.join(cache, 'download.part') }
|
|
299
|
+
let(:deadline) { Process.clock_gettime(Process::CLOCK_MONOTONIC) + 60 }
|
|
300
|
+
|
|
301
|
+
def ok_response(length, chunks)
|
|
302
|
+
response = Net::HTTPOK.new('1.1', '200', 'OK')
|
|
303
|
+
response['content-length'] = length.to_s if length
|
|
304
|
+
allow(response).to receive(:read_body) { |&block| chunks.each(&block) }
|
|
305
|
+
response
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
it 'refuses a Content-Length over the cap before writing anything', :aggregate_failures do
|
|
309
|
+
response = ok_response(described_class::MAX_DOWNLOAD_BYTES + 1, ['x'])
|
|
310
|
+
expect { described_class.send(:handle_response, response, dest, deadline, 60) }
|
|
311
|
+
.to raise_error(IOError, /larger than/)
|
|
312
|
+
expect(File).not_to exist(dest)
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
it 'stops writing once the body passes the cap, whatever Content-Length said' do
|
|
316
|
+
stub_const("#{described_class}::MAX_DOWNLOAD_BYTES", 10)
|
|
317
|
+
response = ok_response(nil, ['x' * 6, 'x' * 6, 'x' * 6])
|
|
318
|
+
expect { described_class.send(:handle_response, response, dest, deadline, 60) }
|
|
319
|
+
.to raise_error(IOError, /larger than/)
|
|
320
|
+
expect(File.size(dest)).to be <= 10
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
it 'writes a body within the cap' do
|
|
324
|
+
response = ok_response(4, %w[ab cd])
|
|
325
|
+
expect(described_class.send(:handle_response, response, dest, deadline, 60)).to be_nil
|
|
326
|
+
expect(File.read(dest)).to eq('abcd')
|
|
327
|
+
end
|
|
328
|
+
end
|
|
329
|
+
|
|
257
330
|
describe 'DEFAULT_WARN' do
|
|
258
331
|
it 'writes to $stderr even when $VERBOSE is nil' do
|
|
259
332
|
original = $VERBOSE
|
|
@@ -281,8 +354,8 @@ describe RubyRaider::Ffmpeg do
|
|
|
281
354
|
expect(described_class.obtainable?(env: {}, manifest:, platform: 'linux-x64')).to be(true)
|
|
282
355
|
end
|
|
283
356
|
|
|
284
|
-
it 'is false with no override and a nil checksum
|
|
285
|
-
expect(described_class.obtainable?(env: {}, platform: 'darwin-arm64')).to be(false)
|
|
357
|
+
it 'is false with no override and a nil checksum' do
|
|
358
|
+
expect(described_class.obtainable?(env: {}, manifest: unpublished, platform: 'darwin-arm64')).to be(false)
|
|
286
359
|
end
|
|
287
360
|
|
|
288
361
|
it 'is false for an unknown platform or a non-executable override' do
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'tmpdir'
|
|
4
|
+
require_relative '../../../lib/utilities/flows/next_run'
|
|
5
|
+
|
|
6
|
+
# Flow specs live under spec/utilities/flows, next to the code in lib/utilities/flows
|
|
7
|
+
RSpec.describe RubyRaider::Flows::NextRun do # rubocop:disable RSpec/FilePath
|
|
8
|
+
let(:dir) { File.realpath(Dir.mktmpdir('flows-next-run')) }
|
|
9
|
+
let(:project) { RubyRaider::Flows::Project.new(dir) }
|
|
10
|
+
|
|
11
|
+
around do |example|
|
|
12
|
+
zone = ENV.fetch('TZ', nil)
|
|
13
|
+
ENV['TZ'] = 'Europe/Copenhagen'
|
|
14
|
+
example.run
|
|
15
|
+
ensure
|
|
16
|
+
ENV['TZ'] = zone
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
after { FileUtils.rm_rf(dir) }
|
|
20
|
+
|
|
21
|
+
def rule(every, at = '08:00', on: nil)
|
|
22
|
+
RubyRaider::Flows::Schedule.build(project: project, name: 'report', every: every, at: at, on: on)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def next_after(schedule, *local)
|
|
26
|
+
described_class.after(schedule, Time.local(*local))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# [wall clock, UTC offset in hours] of a local time
|
|
30
|
+
def wall(time)
|
|
31
|
+
[time.strftime('%F %R'), time.utc_offset / 3600]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe 'every day' do
|
|
35
|
+
it 'runs later today, or tomorrow once the time has passed' do
|
|
36
|
+
expect([wall(next_after(rule('day'), 2026, 11, 9, 7, 59)), wall(next_after(rule('day'), 2026, 11, 9, 8, 0))]).to eq(
|
|
37
|
+
[['2026-11-09 08:00', 1], ['2026-11-10 08:00', 1]]
|
|
38
|
+
)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'is strictly after now, by seconds too' do
|
|
42
|
+
expect(wall(next_after(rule('day'), 2026, 11, 9, 8, 0, 1))).to eq(['2026-11-10 08:00', 1])
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'crosses a month and a year' do
|
|
46
|
+
expect(wall(next_after(rule('day'), 2026, 12, 31, 9, 0))).to eq(['2027-01-01 08:00', 1])
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe 'every weekday' do
|
|
51
|
+
it 'skips the weekend' do
|
|
52
|
+
# 2026-11-13 is a Friday
|
|
53
|
+
expect(wall(next_after(rule('weekday'), 2026, 11, 13, 9, 0))).to eq(['2026-11-16 08:00', 1])
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
describe 'every week' do
|
|
58
|
+
it 'runs on its day, a week later once that has passed' do
|
|
59
|
+
# 2026-11-09 is a Monday
|
|
60
|
+
expect([wall(next_after(rule('week', on: 'wed'), 2026, 11, 9, 9, 0)), wall(next_after(rule('week', on: 'mon'), 2026, 11, 9, 8, 0))]).to eq(
|
|
61
|
+
[['2026-11-11 08:00', 1], ['2026-11-16 08:00', 1]]
|
|
62
|
+
)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
describe 'every hour' do
|
|
67
|
+
it 'runs at the next matching minute' do
|
|
68
|
+
expect([wall(next_after(rule('hour', ':15'), 2026, 11, 9, 10, 20)), wall(next_after(rule('hour', ':15'), 2026, 11, 9, 10, 14, 59))]).to eq(
|
|
69
|
+
[['2026-11-09 11:15', 1], ['2026-11-09 10:15', 1]]
|
|
70
|
+
)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'crosses midnight' do
|
|
74
|
+
expect(wall(next_after(rule('hour', ':00'), 2026, 11, 9, 23, 30))).to eq(['2026-11-10 00:00', 1])
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Copenhagen: 2026-03-29 02:00 CET jumps to 03:00 CEST; 2026-10-25 03:00 CEST falls back to 02:00 CET
|
|
79
|
+
describe 'the last Sunday of March' do
|
|
80
|
+
it 'runs a time in the skipped hour at the first minute after the gap' do
|
|
81
|
+
expect(wall(next_after(rule('day', '02:30'), 2026, 3, 29, 0, 0))).to eq(['2026-03-29 03:00', 2])
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'goes back to the normal time the next day' do
|
|
85
|
+
expect(wall(next_after(rule('day', '02:30'), 2026, 3, 29, 3, 0))).to eq(['2026-03-30 02:30', 2])
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it 'keeps a time outside the gap' do
|
|
89
|
+
expect(wall(next_after(rule('day'), 2026, 3, 29, 0, 0))).to eq(['2026-03-29 08:00', 2])
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'runs every hour at the next real matching minute' do
|
|
93
|
+
expect(wall(next_after(rule('hour', ':30'), 2026, 3, 29, 1, 45))).to eq(['2026-03-29 03:30', 2])
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
describe 'the last Sunday of October' do
|
|
98
|
+
it 'runs a repeated time at its first occurrence' do
|
|
99
|
+
expect(wall(next_after(rule('day', '02:30'), 2026, 10, 25, 0, 0))).to eq(['2026-10-25 02:30', 2])
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it 'does not run again at the second occurrence' do
|
|
103
|
+
first = next_after(rule('day', '02:30'), 2026, 10, 25, 0, 0)
|
|
104
|
+
|
|
105
|
+
expect(wall(described_class.after(rule('day', '02:30'), first))).to eq(['2026-10-26 02:30', 1])
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it 'runs every hour in both repeated hours' do
|
|
109
|
+
first = next_after(rule('hour', ':30'), 2026, 10, 25, 1, 45)
|
|
110
|
+
second = described_class.after(rule('hour', ':30'), first)
|
|
111
|
+
|
|
112
|
+
expect([wall(first), wall(second), second - first]).to eq([['2026-10-25 02:30', 2], ['2026-10-25 02:30', 1], 3600.0])
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it 'runs a week rule on the changeover day' do
|
|
116
|
+
expect(wall(next_after(rule('week', '02:30', on: 'sun'), 2026, 10, 20, 12, 0))).to eq(['2026-10-25 02:30', 2])
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'stringio'
|
|
4
|
+
require_relative '../../../lib/utilities/flows/notifier'
|
|
5
|
+
|
|
6
|
+
# Flow specs live under spec/utilities/flows, next to the code in lib/utilities/flows
|
|
7
|
+
RSpec.describe RubyRaider::Flows::Notifier do # rubocop:disable RSpec/FilePath
|
|
8
|
+
# Records each command instead of running it: no real osascript, notify-send or PowerShell
|
|
9
|
+
let(:runner) do
|
|
10
|
+
Class.new do
|
|
11
|
+
attr_reader :calls
|
|
12
|
+
attr_accessor :exitstatus
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
@calls = []
|
|
16
|
+
@exitstatus = 0
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def call(*argv, env: {}, timeout: nil, **)
|
|
20
|
+
@calls << { argv: argv, env: env, timeout: timeout }
|
|
21
|
+
RubyRaider::Flows::Os::CommandRunner::Result.new(stdout: '', stderr: 'no notification server', exitstatus: exitstatus)
|
|
22
|
+
end
|
|
23
|
+
end.new
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
let(:err) { StringIO.new }
|
|
27
|
+
let(:hostile) do
|
|
28
|
+
["'; rm -rf ~; '", '" & do shell script "id" & "', '$(id)', '</text>', '-u critical', '$env:USERPROFILE', '`whoami`']
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
let(:powershell) { 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe' }
|
|
32
|
+
|
|
33
|
+
def notifier(host_os) = described_class.new(runner: runner, host_os: host_os, err: err, powershell: powershell)
|
|
34
|
+
|
|
35
|
+
it 'passes the title and message to osascript as argv items of a fixed script on macOS' do
|
|
36
|
+
expect(notifier('darwin25').notify('Ruby Raider flow report', 'Failed at step 3 (Open report)')).to be(true)
|
|
37
|
+
|
|
38
|
+
expect(runner.calls).to eq([{ argv: ['/usr/bin/osascript', '-e', 'on run argv', '-e',
|
|
39
|
+
'display notification (item 2 of argv) with title (item 1 of argv)', '-e', 'end run', '--',
|
|
40
|
+
'Ruby Raider flow report', 'Failed at step 3 (Open report)'], env: {}, timeout: 15 }])
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'ends osascript option parsing before the title, so -e in a title is not a script' do
|
|
44
|
+
notifier('darwin25').notify('-e', 'property p : (1 + 2)')
|
|
45
|
+
|
|
46
|
+
expect(runner.calls.first[:argv].last(3)).to eq(['--', '-e', 'property p : (1 + 2)'])
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'keeps hostile text out of the script on every OS' do
|
|
50
|
+
hosts = %w[darwin25 linux-gnu mingw32]
|
|
51
|
+
scripts = hosts.to_h do |host|
|
|
52
|
+
hostile.each { |text| notifier(host).notify(text, text) }
|
|
53
|
+
calls = runner.calls.pop(hostile.size)
|
|
54
|
+
[host, calls.map { |call| host == 'mingw32' ? call[:argv] : call[:argv][0...-2] }.uniq]
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
expect(scripts.values.map(&:size)).to eq([1, 1, 1])
|
|
58
|
+
expect(scripts.values.flatten.join("\n")).not_to include(*hostile)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'passes hostile text unchanged as the last argv items on macOS' do
|
|
62
|
+
hostile.each { |text| notifier('darwin25').notify(text, text) }
|
|
63
|
+
|
|
64
|
+
expect(runner.calls.map { |call| call[:argv].last(2) }).to eq(hostile.map { |text| [text, text] })
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it 'stops notify-send option parsing before the title and escapes markup in the message on Linux' do
|
|
68
|
+
notifier('linux-gnu').notify('-u critical', 'a < b & c > d')
|
|
69
|
+
|
|
70
|
+
expect(runner.calls.first[:argv]).to eq(['notify-send', '--app-name=Ruby Raider', '--', '-u critical', 'a < b & c > d'])
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'passes the title and message to a fixed PowerShell script through the environment on Windows' do
|
|
74
|
+
notifier('mswin64').notify('$env:USERPROFILE', '`whoami`')
|
|
75
|
+
|
|
76
|
+
expect(runner.calls.first).to eq(
|
|
77
|
+
argv: [powershell, '-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-Command', described_class::TOAST_SCRIPT],
|
|
78
|
+
env: { 'RAIDER_NOTIFY_TITLE' => '$env:USERPROFILE', 'RAIDER_NOTIFY_MESSAGE' => '`whoami`' }, timeout: 15
|
|
79
|
+
)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'finds PowerShell under SystemRoot by default' do
|
|
83
|
+
allow(ENV).to receive(:fetch).and_call_original
|
|
84
|
+
allow(ENV).to receive(:fetch).with('SystemRoot', 'C:\\Windows').and_return('D:\\Win')
|
|
85
|
+
described_class.new(runner: runner, host_os: 'mingw32', err: err).notify('t', 'm')
|
|
86
|
+
|
|
87
|
+
expect(runner.calls.first[:argv].first).to eq(File.join('D:\\Win', 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe'))
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'builds the toast from the environment, never from text joined into XML' do
|
|
91
|
+
script = described_class::TOAST_SCRIPT
|
|
92
|
+
|
|
93
|
+
expect(script).to include('$env:RAIDER_NOTIFY_TITLE', '$env:RAIDER_NOTIFY_MESSAGE', 'CreateTextNode', 'ToastText02')
|
|
94
|
+
expect(script).not_to include('"', "\n", 'EncodedCommand')
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'makes control characters printable and caps the message at 200 characters' do
|
|
98
|
+
notifier('darwin25').notify("flow\e[2J", "#{'x' * 250}\n")
|
|
99
|
+
|
|
100
|
+
expect(runner.calls.first[:argv].last(2)).to eq(['flow?[2J', 'x' * 200])
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it 'does nothing on another OS' do
|
|
104
|
+
expect([notifier('solaris2').notify('t', 'm'), runner.calls]).to eq([false, []])
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it 'returns false and warns once when the notification fails, without raising' do
|
|
108
|
+
runner.exitstatus = 1
|
|
109
|
+
sender = notifier('linux-gnu')
|
|
110
|
+
|
|
111
|
+
expect([sender.notify('t', 'm'), sender.notify('t', 'm')]).to eq([false, false])
|
|
112
|
+
expect(err.string).to eq("Could not show a desktop notification: no notification server\n")
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it 'returns false when the runner raises' do
|
|
116
|
+
allow(runner).to receive(:call).and_raise(IOError, 'closed stream')
|
|
117
|
+
|
|
118
|
+
expect(notifier('darwin25').notify('t', 'm')).to be(false)
|
|
119
|
+
expect(err.string).to include('closed stream')
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rbconfig'
|
|
4
|
+
require_relative '../../../../lib/utilities/flows/os/command_runner'
|
|
5
|
+
|
|
6
|
+
# Flow specs live under spec/utilities/flows, next to the code in lib/utilities/flows
|
|
7
|
+
RSpec.describe RubyRaider::Flows::Os::CommandRunner do # rubocop:disable RSpec/FilePath
|
|
8
|
+
let(:runner) { described_class.new }
|
|
9
|
+
let(:ruby) { RbConfig.ruby }
|
|
10
|
+
|
|
11
|
+
it 'captures stdout, stderr and the exit status' do
|
|
12
|
+
result = runner.call(ruby, '-e', '$stdout.print "out"; $stderr.print "err"; exit 3')
|
|
13
|
+
|
|
14
|
+
expect([result.stdout, result.stderr, result.exitstatus, result.success?]).to eq(['out', 'err', 3, false])
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'succeeds on exit 0' do
|
|
18
|
+
expect(runner.call(ruby, '-e', 'exit 0').success?).to be(true)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'feeds stdin' do
|
|
22
|
+
expect(runner.call(ruby, '-e', 'print $stdin.read.upcase', stdin_data: "a b\n").stdout).to eq("A B\n")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'adds env values to the command environment' do
|
|
26
|
+
result = runner.call(ruby, '-e', 'print ENV["RAIDER_NOTIFY_TITLE"]', env: { 'RAIDER_NOTIFY_TITLE' => '$(id)' })
|
|
27
|
+
|
|
28
|
+
expect(result.stdout).to eq('$(id)')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'stops a command that runs past the timeout' do
|
|
32
|
+
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
33
|
+
result = runner.call(ruby, '-e', 'sleep 10', timeout: 0.3)
|
|
34
|
+
|
|
35
|
+
expect([result.success?, result.stderr]).to eq([false, "#{ruby} took longer than 0.3 s"])
|
|
36
|
+
expect(Process.clock_gettime(Process::CLOCK_MONOTONIC) - started).to be < 5
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'passes arguments without a shell' do
|
|
40
|
+
hostile = ["'; rm -rf ~; '", '$(id)', '%h', '</string>']
|
|
41
|
+
|
|
42
|
+
expect(runner.call(ruby, '-e', 'print ARGV.join("|")', *hostile).stdout).to eq(hostile.join('|'))
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'never runs a single string through a shell' do
|
|
46
|
+
result = runner.call('echo $(id)')
|
|
47
|
+
|
|
48
|
+
expect([result.success?, result.stdout]).to eq([false, ''])
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'returns a failed result for a missing executable' do
|
|
52
|
+
result = runner.call('/no/such/raider-command', 'x')
|
|
53
|
+
|
|
54
|
+
expect([result.success?, result.exitstatus, result.stderr]).to match([false, 127, /raider-command/])
|
|
55
|
+
end
|
|
56
|
+
end
|