@browserstack/mcp-server 1.5.0-beta.20 → 1.5.0-beta.21
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/README.md +48 -32
- package/dist/config.d.ts +4 -1
- package/dist/config.js +23 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +7 -3
- package/dist/lib/constants.d.ts +3 -0
- package/dist/lib/constants.js +3 -0
- package/dist/lib/instrumentation.d.ts +14 -2
- package/dist/lib/instrumentation.js +104 -29
- package/dist/lib/node-version-notice.d.ts +1 -0
- package/dist/lib/node-version-notice.js +9 -0
- package/dist/lib/tool-latency.d.ts +4 -0
- package/dist/lib/tool-latency.js +16 -0
- package/dist/lib/untrusted-content.d.ts +15 -0
- package/dist/lib/untrusted-content.js +24 -0
- package/dist/lib/upload-validator.d.ts +3 -2
- package/dist/lib/upload-validator.js +18 -15
- package/dist/lib/utils.js +10 -3
- package/dist/lib/version-resolver.d.ts +0 -5
- package/dist/lib/version-resolver.js +8 -2
- package/dist/logger.js +1 -10
- package/dist/server-factory.js +10 -6
- package/dist/tools/accessibility.js +9 -5
- package/dist/tools/accessiblity-utils/accessibility-rag.js +3 -1
- package/dist/tools/appautomate-utils/native-execution/constants.js +4 -2
- package/dist/tools/appautomate.js +3 -1
- package/dist/tools/applive.js +1 -1
- package/dist/tools/ask-browserstack/central-oauth.d.ts +120 -0
- package/dist/tools/ask-browserstack/central-oauth.js +277 -0
- package/dist/tools/ask-browserstack/config.d.ts +102 -0
- package/dist/tools/ask-browserstack/config.js +140 -0
- package/dist/tools/ask-browserstack/egress.d.ts +34 -0
- package/dist/tools/ask-browserstack/egress.js +31 -0
- package/dist/tools/ask-browserstack/register.d.ts +61 -0
- package/dist/tools/ask-browserstack/register.js +416 -0
- package/dist/tools/ask-browserstack/relay.d.ts +201 -0
- package/dist/tools/ask-browserstack/relay.js +577 -0
- package/dist/tools/ask-browserstack/stream.d.ts +116 -0
- package/dist/tools/ask-browserstack/stream.js +236 -0
- package/dist/tools/ask-browserstack/types.d.ts +196 -0
- package/dist/tools/ask-browserstack/types.js +14 -0
- package/dist/tools/automate-utils/list-session-ids.d.ts +28 -0
- package/dist/tools/automate-utils/list-session-ids.js +87 -0
- package/dist/tools/automate-utils/resolve-hashed-build-id.d.ts +30 -0
- package/dist/tools/automate-utils/resolve-hashed-build-id.js +124 -0
- package/dist/tools/automate.d.ts +7 -0
- package/dist/tools/automate.js +104 -1
- package/dist/tools/bstack-sdk.js +2 -2
- package/dist/tools/build-insights.js +41 -2
- package/dist/tools/failurelogs-utils/app-automate.js +4 -3
- package/dist/tools/failurelogs-utils/automate.js +5 -4
- package/dist/tools/failurelogs-utils/resolve-app-build-id.d.ts +2 -0
- package/dist/tools/failurelogs-utils/resolve-app-build-id.js +5 -0
- package/dist/tools/failurelogs-utils/video.d.ts +3 -0
- package/dist/tools/failurelogs-utils/video.js +25 -0
- package/dist/tools/get-failure-logs.js +30 -11
- package/dist/tools/observability.js +3 -1
- package/dist/tools/percy-sdk.js +9 -9
- package/dist/tools/rca-agent-utils/format-rca.js +5 -4
- package/dist/tools/rca-agent-utils/get-failed-test-id.js +12 -0
- package/dist/tools/rca-agent-utils/types.d.ts +1 -0
- package/dist/tools/rca-agent.js +5 -2
- package/dist/tools/review-agent.js +2 -1
- package/dist/tools/sdk-utils/common/constants.d.ts +1 -1
- package/dist/tools/sdk-utils/common/constants.js +2 -1
- package/dist/tools/selfheal.js +6 -3
- package/dist/tools/testmanagement-utils/TCG-utils/api.js +26 -7
- package/dist/tools/testmanagement-utils/TCG-utils/config.d.ts +2 -0
- package/dist/tools/testmanagement-utils/TCG-utils/config.js +5 -0
- package/dist/tools/testmanagement-utils/testcase-from-file.js +2 -1
- package/dist/tools/testmanagement-utils/upload-file.js +16 -2
- package/dist/tools/testmanagement.js +39 -17
- package/dist/tools/tool-handoff.d.ts +66 -0
- package/dist/tools/tool-handoff.js +78 -0
- package/package.json +5 -11
- package/capability/loadtesting.capability-index.json +0 -1870
- package/capability/tm.capability-index.json +0 -50104
- package/dist/tools/capability-registry/bind.d.ts +0 -29
- package/dist/tools/capability-registry/bind.js +0 -329
- package/dist/tools/capability-registry/config.d.ts +0 -62
- package/dist/tools/capability-registry/config.js +0 -218
- package/dist/tools/capability-registry/discovery.d.ts +0 -44
- package/dist/tools/capability-registry/discovery.js +0 -99
- package/dist/tools/capability-registry/egress.d.ts +0 -44
- package/dist/tools/capability-registry/egress.js +0 -174
- package/dist/tools/capability-registry/index-loader.d.ts +0 -133
- package/dist/tools/capability-registry/index-loader.js +0 -404
- package/dist/tools/capability-registry/register.d.ts +0 -48
- package/dist/tools/capability-registry/register.js +0 -604
- package/dist/tools/capability-registry/resolve.d.ts +0 -38
- package/dist/tools/capability-registry/resolve.js +0 -45
- package/dist/tools/capability-registry/search.d.ts +0 -170
- package/dist/tools/capability-registry/search.js +0 -709
- package/dist/tools/capability-registry/types.d.ts +0 -282
- package/dist/tools/capability-registry/types.js +0 -33
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Turn grouped caller arguments into a path, a query and a body.
|
|
3
|
-
*
|
|
4
|
-
* Arguments arrive GROUPED — {path_params, query, body} — because spec parameter names
|
|
5
|
-
* collide across locations: four tm operations declare one name in two places (`bulk-move`
|
|
6
|
-
* has `folder_id` as both a path parameter and a body field). A flat map cannot say which
|
|
7
|
-
* one is meant, which is exactly why the Python side used to rename body fields `body_*`.
|
|
8
|
-
* Grouping removes the collision AND the rename, so a caller sends the spec's own names.
|
|
9
|
-
*/
|
|
10
|
-
import { Capability, WireParam } from "./types.js";
|
|
11
|
-
export interface GroupedArguments {
|
|
12
|
-
path_params?: Record<string, unknown>;
|
|
13
|
-
query?: Record<string, unknown>;
|
|
14
|
-
body?: Record<string, unknown>;
|
|
15
|
-
}
|
|
16
|
-
export interface BoundRequest {
|
|
17
|
-
path: string;
|
|
18
|
-
query: Record<string, unknown>;
|
|
19
|
-
body?: Record<string, unknown>;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Check one argument against its declared schema, raising a caller-safe error.
|
|
23
|
-
*
|
|
24
|
-
* Type checking is also the injection defence for path parameters: most of tm's 278 path
|
|
25
|
-
* parameters are `type: integer`, so a traversal attempt like `../../admin-v2` fails here
|
|
26
|
-
* rather than being encoded into a URL.
|
|
27
|
-
*/
|
|
28
|
-
export declare function coerce(value: unknown, param: WireParam): unknown;
|
|
29
|
-
export declare function bind(capability: Capability, args: GroupedArguments): BoundRequest;
|
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Turn grouped caller arguments into a path, a query and a body.
|
|
3
|
-
*
|
|
4
|
-
* Arguments arrive GROUPED — {path_params, query, body} — because spec parameter names
|
|
5
|
-
* collide across locations: four tm operations declare one name in two places (`bulk-move`
|
|
6
|
-
* has `folder_id` as both a path parameter and a body field). A flat map cannot say which
|
|
7
|
-
* one is meant, which is exactly why the Python side used to rename body fields `body_*`.
|
|
8
|
-
* Grouping removes the collision AND the rename, so a caller sends the spec's own names.
|
|
9
|
-
*/
|
|
10
|
-
import { InvocationError } from "./index-loader.js";
|
|
11
|
-
/**
|
|
12
|
-
* String formats worth ENFORCING, as opposed to merely publishing.
|
|
13
|
-
*
|
|
14
|
-
* A validator that rejects a correct value is worse than no validator: the caller cannot
|
|
15
|
-
* route around it, and the request that would have worked never leaves. So this covers only
|
|
16
|
-
* the formats where "wrong" is unambiguous and a legitimate value cannot trip it.
|
|
17
|
-
*
|
|
18
|
-
* tm declares eight formats. `date`, `date-time` and `uuid` are here. `email` and `uri` are
|
|
19
|
-
* deliberately NOT — every compact regex for either rejects addresses and URLs that servers
|
|
20
|
-
* accept, and being wrong in that direction blocks real work. `int64`, `float` and `binary`
|
|
21
|
-
* say what a number or blob is, which `type` already covers.
|
|
22
|
-
*/
|
|
23
|
-
const FORMATS = {
|
|
24
|
-
date: {
|
|
25
|
-
// A real calendar date, so 2026-02-31 fails rather than being reformatted.
|
|
26
|
-
test: (v) => /^\d{4}-\d{2}-\d{2}$/.test(v) &&
|
|
27
|
-
!Number.isNaN(Date.parse(`${v}T00:00:00Z`)) &&
|
|
28
|
-
new Date(`${v}T00:00:00Z`).toISOString().startsWith(v),
|
|
29
|
-
want: "a date (YYYY-MM-DD)",
|
|
30
|
-
},
|
|
31
|
-
"date-time": {
|
|
32
|
-
// Permissive on purpose: offset or Z, optional fractional seconds. Tightening this
|
|
33
|
-
// buys nothing and starts rejecting timestamps the product would have taken.
|
|
34
|
-
test: (v) => /^\d{4}-\d{2}-\d{2}[Tt ]\d{2}:\d{2}:\d{2}(\.\d+)?([Zz]|[+-]\d{2}:?\d{2})?$/.test(v) && !Number.isNaN(Date.parse(v)),
|
|
35
|
-
want: "a date-time (e.g. 2026-01-31T09:30:00Z)",
|
|
36
|
-
},
|
|
37
|
-
uuid: {
|
|
38
|
-
test: (v) => /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(v),
|
|
39
|
-
want: "a UUID",
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* A declared `pattern`, compiled once, or undefined if it will not compile here.
|
|
44
|
-
*
|
|
45
|
-
* `u` because tm's patterns use `\p{L}`/`\p{N}`, which are a syntax error without it. A
|
|
46
|
-
* pattern this engine cannot compile is SKIPPED rather than thrown: the index is generated
|
|
47
|
-
* from someone else's spec, and refusing to invoke a working endpoint because its regex
|
|
48
|
-
* dialect differs would be our bug landing on the caller.
|
|
49
|
-
*/
|
|
50
|
-
const patternCache = new Map();
|
|
51
|
-
function compiled(pattern) {
|
|
52
|
-
if (!patternCache.has(pattern)) {
|
|
53
|
-
let regex;
|
|
54
|
-
try {
|
|
55
|
-
regex = new RegExp(pattern, "u");
|
|
56
|
-
}
|
|
57
|
-
catch {
|
|
58
|
-
try {
|
|
59
|
-
regex = new RegExp(pattern);
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
regex = undefined;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
patternCache.set(pattern, regex);
|
|
66
|
-
}
|
|
67
|
-
return patternCache.get(pattern);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Every constraint the parameter declares, checked against the COERCED value.
|
|
71
|
-
*
|
|
72
|
-
* Runs inside `bind`, which register.ts calls dry before the write-consent gate — so a
|
|
73
|
-
* value that breaks a constraint is refused before the user is asked to approve anything,
|
|
74
|
-
* and nothing reaches egress.
|
|
75
|
-
*
|
|
76
|
-
* `label` carries the parent name for a nested field, so the message names `test_case.name`
|
|
77
|
-
* rather than a bare `name` the caller would have to go looking for.
|
|
78
|
-
*/
|
|
79
|
-
function checkConstraints(value, param, label = param.name) {
|
|
80
|
-
const fail = (what) => {
|
|
81
|
-
throw new InvocationError(`'${label}' ${what}`);
|
|
82
|
-
};
|
|
83
|
-
if (typeof value === "number") {
|
|
84
|
-
if (param.minimum !== undefined && value < param.minimum)
|
|
85
|
-
fail(`must be at least ${param.minimum}`);
|
|
86
|
-
if (param.maximum !== undefined && value > param.maximum)
|
|
87
|
-
fail(`must be at most ${param.maximum}`);
|
|
88
|
-
if (param.multipleOf !== undefined && param.multipleOf > 0) {
|
|
89
|
-
// Scale BOTH to integers before the modulo: 0.3 % 0.1 is 0.09999… in binary floating
|
|
90
|
-
// point and would reject a value the product accepts. The scale has to cover the
|
|
91
|
-
// value's decimals as well as the step's — scaling by the step alone rounds 0.25 to
|
|
92
|
-
// 3 against a step of 1, which then divides evenly and lets a bad value through.
|
|
93
|
-
const scale = 10 ** Math.max(decimals(param.multipleOf), decimals(value));
|
|
94
|
-
if (Math.round(value * scale) % Math.round(param.multipleOf * scale) !==
|
|
95
|
-
0)
|
|
96
|
-
fail(`must be a multiple of ${param.multipleOf}`);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (typeof value === "string") {
|
|
100
|
-
if (param.minLength !== undefined && value.length < param.minLength)
|
|
101
|
-
fail(`must be at least ${param.minLength} character(s)`);
|
|
102
|
-
if (param.maxLength !== undefined && value.length > param.maxLength)
|
|
103
|
-
fail(`must be at most ${param.maxLength} character(s)`);
|
|
104
|
-
if (param.pattern) {
|
|
105
|
-
const regex = compiled(param.pattern);
|
|
106
|
-
if (regex && !regex.test(value))
|
|
107
|
-
fail(`must match ${param.pattern}`);
|
|
108
|
-
}
|
|
109
|
-
const format = param.format ? FORMATS[param.format] : undefined;
|
|
110
|
-
if (format && !format.test(value))
|
|
111
|
-
fail(`must be ${format.want}`);
|
|
112
|
-
}
|
|
113
|
-
if (Array.isArray(value)) {
|
|
114
|
-
if (param.minItems !== undefined && value.length < param.minItems)
|
|
115
|
-
fail(`must have at least ${param.minItems} item(s)`);
|
|
116
|
-
if (param.maxItems !== undefined && value.length > param.maxItems)
|
|
117
|
-
fail(`must have at most ${param.maxItems} item(s)`);
|
|
118
|
-
if (param.uniqueItems) {
|
|
119
|
-
const seen = new Set(value.map((item) => JSON.stringify(item)));
|
|
120
|
-
if (seen.size !== value.length)
|
|
121
|
-
fail("must not contain duplicate items");
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/** Decimal places, for scaling `multipleOf` out of floating point. */
|
|
126
|
-
function decimals(n) {
|
|
127
|
-
const text = String(n);
|
|
128
|
-
const dot = text.indexOf(".");
|
|
129
|
-
return dot < 0 ? 0 : text.length - dot - 1;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* The declared fields one level inside an object, or inside each item of an array.
|
|
133
|
-
*
|
|
134
|
-
* Only what `fields` names is checked, and an undeclared key is left alone — `fields` is a
|
|
135
|
-
* projection of the shape, not a closed contract, so rejecting the rest would refuse valid
|
|
136
|
-
* bodies. That is the opposite of the top level, where the full parameter list IS known and
|
|
137
|
-
* an unknown name is an error.
|
|
138
|
-
*/
|
|
139
|
-
function checkFields(value, param) {
|
|
140
|
-
if (!param.fields?.length)
|
|
141
|
-
return;
|
|
142
|
-
const items = Array.isArray(value) ? value : [value];
|
|
143
|
-
for (const item of items) {
|
|
144
|
-
if (typeof item !== "object" || item === null || Array.isArray(item))
|
|
145
|
-
continue;
|
|
146
|
-
const record = item;
|
|
147
|
-
for (const field of param.fields) {
|
|
148
|
-
if (!(field.name in record)) {
|
|
149
|
-
if (field.required)
|
|
150
|
-
throw new InvocationError(`missing required parameter(s): ${param.name}.${field.name}`);
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
const label = `${param.name}.${field.name}`;
|
|
154
|
-
const coerced = coerceType(record[field.name], field, label);
|
|
155
|
-
checkConstraints(coerced, field, label);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Check one argument against its declared schema, raising a caller-safe error.
|
|
161
|
-
*
|
|
162
|
-
* Type checking is also the injection defence for path parameters: most of tm's 278 path
|
|
163
|
-
* parameters are `type: integer`, so a traversal attempt like `../../admin-v2` fails here
|
|
164
|
-
* rather than being encoded into a URL.
|
|
165
|
-
*/
|
|
166
|
-
export function coerce(value, param) {
|
|
167
|
-
const coerced = coerceType(value, param);
|
|
168
|
-
checkConstraints(coerced, param);
|
|
169
|
-
checkFields(coerced, param);
|
|
170
|
-
return coerced;
|
|
171
|
-
}
|
|
172
|
-
function coerceType(value, param, label = param.name) {
|
|
173
|
-
const expected = param.type;
|
|
174
|
-
if (expected === "object" || expected === "array") {
|
|
175
|
-
// An opaque body object is passed through as given: the spec does not describe its
|
|
176
|
-
// fields, so validating or reshaping it would mean inventing a contract.
|
|
177
|
-
if (expected === "object" &&
|
|
178
|
-
(typeof value !== "object" || value === null || Array.isArray(value))) {
|
|
179
|
-
throw new InvocationError(`'${label}' must be an object`);
|
|
180
|
-
}
|
|
181
|
-
if (expected === "array" && !Array.isArray(value)) {
|
|
182
|
-
throw new InvocationError(`'${label}' must be a list`);
|
|
183
|
-
}
|
|
184
|
-
return value;
|
|
185
|
-
}
|
|
186
|
-
if (expected === "integer" || expected === "number") {
|
|
187
|
-
const parsed = Number(String(value).trim());
|
|
188
|
-
if (!Number.isFinite(parsed)) {
|
|
189
|
-
throw new InvocationError(`'${label}' must be a number`);
|
|
190
|
-
}
|
|
191
|
-
return expected === "integer" ? Math.trunc(parsed) : parsed;
|
|
192
|
-
}
|
|
193
|
-
if (expected === "boolean") {
|
|
194
|
-
if (typeof value === "boolean")
|
|
195
|
-
return value;
|
|
196
|
-
const text = String(value).trim().toLowerCase();
|
|
197
|
-
if (["true", "1", "yes"].includes(text))
|
|
198
|
-
return true;
|
|
199
|
-
if (["false", "0", "no"].includes(text))
|
|
200
|
-
return false;
|
|
201
|
-
throw new InvocationError(`'${label}' must be true or false`);
|
|
202
|
-
}
|
|
203
|
-
// NO DECLARED TYPE: pass the value through as given.
|
|
204
|
-
//
|
|
205
|
-
// The fallthrough below is String(value), which is right for a declared string and
|
|
206
|
-
// silently destructive for anything the spec left untyped. create_report_v2 declares
|
|
207
|
-
// `mail_to` and `report_filters` with no type and the API wants objects for both, so a
|
|
208
|
-
// correct payload was serialised to the literal "[object Object]" and refused:
|
|
209
|
-
//
|
|
210
|
-
// The property '#/mail_to' of type string did not match the following type: object
|
|
211
|
-
//
|
|
212
|
-
// The caller sent the right thing, this layer broke it, and the server's message blames
|
|
213
|
-
// the caller for a string it never wrote. An untyped parameter means the spec declines to
|
|
214
|
-
// say what shape it is — which is a reason to leave it alone, not to guess "string".
|
|
215
|
-
const untyped = !expected;
|
|
216
|
-
if (untyped && (typeof value === "object" || typeof value === "boolean")) {
|
|
217
|
-
return value;
|
|
218
|
-
}
|
|
219
|
-
const text = String(value);
|
|
220
|
-
if (param.values && param.values.length > 0) {
|
|
221
|
-
const allowed = param.values.map((v) => String(v));
|
|
222
|
-
if (!allowed.includes(text)) {
|
|
223
|
-
throw new InvocationError(`'${label}' must be one of: ${allowed.join(", ")}`);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return text;
|
|
227
|
-
}
|
|
228
|
-
/** Place a value at a JSON-pointer-ish path, creating the objects on the way. */
|
|
229
|
-
function place(root, pointer, value) {
|
|
230
|
-
const segments = pointer.split("/").filter((segment) => segment !== "");
|
|
231
|
-
let cursor = root;
|
|
232
|
-
for (const segment of segments.slice(0, -1)) {
|
|
233
|
-
const next = cursor[segment];
|
|
234
|
-
if (typeof next !== "object" || next === null || Array.isArray(next)) {
|
|
235
|
-
cursor[segment] = {};
|
|
236
|
-
}
|
|
237
|
-
cursor = cursor[segment];
|
|
238
|
-
}
|
|
239
|
-
cursor[segments[segments.length - 1]] = value;
|
|
240
|
-
}
|
|
241
|
-
const GROUPS = [
|
|
242
|
-
{ group: "path_params", declared: "path_params" },
|
|
243
|
-
{ group: "query", declared: "query" },
|
|
244
|
-
{ group: "body", declared: "body" },
|
|
245
|
-
];
|
|
246
|
-
export function bind(capability, args) {
|
|
247
|
-
let path = capability.path;
|
|
248
|
-
const query = {};
|
|
249
|
-
const body = {};
|
|
250
|
-
for (const { group, declared } of GROUPS) {
|
|
251
|
-
const supplied = args[group] || {};
|
|
252
|
-
if (typeof supplied !== "object" ||
|
|
253
|
-
supplied === null ||
|
|
254
|
-
Array.isArray(supplied)) {
|
|
255
|
-
throw new InvocationError(`${group} must be an object of name -> value`);
|
|
256
|
-
}
|
|
257
|
-
const params = capability[declared] || [];
|
|
258
|
-
const byName = new Map(params.map((param) => [param.name, param]));
|
|
259
|
-
// Unknown arguments are an error rather than being dropped: silently ignoring a
|
|
260
|
-
// misspelled filter would return a larger result set that looks like a correct answer.
|
|
261
|
-
const unknown = Object.keys(supplied).filter((name) => !byName.has(name));
|
|
262
|
-
if (unknown.length > 0) {
|
|
263
|
-
// A CALLER WHO SENT THE WRAPPER WE BUILD DESERVES TO BE TOLD SO.
|
|
264
|
-
//
|
|
265
|
-
// Most of these endpoints want a nested body — Rails `params.require(:test_case)` —
|
|
266
|
-
// and the fields declare that as `json_path: /test_case/name`, so this layer
|
|
267
|
-
// assembles the wrapper itself and the caller sends the fields flat. A caller who
|
|
268
|
-
// wraps it by hand therefore sends a key that is never a declared param, and the
|
|
269
|
-
// bare message reads as "that field does not exist" when the truth is the opposite:
|
|
270
|
-
// it exists, and building it is our job.
|
|
271
|
-
//
|
|
272
|
-
// Worth special-casing because the guidance itself has been telling callers to wrap:
|
|
273
|
-
// 25 tm capabilities carried a line describing the WIRE format to a caller who never
|
|
274
|
-
// writes the wire. Those lines are being corrected, but an agent working from an
|
|
275
|
-
// older artifact, or reasoning from the Rails convention, lands here either way.
|
|
276
|
-
const wrappers = new Set(params
|
|
277
|
-
.map((param) => param.json_path)
|
|
278
|
-
.filter((path) => Boolean(path))
|
|
279
|
-
.map((path) => path.replace(/^\//, "").split("/")[0])
|
|
280
|
-
.filter((segment) => segment && !byName.has(segment)));
|
|
281
|
-
const sentAWrapper = unknown.filter((name) => wrappers.has(name));
|
|
282
|
-
throw new InvocationError(`unknown ${group}: ${unknown.sort().join(", ")}. accepted: ` +
|
|
283
|
-
`${[...byName.keys()].sort().join(", ") || "none"}` +
|
|
284
|
-
(sentAWrapper.length > 0
|
|
285
|
-
? `. ${sentAWrapper.sort().join(" and ")} ` +
|
|
286
|
-
`${sentAWrapper.length > 1 ? "are wrappers" : "is a wrapper"} this ` +
|
|
287
|
-
`surface builds for you from each field's json_path — send the fields ` +
|
|
288
|
-
`directly instead of nesting them`
|
|
289
|
-
: ""));
|
|
290
|
-
}
|
|
291
|
-
for (const [name, raw] of Object.entries(supplied)) {
|
|
292
|
-
const param = byName.get(name);
|
|
293
|
-
const value = coerce(raw, param);
|
|
294
|
-
if (group === "path_params") {
|
|
295
|
-
// Encode with nothing exempt: a `/` inside a path value would otherwise rewrite the
|
|
296
|
-
// route. Schema checking already stops this for integer ids; this covers strings.
|
|
297
|
-
path = path.replaceAll(`{${name}}`, encodeURIComponent(String(value)));
|
|
298
|
-
}
|
|
299
|
-
else if (group === "body") {
|
|
300
|
-
place(body, param.json_path || `/${name}`, value);
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
query[name] = value;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
// `required` is enforced for BODY as well as path. It was path-only on the Python side at
|
|
308
|
-
// first, so a missing required body field passed silently and the product answered with a
|
|
309
|
-
// 4xx that read like the caller's fault.
|
|
310
|
-
const missing = [];
|
|
311
|
-
for (const { group, declared } of GROUPS) {
|
|
312
|
-
if (group === "query")
|
|
313
|
-
continue;
|
|
314
|
-
const supplied = args[group] || {};
|
|
315
|
-
for (const param of capability[declared] ||
|
|
316
|
-
[]) {
|
|
317
|
-
if (param.required && !(param.name in supplied))
|
|
318
|
-
missing.push(param.name);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
if (missing.length > 0) {
|
|
322
|
-
throw new InvocationError(`missing required parameter(s): ${missing.sort().join(", ")}`);
|
|
323
|
-
}
|
|
324
|
-
const leftover = path.match(/\{[a-z_]+\}/gi);
|
|
325
|
-
if (leftover) {
|
|
326
|
-
throw new InvocationError(`path placeholder(s) not supplied: ${leftover.join(", ")}`);
|
|
327
|
-
}
|
|
328
|
-
return { path, query, body: Object.keys(body).length > 0 ? body : undefined };
|
|
329
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Where the index comes from, and where each product lives.
|
|
3
|
-
*
|
|
4
|
-
* A product may DECLARE its host in its own index file (`<product>.base_url`, authored in
|
|
5
|
-
* the harness's product.yaml and carried through by the export). That is the default, not
|
|
6
|
-
* the last word: config overrides it, and for a region-sharded product account discovery
|
|
7
|
-
* outranks it — see `resolveBaseUrl`. The same artifact therefore still ships to every
|
|
8
|
-
* environment, because anything environment- or account-specific is resolved here.
|
|
9
|
-
*/
|
|
10
|
-
import { BrowserStackConfig } from "../../lib/types.js";
|
|
11
|
-
import { HostSource } from "./discovery.js";
|
|
12
|
-
import { Transport } from "./egress.js";
|
|
13
|
-
/**
|
|
14
|
-
* The environment this DEPLOYMENT points at, e.g. "preprod".
|
|
15
|
-
*
|
|
16
|
-
* Process-level on purpose, and the distinction from region matters: an environment is a
|
|
17
|
-
* property of the deployment (this instance talks to preprod), whereas a REGION is a
|
|
18
|
-
* property of the account (this user's data lives in EU). That is why region discovery is
|
|
19
|
-
* per request and never cached under REMOTE_MCP, while the environment is read once here.
|
|
20
|
-
*/
|
|
21
|
-
export declare function selectedEnvironment(): string;
|
|
22
|
-
/** True when this product's host is account-specific and must be discovered per call. */
|
|
23
|
-
export declare function isRegionSharded(product: string, source?: HostSource): boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Resolve a product's host.
|
|
26
|
-
*
|
|
27
|
-
* Atlas resolves: an explicit per-session override, then the host for the session's
|
|
28
|
-
* environment (`harness.extra_environments[env][product]`), then the profile's own
|
|
29
|
-
* `base_url`. The same rungs, in the same order, with one addition:
|
|
30
|
-
*
|
|
31
|
-
* 1. CAPABILITY_REGISTRY_BASE_URL_<PRODUCT> explicit, environment-agnostic
|
|
32
|
-
* 2. CAPABILITY_REGISTRY_BASE_URL_<PRODUCT>_<ENV> this environment's host
|
|
33
|
-
* 3. CAPABILITY_REGISTRY_BASE_URLS {product:{env:url}} the same, as one map
|
|
34
|
-
* 4. account discovery — the index's `base_urls`, probed
|
|
35
|
-
* 5. the single host declared in the index, `base_url`
|
|
36
|
-
* 6. refuse, by name
|
|
37
|
-
*
|
|
38
|
-
* DISCOVERY OUTRANKS THE DECLARED HOST, which is where this departs from Atlas. A declared
|
|
39
|
-
* host is one fixed origin, so for a region-sharded product it would send every account
|
|
40
|
-
* outside the default region to the wrong host — a failure that only shows up on those
|
|
41
|
-
* accounts, and so passes any test run from inside the default one. Discovery answers with
|
|
42
|
-
* the region the account is actually on; `base_url` is the fallback for when the probe
|
|
43
|
-
* cannot answer at all.
|
|
44
|
-
*
|
|
45
|
-
* Refusing rather than guessing is deliberate: a guessed host fails as a DNS error or a 404
|
|
46
|
-
* that reads like the caller's problem, when it is our missing configuration.
|
|
47
|
-
*/
|
|
48
|
-
export declare function resolveBaseUrl(product: string, config: BrowserStackConfig, source?: HostSource, transport?: Transport): Promise<string>;
|
|
49
|
-
/**
|
|
50
|
-
* Locate the artifact(s).
|
|
51
|
-
*
|
|
52
|
-
* ONE FILE PER PRODUCT, so this returns a list. Explicit env wins; otherwise look for a
|
|
53
|
-
* `capability/` directory beside the compiled module and at the package root, then fall
|
|
54
|
-
* back to a single `capability-index.json` for the pre-release layout. The package-root
|
|
55
|
-
* candidates exist because `tsc` compiles TS and does not copy JSON into `dist`.
|
|
56
|
-
*
|
|
57
|
-
* Returns an empty list when nothing is found — the caller logs that and registers no
|
|
58
|
-
* tools, rather than throwing.
|
|
59
|
-
*/
|
|
60
|
-
export declare function indexPaths(): string[];
|
|
61
|
-
/** Off by default is wrong for a shipped feature, but a kill switch is not. */
|
|
62
|
-
export declare function isEnabled(): boolean;
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Where the index comes from, and where each product lives.
|
|
3
|
-
*
|
|
4
|
-
* A product may DECLARE its host in its own index file (`<product>.base_url`, authored in
|
|
5
|
-
* the harness's product.yaml and carried through by the export). That is the default, not
|
|
6
|
-
* the last word: config overrides it, and for a region-sharded product account discovery
|
|
7
|
-
* outranks it — see `resolveBaseUrl`. The same artifact therefore still ships to every
|
|
8
|
-
* environment, because anything environment- or account-specific is resolved here.
|
|
9
|
-
*/
|
|
10
|
-
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
11
|
-
import { fileURLToPath } from "node:url";
|
|
12
|
-
import { dirname, join, resolve } from "node:path";
|
|
13
|
-
import logger from "../../logger.js";
|
|
14
|
-
import { getTMBaseURL } from "../../lib/tm-base-url.js";
|
|
15
|
-
import { discoverBaseUrl } from "./discovery.js";
|
|
16
|
-
import { fetchTransport } from "./egress.js";
|
|
17
|
-
import { FLAT_SUFFIX, INDEX_FILE, InvocationError } from "./index-loader.js";
|
|
18
|
-
/**
|
|
19
|
-
* The environment this DEPLOYMENT points at, e.g. "preprod".
|
|
20
|
-
*
|
|
21
|
-
* Process-level on purpose, and the distinction from region matters: an environment is a
|
|
22
|
-
* property of the deployment (this instance talks to preprod), whereas a REGION is a
|
|
23
|
-
* property of the account (this user's data lives in EU). That is why region discovery is
|
|
24
|
-
* per request and never cached under REMOTE_MCP, while the environment is read once here.
|
|
25
|
-
*/
|
|
26
|
-
export function selectedEnvironment() {
|
|
27
|
-
return (process.env.CAPABILITY_REGISTRY_ENV || "").trim();
|
|
28
|
-
}
|
|
29
|
-
/** product -> env -> host, the analogue of Atlas's `harness.extra_environments`. */
|
|
30
|
-
function environmentMap() {
|
|
31
|
-
const raw = process.env.CAPABILITY_REGISTRY_BASE_URLS;
|
|
32
|
-
if (!raw)
|
|
33
|
-
return {};
|
|
34
|
-
try {
|
|
35
|
-
const parsed = JSON.parse(raw);
|
|
36
|
-
return parsed && typeof parsed === "object" ? parsed : {};
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
// A malformed map must not silently mean "no override" — that would send a preprod
|
|
40
|
-
// deployment at production.
|
|
41
|
-
throw new InvocationError("CAPABILITY_REGISTRY_BASE_URLS is not valid JSON; expected {product: {env: url}}");
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Built-in host discovery, for a product whose regional hosts are not in its index yet.
|
|
46
|
-
*
|
|
47
|
-
* The general mechanism lives in `discovery.ts` and is driven by the index's `base_urls`.
|
|
48
|
-
* This map is the bridge for products that predate that: tm's hosts are still hardcoded in
|
|
49
|
-
* `lib/tm-base-url.ts` and shared with the hand-written Test Management tools. Once tm's
|
|
50
|
-
* product.yaml declares `base_urls`, this entry can go and nothing else changes.
|
|
51
|
-
*/
|
|
52
|
-
const BUILTIN_DISCOVERY = {
|
|
53
|
-
tm: getTMBaseURL,
|
|
54
|
-
};
|
|
55
|
-
/** True when this product's host is account-specific and must be discovered per call. */
|
|
56
|
-
export function isRegionSharded(product, source) {
|
|
57
|
-
return (source?.base_urls?.length ?? 0) > 1 || product in BUILTIN_DISCOVERY;
|
|
58
|
-
}
|
|
59
|
-
function credentialsFrom(config) {
|
|
60
|
-
return {
|
|
61
|
-
username: config["browserstack-username"],
|
|
62
|
-
accessKey: config["browserstack-access-key"],
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Resolve a product's host.
|
|
67
|
-
*
|
|
68
|
-
* Atlas resolves: an explicit per-session override, then the host for the session's
|
|
69
|
-
* environment (`harness.extra_environments[env][product]`), then the profile's own
|
|
70
|
-
* `base_url`. The same rungs, in the same order, with one addition:
|
|
71
|
-
*
|
|
72
|
-
* 1. CAPABILITY_REGISTRY_BASE_URL_<PRODUCT> explicit, environment-agnostic
|
|
73
|
-
* 2. CAPABILITY_REGISTRY_BASE_URL_<PRODUCT>_<ENV> this environment's host
|
|
74
|
-
* 3. CAPABILITY_REGISTRY_BASE_URLS {product:{env:url}} the same, as one map
|
|
75
|
-
* 4. account discovery — the index's `base_urls`, probed
|
|
76
|
-
* 5. the single host declared in the index, `base_url`
|
|
77
|
-
* 6. refuse, by name
|
|
78
|
-
*
|
|
79
|
-
* DISCOVERY OUTRANKS THE DECLARED HOST, which is where this departs from Atlas. A declared
|
|
80
|
-
* host is one fixed origin, so for a region-sharded product it would send every account
|
|
81
|
-
* outside the default region to the wrong host — a failure that only shows up on those
|
|
82
|
-
* accounts, and so passes any test run from inside the default one. Discovery answers with
|
|
83
|
-
* the region the account is actually on; `base_url` is the fallback for when the probe
|
|
84
|
-
* cannot answer at all.
|
|
85
|
-
*
|
|
86
|
-
* Refusing rather than guessing is deliberate: a guessed host fails as a DNS error or a 404
|
|
87
|
-
* that reads like the caller's problem, when it is our missing configuration.
|
|
88
|
-
*/
|
|
89
|
-
export async function resolveBaseUrl(product, config, source, transport) {
|
|
90
|
-
const key = product.toUpperCase();
|
|
91
|
-
const environment = selectedEnvironment();
|
|
92
|
-
const trim = (url) => url.replace(/\/$/, "");
|
|
93
|
-
const explicit = process.env[`CAPABILITY_REGISTRY_BASE_URL_${key}`];
|
|
94
|
-
if (explicit)
|
|
95
|
-
return trim(explicit);
|
|
96
|
-
if (environment) {
|
|
97
|
-
const suffixed = process.env[`CAPABILITY_REGISTRY_BASE_URL_${key}_${environment.toUpperCase()}`];
|
|
98
|
-
if (suffixed)
|
|
99
|
-
return trim(suffixed);
|
|
100
|
-
const mapped = environmentMap()[product]?.[environment];
|
|
101
|
-
if (mapped)
|
|
102
|
-
return trim(String(mapped));
|
|
103
|
-
// An environment was named and nothing defines its host. Falling back to discovery or
|
|
104
|
-
// to the declared production host here would send a preprod deployment at production,
|
|
105
|
-
// silently.
|
|
106
|
-
throw new InvocationError(`environment '${environment}' has no host for product '${product}'. Set ` +
|
|
107
|
-
`CAPABILITY_REGISTRY_BASE_URL_${key}_${environment.toUpperCase()} or add it to ` +
|
|
108
|
-
`CAPABILITY_REGISTRY_BASE_URLS.`);
|
|
109
|
-
}
|
|
110
|
-
/** A declared host is a better answer than none — but only after discovery has tried. */
|
|
111
|
-
const fallback = (error) => {
|
|
112
|
-
if (!source?.base_url)
|
|
113
|
-
throw error;
|
|
114
|
-
logger.warn("host discovery failed for product %s (%s); falling back to the declared host %s", product, error instanceof Error ? error.message : String(error), source.base_url);
|
|
115
|
-
return trim(source.base_url);
|
|
116
|
-
};
|
|
117
|
-
if ((source?.base_urls?.length ?? 0) > 0) {
|
|
118
|
-
try {
|
|
119
|
-
return await discoverBaseUrl(product, source, credentialsFrom(config), transport || fetchTransport());
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
return fallback(error);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
const builtin = BUILTIN_DISCOVERY[product];
|
|
126
|
-
if (builtin) {
|
|
127
|
-
try {
|
|
128
|
-
return trim(await builtin(config));
|
|
129
|
-
}
|
|
130
|
-
catch (error) {
|
|
131
|
-
return fallback(error);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
if (source?.base_url)
|
|
135
|
-
return trim(source.base_url);
|
|
136
|
-
throw new InvocationError(`no host is configured for product '${product}': its index declares none and there ` +
|
|
137
|
-
`is no override. Set CAPABILITY_REGISTRY_BASE_URL_${key}.`);
|
|
138
|
-
}
|
|
139
|
-
/** The directory holding one subdirectory per product. */
|
|
140
|
-
const INDEX_ROOT = "capability";
|
|
141
|
-
function isDirectory(path) {
|
|
142
|
-
try {
|
|
143
|
-
return statSync(path).isDirectory();
|
|
144
|
-
}
|
|
145
|
-
catch {
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Every product index under one directory, sorted so load order is stable.
|
|
151
|
-
*
|
|
152
|
-
* `<product>.capability-index.json` is the stored layout — the export publishes that exact
|
|
153
|
-
* filename, so an artifact drops in unrenamed. `<product>/index.json` is also accepted, so
|
|
154
|
-
* a checkout using the earlier nested layout keeps working.
|
|
155
|
-
*/
|
|
156
|
-
function filesIn(directory) {
|
|
157
|
-
if (!isDirectory(directory))
|
|
158
|
-
return [];
|
|
159
|
-
const found = [];
|
|
160
|
-
for (const entry of readdirSync(directory).sort()) {
|
|
161
|
-
const path = join(directory, entry);
|
|
162
|
-
if (entry.endsWith(FLAT_SUFFIX)) {
|
|
163
|
-
found.push(path);
|
|
164
|
-
}
|
|
165
|
-
else if (isDirectory(path) && existsSync(join(path, INDEX_FILE))) {
|
|
166
|
-
found.push(join(path, INDEX_FILE));
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return found;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Locate the artifact(s).
|
|
173
|
-
*
|
|
174
|
-
* ONE FILE PER PRODUCT, so this returns a list. Explicit env wins; otherwise look for a
|
|
175
|
-
* `capability/` directory beside the compiled module and at the package root, then fall
|
|
176
|
-
* back to a single `capability-index.json` for the pre-release layout. The package-root
|
|
177
|
-
* candidates exist because `tsc` compiles TS and does not copy JSON into `dist`.
|
|
178
|
-
*
|
|
179
|
-
* Returns an empty list when nothing is found — the caller logs that and registers no
|
|
180
|
-
* tools, rather than throwing.
|
|
181
|
-
*/
|
|
182
|
-
export function indexPaths() {
|
|
183
|
-
const configuredFile = process.env.CAPABILITY_REGISTRY_INDEX;
|
|
184
|
-
if (configuredFile) {
|
|
185
|
-
return existsSync(configuredFile) ? [resolve(configuredFile)] : [];
|
|
186
|
-
}
|
|
187
|
-
const configuredDir = process.env.CAPABILITY_REGISTRY_INDEX_DIR;
|
|
188
|
-
if (configuredDir)
|
|
189
|
-
return filesIn(resolve(configuredDir));
|
|
190
|
-
const here = dirname(fileURLToPath(import.meta.url));
|
|
191
|
-
const roots = [
|
|
192
|
-
here,
|
|
193
|
-
join(here, "..", "..", ".."), // dist/ or src/ -> package root
|
|
194
|
-
join(here, "..", "..", "..", ".."),
|
|
195
|
-
];
|
|
196
|
-
for (const root of roots) {
|
|
197
|
-
// `capabilities` (plural) is the layout this shipped with before the move to
|
|
198
|
-
// `capability/<product>/index.json`; still read so an existing checkout keeps working.
|
|
199
|
-
for (const name of [INDEX_ROOT, "capabilities"]) {
|
|
200
|
-
const found = filesIn(join(root, name));
|
|
201
|
-
if (found.length > 0)
|
|
202
|
-
return found;
|
|
203
|
-
}
|
|
204
|
-
const loose = filesIn(root);
|
|
205
|
-
if (loose.length > 0)
|
|
206
|
-
return loose;
|
|
207
|
-
}
|
|
208
|
-
for (const root of roots) {
|
|
209
|
-
const legacy = join(root, "capability-index.json");
|
|
210
|
-
if (existsSync(legacy))
|
|
211
|
-
return [legacy];
|
|
212
|
-
}
|
|
213
|
-
return [];
|
|
214
|
-
}
|
|
215
|
-
/** Off by default is wrong for a shipped feature, but a kill switch is not. */
|
|
216
|
-
export function isEnabled() {
|
|
217
|
-
return ((process.env.CAPABILITY_REGISTRY_DISABLED || "").toLowerCase() !== "true");
|
|
218
|
-
}
|