rogue_machines 0.1.3-aarch64-linux → 0.5.0-aarch64-linux

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,146 +1,252 @@
1
1
  # Fault injection: making a dependency fail, stall or lie on purpose.
2
+ #
3
+ # Two layers: `Rogue` and the Data values mirror the core one for one; the
4
+ # module functions are a process-wide runtime on top of one Rogue. Every
5
+ # value validates through the core at construction: TypeError for the wrong
6
+ # type, RangeError for a value the core's constructor rejects. Time is Integer
7
+ # nanoseconds throughout.
2
8
  module RogueMachines
3
9
  VERSION: String
4
10
 
5
- # Nanoseconds in a second.
6
- NS_PER_SECOND: Integer
7
-
8
- # Millionths in a whole, the unit a share is held in.
11
+ # Millionths in a whole, the unit a Fraction and a Draw are held in.
9
12
  PER_MILLION: Integer
10
13
 
11
- # Experiments a process can arm at once, the width of the armed mask.
14
+ # Slots a Rogue holds, the width of the armed mask.
12
15
  EXPERIMENTS: Integer
13
16
 
14
- # Attempts at one consistent reading before giving up on a clock being
15
- # replaced faster than it can be read.
17
+ # Longest `expires_in` the runtime arms, in nanoseconds: a day.
18
+ LONGEST_EXPERIMENT: Integer
19
+
20
+ # Longest Delay the runtime arms, in nanoseconds: five minutes.
21
+ LONGEST_DELAY: Integer
22
+
23
+ # Attempts at a reading against the clock still installed once the
24
+ # runtime's lock is held.
16
25
  READINGS: Integer
17
26
 
18
27
  class Error < StandardError
19
28
  end
20
29
 
21
- # Raised by a `:raise` fault in place of the real call.
30
+ # Raised by a :raise fault in place of the real call.
22
31
  class Injected < Error
23
32
  end
24
33
 
25
- # The fault to perform for one call.
26
- class Injection < ::Data
27
- # `:raise`, `:delay` or `:garble`.
28
- attr_reader fault: Symbol
34
+ # The core's `Slot`: an index in 0...EXPERIMENTS the caller picks. Not an
35
+ # issued id.
36
+ class Slot < ::Data
37
+ attr_reader index: Integer
38
+ def self.new: (Integer index) -> Slot
39
+ | (index: Integer) -> Slot
40
+ end
29
41
 
30
- # How long a `:delay` waits, and zero for the others.
31
- attr_reader delay_ns: Integer
42
+ # The core's `Fraction`: 0..PER_MILLION millionths.
43
+ class Fraction < ::Data
44
+ NONE: Fraction
45
+ ALL: Fraction
46
+ attr_reader millionths: Integer
47
+ def self.new: (Integer millionths) -> Fraction
48
+ | (millionths: Integer) -> Fraction
49
+ # Whether `draw` falls in this share: `draw.millionths < millionths`.
50
+ def covers?: (Draw draw) -> bool
32
51
  end
33
52
 
34
- # Anything that reports monotonic nanoseconds.
35
- interface _Clock
36
- def now_ns: () -> Integer
53
+ # The core's `Draw`: 0...PER_MILLION millionths.
54
+ class Draw < ::Data
55
+ attr_reader millionths: Integer
56
+ def self.new: (Integer millionths) -> Draw
57
+ | (millionths: Integer) -> Draw
37
58
  end
38
59
 
