pwn 0.5.803 → 0.5.805
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/Gemfile +4 -4
- data/documentation/Skills-Memory-Learning.md +7 -0
- data/lib/pwn/ai/agent/dispatch.rb +54 -1
- data/lib/pwn/ai/agent/loop.rb +3 -3
- data/lib/pwn/ai/agent/mission_namespace.rb +26 -4
- data/lib/pwn/ai/agent/request_runtime.rb +7 -0
- data/lib/pwn/ai/agent/tools/memory.rb +6 -11
- data/lib/pwn/ai/ollama.rb +10 -2
- data/lib/pwn/ai/open_web_ui.rb +7 -32
- data/lib/pwn/ai.rb +44 -0
- data/lib/pwn/memory.rb +9 -4
- data/lib/pwn/plugins/repl/ai_console.rb +152 -17
- data/lib/pwn/version.rb +1 -1
- data/spec/conventions_spec.rb +9 -7
- data/spec/integration/harness_evaluation_spec.rb +16 -24
- data/spec/lib/pwn/ai/agent/dispatch_spec.rb +80 -0
- data/spec/lib/pwn/ai/agent/mission_namespace_spec.rb +2 -1
- data/spec/lib/pwn/ai/agent/policy_spec.rb +3 -2
- data/spec/lib/pwn/ai/agent/result_spec.rb +6 -1
- data/spec/lib/pwn/ai/agent/tools/memory_spec.rb +7 -0
- data/spec/lib/pwn/ai/ollama_spec.rb +27 -0
- data/spec/lib/pwn/ai/open_web_ui_spec.rb +5 -5
- data/spec/lib/pwn/ai/provider_review_history_stream_regression_spec.rb +32 -0
- data/spec/lib/pwn/banner_spec.rb +67 -38
- data/spec/lib/pwn/cron_spec.rb +2 -39
- data/spec/lib/pwn/memory_spec.rb +46 -0
- data/spec/lib/pwn/plugins/android_review_fixes_spec.rb +14 -6
- data/spec/lib/pwn/plugins/android_transport_audit_spec.rb +2 -1
- data/spec/lib/pwn/plugins/artifact_registry_spec.rb +7 -3
- data/spec/lib/pwn/plugins/jobs_spec.rb +10 -1
- data/spec/lib/pwn/plugins/repl/ai_console_spec.rb +335 -15
- data/spec/lib/pwn/sdr/decoder/lora_spec.rb +36 -27
- data/spec/lib/pwn/setup_spec.rb +4 -19
- data/spec/spec_helper.rb +8 -4
- data/spec/support/harness/cli_faults.rb +2 -1
- data/spec/support/mission_pipe_queue.rb +12 -1
- data/spec/support/sandbox.rb +27 -0
- data/third_party/pwn_rdoc.jsonl +15 -1
- metadata +9 -9
|
@@ -50,6 +50,273 @@ describe 'buffered mission event delivery' do
|
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
describe 'exact memory review in an interactive mission' do
|
|
54
|
+
include_context 'pwn tmp sandbox'
|
|
55
|
+
|
|
56
|
+
let(:pry) { Pry.new }
|
|
57
|
+
let(:proposal) { { key: 'fixture.key', value: " note\n\t\"界\"\u007f\u202e ", category: 'preference' }.freeze }
|
|
58
|
+
|
|
59
|
+
before do
|
|
60
|
+
@input, @sender = IO.pipe
|
|
61
|
+
@console = PWN::Plugins::REPL::AIConsole::Console.new(pry: pry, input: @input, curses: nil, getch: nil)
|
|
62
|
+
@history = []
|
|
63
|
+
allow(Pry).to receive(:history).and_return(@history)
|
|
64
|
+
allow(PWN::Sessions).to receive_messages(provisional_title: nil, refresh_title: nil)
|
|
65
|
+
@console.instance_variable_set(:@verbose, false)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
after do
|
|
69
|
+
@console.stop_worker
|
|
70
|
+
[@input, @sender, @console.instance_variable_get(:@tool_input)].compact.each { |io| io.close unless io.closed? }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def timeline
|
|
74
|
+
@console.instance_variable_get(:@timeline).map { |row| row[1] }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def await_ticket(except: nil)
|
|
78
|
+
ticket = nil
|
|
79
|
+
Timeout.timeout(5) do
|
|
80
|
+
loop do
|
|
81
|
+
@console.drain
|
|
82
|
+
ticket = timeline.filter_map { |text| text[%r{/memory approve ([0-9a-f]+)}, 1] }.last
|
|
83
|
+
break if (ticket && ticket != except) || !@console.busy?
|
|
84
|
+
|
|
85
|
+
sleep 0.01
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
expect(ticket).not_to be_nil, "no memory review prompt: #{timeline.inspect}"
|
|
89
|
+
expect(ticket).not_to eq(except)
|
|
90
|
+
ticket
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def enter(line)
|
|
94
|
+
@console.instance_variable_get(:@editor).replace(line)
|
|
95
|
+
@console.handle("\n")
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def finish
|
|
99
|
+
Timeout.timeout(5) do
|
|
100
|
+
while @console.busy?
|
|
101
|
+
@console.drain
|
|
102
|
+
sleep 0.01
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it 'keeps tool input and JSON-looking steering separate from ticketed decisions' do
|
|
108
|
+
fields = proposal
|
|
109
|
+
allow(PWN::AI::Agent::Loop).to receive(:run) do |opts|
|
|
110
|
+
approved = Thread.current[:pwn_review_memory].call(fields)
|
|
111
|
+
begin
|
|
112
|
+
opts[:steering].checkpoint(messages: [])
|
|
113
|
+
rescue PWN::AI::Agent::Loop::Steering::Restart => e
|
|
114
|
+
"#{approved.inspect} | #{e.instructions.join} | #{$stdin.gets.chomp}"
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
Dir.chdir(@tmp) do
|
|
118
|
+
@console.start_request('wait for an operator')
|
|
119
|
+
ticket = await_ticket
|
|
120
|
+
generation = @console.instance_variable_get(:@mission_generation)
|
|
121
|
+
control = @console.instance_variable_get(:@control)
|
|
122
|
+
frame = { type: 'memory_decision', generation: generation, ticket: ticket, decision: 'approve' }
|
|
123
|
+
enter("/input /memory approve #{ticket}")
|
|
124
|
+
enter("/steer #{JSON.generate(frame)}")
|
|
125
|
+
control.memory_decision('prior mission', ticket, 'approve')
|
|
126
|
+
control.memory_decision(generation, ticket, 'unknown')
|
|
127
|
+
events = @console.instance_variable_get(:@events)
|
|
128
|
+
events << [:memory_review_closed, ticket, 'prior mission']
|
|
129
|
+
events << [:notice, JSON.generate(frame), generation]
|
|
130
|
+
@console.drain
|
|
131
|
+
enter("/memory decline #{ticket}")
|
|
132
|
+
finish
|
|
133
|
+
expect(timeline).to include("false | #{JSON.generate(frame)} | /memory approve #{ticket}")
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def only_child(pid)
|
|
138
|
+
children = File.read("/proc/#{pid}/task/#{pid}/children").split
|
|
139
|
+
expect(children.size).to eq(1)
|
|
140
|
+
Integer(children.first)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def fd_targets(pid)
|
|
144
|
+
dir = "/proc/#{pid}/fd"
|
|
145
|
+
Dir.children(dir).filter_map do |fd|
|
|
146
|
+
File.readlink("#{dir}/#{fd}")
|
|
147
|
+
rescue Errno::ENOENT # a transient descriptor (e.g. Dir.children itself)
|
|
148
|
+
nil
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it 'keeps the decision writer out of prepared supervisors, init, workers and sibling missions' do
|
|
153
|
+
namespace = PWN::AI::Agent::MissionNamespace
|
|
154
|
+
fields = proposal
|
|
155
|
+
reader_inode = PWNTestPipeQueue.new
|
|
156
|
+
allow(PWN::AI::Agent::Loop).to receive(:run) do
|
|
157
|
+
reader_inode << namespace.io(6).stat.ino
|
|
158
|
+
worker = fork { exit!($stdin.gets ? 0 : 1) }
|
|
159
|
+
decision = Thread.current[:pwn_review_memory].call(fields)
|
|
160
|
+
Process.wait(worker)
|
|
161
|
+
"decision: #{decision}"
|
|
162
|
+
end
|
|
163
|
+
Dir.chdir(@tmp) do
|
|
164
|
+
@console.start_request('check descriptor ownership')
|
|
165
|
+
ticket = await_ticket
|
|
166
|
+
reader = "socket:[#{Timeout.timeout(5) { reader_inode.pop }}]"
|
|
167
|
+
control = @console.instance_variable_get(:@control).instance_variable_get(:@io)
|
|
168
|
+
writer = "socket:[#{control.stat.ino}]"
|
|
169
|
+
supervisor = @console.instance_variable_get(:@mission).instance_variable_get(:@pid)
|
|
170
|
+
init = only_child(supervisor)
|
|
171
|
+
sibling = namespace.new { sleep }
|
|
172
|
+
sibling_pid = sibling.instance_variable_get(:@pid)
|
|
173
|
+
|
|
174
|
+
expect(fd_targets(Process.pid)).to include(writer)
|
|
175
|
+
expect(fd_targets(Process.pid)).not_to include(reader)
|
|
176
|
+
expect(fd_targets(init)).to include(reader)
|
|
177
|
+
[supervisor, init, only_child(init), sibling_pid, only_child(sibling_pid)].each do |pid|
|
|
178
|
+
expect(fd_targets(pid)).not_to include(writer)
|
|
179
|
+
end
|
|
180
|
+
enter('/input done')
|
|
181
|
+
enter("/memory decline #{ticket}")
|
|
182
|
+
finish
|
|
183
|
+
expect(timeline).to include('decision: false')
|
|
184
|
+
ensure
|
|
185
|
+
sibling&.close
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
it 'also drops the writer before an owned-namespace closure runs' do
|
|
190
|
+
namespace = PWN::AI::Agent::MissionNamespace
|
|
191
|
+
allow(namespace).to receive(:owned).and_return(true)
|
|
192
|
+
reader, writer = namespace.control_socket_pair
|
|
193
|
+
target = "socket:[#{writer.stat.ino}]"
|
|
194
|
+
mission = namespace.new(inherit_namespace: true) { exit!(!fd_targets(Process.pid).include?(target)) }
|
|
195
|
+
mission.wait
|
|
196
|
+
expect(mission.status).to be_success
|
|
197
|
+
expect(writer).not_to be_closed
|
|
198
|
+
ensure
|
|
199
|
+
mission&.close
|
|
200
|
+
[reader, writer].compact.each(&:close)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
it 'declines on command EOF and does not wait for a later proposal on the closed channel' do
|
|
204
|
+
fields = proposal
|
|
205
|
+
allow(PWN::AI::Agent::Loop).to receive(:run) do
|
|
206
|
+
review = Thread.current[:pwn_review_memory]
|
|
207
|
+
"after EOF: #{review.call(fields).inspect}, #{review.call(fields).inspect}"
|
|
208
|
+
end
|
|
209
|
+
Dir.chdir(@tmp) do
|
|
210
|
+
@console.start_request('wait for control channel EOF')
|
|
211
|
+
await_ticket
|
|
212
|
+
@console.instance_variable_get(:@control).close
|
|
213
|
+
finish
|
|
214
|
+
expect(timeline).to include('after EOF: false, false')
|
|
215
|
+
expect(timeline.grep(%r{/memory approve }).length).to eq(1)
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
it 'expires a lost review without treating silence as approval' do
|
|
220
|
+
stub_const('PWN::Plugins::REPL::AIConsole::MemoryReview::WAIT_SECONDS', 0.05)
|
|
221
|
+
fields = proposal
|
|
222
|
+
allow(PWN::AI::Agent::Loop).to receive(:run) { "expired: #{Thread.current[:pwn_review_memory].call(fields).inspect}" }
|
|
223
|
+
Dir.chdir(@tmp) do
|
|
224
|
+
@console.start_request('wait without deciding')
|
|
225
|
+
finish
|
|
226
|
+
expect(timeline).to include('Memory review closed without a decision.', 'expired: false')
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
it 'invalidates a pending ticket on cancellation before another mission starts' do
|
|
231
|
+
fields = proposal
|
|
232
|
+
allow(PWN::AI::Agent::Loop).to receive(:run) { "decision: #{Thread.current[:pwn_review_memory].call(fields).inspect}" }
|
|
233
|
+
Dir.chdir(@tmp) do
|
|
234
|
+
@console.start_request('cancel this review')
|
|
235
|
+
old = await_ticket
|
|
236
|
+
generation = @console.instance_variable_get(:@mission_generation)
|
|
237
|
+
@console.handle("\u0003")
|
|
238
|
+
expect(@console).not_to be_busy
|
|
239
|
+
@console.start_request('different mission')
|
|
240
|
+
current = await_ticket(except: old)
|
|
241
|
+
@console.instance_variable_get(:@events) << [:memory_review_closed, current, generation]
|
|
242
|
+
@console.drain
|
|
243
|
+
enter("/memory approve #{old}")
|
|
244
|
+
enter("/memory decline #{current}")
|
|
245
|
+
finish
|
|
246
|
+
expect(timeline.grep(/\Adecision:/)).to eq(['decision: false'])
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
it 'does not block the UI or leave an ambiguous decision on a full command channel' do
|
|
251
|
+
peer, writer = UNIXSocket.pair
|
|
252
|
+
control = PWN::Plugins::REPL::AIConsole::MissionControl.new(writer)
|
|
253
|
+
block = 'x' * 4096
|
|
254
|
+
loop { break if writer.write_nonblock(block, exception: false) == :wait_writable }
|
|
255
|
+
Timeout.timeout(1) { expect { control.memory_decision('mission', 'a' * 16, 'approve') }.to raise_error(IOError) }
|
|
256
|
+
expect(writer).to be_closed
|
|
257
|
+
ensure
|
|
258
|
+
[peer, writer].compact.each { |io| io.close unless io.closed? }
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
it 'never offers a redaction-altered proposal and restores the prior reviewer after Loop.run' do
|
|
262
|
+
fields = proposal.merge(value: 'password=fixture-only')
|
|
263
|
+
allow(PWN::Sessions).to receive(:provisional_title) do
|
|
264
|
+
Thread.current[:pwn_review_memory] = :previous_reviewer
|
|
265
|
+
nil
|
|
266
|
+
end
|
|
267
|
+
allow(PWN::AI::Agent::Loop).to receive(:run) { "sensitive: #{Thread.current[:pwn_review_memory].call(fields).inspect}" }
|
|
268
|
+
allow(PWN::Sessions).to receive(:refresh_title) do
|
|
269
|
+
puts "restored: #{Thread.current[:pwn_review_memory] == :previous_reviewer}"
|
|
270
|
+
nil
|
|
271
|
+
end
|
|
272
|
+
Dir.chdir(@tmp) do
|
|
273
|
+
@console.start_request('refuse fields that cannot be shown exactly')
|
|
274
|
+
finish
|
|
275
|
+
expect(timeline).to include('sensitive: false', "restored: true\n")
|
|
276
|
+
expect(timeline.join).not_to include('fixture-only', '/memory approve ', '[REDACTED')
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
it 'does not arm a review that redaction at the display boundary would change' do
|
|
281
|
+
fields = proposal
|
|
282
|
+
allow(PWN::AI::Agent::Loop).to receive(:run) { "altered: #{Thread.current[:pwn_review_memory].call(fields).inspect}" }
|
|
283
|
+
allow(PWN::Redaction).to receive(:redact).and_wrap_original do |original, value:|
|
|
284
|
+
clean = original.call(value: value)
|
|
285
|
+
clean.is_a?(String) && clean.include?('Review this one memory_remember write') ? clean.sub('fixture.key', '[REDACTED]') : clean
|
|
286
|
+
end
|
|
287
|
+
Dir.chdir(@tmp) do
|
|
288
|
+
@console.start_request('refuse a changed review display')
|
|
289
|
+
finish
|
|
290
|
+
expect(timeline).to include('altered: false')
|
|
291
|
+
expect(timeline.join).not_to include('/memory approve ', '[REDACTED]')
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
it 'shows every escaped field in compact view and consumes one decision per proposal' do
|
|
296
|
+
fields = proposal
|
|
297
|
+
allow(PWN::AI::Agent::Loop).to receive(:run) do
|
|
298
|
+
review = Thread.current[:pwn_review_memory]
|
|
299
|
+
"decisions: #{review&.call(fields).inspect}, #{review&.call(fields).inspect}"
|
|
300
|
+
end
|
|
301
|
+
Dir.chdir(@tmp) do
|
|
302
|
+
@console.start_request('two proposed writes')
|
|
303
|
+
first = await_ticket
|
|
304
|
+
visible = @console.timeline_rows(50).map { |row| row.last.delete_prefix(' ') }.join
|
|
305
|
+
expect(visible).to include('"key": "fixture.key"', '"category": "preference"', '"value": " note\\n\\t\\"\\u754c\\"\\u007f\\u202e "', "/memory decline #{first}")
|
|
306
|
+
enter("/memory approve #{first}")
|
|
307
|
+
second = await_ticket(except: first)
|
|
308
|
+
enter("/memory approve #{first}") # replay cannot approve the second proposal
|
|
309
|
+
enter("/memory decline #{second}")
|
|
310
|
+
finish
|
|
311
|
+
expect(timeline).to include('decisions: true, false')
|
|
312
|
+
enter("/memory approve #{second}") # not a slash command for an idle agent
|
|
313
|
+
expect(@history).to be_empty
|
|
314
|
+
@console.handle(:up)
|
|
315
|
+
expect(@console.instance_variable_get(:@editor).text).to be_empty
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
end
|
|
319
|
+
|
|
53
320
|
describe 'tool input admission' do
|
|
54
321
|
it 'rejects an oversized line without delivering any prefix to the tool' do
|
|
55
322
|
reader, writer = IO.pipe
|
|
@@ -1065,6 +1332,36 @@ describe 'pwn-ai curses launch' do # rubocop:disable Metrics/BlockLength -- publ
|
|
|
1065
1332
|
expect(role.text).to eq("αβ\n新\nlast")
|
|
1066
1333
|
end
|
|
1067
1334
|
|
|
1335
|
+
it 'approves the exact proposed memory_remember fields through the public curses launch' do
|
|
1336
|
+
@agent_cfg[:plan_first] = false
|
|
1337
|
+
allow(PWN::Sessions).to receive(:refresh_title).and_return(nil)
|
|
1338
|
+
fields = { key: ' Display.units ', value: " °C\t\"literal\\n\"\n#{'界' * 600}\u007f END ", category: 'preference' }
|
|
1339
|
+
call = { id: 'fixture-save', type: 'function', function: { name: 'memory_remember', arguments: JSON.generate(fields) } }
|
|
1340
|
+
allow(PWN::AI::Agent::Loop).to receive(:call_engine).and_return(
|
|
1341
|
+
{ role: 'assistant', tool_calls: [call] }, { role: 'assistant', content: 'Review finished.', tool_calls: [] }
|
|
1342
|
+
)
|
|
1343
|
+
keys = "Remember my display units.\n".chars
|
|
1344
|
+
approved = false
|
|
1345
|
+
launch(keys) do
|
|
1346
|
+
ticket = @rendered.filter_map { |_y, _x, text| text[%r{/memory approve ([0-9a-f]{16})}, 1] }.first
|
|
1347
|
+
if !approved && ticket
|
|
1348
|
+
expect(File).not_to exist(PWN::Memory::MEMORY_FILE)
|
|
1349
|
+
rows = @console.timeline_rows(50).map { |row| row.last.delete_prefix(' ') }.join
|
|
1350
|
+
escaped = JSON.generate(fields[:value], ascii_only: true).gsub("\x7f", '\\u007f')
|
|
1351
|
+
expect(rows).to include('"key": " Display.units "', '"category": "preference"', "\"value\": #{escaped}")
|
|
1352
|
+
approved = true
|
|
1353
|
+
keys.concat("/memory approve #{ticket}\n".chars)
|
|
1354
|
+
nil
|
|
1355
|
+
elsif !@console.busy?
|
|
1356
|
+
"\u0004"
|
|
1357
|
+
end
|
|
1358
|
+
end
|
|
1359
|
+
expect(approved).to be(true), "no review prompt: #{@console.instance_variable_get(:@timeline).map { |type, text| [type, text[0, 240]] }.inspect}"
|
|
1360
|
+
stored = JSON.parse(File.read(PWN::Memory::MEMORY_FILE))
|
|
1361
|
+
expect(stored.keys).to eq([fields[:key]])
|
|
1362
|
+
expect(stored.fetch(fields[:key]).values_at('value', 'category')).to eq(fields.values_at(:value, :category))
|
|
1363
|
+
end
|
|
1364
|
+
|
|
1068
1365
|
it 'runs the real Loop from the public launch, steering a blocked model without a second input reader' do
|
|
1069
1366
|
loop_module = PWN::AI::Agent::Loop
|
|
1070
1367
|
entered = PWNTestPipeQueue.new
|
|
@@ -1534,11 +1831,14 @@ describe 'pwn-ai curses launch' do # rubocop:disable Metrics/BlockLength -- publ
|
|
|
1534
1831
|
console.instance_variable_set(:@banner_activated, true)
|
|
1535
1832
|
allow(console).to receive(:put)
|
|
1536
1833
|
allow(console).to receive(:box)
|
|
1537
|
-
|
|
1834
|
+
# Exercise layout and painting at the requested dimensions, not replay generation.
|
|
1835
|
+
cell = { glyph: '▀', foreground: :cyan, background: :black }.freeze
|
|
1836
|
+
allow(PWN::Banner).to receive(:mini_cells) { |opts| Array.new(opts.fetch(:height)) { Array.new(opts.fetch(:width), cell) } }
|
|
1538
1837
|
height = console.draw_header('ollama', 'fixture')
|
|
1539
1838
|
expect(height).to be > 10
|
|
1540
1839
|
expect(console).to have_received(:box).with(0, 0, height, height, '')
|
|
1541
1840
|
expect(PWN::Banner).to have_received(:mini_cells).with(hash_including(width: height - 2, height: height - 2))
|
|
1841
|
+
expect(console).to have_received(:put).with(height - 2, height - 2, '▀', nil)
|
|
1542
1842
|
expect(console.instance_variable_get(:@header_spans).length + 3).to be <= height
|
|
1543
1843
|
expect(console.header_lines('ollama', 'fixture', console.instance_variable_get(:@header_text_width)).join).to include('REASONING EFFORT: high')
|
|
1544
1844
|
end
|
|
@@ -2766,24 +3066,36 @@ describe 'pwn-ai curses launch' do # rubocop:disable Metrics/BlockLength -- publ
|
|
|
2766
3066
|
PWN::Env[:ai][:openai] = { model: 'old', reasoning_effort: 'medium' }
|
|
2767
3067
|
allow(PWN::Plugins::REPL).to receive(:persist_ai_selection).and_return(false)
|
|
2768
3068
|
allow(PWN::AI::OpenAI).to receive(:get_models).and_return(data: [{ id: 'gpt-6-astra', supported_reasoning_levels: [{ effort: 'low' }, { effort: 'medium' }, { effort: 'high' }] }])
|
|
2769
|
-
|
|
3069
|
+
calls = File.join(@tmp, 'provider-efforts')
|
|
3070
|
+
allow(PWN::AI::OpenAI).to receive(:chat_with_tools) do |opts|
|
|
3071
|
+
File.open(calls, 'a') { |file| file.puts(opts[:reasoning_effort]) }
|
|
2770
3072
|
{ choices: [{ message: { role: 'assistant', content: 'Effort accepted.', tool_calls: [] } }] }
|
|
2771
3073
|
end
|
|
2772
3074
|
keys = "/model openai gpt-6-astra\n".chars
|
|
2773
|
-
|
|
3075
|
+
@launch_phase = :select_effort
|
|
2774
3076
|
launch(keys) do
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
3077
|
+
case @launch_phase
|
|
3078
|
+
when :select_effort
|
|
3079
|
+
next unless @rendered.any? { |row| row.last.include?('REASONING EFFORT · SELECT') }
|
|
3080
|
+
|
|
3081
|
+
keys.push(:down, "\n")
|
|
3082
|
+
@launch_phase = :wait_for_model
|
|
2778
3083
|
nil
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
3084
|
+
when :wait_for_model
|
|
3085
|
+
# Accepting the prompt does not mean the /model worker has finished.
|
|
3086
|
+
next if @console.send(:busy?)
|
|
3087
|
+
|
|
3088
|
+
expect(PWN::Env.dig(:ai, :openai, :reasoning_effort)).to eq('high')
|
|
3089
|
+
keys.concat("what color is a lemon?\n".chars)
|
|
3090
|
+
@launch_phase = :await_reply
|
|
2783
3091
|
nil
|
|
3092
|
+
when :await_reply
|
|
3093
|
+
"\u0004" unless @console.send(:busy?)
|
|
2784
3094
|
end
|
|
2785
3095
|
end
|
|
2786
|
-
expect(
|
|
3096
|
+
expect(File).to exist(calls), 'The follow-up question did not reach the provider'
|
|
3097
|
+
expect(File.readlines(calls, chomp: true)).to eq(['high'])
|
|
3098
|
+
expect(@paint.join).to include('Effort accepted.')
|
|
2787
3099
|
end
|
|
2788
3100
|
|
|
2789
3101
|
it 'stops after a forbidden planning request and displays one access warning' do
|
|
@@ -2812,16 +3124,16 @@ describe 'pwn-ai curses launch' do # rubocop:disable Metrics/BlockLength -- publ
|
|
|
2812
3124
|
expect(events.none? { |type, *| type == :assistant }).to be(true)
|
|
2813
3125
|
end
|
|
2814
3126
|
|
|
2815
|
-
|
|
3127
|
+
def check_split_stream_preview(engine, adapter, label)
|
|
2816
3128
|
require 'rest-client'
|
|
2817
|
-
PWN::Env[:ai] = { active:
|
|
3129
|
+
PWN::Env[:ai] = { active: engine, engine => { model: 'fixture', base_uri: 'https://example.invalid', key: 'fixture-key' }, agent: { toolsets: [], plan_first: false } }
|
|
2818
3130
|
calls = File.join(@tmp, 'preview-calls')
|
|
2819
3131
|
answer = 'Café — ready.'
|
|
2820
3132
|
msg = { role: 'assistant', content: answer, tool_calls: [{ function: { name: 'fixture', arguments: { value: 'private-fixture' } } }] }
|
|
2821
3133
|
wire = JSON.generate(message: msg, done: true).b
|
|
2822
3134
|
cut = wire.index('é'.b) + 1
|
|
2823
3135
|
allow(PWN::AI::Router).to receive(:summarize).and_return('{"title":"Preview","summary":"A text preview."}')
|
|
2824
|
-
allow(
|
|
3136
|
+
allow(adapter).to receive(:chat_with_tools).and_wrap_original do |chat, opts|
|
|
2825
3137
|
chat.call(opts.merge(tools: [{ type: 'function', function: { name: 'fixture', parameters: { type: 'object' } } }]))
|
|
2826
3138
|
File.open(calls, 'a') { |file| file.puts 'returned to caller' }
|
|
2827
3139
|
raise 'Unexpected normal return'
|
|
@@ -2842,11 +3154,19 @@ describe 'pwn-ai curses launch' do # rubocop:disable Metrics/BlockLength -- publ
|
|
|
2842
3154
|
launch("what color is a lemon?\n".chars) { "\u0004" unless @console.send(:busy?) }
|
|
2843
3155
|
events = @console.instance_variable_get(:@timeline)
|
|
2844
3156
|
expect(events.filter_map { |type, text, *| text if type == :assistant }).to contain_exactly(answer)
|
|
2845
|
-
expect(events.filter_map { |type, text, *| text if type == :warning }).to contain_exactly(a_string_matching(
|
|
3157
|
+
expect(events.filter_map { |type, text, *| text if type == :warning }).to contain_exactly(a_string_matching(/#{Regexp.escape(label)}.*action.*not processed/i))
|
|
2846
3158
|
expect(events.to_s).not_to include('private-fixture')
|
|
2847
3159
|
expect(File.readlines(calls, chomp: true)).to eq(['read'])
|
|
2848
3160
|
end
|
|
2849
3161
|
|
|
3162
|
+
it 'shows a split UTF-8 Open WebUI preview once without returning actions to the worker' do
|
|
3163
|
+
check_split_stream_preview(:openwebui, PWN::AI::OpenWebUI, 'Open WebUI')
|
|
3164
|
+
end
|
|
3165
|
+
|
|
3166
|
+
it 'shows a split UTF-8 Ollama preview once without returning actions to the worker' do
|
|
3167
|
+
check_split_stream_preview(:ollama, PWN::AI::Ollama, 'Ollama')
|
|
3168
|
+
end
|
|
3169
|
+
|
|
2850
3170
|
it 'states that instructions in preview text were not run even without structured actions' do
|
|
2851
3171
|
console = PWN::Plugins::REPL::AIConsole::Console.new(pry: Pry.new, input: StringIO.new, curses: nil, getch: nil)
|
|
2852
3172
|
events = []
|
|
@@ -27,11 +27,17 @@ describe PWN::SDR::Decoder::LoRa do
|
|
|
27
27
|
expect(frames).to contain_exactly(include(payload_hex: vector[:payload_hex], decoded: true, crc_valid: true))
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
# Select metadata first. Unused waveforms need not be inflated into arrays of floats.
|
|
31
|
+
def lora_vectors(manifest = 'vectors.json')
|
|
31
32
|
root = File.expand_path('../../../../fixtures/sdr/lora', __dir__)
|
|
32
|
-
JSON.parse(File.read(
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
JSON.parse(File.read(File.join(root, manifest)), symbolize_names: true)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def lora_iq(vector)
|
|
37
|
+
require 'zlib'
|
|
38
|
+
path = File.expand_path("../../../../fixtures/sdr/lora/#{vector.fetch(:file)}", __dir__)
|
|
39
|
+
bytes = path.end_with?('.gz') ? Zlib::GzipReader.open(path, &:read) : File.binread(path)
|
|
40
|
+
bytes.unpack('e*')
|
|
35
41
|
end
|
|
36
42
|
|
|
37
43
|
def lora_receive(signal, spreading: 7, chunk: 194)
|
|
@@ -57,7 +63,8 @@ describe PWN::SDR::Decoder::LoRa do
|
|
|
57
63
|
end
|
|
58
64
|
|
|
59
65
|
it 'runs the public payload path from an explicit offline source' do
|
|
60
|
-
vector
|
|
66
|
+
vector = lora_vectors.first
|
|
67
|
+
iq = lora_iq(vector)
|
|
61
68
|
frames = []
|
|
62
69
|
described_class.decode(source: StringIO.new(iq.map { |v| (v * 16_000).round }.pack('s<*')), iq_format: :cs16, sample_rate: 125_000,
|
|
63
70
|
sf: 7, bw: 125_000, freq_obj: { freq: 915_000_000 },
|
|
@@ -67,7 +74,8 @@ describe PWN::SDR::Decoder::LoRa do
|
|
|
67
74
|
end
|
|
68
75
|
|
|
69
76
|
it 'emits a validated packet while its pipe source remains open' do
|
|
70
|
-
vector
|
|
77
|
+
vector = lora_vectors.first
|
|
78
|
+
iq = lora_iq(vector)
|
|
71
79
|
reader, writer = IO.pipe
|
|
72
80
|
frames = Queue.new
|
|
73
81
|
worker = Thread.new do
|
|
@@ -87,7 +95,8 @@ describe PWN::SDR::Decoder::LoRa do
|
|
|
87
95
|
end
|
|
88
96
|
|
|
89
97
|
it 'uses identical normalized chirps at each supported bandwidth' do
|
|
90
|
-
vector
|
|
98
|
+
vector = lora_vectors.first
|
|
99
|
+
iq = lora_iq(vector)
|
|
91
100
|
[125_000, 250_000, 500_000].each do |bandwidth|
|
|
92
101
|
demod = described_class::PayloadIQ.new(rate: bandwidth, bw: bandwidth, sf: 7)
|
|
93
102
|
frames = []
|
|
@@ -105,8 +114,8 @@ describe PWN::SDR::Decoder::LoRa do
|
|
|
105
114
|
end
|
|
106
115
|
|
|
107
116
|
it 'matches every independent waveform and its symbol-derived synthetic waveform' do
|
|
108
|
-
lora_vectors.each do |vector
|
|
109
|
-
[
|
|
117
|
+
lora_vectors.each do |vector|
|
|
118
|
+
[lora_iq(vector), lora_synthetic(vector[:symbols], spreading: vector[:sf])].each do |signal|
|
|
110
119
|
[1, 194, signal.length].each do |chunk|
|
|
111
120
|
expect(lora_receive(signal, spreading: vector[:sf], chunk: chunk)).to contain_exactly(
|
|
112
121
|
include(payload_hex: vector[:payload_hex], crc_valid: true)
|
|
@@ -117,7 +126,8 @@ describe PWN::SDR::Decoder::LoRa do
|
|
|
117
126
|
end
|
|
118
127
|
|
|
119
128
|
it 'acquires off-grid packets with integer CFO and does not deduplicate identical packets' do
|
|
120
|
-
vector
|
|
129
|
+
vector = lora_vectors.first
|
|
130
|
+
iq = lora_iq(vector)
|
|
121
131
|
[1, 31, 63, 95, 127].each do |offset|
|
|
122
132
|
shifted = Array.new(offset * 2, 0.0) + iq
|
|
123
133
|
shifted = shifted.each_slice(2).with_index.flat_map do |(i, q), k|
|
|
@@ -150,7 +160,7 @@ describe PWN::SDR::Decoder::LoRa do
|
|
|
150
160
|
end
|
|
151
161
|
|
|
152
162
|
it 'corrects a single Hamming bit but rejects double-bit errors' do
|
|
153
|
-
vector = lora_vectors.first
|
|
163
|
+
vector = lora_vectors.first
|
|
154
164
|
fixed = lora_flip_codeword(vector[:symbols], 1)
|
|
155
165
|
expect(lora_receive(lora_synthetic(fixed))).to contain_exactly(include(payload_hex: vector[:payload_hex]))
|
|
156
166
|
broken = lora_flip_codeword(vector[:symbols], 3)
|
|
@@ -158,7 +168,7 @@ describe PWN::SDR::Decoder::LoRa do
|
|
|
158
168
|
end
|
|
159
169
|
|
|
160
170
|
it 'rejects valid FEC with wrong payload CRC and wrong header checksum' do
|
|
161
|
-
vector = lora_vectors.first
|
|
171
|
+
vector = lora_vectors.first
|
|
162
172
|
# 0xD1 is the LoRa extended-Hamming codeword of nibble 1.
|
|
163
173
|
# XOR preserves FEC validity but changes the protected data.
|
|
164
174
|
crc_bad = lora_flip_codeword(vector[:symbols], 0xD1)
|
|
@@ -168,7 +178,8 @@ describe PWN::SDR::Decoder::LoRa do
|
|
|
168
178
|
end
|
|
169
179
|
|
|
170
180
|
it 'rejects truncation, silence, noise and a missing SFD' do
|
|
171
|
-
vector
|
|
181
|
+
vector = lora_vectors.first
|
|
182
|
+
iq = lora_iq(vector)
|
|
172
183
|
expect(lora_receive(iq.first(4000))).to be_empty
|
|
173
184
|
expect(lora_receive(Array.new(10_000, 0.0))).to be_empty
|
|
174
185
|
random = Random.new(123)
|
|
@@ -178,16 +189,9 @@ describe PWN::SDR::Decoder::LoRa do
|
|
|
178
189
|
expect(lora_receive(missing)).to be_empty
|
|
179
190
|
end
|
|
180
191
|
|
|
181
|
-
def lora_modes
|
|
182
|
-
require 'zlib'
|
|
183
|
-
root = File.expand_path('../../../../fixtures/sdr/lora', __dir__)
|
|
184
|
-
JSON.parse(File.read("#{root}/modes.json"), symbolize_names: true).map do |vector|
|
|
185
|
-
[vector, Zlib::GzipReader.open("#{root}/#{vector[:file]}", &:read).unpack('e*')]
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
|
|
189
192
|
it 'decodes independent SF9-12, LDRO, implicit, CRC-off and inverted waveforms' do
|
|
190
|
-
|
|
193
|
+
lora_vectors('modes.json').select { |v| v[:sample_rate] == v[:bw] }.each do |v|
|
|
194
|
+
iq = lora_iq(v)
|
|
191
195
|
[1, 8192, iq.length].each do |size|
|
|
192
196
|
frames = []
|
|
193
197
|
options = v.slice(:sf, :bw, :implicit_header, :payload_length, :cr, :crc, :ldro, :invert_iq)
|
|
@@ -200,7 +204,8 @@ describe PWN::SDR::Decoder::LoRa do
|
|
|
200
204
|
end
|
|
201
205
|
|
|
202
206
|
it 'forwards every new mode through the public offline decode path' do
|
|
203
|
-
|
|
207
|
+
lora_vectors('modes.json').each do |v|
|
|
208
|
+
iq = lora_iq(v)
|
|
204
209
|
frames = []
|
|
205
210
|
options = v.slice(:sf, :sample_rate, :bw, :implicit_header, :payload_length, :cr, :crc, :ldro, :invert_iq)
|
|
206
211
|
described_class.decode(**options, source: StringIO.new(iq.map { |x| (x * 12_000).round }.pack('s<*')),
|
|
@@ -212,7 +217,8 @@ describe PWN::SDR::Decoder::LoRa do
|
|
|
212
217
|
end
|
|
213
218
|
|
|
214
219
|
it 'resamples independent noninteger-rate IQ with identical scalar and bulk chunk results' do
|
|
215
|
-
v
|
|
220
|
+
v = lora_vectors('modes.json').last
|
|
221
|
+
iq = lora_iq(v)
|
|
216
222
|
[1, 194, iq.length].each do |size|
|
|
217
223
|
frames = []
|
|
218
224
|
demod = described_class::PayloadIQ.new(rate: v[:sample_rate], bw: v[:bw], sf: v[:sf])
|
|
@@ -222,7 +228,8 @@ describe PWN::SDR::Decoder::LoRa do
|
|
|
222
228
|
end
|
|
223
229
|
|
|
224
230
|
it 'does not complete truncated packets in any new mode' do
|
|
225
|
-
|
|
231
|
+
lora_vectors('modes.json').each do |v|
|
|
232
|
+
iq = lora_iq(v)
|
|
226
233
|
options = v.slice(:sf, :bw, :implicit_header, :payload_length, :cr, :crc, :ldro, :invert_iq)
|
|
227
234
|
demod = described_class::PayloadIQ.new(**options, rate: v[:sample_rate])
|
|
228
235
|
frames = []
|
|
@@ -232,7 +239,8 @@ describe PWN::SDR::Decoder::LoRa do
|
|
|
232
239
|
end
|
|
233
240
|
|
|
234
241
|
it 'automatically enables LDRO for long symbols but honors an explicit false override' do
|
|
235
|
-
|
|
242
|
+
lora_vectors('modes.json').select { |v| !v[:implicit_header] && v[:sf] >= 11 }.each do |v|
|
|
243
|
+
iq = lora_iq(v)
|
|
236
244
|
options = v.slice(:sf, :bw)
|
|
237
245
|
options[:ldro] = false unless v[:ldro]
|
|
238
246
|
demod = described_class::PayloadIQ.new(**options, rate: v[:sample_rate])
|
|
@@ -246,7 +254,8 @@ describe PWN::SDR::Decoder::LoRa do
|
|
|
246
254
|
dsp = PWN::SDR::Decoder::DSP
|
|
247
255
|
volk = PWN::FFI::Volk
|
|
248
256
|
expect(volk).to receive(:volk_32f_x2_dot_prod_32f).at_least(:once).and_call_original if volk.available?
|
|
249
|
-
v
|
|
257
|
+
v = lora_vectors('modes.json').last
|
|
258
|
+
iq = lora_iq(v)
|
|
250
259
|
signals = [false, true].map do |native|
|
|
251
260
|
allow(dsp).to receive(:native).and_return(native)
|
|
252
261
|
demod = described_class::PayloadIQ.new(rate: v[:sample_rate], bw: v[:bw], sf: v[:sf])
|
data/spec/lib/pwn/setup_spec.rb
CHANGED
|
@@ -30,18 +30,13 @@ describe PWN::Setup do
|
|
|
30
30
|
expect(PWN::Setup).to respond_to(:ensure_cron)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
it 'ensure_cron seeds defaults and starts (or reuses) the worker' do
|
|
34
|
-
tmp = Dir.mktmpdir('pwn-setup-cron-')
|
|
35
|
-
stub_const('PWN::Cron::CRON_DIR', tmp)
|
|
36
|
-
stub_const('PWN::Cron::JOBS_FILE', File.join(tmp, 'jobs.yml'))
|
|
37
|
-
stub_const('PWN::Cron::PID_FILE', File.join(tmp, 'worker.pid'))
|
|
38
|
-
stub_const('PWN::Cron::WORKER_LOG', File.join(tmp, 'worker.log'))
|
|
39
|
-
ENV['PWN_CRON_DIR'] = tmp
|
|
33
|
+
it 'ensure_cron seeds defaults and starts (or reuses) the worker', :isolated_cron_store do
|
|
40
34
|
allow(PWN::Cron).to receive(:install_worker_crontab).and_return('stubbed')
|
|
41
35
|
io = StringIO.new
|
|
42
36
|
first = PWN::Setup.ensure_cron(restart: false, io: io)
|
|
43
37
|
expect(first[:ok]).to be true
|
|
44
38
|
expect(first[:worker][:running]).to be true
|
|
39
|
+
expect(File).to exist(File.join(Dir.home, '.pwn', 'maintenance', 'background.json'))
|
|
45
40
|
pid = first[:worker][:pid]
|
|
46
41
|
expect(pid).to be_a(Integer)
|
|
47
42
|
second = PWN::Setup.ensure_cron(restart: false, io: StringIO.new)
|
|
@@ -55,11 +50,9 @@ describe PWN::Setup do
|
|
|
55
50
|
rescue StandardError
|
|
56
51
|
nil
|
|
57
52
|
end
|
|
58
|
-
ENV.delete('PWN_CRON_DIR')
|
|
59
|
-
FileUtils.remove_entry(tmp) if tmp && Dir.exist?(tmp)
|
|
60
53
|
end
|
|
61
54
|
|
|
62
|
-
it 'ensure_cron dry_run does not spawn' do
|
|
55
|
+
it 'ensure_cron dry_run does not spawn', :isolated_cron_store do
|
|
63
56
|
io = StringIO.new
|
|
64
57
|
allow(PWN::Cron).to receive(:worker_status).and_return(
|
|
65
58
|
running: false, pid: nil, pid_file: '/tmp/x', log: '/tmp/y'
|
|
@@ -68,13 +61,7 @@ describe PWN::Setup do
|
|
|
68
61
|
expect(res[:dry_run]).to be true
|
|
69
62
|
expect(res[:ok]).to be true
|
|
70
63
|
end
|
|
71
|
-
it 'ensure_cron enabled:false disables only the internal worker without native changes' do
|
|
72
|
-
tmp = Dir.mktmpdir('pwn-setup-nocron-')
|
|
73
|
-
stub_const('PWN::Cron::CRON_DIR', tmp)
|
|
74
|
-
stub_const('PWN::Cron::JOBS_FILE', File.join(tmp, 'jobs.yml'))
|
|
75
|
-
stub_const('PWN::Cron::PID_FILE', File.join(tmp, 'worker.pid'))
|
|
76
|
-
stub_const('PWN::Cron::WORKER_LOG', File.join(tmp, 'worker.log'))
|
|
77
|
-
ENV['PWN_CRON_DIR'] = tmp
|
|
64
|
+
it 'ensure_cron enabled:false disables only the internal worker without native changes', :isolated_cron_store do
|
|
78
65
|
io = StringIO.new
|
|
79
66
|
expect(PWN::Cron).not_to receive(:install_scheduler)
|
|
80
67
|
expect(PWN::Cron).not_to receive(:uninstall_scheduler)
|
|
@@ -92,8 +79,6 @@ describe PWN::Setup do
|
|
|
92
79
|
rescue StandardError
|
|
93
80
|
nil
|
|
94
81
|
end
|
|
95
|
-
ENV.delete('PWN_CRON_DIR')
|
|
96
|
-
FileUtils.remove_entry(tmp) if tmp && Dir.exist?(tmp)
|
|
97
82
|
end
|
|
98
83
|
|
|
99
84
|
it 'bin/pwn_setup exposes --[no-]cron' do
|
data/spec/spec_helper.rb
CHANGED
|
@@ -35,19 +35,23 @@ RSpec.configure do |config|
|
|
|
35
35
|
config.filter_run_excluding :combo_nation_mcp unless ENV['PWN_TEST_COMBO_NATION_MCP'] == '1'
|
|
36
36
|
config.filter_run_excluding :x86_64_binary unless RbConfig::CONFIG['host_cpu'].to_s.match?(/amd64|x86_64/)
|
|
37
37
|
|
|
38
|
+
# Let mktmpdir remove its own directory after example mocks (e.g. Dir.children) are gone.
|
|
39
|
+
config.around(:each) do |example|
|
|
40
|
+
Dir.mktmpdir('pwn-backup-spec-') do |root|
|
|
41
|
+
@pwn_spec_backup_root = root
|
|
42
|
+
example.run
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
38
46
|
config.before(:each) do
|
|
39
|
-
@pwn_spec_backup_root = Dir.mktmpdir('pwn-backup-spec-')
|
|
40
47
|
Thread.current[:pwn_backup_real_home] = Dir.home
|
|
41
48
|
Thread.current[:pwn_backup_root] = @pwn_spec_backup_root
|
|
42
49
|
end
|
|
43
50
|
|
|
44
51
|
config.after(:each) do
|
|
45
|
-
root = @pwn_spec_backup_root
|
|
46
52
|
Thread.current[:pwn_backup_root] = nil
|
|
47
53
|
Thread.current[:pwn_backup_real_home] = nil
|
|
48
54
|
@pwn_spec_backup_root = nil
|
|
49
|
-
# FileUtils.remove_entry calls Dir.children, which examples stub with a fixed path.
|
|
50
|
-
system('rm', '-rf', '--', root) if root.is_a?(String) && root.start_with?('/') && root.include?('/pwn-backup-spec-') && !root.include?('..')
|
|
51
55
|
end
|
|
52
56
|
|
|
53
57
|
if ENV['PWN_RAKE_SPEC'] == '1'
|