pwn 0.5.804 → 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.
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
+ require 'shellwords'
4
5
 
5
6
  describe PWN::Plugins::Jobs do
6
7
  before do
@@ -65,7 +66,9 @@ describe PWN::Plugins::Jobs do
65
66
  end
66
67
 
67
68
  it 'pages binary logs with byte offsets and distinguishes EOF from completion' do
68
- row = described_class.start(command: "printf 'abc\\377def'; sleep 1", max_runtime: 5)
69
+ release = File.join(@root, 'release')
70
+ writer = 'STDOUT.binmode; STDOUT.write("abc\\xffdef".b); STDOUT.flush; sleep 0.01 until File.exist?(ARGV.fetch(0))'
71
+ row = described_class.start(command: Shellwords.join([RbConfig.ruby, '--disable=gems,rubyopt', '-e', writer, release]), max_runtime: 5)
69
72
  first = Timeout.timeout(8) do
70
73
  loop do
71
74
  page = described_class.job_tail(handle: row[:id], offset: 0, length: 4)
@@ -80,9 +83,15 @@ describe PWN::Plugins::Jobs do
80
83
  expect(Base64.strict_decode64(first[:data])).to eq("abc\xFF".b)
81
84
  last = described_class.tail(id: row[:id], offset: 4, length: 100)
82
85
  expect(last).to include(body: 'def', data: 'def', bytes: 3, next_offset: 7, eof: true, status: 'RUNNING')
86
+ File.write(release, '')
83
87
  finished(row[:id])
84
88
  expect(described_class.tail(id: row[:id], offset: 7)).to include(bytes: 0, eof: true, status: 'COMPLETED')
85
89
  expect(described_class.tail(id: row[:id])).to be_a(String)
90
+ ensure
91
+ if row && !File.exist?(release)
92
+ File.write(release, '')
93
+ finished(row[:id])
94
+ end
86
95
  end
87
96
 
88
97
  it 'filters and limits durable jobs across sessions' do
@@ -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
- allow(PWN::Banner).to receive(:mini_cells).and_call_original
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
@@ -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
- def lora_vectors
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("#{root}/vectors.json"), symbolize_names: true).map do |vector|
33
- [vector, File.binread("#{root}/#{vector[:file]}").unpack('e*')]
34
- end
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, iq = lora_vectors.first
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, iq = lora_vectors.first
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, iq = lora_vectors.first
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, iq|
109
- [iq, lora_synthetic(vector[:symbols], spreading: vector[:sf])].each do |signal|
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, iq = lora_vectors.first
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.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.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, iq = lora_vectors.first
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
- lora_modes.select { |v, _| v[:sample_rate] == v[:bw] }.each do |v, iq|
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
- lora_modes.each do |v, iq|
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, iq = lora_modes.last
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
- lora_modes.each do |v, iq|
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
- lora_modes.select { |v, _| !v[:implicit_header] && v[:sf] >= 11 }.each do |v, iq|
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, iq = lora_modes.last
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/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'
@@ -62,7 +62,8 @@ module HarnessCLIFaults
62
62
  prompt = 'Create result.txt after the operation completes and read it back.'
63
63
  write = tool("printf 'uncertain-write\\n' >> effects.log; sleep 3; printf done > result.txt", 'uncertain', 1)
64
64
  fixture[:responses] = [write, { fault: name == 'checkpoint-restart' ? 'crash' : 'resource_cap' }]
65
- fixture.merge!(wall_seconds: 4, await_cap_ready: true) if name == 'resource-cap-restart'
65
+ # The provider has already signaled readiness and is blocked; keep the separate startup deadline intact.
66
+ fixture.merge!(wall_seconds: 0.5, await_cap_ready: true) if name == 'resource-cap-restart'
66
67
  end
67
68
  result = invoke(root, fixture, prompt, options)
68
69
  first = result.dup
@@ -4,9 +4,20 @@ require 'json'
4
4
 
5
5
  # Real IPC barriers for examples whose producer lives in a mission child.
