kobako 0.30.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. checksums.yaml +4 -4
  2. data/.release-please-manifest.json +1 -1
  3. data/CHANGELOG.md +335 -0
  4. data/Cargo.lock +469 -11
  5. data/README.md +43 -3
  6. data/ROADMAP.md +1 -1
  7. data/crates/kobako-runtime/CHANGELOG.md +219 -0
  8. data/crates/kobako-runtime/Cargo.toml +51 -3
  9. data/crates/kobako-runtime/README.md +7 -4
  10. data/crates/kobako-runtime/src/cred.rs +124 -0
  11. data/crates/kobako-runtime/src/dispatch.rs +4 -5
  12. data/crates/kobako-runtime/src/endpoint/buffer.rs +153 -44
  13. data/crates/kobako-runtime/src/endpoint/dispatch.rs +80 -41
  14. data/crates/kobako-runtime/src/endpoint/invoke.rs +23 -36
  15. data/crates/kobako-runtime/src/endpoint.rs +137 -36
  16. data/crates/kobako-runtime/src/errno.rs +391 -0
  17. data/crates/kobako-runtime/src/error.rs +31 -10
  18. data/crates/kobako-runtime/src/filesystem/anon_inodes.rs +52 -0
  19. data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +52 -14
  20. data/crates/kobako-runtime/src/filesystem/bind/walk.rs +19 -20
  21. data/crates/kobako-runtime/src/filesystem/bind.rs +437 -245
  22. data/crates/kobako-runtime/src/filesystem/overlay/file.rs +6 -6
  23. data/crates/kobako-runtime/src/filesystem/overlay/path.rs +43 -65
  24. data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +9 -16
  25. data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +47 -72
  26. data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +12 -12
  27. data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +4 -7
  28. data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +121 -37
  29. data/crates/kobako-runtime/src/filesystem/overlay.rs +302 -343
  30. data/crates/kobako-runtime/src/filesystem/pipe.rs +12 -9
  31. data/crates/kobako-runtime/src/filesystem/rdir.rs +15 -32
  32. data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
  33. data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +3 -3
  34. data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +57 -35
  35. data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +2 -2
  36. data/crates/kobako-runtime/src/filesystem/tmpfs.rs +172 -160
  37. data/crates/kobako-runtime/src/filesystem/wrap.rs +36 -52
  38. data/crates/kobako-runtime/src/filesystem.rs +6 -3
  39. data/crates/kobako-runtime/src/fork.rs +96 -0
  40. data/crates/kobako-runtime/src/grant.rs +3 -0
  41. data/crates/kobako-runtime/src/hashtable.rs +4 -2
  42. data/crates/kobako-runtime/src/lib.rs +18 -7
  43. data/crates/kobako-runtime/src/limits.rs +195 -0
  44. data/crates/kobako-runtime/src/locking.rs +10 -0
  45. data/crates/kobako-runtime/src/memcg.rs +383 -0
  46. data/crates/kobako-runtime/src/mount.rs +67 -9
  47. data/crates/kobako-runtime/src/net/backends.rs +43 -0
  48. data/crates/kobako-runtime/src/net/connections.rs +179 -0
  49. data/crates/kobako-runtime/src/net/credential.rs +125 -0
  50. data/crates/kobako-runtime/src/net/egress.rs +160 -0
  51. data/crates/kobako-runtime/src/net/family.rs +181 -0
  52. data/crates/kobako-runtime/src/net/http.rs +2733 -0
  53. data/crates/kobako-runtime/src/net/lookup.rs +285 -0
  54. data/crates/kobako-runtime/src/net/mock.rs +251 -0
  55. data/crates/kobako-runtime/src/net/namespace.rs +1366 -0
  56. data/crates/kobako-runtime/src/net/reactor.rs +531 -0
  57. data/crates/kobako-runtime/src/net/resolv/darwin.rs +275 -0
  58. data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +469 -0
  59. data/crates/kobako-runtime/src/net/resolv/stub.rs +536 -0
  60. data/crates/kobako-runtime/src/net/resolv/windows.rs +248 -0
  61. data/crates/kobako-runtime/src/net/resolv.rs +227 -0
  62. data/crates/kobako-runtime/src/net/socket.rs +870 -0
  63. data/crates/kobako-runtime/src/net/tcp.rs +1588 -0
  64. data/crates/kobako-runtime/src/net/tls.rs +58 -0
  65. data/crates/kobako-runtime/src/net/transport.rs +279 -0
  66. data/crates/kobako-runtime/src/net/udp.rs +1003 -0
  67. data/crates/kobako-runtime/src/net.rs +42 -0
  68. data/crates/kobako-runtime/src/network/builder.rs +177 -0
  69. data/crates/kobako-runtime/src/network/ruleset.rs +777 -0
  70. data/crates/kobako-runtime/src/network.rs +551 -0
  71. data/crates/kobako-runtime/src/policy.rs +16 -0
  72. data/crates/kobako-runtime/src/profile.rs +29 -144
  73. data/crates/kobako-runtime/src/runtime.rs +3 -5
  74. data/crates/kobako-runtime/src/sched.rs +130 -29
  75. data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
  76. data/crates/kobako-runtime/src/{vfs/cred.rs → security/hooks.rs} +52 -144
  77. data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
  78. data/crates/kobako-runtime/src/security.rs +101 -196
  79. data/crates/kobako-runtime/src/snapshot.rs +121 -2
  80. data/crates/kobako-runtime/src/vfs/attr.rs +5 -5
  81. data/crates/kobako-runtime/src/vfs/dentry.rs +143 -89
  82. data/crates/kobako-runtime/src/vfs/file.rs +199 -203
  83. data/crates/kobako-runtime/src/vfs/inode.rs +41 -45
  84. data/crates/kobako-runtime/src/vfs/kern_path.rs +38 -42
  85. data/crates/kobako-runtime/src/vfs/mount.rs +10 -9
  86. data/crates/kobako-runtime/src/vfs/namei.rs +829 -700
  87. data/crates/kobako-runtime/src/vfs/namespace.rs +162 -0
  88. data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
  89. data/crates/kobako-runtime/src/vfs/openat2.rs +3 -3
  90. data/crates/kobako-runtime/src/vfs/path.rs +6 -6
  91. data/crates/kobako-runtime/src/vfs/readdir.rs +6 -6
  92. data/crates/kobako-runtime/src/vfs/stat.rs +159 -23
  93. data/crates/kobako-runtime/src/vfs/super_block.rs +18 -14
  94. data/crates/kobako-runtime/src/vfs/utimes.rs +37 -27
  95. data/crates/kobako-runtime/src/vfs.rs +9 -6
  96. data/crates/kobako-runtime/src/wait.rs +356 -0
  97. data/crates/kobako-transport/CHANGELOG.md +31 -0
  98. data/crates/kobako-transport/Cargo.toml +1 -1
  99. data/crates/kobako-transport/README.md +3 -4
  100. data/crates/kobako-transport/src/abi.rs +78 -72
  101. data/crates/kobako-transport/src/envelope/bytes.rs +17 -6
  102. data/crates/kobako-transport/src/envelope/call.rs +32 -4
  103. data/crates/kobako-transport/src/envelope/error_record.rs +21 -0
  104. data/crates/kobako-transport/src/envelope/name.rs +99 -0
  105. data/crates/kobako-transport/src/envelope/outcome.rs +9 -9
  106. data/crates/kobako-transport/src/envelope/preamble.rs +24 -21
  107. data/crates/kobako-transport/src/envelope/reply.rs +27 -27
  108. data/crates/kobako-transport/src/envelope/unsupported.rs +10 -10
  109. data/crates/kobako-transport/src/envelope.rs +13 -8
  110. data/crates/kobako-wasmtime/CHANGELOG.md +161 -0
  111. data/crates/kobako-wasmtime/Cargo.toml +26 -7
  112. data/crates/kobako-wasmtime/README.md +3 -2
  113. data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
  114. data/crates/kobako-wasmtime/build.rs +16 -0
  115. data/crates/kobako-wasmtime/src/abi.rs +17 -37
  116. data/crates/kobako-wasmtime/src/ambient.rs +33 -18
  117. data/crates/kobako-wasmtime/src/cache.rs +23 -15
  118. data/crates/kobako-wasmtime/src/config.rs +52 -68
  119. data/crates/kobako-wasmtime/src/driver.rs +48 -63
  120. data/crates/kobako-wasmtime/src/exports.rs +143 -17
  121. data/crates/kobako-wasmtime/src/guest.rs +12 -6
  122. data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
  123. data/crates/kobako-wasmtime/src/imports.rs +42 -18
  124. data/crates/kobako-wasmtime/src/instance_pre.rs +4 -4
  125. data/crates/kobako-wasmtime/src/invocation.rs +74 -12
  126. data/crates/kobako-wasmtime/src/lib.rs +5 -3
  127. data/crates/kobako-wasmtime/src/limiter.rs +70 -5
  128. data/crates/kobako-wasmtime/src/preview1/descriptors.rs +309 -0
  129. data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +5 -15
  130. data/crates/kobako-wasmtime/src/preview1/differential.rs +27 -31
  131. data/crates/kobako-wasmtime/src/preview1/errno.rs +55 -66
  132. data/crates/kobako-wasmtime/src/preview1/fd.rs +327 -296
  133. data/crates/kobako-wasmtime/src/preview1/memory.rs +21 -12
  134. data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +34 -53
  135. data/crates/kobako-wasmtime/src/preview1/mount_view.rs +231 -217
  136. data/crates/kobako-wasmtime/src/preview1/path.rs +56 -121
  137. data/crates/kobako-wasmtime/src/preview1/poll.rs +244 -120
  138. data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -8
  139. data/crates/kobako-wasmtime/src/preview1/testsuite.rs +5 -15
  140. data/crates/kobako-wasmtime/src/preview1.rs +46 -42
  141. data/crates/kobako-wasmtime/src/preview2/abi.rs +227 -0
  142. data/crates/kobako-wasmtime/src/preview2/error.rs +118 -0
  143. data/crates/kobako-wasmtime/src/preview2/filesystem.rs +122 -0
  144. data/crates/kobako-wasmtime/src/preview2/host.rs +3959 -0
  145. data/crates/kobako-wasmtime/src/preview2/http.rs +1503 -0
  146. data/crates/kobako-wasmtime/src/preview2/io.rs +315 -0
  147. data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
  148. data/crates/kobako-wasmtime/src/preview2/table.rs +305 -0
  149. data/crates/kobako-wasmtime/src/preview2.rs +57 -0
  150. data/crates/kobako-wasmtime/src/trap.rs +24 -9
  151. data/crates/kobako-wasmtime/src/wasi.rs +210 -81
  152. data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
  153. data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
  154. data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
  155. data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
  156. data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
  157. data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
  158. data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
  159. data/data/kobako.wasm +0 -0
  160. data/ext/kobako/Cargo.toml +1 -1
  161. data/ext/kobako/src/{runtime/errors.rs → errors.rs} +34 -26
  162. data/ext/kobako/src/{runtime/escape.rs → escape.rs} +42 -11
  163. data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +30 -26
  164. data/ext/kobako/src/{runtime/filesystem → filesystem}/ruby.rs +149 -168
  165. data/ext/kobako/src/{runtime/filesystem.rs → filesystem.rs} +24 -15
  166. data/ext/kobako/src/gvl.rs +306 -0
  167. data/ext/kobako/src/lib.rs +64 -3
  168. data/ext/kobako/src/network/mock.rs +187 -0
  169. data/ext/kobako/src/network.rs +591 -0
  170. data/ext/kobako/src/runtime/bridge.rs +30 -29
  171. data/ext/kobako/src/runtime/snapshot.rs +4 -4
  172. data/ext/kobako/src/runtime.rs +221 -143
  173. data/ext/kobako/src/wire.rs +42 -0
  174. data/lib/kobako/catalog/extensions.rb +14 -2
  175. data/lib/kobako/catalog/flags.rb +3 -5
  176. data/lib/kobako/catalog/grants.rb +5 -4
  177. data/lib/kobako/catalog/handles.rb +5 -27
  178. data/lib/kobako/catalog/mount.rb +11 -3
  179. data/lib/kobako/catalog/network.rb +35 -0
  180. data/lib/kobako/catalog/replacements.rb +28 -0
  181. data/lib/kobako/catalog/services.rb +5 -19
  182. data/lib/kobako/catalog/snippets.rb +3 -18
  183. data/lib/kobako/catalog.rb +3 -0
  184. data/lib/kobako/codec/{utils.rb → boundary.rb} +4 -2
  185. data/lib/kobako/codec/decoder.rb +4 -4
  186. data/lib/kobako/codec/ext_types.rb +3 -3
  187. data/lib/kobako/codec/handle_walk.rb +3 -43
  188. data/lib/kobako/codec/value_budget.rb +132 -40
  189. data/lib/kobako/codec.rb +1 -1
  190. data/lib/kobako/context.rb +24 -11
  191. data/lib/kobako/errors.rb +15 -12
  192. data/lib/kobako/extension.rb +3 -2
  193. data/lib/kobako/filesystem.rb +9 -2
  194. data/lib/kobako/handle.rb +2 -2
  195. data/lib/kobako/names.rb +28 -0
  196. data/lib/kobako/network.rb +210 -0
  197. data/lib/kobako/outcome.rb +7 -7
  198. data/lib/kobako/pool.rb +45 -23
  199. data/lib/kobako/runtime.rb +3 -2
  200. data/lib/kobako/sandbox.rb +92 -35
  201. data/lib/kobako/sandbox_options.rb +41 -106
  202. data/lib/kobako/transport/argument_wrap.rb +64 -0
  203. data/lib/kobako/transport/block_failure.rb +1 -1
  204. data/lib/kobako/transport/dispatcher.rb +6 -6
  205. data/lib/kobako/transport/exposure.rb +26 -15
  206. data/lib/kobako/transport/reflection.rb +21 -4
  207. data/lib/kobako/transport/run.rb +8 -23
  208. data/lib/kobako/transport/yielder.rb +2 -9
  209. data/lib/kobako/transport.rb +1 -0
  210. data/lib/kobako/version.rb +1 -1
  211. data/lib/kobako.rb +6 -2
  212. data/release-please-config.json +15 -0
  213. data/sig/core/thread.rbs +6 -0
  214. data/sig/kobako/catalog/extensions.rbs +2 -0
  215. data/sig/kobako/catalog/grants.rbs +7 -4
  216. data/sig/kobako/catalog/handles.rbs +0 -2
  217. data/sig/kobako/catalog/mount.rbs +3 -1
  218. data/sig/kobako/catalog/network.rbs +20 -0
  219. data/sig/kobako/catalog/replacements.rbs +14 -0
  220. data/sig/kobako/catalog/services.rbs +0 -4
  221. data/sig/kobako/catalog/snippets.rbs +0 -2
  222. data/sig/kobako/codec/{utils.rbs → boundary.rbs} +2 -2
  223. data/sig/kobako/codec/handle_walk.rbs +0 -6
  224. data/sig/kobako/codec/value_budget.rbs +47 -4
  225. data/sig/kobako/context.rbs +3 -1
  226. data/sig/kobako/errors.rbs +4 -4
  227. data/sig/kobako/filesystem.rbs +21 -3
  228. data/sig/kobako/network.rbs +115 -0
  229. data/sig/kobako/outcome.rbs +1 -1
  230. data/sig/kobako/pool.rbs +7 -3
  231. data/sig/kobako/runtime.rbs +32 -3
  232. data/sig/kobako/sandbox.rbs +19 -2
  233. data/sig/kobako/sandbox_options.rbs +29 -38
  234. data/sig/kobako/transport/argument_wrap.rbs +15 -0
  235. data/sig/kobako/transport/error.rbs +1 -1
  236. data/sig/kobako/transport/exposure.rbs +2 -4
  237. data/sig/kobako/transport/reflection.rbs +10 -0
  238. data/sig/kobako/transport/run.rbs +0 -2
  239. data/sig/kobako/transport/yielder.rbs +0 -3
  240. data/sig/kobako/transport.rbs +1 -1
  241. data/sig/kobako.rbs +13 -0
  242. metadata +84 -35
  243. data/crates/kobako-runtime/src/endpoint/capture.rs +0 -115
  244. data/crates/kobako-runtime/src/endpoint/memory_cap.rs +0 -238
  245. data/crates/kobako-runtime/src/filesystem/path.rs +0 -21
  246. data/crates/kobako-runtime/src/vfs/errno.rs +0 -153
  247. data/crates/kobako-runtime/tests/linux_baseline/calls.rs +0 -171
  248. data/crates/kobako-runtime/tests/linux_baseline/concurrent.rs +0 -276
  249. data/crates/kobako-runtime/tests/linux_baseline/kobako.rs +0 -323
  250. data/crates/kobako-runtime/tests/linux_baseline/linux-baseline-expected.txt +0 -16
  251. data/crates/kobako-runtime/tests/linux_baseline/linux.rs +0 -449
  252. data/crates/kobako-runtime/tests/linux_baseline/main.rs +0 -611
  253. data/crates/kobako-runtime/tests/linux_baseline/permissions.rs +0 -236
  254. data/crates/kobako-wasmtime/src/descriptors.rs +0 -200
  255. data/crates/kobako-wasmtime/tests/integration/compile_posture.rs +0 -43
  256. data/crates/kobako-wasmtime/tests/integration/guest_file.rs +0 -1085
  257. data/crates/kobako-wasmtime/tests/integration/main.rs +0 -29
  258. data/crates/kobako-wasmtime/tests/integration/preamble_flags.rs +0 -70
  259. data/crates/kobako-wasmtime/tests/integration/snippet_compile.rs +0 -95
  260. data/crates/kobako-wasmtime/tests/integration/support/mod.rs +0 -30
  261. data/crates/kobako-wasmtime/tests/integration/unanswered_call.rs +0 -86
  262. data/crates/kobako-wasmtime/tests/integration/unsupported_call.rs +0 -51
  263. data/ext/kobako/src/runtime/gvl.rs +0 -147
  264. data/lib/kobako/constant_name.rb +0 -8
  265. data/sig/kobako/constant_name.rbs +0 -3
  266. /data/ext/kobako/src/{runtime/pinned_value.rs → pinned_value.rs} +0 -0
