@voxgig/sdkgen 4.49.1 → 4.51.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.
Files changed (218) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/package.json +1 -1
  3. package/project/.sdk/model/feature/cache.aontu +6 -4
  4. package/project/.sdk/model/target/lua.aontu +6 -0
  5. package/project/.sdk/src/cmp/c/Config_c.ts +3 -134
  6. package/project/.sdk/src/cmp/c/TestClean_c.ts +14 -0
  7. package/project/.sdk/src/cmp/clojure/TestClean_clojure.ts +10 -5
  8. package/project/.sdk/src/cmp/cpp/TestClean_cpp.ts +13 -0
  9. package/project/.sdk/src/cmp/csharp/TestClean_csharp.ts +9 -0
  10. package/project/.sdk/src/cmp/elixir/TestClean_elixir.ts +11 -3
  11. package/project/.sdk/src/cmp/go/TestClean_go.ts +39 -3
  12. package/project/.sdk/src/cmp/java/TestClean_java.ts +8 -0
  13. package/project/.sdk/src/cmp/js/TestClean_js.ts +13 -5
  14. package/project/.sdk/src/cmp/kotlin/TestClean_kotlin.ts +22 -0
  15. package/project/.sdk/src/cmp/lua/TestClean_lua.ts +12 -3
  16. package/project/.sdk/src/cmp/ocaml/TestClean_ocaml.ts +18 -4
  17. package/project/.sdk/src/cmp/perl/TestClean_perl.ts +12 -3
  18. package/project/.sdk/src/cmp/php/TestClean_php.ts +10 -3
  19. package/project/.sdk/src/cmp/py/TestClean_py.ts +10 -3
  20. package/project/.sdk/src/cmp/rb/TestClean_rb.ts +10 -3
  21. package/project/.sdk/src/cmp/rust/TestClean_rust.ts +10 -0
  22. package/project/.sdk/src/cmp/scala/TestClean_scala.ts +34 -0
  23. package/project/.sdk/src/cmp/swift/TestClean_swift.ts +20 -10
  24. package/project/.sdk/src/cmp/ts/TestClean_ts.ts +13 -5
  25. package/project/.sdk/src/cmp/zig/TestClean_zig.ts +12 -0
  26. package/project/.sdk/tm/c/core/context.c +1 -0
  27. package/project/.sdk/tm/c/core/sdk.h +7 -4
  28. package/project/.sdk/tm/c/feature/cache.c +243 -13
  29. package/project/.sdk/tm/c/feature/debug.c +1 -0
  30. package/project/.sdk/tm/c/feature/secrets.c +27 -38
  31. package/project/.sdk/tm/c/feature/telemetry.c +1 -0
  32. package/project/.sdk/tm/c/tests/feature_test.c +142 -0
  33. package/project/.sdk/tm/c/utility/clean.c +26 -33
  34. package/project/.sdk/tm/c/utility/make_options.c +9 -8
  35. package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +14 -11
  36. package/project/.sdk/tm/clojure/src/sdk/client.clj +3 -1
  37. package/project/.sdk/tm/clojure/src/sdk/core.clj +19 -11
  38. package/project/.sdk/tm/clojure/src/sdk/features.clj +83 -10
  39. package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +47 -0
  40. package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +1 -0
  41. package/project/.sdk/tm/cpp/Makefile +5 -0
  42. package/project/.sdk/tm/cpp/core/types.hpp +11 -4
  43. package/project/.sdk/tm/cpp/feature/audit.hpp +6 -7
  44. package/project/.sdk/tm/cpp/feature/cache.hpp +188 -9
  45. package/project/.sdk/tm/cpp/feature/debug.hpp +1 -0
  46. package/project/.sdk/tm/cpp/feature/secrets.hpp +12 -0
  47. package/project/.sdk/tm/cpp/feature/telemetry.hpp +1 -0
  48. package/project/.sdk/tm/cpp/test/feature_test.cpp +128 -0
  49. package/project/.sdk/tm/cpp/utility/pipeline.hpp +9 -7
  50. package/project/.sdk/tm/csharp/core/Context.cs +4 -0
  51. package/project/.sdk/tm/csharp/feature/CacheFeature.cs +126 -12
  52. package/project/.sdk/tm/csharp/feature/DebugFeature.cs +1 -0
  53. package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +9 -27
  54. package/project/.sdk/tm/csharp/feature/TelemetryFeature.cs +1 -0
  55. package/project/.sdk/tm/csharp/test/FeatureTest.cs +101 -0
  56. package/project/.sdk/tm/csharp/utility/Clean.cs +5 -10
  57. package/project/.sdk/tm/csharp/utility/Fetcher.cs +7 -1
  58. package/project/.sdk/tm/csharp/utility/MakeOptions.cs +5 -12
  59. package/project/.sdk/tm/elixir/lib/projectname/context.ex +2 -0
  60. package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +146 -30
  61. package/project/.sdk/tm/elixir/lib/projectname/feature/debug.ex +1 -0
  62. package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +10 -56
  63. package/project/.sdk/tm/elixir/lib/projectname/feature/telemetry.ex +1 -0
  64. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +18 -12
  65. package/project/.sdk/tm/elixir/test/feature_test.exs +84 -0
  66. package/project/.sdk/tm/go/core/context.go +6 -0
  67. package/project/.sdk/tm/go/feature/cache_feature.go +131 -4
  68. package/project/.sdk/tm/go/feature/debug_feature.go +3 -2
  69. package/project/.sdk/tm/go/feature/secrets_feature.go +17 -71
  70. package/project/.sdk/tm/go/feature/telemetry_feature.go +5 -4
  71. package/project/.sdk/tm/go/test/feature_corpus_test.go +150 -2
  72. package/project/.sdk/tm/go/test/feature_test.go +101 -0
  73. package/project/.sdk/tm/go/utility/clean.go +5 -7
  74. package/project/.sdk/tm/go/utility/fetcher.go +11 -0
  75. package/project/.sdk/tm/go/utility/make_options.go +5 -7
  76. package/project/.sdk/tm/java/core/Context.java +9 -0
  77. package/project/.sdk/tm/java/feature/CacheFeature.java +123 -17
  78. package/project/.sdk/tm/java/feature/DebugFeature.java +1 -0
  79. package/project/.sdk/tm/java/feature/SecretsFeature.java +9 -92
  80. package/project/.sdk/tm/java/feature/TelemetryFeature.java +1 -0
  81. package/project/.sdk/tm/java/test/FeatureCorpusTest.java +141 -2
  82. package/project/.sdk/tm/java/test/FeatureTest.java +88 -0
  83. package/project/.sdk/tm/java/utility/Clean.java +6 -10
  84. package/project/.sdk/tm/java/utility/Fetcher.java +5 -1
  85. package/project/.sdk/tm/java/utility/MakeOptions.java +3 -1
  86. package/project/.sdk/tm/js/src/Context.js +4 -0
  87. package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +118 -11
  88. package/project/.sdk/tm/js/src/feature/cost/CostFeature.js +3 -2
  89. package/project/.sdk/tm/js/src/feature/debug/DebugFeature.js +1 -0
  90. package/project/.sdk/tm/js/src/feature/metrics/MetricsFeature.js +1 -1
  91. package/project/.sdk/tm/js/src/feature/paging/PagingFeature.js +4 -4
  92. package/project/.sdk/tm/js/src/feature/rbac/RbacFeature.js +4 -4
  93. package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +16 -6
  94. package/project/.sdk/tm/js/src/feature/telemetry/TelemetryFeature.js +1 -0
  95. package/project/.sdk/tm/js/src/feature/validate/ValidateFeature.js +2 -1
  96. package/project/.sdk/tm/js/src/utility/CleanUtility.js +1 -1
  97. package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +6 -6
  98. package/project/.sdk/tm/js/test/feature/Corpus.test.js +100 -2
  99. package/project/.sdk/tm/js/test/feature/harness.js +3 -3
  100. package/project/.sdk/tm/js/test/feature.test.js +17 -0
  101. package/project/.sdk/tm/js/test/pipeline.test.js +1 -1
  102. package/project/.sdk/tm/kotlin/core/Context.kt +3 -0
  103. package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +102 -7
  104. package/project/.sdk/tm/kotlin/feature/DebugFeature.kt +1 -0
  105. package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +10 -20
  106. package/project/.sdk/tm/kotlin/feature/TelemetryFeature.kt +1 -0
  107. package/project/.sdk/tm/kotlin/test/FeatureTest.kt +79 -0
  108. package/project/.sdk/tm/kotlin/utility/CoreUtil.kt +5 -5
  109. package/project/.sdk/tm/kotlin/utility/Fetcher.kt +4 -0
  110. package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +3 -1
  111. package/project/.sdk/tm/lua/core/context.lua +6 -0
  112. package/project/.sdk/tm/lua/feature/cache_feature.lua +212 -15
  113. package/project/.sdk/tm/lua/feature/debug_feature.lua +1 -0
  114. package/project/.sdk/tm/lua/feature/secrets_feature.lua +15 -80
  115. package/project/.sdk/tm/lua/feature/telemetry_feature.lua +1 -0
  116. package/project/.sdk/tm/lua/test/feature_test.lua +108 -0
  117. package/project/.sdk/tm/lua/utility/clean.lua +6 -9
  118. package/project/.sdk/tm/lua/utility/fetcher.lua +9 -0
  119. package/project/.sdk/tm/lua/utility/make_options.lua +5 -5
  120. package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +21 -6
  121. package/project/.sdk/tm/ocaml/sdk_features.ml +108 -8
  122. package/project/.sdk/tm/ocaml/sdk_runtime.ml +13 -10
  123. package/project/.sdk/tm/ocaml/sdk_types.ml +2 -0
  124. package/project/.sdk/tm/ocaml/test/t_feature.ml +51 -1
  125. package/project/.sdk/tm/perl/core/context.pm +3 -0
  126. package/project/.sdk/tm/perl/feature/audit_feature.pm +4 -7
  127. package/project/.sdk/tm/perl/feature/cache_feature.pm +111 -15
  128. package/project/.sdk/tm/perl/feature/debug_feature.pm +1 -0
  129. package/project/.sdk/tm/perl/feature/secrets_feature.pm +13 -18
  130. package/project/.sdk/tm/perl/feature/telemetry_feature.pm +1 -0
  131. package/project/.sdk/tm/perl/t/feature.t +86 -0
  132. package/project/.sdk/tm/perl/t/feature_corpus.t +80 -4
  133. package/project/.sdk/tm/perl/utility/clean.pm +6 -8
  134. package/project/.sdk/tm/perl/utility/fetcher.pm +4 -0
  135. package/project/.sdk/tm/perl/utility/make_options.pm +5 -5
  136. package/project/.sdk/tm/php/core/Context.php +4 -0
  137. package/project/.sdk/tm/php/feature/CacheFeature.php +98 -13
  138. package/project/.sdk/tm/php/feature/DebugFeature.php +1 -0
  139. package/project/.sdk/tm/php/feature/SecretsFeature.php +18 -15
  140. package/project/.sdk/tm/php/feature/TelemetryFeature.php +1 -0
  141. package/project/.sdk/tm/php/test/FeatureCorpusTest.php +113 -3
  142. package/project/.sdk/tm/php/test/FeatureTest.php +90 -0
  143. package/project/.sdk/tm/php/utility/Clean.php +3 -10
  144. package/project/.sdk/tm/php/utility/Fetcher.php +8 -3
  145. package/project/.sdk/tm/php/utility/MakeOptions.php +5 -7
  146. package/project/.sdk/tm/py/pkg/core/context.py +4 -0
  147. package/project/.sdk/tm/py/pkg/feature/cache_feature.py +79 -13
  148. package/project/.sdk/tm/py/pkg/feature/debug_feature.py +1 -0
  149. package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +15 -66
  150. package/project/.sdk/tm/py/pkg/feature/telemetry_feature.py +1 -0
  151. package/project/.sdk/tm/py/pkg/utility/clean.py +4 -10
  152. package/project/.sdk/tm/py/pkg/utility/make_options.py +8 -9
  153. package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +23 -9
  154. package/project/.sdk/tm/py/test/test_feature.py +73 -0
  155. package/project/.sdk/tm/py/test/test_feature_corpus.py +88 -3
  156. package/project/.sdk/tm/rb/core/context.rb +4 -1
  157. package/project/.sdk/tm/rb/feature/audit_feature.rb +6 -5
  158. package/project/.sdk/tm/rb/feature/cache_feature.rb +75 -11
  159. package/project/.sdk/tm/rb/feature/debug_feature.rb +1 -0
  160. package/project/.sdk/tm/rb/feature/secrets_feature.rb +9 -64
  161. package/project/.sdk/tm/rb/feature/telemetry_feature.rb +1 -0
  162. package/project/.sdk/tm/rb/test/feature_corpus_test.rb +85 -3
  163. package/project/.sdk/tm/rb/test/feature_test.rb +93 -0
  164. package/project/.sdk/tm/rb/utility/clean.rb +6 -7
  165. package/project/.sdk/tm/rb/utility/fetcher.rb +6 -0
  166. package/project/.sdk/tm/rb/utility/make_options.rb +5 -5
  167. package/project/.sdk/tm/rust/core/context.rs +8 -0
  168. package/project/.sdk/tm/rust/feature/cache.rs +120 -3
  169. package/project/.sdk/tm/rust/feature/debug.rs +1 -0
  170. package/project/.sdk/tm/rust/feature/secrets.rs +36 -98
  171. package/project/.sdk/tm/rust/feature/telemetry.rs +1 -0
  172. package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +3 -3
  173. package/project/.sdk/tm/rust/tests/feature_test.rs +141 -0
  174. package/project/.sdk/tm/rust/utility/clean.rs +35 -43
  175. package/project/.sdk/tm/rust/utility/fetcher.rs +6 -0
  176. package/project/.sdk/tm/rust/utility/make_options.rs +8 -11
  177. package/project/.sdk/tm/scala/core/Context.scala +4 -0
  178. package/project/.sdk/tm/scala/feature/CacheFeature.scala +117 -11
  179. package/project/.sdk/tm/scala/feature/DebugFeature.scala +1 -0
  180. package/project/.sdk/tm/scala/feature/SecretsFeature.scala +11 -24
  181. package/project/.sdk/tm/scala/feature/TelemetryFeature.scala +1 -0
  182. package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +52 -1
  183. package/project/.sdk/tm/scala/utility/Fetcher.scala +5 -0
  184. package/project/.sdk/tm/scala/utility/Make.scala +3 -1
  185. package/project/.sdk/tm/scala/utility/Misc.scala +5 -8
  186. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Context.swift +3 -0
  187. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +122 -11
  188. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/DebugFeature.swift +1 -0
  189. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +9 -13
  190. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TelemetryFeature.swift +1 -0
  191. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +4 -0
  192. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/MakeOptions.swift +5 -4
  193. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/ResultUtil.swift +4 -5
  194. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +79 -0
  195. package/project/.sdk/tm/ts/src/Context.ts +4 -0
  196. package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +115 -4
  197. package/project/.sdk/tm/ts/src/feature/cost/CostFeature.ts +3 -2
  198. package/project/.sdk/tm/ts/src/feature/debug/DebugFeature.ts +1 -0
  199. package/project/.sdk/tm/ts/src/feature/metrics/MetricsFeature.ts +1 -1
  200. package/project/.sdk/tm/ts/src/feature/paging/PagingFeature.ts +4 -4
  201. package/project/.sdk/tm/ts/src/feature/rbac/RbacFeature.ts +4 -4
  202. package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +14 -2
  203. package/project/.sdk/tm/ts/src/feature/telemetry/TelemetryFeature.ts +1 -0
  204. package/project/.sdk/tm/ts/src/feature/validate/ValidateFeature.ts +2 -1
  205. package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +1 -1
  206. package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +6 -6
  207. package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +101 -2
  208. package/project/.sdk/tm/ts/test/feature/harness.ts +3 -3
  209. package/project/.sdk/tm/ts/test/feature.test.ts +17 -0
  210. package/project/.sdk/tm/ts/test/pipeline.test.ts +1 -1
  211. package/project/.sdk/tm/zig/core/context.zig +5 -0
  212. package/project/.sdk/tm/zig/core/utility.zig +11 -9
  213. package/project/.sdk/tm/zig/feature/cache.zig +144 -13
  214. package/project/.sdk/tm/zig/feature/debug.zig +1 -0
  215. package/project/.sdk/tm/zig/feature/secrets.zig +6 -1
  216. package/project/.sdk/tm/zig/feature/telemetry.zig +1 -0
  217. package/project/.sdk/tm/zig/test/feature_test.zig +100 -0
  218. package/project/sdkgen-package.json +1 -1
