Skip to content

Commit 5e1043e

Browse files
committed
style: standardrb clean across spec
1 parent a9d3350 commit 5e1043e

4 files changed

Lines changed: 82 additions & 78 deletions

File tree

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
require 'spec_helper'
1+
require "spec_helper"
22
require "interscript/ml/byt5_onnx"
33

44
RSpec.describe Interscript::ML::Byt5Onnx do
5-
it 'uses the ByT5 byte conventions' do
5+
it "uses the ByT5 byte conventions" do
66
expect(Interscript::ML::IMF::PAD_ID).to eq(0)
77
expect(Interscript::ML::IMF::EOS_ID).to eq(1)
88
end
99

10-
describe 'byte round-trip (as used for generated output)' do
11-
it 'packs generated bytes back into UTF-8 text' do
12-
text = 'ភាសាខ្មែរ'
10+
describe "byte round-trip (as used for generated output)" do
11+
it "packs generated bytes back into UTF-8 text" do
12+
text = "ភាសាខ្មែរ"
1313
bytes = text.bytes
14-
expect(bytes.pack('C*').force_encoding(Encoding::UTF_8)).to eq(text)
14+
expect(bytes.pack("C*").force_encoding(Encoding::UTF_8)).to eq(text)
1515
end
1616
end
1717
end

‎spec/interscript/ml/golden_spec.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
# gem's ORT build to close it, don't erode the default tiers
5252
artifact_bound = ENV["SECRYST_E2E_CORPUS_BOUND"]&.to_f
5353
corpus_bound = artifact_bound ||
54-
(ENV["SECRYST_E2E_SMOKE"] == "1" ? 0.02 : 0.005)
54+
((ENV["SECRYST_E2E_SMOKE"] == "1") ? 0.02 : 0.005)
5555
expect(total_diffs.to_f / total_chars).to be < corpus_bound
5656
end
5757
end

‎spec/interscript/ml/imf_spec.rb‎

Lines changed: 71 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
11
require "spec_helper"
22
require "zip"
3-
require 'interscript/ml'
4-
require 'fileutils'
5-
require 'tmpdir'
6-
require 'json'
3+
require "interscript/ml"
4+
require "fileutils"
5+
require "tmpdir"
6+
require "json"
77

88
RSpec.describe Interscript::ML::IMF do
9-
it 'uses the canonical ByT5 table (byte + 3, trailing EOS)' do
10-
expect(described_class.encode('rok')).to eq([117, 114, 110, 1])
11-
expect(described_class.decode([117, 114, 110])).to eq('rok')
12-
expect(described_class.decode([117, 1, 114])).to eq('r')
9+
it "uses the canonical ByT5 table (byte + 3, trailing EOS)" do
10+
expect(described_class.encode("rok")).to eq([117, 114, 110, 1])
11+
expect(described_class.decode([117, 114, 110])).to eq("rok")
12+
expect(described_class.decode([117, 1, 114])).to eq("r")
1313
end
1414

15-
describe 'with the tiny IMF fixture zip' do
16-
let(:zip_path) { File.expand_path('../fixtures/tiny-imf.zip', __dir__) }
15+
describe "with the tiny IMF fixture zip" do
16+
let(:zip_path) { File.expand_path("../fixtures/tiny-imf.zip", __dir__) }
1717

18-
it 'parses the manifest and verifies graph checksums' do
18+
it "parses the manifest and verifies graph checksums" do
1919
meta = described_class.manifest(zip_path)
20-
expect(meta['format']).to eq('imf-v1')
21-
expect(meta['tokenizer']).to eq('bytes')
20+
expect(meta["format"]).to eq("imf-v1")
21+
expect(meta["tokenizer"]).to eq("bytes")
2222
graphs = described_class.verify_and_read(zip_path)
23-
expect(graphs.keys.sort).to eq(['decoder.onnx', 'encoder.onnx'])
23+
expect(graphs.keys.sort).to eq(["decoder.onnx", "encoder.onnx"])
2424
end
2525