@@ -21,7 +21,7 @@ module Kobako
21
21
  @runtime = runtime
22
22
  @services = services
23
23
  @extensions = extensions
24
- @grants = grants
24
+ @replacements = Catalog::Replacements.new(grants)
25
25
  @preamble = preamble
26
26
  @resolved = {} # : Hash[String, Transport::Exposure]
27
27
  @overrides = {} # : Hash[String, Transport::Exposure]
@@ -33,12 +33,13 @@ module Kobako
33
33
  # Use +object+ for the Service at +path+ during this invocation only,
34
34
  # filling a fillable Service or shadowing a bound one. Returns +self+.
35
35
  #
36
- # Raises ArgumentError when +path+ was never bound on the Sandbox, or when
37
- # called after the block has returned.
36
+ # Raises TypeError for a +path+ neither a Symbol nor a String, and
37
+ # ArgumentError when +path+ was never bound on the Sandbox, or when called
38
+ # after the block has returned.
38
39
  def bind(path, object)
39
40
  raise ArgumentError, "Kobako::Context is spent; ctx.bind is only valid inside the #eval / #run block" if @spent
40
41
 
41
- key = path.to_s
42
+ key = Kobako.to_name(path, "bind path")
42
43
  raise ArgumentError, "cannot override undeclared path #{key.inspect}" unless @services.bound?(key)