@@ -125,8 +125,24 @@ class FeatureCorpusTest < Minitest::Test
125
125
  out.sort_by { |o| [safe.fetch(o["op"], 2), o["key"]] }
126
126
  end
127
127
 
128
- def invoke(client, op, ctrl)
129
- client.public_send(op["accessor"]).public_send(op["op"], {}, ctrl)
128
+ def invoke(client, op, ctrl, args = nil)
129
+ client.public_send(op["accessor"]).public_send(op["op"], (args || {}).dup, ctrl)
130
+ end
131
+
132
+ ITEM_ARGS = { "id" => "corpus-item" }.freeze
133
+
134
+ # A write of one entity (#ITEM) that completes when driven with ITEM_ARGS.
135
+ def usable_item(accessor)
136
+ candidates(build_client({})).each do |cand|
137
+ next unless cand["accessor"] == accessor && %w[update patch remove].include?(cand["op"])
138
+ begin
139
+ invoke(build_client({}), cand, {}, ITEM_ARGS)
140
+ rescue StandardError
141
+ next
142
+ end
143
+ return cand
144
+ end
145
+ nil
130
146
  end
131
147
 
132
148
  # Pick operations by DRIVING them: an op is usable when it completes
@@ -147,6 +163,48 @@ class FeatureCorpusTest < Minitest::Test
147
163
  picked
