@voxgig/sdkgen 4.50.0 → 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 (180) 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/secrets.c +27 -38
  30. package/project/.sdk/tm/c/tests/feature_test.c +104 -0
  31. package/project/.sdk/tm/c/utility/clean.c +26 -33
  32. package/project/.sdk/tm/c/utility/make_options.c +9 -8
  33. package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +14 -11
  34. package/project/.sdk/tm/clojure/src/sdk/client.clj +3 -1
  35. package/project/.sdk/tm/clojure/src/sdk/core.clj +19 -11
  36. package/project/.sdk/tm/clojure/src/sdk/features.clj +81 -10
  37. package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +33 -0
  38. package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +1 -0
  39. package/project/.sdk/tm/cpp/Makefile +5 -0
  40. package/project/.sdk/tm/cpp/core/types.hpp +11 -4
  41. package/project/.sdk/tm/cpp/feature/audit.hpp +6 -7
  42. package/project/.sdk/tm/cpp/feature/cache.hpp +188 -9
  43. package/project/.sdk/tm/cpp/feature/secrets.hpp +12 -0
  44. package/project/.sdk/tm/cpp/test/feature_test.cpp +99 -0
  45. package/project/.sdk/tm/cpp/utility/pipeline.hpp +9 -7
  46. package/project/.sdk/tm/csharp/core/Context.cs +4 -0
  47. package/project/.sdk/tm/csharp/feature/CacheFeature.cs +126 -12
  48. package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +9 -27
  49. package/project/.sdk/tm/csharp/test/FeatureTest.cs +76 -0
  50. package/project/.sdk/tm/csharp/utility/Clean.cs +5 -10
  51. package/project/.sdk/tm/csharp/utility/Fetcher.cs +7 -1
  52. package/project/.sdk/tm/csharp/utility/MakeOptions.cs +5 -12
  53. package/project/.sdk/tm/elixir/lib/projectname/context.ex +2 -0
  54. package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +146 -30
  55. package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +10 -56
  56. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +18 -12
  57. package/project/.sdk/tm/elixir/test/feature_test.exs +61 -0
  58. package/project/.sdk/tm/go/core/context.go +6 -0
  59. package/project/.sdk/tm/go/feature/cache_feature.go +131 -4
  60. package/project/.sdk/tm/go/feature/secrets_feature.go +17 -71
  61. package/project/.sdk/tm/go/test/feature_corpus_test.go +150 -2
  62. package/project/.sdk/tm/go/test/feature_test.go +61 -0
  63. package/project/.sdk/tm/go/utility/clean.go +5 -7
  64. package/project/.sdk/tm/go/utility/fetcher.go +11 -0
  65. package/project/.sdk/tm/go/utility/make_options.go +5 -7
  66. package/project/.sdk/tm/java/core/Context.java +9 -0
  67. package/project/.sdk/tm/java/feature/CacheFeature.java +123 -17
  68. package/project/.sdk/tm/java/feature/SecretsFeature.java +9 -92
  69. package/project/.sdk/tm/java/test/FeatureCorpusTest.java +141 -2
  70. package/project/.sdk/tm/java/test/FeatureTest.java +60 -0
  71. package/project/.sdk/tm/java/utility/Clean.java +6 -10
  72. package/project/.sdk/tm/java/utility/Fetcher.java +5 -1
  73. package/project/.sdk/tm/java/utility/MakeOptions.java +3 -1
  74. package/project/.sdk/tm/js/src/Context.js +4 -0
  75. package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +118 -11
  76. package/project/.sdk/tm/js/src/feature/cost/CostFeature.js +3 -2
  77. package/project/.sdk/tm/js/src/feature/metrics/MetricsFeature.js +1 -1
  78. package/project/.sdk/tm/js/src/feature/paging/PagingFeature.js +4 -4
  79. package/project/.sdk/tm/js/src/feature/rbac/RbacFeature.js +4 -4
  80. package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +16 -6
  81. package/project/.sdk/tm/js/src/feature/validate/ValidateFeature.js +2 -1
  82. package/project/.sdk/tm/js/src/utility/CleanUtility.js +1 -1
  83. package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +6 -6
  84. package/project/.sdk/tm/js/test/feature/Corpus.test.js +100 -2
  85. package/project/.sdk/tm/js/test/feature/harness.js +3 -3
  86. package/project/.sdk/tm/js/test/pipeline.test.js +1 -1
  87. package/project/.sdk/tm/kotlin/core/Context.kt +3 -0
  88. package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +102 -7
  89. package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +10 -20
  90. package/project/.sdk/tm/kotlin/test/FeatureTest.kt +59 -0
  91. package/project/.sdk/tm/kotlin/utility/CoreUtil.kt +5 -5
  92. package/project/.sdk/tm/kotlin/utility/Fetcher.kt +4 -0
  93. package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +3 -1
  94. package/project/.sdk/tm/lua/core/context.lua +6 -0
  95. package/project/.sdk/tm/lua/feature/cache_feature.lua +212 -15
  96. package/project/.sdk/tm/lua/feature/secrets_feature.lua +15 -80
  97. package/project/.sdk/tm/lua/test/feature_test.lua +81 -0
  98. package/project/.sdk/tm/lua/utility/clean.lua +6 -9
  99. package/project/.sdk/tm/lua/utility/fetcher.lua +9 -0
  100. package/project/.sdk/tm/lua/utility/make_options.lua +5 -5
  101. package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +21 -6
  102. package/project/.sdk/tm/ocaml/sdk_features.ml +106 -8
  103. package/project/.sdk/tm/ocaml/sdk_runtime.ml +13 -10
  104. package/project/.sdk/tm/ocaml/sdk_types.ml +2 -0
  105. package/project/.sdk/tm/ocaml/test/t_feature.ml +35 -1
  106. package/project/.sdk/tm/perl/core/context.pm +3 -0
  107. package/project/.sdk/tm/perl/feature/audit_feature.pm +4 -7
  108. package/project/.sdk/tm/perl/feature/cache_feature.pm +111 -15
  109. package/project/.sdk/tm/perl/feature/secrets_feature.pm +13 -18
  110. package/project/.sdk/tm/perl/t/feature.t +66 -0
  111. package/project/.sdk/tm/perl/t/feature_corpus.t +80 -4
  112. package/project/.sdk/tm/perl/utility/clean.pm +6 -8
  113. package/project/.sdk/tm/perl/utility/fetcher.pm +4 -0
  114. package/project/.sdk/tm/perl/utility/make_options.pm +5 -5
  115. package/project/.sdk/tm/php/core/Context.php +4 -0
  116. package/project/.sdk/tm/php/feature/CacheFeature.php +98 -13
  117. package/project/.sdk/tm/php/feature/SecretsFeature.php +18 -15
  118. package/project/.sdk/tm/php/test/FeatureCorpusTest.php +113 -3
  119. package/project/.sdk/tm/php/test/FeatureTest.php +68 -0
  120. package/project/.sdk/tm/php/utility/Clean.php +3 -10
  121. package/project/.sdk/tm/php/utility/Fetcher.php +8 -3
  122. package/project/.sdk/tm/php/utility/MakeOptions.php +5 -7
  123. package/project/.sdk/tm/py/pkg/core/context.py +4 -0
  124. package/project/.sdk/tm/py/pkg/feature/cache_feature.py +79 -13
  125. package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +15 -66
  126. package/project/.sdk/tm/py/pkg/utility/clean.py +4 -10
  127. package/project/.sdk/tm/py/pkg/utility/make_options.py +8 -9
  128. package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +23 -9
  129. package/project/.sdk/tm/py/test/test_feature.py +50 -0
  130. package/project/.sdk/tm/py/test/test_feature_corpus.py +88 -3
  131. package/project/.sdk/tm/rb/core/context.rb +4 -1
  132. package/project/.sdk/tm/rb/feature/audit_feature.rb +6 -5
  133. package/project/.sdk/tm/rb/feature/cache_feature.rb +75 -11
  134. package/project/.sdk/tm/rb/feature/secrets_feature.rb +9 -64
  135. package/project/.sdk/tm/rb/test/feature_corpus_test.rb +85 -3
  136. package/project/.sdk/tm/rb/test/feature_test.rb +74 -0
  137. package/project/.sdk/tm/rb/utility/clean.rb +6 -7
  138. package/project/.sdk/tm/rb/utility/fetcher.rb +6 -0
  139. package/project/.sdk/tm/rb/utility/make_options.rb +5 -5
  140. package/project/.sdk/tm/rust/core/context.rs +8 -0
  141. package/project/.sdk/tm/rust/feature/cache.rs +120 -3
  142. package/project/.sdk/tm/rust/feature/secrets.rs +36 -98
  143. package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +3 -3
  144. package/project/.sdk/tm/rust/tests/feature_test.rs +100 -0
  145. package/project/.sdk/tm/rust/utility/clean.rs +35 -43
  146. package/project/.sdk/tm/rust/utility/fetcher.rs +6 -0
  147. package/project/.sdk/tm/rust/utility/make_options.rs +8 -11
  148. package/project/.sdk/tm/scala/core/Context.scala +4 -0
  149. package/project/.sdk/tm/scala/feature/CacheFeature.scala +117 -11
  150. package/project/.sdk/tm/scala/feature/SecretsFeature.scala +11 -24
  151. package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +28 -0
  152. package/project/.sdk/tm/scala/utility/Fetcher.scala +5 -0
  153. package/project/.sdk/tm/scala/utility/Make.scala +3 -1
  154. package/project/.sdk/tm/scala/utility/Misc.scala +5 -8
  155. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Context.swift +3 -0
  156. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +122 -11
  157. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +9 -13
  158. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +4 -0
  159. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/MakeOptions.swift +5 -4
  160. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/ResultUtil.swift +4 -5
  161. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +55 -0
  162. package/project/.sdk/tm/ts/src/Context.ts +4 -0
  163. package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +115 -4
  164. package/project/.sdk/tm/ts/src/feature/cost/CostFeature.ts +3 -2
  165. package/project/.sdk/tm/ts/src/feature/metrics/MetricsFeature.ts +1 -1
  166. package/project/.sdk/tm/ts/src/feature/paging/PagingFeature.ts +4 -4
  167. package/project/.sdk/tm/ts/src/feature/rbac/RbacFeature.ts +4 -4
  168. package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +14 -2
  169. package/project/.sdk/tm/ts/src/feature/validate/ValidateFeature.ts +2 -1
  170. package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +1 -1
  171. package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +6 -6
  172. package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +101 -2
  173. package/project/.sdk/tm/ts/test/feature/harness.ts +3 -3
  174. package/project/.sdk/tm/ts/test/pipeline.test.ts +1 -1
  175. package/project/.sdk/tm/zig/core/context.zig +5 -0
  176. package/project/.sdk/tm/zig/core/utility.zig +11 -9
  177. package/project/.sdk/tm/zig/feature/cache.zig +144 -13
  178. package/project/.sdk/tm/zig/feature/secrets.zig +6 -1
  179. package/project/.sdk/tm/zig/test/feature_test.zig +65 -0
  180. package/project/sdkgen-package.json +1 -1