43
44
 
44
45
  @overrides[key] = Transport::Exposure.of(object)
@@ -56,12 +57,23 @@ module Kobako
56
57
  def mount(at, filesystem, access: :read, &policy)
57
58
  raise ArgumentError, "Kobako::Context is spent; ctx.mount is only valid inside the #eval / #run block" if @spent
58
59
 
59
- Runtime.validate_mount(at, access, filesystem)
60
- mount = Catalog::Mount.new(at: at, access: access, filesystem: filesystem, policy: policy)
61
- raise ArgumentError, "cannot override unmounted path #{at.inspect}" unless @grants.include?(mount)
60
+ @replacements.replace(Catalog::Mount.new(at: at, access: access, filesystem: filesystem, policy: policy),
61
+ "cannot override unmounted path #{at.inspect}")
62
+ self
63
+ end
64
+
65
+ # Use +entry+ for the network entry named +name+ during this invocation
66
+ # only, built and added to as Sandbox#network takes them; it may reach more
67
+ # than the Sandbox's own. Returns +self+.
68
+ #
69
+ # Raises TypeError for a +name+ neither a Symbol nor a String, and
70
+ # ArgumentError when +name+ was never given on the Sandbox, or when called
71
+ # after the block has returned.
72
+ def network(name, entry = nil, &builder)
73
+ raise ArgumentError, "Kobako::Context is spent; ctx.network is only valid inside the #eval / #run block" if @spent
62
74
 
