@capybara-hq/testing 0.1.0-rc.22 → 0.1.0-rc.23
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/dist/fixtures.d.ts +2 -2
- package/dist/fixtures.js +2 -2
- package/dist/kernel-helpers.d.ts +2 -1
- package/dist/kernel-helpers.js +4 -1
- package/dist/replica-runner.js +2 -0
- package/fixtures/extensions/fake-connector/src/index.ts +41 -21
- package/fixtures/extensions/fake-openapi/src/index.ts +46 -34
- package/package.json +5 -5
package/dist/fixtures.d.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
* | name | provides / covers |
|
|
9
9
|
* |---|---|
|
|
10
|
-
* | `fake-connector` | `connector@1` kind `fake`: an MCP client for `startFakeMcpServer` (auth, one 401 retry, connectorData routes from `_meta["fake/route"]`, onToolsChanged, onElicit incl. `-32042`, resources, prompts, inspect); endpoint `{ url, headers?, notesText? }`; template `fake-demo`;
|
|
11
|
-
* | `fake-openapi` | `connector@1` kind `openapi` (the web wizard's OpenAPI flow): reads a small JSON document (`securitySchemes` as auth hints, `operations` as tools) from the endpoint's `specUrl`, calls operations over HTTP with the injected auth; endpoint `{ specUrl, baseUrl?, operations? }`;
|
|
10
|
+
* | `fake-connector` | `connector@1` kind `fake`: an MCP client for `startFakeMcpServer` (auth, one 401 retry, connectorData routes from `_meta["fake/route"]`, onToolsChanged, onElicit incl. `-32042`, resources, prompts, inspect); endpoint `{ url, headers?, notesText? }`; template `fake-demo`; requests go through `ctx.net.fetch` (test kernels set `net.allowInsecureLoopback`; `testKernelConfig` and `runConfig` do); deployment config `inspectAuth` (`bearer` / `api_key`), `kind` (default `fake`; `mcp` lets clients that know only the official kinds drive it) |
|
|
11
|
+
* | `fake-openapi` | `connector@1` kind `openapi` (the web wizard's OpenAPI flow): reads a small JSON document (`securitySchemes` as auth hints, `operations` as tools) from the endpoint's `specUrl`, calls operations over HTTP with the injected auth; endpoint `{ specUrl, baseUrl?, operations? }`; requests go through `ctx.net.fetch`, no deployment config |
|
|
12
12
|
* | `fake-object-store` | `object-store@1` on the `startTestS3()` container (deployment config as `TestS3` gives it; POST-policy presign) |
|
|
13
13
|
* | `fake-tools-ui` | tools `write` and `web-only` (`sources` web and channel_dm; returns its call context), view `tasks`, a migration, skill `fake-notes`, template `fake-notes` (for fake-connector); no storage |
|
|
14
14
|
* | `fake-storage-user` | tools `note` / `read_note` through `ctx.storage` (`permissions.storage`) |
|
package/dist/fixtures.js
CHANGED
|
@@ -10,8 +10,8 @@ import { fileURLToPath } from "node:url";
|
|
|
10
10
|
*
|
|
11
11
|
* | name | provides / covers |
|
|
12
12
|
* |---|---|
|
|
13
|
-
* | `fake-connector` | `connector@1` kind `fake`: an MCP client for `startFakeMcpServer` (auth, one 401 retry, connectorData routes from `_meta["fake/route"]`, onToolsChanged, onElicit incl. `-32042`, resources, prompts, inspect); endpoint `{ url, headers?, notesText? }`; template `fake-demo`;
|
|
14
|
-
* | `fake-openapi` | `connector@1` kind `openapi` (the web wizard's OpenAPI flow): reads a small JSON document (`securitySchemes` as auth hints, `operations` as tools) from the endpoint's `specUrl`, calls operations over HTTP with the injected auth; endpoint `{ specUrl, baseUrl?, operations? }`;
|
|
13
|
+
* | `fake-connector` | `connector@1` kind `fake`: an MCP client for `startFakeMcpServer` (auth, one 401 retry, connectorData routes from `_meta["fake/route"]`, onToolsChanged, onElicit incl. `-32042`, resources, prompts, inspect); endpoint `{ url, headers?, notesText? }`; template `fake-demo`; requests go through `ctx.net.fetch` (test kernels set `net.allowInsecureLoopback`; `testKernelConfig` and `runConfig` do); deployment config `inspectAuth` (`bearer` / `api_key`), `kind` (default `fake`; `mcp` lets clients that know only the official kinds drive it) |
|
|
14
|
+
* | `fake-openapi` | `connector@1` kind `openapi` (the web wizard's OpenAPI flow): reads a small JSON document (`securitySchemes` as auth hints, `operations` as tools) from the endpoint's `specUrl`, calls operations over HTTP with the injected auth; endpoint `{ specUrl, baseUrl?, operations? }`; requests go through `ctx.net.fetch`, no deployment config |
|
|
15
15
|
* | `fake-object-store` | `object-store@1` on the `startTestS3()` container (deployment config as `TestS3` gives it; POST-policy presign) |
|
|
16
16
|
* | `fake-tools-ui` | tools `write` and `web-only` (`sources` web and channel_dm; returns its call context), view `tasks`, a migration, skill `fake-notes`, template `fake-notes` (for fake-connector); no storage |
|
|
17
17
|
* | `fake-storage-user` | tools `note` / `read_note` through `ctx.storage` (`permissions.storage`) |
|
package/dist/kernel-helpers.d.ts
CHANGED
|
@@ -12,7 +12,8 @@ export declare const sleep: (ms: number) => Promise<void>;
|
|
|
12
12
|
export declare function waitFor<T>(fn: () => Promise<T | null | undefined | false>, timeoutMs?: number, label?: string, stepMs?: number): Promise<T>;
|
|
13
13
|
/**
|
|
14
14
|
* A kernel config for tests: the given PG / Redis, a fixed master key, an ephemeral HTTP port,
|
|
15
|
-
* auto-approved extension permissions,
|
|
15
|
+
* auto-approved extension permissions, `net.allowInsecureLoopback` (fake servers on loopback),
|
|
16
|
+
* short run-lock timings and the official marketplace off
|
|
16
17
|
* (it is on by default and its address is on the internet). `overrides` are top-level config keys
|
|
17
18
|
* and win; `runtime` is merged into the defaults, and `marketplaces` too, so other marketplace
|
|
18
19
|
* settings keep the official one off unless `marketplaces.official` turns it on.
|
package/dist/kernel-helpers.js
CHANGED
|
@@ -26,7 +26,8 @@ export async function waitFor(fn, timeoutMs = 10_000, label = "condition", stepM
|
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* A kernel config for tests: the given PG / Redis, a fixed master key, an ephemeral HTTP port,
|
|
29
|
-
* auto-approved extension permissions,
|
|
29
|
+
* auto-approved extension permissions, `net.allowInsecureLoopback` (fake servers on loopback),
|
|
30
|
+
* short run-lock timings and the official marketplace off
|
|
30
31
|
* (it is on by default and its address is on the internet). `overrides` are top-level config keys
|
|
31
32
|
* and win; `runtime` is merged into the defaults, and `marketplaces` too, so other marketplace
|
|
32
33
|
* settings keep the official one off unless `marketplaces.official` turns it on.
|
|
@@ -44,6 +45,8 @@ export function testKernelConfig(urls, overrides) {
|
|
|
44
45
|
...marketplaces,
|
|
45
46
|
official: { enabled: false, ...marketplaces?.official },
|
|
46
47
|
},
|
|
48
|
+
// Fake servers run on loopback: ctx.net may reach them (a test overrides `net` to assert refusals)
|
|
49
|
+
net: { allowInsecureLoopback: true },
|
|
47
50
|
...rest,
|
|
48
51
|
});
|
|
49
52
|
}
|
package/dist/replica-runner.js
CHANGED
|
@@ -29,6 +29,8 @@ async function startKernel(c) {
|
|
|
29
29
|
extensionPermissions: { autoApprove: true },
|
|
30
30
|
// The official marketplace is on by default and on the internet: tests turn it on explicitly.
|
|
31
31
|
marketplaces: { official: { enabled: false } },
|
|
32
|
+
// Fake servers run on loopback: ctx.net may reach them
|
|
33
|
+
net: { allowInsecureLoopback: true },
|
|
32
34
|
log: { level: "error" },
|
|
33
35
|
};
|
|
34
36
|
const config = KernelConfigSchema.parse(deepMerge(base, c.overrides));
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
type ConnectorSession,
|
|
8
8
|
defineExtension,
|
|
9
9
|
type ElicitationRequest,
|
|
10
|
+
type ExtensionNet,
|
|
10
11
|
type Logger,
|
|
11
12
|
type PromptInfo,
|
|
12
13
|
type ToolContent,
|
|
@@ -33,8 +34,10 @@ import { z } from "zod";
|
|
|
33
34
|
* `kind` names another): a deliberately small MCP client
|
|
34
35
|
* (Streamable HTTP) meant for `startFakeMcpServer` from `@capybara-hq/testing`. It covers the
|
|
35
36
|
* kernel side of the connector contract, not MCP edge cases:
|
|
36
|
-
* - `endpointSchema`: `{ url, headers? }`, https or (
|
|
37
|
-
*
|
|
37
|
+
* - `endpointSchema`: `{ url, headers? }`, https or loopback http (the kernel's `ctx.net` decides
|
|
38
|
+
* what is reachable: test kernels set `net.allowInsecureLoopback`); credential headers are
|
|
39
|
+
* rejected;
|
|
40
|
+
* - every request goes through `ctx.net.fetch` with the session's `orgId`;
|
|
38
41
|
* - `auth()` before every request, one `onUnauthorized()` + retry on 401, redirects not followed;
|
|
39
42
|
* a 5xx answer's body is logged as the warning `fake-connector request failed` (the kernel
|
|
40
43
|
* redacts credentials in extension logs);
|
|
@@ -65,8 +68,6 @@ const CLIENT_INFO = { name: "capybara-fake-connector", version: "0.1.0" };
|
|
|
65
68
|
const REQUEST_TIMEOUT_MS = 3_600_000;
|
|
66
69
|
|
|
67
70
|
const DeploymentConfig = z.object({
|
|
68
|
-
/** Accept http://127.0.0.1 / localhost / [::1] endpoints (on by default: this is a test fake). */
|
|
69
|
-
allowInsecureLoopback: z.boolean().default(true),
|
|
70
71
|
/** The auth hint `inspect` reports behind a 401. */
|
|
71
72
|
inspectAuth: z.enum(["bearer", "api_key"]).default("bearer"),
|
|
72
73
|
/**
|
|
@@ -83,13 +84,14 @@ const DeploymentConfig = z.object({
|
|
|
83
84
|
/** The `_meta` key of a remote tool that names the remote tool serving it (its route). */
|
|
84
85
|
export const FAKE_ROUTE_META = "fake/route";
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
/**
|
|
88
|
+
* http or https; whether the target is reachable is `ctx.net`'s call at request time (http only for
|
|
89
|
+
* an org-allowed `http://host:port` origin, or loopback under `net.allowInsecureLoopback`).
|
|
90
|
+
*/
|
|
91
|
+
const urlAllowed = (raw: string): boolean => {
|
|
90
92
|
try {
|
|
91
93
|
const u = new URL(raw);
|
|
92
|
-
return u.protocol === "https:" ||
|
|
94
|
+
return u.protocol === "https:" || u.protocol === "http:";
|
|
93
95
|
} catch {
|
|
94
96
|
return true; // z.url() reports the format error
|
|
95
97
|
}
|
|
@@ -99,11 +101,11 @@ const isCredentialHeader = (name: string): boolean =>
|
|
|
99
101
|
["authorization", "proxy-authorization", "cookie"].includes(name.toLowerCase());
|
|
100
102
|
|
|
101
103
|
/** The endpoint: the server URL and optional non-secret fixed headers. */
|
|
102
|
-
export function fakeEndpointSchema(
|
|
104
|
+
export function fakeEndpointSchema() {
|
|
103
105
|
return z
|
|
104
106
|
.object({
|
|
105
|
-
url: z.url().refine(
|
|
106
|
-
message: "URL must use
|
|
107
|
+
url: z.url().refine(urlAllowed, {
|
|
108
|
+
message: "URL must use http or https",
|
|
107
109
|
}),
|
|
108
110
|
/** Free-form text the connector ignores (large-endpoint tests). */
|
|
109
111
|
notesText: z.string().optional(),
|
|
@@ -174,6 +176,8 @@ async function guarded<T>(work: () => Promise<T>): Promise<T> {
|
|
|
174
176
|
|
|
175
177
|
/** A fetch that injects `auth()` before every request and retries once after `onUnauthorized()`. */
|
|
176
178
|
function authedFetch(
|
|
179
|
+
net: ExtensionNet,
|
|
180
|
+
orgId: string,
|
|
177
181
|
endpoint: Endpoint,
|
|
178
182
|
auth: ConnectorOpenArgs["auth"] | undefined,
|
|
179
183
|
onUnauthorized: ConnectorOpenArgs["onUnauthorized"] | undefined,
|
|
@@ -190,7 +194,11 @@ function authedFetch(
|
|
|
190
194
|
for (const [k, v] of Object.entries(endpoint.headers)) if (!headers.has(k)) headers.set(k, v);
|
|
191
195
|
for (const [k, v] of Object.entries(inj.headers)) headers.set(k, v);
|
|
192
196
|
const s = init?.signal ? AbortSignal.any([init.signal, signal]) : signal;
|
|
193
|
-
return fetch(
|
|
197
|
+
return net.fetch(
|
|
198
|
+
url.toString(),
|
|
199
|
+
{ ...init, headers, signal: s, redirect: "manual" },
|
|
200
|
+
{ orgId },
|
|
201
|
+
);
|
|
194
202
|
};
|
|
195
203
|
const noRedirect = async (r: Response) => {
|
|
196
204
|
if (r.status >= 300 && r.status < 400) {
|
|
@@ -275,11 +283,20 @@ async function connect(
|
|
|
275
283
|
}
|
|
276
284
|
|
|
277
285
|
async function openSession(
|
|
286
|
+
net: ExtensionNet,
|
|
278
287
|
endpoint: Endpoint,
|
|
279
288
|
args: ConnectorOpenArgs,
|
|
280
289
|
log?: Logger,
|
|
281
290
|
): Promise<ConnectorSession> {
|
|
282
|
-
const fetchImpl = authedFetch(
|
|
291
|
+
const fetchImpl = authedFetch(
|
|
292
|
+
net,
|
|
293
|
+
args.orgId,
|
|
294
|
+
endpoint,
|
|
295
|
+
args.auth,
|
|
296
|
+
args.onUnauthorized,
|
|
297
|
+
args.signal,
|
|
298
|
+
log,
|
|
299
|
+
);
|
|
283
300
|
const { client, transport } = await connect(endpoint, fetchImpl, args);
|
|
284
301
|
const opts = (signal: AbortSignal = args.signal) => ({ signal, timeout: REQUEST_TIMEOUT_MS });
|
|
285
302
|
const session: ConnectorSession = {
|
|
@@ -412,12 +429,14 @@ const authHint = (kind: InspectAuth): AuthHint =>
|
|
|
412
429
|
|
|
413
430
|
/** Install preview without credentials: 401 -> the configured auth hint; otherwise the tools as operations. */
|
|
414
431
|
async function inspect(
|
|
432
|
+
net: ExtensionNet,
|
|
433
|
+
orgId: string,
|
|
415
434
|
endpoint: Endpoint,
|
|
416
435
|
signal: AbortSignal,
|
|
417
436
|
hint: InspectAuth,
|
|
418
437
|
): Promise<ConnectorInspection> {
|
|
419
438
|
let unauthorized = false;
|
|
420
|
-
const probe = authedFetch(endpoint, undefined, undefined, signal);
|
|
439
|
+
const probe = authedFetch(net, orgId, endpoint, undefined, undefined, signal);
|
|
421
440
|
const fetchImpl = async (input: string | URL, init?: RequestInit) => {
|
|
422
441
|
const r = await probe(input, init);
|
|
423
442
|
if (r.status === 401) unauthorized = true;
|
|
@@ -447,17 +466,18 @@ async function inspect(
|
|
|
447
466
|
|
|
448
467
|
/** Creates the fake connector (exported for unit tests that call it without a kernel). */
|
|
449
468
|
export function createFakeConnector(
|
|
450
|
-
|
|
469
|
+
net: ExtensionNet,
|
|
451
470
|
inspectAuth: InspectAuth = "bearer",
|
|
452
471
|
kind = "fake",
|
|
453
472
|
log?: Logger,
|
|
454
473
|
): Connector {
|
|
455
|
-
const schema = fakeEndpointSchema(
|
|
474
|
+
const schema = fakeEndpointSchema();
|
|
456
475
|
return {
|
|
457
476
|
kind,
|
|
458
477
|
endpointSchema: schema,
|
|
459
|
-
open: (args) => openSession(schema.parse(args.endpoint), args, log),
|
|
460
|
-
inspect: ({ endpoint, signal }) =>
|
|
478
|
+
open: (args) => openSession(net, schema.parse(args.endpoint), args, log),
|
|
479
|
+
inspect: ({ endpoint, signal, orgId }) =>
|
|
480
|
+
inspect(net, orgId, schema.parse(endpoint), signal, inspectAuth),
|
|
461
481
|
};
|
|
462
482
|
}
|
|
463
483
|
|
|
@@ -468,10 +488,10 @@ export default defineExtension({
|
|
|
468
488
|
provides: [CONNECTOR_EXTENSION_POINT],
|
|
469
489
|
config: { deployment: DeploymentConfig },
|
|
470
490
|
setup(ctx) {
|
|
471
|
-
const {
|
|
491
|
+
const { inspectAuth, kind } = DeploymentConfig.parse(ctx.config ?? {});
|
|
472
492
|
ctx.provide(
|
|
473
493
|
CONNECTOR_EXTENSION_POINT,
|
|
474
|
-
createFakeConnector(
|
|
494
|
+
createFakeConnector(ctx.net, inspectAuth, kind, ctx.log),
|
|
475
495
|
);
|
|
476
496
|
},
|
|
477
497
|
});
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
type ConnectorOpenArgs,
|
|
7
7
|
type ConnectorSession,
|
|
8
8
|
defineExtension,
|
|
9
|
+
type ExtensionNet,
|
|
9
10
|
ToolError,
|
|
10
11
|
type ToolResult,
|
|
11
12
|
type ToolSpec,
|
|
@@ -28,7 +29,9 @@ import { z } from "zod";
|
|
|
28
29
|
* ```
|
|
29
30
|
*
|
|
30
31
|
* - `endpointSchema`: `{ specUrl, baseUrl?, operations? }` (the wizard's OpenAPI endpoint without
|
|
31
|
-
* `specText`),
|
|
32
|
+
* `specText`), http or https (the kernel's `ctx.net` decides at request time what is
|
|
33
|
+
* reachable: http only for an org-allowed `http://host:port` origin, or loopback under
|
|
34
|
+
* `net.allowInsecureLoopback`, which test kernels set);
|
|
32
35
|
* - `inspect`: the document's security schemes as auth hints (`{ scheme, ...value }`) and its
|
|
33
36
|
* operations (`id` = name);
|
|
34
37
|
* - a session lists one tool per operation (all, or the endpoint's `operations`), named by the
|
|
@@ -39,27 +42,20 @@ import { z } from "zod";
|
|
|
39
42
|
* kind `unavailable`.
|
|
40
43
|
*/
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
allowInsecureLoopback: z.boolean().default(true),
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const isLoopbackHttp = (u: URL): boolean =>
|
|
48
|
-
u.protocol === "http:" && ["127.0.0.1", "localhost", "[::1]"].includes(u.hostname);
|
|
49
|
-
|
|
50
|
-
const urlOk = (raw: string, loopback: boolean): boolean => {
|
|
45
|
+
/** http or https; whether the target is reachable is `ctx.net`'s call at request time. */
|
|
46
|
+
const urlOk = (raw: string): boolean => {
|
|
51
47
|
try {
|
|
52
48
|
const u = new URL(raw);
|
|
53
|
-
return u.protocol === "https:" ||
|
|
49
|
+
return u.protocol === "https:" || u.protocol === "http:";
|
|
54
50
|
} catch {
|
|
55
51
|
return true; // z.url() reports the format error
|
|
56
52
|
}
|
|
57
53
|
};
|
|
58
54
|
|
|
59
55
|
/** The endpoint: the document URL, an optional API base URL and the selected operations. */
|
|
60
|
-
export function fakeOpenApiEndpointSchema(
|
|
61
|
-
const url = z.url().refine(
|
|
62
|
-
message: "URL must use
|
|
56
|
+
export function fakeOpenApiEndpointSchema() {
|
|
57
|
+
const url = z.url().refine(urlOk, {
|
|
58
|
+
message: "URL must use http or https",
|
|
63
59
|
});
|
|
64
60
|
return z
|
|
65
61
|
.object({
|
|
@@ -104,10 +100,15 @@ const UNREACHABLE_TEXT = "Could not reach the connector's server; retry later.";
|
|
|
104
100
|
const AUTH_FAILED_TEXT = "Authentication failed for this connector; ask the user to reconnect it.";
|
|
105
101
|
|
|
106
102
|
/** Reads the operations document (no credentials: like an OpenAPI document, it is public). */
|
|
107
|
-
async function loadDoc(
|
|
103
|
+
async function loadDoc(
|
|
104
|
+
net: ExtensionNet,
|
|
105
|
+
orgId: string,
|
|
106
|
+
endpoint: Endpoint,
|
|
107
|
+
signal: AbortSignal,
|
|
108
|
+
): Promise<Doc> {
|
|
108
109
|
let res: Response;
|
|
109
110
|
try {
|
|
110
|
-
res = await fetch(endpoint.specUrl, { signal, redirect: "manual" });
|
|
111
|
+
res = await net.fetch(endpoint.specUrl, { signal, redirect: "manual" }, { orgId });
|
|
111
112
|
} catch {
|
|
112
113
|
throw new ToolError(UNREACHABLE_TEXT, { kind: "unavailable" });
|
|
113
114
|
}
|
|
@@ -143,8 +144,12 @@ const INPUT_SCHEMA = {
|
|
|
143
144
|
const isObj = (v: unknown): v is Record<string, unknown> =>
|
|
144
145
|
typeof v === "object" && v !== null && !Array.isArray(v);
|
|
145
146
|
|
|
146
|
-
async function openSession(
|
|
147
|
-
|
|
147
|
+
async function openSession(
|
|
148
|
+
net: ExtensionNet,
|
|
149
|
+
endpoint: Endpoint,
|
|
150
|
+
args: ConnectorOpenArgs,
|
|
151
|
+
): Promise<ConnectorSession> {
|
|
152
|
+
const doc = await loadDoc(net, args.orgId, endpoint, args.signal);
|
|
148
153
|
const base = endpoint.baseUrl ?? doc.baseUrl ?? new URL(endpoint.specUrl).origin;
|
|
149
154
|
const ops = selected(doc, endpoint);
|
|
150
155
|
return {
|
|
@@ -178,13 +183,17 @@ async function openSession(endpoint: Endpoint, args: ConnectorOpenArgs): Promise
|
|
|
178
183
|
const headers = new Headers(inj.headers);
|
|
179
184
|
if (body !== undefined) headers.set("content-type", "application/json");
|
|
180
185
|
try {
|
|
181
|
-
return await fetch(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
186
|
+
return await net.fetch(
|
|
187
|
+
url.toString(),
|
|
188
|
+
{
|
|
189
|
+
method,
|
|
190
|
+
headers,
|
|
191
|
+
...(body !== undefined && { body }),
|
|
192
|
+
signal: AbortSignal.any([signal, args.signal]),
|
|
193
|
+
redirect: "manual",
|
|
194
|
+
},
|
|
195
|
+
{ orgId: args.orgId },
|
|
196
|
+
);
|
|
188
197
|
} catch (e) {
|
|
189
198
|
if (signal.aborted || args.signal.aborted) throw e;
|
|
190
199
|
throw new ToolError(UNREACHABLE_TEXT, { kind: "unavailable" });
|
|
@@ -221,8 +230,13 @@ async function openSession(endpoint: Endpoint, args: ConnectorOpenArgs): Promise
|
|
|
221
230
|
};
|
|
222
231
|
}
|
|
223
232
|
|
|
224
|
-
async function inspect(
|
|
225
|
-
|
|
233
|
+
async function inspect(
|
|
234
|
+
net: ExtensionNet,
|
|
235
|
+
orgId: string,
|
|
236
|
+
endpoint: Endpoint,
|
|
237
|
+
signal: AbortSignal,
|
|
238
|
+
): Promise<ConnectorInspection> {
|
|
239
|
+
const doc = await loadDoc(net, orgId, endpoint, signal);
|
|
226
240
|
return {
|
|
227
241
|
authHints: hintsOf(doc),
|
|
228
242
|
operations: doc.operations.map((o) => ({
|
|
@@ -235,13 +249,13 @@ async function inspect(endpoint: Endpoint, signal: AbortSignal): Promise<Connect
|
|
|
235
249
|
}
|
|
236
250
|
|
|
237
251
|
/** Creates the fake OpenAPI connector (exported for unit tests that call it without a kernel). */
|
|
238
|
-
export function createFakeOpenApiConnector(
|
|
239
|
-
const schema = fakeOpenApiEndpointSchema(
|
|
252
|
+
export function createFakeOpenApiConnector(net: ExtensionNet): Connector {
|
|
253
|
+
const schema = fakeOpenApiEndpointSchema();
|
|
240
254
|
return {
|
|
241
255
|
kind: "openapi",
|
|
242
256
|
endpointSchema: schema,
|
|
243
|
-
open: (args) => openSession(schema.parse(args.endpoint), args),
|
|
244
|
-
inspect: ({ endpoint, signal }) => inspect(schema.parse(endpoint), signal),
|
|
257
|
+
open: (args) => openSession(net, schema.parse(args.endpoint), args),
|
|
258
|
+
inspect: ({ endpoint, signal, orgId }) => inspect(net, orgId, schema.parse(endpoint), signal),
|
|
245
259
|
};
|
|
246
260
|
}
|
|
247
261
|
|
|
@@ -250,9 +264,7 @@ export default defineExtension({
|
|
|
250
264
|
version: "0.1.0",
|
|
251
265
|
sdk: "^0.1.0-rc.0",
|
|
252
266
|
provides: [CONNECTOR_EXTENSION_POINT],
|
|
253
|
-
config: { deployment: DeploymentConfig },
|
|
254
267
|
setup(ctx) {
|
|
255
|
-
|
|
256
|
-
ctx.provide(CONNECTOR_EXTENSION_POINT, createFakeOpenApiConnector(allowInsecureLoopback));
|
|
268
|
+
ctx.provide(CONNECTOR_EXTENSION_POINT, createFakeOpenApiConnector(ctx.net));
|
|
257
269
|
},
|
|
258
270
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/testing",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.23",
|
|
4
4
|
"description": "Test helpers for Capybara: test containers, dual-replica harness and fake third-party servers",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -47,17 +47,17 @@
|
|
|
47
47
|
"tsx": "^4.23.15",
|
|
48
48
|
"ws": "^8.22.0",
|
|
49
49
|
"zod": "^4.6.7",
|
|
50
|
-
"@capybara-hq/kernel": "^0.1.0-rc.
|
|
50
|
+
"@capybara-hq/kernel": "^0.1.0-rc.38"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/pg": "^8.23.1",
|
|
54
54
|
"@types/ws": "^8.18.2",
|
|
55
|
-
"@capybara-hq/plugin-
|
|
56
|
-
"@capybara-hq/plugin-
|
|
55
|
+
"@capybara-hq/plugin-client": "^0.1.0-rc.5",
|
|
56
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.29"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"vitest": "^5.0.5",
|
|
60
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
60
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.29",
|
|
61
61
|
"@capybara-hq/plugin-tools": "^0.1.0-rc.16"
|
|
62
62
|
},
|
|
63
63
|
"peerDependenciesMeta": {
|