@@ -14,7 +14,6 @@ use warnings;
14
14
 
15
15
  use File::Basename ();
16
16
  use Cwd ();
17
- use Scalar::Util ();
18
17
 
19
18
  my $__dir;
20
19
  BEGIN { $__dir = File::Basename::dirname(Cwd::abs_path(__FILE__)) }
@@ -36,7 +35,6 @@ sub new {
36
35
  $self->{client} = undef;
37
36
  $self->{options} = {};
38
37
  $self->{seq} = 0;
39
- $self->{seen} = {};
40
38
  return $self;
41
39
  }
42
40
 
@@ -46,7 +44,6 @@ sub init {
46
44
  $self->{options} = Voxgig::Struct::ismap($options) ? $options : {};
47
45
  $self->{active} = ProjectNameHelpers::is_true($self->{options}{active});
48
46
  $self->{seq} = 0;
49
- $self->{seen} = {};
50
47
 
51
48
  return unless $self->{active};
52
49
 
@@ -76,10 +73,10 @@ sub PreUnexpected {
76
73
  sub _emit {
77
74
  my ($self, $ctx, $outcome) = @_;
78
75
  # One record per operation (PreDone + a following PreUnexpected on a
79
- # non-2xx must not double-log).
80
- my $addr = Scalar::Util::refaddr($ctx);
81
- return if exists $self->{seen}{$addr};
82
- $self->{seen}{$addr} = 1;
76
+ # non-2xx must not double-log). The marker lives on the context: a table
77
+ # keyed by refaddr grows per call, and a reused address skips a call.
78
+ return if $ctx->{out}{audit_seen};
79
+ $ctx->{out}{audit_seen} = 1;
83
80
  $self->{seq} += 1;
84
81
 
85
82
  my $record = $ctx->{utility}{clean}->($ctx, {
@@ -1,12 +1,7 @@
1
1
  # ProjectName SDK cache feature
2
2
  #
3
- # Response caching for safe (read) requests. Wraps the active transport and
4
- # serves a fresh cached snapshot instead of hitting the network when the
5
- # same method+URL was fetched within "ttl" ms (default 5000). Only
6
- # successful (2xx) responses to cacheable methods (default: GET) are
7
- # stored, keyed by method+URL. The cache is bounded ("max" entries, default
8
- # 256, oldest evicted first) and every hit/miss/bypass is counted for
9
- # inspection. Replayed responses expose a re-readable "json" body.
3
+ # Response caching for safe (read) requests, per client: see the features
4
+ # reference for the key, the write invalidation and the Cache-Control rules.
10
5
 
11
6
  use strict;
12
7
  use warnings;
@@ -14,6 +9,7 @@ use warnings;
14
9
  use File::Basename ();
15
10
  use Cwd ();
16
11
  use Scalar::Util ();
12
+ use Digest::SHA ();
17
13
 
18
14
  my $__dir;
19
15
  BEGIN { $__dir = File::Basename::dirname(Cwd::abs_path(__FILE__)) }
@@ -52,6 +48,7 @@ sub init {
52
48
 
53
49
  $self->{store} = {};
54
50
  $self->{order} = [];
51
+ $self->{secret} = _cache_secret();
55
52
 
56
53
  my $feature = $self;
57
54
  my $utility = $ctx->{utility};
@@ -70,10 +67,18 @@ sub through {
70
67
  ? uc("$fetchdef->{method}") : 'GET';
71
68
  my $methods = $self->{options}{methods} || ['GET'];
72
69
 
73
- return $inner->($ctx, $url, $fetchdef)
74
- unless grep { uc("$_") eq $method } @$methods;
70
+ unless (grep { uc("$_") eq $method } @$methods) {
71
+ return $inner->($ctx, $url, $fetchdef) if $method eq 'GET' || $method eq 'HEAD';
72
+ my @out;
73
+ my $done = eval { @out = $inner->($ctx, $url, $fetchdef); 1 };
74
+ my $failure = $@;
75
+ $self->_invalidate($url);
76
+ die $failure unless $done;
77
+ return @out;
78
+ }
75
79
 
76
- my $key = "$method $url";
80
+ my $headers = Voxgig::Struct::ismap($fetchdef) ? $fetchdef->{headers} : undef;
81
+ my $key = "$method $url " . $self->_digest($headers);
77
82
  my $now = $self->_now;
78
83
  my $hit = $self->{store}{$key};
79
84
 
@@ -92,12 +97,17 @@ sub through {
92
97
 
93
98
  if (!defined $err && $self->_cacheable($res)) {
94
99
  my $snapshot = $self->_snapshot($res);
95
- my $ttl = defined $self->{options}{ttl} ? $self->{options}{ttl} : 5000;
96
- $self->_evict;
97
- if (!exists $self->{store}{$key}) {
98
- push @{ $self->{order} }, $key;
100
+ my $ttl = _cache_lifetime($snapshot->{headers},
101
+ defined $self->{options}{ttl} ? $self->{options}{ttl} : 5000);
102
+ if ($ttl <= 0) {
103
+ $self->_track('bypass');
104
+ return ($self->_replay($snapshot), undef);
99
105
  }
100
- $self->{store}{$key} = { 'expiry' => $now + $ttl, 'snapshot' => $snapshot };
106
+ $self->_drop($key);
107
+ $self->_evict;
108
+ push @{ $self->{order} }, $key;
109
+ $self->{store}{$key} = {
110
+ 'expiry' => $now + $ttl, 'scope' => _cache_scope($url), 'snapshot' => $snapshot };
101
111
  $self->_track('miss');
102
112
  return ($self->_replay($snapshot), undef);
103
113
  }
@@ -106,6 +116,92 @@ sub through {
106
116
  return ($res, $err);
107
117
  }
108
118
 
119
+ sub _digest {
120
+ my ($self, $headers) = @_;
121
+ my @pairs;
122
+ if (Voxgig::Struct::ismap($headers)) {
123
+ for my $name (keys %$headers) {
124
+ next unless defined $headers->{$name};
125
+ push @pairs, [lc($name), "$headers->{$name}"];
126
+ }
127
+ }
128
+ my $text = join('', map { "$_->[0]:$_->[1]\n" }
129
+ sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @pairs);
130
+ return Digest::SHA::hmac_sha256_hex($text, $self->{secret});
131
+ }
132
+
133
+ sub _invalidate {
134
+ my ($self, $url) = @_;
135
+ my $path = _cache_scope($url);
136
+ my $collection = _cache_parent($path);
137
+ for my $key (keys %{ $self->{store} }) {
138
+ my $scope = $self->{store}{$key}{scope};
139
+ $self->_drop($key) if _cache_under($scope, $path) || $scope eq $collection;
140
+ }
141
+ return;
142
+ }
143
+
144
+ sub _drop {
145
+ my ($self, $key) = @_;
146
+ return unless exists $self->{store}{$key};
147
+ delete $self->{store}{$key};
148
+ $self->{order} = [grep { $_ ne $key } @{ $self->{order} }];
149
+ return;
150
+ }
151
+
152
+ # The system's random source where it has one; otherwise Perl's own rand,
153
+ # which is not a cryptographic generator.
154
+ sub _cache_secret {
155
+ my $bytes = '';
156
+ if (open(my $fh, '<:raw', '/dev/urandom')) {
157
+ read($fh, $bytes, 32);
158
+ close($fh);
159
+ }
160
+ $bytes .= pack('N', int(rand(4294967296))) while length($bytes) < 32;
161
+ return $bytes;
162
+ }
163
+
164
+ # The configured ttl capped by the response's Cache-Control; zero when the
165
+ # response may not be stored.
166
+ sub _cache_lifetime {
167
+ my ($headers, $ttl) = @_;
168
+ my $control = '';
169
+ for my $name (keys %{ $headers || {} }) {
170
+ $control = lc("$headers->{$name}") if lc($name) eq 'cache-control';
171
+ }
172
+ my $life = $ttl;
173
+ for my $part (split /,/, $control) {
174
+ (my $directive = $part) =~ s/^\s+|\s+$//g;
175
+ return 0 if grep { $_ eq $directive } ('no-store', 'private', 'no-cache');
176
+ if ($directive =~ /^max-age\s*=\s*"?(\d+)"?$/) {
177
+ $life = $1 * 1000 if $1 * 1000 < $life;
178
+ }
179
+ }
180
+ return $life;
181
+ }
182
+
183
+ sub _cache_scope {
184
+ my ($url) = @_;
185
+ my ($scope) = split /[?#]/, "$url", 2;
186
+ $scope = '' unless defined $scope;
187
+ $scope =~ s{/+$}{};
188
+ return $scope;
189
+ }
190
+
191
+ sub _cache_parent {
192
+ my ($scope) = @_;
193
+ my $scheme = index($scope, '://');
194
+ my $root = $scheme < 0 ? 0 : index($scope, '/', $scheme + 3);
195
+ return $scope if $root < 0;
196
+ my $cut = rindex($scope, '/');
197
+ return substr($scope, 0, $cut < $root ? $root : $cut);
198
+ }
199
+
200
+ sub _cache_under {
201
+ my ($scope, $prefix) = @_;
202
+ return $scope eq $prefix || index($scope, "$prefix/") == 0;
203
+ }
204
+
109
205
  sub _cacheable {
110
206
  my ($self, $res) = @_;
111
207
  return 0 unless Voxgig::Struct::ismap($res);
@@ -334,6 +334,7 @@ sub transport {
334
334
  # provider ERROR refuses the request with the provider's own message;
335
335
  # never an unauthenticated send.
336
336
  my $err = $self->resolve();
337
+ return (undef, $err) if Scalar::Util::blessed($err) && $err->isa('ProjectNameError');
337
338
  if (defined $err) {
338
339
  return (undef, $ctx->make_error('secrets_resolve', $err));
339
340
  }
@@ -594,24 +595,12 @@ sub _buy_once {
594
595
  $path =~ s{\A/+}{};
595
596
  my $url = "$base/$path";
596
597
 
597
- # Deliberately NOT the SDK transport. The transport is what this feature
598
- # wraps, and sending the token request back through it would recurse on
599
- # the first expiry - and would route the exchange through the test mock,
600
- # which knows nothing about it. `system.fetch` (the caller's own
601
- # transport seam) when supplied, else the raw HTTP fetch the utility
602
- # registry keeps beside its own fetcher.
603
- my $fetch = ProjectNameHelpers::gpath($options, 'system.fetch');
604
- if (!(defined $fetch && 'CODE' eq ref $fetch)) {
605
- # utility/fetcher.pm keeps the raw HTTP transport as a package global
606
- # BESIDE its registered fetcher, precisely so a caller that must not
607
- # recurse through the wrapper (or trip the test-mode block) can reach
608
- # it. `once` is disabled because this file names it exactly once.
609
- no warnings 'once';
610
- $fetch = $ProjectNameUtilities::DefaultHttpFetch;
611
- }
612
-
613
- return (undef, 'secrets: no fetch implementation for the token exchange')
614
- if !(defined $fetch && 'CODE' eq ref $fetch);
598
+ # The SDK's own transport, beneath every feature's wrapper: it holds the
599
+ # test feature's block and the GET-only guard, and the wrapped one would
600
+ # recurse on the first expiry.
601
+ my $ctx = $self->{ctx};
602
+ no warnings 'once';
603
+ my $fetch = sub { $ProjectNameUtilities::REGISTRY{fetcher}->($ctx, @_) };
615
604
 
616
605
  # The body is MARSHALLED, never concatenated: a refresh token (or a
617
606
  # configured request-field name) carrying a quote, backslash or newline
@@ -624,6 +613,8 @@ sub _buy_once {
624
613
  'body' => $body,
625
614
  # Never followed by the client: a redirect would carry the refresh token on.
626
615
  'redirect' => 'manual',
616
+ # Its own bound, in milliseconds: the timeout feature's wrapper is above it.
617
+ 'timeout' => 30000,
627
618
  };
628
619
 
629
620
  my ($res, $err);
@@ -644,6 +635,10 @@ sub _buy_once {
644
635
 
645
636
  return (undef, _trim("$@")) if !$ok;
646
637
 
638
+ # The transport's own refusal, the GET-only guard's among them, is the
639
+ # operation's error.
640
+ return (undef, $err) if Scalar::Util::blessed($err) && $err->isa('ProjectNameError');
641
+
647
642
  return (undef, 'secrets: token exchange failed: ' . _trim("$err") . " from $url")
648
643
  if defined $err;
649
644
 
@@ -643,6 +643,51 @@ if (has_feature('cache')) {
643
643
  $h->op('path' => '/x');
644
644
  is(scalar @$calls, 2, 'cache inactive does not wrap');
645
645
  }
646
+
647
+ {
648
+ my ($server, $calls) = recording_server();
649
+ my $h = harness([fspec('cache', 'ttl' => 10000)], server => $server);
650
+ $h->op('path' => '/w/1', 'headers' => { 'x-tenant' => 'tenant-a' });
651
+ $h->op('path' => '/w/1', 'headers' => { 'X-Tenant' => 'tenant-b' });
652
+ is(scalar @$calls, 2, 'cache keys on the request headers');
653
+ $h->op('path' => '/w/1', 'headers' => { 'x-tenant' => 'tenant-b' });
654
+ is(scalar @$calls, 2, 'cache shares an entry between the same headers');
655
+ }
656
+
657
+ {
658
+ my ($server, $calls) = recording_server();
659
+ my $h = harness([fspec('cache', 'ttl' => 10000)], server => $server);
660
+ my @paths = ('/w/1', '/w', '/w/1/part', '/other/1', '/w/2');
661
+ $h->op('path' => $_) for @paths;
662
+ $h->op('opname' => 'update', 'method' => 'PUT', 'path' => '/w/1');
663
+ $h->op('path' => $_) for @paths;
664
+ is(scalar @$calls, 9, 'cache write drops its collection');
665
+ is($h->track('_cache')->{hit}, 2, 'cache write keeps another entity');
666
+ }
667
+
668
+ for my $control ('no-store', 'private', 'No-Cache', 'max-age=60, private') {
669
+ my ($server, $calls) = recording_server(sub {
670
+ (make_response(200, { 'ok' => 1 }, { 'Cache-Control' => $control }), undef) });
671
+ my $h = harness([fspec('cache', 'ttl' => 10000)], server => $server);
672
+ $h->op('path' => '/w');
673
+ $h->op('path' => '/w');
674
+ is(scalar @$calls, 2, "cache does not store $control");
675
+ }
676
+
677
+ {
678
+ my $clock = HarnessClock->new;
679
+ my ($server, $calls) = recording_server(sub {
680
+ (make_response(200, { 'ok' => 1 }, { 'cache-control' => 'max-age=1' }), undef) });
681
+ my $h = harness([fspec('cache', 'ttl' => 10000, 'now' => $clock->now)],
682
+ server => $server);
683
+ $h->op('path' => '/w');
684
+ $clock->advance(500);
685
+ $h->op('path' => '/w');
686
+ is(scalar @$calls, 1, 'cache serves inside max-age');
687
+ $clock->advance(600);
688
+ $h->op('path' => '/w');
689
+ is(scalar @$calls, 2, 'cache max-age caps the ttl');
690
+ }
646
691
  }
647
692
  else { note('feature "cache" not present in this SDK') }
648
693
 
@@ -883,6 +928,27 @@ if (has_feature('audit')) {
883
928
  else { note('feature "audit" not present in this SDK') }
884
929
 
885
930
 
931
+ # === per-call state ===
932
+
933
+ {
934
+ my @names = grep { has_feature($_) } qw(audit debug telemetry metrics cost);
935
+ if (has_feature('netsim') && @names) {
936
+ my $h = harness([fspec('netsim', 'failEvery' => 2, 'failStatus' => 500),
937
+ map { fspec($_) } @names]);
938
+ $h->op('path' => "/w/$_") for 1 .. 20;
939
+ for my $name (@names) {
940
+ my $f = $h->feature($name);
941
+ for my $table (qw(seen entries spans starts pending)) {
942
+ next unless ref($f->{$table}) eq 'HASH';
943
+ is(scalar(keys %{ $f->{$table} }), 0,
944
+ "$name $table holds no call after 20 calls");
945
+ }
946
+ }
947
+ is(scalar @{ $h->track('_audit')->{records} }, 20, 'audit records every one of 20 calls')
948
+ if grep { 'audit' eq $_ } @names;
949
+ }
950
+ }
951
+
886
952
  # === one call, one id ===
887
953
 
888
954
  if (has_feature('telemetry') && has_feature('debug') && has_feature('audit')) {
@@ -20,6 +20,7 @@ use FindBin;
20
20
  use lib "$FindBin::Bin/../lib";
21
21
  use Cwd ();
22
22
  use Scalar::Util ();
23
+ use Time::HiRes ();
23
24
 
24
25
  use ProjectNameSDK;
25
26
 
@@ -162,11 +163,25 @@ sub candidates {
162
163
 
163
164
 
164
165
  sub invoke {
165
- my ($client, $op, $ctrl) = @_;
166
+ my ($client, $op, $ctrl, $args) = @_;
166
167
  my $acc = $op->{accessor};
167
168
  my $fn = $op->{op};
168
169
  my $ent = $client->$acc();
169
- return $ent->$fn({}, $ctrl);
170
+ return $ent->$fn({ %{ $args || {} } }, $ctrl);
171
+ }
172
+
173
+
174
+ my %ITEM_ARGS = (id => 'corpus-item');
175
+
176
+ # A write of one entity (#ITEM) that completes when driven with %ITEM_ARGS.
177
+ sub usable_item {
178
+ my ($accessor) = @_;
179
+ for my $cand (candidates(build_client({}))) {
180
+ next unless $cand->{accessor} eq $accessor && grep { $_ eq $cand->{op} } qw(update patch remove);
181
+ next unless eval { invoke(build_client({}), $cand, {}, \%ITEM_ARGS); 1 };
182
+ return $cand;
183
+ }
184
+ return undef;
170
185
  }
171
186
 
172
187
 
@@ -212,6 +227,43 @@ sub resolve {
212
227
  }
213
228
 
214
229
 
230
+ # A read and a write of one entity (#READ, #WRITE), each driven as usable_ops
231
+ # drives an op.
232
+ sub usable_pair {
233
+ my %found;
234
+ for my $cand (candidates(build_client({}))) {
235
+ my $role = (grep { $_ eq $cand->{op} } qw(list load)) ? 'read'
236
+ : (grep { $_ eq $cand->{op} } qw(create update patch remove)) ? 'write' : undef;
237
+ next unless defined $role;
238
+ my $seen = $found{ $cand->{accessor} } ||= {};
239
+ next if $seen->{$role};
240
+ next unless eval { invoke(build_client({}), $cand, {}); 1 };
241
+ $seen->{$role} = $cand;
242
+ return $seen if $seen->{read} && $seen->{write};
243
+ }
244
+ return undef;
245
+ }
246
+
247
+
248
+ # One step: it may wait before its call, may add request headers for its
249
+ # call, and may pass `args` as the operation's first argument.
250
+ sub step_call {
251
+ my ($client, $op, $step, $ctrl) = @_;
252
+ Time::HiRes::sleep($step->{wait} / 1000) if defined $step->{wait};
253
+ my $args = Voxgig::Struct::ismap($step->{args}) ? $step->{args} : {};
254
+ return invoke($client, $op, $ctrl, $args) unless Voxgig::Struct::ismap($step->{headers});
255
+ my $options = $client->{options};
256
+ my $had = exists $options->{headers};
257
+ my $prior = $options->{headers};
258
+ $options->{headers} = { %{ $prior || {} }, %{ $step->{headers} } };
259
+ my $ok = eval { invoke($client, $op, $ctrl, $args); 1 };
260
+ my $err = $@;
261
+ if ($had) { $options->{headers} = $prior } else { delete $options->{headers} }
262
+ die $err unless $ok;
263
+ return;
264
+ }
265
+
266
+
215
267
  # The highest #OPn a case mentions.
216
268
  sub tokens_used {
217
269
  my ($kase) = @_;
@@ -304,6 +356,9 @@ sub missing_feature {
304
356
 
305
357
 
306
358
  my @ops = usable_ops(2);
359
+ my $pair = usable_pair();
360
+ my $item = $pair ? usable_item($pair->{read}{accessor}) : undef;
361
+ my ($other) = $pair ? grep { $_->{accessor} ne $pair->{read}{accessor} } @ops : ();
307
362
 
308
363
  # At least one operation, or every case would skip and this file would report
309
364
  # green having run nothing.
@@ -333,7 +388,7 @@ for my $name (sort keys %{ $CORPUS->{feature} || {} }) {
333
388
  next;
334
389
  }
335
390
 
336
- my %by_key = map { $_->{key} => $_ } @ops;
391
+ my %by_key = map { $_->{key} => $_ } @ops, ($pair ? values %$pair : ()), ($item ? $item : ());
337
392
 
338
393
  my $ran = 0;
339
394
  for my $raw (@$cases) {
@@ -344,6 +399,21 @@ for my $name (sort keys %{ $CORPUS->{feature} || {} }) {
344
399
  next;
345
400
  }
346
401
 
402
+ my $paired = Voxgig::Struct::stringify($raw) =~ /#(READ|WRITE|ITEM|OTHER)\b/;
403
+ if ($paired && !$pair) {
404
+ diag(sprintf('skip "%s": needs a read and a write of one entity, this SDK offers none',
405
+ $raw->{name} // ''));
406
+ next;
407
+ }
408
+ my ($lacking) = grep {
409
+ my ($tok, $found) = @$_;
410
+ $paired && !$found && Voxgig::Struct::stringify($raw) =~ /\Q$tok\E\b/
411
+ } (['#ITEM', $item], ['#OTHER', $other]);
412
+ if ($lacking) {
413
+ diag(sprintf('skip "%s": needs %s, which this SDK cannot drive', $raw->{name} // '', $lacking->[0]));
414
+ next;
415
+ }
416
+
347
417
  my $missing = missing_feature($raw, \%have);
348
418
  if (defined $missing) {
349
419
  diag(sprintf('skip "%s": needs the %s feature, which this SDK does not generate',
@@ -355,6 +425,12 @@ for my $name (sort keys %{ $CORPUS->{feature} || {} }) {
355
425
  for my $i (0 .. $need - 1) {
356
426
  $tokens{ '#OP' . ($i + 1) } = $ops[$i]{key};
357
427
  }
428
+ if ($paired) {
429
+ $tokens{'#READ'} = $pair->{read}{key};
430
+ $tokens{'#WRITE'} = $pair->{write}{key};
431
+ $tokens{'#ITEM'} = $item->{key} if $item;
432
+ $tokens{'#OTHER'} = $other->{key} if $other;
433
+ }
358
434
  my $kase = resolve($raw, \%tokens);
359
435
  my $label = $kase->{name} || '';
360
436
  $ran++;
@@ -369,7 +445,7 @@ for my $name (sort keys %{ $CORPUS->{feature} || {} }) {
369
445
  my $ctrl = $step->{ctrl} || {};
370
446
  my $wanterr = $step->{err};
371
447
 
372
- my $ok = eval { invoke($client, $op, $ctrl); 1 };
448
+ my $ok = eval { step_call($client, $op, $step, $ctrl); 1 };
373
449
  my $err = $@;
374
450
 
375
451
  if (!defined $wanterr) {
@@ -69,16 +69,14 @@ sub count {
69
69
  return $n < 0 ? $dflt : $n;
70
70
  }
71
71
 
72
- # The derived block make_options builds; a context without options
73
- # (make_error is reached with a bare one) falls back to the schema
74
- # defaults, so nothing leaves raw for want of a constructor. A plain hash
75
- # stands in for a context before one exists (make_options).
72
+ # The registry make_options builds; a context without one (make_error is
73
+ # reached with a bare one) falls back to the schema defaults, so nothing
74
+ # leaves raw for want of a constructor. A plain hash stands in for a context
75
+ # before one exists (make_options).
76
76
  sub config {
77
77
  my ($ctx) = @_;
78
- my $opts = (defined $ctx && ref $ctx && (Scalar::Util::reftype($ctx) // '') eq 'HASH')
79
- ? $ctx->{options} : undef;
80
- my $derived = Voxgig::Struct::ismap($opts) ? $opts->{__derived__} : undef;
81
- my $cfg = Voxgig::Struct::ismap($derived) ? $derived->{clean} : undef;
78
+ my $cfg = (defined $ctx && ref $ctx && (Scalar::Util::reftype($ctx) // '') eq 'HASH')
79
+ ? $ctx->{cleancfg} : undef;
82
80
  return $cfg if Voxgig::Struct::ismap($cfg) && Voxgig::Struct::islist($cfg->{values});
83
81
  return make_config(ProjectNameSchema::optspec()->{clean});
84
82
  }
@@ -162,6 +162,10 @@ sub _send_once {
162
162
  $new_args{http_proxy} = $new_args{https_proxy} = "$fetchdef->{proxy}"
163
163
  if defined $fetchdef->{proxy} && !ref $fetchdef->{proxy}
164
164
  && length $fetchdef->{proxy};
165
+ # A bound in milliseconds, for a caller beneath the timeout feature.
166
+ $new_args{timeout} = $fetchdef->{timeout} / 1000
167
+ if defined $fetchdef->{timeout} && !ref $fetchdef->{timeout}
168
+ && $fetchdef->{timeout} =~ /\A\d+(?:\.\d+)?\z/ && $fetchdef->{timeout} > 0;
165
169
 
166
170
  # A request that got no answer fails the operation.
167
171
  my $res = eval { _http_client(%new_args)->request($method, $fullurl, $opts) };
@@ -102,7 +102,7 @@ $REGISTRY{make_options} = sub {
102
102
  (Voxgig::Struct::clone(ProjectNameSchema::optspec()->{clean}),
103
103
  Voxgig::Struct::clone($cfgopts->{clean}), $opts->{clean}),
104
104
  ]));
105
- my $cleanctx = { 'options' => { '__derived__' => { 'clean' => $cleancfg } } };
105
+ my $cleanctx = { 'cleancfg' => $cleancfg };
106
106
  my %rawscan = %$opts;
107
107
  delete $rawscan{clean};
108
108
  ProjectNameCleanSupport::add_options($cleanctx, \%rawscan);
@@ -233,10 +233,10 @@ $REGISTRY{make_options} = sub {
233
233
  }
234
234
  }
235
235
 
236
- $opts->{__derived__} = {
237
- 'clean' => $cleancfg,
238
- 'featureorder' => \@featureorder,
239
- };
236
+ $opts->{__derived__} = { 'featureorder' => \@featureorder };
237
+
238
+ # Beside the options, not in them: options_map hands them to callers.
239
+ $ctx->{cleancfg} = $cleancfg;
240
240
 
241
241
  # Again over the merged result: the config's own defaults can carry one.
242
242
  # The extend instances are live objects, not option data.
@@ -22,6 +22,8 @@ class ProjectNameContext implements \JsonSerializable
22
22
  public ?array $config;
23
23
  public ?array $entopts;
24
24
  public ?array $options;
25
+ // The clean registry, beside the options rather than in them.
26
+ public ?\stdClass $cleancfg = null;
25
27
  public mixed $entity;
26
28
  public ?array $shared;
27
29
  public array $opmap;
@@ -77,6 +79,8 @@ class ProjectNameContext implements \JsonSerializable
77
79
 
78
80
  $o = ProjectNameHelpers::get_ctx_prop($ctxmap, 'options');
79
81
  $this->options = is_array($o) ? $o : ($basectx ? $basectx->options : null);
82
+ $cc = ProjectNameHelpers::get_ctx_prop($ctxmap, 'cleancfg');
83
+ $this->cleancfg = $cc instanceof \stdClass ? $cc : ($basectx ? $basectx->cleancfg : null);
80
84
 
81
85
  $e = ProjectNameHelpers::get_ctx_prop($ctxmap, 'entity');
82
86
  $this->entity = $e ?? ($basectx ? $basectx->entity : null);