6
6
  class PWNTestPipeQueue
7
+ # Process-local, not thread-local: a worker can construct a queue too.
8
+ CREATED = Queue.new
9
+ private_constant :CREATED
10
+
11
+ def self.close_created
12
+ while (queue = CREATED.pop(timeout: 0))
13
+ queue.close
14
+ end
15
+ end
16
+
7
17
  def initialize
8
18
  @reader, @writer = IO.pipe
9
19
  @mutex = Mutex.new
20
+ CREATED << self
10
21
  end
11
22
 
12
23
  def <<(value)
@@ -29,5 +40,5 @@ class PWNTestPipeQueue
29
40
  end
30
41
 
31
42
  RSpec.configure do |config|
32
- config.after { ObjectSpace.each_object(PWNTestPipeQueue, &:close) }
43
+ config.after { PWNTestPipeQueue.close_created }
33
44
  end
@@ -99,6 +99,8 @@
99
99
  {"messages":[{"role":"user","content":"PWN::AI::Agent::Dispatch.parse_string_args Usage"},{"role":"assistant","content":"`PWN::AI::Agent::Dispatch.parse_string_args`: "}]}
100
100
  {"messages":[{"role":"user","content":"PWN::AI::Agent::Dispatch.prepare_budget Usage"},{"role":"assistant","content":"`PWN::AI::Agent::Dispatch.prepare_budget`: "}]}
101
101
  {"messages":[{"role":"user","content":"PWN::AI::Agent::Dispatch.repair_name Usage"},{"role":"assistant","content":"`PWN::AI::Agent::Dispatch.repair_name`: Supported Method Parameters\n\nfixed = PWN::AI::Agent::Dispatch.repair_name(\n\nname: 'required - possibly-wrong tool name emitted by the model'\n\n)\n\nReturns the closest registered tool name by Levenshtein distance (max distance = 1/3 of the emitted name, min 3) or nil when nothing is close enough. Every successful repair is fingerprinted into Mistakes so the negative-feedback loop trains the model’s output format via its own system prompt.\n"}]}
102
+ {"messages":[{"role":"user","content":"PWN::AI::Agent::Dispatch.review_memory_save Usage"},{"role":"assistant","content":"`PWN::AI::Agent::Dispatch.review_memory_save`: "}]}
103
+ {"messages":[{"role":"user","content":"PWN::AI::Agent::Dispatch.save_reviewed_memory Usage"},{"role":"assistant","content":"`PWN::AI::Agent::Dispatch.save_reviewed_memory`: "}]}
102
104
  {"messages":[{"role":"user","content":"PWN::AI::Agent::Dispatch.scheduling Usage"},{"role":"assistant","content":"`PWN::AI::Agent::Dispatch.scheduling`: Supported Method Parameters\n\nmetadata = PWN::AI::Agent::Dispatch.scheduling(\n\ntool_call: 'required - tool call whose audited read resources are resolved'\n\n)\n"}]}
103
105
  {"messages":[{"role":"user","content":"PWN::AI::Agent::Dispatch.schema_denial Usage"},{"role":"assistant","content":"`PWN::AI::Agent::Dispatch.schema_denial`: "}]}
104
106
  {"messages":[{"role":"user","content":"PWN::AI::Agent::Dispatch.symbolize Usage"},{"role":"assistant","content":"`PWN::AI::Agent::Dispatch.symbolize`: "}]}
@@ -605,9 +607,11 @@
605
607
  {"messages":[{"role":"user","content":"PWN::AI::Agent::Mission.write_row Usage"},{"role":"assistant","content":"`PWN::AI::Agent::Mission.write_row`: "}]}
606
608
  {"messages":[{"role":"user","content":"PWN::AI::Agent::MissionNamespace.authors Usage"},{"role":"assistant","content":"`PWN::AI::Agent::MissionNamespace.authors`: "}]}
607
609
  {"messages":[{"role":"user","content":"PWN::AI::Agent::MissionNamespace.checked Usage"},{"role":"assistant","content":"`PWN::AI::Agent::MissionNamespace.checked`: "}]}