63
- mounts = @mounts ||= {} # : Hash[String, Catalog::Mount]
64
- mounts[mount.key] = mount
75
+ @replacements.replace(Catalog::Network.new(name: name, entry: entry, &builder),
76
+ "cannot override undeclared network entry #{name.to_s.inspect}")
65
77
  self
66
78
  end
67
79
 
@@ -90,10 +102,11 @@ module Kobako
90
102
  private
91
103
 
92
104
  # What the Runtime builds the invocation from: the Preamble's parts,
93
- # then this invocation's mounts.
105
+ # then this invocation's Mounts and network entries.
94
106
  def setup
95
107
  paths, snippets, flags = @preamble
96
- [paths, snippets, flags, @grants.entries(@mounts || {})]
108
+ mounts, networks = @replacements.entries
109
+ [paths, snippets, flags, mounts, networks]
97
110
  end
98
111
 
99
112
  # The Context is spent once the block returns, so a captured +ctx+ used
data/lib/kobako/errors.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kobako
4
- # Every Sandbox#eval or Sandbox#run returns, or raises exactly one of
5
- # TrapError, SandboxError, or ServiceError. SetupError and PoolTimeoutError
6
- # arise outside any invocation.
4
+ # Every Sandbox#eval or Sandbox#run that reaches the guest returns, or
5
+ # raises exactly one of TrapError, SandboxError, or ServiceError. SetupError
6
+ # and PoolTimeoutError arise outside any invocation. A mistake in a call
7
+ # raises the TypeError, ArgumentError, RangeError, or FrozenError a CRuby
8
+ # core method raises for it.
7
9
 
8
- # The base of every error kobako raises.
10
+ # The base of every failure a run or a setup meets.
9
11
  class Error < StandardError; end
10
12
 
11
13
  module Recorded # :nodoc:
@@ -38,22 +40,23 @@ module Kobako
38
40
  class SetupError < Error; end
39
41
 
40
42
  # The Guest Binary is missing at +wasm_path+.
41
- class ModuleNotBuiltError < SetupError; end
43
+ class GuestBinaryNotFoundError < SetupError; end
42
44
 
43
45
  module Diagnosable # :nodoc:
44
- attr_reader :origin, :klass, :backtrace_lines
46
+ attr_reader :origin, :class_name, :backtrace_lines
45
47
 
46
- def initialize(message, origin: nil, klass: nil, backtrace_lines: nil) # :nodoc:
48
+ def initialize(message, origin: nil, class_name: nil, backtrace_lines: nil) # :nodoc:
47
49
  super(message)
48
50
  @origin = origin
49
- @klass = klass
51
+ @class_name = class_name
50
52
  @backtrace_lines = backtrace_lines
51
53
  end
52
54
  end
53
55
 
54
56
  # The guest failed: the script raised or did not compile, the Guest Binary
55
- # could not start the run, or what it produced could not be read.
56
- # +origin+ (<tt>"sandbox"</tt> or <tt>"service"</tt>), +klass+ and
57
+ # could not start the run, a nested Mount stood nowhere Linux would place
58
+ # it, or what it produced could not be read.
59
+ # +origin+ (<tt>"sandbox"</tt> or <tt>"service"</tt>), +class_name+ and
57
60
  # +backtrace_lines+ say where it came from, which class raised it, and its
58
61
  # backtrace. +execution+ is the failed run's Execution, as on TrapError.
59
62
  class SandboxError < Error
@@ -62,7 +65,7 @@ module Kobako
62
65
  end
