kobako 0.12.2 → 0.13.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.
@@ -10,13 +10,13 @@ module Kobako
10
10
  def memory_limit: () -> Integer?
11
11
  def stdout_limit: () -> Integer?
12
12
  def stderr_limit: () -> Integer?
13
+ def profile: () -> Symbol
13
14
 
15
+ # Every keyword beyond wasm_path forwards verbatim to
16
+ # SandboxOptions.new (the four caps + the profile floor).
14
17
  def initialize: (
15
18
  ?wasm_path: String?,
16
- ?stdout_limit: Integer?,
17
- ?stderr_limit: Integer?,
18
- ?timeout: (Float | Integer)?,
19
- ?memory_limit: Integer?
19
+ **untyped options
20
20
  ) -> void
21
21
 
22
22
  def stdout: () -> String
@@ -42,14 +42,18 @@ module Kobako
42
42
 
43
43
  private
44
44
 
45
+ def build_runtime!: () -> Kobako::Runtime
46
+
45
47
  def install_dispatch_proc!: () -> void
46
48
 
47
49
  def begin_invocation!: () -> void
48
50
 
49
51
  def read_usage!: () -> void
50
52
 
53
+ def read_captures!: () -> void
54
+
51
55
  def trap_class_for: (Kobako::TrapError err) -> singleton(Kobako::TrapError)
52
56
 
53
- def invoke!: (Symbol verb) { () -> Kobako::Snapshot } -> untyped
57
+ def invoke!: (Symbol verb) { () -> String } -> untyped
54
58
  end
55
59
  end
@@ -3,26 +3,33 @@ module Kobako
3
3
  DEFAULT_TIMEOUT_SECONDS: Float
4
4
  DEFAULT_MEMORY_LIMIT: Integer
5
5
  DEFAULT_OUTPUT_LIMIT: Integer
6
+ DEFAULT_PROFILE: Symbol
7
+ PROFILES: Array[Symbol]
6
8
 
7
9
  attr_reader timeout: Float?
8
10
  attr_reader memory_limit: Integer?
9
11
  attr_reader stdout_limit: Integer?
10
12
  attr_reader stderr_limit: Integer?
13
+ attr_reader profile: Symbol
11
14
 
12
15
  def self.new: (
13
16
  ?timeout: (Float | Integer)?,
14
17
  ?memory_limit: Integer?,
15
18
  ?stdout_limit: Integer?,
16
- ?stderr_limit: Integer?
19
+ ?stderr_limit: Integer?,
20
+ ?profile: Symbol
17
21
  ) -> SandboxOptions
18
22
 
19
23
  def initialize: (
20
24
  ?timeout: (Float | Integer)?,
21
25
  ?memory_limit: Integer?,
22
26
  ?stdout_limit: Integer?,
23
- ?stderr_limit: Integer?
27
+ ?stderr_limit: Integer?,
28
+ ?profile: Symbol
24
29
  ) -> void
25
30
 
31
+ def enforce_floor!: (Symbol declared) -> void
32
+
26
33
  private
27
34
 
28
35
  def normalize_timeout: ((Float | Integer)? timeout) -> Float?
@@ -30,5 +37,7 @@ module Kobako
30
37
  def normalize_memory_limit: (Integer? memory_limit) -> Integer?
31
38
 
32
39
  def normalize_output_limit: (Integer? limit, String name) -> Integer?
40
+
41
+ def normalize_profile: (untyped profile) -> Symbol
33
42
  end
34
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kobako
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.2
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aotokitsuruya
@@ -60,6 +60,7 @@ files:
60
60
  - crates/kobako-runtime/src/dispatch.rs
61
61
  - crates/kobako-runtime/src/error.rs
62
62
  - crates/kobako-runtime/src/lib.rs
63
+ - crates/kobako-runtime/src/profile.rs
63
64
  - crates/kobako-runtime/src/runtime.rs
64
65
  - crates/kobako-runtime/src/snapshot.rs
65
66
  - crates/kobako-runtime/src/yielder.rs
@@ -86,7 +87,6 @@ files:
86
87
  - ext/kobako/src/runtime.rs
87
88
  - ext/kobako/src/runtime/bridge.rs
88
89
  - ext/kobako/src/runtime/errors.rs
89
- - ext/kobako/src/snapshot.rs
90
90
  - lib/kobako.rb
91
91
  - lib/kobako/capture.rb
92
92
  - lib/kobako/catalog.rb
@@ -110,7 +110,6 @@ files:
110
110
  - lib/kobako/runtime.rb
111
111
  - lib/kobako/sandbox.rb
112
112
  - lib/kobako/sandbox_options.rb
113
- - lib/kobako/snapshot.rb
114
113
  - lib/kobako/snippet.rb
115
114
  - lib/kobako/snippet/binary.rb
116
115
  - lib/kobako/snippet/source.rb
@@ -149,7 +148,6 @@ files:
149
148
  - sig/kobako/runtime.rbs
150
149
  - sig/kobako/sandbox.rbs
151
150
  - sig/kobako/sandbox_options.rbs
152
- - sig/kobako/snapshot.rbs
153
151
  - sig/kobako/snippet.rbs
154
152
  - sig/kobako/snippet/binary.rbs
155
153
  - sig/kobako/snippet/source.rbs