39
- # Anything that draws below a bound, which `Random` satisfies.
40
- interface _Random
41
- def rand: (Integer bound) -> Integer
60
+ # The core's `Fault::Delay`: `duration` Integer nanoseconds, 0..2**64-1.
61
+ class Delay < ::Data
62
+ attr_reader duration: Integer
63
+ def self.new: (Integer duration) -> Delay
64
+ | (duration: Integer) -> Delay
65
+ end
66
+
67
+ # The core's `Fault`: unit variants as symbols, the tuple variant as Delay.
68
+ type fault = :raise | :garble | Delay
69
+
70
+ # The core's `Experiment`. `expires_at` is Integer nanoseconds, 0..2**64-1.
71
+ class Experiment < ::Data
72
+ attr_reader fault: fault
73
+ attr_reader fraction: Fraction
74
+ attr_reader expires_at: Integer
75
+ def self.new: (fault fault, Fraction fraction, Integer expires_at) -> Experiment
76
+ | (fault: fault, fraction: Fraction, expires_at: Integer) -> Experiment
77
+ # Whether this has expired by `now`: `now >= expires_at`.
78
+ def spent?: (Integer now) -> bool
79
+ end
80
+
81
+ # The core's `Decision::Inject`.
82
+ class Inject < ::Data
83
+ attr_reader fault: fault
84
+ def self.new: (fault fault) -> Inject
85
+ | (fault: fault) -> Inject
86
+ end
87
+
88
+ # The core's `Arming::Replaced`: what the slot held before, expired or not,
89
+ # and the runtime's `garbled:` substitute held with it (nil when there was
90
+ # none, and always nil from `Rogue#arm`: the core keeps no substitutes).
91
+ class Replaced < ::Data
92
+ attr_reader experiment: Experiment
93
+ attr_reader garbled: untyped
94
+ def self.new: (Experiment experiment, untyped garbled) -> Replaced
95
+ | (experiment: Experiment, garbled: untyped) -> Replaced
42
96
  end
43
97
 
44
- # The experiments a process is running, by name. Reach it through the module.
98
+ # The core's `Disarming::Disarmed`: what the slot held, expired or not,
99
+ # and the runtime's `garbled:` substitute removed with it (nil when there
100
+ # was none, and always nil from `Rogue#disarm`: the core keeps no
101
+ # substitutes).
102
+ class Disarmed < ::Data
103
+ attr_reader experiment: Experiment
104
+ attr_reader garbled: untyped
105
+ def self.new: (Experiment experiment, untyped garbled) -> Disarmed
106
+ | (experiment: Experiment, garbled: untyped) -> Disarmed
107
+ end
108
+
109
+ type arming = :armed | Replaced | :already_armed
110
+ type disarming = Disarmed | :not_armed
111
+
112
+ # The core's `Rogue`. Nothing refuses. Queries judge expiry against the
113
+ # instant they are given and change nothing; only `sweep` empties expired
114
+ # slots. Mutating methods raise FrozenError on a frozen Rogue, and every
115
+ # method raises before changing anything when an argument is malformed.
45
116
  class Rogue
46
- def self.new: () -> instance
117
+ def self.new: () -> Rogue
118
+
119
+ # Honoured: :armed (slot was empty), Replaced (it held another
120
+ # experiment), :already_armed (it holds exactly this one; unchanged).
121
+ def arm: (Slot slot, Experiment experiment) -> arming
122
+
123
+ # Honoured: Disarmed (what it held), :not_armed (unchanged).
124
+ def disarm: (Slot slot) -> disarming
47
125
 
48
- # Whether any experiment is armed as of the last sweep, which is the whole
49
- # of the decision a disarmed process takes. A sweep happens on every
50
- # `decide` and every `armed`, so this trails an expiry by one call.
126
+ # Slots emptied, expired or not; 0 is unchanged.
127
+ def disarm_all: () -> Integer
128
+
129
+ # Slots emptied because expired by `now`; 0 is unchanged.
130
+ def sweep: (Integer now) -> Integer
131
+
132
+ # Whether any slot holds an experiment, expired or not.
51
133
  def any_armed?: () -> bool
52
134
 