63
66
 
64
67
  # A Service call failed and the guest left it unrescued. It carries
65
- # +origin+, +klass+, +backtrace_lines+ and +execution+ as SandboxError does.
68
+ # +origin+, +class_name+, +backtrace_lines+ and +execution+ as SandboxError does.
66
69
  class ServiceError < Error
67
70
  include Diagnosable
68
71
  include Recorded
@@ -88,7 +91,7 @@ module Kobako
88
91
  # so the block never ran. Left unrescued, the Service call fails.
89
92
  class YieldValueError < Error; end
90
93
 
91
- # Raised at a Service's +yield+ when the guest serves no block, so the
94
+ # Raised at a Service's +yield+ when the guest supports no block, so the
92
95
  # block never ran. Left unrescued, the Service call fails.
93
96
  class UnsupportedError < Error; end
94
97
 
@@ -12,8 +12,9 @@ module Kobako
12
12
  # is bound with Sandbox#bind instead.
13
13
  # [+backend+] A Backend, or +nil+ for an Extension that runs entirely in
14
14
  # the guest.
15
- # [+depends_on+] Names of Extensions that must also be installed, checked
16
- # at the first invocation.
15
+ # [+depends_on+] An Array naming, as Symbols or Strings, the Extensions that
16
+ # must also be installed, checked at the first invocation.
17
+ # Sandbox#install raises TypeError for another class.
17
18
  class Extension < Data.define(:name, :source, :backend, :depends_on)
18
19
  # The host object an Extension's constant at +path+ calls, such as
19
20
  # <tt>"MyApp::Store"</tt>, given by keyword:
@@ -11,9 +11,12 @@ module Kobako
11
11
  # Files held in memory for as long as the object lives, seeded from a
12
12
  # Hash of path to contents. Every invocation shares them; one that
13
13
  # should start empty mounts a new Tmpfs through Context#mount.
14
- # [<tt>Bind.new(path)</tt>]
14
+ # [<tt>Bind.new(path, exclusive: false)</tt>]
15
15
  # A host directory and everything beneath it. Nothing outside it is
16
- # reachable, a symbolic link pointing out included.
16
+ # reachable, a symbolic link pointing out included. With +exclusive+
17
+ # the Host App vouches that only the guest changes the directory, so a
18
+ # name the guest found is not looked up on the host again; a change the
19
+ # host makes meanwhile may go unseen.
17
20
  # [<tt>Overlay.new(lower: [filesystem, ...], upper: tmpfs)</tt>]
18
21
  # Read-only lower Layers, topmost first, under an upper Tmpfs that
19
22
  # takes every change, as Linux's overlayfs stacks them. Without
@@ -46,6 +49,10 @@ module Kobako
46
49
  # device, and +ftype+, which says a FIFO, a socket, or a device is one
47
50
  # so the guest's open is refused without asking +open+.
48
51
  #
52
+ # An object whose +exclusive?+ answers true vouches that only the guest
53
+ # changes it, so +stat+ is asked about a name once rather than again on
54
+ # each walk, as <tt>Bind.new(path, exclusive: true)</tt> does.
55
+ #
49
56
  # The file +open+ answers takes the guest's reads and writes, each named
50
57
  # as +IO+ names it:
51
58
  #
data/lib/kobako/handle.rb CHANGED
@@ -6,9 +6,9 @@ module Kobako
6
6
  class Handle < Data.define(:id)
7
7
  # The smallest id; 0 never names a Handle.
8
8
  MIN_ID = 1
9
- # The largest id, the positive half of a signed 32-bit integer; an
9
+ # The largest id, the bound the wire's Envelope holds every side to; an
10
10
  # invocation needing more raises HandleExhaustedError.
11
- MAX_ID = 0x7fff_ffff
11
+ MAX_ID = Kobako.max_handle_id
12
12
 
13
13
  def initialize(id:) # :nodoc:
