bitfab 0.74.0 → 0.74.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: 3c5d6ffd1ec89aa3d5e4bd2cbb3a261d5e4007065c3481a4f33898255ab34d37
4
- data.tar.gz: 0c662b87145b14ce88ab61aa62e28c8e473de63d42a8335c687df9586353fb44
3
+ metadata.gz: b1def1a5df451e3c7b1afa22248c2c54b2b135f5712eb19a989b41209a8c5622
4
+ data.tar.gz: 16a9741bbda86c16c78aafec91688d962c9ae58e9b032681a07d7b633497c258
5
5
  SHA512:
6
- metadata.gz: 3ff0a584aa0928967b16865aa5e107b895180cde0ea03fa4146f0bff1ebf0b53ba869310ce6c9658bec06583e35c11b897a5e996816f619389b1a8019c8f7909
7
- data.tar.gz: d5d1783b9c5af65a670757dd445ea937b339a6faeadc42b564f78e143e392bc359f394bfbc586d613df9f3a20457f345f71e842bc89497fed8c9caba1eb20f08
6
+ metadata.gz: 2be36b8b49c5b7c6d6525364c6f10a24d696eb40d8dae2343bdf1b1017e2f2fd47e6c52d8cdf200b4f1cf22a75fdd0ea41bf217e533090a9a42fa725ee7018a8
7
+ data.tar.gz: 5a4fe53c914d211714bbd2a31d44af37743edf1007f4599f52c6dfcce9e3bf970d90778588b1ee17267394017ed554752882f63d45a06fa7ce693786b97dc152
@@ -4,9 +4,11 @@ require "uri"
4
4
 
5
5
  module Bitfab
6
6
  class Traces
7
+ CODE_DRAFT_SAVE_TIMEOUT_SECONDS = 300
8
+ CODED_KINDS = ["code", "hybrid", :code, :hybrid].freeze
7
9
  CATEGORY_ID_KEYS = ["category_id", :category_id].freeze
8
10
  DEPRECATED_CATEGORY_ID_KEYS = ["category_assertion_id", :category_assertion_id].freeze
9
- private_constant :CATEGORY_ID_KEYS, :DEPRECATED_CATEGORY_ID_KEYS
11
+ private_constant :CODE_DRAFT_SAVE_TIMEOUT_SECONDS, :CODED_KINDS, :CATEGORY_ID_KEYS, :DEPRECATED_CATEGORY_ID_KEYS
10
12
 
11
13
  def initialize(http_client)
12
14
  @http_client = http_client
@@ -44,6 +46,17 @@ module Bitfab
44
46
  # pass "kind" => "judge" to remove the code. Returned assertions carry
45
47
  # "kind", "code", and "codeBrokenReason".
46
48
  #
49
+ # Send "kind" => "code" or "hybrid" without "code", on an assertion that
50
+ # has no code yet, to have Bitfab write the code: the text is checked by
51
+ # the guided rewrite (unless skipped), code of that kind is written and run
52
+ # on the trace, and the save waits for both, so that entry's "rewrite" is
53
+ # already final. Its returned "codeDraft" hash says what happened:
54
+ # "requestedKind", "status" ("written", or "not_written" when no working
55
+ # code could be written and the assertion was saved as "judge" without
56
+ # code), and "reason" (why not, or nil). Every other entry's "codeDraft"
57
+ # is nil. At most 10 assertions per save may ask for code this way, and a
58
+ # save that asks for any waits up to five minutes.
59
+ #
47
60
  # By default, after the save, Bitfab checks each assertion's text against its
48
61
  # trace. When the text bundles two claims, adds a condition, points at a
49
62
  # value instead of stating it, names an id from the recorded run, or cannot
@@ -77,7 +90,8 @@ module Bitfab
77
90
  "updates" => updates.map { |update| with_new_category_key(update) },
78
91
  "source" => source,
79
92
  "guidedRewrite" => !skip_guided_rewrite
80
- }
93
+ },
94
+ timeout: save_timeout(updates)
81
95
  )["assertions"]
82
96
  saved.is_a?(Array) ? saved.map { |assertion| with_both_category_keys(assertion) } : saved
83
97
  end
@@ -88,6 +102,18 @@ module Bitfab
88
102
 
89
103
  private
90
104
 
105
+ def save_timeout(updates)
106
+ asks = updates.any? do |update|
107
+ (update["assertions"] || update[:assertions] || []).any? { |assertion| asks_bitfab_to_write_code?(assertion) }
108
+ end
109
+ asks ? CODE_DRAFT_SAVE_TIMEOUT_SECONDS : nil
110
+ end
111
+
112
+ def asks_bitfab_to_write_code?(assertion)
113
+ kind = assertion["kind"] || assertion[:kind]
114
+ CODED_KINDS.include?(kind) && !assertion.key?("code") && !assertion.key?(:code)
115
+ end
116
+
91
117
  def assertions_path(trace_id, suffix = "")
92
118
  "/api/sdk/traces/#{URI.encode_www_form_component(trace_id).gsub("+", "%20")}/assertions#{suffix}"
93
119
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bitfab
4
- VERSION = "0.74.0"
4
+ VERSION = "0.74.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.74.0
4
+ version: 0.74.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harvest Team