@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
|
@@ -119,6 +119,66 @@ async function usableOps(want: number): Promise<OpRef[]> {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
|
|
122
|
+
|
|
123
|
+
const READ_OPS = ['list', 'load']
|
|
124
|
+
const WRITE_OPS = ['create', 'update', 'patch', 'remove']
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
// A read and a write of one entity (#READ, #WRITE), each driven as usableOps
|
|
128
|
+
// drives an op; #ITEM is a write of the same entity driven with ITEM_ARGS.
|
|
129
|
+
async function usablePair(): Promise<{ read: OpRef, write: OpRef, item?: OpRef } | undefined> {
|
|
130
|
+
const found: Record<string, { read?: OpRef, write?: OpRef }> = {}
|
|
131
|
+
for (const cand of candidates(makeClient({}))) {
|
|
132
|
+
const role: 'read' | 'write' | '' = READ_OPS.includes(cand.op) ? 'read' : WRITE_OPS.includes(cand.op) ? 'write' : ''
|
|
133
|
+
const seen = found[cand.entity] = found[cand.entity] || {}
|
|
134
|
+
if ('' === role || null != seen[role]) { continue }
|
|
135
|
+
try {
|
|
136
|
+
await makeClient({})[cand.accessor]()[cand.op]({}, {})
|
|
137
|
+
}
|
|
138
|
+
catch (e) { continue }
|
|
139
|
+
seen[role] = cand
|
|
140
|
+
if (null != seen.read && null != seen.write) {
|
|
141
|
+
return { read: seen.read, write: seen.write, item: await usableItem(cand.entity) }
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return undefined
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
const ITEM_ARGS = { id: 'corpus-item' }
|
|
149
|
+
|
|
150
|
+
async function usableItem(entity: string): Promise<OpRef | undefined> {
|
|
151
|
+
for (const cand of candidates(makeClient({}))) {
|
|
152
|
+
if (entity !== cand.entity || !['update', 'patch', 'remove'].includes(cand.op)) { continue }
|
|
153
|
+
try {
|
|
154
|
+
await makeClient({})[cand.accessor]()[cand.op]({ ...ITEM_ARGS }, {})
|
|
155
|
+
return cand
|
|
156
|
+
}
|
|
157
|
+
catch (e) { continue }
|
|
158
|
+
}
|
|
159
|
+
return undefined
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
// A step may wait before its call, may add request headers for its call, and
|
|
164
|
+
// may pass `args` as the operation's first argument.
|
|
165
|
+
async function runStep(client: any, ref: OpRef, step: any) {
|
|
166
|
+
if (null != step.wait) {
|
|
167
|
+
await new Promise((resolve) => setTimeout(resolve, step.wait))
|
|
168
|
+
}
|
|
169
|
+
const options = client._rootctx.options
|
|
170
|
+
const prior = options.headers
|
|
171
|
+
if (null != step.headers) {
|
|
172
|
+
options.headers = { ...(prior || {}), ...step.headers }
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
await client[ref.accessor]()[ref.op]({ ...(step.args || {}) }, step.ctrl || {})
|
|
176
|
+
}
|
|
177
|
+
finally {
|
|
178
|
+
options.headers = prior
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
122
182
|
// Replace #OP1/#OP2 throughout a case, keys included.
|
|
123
183
|
function resolve(node: any, tokens: Record<string, string>): any {
|
|
124
184
|
if ('string' === typeof node) {
|
|
@@ -132,7 +192,9 @@ function resolve(node: any, tokens: Record<string, string>): any {
|
|
|
132
192
|
if (null != node && 'object' === typeof node) {
|
|
133
193
|
const out: any = {}
|
|
134
194
|
for (const k of Object.keys(node)) {
|
|
135
|
-
out
|
|
195
|
+
Object.defineProperty(out, resolve(k, tokens), {
|
|
196
|
+
value: resolve(node[k], tokens), enumerable: true, writable: true, configurable: true,
|
|
197
|
+
})
|
|
136
198
|
}
|
|
137
199
|
return out
|
|
138
200
|
}
|
|
@@ -140,6 +202,15 @@ function resolve(node: any, tokens: Record<string, string>): any {
|
|
|
140
202
|
}
|
|
141
203
|
|
|
142
204
|
|
|
205
|
+
// No case may write onto the shared prototypes, as a `__proto__` key can.
|
|
206
|
+
function shared(): string {
|
|
207
|
+
return [Object.prototype, Object]
|
|
208
|
+
.map((o) => Object.getOwnPropertyNames(o).sort().join(',')).join(' | ')
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const PRISTINE = shared()
|
|
212
|
+
|
|
213
|
+
|
|
143
214
|
// Which #OPn tokens a case uses. A case wanting more operations than this SDK
|
|
144
215
|
// has is skipped rather than failed.
|
|
145
216
|
function tokensUsed(kase: any): number {
|
|
@@ -177,6 +248,7 @@ describe('FeatureCorpus', () => {
|
|
|
177
248
|
let corpus: any
|
|
178
249
|
let ops: OpRef[] = []
|
|
179
250
|
let byKey: Record<string, OpRef> = {}
|
|
251
|
+
let pair: { read: OpRef, write: OpRef, item?: OpRef } | undefined
|
|
180
252
|
|
|
181
253
|
|
|
182
254
|
before(async () => {
|
|
@@ -184,6 +256,10 @@ describe('FeatureCorpus', () => {
|
|
|
184
256
|
ops = await usableOps(2)
|
|
185
257
|
byKey = {}
|
|
186
258
|
for (const o of ops) { byKey[o.key] = o }
|
|
259
|
+
pair = await usablePair()
|
|
260
|
+
for (const o of pair ? [pair.read, pair.write, pair.item] : []) {
|
|
261
|
+
if (null != o) { byKey[o.key] = o }
|
|
262
|
+
}
|
|
187
263
|
})
|
|
188
264
|
|
|
189
265
|
|
|
@@ -234,6 +310,21 @@ describe('FeatureCorpus', () => {
|
|
|
234
310
|
continue
|
|
235
311
|
}
|
|
236
312
|
|
|
313
|
+
const paired = /#(READ|WRITE|ITEM|OTHER)\b/.test(JSON.stringify(raw))
|
|
314
|
+
if (paired && null == pair) {
|
|
315
|
+
t.diagnostic(`skip "${raw.name}": needs a read and a write of one entity, this SDK offers none`)
|
|
316
|
+
continue
|
|
317
|
+
}
|
|
318
|
+
const other = null == pair ? undefined :
|
|
319
|
+
ops.find((o) => o.entity !== pair!.read.entity)
|
|
320
|
+
const needed: [string, OpRef | undefined][] = [['#ITEM', pair?.item], ['#OTHER', other]]
|
|
321
|
+
const lacking = needed
|
|
322
|
+
.find(([tok, op]) => null == op && new RegExp(tok + '\\b').test(JSON.stringify(raw)))
|
|
323
|
+
if (null != lacking) {
|
|
324
|
+
t.diagnostic(`skip "${raw.name}": needs ${lacking[0]}, which this SDK cannot drive`)
|
|
325
|
+
continue
|
|
326
|
+
}
|
|
327
|
+
|
|
237
328
|
const missing = missingFeature(probe, raw)
|
|
238
329
|
if (null != missing) {
|
|
239
330
|
t.diagnostic(`skip "${raw.name}": needs the ${missing} feature, ` +
|
|
@@ -243,6 +334,12 @@ describe('FeatureCorpus', () => {
|
|
|
243
334
|
|
|
244
335
|
const tokens: Record<string, string> = {}
|
|
245
336
|
for (let i = 0; i < need; i++) { tokens['#OP' + (i + 1)] = ops[i].key }
|
|
337
|
+
if (paired && null != pair) {
|
|
338
|
+
tokens['#READ'] = pair.read.key
|
|
339
|
+
tokens['#WRITE'] = pair.write.key
|
|
340
|
+
if (null != pair.item) { tokens['#ITEM'] = pair.item.key }
|
|
341
|
+
if (null != other) { tokens['#OTHER'] = other.key }
|
|
342
|
+
}
|
|
246
343
|
|
|
247
344
|
const kase = resolve(raw, tokens)
|
|
248
345
|
ran++
|
|
@@ -256,7 +353,7 @@ describe('FeatureCorpus', () => {
|
|
|
256
353
|
ok(null != ref, `${kase.name}: no operation ${step.op}`)
|
|
257
354
|
let err: any = undefined
|
|
258
355
|
try {
|
|
259
|
-
await client
|
|
356
|
+
await runStep(client, ref, step)
|
|
260
357
|
}
|
|
261
358
|
catch (e: any) {
|
|
262
359
|
err = e
|
|
@@ -273,6 +370,8 @@ describe('FeatureCorpus', () => {
|
|
|
273
370
|
}
|
|
274
371
|
|
|
275
372
|
subset(client[`_${name}`], kase.out, `${kase.name}: _${name}`)
|
|
373
|
+
deepStrictEqual(shared(), PRISTINE,
|
|
374
|
+
`${kase.name}: the case wrote onto Object or Object.prototype`)
|
|
276
375
|
}
|
|
277
376
|
catch (err: any) {
|
|
278
377
|
const msg = String(err?.message ?? err)
|
|
@@ -93,9 +93,8 @@ function makeClient(spec: {
|
|
|
93
93
|
|
|
94
94
|
// One clean registry per client, as makeOptions gives a real one, so a value
|
|
95
95
|
// a feature registers with cleanAdd is masked by every clean after it.
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
}).__derived__
|
|
96
|
+
const regctx: any = { utility, options: { feature: { test: { active: true } } }, config: {} }
|
|
97
|
+
const derived = (stdutil as any).makeOptions(regctx).__derived__
|
|
99
98
|
|
|
100
99
|
const client: any = {
|
|
101
100
|
_mode: spec.mode || 'test',
|
|
@@ -121,6 +120,7 @@ function makeClient(spec: {
|
|
|
121
120
|
client,
|
|
122
121
|
utility,
|
|
123
122
|
options: client._options,
|
|
123
|
+
cleancfg: regctx.cleancfg,
|
|
124
124
|
out: {},
|
|
125
125
|
ctrl: over.ctrl || {},
|
|
126
126
|
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: any[]) => recs.map((rec: any) => rec.correlationId)
|
|
465
|
+
const calls = ids(h.client._audit.records)
|
|
466
|
+
strictEqual(calls.length, 2)
|
|
467
|
+
ok(calls.every((id: any) => '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
|
|
|
@@ -545,7 +545,7 @@ describe('pipeline:result helpers', () => {
|
|
|
545
545
|
const secret = 'PIPELINE-SECRET-a1b2c3d4e5f6'
|
|
546
546
|
const text = 'x'.repeat(150) + secret + 'y'.repeat(100)
|
|
547
547
|
const ctx = base({
|
|
548
|
-
|
|
548
|
+
cleancfg: { active: true, keys: [], values: [], mask: '[redacted]', hint: 0, min: 4 },
|
|
549
549
|
spec: { headers: { 'user-agent': 'Probe ' + secret } },
|
|
550
550
|
response: { body: 'body', json: async () => { throw Object.assign(new SyntaxError('bad json'), { text }) } },
|
|
551
551
|
result: { status: 200, headers: { 'content-type': 'text/html' } },
|
|
@@ -39,6 +39,7 @@ pub const CtxSpec = struct {
|
|
|
39
39
|
config: ?Value = null,
|
|
40
40
|
entopts: ?Value = null,
|
|
41
41
|
options: ?Value = null,
|
|
42
|
+
cleancfg: ?Value = null,
|
|
42
43
|
entity: ?Entity = null,
|
|
43
44
|
shared: ?Value = null,
|
|
44
45
|
opmap: ?*OpMap = null,
|
|
@@ -64,6 +65,8 @@ pub const Context = struct {
|
|
|
64
65
|
config: Value,
|
|
65
66
|
entopts: Value,
|
|
66
67
|
options: Value,
|
|
68
|
+
// The clean registry, beside the options rather than in them.
|
|
69
|
+
cleancfg: Value,
|
|
67
70
|
opmap: *OpMap,
|
|
68
71
|
response: ?*Response,
|
|
69
72
|
result: ?*SdkResult,
|
|
@@ -118,6 +121,7 @@ pub const Context = struct {
|
|
|
118
121
|
const config: Value = ctxspec.config orelse (if (basectx) |b| b.config else h.vnull());
|
|
119
122
|
const entopts: Value = ctxspec.entopts orelse (if (basectx) |b| b.entopts else h.vnull());
|
|
120
123
|
const options: Value = ctxspec.options orelse (if (basectx) |b| b.options else h.vnull());
|
|
124
|
+
const cleancfg: Value = ctxspec.cleancfg orelse (if (basectx) |b| b.cleancfg else h.vnull());
|
|
121
125
|
const entity: ?Entity = ctxspec.entity orelse (if (basectx) |b| b.entity else null);
|
|
122
126
|
const shared: Value = ctxspec.shared orelse blk: {
|
|
123
127
|
if (basectx) |b| {
|
|
@@ -163,6 +167,7 @@ pub const Context = struct {
|
|
|
163
167
|
.config = config,
|
|
164
168
|
.entopts = entopts,
|
|
165
169
|
.options = options,
|
|
170
|
+
.cleancfg = cleancfg,
|
|
166
171
|
.opmap = opmap,
|
|
167
172
|
.response = response,
|
|
168
173
|
.result = result,
|
|
@@ -179,9 +179,9 @@ pub const Utility = struct {
|
|
|
179
179
|
|
|
180
180
|
// Everything that leaves the pipeline passes through clean; inside it data
|
|
181
181
|
// stays raw, so a hook can still read the header it must add to. The zig
|
|
182
|
-
// port of tm/ts/src/utility/CleanUtility.ts. The
|
|
183
|
-
//
|
|
184
|
-
// features register secrets after make_options.
|
|
182
|
+
// port of tm/ts/src/utility/CleanUtility.ts. The clean registry is a Value
|
|
183
|
+
// map held on the context beside the options (`ctx.cleancfg`), whose
|
|
184
|
+
// `values` list is MUTABLE: features register secrets after make_options.
|
|
185
185
|
|
|
186
186
|
const CLEAN_MAXDEPTH: usize = 32;
|
|
187
187
|
const CLEAN_CIRCULAR = "[circular]";
|
|
@@ -279,11 +279,11 @@ pub fn clean_splitvalues(values: Value) [][]const u8 {
|
|
|
279
279
|
return out.toOwnedSlice(h.A()) catch &.{};
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
-
// A context without
|
|
283
|
-
// the schema defaults.
|
|
282
|
+
// A context without a registry (make_error accepts a bare one) still masks
|
|
283
|
+
// by the schema defaults.
|
|
284
284
|
fn clean_config(ctx: *Context) Value {
|
|
285
|
-
const
|
|
286
|
-
if (
|
|
285
|
+
const cfg = ctx.cleancfg;
|
|
286
|
+
if (cfg == .object and h.getp(cfg, "values") == .array) return cfg;
|
|
287
287
|
return make_clean_config(h.getp(schema.shared_optspec(), "clean"));
|
|
288
288
|
}
|
|
289
289
|
|
|
@@ -938,10 +938,12 @@ pub fn make_options_util(ctx: *Context) E!Value {
|
|
|
938
938
|
}
|
|
939
939
|
|
|
940
940
|
h.setp(opts, "__derived__", h.jo(&.{
|
|
941
|
-
.{ "clean", cleancfg },
|
|
942
941
|
.{ "featureorder", feature_order },
|
|
943
942
|
}));
|
|
944
943
|
|
|
944
|
+
// Beside the options, not in them: options_map hands them to callers.
|
|
945
|
+
ctx.cleancfg = cleancfg;
|
|
946
|
+
|
|
945
947
|
// Again over the merged result: the config's own defaults can carry one.
|
|
946
948
|
clean_add_sensitive_cfg(cleancfg, mo_without(opts, &.{ "clean", "__derived__" }));
|
|
947
949
|
|
|
@@ -2430,7 +2432,7 @@ pub fn fetcher_util(ctx: *Context, fullurl: []const u8, fetchdef: Value) E!Value
|
|
|
2430
2432
|
|
|
2431
2433
|
// A GET-only live run refuses any other method before it is sent. The error
|
|
2432
2434
|
// names the path alone: the query can carry a credential.
|
|
2433
|
-
fn getonly_refusal(fullurl: []const u8, fetchdef: Value) ?[]const u8 {
|
|
2435
|
+
pub fn getonly_refusal(fullurl: []const u8, fetchdef: Value) ?[]const u8 {
|
|
2434
2436
|
const environ = mem.threaded().environ.process_environ;
|
|
2435
2437
|
const flag = environ.getAlloc(h.A(), "VOXGIG_GETONLY_GUARD") catch return null;
|
|
2436
2438
|
if (!std.mem.eql(u8, flag, "TRUE")) return null;
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
// Response caching for safe (read) requests (mirrors go
|
|
2
|
-
// feature/cache_feature.go / rust feature/cache.rs)
|
|
3
|
-
//
|
|
4
|
-
// when the same method+URL was fetched within `ttl` ms (default: 5000). Only
|
|
5
|
-
// successful (2xx) responses to cacheable methods (default: GET) are stored,
|
|
6
|
-
// keyed by method+URL. The cache is bounded (`max` entries, default 256,
|
|
7
|
-
// oldest evicted first) and every hit/miss/bypass is counted. Bodies are
|
|
8
|
-
// snapshotted on capture so both the current caller and later hits can
|
|
9
|
-
// re-read the JSON body repeatedly.
|
|
1
|
+
// Response caching for safe (read) requests, per client (mirrors go
|
|
2
|
+
// feature/cache_feature.go / rust feature/cache.rs): see the features
|
|
3
|
+
// reference for the key, the write invalidation and the Cache-Control rules.
|
|
10
4
|
|
|
11
5
|
const std = @import("std");
|
|
12
6
|
const h = @import("../core/helpers.zig");
|
|
@@ -19,6 +13,7 @@ const Value = h.Value;
|
|
|
19
13
|
const Context = types.Context;
|
|
20
14
|
const Feature = types.Feature;
|
|
21
15
|
const Fetcher = types.Fetcher;
|
|
16
|
+
const HmacSha256 = std.crypto.auth.hmac.sha2.HmacSha256;
|
|
22
17
|
|
|
23
18
|
pub const CacheSnapshot = struct {
|
|
24
19
|
status: i64,
|
|
@@ -29,12 +24,14 @@ pub const CacheSnapshot = struct {
|
|
|
29
24
|
|
|
30
25
|
pub const CacheEntry = struct {
|
|
31
26
|
expiry: i64,
|
|
27
|
+
scope: []const u8,
|
|
32
28
|
snapshot: *CacheSnapshot,
|
|
33
29
|
};
|
|
34
30
|
|
|
35
31
|
pub const CacheTrack = struct {
|
|
36
32
|
store: std.StringHashMap(CacheEntry),
|
|
37
33
|
order: std.ArrayList([]const u8),
|
|
34
|
+
secret: [32]u8 = undefined,
|
|
38
35
|
|
|
39
36
|
// Activity tracking (mirrors the ts client._cache record).
|
|
40
37
|
hit: i64 = 0,
|
|
@@ -75,6 +72,8 @@ pub const CacheFeature = struct {
|
|
|
75
72
|
self.active = sup.fopt_bool(options, "active", false);
|
|
76
73
|
if (!self.active) return;
|
|
77
74
|
|
|
75
|
+
h.IO().randomSecure(&self.track.secret) catch h.IO().random(&self.track.secret);
|
|
76
|
+
|
|
78
77
|
const util = ctx.util();
|
|
79
78
|
const w = h.A().create(WrapCtx) catch unreachable;
|
|
80
79
|
w.* = .{ .inner = util.fetcher, .options = options, .track = self.track };
|
|
@@ -133,9 +132,16 @@ fn through(track: *CacheTrack, options: Value, ctx: *Context, url: []const u8, f
|
|
|
133
132
|
break;
|
|
134
133
|
}
|
|
135
134
|
}
|
|
136
|
-
if (!cacheable)
|
|
135
|
+
if (!cacheable) {
|
|
136
|
+
if (std.mem.eql(u8, method, "GET") or std.mem.eql(u8, method, "HEAD")) {
|
|
137
|
+
return inner.invoke(ctx, url, fetchdef);
|
|
138
|
+
}
|
|
139
|
+
defer invalidate(track, url);
|
|
140
|
+
return inner.invoke(ctx, url, fetchdef);
|
|
141
|
+
}
|
|
137
142
|
|
|
138
|
-
const
|
|
143
|
+
const hdigest = digest(&track.secret, h.getp(fetchdef, "headers"));
|
|
144
|
+
const key = std.fmt.allocPrint(h.A(), "{s} {s} {s}", .{ method, url, hdigest }) catch method;
|
|
139
145
|
const now = sup.fopt_now(options);
|
|
140
146
|
|
|
141
147
|
if (track.store.get(key)) |hit| {
|
|
@@ -150,9 +156,14 @@ fn through(track: *CacheTrack, options: Value, ctx: *Context, url: []const u8, f
|
|
|
150
156
|
if (storable(res) and json(res)) {
|
|
151
157
|
const snap = h.A().create(CacheSnapshot) catch unreachable;
|
|
152
158
|
snap.* = snapshot(res);
|
|
153
|
-
const ttl = sup.fopt_int(options, "ttl", 5000);
|
|
159
|
+
const ttl = lifetime(snap.headers, sup.fopt_int(options, "ttl", 5000));
|
|
160
|
+
if (ttl <= 0) {
|
|
161
|
+
track.bypass += 1;
|
|
162
|
+
return replay(snap);
|
|
163
|
+
}
|
|
164
|
+
dropEntry(track, key);
|
|
154
165
|
evict(track, options);
|
|
155
|
-
track.store.put(key, .{ .expiry = now + ttl, .snapshot = snap }) catch {};
|
|
166
|
+
track.store.put(key, .{ .expiry = now + ttl, .scope = urlScope(url), .snapshot = snap }) catch {};
|
|
156
167
|
track.order.append(h.A(), key) catch {};
|
|
157
168
|
track.miss += 1;
|
|
158
169
|
return replay(snap);
|
|
@@ -165,6 +176,126 @@ fn through(track: *CacheTrack, options: Value, ctx: *Context, url: []const u8, f
|
|
|
165
176
|
}
|
|
166
177
|
}
|
|
167
178
|
|
|
179
|
+
fn headerText(v: Value) ?[]const u8 {
|
|
180
|
+
return switch (v) {
|
|
181
|
+
.string => |t| t,
|
|
182
|
+
.integer => |n| std.fmt.allocPrint(h.A(), "{d}", .{n}) catch null,
|
|
183
|
+
.float => |f| if (f == @floor(f) and @abs(f) < 9.0e15)
|
|
184
|
+
std.fmt.allocPrint(h.A(), "{d}", .{@as(i64, @intFromFloat(f))}) catch null
|
|
185
|
+
else
|
|
186
|
+
std.fmt.allocPrint(h.A(), "{d}", .{f}) catch null,
|
|
187
|
+
.bool => |b| if (b) "true" else "false",
|
|
188
|
+
else => null,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const HeaderPair = struct { name: []const u8, value: []const u8 };
|
|
193
|
+
|
|
194
|
+
fn pairLess(_: void, a: HeaderPair, b: HeaderPair) bool {
|
|
195
|
+
const order = std.mem.order(u8, a.name, b.name);
|
|
196
|
+
if (order != .eq) return order == .lt;
|
|
197
|
+
return std.mem.lessThan(u8, a.value, b.value);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
fn digest(secret: *const [32]u8, headers: Value) []const u8 {
|
|
201
|
+
var pairs: std.ArrayList(HeaderPair) = .empty;
|
|
202
|
+
if (headers == .object) {
|
|
203
|
+
var it = headers.object.iterator();
|
|
204
|
+
while (it.next()) |kv| {
|
|
205
|
+
const text = headerText(kv.value_ptr.*) orelse continue;
|
|
206
|
+
pairs.append(h.A(), .{ .name = lowerAlloc(kv.key_ptr.*), .value = text }) catch {};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
std.mem.sort(HeaderPair, pairs.items, {}, pairLess);
|
|
210
|
+
var mac = HmacSha256.init(secret);
|
|
211
|
+
for (pairs.items) |p| {
|
|
212
|
+
mac.update(p.name);
|
|
213
|
+
mac.update(":");
|
|
214
|
+
mac.update(p.value);
|
|
215
|
+
mac.update("\n");
|
|
216
|
+
}
|
|
217
|
+
var out: [HmacSha256.mac_length]u8 = undefined;
|
|
218
|
+
mac.final(&out);
|
|
219
|
+
const hex = std.fmt.bytesToHex(out, .lower);
|
|
220
|
+
return h.A().dupe(u8, &hex) catch "";
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
fn invalidate(track: *CacheTrack, url: []const u8) void {
|
|
224
|
+
const path = urlScope(url);
|
|
225
|
+
const collection = urlParent(path);
|
|
226
|
+
var dropped: std.ArrayList([]const u8) = .empty;
|
|
227
|
+
var it = track.store.iterator();
|
|
228
|
+
while (it.next()) |kv| {
|
|
229
|
+
const scope = kv.value_ptr.scope;
|
|
230
|
+
if (scopeUnder(scope, path) or std.mem.eql(u8, scope, collection)) {
|
|
231
|
+
dropped.append(h.A(), kv.key_ptr.*) catch {};
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
for (dropped.items) |key| dropEntry(track, key);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
fn dropEntry(track: *CacheTrack, key: []const u8) void {
|
|
238
|
+
if (!track.store.remove(key)) return;
|
|
239
|
+
var i: usize = track.order.items.len;
|
|
240
|
+
while (i > 0) {
|
|
241
|
+
i -= 1;
|
|
242
|
+
if (std.mem.eql(u8, track.order.items[i], key)) _ = track.order.orderedRemove(i);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// The configured ttl capped by the response's Cache-Control; zero when the
|
|
247
|
+
// response may not be stored.
|
|
248
|
+
fn lifetime(headers: Value, ttl: i64) i64 {
|
|
249
|
+
var control: []const u8 = "";
|
|
250
|
+
if (headers == .object) {
|
|
251
|
+
var it = headers.object.iterator();
|
|
252
|
+
while (it.next()) |kv| {
|
|
253
|
+
if (std.ascii.eqlIgnoreCase(kv.key_ptr.*, "cache-control")) {
|
|
254
|
+
control = lowerAlloc(headerText(kv.value_ptr.*) orelse "");
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
var life = ttl;
|
|
259
|
+
var parts = std.mem.splitScalar(u8, control, ',');
|
|
260
|
+
while (parts.next()) |part| {
|
|
261
|
+
const directive = std.mem.trim(u8, part, " \t");
|
|
262
|
+
if (std.mem.eql(u8, directive, "no-store") or std.mem.eql(u8, directive, "private") or
|
|
263
|
+
std.mem.eql(u8, directive, "no-cache")) return 0;
|
|
264
|
+
if (std.mem.startsWith(u8, directive, "max-age")) {
|
|
265
|
+
const rest = std.mem.trim(u8, directive["max-age".len..], " \t");
|
|
266
|
+
if (rest.len == 0 or rest[0] != '=') continue;
|
|
267
|
+
const value = std.mem.trim(u8, std.mem.trim(u8, rest[1..], " \t"), "\"");
|
|
268
|
+
if (value.len == 0) continue;
|
|
269
|
+
var digits = true;
|
|
270
|
+
for (value) |c| digits = digits and std.ascii.isDigit(c);
|
|
271
|
+
if (!digits) continue;
|
|
272
|
+
const secs = std.fmt.parseInt(i64, value, 10) catch continue;
|
|
273
|
+
life = @min(life, secs *| 1000);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return life;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
fn urlScope(url: []const u8) []const u8 {
|
|
280
|
+
var end = std.mem.indexOfAny(u8, url, "?#") orelse url.len;
|
|
281
|
+
while (end > 0 and url[end - 1] == '/') end -= 1;
|
|
282
|
+
return url[0..end];
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
fn urlParent(scope: []const u8) []const u8 {
|
|
286
|
+
var root: usize = 0;
|
|
287
|
+
if (std.mem.indexOf(u8, scope, "://")) |scheme| {
|
|
288
|
+
root = std.mem.indexOfScalarPos(u8, scope, scheme + 3, '/') orelse return scope;
|
|
289
|
+
}
|
|
290
|
+
const cut = std.mem.lastIndexOfScalar(u8, scope, '/') orelse 0;
|
|
291
|
+
return scope[0..@max(cut, root)];
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
fn scopeUnder(scope: []const u8, prefix: []const u8) bool {
|
|
295
|
+
if (std.mem.eql(u8, scope, prefix)) return true;
|
|
296
|
+
return scope.len > prefix.len and std.mem.startsWith(u8, scope, prefix) and scope[prefix.len] == '/';
|
|
297
|
+
}
|
|
298
|
+
|
|
168
299
|
// A body the transport could not read as JSON passes through, for the operation to report.
|
|
169
300
|
fn storable(res: Value) bool {
|
|
170
301
|
const status = sup.fres_status(res) orelse return false;
|
|
@@ -107,6 +107,7 @@ pub const DebugFeature = struct {
|
|
|
107
107
|
|
|
108
108
|
const entry = h.omap();
|
|
109
109
|
h.setp(entry, "op", h.vstr(std.fmt.allocPrint(h.A(), "{s}.{s}", .{ entity, opname }) catch ""));
|
|
110
|
+
h.setp(entry, "correlationId", h.vstr(ctx.id));
|
|
110
111
|
h.setp(entry, "start", h.vnum(sup.fopt_now(self.options)));
|
|
111
112
|
if (ctx.spec) |sp| {
|
|
112
113
|
h.setp(entry, "method", h.vstr(sp.method));
|
|
@@ -82,6 +82,7 @@ const h = @import("../core/helpers.zig");
|
|
|
82
82
|
const mem = @import("../core/mem.zig");
|
|
83
83
|
const err = @import("../core/error.zig");
|
|
84
84
|
const types = @import("../core/types.zig");
|
|
85
|
+
const utility = @import("../core/utility.zig");
|
|
85
86
|
const sup = @import("support.zig");
|
|
86
87
|
|
|
87
88
|
// NAMED BUILD MODULES, not paths: the vendored trees under feature/secrets/
|
|
@@ -857,7 +858,11 @@ fn send(ctx: *Context, sysfetch: Value, url: []const u8, method: []const u8, bod
|
|
|
857
858
|
}
|
|
858
859
|
// No custom transport supplied - the ordinary case (make_options leaves
|
|
859
860
|
// system.fetch unset, and the SDK's default transport has no HTTP
|
|
860
|
-
// client). See raw_exchange_fetch.
|
|
861
|
+
// client). See raw_exchange_fetch. Not the SDK fetcher, as every other
|
|
862
|
+
// target does, for that reason: only its GET-only guard comes first.
|
|
863
|
+
if (utility.getonly_refusal(url, h.jo(&.{.{ "method", h.vstr(method) }}))) |msg| {
|
|
864
|
+
return ctx.fail("fetch_getonly_block", msg);
|
|
865
|
+
}
|
|
861
866
|
return raw_exchange_fetch(ctx, url, method, body);
|
|
862
867
|
}
|
|
863
868
|
|
|
@@ -92,6 +92,7 @@ pub const TelemetryFeature = struct {
|
|
|
92
92
|
const span = h.omap();
|
|
93
93
|
h.setp(span, "traceId", h.vstr(self.id("trace")));
|
|
94
94
|
h.setp(span, "spanId", h.vstr(self.id("span")));
|
|
95
|
+
h.setp(span, "correlationId", h.vstr(ctx.id));
|
|
95
96
|
h.setp(span, "name", h.vstr(std.fmt.allocPrint(h.A(), "{s}.{s}", .{ entity, opname }) catch ""));
|
|
96
97
|
h.setp(span, "start", h.vnum(sup.fopt_now(self.options)));
|
|
97
98
|
ctx.out_set(TELEMETRY_SPAN_KEY, OutVal{ .val = span });
|
|
@@ -488,6 +488,71 @@ test "feature cache: inactive does not wrap" {
|
|
|
488
488
|
try testing.expect(rec.count() == 2);
|
|
489
489
|
}
|
|
490
490
|
|
|
491
|
+
var cache_control: []const u8 = "";
|
|
492
|
+
|
|
493
|
+
fn replyControl(_: i64, _: *sdk.Context, _: Value) fh.E!Value {
|
|
494
|
+
return fh.fh_response(200, h.jo(&.{.{ "ok", h.vbool(true) }}), h.jo(&.{.{ "Cache-Control", h.vstr(cache_control) }}));
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
test "feature cache: keys on request headers" {
|
|
498
|
+
if (!fh.fh_present(&.{"cache"})) return;
|
|
499
|
+
const rec = fh.Recorder.new(null);
|
|
500
|
+
const f = sdk.CacheFeature.make();
|
|
501
|
+
const hh = fh.fh_make(rec.fetcher(), &.{.{ .feat = f, .options = h.jo(&.{.{ "ttl", h.vnum(10000) }}) }});
|
|
502
|
+
_ = hh.op(.{ .op = "load", .path = "/w/1", .headers = h.jo(&.{.{ "x-tenant", h.vstr("tenant-a") }}) });
|
|
503
|
+
_ = hh.op(.{ .op = "load", .path = "/w/1", .headers = h.jo(&.{.{ "X-Tenant", h.vstr("tenant-b") }}) });
|
|
504
|
+
try testing.expect(rec.count() == 2);
|
|
505
|
+
_ = hh.op(.{ .op = "load", .path = "/w/1", .headers = h.jo(&.{.{ "x-tenant", h.vstr("tenant-b") }}) });
|
|
506
|
+
try testing.expect(rec.count() == 2);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
test "feature cache: a write drops its collection" {
|
|
510
|
+
if (!fh.fh_present(&.{"cache"})) return;
|
|
511
|
+
const rec = fh.Recorder.new(null);
|
|
512
|
+
const f = sdk.CacheFeature.make();
|
|
513
|
+
const cf: *sdk.CacheFeature = @ptrCast(@alignCast(f.ptr));
|
|
514
|
+
const hh = fh.fh_make(rec.fetcher(), &.{.{ .feat = f, .options = h.jo(&.{.{ "ttl", h.vnum(10000) }}) }});
|
|
515
|
+
const paths = [_][]const u8{ "/w/1", "/w", "/w/1/part", "/other/1", "/w/2" };
|
|
516
|
+
for (paths) |p| _ = hh.op(.{ .op = "load", .path = p });
|
|
517
|
+
_ = hh.op(.{ .op = "update", .method = "PUT", .path = "/w/1" });
|
|
518
|
+
for (paths) |p| _ = hh.op(.{ .op = "load", .path = p });
|
|
519
|
+
try testing.expect(rec.count() == 9);
|
|
520
|
+
try testing.expect(cf.track.hit == 2);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
test "feature cache: Cache-Control prevents storing" {
|
|
524
|
+
if (!fh.fh_present(&.{"cache"})) return;
|
|
525
|
+
const controls = [_][]const u8{ "no-store", "private", "No-Cache", "max-age=60, private" };
|
|
526
|
+
for (controls) |control| {
|
|
527
|
+
cache_control = control;
|
|
528
|
+
const rec = fh.Recorder.new(replyControl);
|
|
529
|
+
const f = sdk.CacheFeature.make();
|
|
530
|
+
const hh = fh.fh_make(rec.fetcher(), &.{.{ .feat = f, .options = h.jo(&.{.{ "ttl", h.vnum(10000) }}) }});
|
|
531
|
+
_ = hh.op(.{ .op = "load", .path = "/w" });
|
|
532
|
+
_ = hh.op(.{ .op = "load", .path = "/w" });
|
|
533
|
+
try testing.expect(rec.count() == 2);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
test "feature cache: max-age caps the ttl" {
|
|
538
|
+
if (!fh.fh_present(&.{"cache"})) return;
|
|
539
|
+
cache_control = "max-age=1";
|
|
540
|
+
const clock = fh.FhClock.new();
|
|
541
|
+
const rec = fh.Recorder.new(replyControl);
|
|
542
|
+
const f = sdk.CacheFeature.make();
|
|
543
|
+
const hh = fh.fh_make(rec.fetcher(), &.{.{ .feat = f, .options = h.jo(&.{
|
|
544
|
+
.{ "ttl", h.vnum(10000) },
|
|
545
|
+
.{ "now", clock.now_fn() },
|
|
546
|
+
}) }});
|
|
547
|
+
_ = hh.op(.{ .op = "load", .path = "/w" });
|
|
548
|
+
clock.advance(500);
|
|
549
|
+
_ = hh.op(.{ .op = "load", .path = "/w" });
|
|
550
|
+
try testing.expect(rec.count() == 1);
|
|
551
|
+
clock.advance(600);
|
|
552
|
+
_ = hh.op(.{ .op = "load", .path = "/w" });
|
|
553
|
+
try testing.expect(rec.count() == 2);
|
|
554
|
+
}
|
|
555
|
+
|
|
491
556
|
// =====================================================================
|
|
492
557
|
// idempotency
|
|
493
558
|
// =====================================================================
|
|
@@ -828,6 +893,41 @@ test "feature audit: inactive records nothing" {
|
|
|
828
893
|
try testing.expect(af.records.items.len == 0);
|
|
829
894
|
}
|
|
830
895
|
|
|
896
|
+
// =====================================================================
|
|
897
|
+
// one call, one id
|
|
898
|
+
// =====================================================================
|
|
899
|
+
|
|
900
|
+
test "feature telemetry, debug and audit: carry one call's context id" {
|
|
901
|
+
if (!fh.fh_present(&.{ "telemetry", "debug", "audit" })) return;
|
|
902
|
+
const tfeat = sdk.TelemetryFeature.make();
|
|
903
|
+
const tf: *sdk.TelemetryFeature = @ptrCast(@alignCast(tfeat.ptr));
|
|
904
|
+
const dfeat = sdk.DebugFeature.make();
|
|
905
|
+
const df: *sdk.DebugFeature = @ptrCast(@alignCast(dfeat.ptr));
|
|
906
|
+
const afeat = sdk.AuditFeature.make();
|
|
907
|
+
const af: *sdk.AuditFeature = @ptrCast(@alignCast(afeat.ptr));
|
|
908
|
+
const hh = fh.fh_make(null, &.{
|
|
909
|
+
.{ .feat = tfeat, .options = vnull() },
|
|
910
|
+
.{ .feat = dfeat, .options = vnull() },
|
|
911
|
+
.{ .feat = afeat, .options = vnull() },
|
|
912
|
+
});
|
|
913
|
+
_ = hh.op(.{ .op = "load" });
|
|
914
|
+
_ = hh.op(.{ .op = "list" });
|
|
915
|
+
const calls = af.records.items;
|
|
916
|
+
try testing.expect(calls.len == 2);
|
|
917
|
+
for (calls) |rec| {
|
|
918
|
+
const id = h.get_str(rec, "correlationId") orelse "";
|
|
919
|
+
try testing.expect(id.len != 0);
|
|
920
|
+
}
|
|
921
|
+
try testing.expect(!h.veq(h.getp(calls[0], "correlationId"), h.getp(calls[1], "correlationId")));
|
|
922
|
+
try testing.expect(tf.spans.items.len == calls.len);
|
|
923
|
+
try testing.expect(df.entries.items.len == calls.len);
|
|
924
|
+
for (calls, tf.spans.items, df.entries.items) |rec, span, entry| {
|
|
925
|
+
const id = h.getp(rec, "correlationId");
|
|
926
|
+
try testing.expect(h.veq(h.getp(span, "correlationId"), id));
|
|
927
|
+
try testing.expect(h.veq(h.getp(entry, "correlationId"), id));
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
|
|
831
931
|
// =====================================================================
|
|
832
932
|
// clienttrack
|
|
833
933
|
// =====================================================================
|