14
14
  raise ArgumentError, "Handle id must be Integer" unless id.is_a?(Integer)
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The name rules on Kobako itself, at the root tier so the Catalog and
4
+ # Transport share one.
5
+ module Kobako
6
+ # A name the Host App gives is a Symbol or a String, as CRuby's
7
+ # +const_get+ and +define_method+ take one; any other class is refused
8
+ # before its text is read.
9
+ def self.to_name(name, what) # :nodoc:
10
+ unless name.is_a?(Symbol) || name.is_a?(String)
11
+ raise TypeError,
12
+ "#{what} must be a Symbol or String, got #{name.class}"
13
+ end
14
+
15
+ name.to_s
16
+ end
17
+
18
+ # A name that must read as a Ruby constant, as the Symbol it stands for.
19
+ def self.to_constant_name(name, what) # :nodoc:
20
+ text = to_name(name, what)
21
+ unless constant_name?(text)
22
+ raise ArgumentError,
23
+ "#{what} must be a Ruby constant name (got #{name.inspect})"
24
+ end
25
+
26
+ text.to_sym
27
+ end
28
+ end
@@ -0,0 +1,210 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kobako
4
+ # The network a Sandbox gives the guest, one named entry at a time. An entry
5
+ # is any object answering one or more of +endpoints+, +resolve?+,
6
+ # +connect?+, +request?+, and +credentials+, or one Sandbox#network builds
7
+ # from its block:
8
+ #
9
+ # sandbox.network(:github) do |net|
10
+ # net.endpoint "api.github.com", port: 443
11
+ # net.endpoint "cache.internal", port: 6379, protocol: :tcp, addresses: [:private]
12
+ # end
13
+ #
14
+ # A test hands Sandbox.new a Mock as +network:+, so the guest's names
15
+ # answer from a table and its dials reach a server the test runs. The
16
+ # rules judge the Mock's answers as they judge the host's:
17
+ #
18
+ # mock = Kobako::Network::Mock.new
19
+ # mock.resolve("api.example.com", to: "93.184.216.34")
20
+ # mock.route("93.184.216.34", 443, to: ["127.0.0.1", server.addr[1]])
21
+ # sandbox = Kobako::Sandbox.new(network: mock)
22
+ #
23
+ # [<tt>Mock.new(local_addresses: [])</tt>]
24
+ # The host's own addresses, which the rules count as local; +nil+ for a
25
+ # host that cannot say them, so every connect to a name is refused.
26
+ # [<tt>resolve(name, to: address)</tt>, <tt>resolve(name, to: [address, ...])</tt>]
27
+ # What a lookup of +name+ answers from now on; a name with no answer
28
+ # resolves to nothing. The name reads as a guest's lookup reads it, so
29
+ # case, the root's dot, and an IDN's spelling do not matter. Raises
30
+ # ArgumentError for a host no lookup asks, such as an address.
31
+ # [<tt>route(address, port, to: [address, port], protocol: :tcp)</tt>]
32
+ # Where a dial over +protocol+, +:tcp+ or +:udp+, goes instead. A dial
33
+ # with no route for its protocol is refused, so nothing reaches the host
34
+ # network unasked; a UDP socket is refused as it connects.
35
+ # [<tt>refuse(address, port, errno, protocol: :tcp)</tt>]
36
+ # Fails a dial over +protocol+ as a host socket failing with +errno+
37
+ # does: an Errno class such as Errno::ECONNRESET, or a subclass of one,
38
+ # read by its name so it fails alike on every host. Raises ArgumentError
39
+ # for a class no Errno class is behind, or an errno kobako never answers.
40
+ # [<tt>hold(name) { ... }</tt>]
41
+ # Keeps each lookup of +name+ waiting until the block returns or raises,
42
+ # +name+ read as +resolve+ reads it.
43
+ # [+lookups+, +dialed_addresses+]
44
+ # Each name asked, and each <tt>[address, port]</tt> dialed, in order.
45
+ module Network
46
+ # What a keyword nobody wrote reads as, so the runtime's contract alone
47
+ # gives its default.
48
+ UNWRITTEN = Object.new.freeze # :nodoc:
49
+ private_constant :UNWRITTEN
50
+
51
+ # What the guest may reach: a +host+ and a +port+, the +protocol+ it
52
+ # speaks, and the +addresses+ the host's name may lead to. Unless written
53
+ # otherwise it speaks +:http+ and leads only to +:public+ addresses. Each
54
+ # address is +:public+, +:private+, +:local+, or a CIDR as a String or an
55
+ # IPAddr.
56
+ #
57
+ # An +:http+ endpoint's +rules+ say which methods and paths it allows and
58
+ # denies; with none, it allows every request.
59
+ #
60
+ # Raises TypeError for a host neither a Symbol nor a String, and
61
+ # ArgumentError for an empty host, a port outside 1 to 65535, a protocol
62
+ # other than +:http+, +:tcp+, or +:udp+, or another address, by the rules
63
+ # an invocation reads the endpoint with.
64
+ class Endpoint < Data.define(:host, :port, :protocol, :addresses, :rules)
65
+ def initialize(host:, port:, protocol: UNWRITTEN, addresses: UNWRITTEN, rules: UNWRITTEN)
66
+ written = { protocol:, addresses:, rules: }.reject { |_, value| value.equal?(UNWRITTEN) }
67
+ %i[addresses rules].each { |field| written[field] = Array(written[field]).freeze if written.key?(field) }
68
+ host, port, protocol, addresses, rules = Network.normalize_endpoint(host, port, written)
69
+ super
70
+ end
71
+ end
72
+
73
+ # One connection the guest asks for, as a +connect?+ policy is handed it:
74
+ # the +host+ it named, a name or a literal address, its +port+, and its
75
+ # +protocol+. The host is never a real address a name resolved to.
76
+ class Connection < Data.define(:host, :port, :protocol); end
77
+
78
+ # One rule an +:http+ endpoint judges a request by: whether it allows or
79
+ # denies, its +method+ uppercase or +nil+ for any, and a +path+ pattern,
80
+ # where <tt>*</tt> stands for one segment and <tt>**</tt> for any number.
81
+ # Each is given as a Symbol or a String; another class raises TypeError.
82
+ class HttpRule
83
+ attr_reader :method, :path
84
+
85
+ # Whether the rule allows what it matches, or denies it.
86
+ def allow? = @allow
87
+
88
+ def initialize(allow:, method:, path:)
89
+ method = nil if method == :any
90
+ @allow, @method, @path = Network.normalize_rule(allow ? true : false, method, path)
91
+ @method&.freeze
92
+ @path.freeze
93
+ freeze
94
+ end
95
+ end
96
+
97
+ # The rules a block given to Builder#endpoint adds to its endpoint.
98
+ class Rules
99
+ def initialize # :nodoc:
100
+ @rules = [] # : Array[HttpRule]
101
+ end
102
+
103
+ # Allow +method+, or +:any+, on paths +path+ matches. Returns +self+.
104
+ def allow(method, path)
105
+ @rules << HttpRule.new(allow: true, method: method, path: path)
106
+ self
107
+ end
108
+
109
+ # Deny +method+, or +:any+, on paths +path+ matches; a denial wins over
110
+ # any allowance. Returns +self+.
111
+ def deny(method, path)
112
+ @rules << HttpRule.new(allow: false, method: method, path: path)
113
+ self
114
+ end
115
+
116
+ def to_a = @rules.dup # :nodoc:
117
+ end
118
+
119
+ # A value the Host App hands no guest, swapped in place of +placeholder+ in
120
+ # one header of a request bound to its entry's own endpoints. The
121
+ # +placement+ is +:bearer+ or +:basic+ for the +authorization+ header, or a
122
+ # header's name. The block answers the value for a Request, or +nil+ to
123
+ # send nothing, as the request leaves; a block that raises refuses the
124
+ # request. A +placeholder+ neither a Symbol nor a String raises TypeError.
125
+ class Credential
126
+ attr_reader :placement, :placeholder
127
+
128
+ def initialize(placement, placeholder:, &source)
129
+ raise ArgumentError, "a credential needs a block answering its value" unless source
130
+
131
+ @placement = placement.is_a?(String) ? placement.dup.freeze : placement
132
+ @placeholder = Network.normalize_credential(@placement, placeholder).freeze
133
+ @source = source
134
+ end
135
+
136
+ # The value for +request+, or +nil+ to send nothing; raising refuses it.
137
+ def value(request) = @source.call(request)
138
+ end
139
+
140
+ # One HTTP request the guest sends, as a +request?+ policy is handed it:
141
+ # the +host+ lowercase and the +port+, the +method+ as sent, since a
142
+ # method is case-sensitive, the +scheme+, the +path+ with no query, and
143
+ # the +header_names+ lowercase, never a header's value.
144
+ class Request
145
+ attr_reader :host, :port, :method, :scheme, :path, :header_names
146
+
147
+ def initialize(authority, method, scheme, path, header_names) # :nodoc:
148
+ @host, @port = authority
149
+ @method = method
150
+ @scheme = scheme
151
+ @path = path
152
+ @header_names = header_names
153
+ freeze
154
+ end
155
+ end
156
+
157
+ # The entry a block given to Sandbox#network builds, adding to the object
158
+ # given beside it, as Faraday.new yields its builder. It collects what the
159
+ # block declares; each invocation composes it with the given object, the
160
+ # object's endpoints, credentials, and policies first, any refusal
161
+ # winning.
162
+ class Builder
163
+ HOOKS = %i[resolve connect request].freeze # :nodoc:
164
+
165
+ def initialize(entry = nil) # :nodoc:
166
+ @entry = entry
167
+ @endpoints = [] # : Array[Endpoint]
168
+ @policies = HOOKS.to_h { |hook| [hook, []] } # : Hash[Symbol, Array[^(untyped) -> boolish]]
169
+ @credentials = [] # : Array[Credential]
170
+ end
171
+
172
+ # Let the guest reach +host+ on +port+, as Endpoint.new takes them.
173
+ # Returns +self+.
174
+ # A given block yields a Rules adding the methods and paths an +:http+
175
+ # endpoint allows and denies.
176
+ def endpoint(host, port:, protocol: UNWRITTEN, addresses: UNWRITTEN)
177
+ rules = Rules.new
178
+ yield rules if block_given?
179
+ @endpoints << Endpoint.new(host: host, port: port, protocol: protocol, addresses: addresses,
180
+ rules: rules.to_a)
181
+ self
182
+ end
183
+
184
+ # Judge each decision +hook+ names with the block; a falsy answer or a
185
+ # raised StandardError refuses. +:resolve+ hands the block the name a
186
+ # lookup asks for, lowercase with no trailing dot and an IDN as its
187
+ # A-label, +:connect+ a Connection, and +:request+ a Request. Raises
188
+ # ArgumentError for another hook. Returns +self+.
189
+ def policy(hook, &block)
190
+ unless HOOKS.include?(hook)
191
+ raise ArgumentError,
192
+ "a policy hook must be one of #{HOOKS.inspect}, got #{hook.inspect}"
193
+ end
194
+ raise ArgumentError, "a policy needs a block" unless block
195
+
196
+ @policies.fetch(hook) << block
197
+ self
198
+ end
199
+
200
+ # Swap a Credential's value in place of +placeholder+ in requests bound
201
+ # to this entry's endpoints. Returns +self+.
202
+ def credential(placement, placeholder:, &source)
203
+ @credentials << Credential.new(placement, placeholder: placeholder, &source)
204
+ self
205
+ end
206
+
207
+ def to_native = [@entry, @endpoints, @credentials, @policies] # :nodoc:
208
+ end
209
+ end
210
+ end
@@ -41,9 +41,9 @@ module Kobako
41
41
  # The fields land on the exception verbatim — it carries the record
