bitfab 0.20.1 → 0.20.2

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: cd571926bd40dc39f337e87f9977bfb0fe3219c21532dc1cf7be382c175a4559
4
- data.tar.gz: 17ff724ae1a42f97fa6eae82c97404de8dc9cef738a18674d76da48ba9ea762d
3
+ metadata.gz: d2428cc39dcd97d154e36ba9792628478e86a4b4dde5101c79d37ebb1635378f
4
+ data.tar.gz: effa0dba40674696ad3d9155615d9d9e2e40a3fe7f9aed9c8ee97516985e13c6
5
5
  SHA512:
6
- metadata.gz: 012d3433d2d59200c812557a95b4f2b7cb8d93d7885d9495f59b7e21d89a892ffcc3c0bb83200f4c9f324320d5a1153f4c59bd2facac2dc1924174a7f184d81f
7
- data.tar.gz: 69aaffc897238560ebecf6fedbd81509eda58fd082126107585a913cc74a025456a32111356902251a0c5b3439ff2b84ef7ea5aac4325a10e531c93a5d460334
6
+ metadata.gz: 5f172f0178829a08315ae1caf3de6ff4a22389b2f83dbf449721ca53ca3a466580af00c15bd5279dffc2c9d074aee2afd0e157733f9257987460ef8d101350c9
7
+ data.tar.gz: 9c6af19d4ebac35d13280aeaa89ac6104cbff3020e24813e292e4170c6524016a0df943025f3ced5510345c863e4b86f9f027fe281912e99a6438f863dde9d28
data/lib/bitfab/replay.rb CHANGED
@@ -170,6 +170,10 @@ module Bitfab
170
170
  # loudly.
171
171
  complete_response = http_client.complete_replay(test_run_id)
172
172
  trace_id_map = complete_response&.dig("traceIds")
173
+ # Per-replay-trace token usage keyed by server trace id: the REPLAYED
174
+ # run's tokens (span-aggregated server-side), used below to fill each
175
+ # item's :tokens.
176
+ replay_tokens = complete_response&.dig("tokens") || {}
173
177
 
174
178
  if trace_id_map.nil?
175
179
  # Older servers don't return the mapping. Preserve the legacy
@@ -202,6 +206,9 @@ module Bitfab
202
206
  completed_count += 1
203
207
  missing << item[:trace_id] if mapped.nil?
204
208
  end
209
+ # Pull this item's replayed-run tokens by its server trace id, before
210
+ # :trace_id is overwritten with that id below.
211
+ item[:tokens] = normalize_tokens(replay_tokens[mapped]) if mapped
205
212
  item[:trace_id] = mapped
206
213
  end
207
214
  if missing.any?
@@ -386,27 +393,34 @@ module Bitfab
386
393
  }
387
394
  end
388
395
 
389
- # Pull durationMs / tokens / model from the start-replay server item.
390
- # Normalizes to symbol-keyed tokens hash and nil-safe defaults so older
391
- # servers without these fields still produce a consistent shape.
396
+ # Pull durationMs / model from the start-replay server item. Nil-safe
397
+ # defaults so older servers without these fields still produce a consistent
398
+ # shape. Tokens are intentionally NOT read from the start item (it carries
399
+ # the ORIGINAL trace's tokens); the replayed run's tokens are filled in by
400
+ # run() from the complete-replay response once spans are aggregated
401
+ # server-side, and stay nil here and on older servers.
392
402
  def extract_server_item_metrics(server_item)
393
- raw_tokens = server_item["tokens"]
394
- tokens = if raw_tokens.is_a?(Hash)
395
- {
396
- input: raw_tokens["input"],
397
- output: raw_tokens["output"],
398
- cached: raw_tokens["cached"],
399
- total: raw_tokens["total"]
400
- }
401
- end
402
-
403
403
  {
404
404
  duration_ms: server_item["durationMs"],
405
- tokens:,
405
+ tokens: nil,
406
406
  model: server_item["model"]
407
407
  }
408
408
  end
409
409
 
410
+ # Normalize a complete-replay tokens hash (string-keyed JSON) into the
411
+ # symbol-keyed shape the replay item exposes. Nil when the server reported
412
+ # no token data for this trace.
413
+ def normalize_tokens(raw_tokens)
414
+ return nil unless raw_tokens.is_a?(Hash)
415
+
416
+ {
417
+ input: raw_tokens["input"],
418
+ output: raw_tokens["output"],
419
+ cached: raw_tokens["cached"],
420
+ total: raw_tokens["total"]
421
+ }
422
+ end
423
+
410
424
  # Execute a single replay item: deserialize inputs, call method with replay context.
411
425
  def execute_item(item, receiver, method_name, test_run_id, input_source_span_id = nil, metrics = {},
412
426
  input_source_trace_id: nil, mock_strategy: "none", mock_tree: nil, adapt_inputs: nil, adapt_ctx: nil,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bitfab
4
- VERSION = "0.20.1"
4
+ VERSION = "0.20.2"
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.1
4
+ version: 0.20.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harvest Team