26-
it 'loads sessions from verified bytes' do
26+
it "loads sessions from verified bytes" do
2727
model = Interscript::ML::Byt5Onnx.new(zip_path)
28-
expect(model.id).to eq('tiny-1.0')
28+
expect(model.id).to eq("tiny-1.0")
2929
end
3030

31-
it 'decodes a real zip against the shared golden set', :e2e do
32-
zip = ENV['SECRYST_E2E_ZIP']
33-
golden = ENV['SECRYST_GOLDEN']
34-
skip 'set SECRYST_E2E_ZIP and SECRYST_GOLDEN for the end-to-end run' unless zip && golden
31+
it "decodes a real zip against the shared golden set", :e2e do
32+
zip = ENV["SECRYST_E2E_ZIP"]
33+
golden = ENV["SECRYST_GOLDEN"]
34+
skip "set SECRYST_E2E_ZIP and SECRYST_GOLDEN for the end-to-end run" unless zip && golden
3535
translator = Interscript::ML::Translator.new(model_file: zip)
3636
ok = 0
3737
total = 0
3838
File.readlines(golden).each do |line|
3939
row = JSON.parse(line)
4040
total += 1
41-
ok += 1 if translator.translate(row['input'], max_seq_length: 128) == row['output']
41+
ok += 1 if translator.translate(row["input"], max_seq_length: 128) == row["output"]
4242
end
4343
expect(ok).to eq(total)
4444
end
4545
end
4646

47-
it 'rejects a tampered zip loudly' do
47+
it "rejects a tampered zip loudly" do
4848
Dir.mktmpdir do |tmp|
49-
source = File.expand_path('../fixtures/tiny-imf.zip', __dir__)
50-
tampered = File.join(tmp, 'tampered.zip')
51-
require 'zip'
49+
source = File.expand_path("../fixtures/tiny-imf.zip", __dir__)
50+
tampered = File.join(tmp, "tampered.zip")
51+
require "zip"
5252
Zip::File.open(source) do |src|
5353
Zip::File.open(tampered, create: true) do |dst|
5454
src.entries.each do |e|
55-
if e.name == 'encoder.onnx'
56-
dst.get_output_stream(e.name) { |io| io.write('corrupted-bytes') }
55+
if e.name == "encoder.onnx"
56+
dst.get_output_stream(e.name) { |io| io.write("corrupted-bytes") }
5757
else
5858
dst.get_output_stream(e.name) { |io| io.write(e.get_input_stream.read) }
5959
end
@@ -65,15 +65,15 @@
6565
end
6666
end
6767