42
42
  # rather than a translation of one.
43
43
  def panic_error(panic, entrypoint)
44
- origin, klass, message, backtrace, available = panic
45
- selected = error_class(origin, klass)
46
- attribution = { origin: origin, klass: klass, backtrace_lines: backtrace }
44
+ origin, class_name, message, backtrace, available = panic
45
+ selected = error_class(origin, class_name)
46
+ attribution = { origin: origin, class_name: class_name, backtrace_lines: backtrace }
47
47
  return selected.new(message, **attribution) unless selected == UndefinedEntrypointError
48
48
 
49
49
  UndefinedEntrypointError.new(message, name: entrypoint, available: available.map(&:to_sym), **attribution)
@@ -54,9 +54,9 @@ module Kobako
54
54
  # naming a class outside the branch its origin chose is ignored rather
55
55
  # than honoured: what a guest calls its exception must not move the
56
56
  # failure to a layer the attribution did not put it in.
57
- def error_class(origin, klass)
57
+ def error_class(origin, class_name)
58
58
  base = origin == ORIGIN_SERVICE ? ServiceError : SandboxError
59
- selected = SUBCLASSES.fetch(klass, base)
59
+ selected = SUBCLASSES.fetch(class_name, base)
60
60
  return base unless selected <= base
61
61
 
62
62
  selected
@@ -71,12 +71,12 @@ module Kobako
71
71
  end
72
72
 
73
73
  # No guest class stands behind a result kobako cannot decode, so
74
- # +klass+ names the host class raised.
74
+ # +class_name+ names the host class raised.
75
75
  def wire_error(message, diagnostic: nil)
76
76
  Kobako::Transport::Error.new(
77
77
  message,
78
78
  origin: ORIGIN_SANDBOX,
79
- klass: "Kobako::Transport::Error",
79
+ class_name: "Kobako::Transport::Error",
80
80
  diagnostic: diagnostic
81
81
  )
82
82
  end
data/lib/kobako/pool.rb CHANGED
@@ -7,21 +7,29 @@ module Kobako
7
7
  # A bounded set of warm, identically set-up Sandboxes, handed out to one
8
8
  # holder at a time. Every Sandbox it builds is kept: an invocation leaves
9
9
  # nothing behind, whatever ended it.
10
+ #
11
+ # Deprecated: the next release removes Pool. A Sandbox keeps nothing
12
+ # between runs, so Threads share one Sandbox instead.
10
13
  class Pool
11
14
  # The default +checkout_timeout+: 5 seconds.
12
15
  DEFAULT_CHECKOUT_TIMEOUT_SECONDS = 5.0
16
+ # What building a Pool warns while deprecation warnings are shown.
17
+ DEPRECATION = "Kobako::Pool is deprecated, removed next release; share a Kobako::Sandbox across Threads"
18
+ private_constant :DEPRECATION
13
19
 