@@ -1,75 +0,0 @@
1
- //! `Kobako::Snapshot` — the Ruby-facing per-invocation observable bundle.
2
- //!
3
- //! The success-path view of the engine-neutral snapshot: the outcome bytes
4
- //! and the two captured output channels, exposed through five raw readers.
5
- //! The helper methods that pack them into `Kobako::Capture`
6
- //! (`Kobako::Snapshot#stdout` / `#stderr`) live in
7
- //! `lib/kobako/snapshot.rb`. The split keeps the ext side a pure value
8
- //! carrier and lets Ruby own the convenience surface. Usage is not on the
9
- //! Snapshot — `Sandbox#usage` reads it from `Kobako::Runtime#usage`, which
10
- //! survives the trap path where no `Kobako::Snapshot` is produced.
11
-
12
- use magnus::{method, prelude::*, Error as MagnusError, RModule, RString, Ruby};
13
-
14
- use kobako_runtime::snapshot::Capture;
15
-
16
- /// Per-invocation snapshot value. Magnus wraps it so a single ext call
17
- /// from `Runtime::eval` / `Runtime::run` returns the whole bundle — the
18
- /// Sandbox layer decomposes it without round-tripping into ext again. The
19
- /// fields are set once at construction and never mutated; the five public
20
- /// methods registered in `init` read them out one by one.
21
- #[magnus::wrap(class = "Kobako::Snapshot", free_immediately, size)]
22
- pub(crate) struct Snapshot {
23
- return_bytes: Vec<u8>,
24
- stdout: Capture,
25
- stderr: Capture,
26
- }
27
-
28
- impl Snapshot {
29
- /// Bundle the success outputs the Runtime collected once the guest
30
- /// export returned with an outcome: the drained OUTCOME_BUFFER bytes
31
- /// and the capture pipes clipped to their caps.
32
- pub(crate) fn new(return_bytes: Vec<u8>, stdout: Capture, stderr: Capture) -> Self {
33
- Self {
34
- return_bytes,
35
- stdout,
36
- stderr,
37
- }
38
- }
39
-
40
- fn return_bytes(&self) -> RString {
41
- let ruby = Ruby::get().expect("Ruby thread");
42
- ruby.str_from_slice(&self.return_bytes)
43
- }
44
-
45
- fn stdout_bytes(&self) -> RString {
46
- let ruby = Ruby::get().expect("Ruby thread");
47
- ruby.str_from_slice(&self.stdout.bytes)
48
- }
49
-
50
- fn stdout_truncated(&self) -> bool {
51
- self.stdout.truncated
52
- }
53
-
54
- fn stderr_bytes(&self) -> RString {
55
- let ruby = Ruby::get().expect("Ruby thread");
56
- ruby.str_from_slice(&self.stderr.bytes)
57
- }
58
-
59
- fn stderr_truncated(&self) -> bool {
60
- self.stderr.truncated
61
- }
62
- }
63
-
64
- /// Register `Kobako::Snapshot` plus its five raw readers under the
65
- /// `Kobako` module. Called from `crate::init` after `Kobako::Runtime`
66
- /// is registered so the magnus wrap macro can resolve the class name.
67
- pub(crate) fn init(ruby: &Ruby, kobako: RModule) -> Result<(), MagnusError> {
68
- let snapshot = kobako.define_class("Snapshot", ruby.class_object())?;
69
- snapshot.define_method("return_bytes", method!(Snapshot::return_bytes, 0))?;
70
- snapshot.define_method("stdout_bytes", method!(Snapshot::stdout_bytes, 0))?;
71
- snapshot.define_method("stdout_truncated", method!(Snapshot::stdout_truncated, 0))?;
72
- snapshot.define_method("stderr_bytes", method!(Snapshot::stderr_bytes, 0))?;
73
- snapshot.define_method("stderr_truncated", method!(Snapshot::stderr_truncated, 0))?;
74
- Ok(())
75
- }
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "capture"
4
-
5
- module Kobako
6
- # Kobako::Snapshot — per-invocation observable bundle returned from
7
- # +Kobako::Runtime#eval+ and +#run+.
8
- #
9
- # The magnus class (see ext/kobako/src/snapshot.rs) carries five raw
10
- # readers: +return_bytes+, +stdout_bytes+, +stdout_truncated+,
11
- # +stderr_bytes+, +stderr_truncated+. This file reopens the class to add
12
- # the Ruby-side helpers that pack those raw fields into the user-facing
13
- # value object +Kobako::Capture+ — the same shape +Kobako::Sandbox+
14
- # exposes to the Host App. Usage is not on the Snapshot; +Sandbox#usage+
15
- # reads it from +Kobako::Runtime#usage+, which also covers the trap path
16
- # where no Snapshot is produced.
17
- class Snapshot
18
- # Wrap the stdout capture pair (+stdout_bytes+, +stdout_truncated+)
19
- # as a +Kobako::Capture+ value object. The byte content never carries
20
- # a truncation sentinel; +#truncated?+ is the only way to observe
21
- # that the cap was hit.
22
- def stdout
23
- Capture.new(bytes: stdout_bytes, truncated: stdout_truncated)
24
- end
25
-
26
- # Wrap the stderr capture pair as a +Kobako::Capture+ value object.
27
- # Mirror of +#stdout+.
28
- def stderr
29
- Capture.new(bytes: stderr_bytes, truncated: stderr_truncated)
30
- end
31
- end
32
- end
@@ -1,12 +0,0 @@
1
- module Kobako
2
- class Snapshot
3
- def return_bytes: () -> String
4
- def stdout_bytes: () -> String
5
- def stdout_truncated: () -> bool
6
- def stderr_bytes: () -> String
7
- def stderr_truncated: () -> bool
8
-
9
- def stdout: () -> Kobako::Capture
10
- def stderr: () -> Kobako::Capture
11
- end
12
- end