53
- # Sweeps expired experiments at `now_ns`, then counts what is left.
54
- # Reports 0 without sweeping for a superseded generation. Every seam
55
- # taking a reading refuses a Float rather than truncating it.
56
- def armed_count: (Integer now_ns, Integer generation) -> Integer
57
-
58
- # Arms `name`, replacing any experiment already there. Raises
59
- # `ArgumentError` for an unknown fault, a share outside a whole or below
60
- # one millionth, a duration that is non-positive, below a nanosecond or
61
- # longer than the cap, a `now_ns` that is not an Integer or is outside the
62
- # range, or a `:delay`
63
- # with no `delay:`. Raises `Error` when every slot is taken. Nothing is
64
- # armed and no slot is taken when it raises.
65
- def arm: (String name, fault: String, share: Float, expires_in: Float,
66
- now_ns: Integer, generation: Integer, ?delay: Float) -> void
67
-
68
- # Reports whether `name` was still running, which an experiment that
69
- # expired on its own is not.
70
- def disarm: (String name, Integer now_ns, Integer generation) -> bool
71
-
72
- def disarm_all: () -> void
73
-
74
- # Which clock the armed expiries were computed against. Every reading is
75
- # only meaningful for one of these, and a call carrying another one is
76
- # refused rather than acted on, since sweeping is destructive.
77
- def generation: () -> Integer
78
-
79
- # Disarms everything and starts a generation, retiring readings already
80
- # taken against the outgoing clock. Returns the new generation.
81
- def invalidate: () -> Integer
82
-
83
- # The names still running at `now_ns`, in no particular order, and none
84
- # for a superseded generation.
85
- def armed: (Integer now_ns, Integer generation) -> Array[String]
86
-
87
- # The fault to perform, or `nil` to make the real call. Raises
88
- # `ArgumentError` for a `draw` or `now_ns` that is not an Integer, is
89
- # outside its range, or is a `draw` at or above `PER_MILLION`. A Float is
90
- # refused rather than truncated, because a truncated draw becomes 0,
91
- # which every share covers.
92
- def decide: (String name, Integer now_ns, Integer draw, Integer generation) -> Injection?
135
+ # Slots holding an experiment, expired or not.
136
+ def armed_count: () -> Integer
137
+
138
+ # Slots holding an experiment live at `now`.
139
+ def live_count: (Integer now) -> Integer
140
+
141
+ # The lowest empty slot, nil when all are held.
142
+ def vacant: () -> Slot?
143
+
144
+ # What `slot` holds, expired or not.
145
+ def experiment: (Slot slot) -> Experiment?
146
+
147
+ # What `slot` holds if live at `now`.
148
+ def active: (Slot slot, Integer now) -> Experiment?
149
+
150
+ # Inject when `slot` holds an experiment live at `now` whose share covers
151
+ # `draw`, else :pass.
152
+ def decide: (Slot slot, Integer now, Draw draw) -> (Inject | :pass)
153
+
154
+ # An unfrozen copy holding the same experiments.
155
+ def dup: () -> Rogue
156
+
157
+ # A copy, frozen when this is unless `freeze:` says otherwise.
158
+ def clone: (?freeze: bool?) -> Rogue
93
159
 
94
160
  def inspect: () -> String
95
161
  end
96
162
 
97
- # Delegates to `DeadlineMachines.clock` when unset, rather than memoising
98
- # it, so replacing that clock moves every expiry with it.
163
+ # Anything that reports monotonic Integer nanoseconds.
164
+ interface _Clock
165
+ def now_ns: () -> Integer
166
+ end
167
+
168
+ # Anything that draws below a bound, which `Random` satisfies.
169
+ interface _Random
170
+ def rand: (Integer bound) -> Integer
171
+ end
172
+
173
+ # Delegates to `DeadlineMachines.clock` when unset.
99
174
  def self.clock: () -> _Clock
100
175
 
101
- # Disarms everything first: an armed expiry was computed against the
102
- # outgoing clock and is not meaningful against another one.
176
+ # Disarms everything first: an armed expiry is not meaningful against
177
+ # another clock.
103
178
  def self.clock=: (_Clock?) -> void