610
+ {"messages":[{"role":"user","content":"PWN::AI::Agent::MissionNamespace.control_socket_pair Usage"},{"role":"assistant","content":"`PWN::AI::Agent::MissionNamespace.control_socket_pair`: "}]}
608
611
  {"messages":[{"role":"user","content":"PWN::AI::Agent::MissionNamespace.decode Usage"},{"role":"assistant","content":"`PWN::AI::Agent::MissionNamespace.decode`: "}]}
609
612
  {"messages":[{"role":"user","content":"PWN::AI::Agent::MissionNamespace.encode Usage"},{"role":"assistant","content":"`PWN::AI::Agent::MissionNamespace.encode`: "}]}
610
613
  {"messages":[{"role":"user","content":"PWN::AI::Agent::MissionNamespace.execute Usage"},{"role":"assistant","content":"`PWN::AI::Agent::MissionNamespace.execute`: "}]}
614
+ {"messages":[{"role":"user","content":"PWN::AI::Agent::MissionNamespace.fork_mission Usage"},{"role":"assistant","content":"`PWN::AI::Agent::MissionNamespace.fork_mission`: "}]}
611
615
  {"messages":[{"role":"user","content":"PWN::AI::Agent::MissionNamespace.help Usage"},{"role":"assistant","content":"`PWN::AI::Agent::MissionNamespace.help`: "}]}
612
616
  {"messages":[{"role":"user","content":"PWN::AI::Agent::MissionNamespace.io Usage"},{"role":"assistant","content":"`PWN::AI::Agent::MissionNamespace.io`: "}]}
613
617
  {"messages":[{"role":"user","content":"PWN::AI::Agent::MissionNamespace.native Usage"},{"role":"assistant","content":"`PWN::AI::Agent::MissionNamespace.native`: "}]}
@@ -3617,6 +3621,7 @@
3617
3621
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.clear_view Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.clear_view`: "}]}
3618
3622
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.complete Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.complete`: "}]}
3619
3623
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.completion_layout Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.completion_layout`: "}]}
3624
+ {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.decide_memory Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.decide_memory`: "}]}
3620
3625
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.disable_shift_enter Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.disable_shift_enter`: "}]}
3621
3626
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.drain Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.drain`: "}]}
3622
3627
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.draw Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.draw`: "}]}
@@ -3680,6 +3685,7 @@
3680
3685
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.page_completion Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.page_completion`: "}]}
3681
3686
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.playable_banner Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.playable_banner`: "}]}
3682
3687
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.prepare_swarm_mission Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.prepare_swarm_mission`: "}]}
3688
+ {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.present_memory_review Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.present_memory_review`: "}]}
3683
3689
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.put Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.put`: "}]}
3684
3690
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.put_spans Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.put_spans`: "}]}
3685
3691
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.queue_title_update Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.queue_title_update`: "}]}
@@ -3746,7 +3752,13 @@
3746
3752
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Keyboard.call Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Keyboard.call`: "}]}
3747
3753
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Keyboard.cursor_key Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Keyboard.cursor_key`: "}]}
3748
3754
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Keyboard.decode_character Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Keyboard.decode_character`: "}]}
3755
+ {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::MemoryReview.new Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::MemoryReview.new`: "}]}
3756
+ {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::MemoryReview.call Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::MemoryReview.call`: "}]}
3757
+ {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::MemoryReview.close Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::MemoryReview.close`: "}]}
3758
+ {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::MemoryReview.decide Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::MemoryReview.decide`: "}]}
3749
3759
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::MissionControl.new Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::MissionControl.new`: "}]}
3760
+ {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::MissionControl.close Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::MissionControl.close`: "}]}
3761
+ {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::MissionControl.memory_decision Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::MissionControl.memory_decision`: "}]}
3750
3762
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::MissionControl.phase Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::MissionControl.phase`: "}]}
3751
3763
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::MissionControl.stop Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::MissionControl.stop`: "}]}
3752
3764
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::MissionControl.submit Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::MissionControl.submit`: "}]}