148
164
  end
149
165
 
166
+ READ_OPS = ["list", "load"].freeze
167
+ WRITE_OPS = ["create", "update", "patch", "remove"].freeze
168
+
169
+ # A read and a write of one entity (#READ, #WRITE), each driven as
170
+ # usable_ops drives an op.
171
+ def usable_pair
172
+ found = {}
173
+ candidates(build_client({})).each do |cand|
174
+ role = READ_OPS.include?(cand["op"]) ? "read" : (WRITE_OPS.include?(cand["op"]) ? "write" : nil)
175
+ seen = (found[cand["accessor"]] ||= {})
176
+ next if role.nil? || seen.key?(role)
177
+ begin
178
+ invoke(build_client({}), cand, {})
179
+ rescue StandardError
180
+ next
181
+ end
182
+ seen[role] = cand
183
+ return seen if seen.key?("read") && seen.key?("write")
184
+ end
185
+ nil
186
+ end
187
+
188
+ # One step: it may wait before its call, may add request headers for its
189
+ # call, and may pass `args` as the operation's first argument.
190
+ def step_call(client, op, step, ctrl)
191
+ sleep(step["wait"] / 1000.0) unless step["wait"].nil?
192
+ return invoke(client, op, ctrl, step["args"]) if step["headers"].nil?
193
+ options = client.options
194
+ had = options.key?("headers")
195
+ prior = options["headers"]
196
+ options["headers"] = (prior || {}).merge(step["headers"])
197
+ begin
198
+ invoke(client, op, ctrl, step["args"])
199
+ ensure
200
+ if had
201
+ options["headers"] = prior
202
+ else
203
+ options.delete("headers")
204
+ end
205
+ end
206
+ end
207
+
150
208
  # Replace #OPn throughout a case, keys included.