104
179
  def self.random: () -> _Random
105
180
  def self.random=: (_Random?) -> void
106
- # The registry itself. Reach for the module methods instead: arming
107
- # through this bypasses the substitute a `:garble` returns, and freezing
108
- # it does not prevent arming, since the native side holds its own state.
109
- def self.registry: () -> Rogue
110
-
111
- # Arms an experiment under `name`. `expires_in` counts from now and is
112
- # required, so no experiment outlives the person who armed it.
113
- #
114
- # Raises `ArgumentError` for a blank name, a name that is neither ASCII nor
115
- # valid UTF-8, or any argument the registry refuses. Raises `Error` when
116
- # every slot is taken, when the clock was replaced faster than a reading
117
- # could be taken, and when the clock returned something that is not a
118
- # non-negative Integer of nanoseconds.
119
- #
120
- # `share`, `expires_in` and `delay` go through `Float()`, so a String that
121
- # parses as a number is accepted, one that does not raises `ArgumentError`,
122
- # and a value with no numeric conversion at all raises `TypeError`.
123
- def self.arm: (Symbol | String name, fault: Symbol | String, share: Numeric | String,
124
- expires_in: Numeric | String, ?delay: (Numeric | String)?,
125
- ?garbled: untyped) -> (Symbol | String)
126
-
127
- def self.disarm: (Symbol | String name) -> bool
128
- def self.disarm_all: () -> void
129
-
130
- # With no name, whether anything at all is armed.
181
+
182
+ # A frozen copy of the runtime's Rogue, taken under the lock, for reading.
183
+ def self.rogue: () -> Rogue
184
+
185
+ # Arms `name`, replacing what it held. `share` is a Fraction or a real
186
+ # Numeric in 0..1 rounded to millionths; `expires_in` Integer nanoseconds
187
+ # in 1..LONGEST_EXPERIMENT; a Delay 1..LONGEST_DELAY. Honoured: the core's
188
+ # arming answer for the name's slot, except that :already_armed needs an
189
+ # equal (==) `garbled:` substitute too; a differing one replaces it and
190
+ # answers Replaced holding the experiment. Every Replaced it answers holds
191
+ # the substitute it displaced (nil for none). Refused, unchanged: :full
192
+ # when every slot holds a live experiment. Raises TypeError/RangeError for
193
+ # malformed arguments or clock readings, and Error when the clock was
194
+ # replaced READINGS times while arming; nothing is armed when it raises.
195
+ def self.arm: (Symbol | String name, fault: fault, share: Fraction | Numeric, expires_in: Integer,
196
+ ?garbled: untyped) -> (arming | :full)
197
+
198
+ # Honoured: Disarmed (what the name held, expired or not, with the
199
+ # substitute it removed, nil for none), :not_armed. Takes no reading.
200
+ def self.disarm: (Symbol | String name) -> disarming
201
+
202
+ # Experiments held, expired or not; 0 is unchanged.
203
+ def self.disarm_all: () -> Integer
204
+
205
+ # With no name, whether anything is live now. Retires expired experiments.
131
206
  def self.armed?: (?(Symbol | String)?) -> bool
132
207
 
133
- # The experiments still running, which excludes any that has expired.
208
+ # The names live now. Retires expired experiments.
134
209
  def self.armed: () -> Array[Symbol]
135
210
 
136
- # Runs the block, or the fault armed under `name` instead. Not the block's
137
- # own type: a `:garble` returns the substitute it was armed with, which is
138
- # whatever the caller passed as `garbled:`. Makes the real call when the
139
- # clock was replaced faster than a reading could be taken.
140
- #
141
- # Raises `Injected` for a `:raise` fault, which is the point of the gem,
142
- # `DeadlineMachines::Error` when a `:delay` spends the ambient budget,
143
- # `ArgumentError` for a name it cannot key on or a draw the random gave it,
144
- # and `Error` for a clock returning an unusable reading.
211
+ # Runs the block, or the fault armed under `name`: raises Injected for
212
+ # :raise, returns the `garbled:` substitute for :garble, waits then runs
213
+ # the block for a Delay (raising `DeadlineMachines::Error` when that spends
214
+ # the ambient budget). Raises TypeError/RangeError for a malformed name,
215
+ # draw or reading.
145
216
  def self.run: (Symbol | String name) { () -> untyped } -> untyped