68-
describe '.resolve' do
69-
it 'installs a verified copy into the cache from a local index' do
68+
describe ".resolve" do
69+
it "installs a verified copy into the cache from a local index" do
7070
Dir.mktmpdir do |tmp|
71-
channel = File.join(tmp, 'channel')
71+
channel = File.join(tmp, "channel")
7272
FileUtils.mkdir_p(channel)
73-
zip_path = File.expand_path('../fixtures/tiny-imf.zip', __dir__)
74-
FileUtils.cp(zip_path, File.join(channel, 'tiny.zip'))
75-
require 'digest'
76-
index = File.join(tmp, 'models.yaml')
73+
zip_path = File.expand_path("../fixtures/tiny-imf.zip", __dir__)
74+
FileUtils.cp(zip_path, File.join(channel, "tiny.zip"))
75+
require "digest"
76+
index = File.join(tmp, "models.yaml")
7777
File.write(index, <<~YAML)
7878
version: 1
7979
models:
@@ -82,41 +82,41 @@
8282
url: file://#{channel}/tiny.zip
8383
sha256: #{Digest::SHA256.file(zip_path).hexdigest}
8484
YAML
85-
cache = File.join(tmp, 'cache')
86-
result = described_class.resolve('tiny-1.0', index_url: index) if false
85+
cache = File.join(tmp, "cache")
86+
8787
# env-based cache (the public API reads ENV at call time)
88-
ENV['SECRYST_CACHE'] = cache
88+
ENV["SECRYST_CACHE"] = cache
8989
begin
90-
installed = described_class.resolve('tiny-1.0', index_url: index)
91-
expect(installed).to eq(File.join(cache, 'models', 'tiny-1.0', 'tiny.zip'))
90+
installed = described_class.resolve("tiny-1.0", index_url: index)
91+
expect(installed).to eq(File.join(cache, "models", "tiny-1.0", "tiny.zip"))
9292
expect(File.file?(installed)).to be(true)
93-
FileUtils.rm_f(File.join(channel, 'tiny.zip'))
94-
expect(described_class.resolve('tiny-1.0', index_url: index)).to eq(installed)
93+
FileUtils.rm_f(File.join(channel, "tiny.zip"))
94+
expect(described_class.resolve("tiny-1.0", index_url: index)).to eq(installed)
9595
ensure
96-
ENV.delete('SECRYST_CACHE')
96+
ENV.delete("SECRYST_CACHE")
9797
end
9898
end
9999
end
100100

101-
it 'raises for unknown ids' do
101+
it "raises for unknown ids" do
102102
Dir.mktmpdir do |tmp|
103-
index = File.join(tmp, 'models.yaml')
103+
index = File.join(tmp, "models.yaml")
104104
File.write(index, "version: 1\nmodels: {}\n")
105-
expect { described_class.resolve('nope-1.0', index_url: index) }
105+
expect { described_class.resolve("nope-1.0", index_url: index) }
106106
.to raise_error(Interscript::ML::IMF::RegistryError, /unknown model id/)
107107
end
108108
end
109109

110-
it 'assembles and verifies split parts (the >2GiB GitHub cap path)' do
110+
it "assembles and verifies split parts (the >2GiB GitHub cap path)" do
111111
Dir.mktmpdir do |tmp|
112-
channel = File.join(tmp, 'channel')
112+
channel = File.join(tmp, "channel")
113113
FileUtils.mkdir_p(channel)
114-
zip_path = File.expand_path('../fixtures/tiny-imf.zip', __dir__)
114+
zip_path = File.expand_path("../fixtures/tiny-imf.zip", __dir__)
115115
blob = File.binread(zip_path)
116116
part_a, part_b = blob[0, (blob.bytesize / 2 + 3)], blob[(blob.bytesize / 2 + 3)..]
117-
File.binwrite(File.join(channel, 'tiny.zip.part-00'), part_a)
118-
File.binwrite(File.join(channel, 'tiny.zip.part-01'), part_b)
119-
index = File.join(tmp, 'models.yaml')
117+
File.binwrite(File.join(channel, "tiny.zip.part-00"), part_a)
118+
File.binwrite(File.join(channel, "tiny.zip.part-01"), part_b)
119+
index = File.join(tmp, "models.yaml")
120120
File.write(index, <<~YAML)
121121
version: 1
122122
models:
@@ -131,29 +131,29 @@
131131
sha256: #{Digest::SHA256.hexdigest(part_b)}
132132
size: #{part_b.bytesize}
133133
YAML
134-
cache = File.join(tmp, 'cache')
135-
ENV['SECRYST_CACHE'] = cache
134+
cache = File.join(tmp, "cache")
135+
ENV["SECRYST_CACHE"] = cache
136136
begin
137-
installed = described_class.resolve('tiny-1.0', index_url: index)
137+
installed = described_class.resolve("tiny-1.0", index_url: index)
138138
expect(File.binread(installed)).to eq(blob)
139-
FileUtils.rm_f(File.join(channel, 'tiny.zip.part-00'))
140-
expect(described_class.resolve('tiny-1.0', index_url: index)).to eq(installed)
139+
FileUtils.rm_f(File.join(channel, "tiny.zip.part-00"))
140+
expect(described_class.resolve("tiny-1.0", index_url: index)).to eq(installed)
141141
ensure
142-
ENV.delete('SECRYST_CACHE')
142+
ENV.delete("SECRYST_CACHE")
143143
end
144144
end
145145
end
146146

