tep 0.11.9 → 0.11.10
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/bin/tep +16 -3
- data/lib/tep/shell.rb +10 -2
- data/lib/tep/version.rb +1 -1
- data/lib/tep.rb +4 -4
- data/test/test_boot_seed_stdin.rb +29 -0
- data/test/test_ext_cache.rb +81 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ab07017a55b832e36f074079ebb1b1f84cb7b7fb7223bf099b05649f876f6762
|
|
4
|
+
data.tar.gz: 98a0328f60412b5a65859ca2a17856992775c7c9e33ea57efa595b67db6f8444
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 05bc8d5707d6a2a838cb3e2a845d6ef3be3fb11ebb6a66ff72f9ff5e5bb06fa2d135714368a8b8af4caf673b1b6a4e21afbd6d5252196bdebef4bcc616db574f
|
|
7
|
+
data.tar.gz: d2d77d39aa8b589a5617b55c32197d43100b3291f028139b404eef99d8edcf00ade30e521294c61d1cf03806385605470b974b0b5302e030a98bc35095d63773
|
data/bin/tep
CHANGED
|
@@ -2060,13 +2060,26 @@ def resolve_ext_o(entry, entries, env_var)
|
|
|
2060
2060
|
fatal("ext '#{entry["name"]}' needs #{missing} — install its -dev headers")
|
|
2061
2061
|
end
|
|
2062
2062
|
|
|
2063
|
+
# The cached object is keyed by what it was built from: the source
|
|
2064
|
+
# bytes and the compile flags. The directory used to be the checkout's
|
|
2065
|
+
# basename alone with an mtime check, so two trees with the same name
|
|
2066
|
+
# (a dev checkout and an app's vendored copy are both `tep`) shared a
|
|
2067
|
+
# slot, and whichever compiled last won as long as its object was newer
|
|
2068
|
+
# than the other tree's source. The result linked cleanly and returned
|
|
2069
|
+
# wrong data at run time.
|
|
2070
|
+
require "digest"
|
|
2071
|
+
key = Digest::SHA256.hexdigest(File.binread(src) + "\0" + cflags.join("\0"))[0, 16]
|
|
2063
2072
|
cache = File.join(ENV["HOME"] || Dir.tmpdir, ".cache", "tep", "ext", File.basename(REPO_ROOT))
|
|
2064
2073
|
FileUtils.mkdir_p(cache)
|
|
2065
|
-
out = File.join(cache, File.basename(prebuilt))
|
|
2066
|
-
return out if File.exist?(out)
|
|
2074
|
+
out = File.join(cache, File.basename(prebuilt, ".o") + "-" + key + ".o")
|
|
2075
|
+
return out if File.exist?(out)
|
|
2067
2076
|
|
|
2068
2077
|
warn "[tep] building ext '#{entry["name"]}' on demand (#{entry["source"]})"
|
|
2069
|
-
|
|
2078
|
+
# Compile to a private name and rename, so a concurrent build never
|
|
2079
|
+
# links a half-written object.
|
|
2080
|
+
tmp = out + ".#{Process.pid}.tmp"
|
|
2081
|
+
if system(ENV.fetch("CC", "cc"), *cflags, "-c", src, "-o", tmp) && File.exist?(tmp)
|
|
2082
|
+
File.rename(tmp, out)
|
|
2070
2083
|
out
|
|
2071
2084
|
elsif entry["optional"]
|
|
2072
2085
|
warn "[tep] optional ext '#{entry["name"]}' failed to build — disabling"
|
data/lib/tep/shell.rb
CHANGED
|
@@ -41,12 +41,20 @@ module Tep
|
|
|
41
41
|
# silently return ""); we rescue here to preserve this helper's
|
|
42
42
|
# never-raise contract -- a handler reading /proc should get "" for
|
|
43
43
|
# an absent file, not a 502'd worker.
|
|
44
|
+
#
|
|
45
|
+
# The result goes through a local rather than being the begin/rescue
|
|
46
|
+
# expression's own value: at spinel 2026.10.25 a method whose value is
|
|
47
|
+
# `begin File.read(path) rescue "" end` hands back its ARGUMENT when
|
|
48
|
+
# the caller pushes the result onto a String array (broke
|
|
49
|
+
# Tep::Parallel#map_processes).
|
|
44
50
|
def self.read(path)
|
|
51
|
+
out = ""
|
|
45
52
|
begin
|
|
46
|
-
File.read(path)
|
|
53
|
+
out = File.read(path)
|
|
47
54
|
rescue => e
|
|
48
|
-
""
|
|
55
|
+
out = ""
|
|
49
56
|
end
|
|
57
|
+
out
|
|
50
58
|
end
|
|
51
59
|
|
|
52
60
|
# Bounded read: slice after the fact. The cap is mostly a
|
data/lib/tep/version.rb
CHANGED
data/lib/tep.rb
CHANGED
|
@@ -255,7 +255,7 @@ module Tep
|
|
|
255
255
|
_tep_seed_sess.get("a")
|
|
256
256
|
_tep_seed_sess.has?("a")
|
|
257
257
|
_tep_seed_res.start_stream(Streamer.new)
|
|
258
|
-
_tep_seed_stream = Stream.new(
|
|
258
|
+
_tep_seed_stream = Stream.new(-1)
|
|
259
259
|
_tep_seed_res.streamer.pump(_tep_seed_stream)
|
|
260
260
|
_tep_seed_stream.write("") # pin the parameter type to :str
|
|
261
261
|
Tep.h("") # pin Tep.h(s)'s param to :str
|
|
@@ -265,7 +265,7 @@ module Tep
|
|
|
265
265
|
Tep::Multipart.parse("", "")
|
|
266
266
|
Tep::Multipart.extract_boundary("")
|
|
267
267
|
Tep::Multipart.extract_field_name("")
|
|
268
|
-
_tep_seed_res.start_websocket("", Tep::WebSocket::Driver.new(
|
|
268
|
+
_tep_seed_res.start_websocket("", Tep::WebSocket::Driver.new(-1))
|
|
269
269
|
|
|
270
270
|
# AuthOAuth2 type-seeding. Every public cmeth needs at least one
|
|
271
271
|
# top-level call so spinel locks the param C types in compile
|
|
@@ -782,7 +782,7 @@ module Tep
|
|
|
782
782
|
_tep_seed_llm_state.acc = ""
|
|
783
783
|
_tep_seed_llm_state.leftover = ""
|
|
784
784
|
_tep_seed_llm_state.done = false
|
|
785
|
-
_tep_seed_llm_stream = Tep::Stream.new(
|
|
785
|
+
_tep_seed_llm_stream = Tep::Stream.new(-1)
|
|
786
786
|
Tep::Llm.consume_sse_events(_tep_seed_llm_stream, _tep_seed_llm_state)
|
|
787
787
|
Tep::Llm.dechunk_consume("")
|
|
788
788
|
Tep::Llm.dechunk_leftover("")
|
|
@@ -822,7 +822,7 @@ module Tep
|
|
|
822
822
|
_tep_seed_ws_event.code = 0
|
|
823
823
|
_tep_seed_ws_event.reason = ""
|
|
824
824
|
_tep_seed_ws_handler.handle_event(_tep_seed_ws_event)
|
|
825
|
-
_tep_seed_ws_drv = Tep::WebSocket::Driver.new(
|
|
825
|
+
_tep_seed_ws_drv = Tep::WebSocket::Driver.new(-1)
|
|
826
826
|
_tep_seed_ws_drv.set_max_frame_size(0)
|
|
827
827
|
_tep_seed_ws_drv.set_subprotocol("")
|
|
828
828
|
_tep_seed_ws_drv.set_on_open(_tep_seed_ws_handler)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require_relative "helper"
|
|
2
|
+
require "socket"
|
|
3
|
+
|
|
4
|
+
# The boot-time type seeds used to build a Stream and two WebSocket
|
|
5
|
+
# drivers on descriptor 0 and write test frames to it. With a socket on
|
|
6
|
+
# stdin those 54 bytes reached the peer, and once an unread socket
|
|
7
|
+
# filled, a later start blocked before serving (#283).
|
|
8
|
+
class TestBootSeedStdin < Minitest::Test
|
|
9
|
+
def test_start_writes_nothing_to_a_socket_on_stdin
|
|
10
|
+
tmp = Dir.mktmpdir("tep-seed-stdin")
|
|
11
|
+
src = File.join(tmp, "app.rb")
|
|
12
|
+
File.write(src, "require \"sinatra\"\nget \"/\" do\n \"hi\"\nend\n")
|
|
13
|
+
bin = File.join(tmp, "app")
|
|
14
|
+
TepHarness.build_with_retry("#{TepHarness::TEP_BIN} build #{src} -o #{bin}", "tep build seed stdin app")
|
|
15
|
+
ours, theirs = UNIXSocket.pair
|
|
16
|
+
port = TepHarness.next_port
|
|
17
|
+
pid = Process.spawn(bin, "-p", port.to_s, "-q", in: theirs,
|
|
18
|
+
out: File.join(tmp, "app.log"), err: [:child, :out], pgroup: true)
|
|
19
|
+
theirs.close
|
|
20
|
+
TepHarness.wait_for_port(port, tmp: tmp, pid: pid)
|
|
21
|
+
TepHarness.reap(pid)
|
|
22
|
+
pid = nil
|
|
23
|
+
assert_equal "", ours.read, "the app wrote to its stdin socket at start"
|
|
24
|
+
ensure
|
|
25
|
+
TepHarness.reap(pid) if pid
|
|
26
|
+
ours&.close
|
|
27
|
+
FileUtils.rm_rf(tmp) if tmp
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
require_relative "helper"
|
|
2
|
+
require "net/http"
|
|
3
|
+
|
|
4
|
+
# `tep build` compiles the optional native helpers (sqlite, pg) on demand
|
|
5
|
+
# into ~/.cache/tep/ext/<checkout basename>/. The slot used to be keyed by
|
|
6
|
+
# that basename plus an mtime check, so another tree with the same name
|
|
7
|
+
# could leave an object there that this tree then linked: it built fine
|
|
8
|
+
# and SQLite queries returned nothing. The object is now keyed by the
|
|
9
|
+
# source bytes and compile flags.
|
|
10
|
+
class TestExtCache < Minitest::Test
|
|
11
|
+
REPO = File.expand_path("..", __dir__)
|
|
12
|
+
APP = <<~'RB'
|
|
13
|
+
require "sinatra"
|
|
14
|
+
get "/count" do
|
|
15
|
+
db = Tep::SQLite.new
|
|
16
|
+
db.open(ENV.fetch("DB_PATH", "/tmp/unset.db"))
|
|
17
|
+
db.exec("CREATE TABLE n (id INTEGER PRIMARY KEY, b TEXT)")
|
|
18
|
+
db.exec("INSERT INTO n (b) VALUES ('x')")
|
|
19
|
+
db.exec("INSERT INTO n (b) VALUES ('y')")
|
|
20
|
+
"count=" + db.first_int("SELECT COUNT(*) FROM n WHERE id > ?", "0").to_s
|
|
21
|
+
end
|
|
22
|
+
RB
|
|
23
|
+
|
|
24
|
+
def setup
|
|
25
|
+
skip "TEP_SQLITE_O set; the cache is bypassed" unless ENV["TEP_SQLITE_O"].to_s.empty?
|
|
26
|
+
@tmp = Dir.mktmpdir("tep-extcache")
|
|
27
|
+
@home = File.join(@tmp, "home")
|
|
28
|
+
# A dev checkout has `make helper`s prebuilt lib/tep/tep_sqlite.o, which
|
|
29
|
+
# bypasses the cache. Build from a copy without it, as an installed gem
|
|
30
|
+
# or an app-vendored tep does.
|
|
31
|
+
@tree = File.join(@tmp, "tep")
|
|
32
|
+
FileUtils.mkdir_p(@tree)
|
|
33
|
+
FileUtils.cp_r([File.join(REPO, "bin"), File.join(REPO, "lib"), File.join(REPO, "spinel-ext.json")], @tree)
|
|
34
|
+
FileUtils.rm_f(Dir[File.join(@tree, "lib", "tep", "tep_{sqlite,pg}.o")])
|
|
35
|
+
@slot = File.join(@home, ".cache", "tep", "ext", "tep")
|
|
36
|
+
FileUtils.mkdir_p(@slot)
|
|
37
|
+
@src = File.join(@tmp, "app.rb")
|
|
38
|
+
File.write(@src, APP)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def teardown
|
|
42
|
+
TepHarness.reap(@pid) if @pid
|
|
43
|
+
FileUtils.rm_rf(@tmp) if @tmp
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def build(bin)
|
|
47
|
+
out = `HOME=#{@home} #{File.join(@tree, "bin", "tep")} build #{@src} -o #{bin} 2>&1`
|
|
48
|
+
assert $?.success?, "tep build failed:\n#{out}"
|
|
49
|
+
out
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_foreign_object_in_the_slot_is_not_linked
|
|
53
|
+
# What another same-named tree would have left behind under the old
|
|
54
|
+
# scheme: an object at the unkeyed name, newer than our source. This
|
|
55
|
+
# one defines nothing, so linking it cannot produce a working binary.
|
|
56
|
+
decoy_c = File.join(@tmp, "decoy.c")
|
|
57
|
+
File.write(decoy_c, "int tep_decoy_unused;\n")
|
|
58
|
+
decoy = File.join(@slot, "tep_sqlite.o")
|
|
59
|
+
assert system("cc", "-c", decoy_c, "-o", decoy)
|
|
60
|
+
File.utime(Time.now + 3600, Time.now + 3600, decoy)
|
|
61
|
+
|
|
62
|
+
bin = File.join(@tmp, "app")
|
|
63
|
+
build(bin)
|
|
64
|
+
|
|
65
|
+
keyed = Dir[File.join(@slot, "tep_sqlite-*.o")]
|
|
66
|
+
assert_equal 1, keyed.length, "expected one content-keyed object, got #{Dir[File.join(@slot, '*')].inspect}"
|
|
67
|
+
assert_match(/tep_sqlite-\h{16}\.o\z/, keyed[0])
|
|
68
|
+
|
|
69
|
+
@port = TepHarness.next_port
|
|
70
|
+
@pid = Process.spawn({ "DB_PATH" => File.join(@tmp, "t.db") }, bin, "-p", @port.to_s, "-q",
|
|
71
|
+
out: File.join(@tmp, "app.log"), err: [:child, :out], pgroup: true)
|
|
72
|
+
TepHarness.wait_for_port(@port, tmp: @tmp, pid: @pid)
|
|
73
|
+
assert_equal "count=2", Net::HTTP.get(URI("http://127.0.0.1:#{@port}/count"))
|
|
74
|
+
|
|
75
|
+
# A second build reuses the keyed object.
|
|
76
|
+
before = File.mtime(keyed[0])
|
|
77
|
+
out = build(File.join(@tmp, "app2"))
|
|
78
|
+
refute_match(/building ext 'sqlite'/, out)
|
|
79
|
+
assert_equal before, File.mtime(keyed[0])
|
|
80
|
+
end
|
|
81
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tep
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.11.
|
|
4
|
+
version: 0.11.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ori Pekelman
|
|
@@ -183,6 +183,7 @@ files:
|
|
|
183
183
|
- test/test_auth.rb
|
|
184
184
|
- test/test_auth_oauth2.rb
|
|
185
185
|
- test/test_auth_session_cookie.rb
|
|
186
|
+
- test/test_boot_seed_stdin.rb
|
|
186
187
|
- test/test_broadcast.rb
|
|
187
188
|
- test/test_broadcast_pg.rb
|
|
188
189
|
- test/test_cache.rb
|
|
@@ -191,6 +192,7 @@ files:
|
|
|
191
192
|
- test/test_erb.rb
|
|
192
193
|
- test/test_erb_ivars.rb
|
|
193
194
|
- test/test_events.rb
|
|
195
|
+
- test/test_ext_cache.rb
|
|
194
196
|
- test/test_filters.rb
|
|
195
197
|
- test/test_geohash_example.rb
|
|
196
198
|
- test/test_http.rb
|