@voxgig/sdkgen 4.4.1 → 4.5.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/dist/cmp/FeatureDocs.d.ts +16 -0
- package/dist/cmp/FeatureDocs.js +72 -0
- package/dist/cmp/FeatureDocs.js.map +1 -0
- package/dist/cmp/Readme.js +2 -0
- package/dist/cmp/Readme.js.map +1 -1
- package/dist/cmp/ReadmeFeatures.d.ts +2 -0
- package/dist/cmp/ReadmeFeatures.js +95 -0
- package/dist/cmp/ReadmeFeatures.js.map +1 -0
- package/dist/cmp/ReadmeRef.js +4 -0
- package/dist/cmp/ReadmeRef.js.map +1 -1
- package/dist/cmp/ReadmeRefFeatures.d.ts +2 -0
- package/dist/cmp/ReadmeRefFeatures.js +130 -0
- package/dist/cmp/ReadmeRefFeatures.js.map +1 -0
- package/dist/cmp/ReadmeTop.js +46 -0
- package/dist/cmp/ReadmeTop.js.map +1 -1
- package/dist/helpers/opShape.js +5 -1
- package/dist/helpers/opShape.js.map +1 -1
- package/dist/sdkgen.d.ts +3 -2
- package/dist/sdkgen.js +30 -10
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility.d.ts +2 -1
- package/dist/utility.js +17 -1
- package/dist/utility.js.map +1 -1
- package/package.json +1 -1
- package/project/.sdk/src/cmp/c/ReadmeRef_c.ts +5 -0
- package/project/.sdk/src/cmp/clojure/ReadmeRef_clojure.ts +5 -0
- package/project/.sdk/src/cmp/cpp/ReadmeRef_cpp.ts +5 -0
- package/project/.sdk/src/cmp/csharp/ReadmeRef_csharp.ts +5 -0
- package/project/.sdk/src/cmp/dart/ReadmeRef_dart.ts +5 -0
- package/project/.sdk/src/cmp/elixir/ReadmeRef_elixir.ts +5 -0
- package/project/.sdk/src/cmp/go/ReadmeRef_go.ts +5 -0
- package/project/.sdk/src/cmp/go/TestDirect_go.ts +123 -2
- package/project/.sdk/src/cmp/java/ReadmeRef_java.ts +5 -0
- package/project/.sdk/src/cmp/js/ReadmeRef_js.ts +5 -0
- package/project/.sdk/src/cmp/js/TestDirect_js.ts +62 -0
- package/project/.sdk/src/cmp/kotlin/ReadmeRef_kotlin.ts +5 -0
- package/project/.sdk/src/cmp/lean/ReadmeRef_lean.ts +27 -3
- package/project/.sdk/src/cmp/lua/ReadmeRef_lua.ts +5 -0
- package/project/.sdk/src/cmp/ocaml/ReadmeRef_ocaml.ts +5 -0
- package/project/.sdk/src/cmp/perl/ReadmeRef_perl.ts +5 -0
- package/project/.sdk/src/cmp/php/ReadmeRef_php.ts +5 -0
- package/project/.sdk/src/cmp/py/ReadmeRef_py.ts +5 -0
- package/project/.sdk/src/cmp/rb/ReadmeRef_rb.ts +5 -0
- package/project/.sdk/src/cmp/rust/ReadmeRef_rust.ts +5 -0
- package/project/.sdk/src/cmp/scala/ReadmeRef_scala.ts +5 -0
- package/project/.sdk/src/cmp/seneca-provider/Extras_seneca-provider.ts +19 -1
- package/project/.sdk/src/cmp/seneca-provider/Main_seneca-provider.ts +27 -2
- package/project/.sdk/src/cmp/swift/ReadmeRef_swift.ts +5 -0
- package/project/.sdk/src/cmp/ts/Config_ts.ts +4 -1
- package/project/.sdk/src/cmp/ts/ReadmeHowto_ts.ts +9 -4
- package/project/.sdk/src/cmp/ts/ReadmeModel_ts.ts +8 -3
- package/project/.sdk/src/cmp/ts/ReadmeQuick_ts.ts +3 -2
- package/project/.sdk/src/cmp/ts/ReadmeRef_ts.ts +7 -2
- package/project/.sdk/src/cmp/ts/ReadmeTopQuick_ts.ts +3 -2
- package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +5 -2
- package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +5 -2
- package/project/.sdk/src/cmp/zig/ReadmeRef_zig.ts +5 -0
- package/project/.sdk/tm/clojure/src/sdk/features.clj +175 -0
- package/project/.sdk/tm/dart/test/feature_test.dart +54 -0
- package/project/.sdk/tm/go/feature/test_feature.go +17 -6
- package/project/.sdk/tm/go/test/feature_corpus_test.go +10 -3
- package/project/.sdk/tm/java/test/FeatureCorpusTest.java +5 -4
- package/project/.sdk/tm/js/src/feature/test/TestFeature.js +8 -1
- package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +3 -1
- package/project/.sdk/tm/js/test/feature/Corpus.test.js +13 -3
- package/project/.sdk/tm/js/test/feature.test.js +19 -9
- package/project/.sdk/tm/lean/src/SdkFeatures.lean +186 -1
- package/project/.sdk/tm/lua/feature/test_feature.lua +21 -7
- package/project/.sdk/tm/lua/test/feature_test.lua +18 -18
- package/project/.sdk/tm/lua/utility/make_options.lua +2 -0
- package/project/.sdk/tm/ocaml/sdk_features.ml +5 -0
- package/project/.sdk/tm/perl/t/feature_corpus.t +5 -4
- package/project/.sdk/tm/php/feature/TestFeature.php +19 -8
- package/project/.sdk/tm/php/test/FeatureCorpusTest.php +7 -4
- package/project/.sdk/tm/php/utility/MakeOptions.php +2 -1
- package/project/.sdk/tm/py/pkg/feature/test_feature.py +15 -4
- package/project/.sdk/tm/py/pkg/utility/make_options.py +2 -0
- package/project/.sdk/tm/py/test/test_feature.py +40 -0
- package/project/.sdk/tm/py/test/test_feature_corpus.py +14 -3
- package/project/.sdk/tm/rb/test/feature_corpus_test.rb +12 -4
- package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +15 -1
- package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +3 -1
- package/project/.sdk/tm/ts/src/utility/PrepareAuthUtility.ts +20 -0
- package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +13 -3
- package/project/.sdk/tm/ts/test/feature.test.ts +19 -9
- package/project/sdkgen-package.json +1 -1
- package/src/cmp/FeatureDocs.ts +100 -0
- package/src/cmp/Readme.ts +2 -0
- package/src/cmp/ReadmeFeatures.ts +113 -0
- package/src/cmp/ReadmeRef.ts +4 -0
- package/src/cmp/ReadmeRefFeatures.ts +149 -0
- package/src/cmp/ReadmeTop.ts +48 -0
- package/src/helpers/opShape.ts +5 -1
- package/src/sdkgen.ts +28 -7
- package/src/utility.ts +21 -1
|
@@ -75,11 +75,13 @@ local function make_options_util(ctx)
|
|
|
75
75
|
|
|
76
76
|
local optspec = {
|
|
77
77
|
apikey = "",
|
|
78
|
+
secret = "",
|
|
78
79
|
base = "http://localhost:8000",
|
|
79
80
|
prefix = "",
|
|
80
81
|
suffix = "",
|
|
81
82
|
auth = {
|
|
82
83
|
prefix = "",
|
|
84
|
+
basic = false,
|
|
83
85
|
},
|
|
84
86
|
headers = {
|
|
85
87
|
["`$CHILD`"] = "`$STRING`",
|
|
@@ -813,6 +813,11 @@ let cost_feature () : feature =
|
|
|
813
813
|
end
|
|
814
814
|
end
|
|
815
815
|
| "PreDone" -> finish ctx true
|
|
816
|
+
(* A failed operation never reaches PreDone - make_error dispatches
|
|
817
|
+
PreUnexpected - so its attempts would be priced and discarded, and
|
|
818
|
+
repeated failures could slip past an onBudget "deny" ceiling.
|
|
819
|
+
`false` keeps a call that made NO attempt from being counted. *)
|
|
820
|
+
| "PreUnexpected" -> finish ctx false
|
|
816
821
|
| _ -> ());
|
|
817
822
|
f
|
|
818
823
|
|
|
@@ -29,9 +29,10 @@ unless (defined $TEST_JSON && -e $TEST_JSON) {
|
|
|
29
29
|
plan skip_all => 'test.json corpus not found';
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
# Features with a corpus section
|
|
33
|
-
#
|
|
34
|
-
|
|
32
|
+
# Features with a corpus section are read from the corpus itself (see the
|
|
33
|
+
# loop below), so a project-authored section - a custom feature added under
|
|
34
|
+
# .sdk/test/feature/ - runs without editing this file. An SDK generated
|
|
35
|
+
# without a listed feature still skips, not fails.
|
|
35
36
|
|
|
36
37
|
# The standard operation names, in the order the runner prefers them.
|
|
37
38
|
my @FEATURE_CORPUS_OPS = qw(load list create update remove);
|
|
@@ -282,7 +283,7 @@ ok(scalar(@ops) > 0,
|
|
|
282
283
|
exit 0;
|
|
283
284
|
};
|
|
284
285
|
|
|
285
|
-
for my $name (
|
|
286
|
+
for my $name (sort keys %{ $CORPUS->{feature} || {} }) {
|
|
286
287
|
my $section = ($CORPUS->{feature} || {})->{$name};
|
|
287
288
|
next unless defined $section;
|
|
288
289
|
|
|
@@ -69,10 +69,16 @@ class ProjectNameTestFeature extends ProjectNameBaseFeature
|
|
|
69
69
|
if (!is_string($restf)) {
|
|
70
70
|
return $data;
|
|
71
71
|
}
|
|
72
|
-
if (!preg_match('/^`body\.(
|
|
72
|
+
if (!preg_match('/^`body\.(.+)`$/', $restf, $m)) {
|
|
73
73
|
return $data;
|
|
74
74
|
}
|
|
75
|
-
|
|
75
|
+
// Multi-segment on purpose: GraphQL ops unwrap body.data.<field>
|
|
76
|
+
// (and body.data.<field>.<entity> for mutations), not just one level.
|
|
77
|
+
$out = $data;
|
|
78
|
+
foreach (array_reverse(explode('.', $m[1])) as $seg) {
|
|
79
|
+
$out = [$seg => $out];
|
|
80
|
+
}
|
|
81
|
+
return $out;
|
|
76
82
|
};
|
|
77
83
|
|
|
78
84
|
$respond = function (int $status, mixed $data, ?array $extra = null) use ($envelope): array {
|
|
@@ -433,13 +439,18 @@ class ProjectNameTestFeature extends ProjectNameBaseFeature
|
|
|
433
439
|
}
|
|
434
440
|
}
|
|
435
441
|
}
|
|
442
|
+
// Path AND query: a path-only read misses a query-addressed
|
|
443
|
+
// record (e.g. GET /result?trace_id=), which has no path param.
|
|
436
444
|
$params = is_array($point) ? ($point['args']['params'] ?? null) : null;
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
if ($
|
|
442
|
-
$
|
|
445
|
+
$query = is_array($point) ? ($point['args']['query'] ?? null) : null;
|
|
446
|
+
foreach ([$params, $query] as $arglist) {
|
|
447
|
+
if (is_array($arglist)) {
|
|
448
|
+
foreach ($arglist as $p) {
|
|
449
|
+
if (is_array($p) && (($p['reqd'] ?? false) === true)) {
|
|
450
|
+
$n = $p['name'] ?? null;
|
|
451
|
+
if ($n !== null) {
|
|
452
|
+
$reqd_names[] = $n;
|
|
453
|
+
}
|
|
443
454
|
}
|
|
444
455
|
}
|
|
445
456
|
}
|
|
@@ -23,9 +23,10 @@ use PHPUnit\Framework\TestCase;
|
|
|
23
23
|
|
|
24
24
|
class FeatureCorpusTest extends TestCase
|
|
25
25
|
{
|
|
26
|
-
// Features with a corpus section
|
|
27
|
-
//
|
|
28
|
-
|
|
26
|
+
// Features with a corpus section are read from the corpus itself (see
|
|
27
|
+
// testFeatureCorpus), so a project-authored section - a custom feature
|
|
28
|
+
// added under .sdk/test/feature/ - runs without editing this file. An
|
|
29
|
+
// SDK generated without a listed feature still skips, not fails.
|
|
29
30
|
|
|
30
31
|
// The standard operation names, in the order the runner prefers them.
|
|
31
32
|
private const FEATURE_CORPUS_OPS = ['load', 'list', 'create', 'update', 'remove'];
|
|
@@ -300,7 +301,9 @@ class FeatureCorpusTest extends TestCase
|
|
|
300
301
|
. 'the corpus (create-sdkgen .sdk/test/feature/) to run these cases');
|
|
301
302
|
}
|
|
302
303
|
|
|
303
|
-
|
|
304
|
+
$names = array_keys(self::corpus()['feature'] ?? []);
|
|
305
|
+
sort($names);
|
|
306
|
+
foreach ($names as $name) {
|
|
304
307
|
$section = self::corpus()['feature'][$name] ?? null;
|
|
305
308
|
if (null === $section) {
|
|
306
309
|
continue;
|
|
@@ -130,10 +130,11 @@ class ProjectNameMakeOptions
|
|
|
130
130
|
|
|
131
131
|
$optspec = [
|
|
132
132
|
'apikey' => '',
|
|
133
|
+
'secret' => '',
|
|
133
134
|
'base' => 'http://localhost:8000',
|
|
134
135
|
'prefix' => '',
|
|
135
136
|
'suffix' => '',
|
|
136
|
-
'auth' => ['prefix' => ''],
|
|
137
|
+
'auth' => ['prefix' => '', 'basic' => false],
|
|
137
138
|
'headers' => ['`$CHILD`' => '`$STRING`'],
|
|
138
139
|
'allow' => [
|
|
139
140
|
'method' => 'GET,PUT,POST,PATCH,DELETE,OPTIONS',
|
|
@@ -11,7 +11,7 @@ from projectname_sdk.feature.base_feature import ProjectNameBaseFeature
|
|
|
11
11
|
|
|
12
12
|
# The `body.<key>` form of an op's response transform: the mock wraps its
|
|
13
13
|
# payload in <key> so the transform can unwrap it again.
|
|
14
|
-
ENVELOPE_RES_RE = re.compile(r"^`body\.(
|
|
14
|
+
ENVELOPE_RES_RE = re.compile(r"^`body\.(.+)`$")
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
class ProjectNameTestFeature(ProjectNameBaseFeature):
|
|
@@ -60,7 +60,14 @@ class ProjectNameTestFeature(ProjectNameBaseFeature):
|
|
|
60
60
|
if not isinstance(restf, str):
|
|
61
61
|
return data
|
|
62
62
|
m = ENVELOPE_RES_RE.match(restf)
|
|
63
|
-
|
|
63
|
+
if m is None:
|
|
64
|
+
return data
|
|
65
|
+
# Multi-segment on purpose: GraphQL ops unwrap body.data.<field>
|
|
66
|
+
# (and body.data.<field>.<entity> for mutations), not just one level.
|
|
67
|
+
out = data
|
|
68
|
+
for seg in reversed(m.group(1).split(".")):
|
|
69
|
+
out = {seg: out}
|
|
70
|
+
return out
|
|
64
71
|
|
|
65
72
|
def respond(status, data, extra=None):
|
|
66
73
|
payload = envelope(data)
|
|
@@ -260,10 +267,14 @@ class ProjectNameTestFeature(ProjectNameBaseFeature):
|
|
|
260
267
|
points = vs.getpath(ctx.config, "entity." + ctx.entity.get_name() + ".op." + opname + ".points")
|
|
261
268
|
point = vs.getelem(points, -1)
|
|
262
269
|
|
|
263
|
-
#
|
|
270
|
+
# Path AND query: a path-only read misses a query-addressed record
|
|
271
|
+
# (e.g. GET /result?trace_id=), which has no path param at all.
|
|
264
272
|
params_path = vs.getpath(point, "args.params")
|
|
265
273
|
reqd_params = vs.select(params_path, {"reqd": True})
|
|
266
|
-
|
|
274
|
+
query_path = vs.getpath(point, "args.query")
|
|
275
|
+
reqd_query = vs.select(query_path, {"reqd": True})
|
|
276
|
+
reqd = (vs.transform(reqd_params, ["`$EACH`", "", "`$KEY.name`"]) or []) + \
|
|
277
|
+
(vs.transform(reqd_query, ["`$EACH`", "", "`$KEY.name`"]) or [])
|
|
267
278
|
|
|
268
279
|
qand = []
|
|
269
280
|
q = {"`$AND`": qand}
|
|
@@ -97,11 +97,13 @@ def make_options_util(ctx):
|
|
|
97
97
|
|
|
98
98
|
optspec = {
|
|
99
99
|
"apikey": "",
|
|
100
|
+
"secret": "",
|
|
100
101
|
"base": "http://localhost:8000",
|
|
101
102
|
"prefix": "",
|
|
102
103
|
"suffix": "",
|
|
103
104
|
"auth": {
|
|
104
105
|
"prefix": "",
|
|
106
|
+
"basic": False,
|
|
105
107
|
},
|
|
106
108
|
"headers": {
|
|
107
109
|
"`$CHILD`": "`$STRING`",
|
|
@@ -105,6 +105,10 @@ class TestNetsimFeature:
|
|
|
105
105
|
@pytest.mark.skipif(not has_feature("retry"), reason="retry not in this SDK")
|
|
106
106
|
class TestRetryFeature:
|
|
107
107
|
|
|
108
|
+
# Drives netsim as the simulated network: runnable only when this
|
|
109
|
+
# SDK was generated with it (the harness skips absent features).
|
|
110
|
+
@pytest.mark.skipif(not has_feature("netsim"),
|
|
111
|
+
reason="netsim not in this SDK")
|
|
108
112
|
def test_retries_transient_failures_then_succeeds(self):
|
|
109
113
|
clock = make_clock()
|
|
110
114
|
h = make_client([
|
|
@@ -115,6 +119,10 @@ class TestRetryFeature:
|
|
|
115
119
|
assert h.op(op="load")["ok"] is True
|
|
116
120
|
assert h.client._retry["attempts"] == 2
|
|
117
121
|
|
|
122
|
+
# Drives netsim as the simulated network: runnable only when this
|
|
123
|
+
# SDK was generated with it (the harness skips absent features).
|
|
124
|
+
@pytest.mark.skipif(not has_feature("netsim"),
|
|
125
|
+
reason="netsim not in this SDK")
|
|
118
126
|
def test_gives_up_after_the_budget(self):
|
|
119
127
|
clock = make_clock()
|
|
120
128
|
h = make_client([
|
|
@@ -163,6 +171,10 @@ class TestRetryFeature:
|
|
|
163
171
|
assert h.op(op="load")["ok"] is True
|
|
164
172
|
assert state["n"] == 2
|
|
165
173
|
|
|
174
|
+
# Drives netsim as the simulated network: runnable only when this
|
|
175
|
+
# SDK was generated with it (the harness skips absent features).
|
|
176
|
+
@pytest.mark.skipif(not has_feature("netsim"),
|
|
177
|
+
reason="netsim not in this SDK")
|
|
166
178
|
def test_honours_a_server_retry_after(self):
|
|
167
179
|
clock = make_clock()
|
|
168
180
|
h = make_client([
|
|
@@ -174,6 +186,10 @@ class TestRetryFeature:
|
|
|
174
186
|
assert h.op(op="load")["ok"] is True
|
|
175
187
|
assert clock.time == 2000
|
|
176
188
|
|
|
189
|
+
# Drives netsim as the simulated network: runnable only when this
|
|
190
|
+
# SDK was generated with it (the harness skips absent features).
|
|
191
|
+
@pytest.mark.skipif(not has_feature("netsim"),
|
|
192
|
+
reason="netsim not in this SDK")
|
|
177
193
|
def test_default_jitter_path_still_succeeds(self):
|
|
178
194
|
h = make_client([
|
|
179
195
|
{"name": "netsim", "options": {"failTimes": 1}},
|
|
@@ -202,6 +218,10 @@ class TestRetryFeature:
|
|
|
202
218
|
@pytest.mark.skipif(not has_feature("timeout"), reason="timeout not in this SDK")
|
|
203
219
|
class TestTimeoutFeature:
|
|
204
220
|
|
|
221
|
+
# Drives netsim as the simulated network: runnable only when this
|
|
222
|
+
# SDK was generated with it (the harness skips absent features).
|
|
223
|
+
@pytest.mark.skipif(not has_feature("netsim"),
|
|
224
|
+
reason="netsim not in this SDK")
|
|
205
225
|
def test_a_slow_request_times_out(self):
|
|
206
226
|
clock = make_clock()
|
|
207
227
|
h = make_client([
|
|
@@ -438,6 +458,10 @@ class TestRbacFeature:
|
|
|
438
458
|
@pytest.mark.skipif(not has_feature("metrics"), reason="metrics not in this SDK")
|
|
439
459
|
class TestMetricsFeature:
|
|
440
460
|
|
|
461
|
+
# Drives netsim as the simulated network: runnable only when this
|
|
462
|
+
# SDK was generated with it (the harness skips absent features).
|
|
463
|
+
@pytest.mark.skipif(not has_feature("netsim"),
|
|
464
|
+
reason="netsim not in this SDK")
|
|
441
465
|
def test_counts_ok_and_err_per_op(self):
|
|
442
466
|
h = make_client([
|
|
443
467
|
{"name": "netsim", "options": {"failTimes": 1, "failStatus": 500}},
|
|
@@ -490,6 +514,10 @@ class TestTelemetryFeature:
|
|
|
490
514
|
assert sent["X-Trace-Id"] == h.client._telemetry["spans"][0]["traceId"]
|
|
491
515
|
assert re.match(r"^00-.+-.+-01$", sent["traceparent"])
|
|
492
516
|
|
|
517
|
+
# Drives netsim as the simulated network: runnable only when this
|
|
518
|
+
# SDK was generated with it (the harness skips absent features).
|
|
519
|
+
@pytest.mark.skipif(not has_feature("netsim"),
|
|
520
|
+
reason="netsim not in this SDK")
|
|
493
521
|
def test_records_a_failed_span_on_error(self):
|
|
494
522
|
h = make_client([
|
|
495
523
|
{"name": "netsim", "options": {"failTimes": 1, "failStatus": 500}},
|
|
@@ -498,6 +526,10 @@ class TestTelemetryFeature:
|
|
|
498
526
|
h.op(op="load")
|
|
499
527
|
assert h.client._telemetry["spans"][0]["ok"] is False
|
|
500
528
|
|
|
529
|
+
# Drives netsim as the simulated network: runnable only when this
|
|
530
|
+
# SDK was generated with it (the harness skips absent features).
|
|
531
|
+
@pytest.mark.skipif(not has_feature("netsim"),
|
|
532
|
+
reason="netsim not in this SDK")
|
|
501
533
|
def test_closes_each_span_exactly_once(self):
|
|
502
534
|
h = make_client([
|
|
503
535
|
{"name": "netsim", "options": {"failTimes": 1, "failStatus": 500}},
|
|
@@ -542,6 +574,10 @@ class TestDebugFeature:
|
|
|
542
574
|
assert len(seen) == 2
|
|
543
575
|
assert seen[0]["headers"]["authorization"] == "<redacted>"
|
|
544
576
|
|
|
577
|
+
# Drives netsim as the simulated network: runnable only when this
|
|
578
|
+
# SDK was generated with it (the harness skips absent features).
|
|
579
|
+
@pytest.mark.skipif(not has_feature("netsim"),
|
|
580
|
+
reason="netsim not in this SDK")
|
|
545
581
|
def test_captures_failures(self):
|
|
546
582
|
h = make_client([
|
|
547
583
|
{"name": "netsim", "options": {"failTimes": 1, "failStatus": 500}},
|
|
@@ -571,6 +607,10 @@ class TestDebugFeature:
|
|
|
571
607
|
@pytest.mark.skipif(not has_feature("audit"), reason="audit not in this SDK")
|
|
572
608
|
class TestAuditFeature:
|
|
573
609
|
|
|
610
|
+
# Drives netsim as the simulated network: runnable only when this
|
|
611
|
+
# SDK was generated with it (the harness skips absent features).
|
|
612
|
+
@pytest.mark.skipif(not has_feature("netsim"),
|
|
613
|
+
reason="netsim not in this SDK")
|
|
574
614
|
def test_one_record_per_op_with_sink_and_actor(self):
|
|
575
615
|
sink = []
|
|
576
616
|
h = make_client([
|
|
@@ -23,9 +23,20 @@ from projectname_sdk import ProjectNameSDK
|
|
|
23
23
|
|
|
24
24
|
_TEST_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
25
25
|
|
|
26
|
-
# Features with a corpus section
|
|
27
|
-
#
|
|
28
|
-
|
|
26
|
+
# Features with a corpus section — read from the corpus itself, so a
|
|
27
|
+
# project-authored section (a custom feature added under
|
|
28
|
+
# .sdk/test/feature/) runs without editing this file. Read eagerly:
|
|
29
|
+
# parametrize needs the names at collection time. An SDK generated
|
|
30
|
+
# without a listed feature still skips, not fails.
|
|
31
|
+
def _corpus_feature_names():
|
|
32
|
+
try:
|
|
33
|
+
with open(os.path.join(_TEST_DIR, "../../.sdk/test/test.json"), "r") as f:
|
|
34
|
+
return sorted((json.loads(f.read()).get("feature") or {}).keys())
|
|
35
|
+
except OSError:
|
|
36
|
+
return []
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
FEATURE_CORPUS_NAMES = _corpus_feature_names()
|
|
29
40
|
|
|
30
41
|
# The standard operation names, in the order the runner prefers them.
|
|
31
42
|
FEATURE_CORPUS_OPS = ["load", "list", "create", "update", "remove"]
|
|
@@ -19,9 +19,10 @@ require_relative "../ProjectName_sdk"
|
|
|
19
19
|
|
|
20
20
|
class FeatureCorpusTest < Minitest::Test
|
|
21
21
|
|
|
22
|
-
# Features with a corpus section
|
|
23
|
-
#
|
|
24
|
-
|
|
22
|
+
# Features with a corpus section are read from the corpus itself (see
|
|
23
|
+
# test_feature_corpus), so a project-authored section - a custom feature
|
|
24
|
+
# added under .sdk/test/feature/ - runs without editing this file. An SDK
|
|
25
|
+
# generated without a listed feature still skips, not fails.
|
|
25
26
|
|
|
26
27
|
# The standard operation names, in the order the runner prefers them.
|
|
27
28
|
FEATURE_CORPUS_OPS = %w[load list create update remove].freeze
|
|
@@ -192,6 +193,13 @@ class FeatureCorpusTest < Minitest::Test
|
|
|
192
193
|
end
|
|
193
194
|
|
|
194
195
|
def record(client, name)
|
|
196
|
+
# A corpus key is any manifest item name, so it may carry characters
|
|
197
|
+
# (foo-bar, foo.2) that cannot form a Ruby instance-variable name. The
|
|
198
|
+
# probe uses this lookup to SKIP such a section, so answer nil rather
|
|
199
|
+
# than letting instance_variable_get raise NameError for a feature this
|
|
200
|
+
# SDK could never have stored under that name anyway.
|
|
201
|
+
return nil unless name.match?(/\A[A-Za-z0-9_]+\z/)
|
|
202
|
+
|
|
195
203
|
client.instance_variable_get(:"@_#{name}")
|
|
196
204
|
end
|
|
197
205
|
|
|
@@ -218,7 +226,7 @@ class FeatureCorpusTest < Minitest::Test
|
|
|
218
226
|
end
|
|
219
227
|
|
|
220
228
|
def test_feature_corpus
|
|
221
|
-
|
|
229
|
+
(corpus["feature"] || {}).keys.sort.each do |name|
|
|
222
230
|
section = (corpus["feature"] || {})[name]
|
|
223
231
|
next if section.nil?
|
|
224
232
|
|
|
@@ -43,6 +43,13 @@ function ownIdField(config: any, getpath: any, entityName: string): string {
|
|
|
43
43
|
// key, so move on to the next op rather than guess from it.
|
|
44
44
|
const lastPart = 0 < parts.length ? String(parts[parts.length - 1]) : ''
|
|
45
45
|
if (lastPart.startsWith('{')) return lastPart.slice(1, -1)
|
|
46
|
+
|
|
47
|
+
// No path param at all (or the route ends in a literal, e.g.
|
|
48
|
+
// /orgs/{org}/private-registries/public-key): a single required QUERY
|
|
49
|
+
// param can still be the record's own key (e.g. GET /result?trace_id=).
|
|
50
|
+
const query = (best && best.args && best.args.query) || []
|
|
51
|
+
const reqdQuery = query.filter((q: any) => false !== q.reqd)
|
|
52
|
+
if (1 === reqdQuery.length) return String(reqdQuery[0].name)
|
|
46
53
|
}
|
|
47
54
|
return 'id'
|
|
48
55
|
}
|
|
@@ -332,10 +339,17 @@ class TestFeature extends BaseFeature {
|
|
|
332
339
|
}
|
|
333
340
|
}
|
|
334
341
|
|
|
335
|
-
|
|
342
|
+
// Path AND query: a path-only read misses a query-addressed record
|
|
343
|
+
// (e.g. GET /result?trace_id=), which has no path param at all.
|
|
344
|
+
const reqdParams = transform(
|
|
336
345
|
select(getpath(point, ['args', 'params']), { reqd: true }),
|
|
337
346
|
['`$EACH`', '', '`$KEY.name`']
|
|
338
347
|
)
|
|
348
|
+
const reqdQuery = transform(
|
|
349
|
+
select(getpath(point, ['args', 'query']), { reqd: true }),
|
|
350
|
+
['`$EACH`', '', '`$KEY.name`']
|
|
351
|
+
)
|
|
352
|
+
const reqd = [...(reqdParams || []), ...(reqdQuery || [])]
|
|
339
353
|
|
|
340
354
|
const qand: any[] = []
|
|
341
355
|
const q = { '`$AND`': qand }
|
|
@@ -44,11 +44,13 @@ function makeOptions(ctx: Context) {
|
|
|
44
44
|
// Standard SDK option values.
|
|
45
45
|
const optspec = {
|
|
46
46
|
apikey: '',
|
|
47
|
+
secret: '',
|
|
47
48
|
base: 'http://localhost:8000',
|
|
48
49
|
prefix: '',
|
|
49
50
|
suffix: '',
|
|
50
51
|
auth: {
|
|
51
|
-
prefix: ''
|
|
52
|
+
prefix: '',
|
|
53
|
+
basic: false
|
|
52
54
|
},
|
|
53
55
|
headers: {
|
|
54
56
|
'`$CHILD`': '`$STRING`'
|
|
@@ -5,6 +5,7 @@ import { Context, Spec } from '../types'
|
|
|
5
5
|
const HEADER_auth = 'authorization'
|
|
6
6
|
|
|
7
7
|
const OPTION_apikey = 'apikey'
|
|
8
|
+
const OPTION_secret = 'secret'
|
|
8
9
|
|
|
9
10
|
const NOTFOUND = '__NOTFOUND__'
|
|
10
11
|
|
|
@@ -40,6 +41,25 @@ function prepareAuth(ctx: Context): Spec | Error {
|
|
|
40
41
|
|
|
41
42
|
const apikey = getprop(options, OPTION_apikey, NOTFOUND)
|
|
42
43
|
|
|
44
|
+
// True HTTP Basic Auth needs TWO credentials, base64-joined - a single
|
|
45
|
+
// token in the header (the branch below) can never authenticate against
|
|
46
|
+
// an API that actually checks `Authorization: Basic base64(user:pass)`.
|
|
47
|
+
if (true === options.auth.basic) {
|
|
48
|
+
const secret = getprop(options, OPTION_secret, NOTFOUND)
|
|
49
|
+
const noApikey = NOTFOUND === apikey || null == apikey || '' === apikey
|
|
50
|
+
const noSecret = NOTFOUND === secret || null == secret || '' === secret
|
|
51
|
+
|
|
52
|
+
if (noApikey || noSecret) {
|
|
53
|
+
delprop(headers, HEADER_auth)
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const b64 = Buffer.from(apikey + ':' + secret).toString('base64')
|
|
57
|
+
setprop(headers, HEADER_auth, prefix ? prefix + ' ' + b64 : b64)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return spec
|
|
61
|
+
}
|
|
62
|
+
|
|
43
63
|
if (NOTFOUND === apikey || null == apikey || '' === apikey) {
|
|
44
64
|
delprop(headers, HEADER_auth)
|
|
45
65
|
}
|
|
@@ -25,9 +25,19 @@ import { join } from 'node:path'
|
|
|
25
25
|
import { SDK, TEST_JSON_FILE } from '../utility/index'
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
// Features with a corpus section
|
|
29
|
-
//
|
|
30
|
-
|
|
28
|
+
// Features with a corpus section — read from the corpus itself, so a
|
|
29
|
+
// project-authored section (a custom feature added under
|
|
30
|
+
// .sdk/test/feature/) runs without editing this file. Read eagerly: the
|
|
31
|
+
// node test runner collects the per-feature tests at describe time,
|
|
32
|
+
// before any `before` hook fires. An SDK generated without a listed
|
|
33
|
+
// feature still skips, not fails.
|
|
34
|
+
const FEATURES = Object.keys((() => {
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(readFileSync(
|
|
37
|
+
join(__dirname, '..', TEST_JSON_FILE), 'utf8')).feature || {}
|
|
38
|
+
}
|
|
39
|
+
catch (e) { return {} }
|
|
40
|
+
})()).sort()
|
|
31
41
|
|
|
32
42
|
|
|
33
43
|
// One operation this SDK can actually perform.
|
|
@@ -21,6 +21,16 @@ function recordingServer(reply?: (n: number, fetchdef: any) => any) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
|
|
24
|
+
// A subtest that drives a second feature (netsim as the simulated network)
|
|
25
|
+
// can only run when this SDK was generated with it: the harness skips
|
|
26
|
+
// absent features, which would leave the scenario unsimulated and the
|
|
27
|
+
// assertions meaningless. Same convention as the other targets.
|
|
28
|
+
function skipWithout(name: string): string | boolean {
|
|
29
|
+
return hasFeature(name) ? false
|
|
30
|
+
: ('this SDK was generated without the ' + name + ' feature')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
24
34
|
describe('feature', () => {
|
|
25
35
|
|
|
26
36
|
test('at least the test feature is present', () => {
|
|
@@ -95,7 +105,7 @@ describe('feature', () => {
|
|
|
95
105
|
// --- retry ----------------------------------------------------------------
|
|
96
106
|
if (hasFeature('retry')) describe('retry', () => {
|
|
97
107
|
|
|
98
|
-
test('retries transient failures then succeeds', async () => {
|
|
108
|
+
test('retries transient failures then succeeds', { skip: skipWithout('netsim') }, async () => {
|
|
99
109
|
const clock = makeClock()
|
|
100
110
|
const h = makeClient({ features: [
|
|
101
111
|
{ name: 'netsim', options: { failTimes: 2, failStatus: 503 } },
|
|
@@ -105,7 +115,7 @@ describe('feature', () => {
|
|
|
105
115
|
strictEqual(h.client._retry.attempts, 2)
|
|
106
116
|
})
|
|
107
117
|
|
|
108
|
-
test('gives up after the budget', async () => {
|
|
118
|
+
test('gives up after the budget', { skip: skipWithout('netsim') }, async () => {
|
|
109
119
|
const clock = makeClock()
|
|
110
120
|
const h = makeClient({ features: [
|
|
111
121
|
{ name: 'netsim', options: { failTimes: 9, failStatus: 500 } },
|
|
@@ -131,7 +141,7 @@ describe('feature', () => {
|
|
|
131
141
|
strictEqual(n, 3)
|
|
132
142
|
})
|
|
133
143
|
|
|
134
|
-
test('honours a server Retry-After', async () => {
|
|
144
|
+
test('honours a server Retry-After', { skip: skipWithout('netsim') }, async () => {
|
|
135
145
|
const clock = makeClock()
|
|
136
146
|
const h = makeClient({ features: [
|
|
137
147
|
{ name: 'netsim', options: { rateLimitTimes: 1, retryAfter: 2 } },
|
|
@@ -141,7 +151,7 @@ describe('feature', () => {
|
|
|
141
151
|
strictEqual(clock.time, 2000)
|
|
142
152
|
})
|
|
143
153
|
|
|
144
|
-
test('default jitter path still succeeds', async () => {
|
|
154
|
+
test('default jitter path still succeeds', { skip: skipWithout('netsim') }, async () => {
|
|
145
155
|
const h = makeClient({ features: [
|
|
146
156
|
{ name: 'netsim', options: { failTimes: 1 } },
|
|
147
157
|
{ name: 'retry', options: { retries: 2, minDelay: 0 } },
|
|
@@ -154,7 +164,7 @@ describe('feature', () => {
|
|
|
154
164
|
// --- timeout --------------------------------------------------------------
|
|
155
165
|
if (hasFeature('timeout')) describe('timeout', () => {
|
|
156
166
|
|
|
157
|
-
test('a slow request times out', async () => {
|
|
167
|
+
test('a slow request times out', { skip: skipWithout('netsim') }, async () => {
|
|
158
168
|
const h = makeClient({ features: [
|
|
159
169
|
{ name: 'netsim', options: { latency: 80 } },
|
|
160
170
|
{ name: 'timeout', options: { ms: 10 } },
|
|
@@ -319,7 +329,7 @@ describe('feature', () => {
|
|
|
319
329
|
// --- metrics --------------------------------------------------------------
|
|
320
330
|
if (hasFeature('metrics')) describe('metrics', () => {
|
|
321
331
|
|
|
322
|
-
test('counts ok and err per op', async () => {
|
|
332
|
+
test('counts ok and err per op', { skip: skipWithout('netsim') }, async () => {
|
|
323
333
|
const h = makeClient({ features: [
|
|
324
334
|
{ name: 'netsim', options: { failTimes: 1, failStatus: 500 } },
|
|
325
335
|
{ name: 'metrics', options: {} },
|
|
@@ -352,7 +362,7 @@ describe('feature', () => {
|
|
|
352
362
|
ok(/^00-.+-.+-01$/.test(sent['traceparent']))
|
|
353
363
|
})
|
|
354
364
|
|
|
355
|
-
test('records a failed span on error', async () => {
|
|
365
|
+
test('records a failed span on error', { skip: skipWithout('netsim') }, async () => {
|
|
356
366
|
const h = makeClient({ features: [
|
|
357
367
|
{ name: 'netsim', options: { failTimes: 1, failStatus: 500 } },
|
|
358
368
|
{ name: 'telemetry', options: {} },
|
|
@@ -377,7 +387,7 @@ describe('feature', () => {
|
|
|
377
387
|
strictEqual(seen[0].headers.authorization, '<redacted>')
|
|
378
388
|
})
|
|
379
389
|
|
|
380
|
-
test('captures failures', async () => {
|
|
390
|
+
test('captures failures', { skip: skipWithout('netsim') }, async () => {
|
|
381
391
|
const h = makeClient({ features: [
|
|
382
392
|
{ name: 'netsim', options: { failTimes: 1, failStatus: 500 } },
|
|
383
393
|
{ name: 'debug', options: {} },
|
|
@@ -391,7 +401,7 @@ describe('feature', () => {
|
|
|
391
401
|
// --- audit ----------------------------------------------------------------
|
|
392
402
|
if (hasFeature('audit')) describe('audit', () => {
|
|
393
403
|
|
|
394
|
-
test('one record per op with sink + actor', async () => {
|
|
404
|
+
test('one record per op with sink + actor', { skip: skipWithout('netsim') }, async () => {
|
|
395
405
|
const sink: any[] = []
|
|
396
406
|
const h = makeClient({ features: [
|
|
397
407
|
{ name: 'netsim', options: { failTimes: 1, failStatus: 500 } },
|