14
- # Build a Pool of up to +slots+ Sandboxes, built on first demand with the
20
+ # Build a Pool of up to +size+ Sandboxes, built on first demand with the
15
21
  # other keywords as Sandbox.new takes them. +checkout_timeout+ bounds how
16
22
  # many seconds #with waits, and +nil+ waits indefinitely. The block, if
17
23
  # given, sets up each Sandbox once, as with Sandbox#bind and
18
24
  # Sandbox#preload.
19
25
  #
20
- # Raises ArgumentError when +slots+ is not a positive Integer or
21
- # +checkout_timeout+ is not a positive finite number.
22
- def initialize(slots:, checkout_timeout: DEFAULT_CHECKOUT_TIMEOUT_SECONDS, **sandbox_options, &setup)
23
- validate_slots(slots)
24
- @slots = slots
26
+ # Raises TypeError when +size+ is not an Integer or +checkout_timeout+
27
+ # is not Numeric, and ArgumentError when either is not positive or
28
+ # +checkout_timeout+ is not finite.
29
+ def initialize(size:, checkout_timeout: DEFAULT_CHECKOUT_TIMEOUT_SECONDS, **sandbox_options, &setup)
30
+ warn(DEPRECATION, category: :deprecated, uplevel: 1)
31
+ validate_size(size)
32
+ @size = size
25
33
  @checkout_timeout = normalize_checkout_timeout(checkout_timeout)
26
34
  @sandbox_options = sandbox_options
27
35
  @setup = setup
@@ -35,12 +43,18 @@ module Kobako
35
43
  # block's value; the Sandbox returns to the pool however the block
36
44
  # exits. Raises PoolTimeoutError once every slot has stayed held past
37
45
  # +checkout_timeout+.
46
+ #
47
+ # An interrupt reaches the checkout only while it waits or builds, and
48
+ # the block as it runs, as connection_pool's +with+ does, so none lands
49
+ # between taking a Sandbox and handing it back.
38
50
  def with
39
- sandbox = acquire
40
- begin
41
- yield sandbox
42
- ensure
43
- checkin(sandbox)
51
+ Thread.handle_interrupt(Exception => :never) do
52
+ sandbox = acquire
53
+ begin
54
+ Thread.handle_interrupt(Exception => :immediate) { yield sandbox }
55
+ ensure
56
+ checkin(sandbox)
57
+ end
44
58
  end
45
59
  end
46
60
 
@@ -64,7 +78,7 @@ module Kobako
64
78
  @mutex.synchronize do
65
79
  return [:idle, @idle.pop] unless @idle.empty?
66
80
 
67
- if @constructed < @slots
81
+ if @constructed < @size
68
82
  @constructed += 1
69
83
  return [:build, nil]
70
84
  end
@@ -79,35 +93,42 @@ module Kobako
79
93
  remaining = deadline && (deadline - monotonic_now)
80
94
  if remaining && remaining <= 0
81
95
  raise PoolTimeoutError,
82
- "no Sandbox returned within #{@checkout_timeout}s: all #{@slots} slots are held"
96
+ "no Sandbox returned within #{@checkout_timeout}s: all #{@size} Sandboxes are held"
83
97
  end
84
98
 
85
- @slot_freed.wait(@mutex, remaining)
99
+ Thread.handle_interrupt(Exception => :immediate) { @slot_freed.wait(@mutex, remaining) }
86
100
  end
87
101
 
88
102
  # A failed construction releases its reserved capacity so a later
89
- # checkout can retry.
103
+ # checkout can retry. Setup closes registration, so each holder gets
104
+ # the Sandbox as the setup block left it.
90
105
  def construct_slot
91
106
  done = false
92
- sandbox = Sandbox.new(**@sandbox_options)
93
- @setup&.call(sandbox)
107
+ sandbox = Thread.handle_interrupt(Exception => :immediate) { build_slot }
94
108
  done = true
95
109
  sandbox
96
110
  ensure
97
111
  release_capacity unless done
98
112
  end
99
113
 
114
+ def build_slot
115
+ sandbox = Sandbox.new(**@sandbox_options)
116
+ @setup&.call(sandbox)
117
+ sandbox.send(:seal, "on a pooled Sandbox once its setup ran")
118
+ sandbox
119
+ end
120
+
100
121
  def checkin(sandbox)
101
122
  @mutex.synchronize do
102
123
  @idle.push(sandbox)
103
- @slot_freed.signal
124
+ @slot_freed.broadcast
104
125
  end
105
126
  end
106
127
 
107
128
  def release_capacity
108
129
  @mutex.synchronize do
109
130
  @constructed -= 1
110
- @slot_freed.signal
131
+ @slot_freed.broadcast
111
132
  end
112
133
  end
113
134
 
@@ -117,16 +138,17 @@ module Kobako
117
138
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
118
139
  end
119
140
 
120
- def validate_slots(slots)
121
- return if slots.is_a?(Integer) && slots.positive?
141
+ def validate_size(size)
142
+ raise TypeError, "size must be an Integer, got #{size.class}" unless size.is_a?(Integer)
143
+ return if size.positive?
122
144
 
123
- raise ArgumentError, "slots must be a positive Integer, got #{slots.inspect}"
145
+ raise ArgumentError, "size must be a positive Integer, got #{size.inspect}"
124
146
  end
125
147
 
126
148
  def normalize_checkout_timeout(checkout_timeout)
127
149
  return nil if checkout_timeout.nil?
128
150
  unless checkout_timeout.is_a?(Numeric)
129
- raise ArgumentError, "checkout_timeout must be Numeric or nil, got #{checkout_timeout.inspect}"
151
+ raise TypeError, "checkout_timeout must be Numeric or nil, got #{checkout_timeout.inspect}"
130
152
  end
131
153
 
132
154
  seconds = checkout_timeout.to_f
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kobako
4
- # The native wasmtime runtime, defined by the ext; this file adds only the
5
- # default Guest Binary path.
4
+ # The Ruby handle of the contract Runtime a Sandbox runs each invocation
5
+ # on, defined by the ext; this file adds only the default Guest Binary
6
+ # path.
6
7
  class Runtime # :nodoc:
7
8
  # The path is answered whether or not the file exists; from_path is
8
9
  # where a missing artifact is refused. A missing +__dir__+ raises