217
+
218
+ # Private native hooks behind the Data values: each answers the field as
219
+ # the core holds it, TypeError/RangeError for what the core rejects.
220
+ private def self.__slot: (Integer index) -> Integer
221
+ private def self.__fraction: (Integer millionths) -> Integer
222
+ private def self.__draw: (Integer millionths) -> Integer
223
+ private def self.__delay: (Integer duration) -> Integer
224
+ private def self.__experiment: (fault fault, Fraction fraction, Integer expires_at) -> [fault, Fraction, Integer]
225
+ private def self.__fault: (fault fault) -> fault
226
+ private def self.__held: (Experiment experiment) -> Experiment
227
+ # A Delay's Integer nanoseconds, nil for :raise and :garble.
228
+ private def self.__delay_of: (fault fault) -> Integer?
229
+ private def self.__spent: (Experiment experiment, Integer now) -> bool
230
+ private def self.__covers: (Fraction fraction, Draw draw) -> bool
231
+
232
+ # Private runtime helpers. `key` is the checked name as a frozen String.
233
+ private def self.arm_at: (String key, Experiment experiment, untyped payload, Integer now) -> (arming | :full)
234
+ private def self.disarmed: (disarming answer, untyped removed) -> disarming
235
+ private def self.replaced: (arming answer, Experiment experiment, untyped previous, bool same_payload) -> arming
236
+ private def self.decide_at: (String key, Integer now, Draw drawn) -> [Inject | :pass, untyped]
237
+ private def self.retire: (Integer now) -> void
238
+ # `[block's answer]` for a reading against the clock still installed once
239
+ # the lock is held, nil after READINGS attempts.
240
+ private def self.locked_reading: [T] () { (Integer now) -> T } -> [T]?
241
+ # Raises TypeError for a non-Integer reading, RangeError for a negative one.
242
+ private def self.checked_reading: (_Clock source, Integer now) -> nil
243
+ # Raises TypeError for a non-Symbol/String name, RangeError for an empty or
244
+ # illegible one.
245
+ private def self.legible: (Symbol | String name) -> nil
246
+ private def self.named: (Symbol | String name) -> String
247
+ private def self.fraction_of: (Fraction | Numeric share) -> Fraction
248
+ private def self.checked_fault: (fault fault) -> nil
249
+ private def self.span_of: (Integer expires_in) -> Integer
250
+ private def self.perform: (Symbol | String name, fault fault, untyped payload) { () -> untyped } -> untyped
251
+ private def self.stall: (Integer delay_ns) -> void
146
252
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rogue_machines
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.5.0
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Abdelkader Boudih
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-06 00:00:00.000000000 Z
11
+ date: 2026-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deadline_machines
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.0
19
+ version: 0.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.0
26
+ version: 0.2.0
27
27
  description: 'Fault injection for chaos engineering: arms a named experiment that
28
28
  makes a dependency fail, stall or lie for a share of calls, so the breakers, retries
29
29
  and budgets around it can be shown to work. Bound to Ruby from the zero-dependency
@@ -40,6 +40,7 @@ files:
40
40
  - README.md
41
41
  - ext/rogue_machines_native/extconf.rb
42
42
  - lib/rogue_machines.rb
43
+ - lib/rogue_machines/runtime.rb
43
44
  - lib/rogue_machines/version.rb
44
45
  - lib/rogue_machines_native/rogue_machines_native.so
45
46
  - sig/rogue_machines.rbs