@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.
- package/bin/voxgig-sdkgen +1 -1
- package/package.json +1 -1
- package/project/.sdk/model/feature/cache.aontu +6 -4
- package/project/.sdk/model/target/lua.aontu +6 -0
- package/project/.sdk/src/cmp/c/Config_c.ts +3 -134
- package/project/.sdk/src/cmp/c/TestClean_c.ts +14 -0
- package/project/.sdk/src/cmp/clojure/TestClean_clojure.ts +10 -5
- package/project/.sdk/src/cmp/cpp/TestClean_cpp.ts +13 -0
- package/project/.sdk/src/cmp/csharp/TestClean_csharp.ts +9 -0
- package/project/.sdk/src/cmp/elixir/TestClean_elixir.ts +11 -3
- package/project/.sdk/src/cmp/go/TestClean_go.ts +39 -3
- package/project/.sdk/src/cmp/java/TestClean_java.ts +8 -0
- package/project/.sdk/src/cmp/js/TestClean_js.ts +13 -5
- package/project/.sdk/src/cmp/kotlin/TestClean_kotlin.ts +22 -0
- package/project/.sdk/src/cmp/lua/TestClean_lua.ts +12 -3
- package/project/.sdk/src/cmp/ocaml/TestClean_ocaml.ts +18 -4
- package/project/.sdk/src/cmp/perl/TestClean_perl.ts +12 -3
- package/project/.sdk/src/cmp/php/TestClean_php.ts +10 -3
- package/project/.sdk/src/cmp/py/TestClean_py.ts +10 -3
- package/project/.sdk/src/cmp/rb/TestClean_rb.ts +10 -3
- package/project/.sdk/src/cmp/rust/TestClean_rust.ts +10 -0
- package/project/.sdk/src/cmp/scala/TestClean_scala.ts +34 -0
- package/project/.sdk/src/cmp/swift/TestClean_swift.ts +20 -10
- package/project/.sdk/src/cmp/ts/TestClean_ts.ts +13 -5
- package/project/.sdk/src/cmp/zig/TestClean_zig.ts +12 -0
- package/project/.sdk/tm/c/core/context.c +1 -0
- package/project/.sdk/tm/c/core/sdk.h +7 -4
- package/project/.sdk/tm/c/feature/cache.c +243 -13
- package/project/.sdk/tm/c/feature/debug.c +1 -0
- package/project/.sdk/tm/c/feature/secrets.c +27 -38
- package/project/.sdk/tm/c/feature/telemetry.c +1 -0
- package/project/.sdk/tm/c/tests/feature_test.c +142 -0
- package/project/.sdk/tm/c/utility/clean.c +26 -33
- package/project/.sdk/tm/c/utility/make_options.c +9 -8
- package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +14 -11
- package/project/.sdk/tm/clojure/src/sdk/client.clj +3 -1
- package/project/.sdk/tm/clojure/src/sdk/core.clj +19 -11
- package/project/.sdk/tm/clojure/src/sdk/features.clj +83 -10
- package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +47 -0
- package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +1 -0
- package/project/.sdk/tm/cpp/Makefile +5 -0
- package/project/.sdk/tm/cpp/core/types.hpp +11 -4
- package/project/.sdk/tm/cpp/feature/audit.hpp +6 -7
- package/project/.sdk/tm/cpp/feature/cache.hpp +188 -9
- package/project/.sdk/tm/cpp/feature/debug.hpp +1 -0
- package/project/.sdk/tm/cpp/feature/secrets.hpp +12 -0
- package/project/.sdk/tm/cpp/feature/telemetry.hpp +1 -0
- package/project/.sdk/tm/cpp/test/feature_test.cpp +128 -0
- package/project/.sdk/tm/cpp/utility/pipeline.hpp +9 -7
- package/project/.sdk/tm/csharp/core/Context.cs +4 -0
- package/project/.sdk/tm/csharp/feature/CacheFeature.cs +126 -12
- package/project/.sdk/tm/csharp/feature/DebugFeature.cs +1 -0
- package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +9 -27
- package/project/.sdk/tm/csharp/feature/TelemetryFeature.cs +1 -0
- package/project/.sdk/tm/csharp/test/FeatureTest.cs +101 -0
- package/project/.sdk/tm/csharp/utility/Clean.cs +5 -10
- package/project/.sdk/tm/csharp/utility/Fetcher.cs +7 -1
- package/project/.sdk/tm/csharp/utility/MakeOptions.cs +5 -12
- package/project/.sdk/tm/elixir/lib/projectname/context.ex +2 -0
- package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +146 -30
- package/project/.sdk/tm/elixir/lib/projectname/feature/debug.ex +1 -0
- package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +10 -56
- package/project/.sdk/tm/elixir/lib/projectname/feature/telemetry.ex +1 -0
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +18 -12
- package/project/.sdk/tm/elixir/test/feature_test.exs +84 -0
- package/project/.sdk/tm/go/core/context.go +6 -0
- package/project/.sdk/tm/go/feature/cache_feature.go +131 -4
- package/project/.sdk/tm/go/feature/debug_feature.go +3 -2
- package/project/.sdk/tm/go/feature/secrets_feature.go +17 -71
- package/project/.sdk/tm/go/feature/telemetry_feature.go +5 -4
- package/project/.sdk/tm/go/test/feature_corpus_test.go +150 -2
- package/project/.sdk/tm/go/test/feature_test.go +101 -0
- package/project/.sdk/tm/go/utility/clean.go +5 -7
- package/project/.sdk/tm/go/utility/fetcher.go +11 -0
- package/project/.sdk/tm/go/utility/make_options.go +5 -7
- package/project/.sdk/tm/java/core/Context.java +9 -0
- package/project/.sdk/tm/java/feature/CacheFeature.java +123 -17
- package/project/.sdk/tm/java/feature/DebugFeature.java +1 -0
- package/project/.sdk/tm/java/feature/SecretsFeature.java +9 -92
- package/project/.sdk/tm/java/feature/TelemetryFeature.java +1 -0
- package/project/.sdk/tm/java/test/FeatureCorpusTest.java +141 -2
- package/project/.sdk/tm/java/test/FeatureTest.java +88 -0
- package/project/.sdk/tm/java/utility/Clean.java +6 -10
- package/project/.sdk/tm/java/utility/Fetcher.java +5 -1
- package/project/.sdk/tm/java/utility/MakeOptions.java +3 -1
- package/project/.sdk/tm/js/src/Context.js +4 -0
- package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +118 -11
- package/project/.sdk/tm/js/src/feature/cost/CostFeature.js +3 -2
- package/project/.sdk/tm/js/src/feature/debug/DebugFeature.js +1 -0
- package/project/.sdk/tm/js/src/feature/metrics/MetricsFeature.js +1 -1
- package/project/.sdk/tm/js/src/feature/paging/PagingFeature.js +4 -4
- package/project/.sdk/tm/js/src/feature/rbac/RbacFeature.js +4 -4
- package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +16 -6
- package/project/.sdk/tm/js/src/feature/telemetry/TelemetryFeature.js +1 -0
- package/project/.sdk/tm/js/src/feature/validate/ValidateFeature.js +2 -1
- package/project/.sdk/tm/js/src/utility/CleanUtility.js +1 -1
- package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +6 -6
- package/project/.sdk/tm/js/test/feature/Corpus.test.js +100 -2
- package/project/.sdk/tm/js/test/feature/harness.js +3 -3
- package/project/.sdk/tm/js/test/feature.test.js +17 -0
- package/project/.sdk/tm/js/test/pipeline.test.js +1 -1
- package/project/.sdk/tm/kotlin/core/Context.kt +3 -0
- package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +102 -7
- package/project/.sdk/tm/kotlin/feature/DebugFeature.kt +1 -0
- package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +10 -20
- package/project/.sdk/tm/kotlin/feature/TelemetryFeature.kt +1 -0
- package/project/.sdk/tm/kotlin/test/FeatureTest.kt +79 -0
- package/project/.sdk/tm/kotlin/utility/CoreUtil.kt +5 -5
- package/project/.sdk/tm/kotlin/utility/Fetcher.kt +4 -0
- package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +3 -1
- package/project/.sdk/tm/lua/core/context.lua +6 -0
- package/project/.sdk/tm/lua/feature/cache_feature.lua +212 -15
- package/project/.sdk/tm/lua/feature/debug_feature.lua +1 -0
- package/project/.sdk/tm/lua/feature/secrets_feature.lua +15 -80
- package/project/.sdk/tm/lua/feature/telemetry_feature.lua +1 -0
- package/project/.sdk/tm/lua/test/feature_test.lua +108 -0
- package/project/.sdk/tm/lua/utility/clean.lua +6 -9
- package/project/.sdk/tm/lua/utility/fetcher.lua +9 -0
- package/project/.sdk/tm/lua/utility/make_options.lua +5 -5
- package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +21 -6
- package/project/.sdk/tm/ocaml/sdk_features.ml +108 -8
- package/project/.sdk/tm/ocaml/sdk_runtime.ml +13 -10
- package/project/.sdk/tm/ocaml/sdk_types.ml +2 -0
- package/project/.sdk/tm/ocaml/test/t_feature.ml +51 -1
- package/project/.sdk/tm/perl/core/context.pm +3 -0
- package/project/.sdk/tm/perl/feature/audit_feature.pm +4 -7
- package/project/.sdk/tm/perl/feature/cache_feature.pm +111 -15
- package/project/.sdk/tm/perl/feature/debug_feature.pm +1 -0
- package/project/.sdk/tm/perl/feature/secrets_feature.pm +13 -18
- package/project/.sdk/tm/perl/feature/telemetry_feature.pm +1 -0
- package/project/.sdk/tm/perl/t/feature.t +86 -0
- package/project/.sdk/tm/perl/t/feature_corpus.t +80 -4
- package/project/.sdk/tm/perl/utility/clean.pm +6 -8
- package/project/.sdk/tm/perl/utility/fetcher.pm +4 -0
- package/project/.sdk/tm/perl/utility/make_options.pm +5 -5
- package/project/.sdk/tm/php/core/Context.php +4 -0
- package/project/.sdk/tm/php/feature/CacheFeature.php +98 -13
- package/project/.sdk/tm/php/feature/DebugFeature.php +1 -0
- package/project/.sdk/tm/php/feature/SecretsFeature.php +18 -15
- package/project/.sdk/tm/php/feature/TelemetryFeature.php +1 -0
- package/project/.sdk/tm/php/test/FeatureCorpusTest.php +113 -3
- package/project/.sdk/tm/php/test/FeatureTest.php +90 -0
- package/project/.sdk/tm/php/utility/Clean.php +3 -10
- package/project/.sdk/tm/php/utility/Fetcher.php +8 -3
- package/project/.sdk/tm/php/utility/MakeOptions.php +5 -7
- package/project/.sdk/tm/py/pkg/core/context.py +4 -0
- package/project/.sdk/tm/py/pkg/feature/cache_feature.py +79 -13
- package/project/.sdk/tm/py/pkg/feature/debug_feature.py +1 -0
- package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +15 -66
- package/project/.sdk/tm/py/pkg/feature/telemetry_feature.py +1 -0
- package/project/.sdk/tm/py/pkg/utility/clean.py +4 -10
- package/project/.sdk/tm/py/pkg/utility/make_options.py +8 -9
- package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +23 -9
- package/project/.sdk/tm/py/test/test_feature.py +73 -0
- package/project/.sdk/tm/py/test/test_feature_corpus.py +88 -3
- package/project/.sdk/tm/rb/core/context.rb +4 -1
- package/project/.sdk/tm/rb/feature/audit_feature.rb +6 -5
- package/project/.sdk/tm/rb/feature/cache_feature.rb +75 -11
- package/project/.sdk/tm/rb/feature/debug_feature.rb +1 -0
- package/project/.sdk/tm/rb/feature/secrets_feature.rb +9 -64
- package/project/.sdk/tm/rb/feature/telemetry_feature.rb +1 -0
- package/project/.sdk/tm/rb/test/feature_corpus_test.rb +85 -3
- package/project/.sdk/tm/rb/test/feature_test.rb +93 -0
- package/project/.sdk/tm/rb/utility/clean.rb +6 -7
- package/project/.sdk/tm/rb/utility/fetcher.rb +6 -0
- package/project/.sdk/tm/rb/utility/make_options.rb +5 -5
- package/project/.sdk/tm/rust/core/context.rs +8 -0
- package/project/.sdk/tm/rust/feature/cache.rs +120 -3
- package/project/.sdk/tm/rust/feature/debug.rs +1 -0
- package/project/.sdk/tm/rust/feature/secrets.rs +36 -98
- package/project/.sdk/tm/rust/feature/telemetry.rs +1 -0
- package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +3 -3
- package/project/.sdk/tm/rust/tests/feature_test.rs +141 -0
- package/project/.sdk/tm/rust/utility/clean.rs +35 -43
- package/project/.sdk/tm/rust/utility/fetcher.rs +6 -0
- package/project/.sdk/tm/rust/utility/make_options.rs +8 -11
- package/project/.sdk/tm/scala/core/Context.scala +4 -0
- package/project/.sdk/tm/scala/feature/CacheFeature.scala +117 -11
- package/project/.sdk/tm/scala/feature/DebugFeature.scala +1 -0
- package/project/.sdk/tm/scala/feature/SecretsFeature.scala +11 -24
- package/project/.sdk/tm/scala/feature/TelemetryFeature.scala +1 -0
- package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +52 -1
- package/project/.sdk/tm/scala/utility/Fetcher.scala +5 -0
- package/project/.sdk/tm/scala/utility/Make.scala +3 -1
- package/project/.sdk/tm/scala/utility/Misc.scala +5 -8
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Context.swift +3 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +122 -11
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/DebugFeature.swift +1 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +9 -13
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TelemetryFeature.swift +1 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +4 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/MakeOptions.swift +5 -4
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/ResultUtil.swift +4 -5
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +79 -0
- package/project/.sdk/tm/ts/src/Context.ts +4 -0
- package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +115 -4
- package/project/.sdk/tm/ts/src/feature/cost/CostFeature.ts +3 -2
- package/project/.sdk/tm/ts/src/feature/debug/DebugFeature.ts +1 -0
- package/project/.sdk/tm/ts/src/feature/metrics/MetricsFeature.ts +1 -1
- package/project/.sdk/tm/ts/src/feature/paging/PagingFeature.ts +4 -4
- package/project/.sdk/tm/ts/src/feature/rbac/RbacFeature.ts +4 -4
- package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +14 -2
- package/project/.sdk/tm/ts/src/feature/telemetry/TelemetryFeature.ts +1 -0
- package/project/.sdk/tm/ts/src/feature/validate/ValidateFeature.ts +2 -1
- package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +1 -1
- package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +6 -6
- package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +101 -2
- package/project/.sdk/tm/ts/test/feature/harness.ts +3 -3
- package/project/.sdk/tm/ts/test/feature.test.ts +17 -0
- package/project/.sdk/tm/ts/test/pipeline.test.ts +1 -1
- package/project/.sdk/tm/zig/core/context.zig +5 -0
- package/project/.sdk/tm/zig/core/utility.zig +11 -9
- package/project/.sdk/tm/zig/feature/cache.zig +144 -13
- package/project/.sdk/tm/zig/feature/debug.zig +1 -0
- package/project/.sdk/tm/zig/feature/secrets.zig +6 -1
- package/project/.sdk/tm/zig/feature/telemetry.zig +1 -0
- package/project/.sdk/tm/zig/test/feature_test.zig +100 -0
- package/project/sdkgen-package.json +1 -1
|
@@ -156,6 +156,66 @@ async function usableOps(want) {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
|
|
159
|
+
|
|
160
|
+
const READ_OPS = ['list', 'load']
|
|
161
|
+
const WRITE_OPS = ['create', 'update', 'patch', 'remove']
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
// A read and a write of one entity (#READ, #WRITE), each driven as usableOps
|
|
165
|
+
// drives an op; #ITEM is a write of the same entity driven with ITEM_ARGS.
|
|
166
|
+
async function usablePair() {
|
|
167
|
+
const found = {}
|
|
168
|
+
for (const cand of candidates(makeClient({}))) {
|
|
169
|
+
const role = READ_OPS.includes(cand.op) ? 'read' : WRITE_OPS.includes(cand.op) ? 'write' : ''
|
|
170
|
+
const seen = found[cand.entity] = found[cand.entity] || {}
|
|
171
|
+
if ('' === role || null != seen[role]) { continue }
|
|
172
|
+
try {
|
|
173
|
+
await makeClient({})[cand.accessor]()[cand.op]({}, {})
|
|
174
|
+
}
|
|
175
|
+
catch (e) { continue }
|
|
176
|
+
seen[role] = cand
|
|
177
|
+
if (null != seen.read && null != seen.write) {
|
|
178
|
+
return { read: seen.read, write: seen.write, item: await usableItem(cand.entity) }
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return undefined
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
const ITEM_ARGS = { id: 'corpus-item' }
|
|
186
|
+
|
|
187
|
+
async function usableItem(entity) {
|
|
188
|
+
for (const cand of candidates(makeClient({}))) {
|
|
189
|
+
if (entity !== cand.entity || !['update', 'patch', 'remove'].includes(cand.op)) { continue }
|
|
190
|
+
try {
|
|
191
|
+
await makeClient({})[cand.accessor]()[cand.op]({ ...ITEM_ARGS }, {})
|
|
192
|
+
return cand
|
|
193
|
+
}
|
|
194
|
+
catch (e) { continue }
|
|
195
|
+
}
|
|
196
|
+
return undefined
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
// A step may wait before its call, may add request headers for its call, and
|
|
201
|
+
// may pass `args` as the operation's first argument.
|
|
202
|
+
async function runStep(client, ref, step) {
|
|
203
|
+
if (null != step.wait) {
|
|
204
|
+
await new Promise((resolve) => setTimeout(resolve, step.wait))
|
|
205
|
+
}
|
|
206
|
+
const options = client._rootctx.options
|
|
207
|
+
const prior = options.headers
|
|
208
|
+
if (null != step.headers) {
|
|
209
|
+
options.headers = { ...(prior || {}), ...step.headers }
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
await client[ref.accessor]()[ref.op]({ ...(step.args || {}) }, step.ctrl || {})
|
|
213
|
+
}
|
|
214
|
+
finally {
|
|
215
|
+
options.headers = prior
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
159
219
|
// Replace #OP1/#OP2 throughout a case, keys included.
|
|
160
220
|
function resolve(node, tokens) {
|
|
161
221
|
if ('string' === typeof node) {
|
|
@@ -169,7 +229,9 @@ function resolve(node, tokens) {
|
|
|
169
229
|
if (null != node && 'object' === typeof node) {
|
|
170
230
|
const out = {}
|
|
171
231
|
for (const k of Object.keys(node)) {
|
|
172
|
-
out
|
|
232
|
+
Object.defineProperty(out, resolve(k, tokens), {
|
|
233
|
+
value: resolve(node[k], tokens), enumerable: true, writable: true, configurable: true,
|
|
234
|
+
})
|
|
173
235
|
}
|
|
174
236
|
return out
|
|
175
237
|
}
|
|
@@ -177,6 +239,15 @@ function resolve(node, tokens) {
|
|
|
177
239
|
}
|
|
178
240
|
|
|
179
241
|
|
|
242
|
+
// No case may write onto the shared prototypes, as a `__proto__` key can.
|
|
243
|
+
function shared() {
|
|
244
|
+
return [Object.prototype, Object]
|
|
245
|
+
.map((o) => Object.getOwnPropertyNames(o).sort().join(',')).join(' | ')
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const PRISTINE = shared()
|
|
249
|
+
|
|
250
|
+
|
|
180
251
|
// Which #OPn tokens a case uses. A case wanting more operations than this SDK
|
|
181
252
|
// has is skipped rather than failed.
|
|
182
253
|
function tokensUsed(kase) {
|
|
@@ -214,6 +285,7 @@ describe('FeatureCorpus', () => {
|
|
|
214
285
|
let corpus
|
|
215
286
|
let ops = []
|
|
216
287
|
let byKey = {}
|
|
288
|
+
let pair
|
|
217
289
|
|
|
218
290
|
|
|
219
291
|
before(async () => {
|
|
@@ -221,6 +293,10 @@ describe('FeatureCorpus', () => {
|
|
|
221
293
|
ops = await usableOps(2)
|
|
222
294
|
byKey = {}
|
|
223
295
|
for (const o of ops) { byKey[o.key] = o }
|
|
296
|
+
pair = await usablePair()
|
|
297
|
+
for (const o of pair ? [pair.read, pair.write, pair.item] : []) {
|
|
298
|
+
if (null != o) { byKey[o.key] = o }
|
|
299
|
+
}
|
|
224
300
|
})
|
|
225
301
|
|
|
226
302
|
|
|
@@ -285,6 +361,20 @@ describe('FeatureCorpus', () => {
|
|
|
285
361
|
continue
|
|
286
362
|
}
|
|
287
363
|
|
|
364
|
+
const paired = /#(READ|WRITE|ITEM|OTHER)\b/.test(JSON.stringify(raw))
|
|
365
|
+
if (paired && null == pair) {
|
|
366
|
+
t.diagnostic(`skip "${raw.name}": needs a read and a write of one entity, this SDK offers none`)
|
|
367
|
+
continue
|
|
368
|
+
}
|
|
369
|
+
const other = null == pair ? undefined :
|
|
370
|
+
ops.find((o) => o.entity !== pair.read.entity)
|
|
371
|
+
const lacking = [['#ITEM', pair?.item], ['#OTHER', other]]
|
|
372
|
+
.find(([tok, op]) => null == op && new RegExp(tok + '\\b').test(JSON.stringify(raw)))
|
|
373
|
+
if (null != lacking) {
|
|
374
|
+
t.diagnostic(`skip "${raw.name}": needs ${lacking[0]}, which this SDK cannot drive`)
|
|
375
|
+
continue
|
|
376
|
+
}
|
|
377
|
+
|
|
288
378
|
const missing = missingFeature(probe, raw)
|
|
289
379
|
if (null != missing) {
|
|
290
380
|
t.diagnostic(`skip "${raw.name}": needs the ${missing} feature, ` +
|
|
@@ -294,6 +384,12 @@ describe('FeatureCorpus', () => {
|
|
|
294
384
|
|
|
295
385
|
const tokens = {}
|
|
296
386
|
for (let i = 0; i < need; i++) { tokens['#OP' + (i + 1)] = ops[i].key }
|
|
387
|
+
if (paired && null != pair) {
|
|
388
|
+
tokens['#READ'] = pair.read.key
|
|
389
|
+
tokens['#WRITE'] = pair.write.key
|
|
390
|
+
if (null != pair.item) { tokens['#ITEM'] = pair.item.key }
|
|
391
|
+
if (null != other) { tokens['#OTHER'] = other.key }
|
|
392
|
+
}
|
|
297
393
|
|
|
298
394
|
const kase = resolve(raw, tokens)
|
|
299
395
|
ran++
|
|
@@ -307,7 +403,7 @@ describe('FeatureCorpus', () => {
|
|
|
307
403
|
ok(null != ref, `${kase.name}: no operation ${step.op}`)
|
|
308
404
|
let err = undefined
|
|
309
405
|
try {
|
|
310
|
-
await client
|
|
406
|
+
await runStep(client, ref, step)
|
|
311
407
|
}
|
|
312
408
|
catch (e) {
|
|
313
409
|
err = e
|
|
@@ -324,6 +420,8 @@ describe('FeatureCorpus', () => {
|
|
|
324
420
|
}
|
|
325
421
|
|
|
326
422
|
subset(client[`_${name}`], kase.out, `${kase.name}: _${name}`)
|
|
423
|
+
deepStrictEqual(shared(), PRISTINE,
|
|
424
|
+
`${kase.name}: the case wrote onto Object or Object.prototype`)
|
|
327
425
|
}
|
|
328
426
|
catch (err) {
|
|
329
427
|
const msg = String(err?.message ?? err)
|
|
@@ -92,9 +92,8 @@ function makeClient(spec) {
|
|
|
92
92
|
|
|
93
93
|
// One clean registry per client, as makeOptions gives a real one, so a value
|
|
94
94
|
// a feature registers with cleanAdd is masked by every clean after it.
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
}).__derived__
|
|
95
|
+
const regctx = { utility, options: { feature: { test: { active: true } } }, config: {} }
|
|
96
|
+
const derived = stdutil.makeOptions(regctx).__derived__
|
|
98
97
|
|
|
99
98
|
const client = {
|
|
100
99
|
_mode: spec.mode || 'test',
|
|
@@ -120,6 +119,7 @@ function makeClient(spec) {
|
|
|
120
119
|
client,
|
|
121
120
|
utility,
|
|
122
121
|
options: client._options,
|
|
122
|
+
cleancfg: regctx.cleancfg,
|
|
123
123
|
out: {},
|
|
124
124
|
ctrl: over.ctrl || {},
|
|
125
125
|
meta: {},
|
|
@@ -455,6 +455,23 @@ describe('feature', () => {
|
|
|
455
455
|
})
|
|
456
456
|
|
|
457
457
|
|
|
458
|
+
// --- one call, one id -----------------------------------------------------
|
|
459
|
+
if (hasFeature('telemetry') && hasFeature('debug') && hasFeature('audit')) {
|
|
460
|
+
test('telemetry, debug and audit carry one call\'s context id', async () => {
|
|
461
|
+
const h = makeClient({ features: [{ name: 'telemetry' }, { name: 'debug' }, { name: 'audit' }] })
|
|
462
|
+
await h.op({ op: 'load' })
|
|
463
|
+
await h.op({ op: 'list' })
|
|
464
|
+
const ids = (recs) => recs.map((rec) => rec.correlationId)
|
|
465
|
+
const calls = ids(h.client._audit.records)
|
|
466
|
+
strictEqual(calls.length, 2)
|
|
467
|
+
ok(calls.every((id) => 'string' === typeof id && '' !== id), JSON.stringify(calls))
|
|
468
|
+
ok(calls[0] !== calls[1])
|
|
469
|
+
deepStrictEqual(ids(h.client._telemetry.spans), calls)
|
|
470
|
+
deepStrictEqual(ids(h.client._debug.entries), calls)
|
|
471
|
+
})
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
|
|
458
475
|
// --- clienttrack ----------------------------------------------------------
|
|
459
476
|
if (hasFeature('clienttrack')) describe('clienttrack', () => {
|
|
460
477
|
|
|
@@ -559,7 +559,7 @@ describe('pipeline:result helpers', () => {
|
|
|
559
559
|
const secret = 'PIPELINE-SECRET-a1b2c3d4e5f6'
|
|
560
560
|
const text = 'x'.repeat(150) + secret + 'y'.repeat(100)
|
|
561
561
|
const ctx = base({
|
|
562
|
-
|
|
562
|
+
cleancfg: { active: true, keys: [], values: [], mask: '[redacted]', hint: 0, min: 4 },
|
|
563
563
|
spec: { headers: { 'user-agent': 'Probe ' + secret } },
|
|
564
564
|
response: { body: 'body', json: async () => { throw Object.assign(new SyntaxError('bad json'), { text }) } },
|
|
565
565
|
result: { status: 200, headers: { 'content-type': 'text/html' } },
|
|
@@ -20,6 +20,8 @@ class Context(ctxmap: MutableMap<String, Any?>?, basectx: Context?) {
|
|
|
20
20
|
var config: MutableMap<String, Any?>? = null
|
|
21
21
|
var entopts: MutableMap<String, Any?>? = null
|
|
22
22
|
var options: MutableMap<String, Any?>? = null
|
|
23
|
+
// The clean registry, beside the options rather than in them.
|
|
24
|
+
var cleancfg: Any? = null
|
|
23
25
|
var opmap: MutableMap<String, Operation>? = null
|
|
24
26
|
var response: Response? = null
|
|
25
27
|
var result: Result? = null
|
|
@@ -116,6 +118,7 @@ class Context(ctxmap: MutableMap<String, Any?>?, basectx: Context?) {
|
|
|
116
118
|
if (this.options == null && basectx != null) {
|
|
117
119
|
this.options = basectx.options
|
|
118
120
|
}
|
|
121
|
+
this.cleancfg = Helpers.getCtxProp(ctxmap, "cleancfg") ?: basectx?.cleancfg
|
|
119
122
|
|
|
120
123
|
// Entity
|
|
121
124
|
val e = Helpers.getCtxProp(ctxmap, "entity")
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
package KOTLINPACKAGE.feature
|
|
2
2
|
|
|
3
|
+
import java.security.SecureRandom
|
|
3
4
|
import java.util.function.Supplier
|
|
5
|
+
import javax.crypto.Mac
|
|
6
|
+
import javax.crypto.spec.SecretKeySpec
|
|
4
7
|
|
|
5
8
|
import KOTLINPACKAGE.core.Context
|
|
6
9
|
import KOTLINPACKAGE.core.FetcherFn
|
|
7
10
|
import KOTLINPACKAGE.core.SdkClient
|
|
8
11
|
import KOTLINPACKAGE.utility.Media
|
|
9
12
|
|
|
10
|
-
// Response caching for safe (read) requests
|
|
11
|
-
//
|
|
12
|
-
// method+URL was fetched within `ttl` ms (default: 5000). Only successful
|
|
13
|
-
// (2xx) responses to cacheable methods (default: GET) are stored.
|
|
13
|
+
// Response caching for safe (read) requests, per client: see the features
|
|
14
|
+
// reference for the key, the write invalidation and the Cache-Control rules.
|
|
14
15
|
@Suppress("UNCHECKED_CAST")
|
|
15
16
|
class CacheFeature : BaseFeature("cache", "0.0.1", true) {
|
|
16
17
|
|
|
@@ -18,6 +19,7 @@ class CacheFeature : BaseFeature("cache", "0.0.1", true) {
|
|
|
18
19
|
private var options: MutableMap<String, Any?>? = null
|
|
19
20
|
private var store: MutableMap<String, CacheEntry> = linkedMapOf()
|
|
20
21
|
private var order: MutableList<String> = mutableListOf()
|
|
22
|
+
private var secret: SecretKeySpec? = null
|
|
21
23
|
|
|
22
24
|
// Activity tracking (mirrors the ts client._cache record).
|
|
23
25
|
var hit = 0
|
|
@@ -26,6 +28,7 @@ class CacheFeature : BaseFeature("cache", "0.0.1", true) {
|
|
|
26
28
|
|
|
27
29
|
private class CacheEntry {
|
|
28
30
|
var expiry: Long = 0
|
|
31
|
+
var scope: String = ""
|
|
29
32
|
lateinit var snapshot: CacheSnapshot
|
|
30
33
|
}
|
|
31
34
|
|
|
@@ -47,6 +50,9 @@ class CacheFeature : BaseFeature("cache", "0.0.1", true) {
|
|
|
47
50
|
|
|
48
51
|
this.store = linkedMapOf()
|
|
49
52
|
this.order = mutableListOf()
|
|
53
|
+
val key = ByteArray(32)
|
|
54
|
+
SecureRandom().nextBytes(key)
|
|
55
|
+
this.secret = SecretKeySpec(key, "HmacSHA256")
|
|
50
56
|
|
|
51
57
|
val inner: FetcherFn = ctx.utility!!.fetcher
|
|
52
58
|
|
|
@@ -72,10 +78,17 @@ class CacheFeature : BaseFeature("cache", "0.0.1", true) {
|
|
|
72
78
|
}
|
|
73
79
|
}
|
|
74
80
|
if (!cacheable) {
|
|
75
|
-
|
|
81
|
+
if (method in SAFE_METHODS) {
|
|
82
|
+
return inner(ctx, url, fetchdef)
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
return inner(ctx, url, fetchdef)
|
|
86
|
+
} finally {
|
|
87
|
+
invalidate(url)
|
|
88
|
+
}
|
|
76
89
|
}
|
|
77
90
|
|
|
78
|
-
val key = "$method $url"
|
|
91
|
+
val key = "$method $url " + digest(fetchdef["headers"])
|
|
79
92
|
val now = FeatureOptions.foptNow(this.options).getAsLong()
|
|
80
93
|
|
|
81
94
|
val hitEntry = this.store[key]
|
|
@@ -100,10 +113,16 @@ class CacheFeature : BaseFeature("cache", "0.0.1", true) {
|
|
|
100
113
|
|
|
101
114
|
if (storable(res)) {
|
|
102
115
|
val snapshot = snapshot(res)
|
|
103
|
-
val ttl = FeatureOptions.foptInt(this.options, "ttl", 5000)
|
|
116
|
+
val ttl = lifetime(snapshot.headers, FeatureOptions.foptInt(this.options, "ttl", 5000).toLong())
|
|
117
|
+
if (ttl <= 0) {
|
|
118
|
+
this.bypass++
|
|
119
|
+
return replay(snapshot)
|
|
120
|
+
}
|
|
121
|
+
drop(key)
|
|
104
122
|
evict()
|
|
105
123
|
val entry = CacheEntry()
|
|
106
124
|
entry.expiry = now + ttl
|
|
125
|
+
entry.scope = scope(url)
|
|
107
126
|
entry.snapshot = snapshot
|
|
108
127
|
this.store[key] = entry
|
|
109
128
|
this.order.add(key)
|
|
@@ -115,6 +134,39 @@ class CacheFeature : BaseFeature("cache", "0.0.1", true) {
|
|
|
115
134
|
return res
|
|
116
135
|
}
|
|
117
136
|
|
|
137
|
+
private fun digest(headers: Any?): String {
|
|
138
|
+
val pairs = mutableListOf<Pair<String, String>>()
|
|
139
|
+
if (headers is Map<*, *>) {
|
|
140
|
+
for ((name, value) in headers) {
|
|
141
|
+
if (value != null) {
|
|
142
|
+
pairs.add(Pair(name.toString().lowercase(), value.toString()))
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
pairs.sortWith(compareBy<Pair<String, String>> { it.first }.thenBy { it.second })
|
|
147
|
+
val mac = Mac.getInstance("HmacSHA256")
|
|
148
|
+
mac.init(this.secret)
|
|
149
|
+
for ((name, value) in pairs) {
|
|
150
|
+
mac.update("$name:$value\n".toByteArray(Charsets.UTF_8))
|
|
151
|
+
}
|
|
152
|
+
return mac.doFinal().joinToString("") { "%02x".format(it) }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private fun invalidate(url: String) {
|
|
156
|
+
val path = scope(url)
|
|
157
|
+
val collection = parent(path)
|
|
158
|
+
val dropped = this.store.filterValues { under(it.scope, path) || it.scope == collection }.keys.toList()
|
|
159
|
+
for (key in dropped) {
|
|
160
|
+
drop(key)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private fun drop(key: String) {
|
|
165
|
+
if (this.store.remove(key) != null) {
|
|
166
|
+
this.order.remove(key)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
118
170
|
// A body the transport could not read as JSON passes through, for the operation to report.
|
|
119
171
|
private fun storable(res: Any?): Boolean {
|
|
120
172
|
val status = FeatureOptions.fresStatus(res)
|
|
@@ -177,4 +229,47 @@ class CacheFeature : BaseFeature("cache", "0.0.1", true) {
|
|
|
177
229
|
this.store.remove(oldest)
|
|
178
230
|
}
|
|
179
231
|
}
|
|
232
|
+
|
|
233
|
+
companion object {
|
|
234
|
+
private val SAFE_METHODS = listOf("GET", "HEAD")
|
|
235
|
+
private val UNSTORED = listOf("no-store", "private", "no-cache")
|
|
236
|
+
private val MAX_AGE = Regex("^max-age\\s*=\\s*\"?(\\d+)\"?$")
|
|
237
|
+
|
|
238
|
+
// The configured ttl capped by the response's Cache-Control; zero when
|
|
239
|
+
// the response may not be stored.
|
|
240
|
+
private fun lifetime(headers: Map<String, Any?>, ttl: Long): Long {
|
|
241
|
+
var control = ""
|
|
242
|
+
for ((name, value) in headers) {
|
|
243
|
+
if (name.lowercase() == "cache-control") {
|
|
244
|
+
control = value.toString().lowercase()
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
var life = ttl
|
|
248
|
+
for (part in control.split(",")) {
|
|
249
|
+
val directive = part.trim()
|
|
250
|
+
if (directive in UNSTORED) {
|
|
251
|
+
return 0
|
|
252
|
+
}
|
|
253
|
+
val secs = MAX_AGE.matchEntire(directive)?.groupValues?.get(1)?.toLongOrNull()
|
|
254
|
+
if (secs != null) {
|
|
255
|
+
life = minOf(life, secs * 1000)
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return life
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
private fun scope(url: String): String = url.split(Regex("[?#]"), 2)[0].trimEnd('/')
|
|
262
|
+
|
|
263
|
+
private fun parent(scope: String): String {
|
|
264
|
+
val scheme = scope.indexOf("://")
|
|
265
|
+
val root = if (scheme < 0) 0 else scope.indexOf('/', scheme + 3)
|
|
266
|
+
if (root < 0) {
|
|
267
|
+
return scope
|
|
268
|
+
}
|
|
269
|
+
return scope.substring(0, maxOf(scope.lastIndexOf('/'), root))
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
private fun under(scope: String, prefix: String): Boolean =
|
|
273
|
+
scope == prefix || scope.startsWith("$prefix/")
|
|
274
|
+
}
|
|
180
275
|
}
|
|
@@ -34,6 +34,7 @@ class DebugFeature : BaseFeature("debug", "0.0.1", true) {
|
|
|
34
34
|
|
|
35
35
|
val entry = linkedMapOf<String, Any?>()
|
|
36
36
|
entry["op"] = "$entity.$opname"
|
|
37
|
+
entry["correlationId"] = ctx.id
|
|
37
38
|
entry["start"] = FeatureOptions.foptNow(this.options).getAsLong()
|
|
38
39
|
val spec = ctx.spec
|
|
39
40
|
if (spec != null) {
|
|
@@ -21,7 +21,7 @@ import KOTLINPACKAGE.feature.secrets.sekreto.SekretoError
|
|
|
21
21
|
import KOTLINPACKAGE.feature.secrets.sekreto.envkey
|
|
22
22
|
import KOTLINPACKAGE.feature.secrets.sekreto.specof
|
|
23
23
|
import KOTLINPACKAGE.feature.secrets.sekreto.Json as SekJson
|
|
24
|
-
import KOTLINPACKAGE.utility.
|
|
24
|
+
import KOTLINPACKAGE.utility.fetcher
|
|
25
25
|
import KOTLINPACKAGE.utility.resolveLocation
|
|
26
26
|
import KOTLINPACKAGE.utility.struct.Struct
|
|
27
27
|
|
|
@@ -83,6 +83,7 @@ private const val REDIRECT_MAX = 5
|
|
|
83
83
|
class SecretsFeature : BaseFeature("secrets", "0.1.0", true) {
|
|
84
84
|
|
|
85
85
|
private var client: SdkClient? = null
|
|
86
|
+
private var rootctx: Context? = null
|
|
86
87
|
|
|
87
88
|
// Every value this feature resolves or buys is a secret the SDK handles,
|
|
88
89
|
// and none arrives under an option key the intake registration saw.
|
|
@@ -170,6 +171,7 @@ class SecretsFeature : BaseFeature("secrets", "0.1.0", true) {
|
|
|
170
171
|
// Sync by feature contract: build the chain, never look anything up here.
|
|
171
172
|
override fun init(ctx: Context, options: MutableMap<String, Any?>) {
|
|
172
173
|
this.client = ctx.client
|
|
174
|
+
this.rootctx = ctx
|
|
173
175
|
this.fopts = options
|
|
174
176
|
this.liveopts = ctx.options ?: linkedMapOf()
|
|
175
177
|
this.active = FeatureOptions.foptBool(options, "active", false)
|
|
@@ -704,27 +706,15 @@ class SecretsFeature : BaseFeature("secrets", "0.1.0", true) {
|
|
|
704
706
|
"body" to body,
|
|
705
707
|
// Never followed by the client: a redirect would carry the refresh token on.
|
|
706
708
|
"redirect" to "manual",
|
|
709
|
+
// Its own bound, in milliseconds: the timeout feature's wrapper is above it.
|
|
710
|
+
"timeout" to 30000,
|
|
707
711
|
)
|
|
708
712
|
|
|
709
|
-
//
|
|
710
|
-
//
|
|
711
|
-
// the first expiry
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
// so the ordinary case needs no custom transport; a supplied
|
|
715
|
-
// system.fetch is honoured so a test can intercept the purchase.
|
|
716
|
-
var sysFetch = Struct.getpath(options, listOf("system", "fetch"))
|
|
717
|
-
if (sysFetch === Struct.UNDEF) {
|
|
718
|
-
sysFetch = null
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
val ask = { at: String ->
|
|
722
|
-
if (sysFetch is BiFunction<*, *, *>) {
|
|
723
|
-
(sysFetch as BiFunction<String, MutableMap<String, Any?>, Any?>).apply(at, fetchdef)
|
|
724
|
-
} else {
|
|
725
|
-
defaultHttpFetch(at, fetchdef)
|
|
726
|
-
}
|
|
727
|
-
}
|
|
713
|
+
// The SDK's own transport, beneath every feature's wrapper: it holds the
|
|
714
|
+
// test feature's block and the GET-only guard, and the wrapped one would
|
|
715
|
+
// recurse on the first expiry.
|
|
716
|
+
val rctx = this.rootctx!!
|
|
717
|
+
val ask = { at: String -> fetcher(rctx, at, fetchdef) }
|
|
728
718
|
|
|
729
719
|
var res: Any? = ask(url)
|
|
730
720
|
|
|
@@ -40,6 +40,7 @@ class TelemetryFeature : BaseFeature("telemetry", "0.0.1", true) {
|
|
|
40
40
|
val span = linkedMapOf<String, Any?>()
|
|
41
41
|
span["traceId"] = id("trace")
|
|
42
42
|
span["spanId"] = id("span")
|
|
43
|
+
span["correlationId"] = ctx.id
|
|
43
44
|
span["name"] = "$entity.$opname"
|
|
44
45
|
span["start"] = FeatureOptions.foptNow(this.options).getAsLong()
|
|
45
46
|
ctx.out[TELEMETRY_SPAN_KEY] = span
|
|
@@ -453,6 +453,65 @@ class FeatureTest {
|
|
|
453
453
|
assertEquals(3, rec.calls.size, "expected 3 calls")
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
+
@Test
|
|
457
|
+
fun cache_keysOnRequestHeaders() {
|
|
458
|
+
assumeFeatures("cache")
|
|
459
|
+
val rec = FhRecorder()
|
|
460
|
+
val h = fhMake(rec::fetch, fhF(CacheFeature(), fhMap("ttl", 10000)))
|
|
461
|
+
h.op(fhOp("load").path("/w/1").headers(fhMap("x-tenant", "tenant-a")))
|
|
462
|
+
h.op(fhOp("load").path("/w/1").headers(fhMap("X-Tenant", "tenant-b")))
|
|
463
|
+
assertEquals(2, rec.calls.size, "a second tenant was served the first tenant's entry")
|
|
464
|
+
h.op(fhOp("load").path("/w/1").headers(fhMap("x-tenant", "tenant-b")))
|
|
465
|
+
assertEquals(2, rec.calls.size, "the same headers did not share an entry")
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
@Test
|
|
469
|
+
fun cache_aWriteDropsItsCollection() {
|
|
470
|
+
assumeFeatures("cache")
|
|
471
|
+
val rec = FhRecorder()
|
|
472
|
+
val f = CacheFeature()
|
|
473
|
+
val h = fhMake(rec::fetch, fhF(f, fhMap("ttl", 10000)))
|
|
474
|
+
val paths = listOf("/w/1", "/w", "/w/1/part", "/other/1", "/w/2")
|
|
475
|
+
for (p in paths) {
|
|
476
|
+
h.op(fhOp("load").path(p))
|
|
477
|
+
}
|
|
478
|
+
h.op(fhOp("update").method("PUT").path("/w/1"))
|
|
479
|
+
for (p in paths) {
|
|
480
|
+
h.op(fhOp("load").path(p))
|
|
481
|
+
}
|
|
482
|
+
assertEquals(9, rec.calls.size, "expected the collection refetched and /other cached")
|
|
483
|
+
assertEquals(2, f.hit, "expected /other served from cache")
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
@Test
|
|
487
|
+
fun cache_cacheControlPreventsStoring() {
|
|
488
|
+
assumeFeatures("cache")
|
|
489
|
+
for (control in listOf("no-store", "private", "No-Cache", "max-age=60, private")) {
|
|
490
|
+
val rec = FhRecorder()
|
|
491
|
+
rec.reply = { _, _ -> fhResponse(200, fhMap("ok", true), fhMap("Cache-Control", control)) }
|
|
492
|
+
val h = fhMake(rec::fetch, fhF(CacheFeature(), fhMap("ttl", 10000)))
|
|
493
|
+
h.op(fhOp("load").path("/w"))
|
|
494
|
+
h.op(fhOp("load").path("/w"))
|
|
495
|
+
assertEquals(2, rec.calls.size, "$control was stored")
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
@Test
|
|
500
|
+
fun cache_maxAgeCapsTheTtl() {
|
|
501
|
+
assumeFeatures("cache")
|
|
502
|
+
val clock = FhClock()
|
|
503
|
+
val rec = FhRecorder()
|
|
504
|
+
rec.reply = { _, _ -> fhResponse(200, fhMap("ok", true), fhMap("cache-control", "max-age=1")) }
|
|
505
|
+
val h = fhMake(rec::fetch, fhF(CacheFeature(), fhMap("ttl", 10000, "now", nowFn(clock))))
|
|
506
|
+
h.op(fhOp("load").path("/w"))
|
|
507
|
+
clock.advance(500)
|
|
508
|
+
h.op(fhOp("load").path("/w"))
|
|
509
|
+
assertEquals(1, rec.calls.size, "expected a hit inside max-age")
|
|
510
|
+
clock.advance(600)
|
|
511
|
+
h.op(fhOp("load").path("/w"))
|
|
512
|
+
assertEquals(2, rec.calls.size, "expected max-age=1 to expire the entry before the ttl")
|
|
513
|
+
}
|
|
514
|
+
|
|
456
515
|
@Test
|
|
457
516
|
fun cache_inactiveDoesNotWrap() {
|
|
458
517
|
assumeFeatures("cache")
|
|
@@ -768,6 +827,26 @@ class FeatureTest {
|
|
|
768
827
|
assertEquals(0, f.records.size, "expected no records")
|
|
769
828
|
}
|
|
770
829
|
|
|
830
|
+
// --- one call, one id -----------------------------------------------------------
|
|
831
|
+
|
|
832
|
+
@Test
|
|
833
|
+
fun correlation_telemetryDebugAndAuditCarryOneCallsContextId() {
|
|
834
|
+
assumeFeatures("telemetry", "debug", "audit")
|
|
835
|
+
val telemetry = TelemetryFeature()
|
|
836
|
+
val debug = DebugFeature()
|
|
837
|
+
val audit = AuditFeature()
|
|
838
|
+
val h = fhMake(null, fhF(telemetry, null), fhF(debug, null), fhF(audit, null))
|
|
839
|
+
h.op(fhOp("load"))
|
|
840
|
+
h.op(fhOp("list"))
|
|
841
|
+
val ids = { recs: List<Map<String, Any?>> -> recs.map { it["correlationId"] } }
|
|
842
|
+
val calls = ids(audit.records)
|
|
843
|
+
assertEquals(2, calls.size, "expected one audit record per call")
|
|
844
|
+
assertTrue(calls.all { it is String && "" != it }, "expected a context id per call, got $calls")
|
|
845
|
+
assertNotEquals(calls[0], calls[1], "expected a different id per call")
|
|
846
|
+
assertEquals(calls, ids(telemetry.spans), "expected the spans to carry the audit ids")
|
|
847
|
+
assertEquals(calls, ids(debug.entries), "expected the debug entries to carry the audit ids")
|
|
848
|
+
}
|
|
849
|
+
|
|
771
850
|
// --- clienttrack ----------------------------------------------------------------
|
|
772
851
|
|
|
773
852
|
@Test
|
|
@@ -40,7 +40,7 @@ private class BinaryBody(val live: List<Any>, val type: String?, val sized: Bool
|
|
|
40
40
|
fun holds(v: Any): Boolean = live.any { it === v || (v is String && v == it) }
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
// The
|
|
43
|
+
// The clean registry: built by makeOptions from the raw input, grown by
|
|
44
44
|
// cleanAdd for as long as the client lives (features register later).
|
|
45
45
|
class CleanConfig(
|
|
46
46
|
val active: Boolean,
|
|
@@ -95,12 +95,12 @@ fun makeCleanConfig(cleanopts: Any?): CleanConfig {
|
|
|
95
95
|
)
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
// A context without
|
|
98
|
+
// A context without a registry (makeError accepts a bare one) still masks by
|
|
99
99
|
// the schema defaults.
|
|
100
100
|
private fun cleanConfig(ctx: Context?): CleanConfig {
|
|
101
|
-
val
|
|
102
|
-
if (
|
|
103
|
-
return
|
|
101
|
+
val cfg = ctx?.cleancfg
|
|
102
|
+
if (cfg is CleanConfig) {
|
|
103
|
+
return cfg
|
|
104
104
|
}
|
|
105
105
|
return makeCleanConfig(Schema.optspec["clean"])
|
|
106
106
|
}
|
|
@@ -206,6 +206,10 @@ private fun fetchOnce(fullurl: String, fetchdef: MutableMap<String, Any?>): Muta
|
|
|
206
206
|
} catch (e: RuntimeException) {
|
|
207
207
|
throw RuntimeException("fetch: invalid url: $fullurl", e)
|
|
208
208
|
}
|
|
209
|
+
// A bound in milliseconds, for a caller beneath the timeout feature.
|
|
210
|
+
(fetchdef["timeout"] as? Number)?.toLong()?.takeIf { it > 0 }?.let {
|
|
211
|
+
reqb.timeout(java.time.Duration.ofMillis(it))
|
|
212
|
+
}
|
|
209
213
|
|
|
210
214
|
var hasUA = false
|
|
211
215
|
val headersRaw = fetchdef["headers"]
|
|
@@ -211,10 +211,12 @@ fun makeOptions(ctx: Context): MutableMap<String, Any?> {
|
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
val derived = linkedMapOf<String, Any?>()
|
|
214
|
-
derived["clean"] = cleancfg
|
|
215
214
|
derived["featureorder"] = featureorder
|
|
216
215
|
opts["__derived__"] = derived
|
|
217
216
|
|
|
217
|
+
// Beside the options, not in them: optionsMap hands them to callers.
|
|
218
|
+
ctx.cleancfg = cleancfg
|
|
219
|
+
|
|
218
220
|
// Again over the merged result: the config's own defaults can carry one.
|
|
219
221
|
registerSensitive(cleancfg, opts - "clean" - "__derived__")
|
|
220
222
|
|
|
@@ -97,6 +97,12 @@ function Context.new(ctxmap, basectx)
|
|
|
97
97
|
self.options = basectx.options
|
|
98
98
|
end
|
|
99
99
|
|
|
100
|
+
-- The clean registry, beside the options rather than in them.
|
|
101
|
+
self.cleancfg = helpers.get_ctx_prop(ctxmap, "cleancfg")
|
|
102
|
+
if self.cleancfg == nil and basectx ~= nil then
|
|
103
|
+
self.cleancfg = basectx.cleancfg
|
|
104
|
+
end
|
|
105
|
+
|
|
100
106
|
-- Entity
|
|
101
107
|
local e = helpers.get_ctx_prop(ctxmap, "entity")
|
|
102
108
|
if e ~= nil then
|