bitfab 0.20.0 → 0.20.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9624757032370e1e318121cabcf2bfa984c7bcdcd07c9ecd5dcee449fef57a7c
4
- data.tar.gz: c3925bbae804c16d21c3f373ec6cde4de340ee645fc6423505fc0b5d5f5e638e
3
+ metadata.gz: cd571926bd40dc39f337e87f9977bfb0fe3219c21532dc1cf7be382c175a4559
4
+ data.tar.gz: 17ff724ae1a42f97fa6eae82c97404de8dc9cef738a18674d76da48ba9ea762d
5
5
  SHA512:
6
- metadata.gz: d2c33cd4a3432d79703685f00bb8c8278e2bebbd694b3a695f1dee646680a5af11370f233635f04590eeb0d5cedee850c496b40bee2fc176c34cf22fb721cde8
7
- data.tar.gz: c64be06a07ca8ea807bca23e0f96acb15e1647945b33c3ea731f10c0b52759870b88637d86b680aee07caac7836e3818946f2fb85f0979d83b3ea89ef8ea1704
6
+ metadata.gz: 012d3433d2d59200c812557a95b4f2b7cb8d93d7885d9495f59b7e21d89a892ffcc3c0bb83200f4c9f324320d5a1153f4c59bd2facac2dc1924174a7f184d81f
7
+ data.tar.gz: 69aaffc897238560ebecf6fedbd81509eda58fd082126107585a913cc74a025456a32111356902251a0c5b3439ff2b84ef7ea5aac4325a10e531c93a5d460334
data/lib/bitfab/replay.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "constants"
4
4
  require_relative "serialize"
5
+ require_relative "traceable"
5
6
 
6
7
  module Bitfab
7
8
  # Replay mock strategies. Mirrors the Python and TypeScript SDKs.
@@ -117,6 +118,21 @@ module Bitfab
117
118
  "determines how many traces replay."
118
119
  end
119
120
 
121
+ # Reject a trace_function_key that contradicts the method's declared key.
122
+ # replay() fetches historical traces by trace_function_key but records the
123
+ # replayed spans under the method's own bitfab_span key (via send below),
124
+ # so a mismatch produces an incoherent test run (traces fetched for one
125
+ # function, recorded under another). Only fires when the method's key is
126
+ # introspectable; an untraced method falls through to the persistence
127
+ # check in complete_replay. Mirrors the TypeScript/Python SDKs.
128
+ declared_key = Traceable.trace_function_key_for(receiver, method_name)
129
+ if declared_key && declared_key != trace_function_key
130
+ raise ArgumentError,
131
+ "Method #{method_name} is traced under trace function key '#{declared_key}' but replay was " \
132
+ "called with '#{trace_function_key}'. Pass trace_function_key: '#{declared_key}' to replay it, " \
133
+ "or point at the method traced under '#{trace_function_key}'."
134
+ end
135
+
120
136
  http_client = client.instance_variable_get(:@http_client)
121
137
 
122
138
  # limit is meaningless with explicit trace_ids (the ID list determines
@@ -69,9 +69,43 @@ module Bitfab
69
69
  end
70
70
  end
71
71
 
72
+ wrapper.instance_variable_set(:@bitfab_span_method, method_name_str)
73
+ wrapper.instance_variable_set(:@bitfab_span_key, trace_function_key)
72
74
  klass.prepend(wrapper)
73
75
  end
74
76
 
77
+ # Resolve the trace function key a traced method records spans under, or
78
+ # nil if the method carries no Bitfab span wrapper. Walks the receiver's
79
+ # ancestor chain for the wrapper module that bitfab_span / Traceable.wrap
80
+ # prepended. Instances resolve via the class. A Class/Module receiver
81
+ # resolves either way: singleton-class ancestors first (class/module
82
+ # methods wrapped on the singleton class), then the class's own ancestors
83
+ # (methods whose wrapper was prepended onto the class itself), so a
84
+ # class-method replay is guarded regardless of which surface carries the
85
+ # wrapper. Singleton-first keeps the method actually dispatched by
86
+ # `receiver.send` (a class method shadows a same-named instance wrapper).
87
+ #
88
+ # replay() uses this to reject a trace_function_key that contradicts the
89
+ # method's declared key: a mismatch fetches one function's historical
90
+ # traces but re-records the replay under the method's own key, producing
91
+ # an incoherent test run. Mirrors the TypeScript and Python SDKs, which
92
+ # throw on the same key mismatch.
93
+ def self.trace_function_key_for(receiver, method_name)
94
+ name = method_name.to_s
95
+ ancestors = if receiver.is_a?(Module)
96
+ receiver.singleton_class.ancestors + receiver.ancestors
97
+ else
98
+ receiver.class.ancestors
99
+ end
100
+ ancestors.each do |mod|
101
+ next unless mod.instance_variable_defined?(:@bitfab_span_method)
102
+ next unless mod.instance_variable_get(:@bitfab_span_method) == name
103
+
104
+ return mod.instance_variable_get(:@bitfab_span_key)
105
+ end
106
+ nil
107
+ end
108
+
75
109
  module ClassMethods
76
110
  # Set the trace function key for this class.
77
111
  # All spans declared in this class will be grouped under this key.
@@ -152,6 +186,8 @@ module Bitfab
152
186
  end
153
187
  end
154
188
 
189
+ wrapper.instance_variable_set(:@bitfab_span_method, method_name_str)
190
+ wrapper.instance_variable_set(:@bitfab_span_key, trace_function_key)
155
191
  prepend(wrapper)
156
192
  end
157
193
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bitfab
4
- VERSION = "0.20.0"
4
+ VERSION = "0.20.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitfab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.20.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harvest Team