147-
it 'rejects a corrupt part by index' do
147+
it "rejects a corrupt part by index" do
148148
Dir.mktmpdir do |tmp|
149-
channel = File.join(tmp, 'channel')
149+
channel = File.join(tmp, "channel")
150150
FileUtils.mkdir_p(channel)
151-
zip_path = File.expand_path('../fixtures/tiny-imf.zip', __dir__)
151+
zip_path = File.expand_path("../fixtures/tiny-imf.zip", __dir__)
152152
blob = File.binread(zip_path)
153153
part_a, part_b = blob[0, 7], blob[7..]
154-
File.binwrite(File.join(channel, 'tiny.zip.part-00'), part_a)
155-
File.binwrite(File.join(channel, 'tiny.zip.part-01'), part_b)
156-
index = File.join(tmp, 'models.yaml')
154+
File.binwrite(File.join(channel, "tiny.zip.part-00"), part_a)
155+
File.binwrite(File.join(channel, "tiny.zip.part-01"), part_b)
156+
index = File.join(tmp, "models.yaml")
157157
File.write(index, <<~YAML)
158158
version: 1
159159
models:
@@ -168,12 +168,12 @@
168168
sha256: #{Digest::SHA256.hexdigest(part_b)}
169169
size: #{part_b.bytesize}
170170
YAML
171-
ENV['SECRYST_CACHE'] = File.join(tmp, 'cache')
171+
ENV["SECRYST_CACHE"] = File.join(tmp, "cache")
172172
begin
173-
expect { described_class.resolve('tiny-1.0', index_url: index) }
173+
expect { described_class.resolve("tiny-1.0", index_url: index) }
174174
.to raise_error(Interscript::ML::IMF::RegistryError, /part 0 .* sha256 mismatch/)
175175
ensure
176-
ENV.delete('SECRYST_CACHE')
176+
ENV.delete("SECRYST_CACHE")
177177
end
178178
end
179179
end
@@ -201,7 +201,11 @@
201201
port = server.addr[1]
202202
thread = Thread.new do
203203
loop do
204-
client = server.accept rescue break
204+
client = begin
205+
server.accept
206+
rescue
207+
break
208+
end
205209
request = client.readline
206210
client.each_line { |line| break if line == "\r\n" }
207211
path = request.split(" ")[1]

‎spec/interscript/ml/plane_spec.rb‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
describe ".from_zip" do
1212
it "verifies member sha256s and rejects tampering" do
1313
expect { described_class.from_zip(File.read(zip)) }.not_to raise_error
14-
require 'zip'
15-
require 'stringio'
14+
require "zip"
15+
require "stringio"
1616
src = Zip::File.open(zip)
1717
bad = Zip::File.open_buffer(StringIO.new(File.binread(zip)))
18-
bad_entry = bad.entries.find { |e| e.name == 'plane.onnx' }
18+
bad_entry = bad.entries.find { |e| e.name == "plane.onnx" }
1919
tampered = bad_entry.get_input_stream.read + "x"
2020
buf = Zip::OutputStream.write_buffer do |out|
2121
src.entries.each do |e|
2222
out.put_next_entry(e.name)
23-
out.write(e.name == 'plane.onnx' ? tampered : e.get_input_stream.read)
23+
out.write((e.name == "plane.onnx") ? tampered : e.get_input_stream.read)
2424
end
2525
end.string
2626
expect { described_class.from_zip(buf) }.to raise_error(Interscript::ML::IMF::FormatError, /sha256 mismatch/)

0 commit comments

Comments
 (0)