151
209
  def resolve(node, tokens)
152
210
  case node
@@ -286,6 +344,11 @@ class FeatureCorpusTest < Minitest::Test
286
344
 
287
345
  ops = usable_ops(2)
288
346
  by_key = ops.each_with_object({}) { |o, h| h[o["key"]] = o }
347
+ pair = usable_pair
348
+ pair&.each_value { |o| by_key[o["key"]] = o }
349
+ item = pair && usable_item(pair["read"]["accessor"])
350
+ by_key[item["key"]] = item unless item.nil?
351
+ other = pair && ops.find { |o| o["accessor"] != pair["read"]["accessor"] }
289
352
 
290
353
  ran = 0
291
354
  cases.each do |raw|
@@ -295,6 +358,19 @@ class FeatureCorpusTest < Minitest::Test
295
358
  next
296
359
  end
297
360
 
361
+ paired = JSON.generate(raw).match?(/#(READ|WRITE|ITEM|OTHER)\b/)
362
+ if paired && pair.nil?
363
+ puts "skip \"#{raw['name']}\": needs a read and a write of one entity, this SDK offers none"
364
+ next
365
+ end
366
+ lacking = [["#ITEM", item], ["#OTHER", other]].find do |tok, op|
367
+ paired && op.nil? && JSON.generate(raw).match?(/#{tok}\b/)
368
+ end
369
+ unless lacking.nil?
370
+ puts "skip \"#{raw['name']}\": needs #{lacking[0]}, which this SDK cannot drive"
371
+ next
372
+ end
373
+
298
374
  missing = missing_feature(raw, have)
299
375
  unless missing.nil?
300
376
  puts "skip \"#{raw['name']}\": needs the #{missing} feature, " \
@@ -304,6 +380,12 @@ class FeatureCorpusTest < Minitest::Test
304
380
 
305
381
  tokens = {}
306
382
  need.times { |i| tokens["#OP#{i + 1}"] = ops[i]["key"] }
383
+ if paired
384
+ tokens["#READ"] = pair["read"]["key"]
385
+ tokens["#WRITE"] = pair["write"]["key"]
386
+ tokens["#ITEM"] = item["key"] unless item.nil?
387
+ tokens["#OTHER"] = other["key"] unless other.nil?
388
+ end
307
389
  kase = resolve(raw, tokens)
308
390
  label = kase["name"].to_s
309
391
  ran += 1
@@ -319,7 +401,7 @@ class FeatureCorpusTest < Minitest::Test
319
401
  wanterr = step["err"]
320
402
 
321
403
  begin
322
- invoke(client, op, ctrl)
404
+ step_call(client, op, step, ctrl)
323
405
  assert_nil wanterr, "#{label}: #{step['op']} was expected to fail, and did not"
324
406
  rescue Minitest::Assertion
325
407
  raise
@@ -610,6 +610,58 @@ class FeatureTest < Minitest::Test
610
610
  assert_equal 3, calls.length
611
611
  end
612
612
 
613
+ def test_cache_keys_on_the_request_headers
614
+ skip_unless_feature("cache")
615
+ server, calls = H.recording_server
616
+ h = harness([fspec("cache", "ttl" => 10000)], server: server)
617
+ h.op(path: "/w/1", headers: { "x-tenant" => "tenant-a" })
618
+ h.op(path: "/w/1", headers: { "X-Tenant" => "tenant-b" })
619
+ assert_equal 2, calls.length
620
+ h.op(path: "/w/1", headers: { "x-tenant" => "tenant-b" })
621
+ assert_equal 2, calls.length
622
+ end
623
+
624
+ def test_cache_a_write_drops_its_collection
625
+ skip_unless_feature("cache")
626
+ server, calls = H.recording_server
627
+ h = harness([fspec("cache", "ttl" => 10000)], server: server)
628
+ paths = ["/w/1", "/w", "/w/1/part", "/other/1", "/w/2"]
629
+ paths.each { |p| h.op(path: p) }
630
+ h.op(opname: "update", method: "PUT", path: "/w/1")
631
+ paths.each { |p| h.op(path: p) }
632
+ assert_equal 9, calls.length
633
+ assert_equal 2, h.track(:@_cache)["hit"]
634
+ end
635
+
636
+ def test_cache_control_prevents_storing
637
+ skip_unless_feature("cache")
638
+ ["no-store", "private", "No-Cache", "max-age=60, private"].each do |control|
639
+ server, calls = H.recording_server do |_n, _fd|
640
+ [H.make_response(200, { "ok" => true }, { "Cache-Control" => control }), nil]
641
+ end
642
+ h = harness([fspec("cache", "ttl" => 10000)], server: server)
643
+ h.op(path: "/w")
644
+ h.op(path: "/w")
645
+ assert_equal 2, calls.length, control
646
+ end
647
+ end
648
+
649
+ def test_cache_max_age_caps_the_ttl
650
+ skip_unless_feature("cache")
651
+ clock = H::Clock.new
652
+ server, calls = H.recording_server do |_n, _fd|
653
+ [H.make_response(200, { "ok" => true }, { "cache-control" => "max-age=1" }), nil]
654
+ end
655
+ h = harness([fspec("cache", "ttl" => 10000, "now" => clock.now)], server: server)
656
+ h.op(path: "/w")
657
+ clock.advance(500)
658
+ h.op(path: "/w")
659
+ assert_equal 1, calls.length
660
+ clock.advance(600)
661
+ h.op(path: "/w")
662
+ assert_equal 2, calls.length
663
+ end
664
+
613
665
  def test_cache_inactive_does_not_wrap
614
666
  skip_unless_feature("cache")
615
667
  server, calls = H.recording_server
@@ -853,6 +905,47 @@ class FeatureTest < Minitest::Test
853
905
  end
854
906
 
855
907
 
908
+ # === per-call state ===
909
+
910
+ def test_no_feature_keeps_a_context_past_its_call
911
+ skip_unless_feature("netsim")
912
+ names = %w[audit debug telemetry metrics cost].select { |n| H.has_feature?(n) }
913
+ skip "no feature here keeps per-call state" if names.empty?
914
+ h = harness([fspec("netsim", "failEvery" => 2, "failStatus" => 500)] +
915
+ names.map { |n| fspec(n) })
916
+ 20.times { |i| h.op(path: "/w/#{i}") }
917
+ names.each do |n|
918
+ f = h.feature(n)
919
+ f.instance_variables.each do |iv|
920
+ table = f.instance_variable_get(iv)
921
+ next unless table.is_a?(Hash)
922
+ held = table.keys.count { |k| k.is_a?(ProjectNameContext) }
923
+ assert_equal 0, held, "#{n} #{iv} still holds #{held} context(s) after 20 calls"
924
+ end
925
+ end
926
+ assert_equal 20, h.track(:@_audit)["records"].length if names.include?("audit")
927
+ end
928
+
929
+
930
+ # === one call, one id ===
931
+
932
+ def test_telemetry_debug_and_audit_carry_one_calls_context_id
933
+ skip_unless_feature("telemetry")
934
+ skip_unless_feature("debug")
935
+ skip_unless_feature("audit")
936
+ h = harness([fspec("telemetry"), fspec("debug"), fspec("audit")])
937
+ h.op
938
+ h.op(opname: "list")
939
+ ids = ->(recs) { recs.map { |r| r["correlationId"] } }
940
+ calls = ids.call(h.track(:@_audit)["records"])
941
+ assert_equal 2, calls.length
942
+ assert calls.all? { |id| id.is_a?(String) && !id.empty? }, calls.inspect
943
+ refute_equal calls[0], calls[1]
944
+ assert_equal calls, ids.call(h.track(:@_telemetry)["spans"])
945
+ assert_equal calls, ids.call(h.track(:@_debug)["entries"])
946
+ end
947
+
948
+
856
949
  # === clienttrack ===
857
950
 
858
951
  def test_clienttrack_stable_client_id_unique_request_ids_and_ua
@@ -44,14 +44,13 @@ module ProjectNameUtilities
44
44
  n.nil? || n.nan? || n.infinite? || n < 0 ? dflt : n.floor
45
45
  end
46
46
 
47
- # The derived block make_options builds; a context without options
48
- # (make_error is reached with a bare one) falls back to the schema
49
- # defaults, so nothing leaves raw for want of a constructor. A Hash
50
- # stands in for a context before one exists (make_options).
47
+ # The registry make_options builds; a context without one (make_error is
48
+ # reached with a bare one) falls back to the schema defaults, so nothing
49
+ # leaves raw for want of a constructor. A Hash stands in for a context
50
+ # before one exists (make_options).
51
51
  def self.config(ctx)
52
- opts = ctx.respond_to?(:options) ? ctx.options : (ctx.is_a?(Hash) ? ctx["options"] : nil)
53
- derived = opts.is_a?(Hash) ? VoxgigStruct.getpath(opts, "__derived__.clean") : nil
54
- return derived if derived.is_a?(Hash)
52
+ cfg = ctx.respond_to?(:cleancfg) ? ctx.cleancfg : (ctx.is_a?(Hash) ? ctx["cleancfg"] : nil)
53
+ return cfg if cfg.is_a?(Hash)
55
54
  make_config(ProjectNameSchema::OPTSPEC["clean"])
56
55
  end
57
56
 
@@ -189,6 +189,12 @@ module ProjectNameUtilities
189
189
  end
190
190
 
191
191
  http = ProjectNameUtilities.http_checkout(key, uri, proxy)
192
+ # A bound in milliseconds, for a caller beneath the timeout feature;
193
+ # a pooled connection goes back with Net::HTTP's own.
194
+ bound = fetchdef["timeout"]
195
+ bound = bound.is_a?(Numeric) && bound > 0 ? bound / 1000.0 : 60
196
+ http.read_timeout = bound
197
+ http.write_timeout = bound
192
198
  begin
193
199
  # Net::HTTP retries idempotent requests; an EOF can follow a committed POST.
194
200
  resp = http.request(request) do |r|
@@ -68,7 +68,7 @@ module ProjectNameUtilities
68
68
  cfgclean = cfgopts["clean"].is_a?(Hash) ? VoxgigStruct.clone(cfgopts["clean"]) : nil
69
69
  cleancfg = CleanSupport.make_config(VoxgigStruct.merge(
70
70
  [{}, ProjectNameSchema::OPTSPEC["clean"], cfgclean, opts["clean"]].select { |c| c.is_a?(Hash) }))
71
- cleanctx = { "options" => { "__derived__" => { "clean" => cleancfg } } }
71
+ cleanctx = { "cleancfg" => cleancfg }
72
72
  CleanSupport.add_options(cleanctx, opts.reject { |k, _| k == "clean" })
73
73
  [cfgopts, opts].each do |block|
74
74
  CleanSupport.splitvalues(VoxgigStruct.getpath(block, "clean.values")).each do |raw|
@@ -194,10 +194,10 @@ module ProjectNameUtilities
194
194
  # Again over the merged result: the config's own defaults can carry one.
195
195
  CleanSupport.add_options(cleanctx, opts.reject { |k, _| k == "clean" })
196
196
 
197
- opts["__derived__"] = {
198
- "clean" => cleancfg,
199
- "featureorder" => featureorder,
200
- }
197
+ opts["__derived__"] = { "featureorder" => featureorder }
198
+
199
+ # Beside the options, not in them: options_map hands them to callers.
200
+ ctx.cleancfg = cleancfg
201
201
 
202
202
  opts
203
203
  }
@@ -32,6 +32,7 @@ pub struct CtxSpec {
32
32
  pub config: Option<Value>,
33
33
  pub entopts: Option<Value>,
34
34
  pub options: Option<Value>,
35
+ pub cleancfg: Option<Value>,
35
36
  pub entity: Option<Rc<dyn Entity>>,
36
37
  pub shared: Option<Value>,
37
38
  pub opmap: Option<OpMap>,
@@ -57,6 +58,8 @@ pub struct Context {
57
58
  pub config: RefCell<Value>,
58
59
  pub entopts: RefCell<Value>,
59
60
  pub options: RefCell<Value>,
61
+ /// The clean registry, beside the options rather than in them.
62
+ pub cleancfg: RefCell<Value>,
60
63
  pub opmap: RefCell<OpMap>,
61
64
  pub response: RefCell<Option<Rc<RefCell<Response>>>>,
62
65
  pub result: RefCell<Option<Rc<RefCell<SdkResult>>>>,
@@ -135,6 +138,10 @@ impl Context {
135
138
  .options
136
139
  .or_else(|| basectx.map(|b| b.options.borrow().clone()))
137
140
  .unwrap_or(Value::Noval);
141
+ let cleancfg = ctxspec
142
+ .cleancfg
143
+ .or_else(|| basectx.map(|b| b.cleancfg.borrow().clone()))
144
+ .unwrap_or(Value::Noval);
138
145
  let entity = ctxspec
139
146
  .entity
140
147
  .or_else(|| basectx.and_then(|b| b.entity.borrow().clone()));
@@ -212,6 +219,7 @@ impl Context {
212
219
  config: RefCell::new(config),
213
220
  entopts: RefCell::new(entopts),
214
221
  options: RefCell::new(options),
222
+ cleancfg: RefCell::new(cleancfg),
215
223
  opmap: RefCell::new(opmap),
216
224
  response: RefCell::new(response),
217
225
  result: RefCell::new(result),
@@ -1,6 +1,8 @@
1
1
 
2
2
  use std::cell::RefCell;
3
+ use std::collections::hash_map::RandomState;
3
4
  use std::collections::HashMap;
5
+ use std::hash::{BuildHasher, Hash, Hasher};
4
6
  use std::rc::Rc;
5
7
 
6
8
  use crate::core::context::Context;
@@ -20,6 +22,7 @@ pub struct CacheSnapshot {
20
22
 
21
23
  pub struct CacheEntry {
22
24
  expiry: i64,
25
+ scope: String,
23
26
  snapshot: Rc<CacheSnapshot>,
24
27
  }
25
28
 
@@ -27,6 +30,10 @@ pub struct CacheEntry {
27
30
  pub struct CacheTrack {
28
31
  store: HashMap<String, CacheEntry>,
29
32
  order: Vec<String>,
33
+ // No HMAC in std: SipHash under this client's random keys separates
34
+ // header sets within one store without holding a header value. It is not
35
+ // a cryptographic commitment.
36
+ secret: RandomState,
30
37
 
31
38
  // Activity tracking (mirrors the ts client._cache record).
32
39
  pub hit: i64,
@@ -100,10 +107,14 @@ fn through(
100
107
  let methods = fopt_str_list(options, "methods").unwrap_or_else(|| vec!["GET".to_string()]);
101
108
  let cacheable = methods.iter().any(|m| m.to_uppercase() == method);
102
109
  if !cacheable {
103
- return inner(ctx, url, fetchdef);
110
+ let out = inner(ctx, url, fetchdef);
111
+ if method != "GET" && method != "HEAD" {
112
+ invalidate(&mut track.borrow_mut(), url);
113
+ }
114
+ return out;
104
115
  }
105
116
 
106
- let key = format!("{} {}", method, url);
117
+ let key = format!("{} {} {}", method, url, digest(&track.borrow().secret, &getp(fetchdef, "headers")));
107
118
  let now = fopt_now(options)();
108
119
 
109
120
  {
@@ -122,13 +133,19 @@ fn through(
122
133
  if let Ok(res) = &out {
123
134
  if storable(res) && json(res) {
124
135
  let snap = Rc::new(snapshot(res));
125
- let ttl = fopt_int(options, "ttl", 5000);
136
+ let ttl = lifetime(&snap.headers, fopt_int(options, "ttl", 5000));
126
137
  let mut t = track.borrow_mut();
138
+ if ttl <= 0 {
139
+ t.bypass += 1;
140
+ return Ok(replay(&snap));
141
+ }
142
+ drop_entry(&mut t, &key);
127
143
  evict(&mut t, options);
128
144
  t.store.insert(
129
145
  key.clone(),
130
146
  CacheEntry {
131
147
  expiry: now + ttl,
148
+ scope: url_scope(url),
132
149
  snapshot: snap.clone(),
133
150
  },
134
151
  );
@@ -142,6 +159,106 @@ fn through(
142
159
  out
143
160
  }
144
161
 
162
+ fn header_text(v: &Value) -> Option<String> {
163
+ match v {
164
+ Value::Noval | Value::Null => None,
165
+ Value::Str(s) => Some(s.clone()),
166
+ Value::Num(n) if n.fract() == 0.0 => Some(format!("{}", *n as i64)),
167
+ Value::Num(n) => Some(n.to_string()),
168
+ Value::Bool(b) => Some(b.to_string()),
169
+ other => Some(format!("{:?}", other)),
170
+ }
171
+ }
172
+
173
+ fn digest(secret: &RandomState, headers: &Value) -> String {
174
+ let mut pairs: Vec<(String, String)> = Vec::new();
175
+ if let Value::Map(hm) = headers {
176
+ for (k, v) in hm.borrow().iter() {
177
+ if let Some(text) = header_text(v) {
178
+ pairs.push((k.to_lowercase(), text));
179
+ }
180
+ }
181
+ }
182
+ pairs.sort();
183
+ let mut hasher = secret.build_hasher();
184
+ for (k, v) in &pairs {
185
+ format!("{}:{}\n", k, v).hash(&mut hasher);
186
+ }
187
+ format!("{:016x}", hasher.finish())
188
+ }
189
+
190
+ fn invalidate(t: &mut CacheTrack, url: &str) {
191
+ let path = url_scope(url);
192
+ let collection = url_parent(&path);
193
+ let dropped: Vec<String> = t
194
+ .store
195
+ .iter()
196
+ .filter(|(_, e)| scope_under(&e.scope, &path) || e.scope == collection)
197
+ .map(|(k, _)| k.clone())
198
+ .collect();
199
+ for key in dropped {
200
+ drop_entry(t, &key);
201
+ }
202
+ }
203
+
204
+ fn drop_entry(t: &mut CacheTrack, key: &str) {
205
+ if t.store.remove(key).is_some() {
206
+ t.order.retain(|k| k != key);
207
+ }
208
+ }
209
+
210
+ // The configured ttl capped by the response's Cache-Control; zero when the
211
+ // response may not be stored.
212
+ fn lifetime(headers: &Value, ttl: i64) -> i64 {
213
+ let mut control = String::new();
214
+ if let Value::Map(hm) = headers {
215
+ for (k, v) in hm.borrow().iter() {
216
+ if k.to_lowercase() == "cache-control" {
217
+ control = header_text(v).unwrap_or_default().to_lowercase();
218
+ }
219
+ }
220
+ }
221
+ let mut life = ttl;
222
+ for part in control.split(',') {
223
+ let directive = part.trim();
224
+ if ["no-store", "private", "no-cache"].contains(&directive) {
225
+ return 0;
226
+ }
227
+ if let Some(rest) = directive.strip_prefix("max-age") {
228
+ if let Some(value) = rest.trim_start().strip_prefix('=') {
229
+ let digits = value.trim().trim_matches('"');
230
+ if !digits.is_empty() && digits.bytes().all(|b| b.is_ascii_digit()) {
231
+ if let Ok(secs) = digits.parse::<i64>() {
232
+ life = life.min(secs.saturating_mul(1000));
233
+ }
234
+ }
235
+ }
236
+ }
237
+ }
238
+ life
239
+ }
240
+
241
+ fn url_scope(url: &str) -> String {
242
+ let base = url.split(|c| c == '?' || c == '#').next().unwrap_or("");
243
+ base.trim_end_matches('/').to_string()
244
+ }
245
+
246
+ fn url_parent(scope: &str) -> String {
247
+ let root = match scope.find("://") {
248
+ None => 0,
249
+ Some(scheme) => match scope[scheme + 3..].find('/') {
250
+ None => return scope.to_string(),
251
+ Some(slash) => scheme + 3 + slash,
252
+ },
253
+ };
254
+ let cut = scope.rfind('/').unwrap_or(0);
255
+ scope[..cut.max(root)].to_string()
256
+ }
257
+
258
+ fn scope_under(scope: &str, prefix: &str) -> bool {
259
+ scope == prefix || scope.starts_with(&format!("{}/", prefix))
260
+ }
261
+
145
262
  // A body the transport could not read as JSON passes through, for the operation to report.
146
263
  fn storable(res: &Value) -> bool {
147
264
  matches!(fres_status(res), Some(status) if (200..300).contains(&status))
@@ -119,6 +119,7 @@ impl Feature for DebugFeature {
119
119
 
120
120
  let entry = Value::empty_map();
121
121
  setp(&entry, "op", Value::str(format!("{}.{}", entity, opname)));
122
+ setp(&entry, "correlationId", Value::str(ctx.id.clone()));
122
123
  setp(
123
124
  &entry,
124
125
  "start",