@capybara-hq/testing 0.1.0-rc.22 → 0.1.0-rc.24
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/dist/sandbox-permission-conformance.d.ts +18 -1
- package/dist/sandbox-permission-conformance.js +246 -2
- package/fixtures/extensions/fake-connector/src/index.ts +41 -21
- package/fixtures/extensions/fake-openapi/src/index.ts +46 -34
- package/package.json +6 -6
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));
|
|
@@ -53,6 +53,13 @@ export interface SandboxPermissionFixture {
|
|
|
53
53
|
*/
|
|
54
54
|
readonly access: "direct" | "proxy";
|
|
55
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
* Set to "refused" when the provider refuses a restricted filesystem with the `environment`
|
|
58
|
+
* network by policy (a local device whose owner ceiling ties the environment network to Full
|
|
59
|
+
* access). The harness then proves that refusal (a scope denial, nothing run) where it would
|
|
60
|
+
* otherwise probe a restricted operation on the environment network. Default: "supported".
|
|
61
|
+
*/
|
|
62
|
+
readonly restrictedEnvironment?: "supported" | "refused";
|
|
56
63
|
/** The provider's own runtime report; the harness never infers support from a fixture. */
|
|
57
64
|
support(): Promise<SandboxPermissionSupport>;
|
|
58
65
|
/** A fresh operation (new operation ID) for the grant, through the provider's factory. */
|
|
@@ -65,6 +72,15 @@ export interface SandboxPermissionFixture {
|
|
|
65
72
|
mode(path: string): Promise<number | null>;
|
|
66
73
|
/** The subset of `pids` still running on the device. */
|
|
67
74
|
alive(pids: readonly number[]): Promise<number[]>;
|
|
75
|
+
/**
|
|
76
|
+
* Runs a Python 3 program (`python3 - ...args`, program on stdin) as the device user in a
|
|
77
|
+
* fresh process outside every operation and every restricted domain, standing in for another
|
|
78
|
+
* session's Full-access work, and returns its stdout. When present, the harness proves that
|
|
79
|
+
* such a process can neither ptrace nor read the memory or environment of the process that
|
|
80
|
+
* supervises a restricted command (its parent). Omit it only where no process outside an
|
|
81
|
+
* operation can run as the device user.
|
|
82
|
+
*/
|
|
83
|
+
outside?(program: string, args: readonly string[]): Promise<string>;
|
|
68
84
|
};
|
|
69
85
|
/** Removes fixture-owned resources, including after an assertion failure. */
|
|
70
86
|
dispose(): Promise<void>;
|
|
@@ -73,7 +89,8 @@ export interface SandboxPermissionFixture {
|
|
|
73
89
|
* Proves an actual provider's permission boundary on one shared device: positive controls, sibling,
|
|
74
90
|
* symlink, protected-path and network denials, Full controls without restricted filters, both
|
|
75
91
|
* overlap orders, component/root swaps and mutable syscall pointers during access, exact
|
|
76
|
-
* cancellation
|
|
92
|
+
* cancellation, a supervisor closed to same-uid outsiders (when the fixture can run one) and fresh
|
|
93
|
+
* narrowed scopes. Restricted network none/allowlist may bind and listen on
|
|
77
94
|
* loopback (127.0.0.1, ::1) only. Pathname UNIX services outside the roots stay unreachable under
|
|
78
95
|
* every network kind, environment included. A provider that reports restricted unsupported must
|
|
79
96
|
* refuse restricted operations (fail closed); nothing here substitutes a fixture flag for support.
|
|
@@ -164,11 +164,60 @@ while not os.path.exists(stop):
|
|
|
164
164
|
swaps += 1
|
|
165
165
|
print("swaps=%d" % swaps)
|
|
166
166
|
`;
|
|
167
|
+
/**
|
|
168
|
+
* Run by a same-uid process outside every operation: tries `PTRACE_ATTACH` and opens `mem` and
|
|
169
|
+
* `environ` of a control child of its own (proving the probe sees real access) and of the target.
|
|
170
|
+
*/
|
|
171
|
+
const OUTSIDE_PROBE = `
|
|
172
|
+
import ctypes, errno, json, os, signal, sys, time
|
|
173
|
+
libc = ctypes.CDLL(None, use_errno=True)
|
|
174
|
+
libc.ptrace.restype = ctypes.c_long
|
|
175
|
+
libc.ptrace.argtypes = (ctypes.c_long, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p)
|
|
176
|
+
PTRACE_ATTACH, PTRACE_DETACH, WALL = 16, 17, 0x40000000
|
|
177
|
+
def name(code):
|
|
178
|
+
return errno.errorcode.get(code, str(code))
|
|
179
|
+
def opened(pid, entry):
|
|
180
|
+
try:
|
|
181
|
+
fd = os.open("/proc/%d/%s" % (pid, entry), os.O_RDONLY)
|
|
182
|
+
except OSError as error:
|
|
183
|
+
return name(error.errno)
|
|
184
|
+
try:
|
|
185
|
+
if entry == "environ":
|
|
186
|
+
os.read(fd, 1)
|
|
187
|
+
finally:
|
|
188
|
+
os.close(fd)
|
|
189
|
+
return "ALLOWED"
|
|
190
|
+
def attach(pid):
|
|
191
|
+
if libc.ptrace(PTRACE_ATTACH, pid, None, None) < 0:
|
|
192
|
+
return name(ctypes.get_errno())
|
|
193
|
+
# Undo at once (the attach stopped the target) so even a failing check leaves it running.
|
|
194
|
+
os.waitpid(pid, WALL)
|
|
195
|
+
libc.ptrace(PTRACE_DETACH, pid, None, None)
|
|
196
|
+
return "ALLOWED"
|
|
197
|
+
def probe(pid):
|
|
198
|
+
return {"mem": opened(pid, "mem"), "environ": opened(pid, "environ"), "attach": attach(pid)}
|
|
199
|
+
child = os.fork()
|
|
200
|
+
if child == 0:
|
|
201
|
+
time.sleep(600)
|
|
202
|
+
os._exit(0)
|
|
203
|
+
control = probe(child)
|
|
204
|
+
os.kill(child, signal.SIGKILL)
|
|
205
|
+
os.waitpid(child, 0)
|
|
206
|
+
target = int(sys.argv[1])
|
|
207
|
+
def identity(pid):
|
|
208
|
+
with open("/proc/%d/status" % pid) as handle:
|
|
209
|
+
uid = [int(line.split()[1]) for line in handle if line.startswith("Uid:")][0]
|
|
210
|
+
with open("/proc/%d/cmdline" % pid, "rb") as handle:
|
|
211
|
+
return {"uid": uid, "cmdline": handle.read().replace(b"\\0", b" ").decode().strip()}
|
|
212
|
+
print(json.dumps({"uid": os.getuid(), "who": identity(target), "control": control,
|
|
213
|
+
"target": probe(target)}))
|
|
214
|
+
`;
|
|
167
215
|
/**
|
|
168
216
|
* Proves an actual provider's permission boundary on one shared device: positive controls, sibling,
|
|
169
217
|
* symlink, protected-path and network denials, Full controls without restricted filters, both
|
|
170
218
|
* overlap orders, component/root swaps and mutable syscall pointers during access, exact
|
|
171
|
-
* cancellation
|
|
219
|
+
* cancellation, a supervisor closed to same-uid outsiders (when the fixture can run one) and fresh
|
|
220
|
+
* narrowed scopes. Restricted network none/allowlist may bind and listen on
|
|
172
221
|
* loopback (127.0.0.1, ::1) only. Pathname UNIX services outside the roots stay unreachable under
|
|
173
222
|
* every network kind, environment included. A provider that reports restricted unsupported must
|
|
174
223
|
* refuse restricted operations (fail closed); nothing here substitutes a fixture flag for support.
|
|
@@ -285,6 +334,172 @@ export async function runSandboxPermissionConformance(fixture) {
|
|
|
285
334
|
limit: 10,
|
|
286
335
|
signal,
|
|
287
336
|
}), { entries: [{ name: "n.bin", isDir: false }], truncated: false });
|
|
337
|
+
// Mandatory write denies inside a granted root (the macOS set, shared through the SDK): git
|
|
338
|
+
// configuration and hooks (a later unsandboxed `git` there would run them), shell startup
|
|
339
|
+
// files and editor/agent configuration. Direct writes, creation, renames, hard and symbolic
|
|
340
|
+
// links, and the same paths in a repository the command creates itself all stay refused.
|
|
341
|
+
await fixture.seed([
|
|
342
|
+
{ path: at(root, "repo/.git/config"), kind: "file", data: new TextEncoder().encode("cfg") },
|
|
343
|
+
{
|
|
344
|
+
path: at(root, "repo/.git/hooks/pre-commit.sample"),
|
|
345
|
+
kind: "file",
|
|
346
|
+
data: new TextEncoder().encode("s"),
|
|
347
|
+
},
|
|
348
|
+
{ path: at(root, "repo/.git/HEAD"), kind: "file", data: new TextEncoder().encode("ref: x") },
|
|
349
|
+
]);
|
|
350
|
+
const evil = '[core]\n\tfsmonitor = "touch escaped; false"\n';
|
|
351
|
+
const denies = await exec(restricted(), [
|
|
352
|
+
`cd repo`,
|
|
353
|
+
`printf ${quote(evil)} > .git/config`,
|
|
354
|
+
`printf x >> .git/config`,
|
|
355
|
+
`mkdir -p .git/hooks; printf '#!/bin/sh' > .git/hooks/pre-commit`,
|
|
356
|
+
`chmod 755 .git/hooks/pre-commit.sample`,
|
|
357
|
+
`printf x > staged-config; mv staged-config .git/config`,
|
|
358
|
+
`printf x > staged-hook; ln staged-hook .git/hooks/post-checkout`,
|
|
359
|
+
`ln -s ../staged-hook .git/hooks/pre-push`,
|
|
360
|
+
`ln -s .git/config cfg-link; printf x > cfg-link`,
|
|
361
|
+
`mkdir moved; printf x > moved/config; mkdir -p sub; mv moved sub/.git`,
|
|
362
|
+
`mkdir -p ../ptr && printf 'gitdir: /tmp' > ../ptr/.git`,
|
|
363
|
+
`cd ..; git init -q nested 2>/dev/null; mkdir -p nested/.git/hooks; printf x > nested/.git/hooks/pre-commit; printf x > nested/.git/config`,
|
|
364
|
+
`printf x > .bashrc; printf x > .zshrc; printf x > .profile; printf x > .gitconfig; printf x > .gitmodules; printf x > .mcp.json`,
|
|
365
|
+
`mkdir -p .vscode && printf x > .vscode/settings.json; mkdir -p .idea && printf x > .idea/x`,
|
|
366
|
+
`mkdir -p .claude/commands .claude/agents; printf x > .claude/commands/c.md; printf x > .claude/agents/a.md`,
|
|
367
|
+
`mkdir -p deep/er; printf x > deep/er/.bash_profile`,
|
|
368
|
+
`printf ok > allowed.txt`,
|
|
369
|
+
`true`,
|
|
370
|
+
].join("; "));
|
|
371
|
+
assert.equal(denies.exitCode, 0, `the mandatory-deny probe must run: ${denies.stderr}`);
|
|
372
|
+
assert.equal(text(await fixture.inspect.readFile(at(root, "allowed.txt"))), "ok", "ordinary writes");
|
|
373
|
+
assert.equal(text(await fixture.inspect.readFile(at(root, "repo/.git/config"))), "cfg", ".git/config");
|
|
374
|
+
assert.equal((await fixture.inspect.mode(at(root, "repo/.git/hooks/pre-commit.sample"))) !== 0o755, true, "hook mode");
|
|
375
|
+
for (const path of [
|
|
376
|
+
"repo/.git/hooks/pre-commit",
|
|
377
|
+
"repo/.git/hooks/post-checkout",
|
|
378
|
+
"repo/.git/hooks/pre-push",
|
|
379
|
+
"repo/sub/.git/config",
|
|
380
|
+
"ptr/.git",
|
|
381
|
+
"nested/.git/hooks/pre-commit",
|
|
382
|
+
"nested/.git/config",
|
|
383
|
+
".bashrc",
|
|
384
|
+
".zshrc",
|
|
385
|
+
".profile",
|
|
386
|
+
".gitconfig",
|
|
387
|
+
".gitmodules",
|
|
388
|
+
".mcp.json",
|
|
389
|
+
".vscode/settings.json",
|
|
390
|
+
".idea/x",
|
|
391
|
+
".claude/commands/c.md",
|
|
392
|
+
".claude/agents/a.md",
|
|
393
|
+
"deep/er/.bash_profile",
|
|
394
|
+
])
|
|
395
|
+
assert.equal(await fixture.inspect.readFile(at(root, path)), null, `mandatory deny: ${path}`);
|
|
396
|
+
assert.equal(await fixture.inspect.mode(at(root, "repo/.git/hooks/pre-push")), null, "a symbolic link into the hooks is refused too");
|
|
397
|
+
await denied((await native(restricted())).writeFile(at(root, "repo/.git/config"), bytes, signal), "native write of .git/config");
|
|
398
|
+
await denied((await native(restricted())).writeFile(at(root, "repo/.git/hooks/post-merge"), bytes, signal), "native write of a git hook");
|
|
399
|
+
await denied((await native(restricted())).writeFile(at(root, ".vscode/tasks.json"), bytes, signal), "native write of editor configuration");
|
|
400
|
+
assert.equal(text(await fixture.inspect.readFile(at(root, "repo/.git/config"))), "cfg");
|
|
401
|
+
// Inside a .git directory only git's ordinary internals are writable: the gitdirs of
|
|
402
|
+
// submodules and worktrees keep their configuration, hooks and pointers too. A bare-repository
|
|
403
|
+
// lookalike (a HEAD file outside .git) and moving .git away are refused as well, and the
|
|
404
|
+
// matching folds case and Unicode compatibility forms.
|
|
405
|
+
await fixture.seed([
|
|
406
|
+
{
|
|
407
|
+
path: at(root, "repo/.git/modules/sub/config"),
|
|
408
|
+
kind: "file",
|
|
409
|
+
data: new TextEncoder().encode("cfg"),
|
|
410
|
+
},
|
|
411
|
+
{ path: at(root, "repo/.git/modules/sub/hooks"), kind: "directory" },
|
|
412
|
+
{ path: at(root, "repo/.git/modules/sub/objects"), kind: "directory" },
|
|
413
|
+
{
|
|
414
|
+
path: at(root, "repo/.git/worktrees/wt/commondir"),
|
|
415
|
+
kind: "file",
|
|
416
|
+
data: new TextEncoder().encode("../.."),
|
|
417
|
+
},
|
|
418
|
+
]);
|
|
419
|
+
const internals = await exec(restricted(), [
|
|
420
|
+
"cd repo",
|
|
421
|
+
"printf x >> .git/modules/sub/config",
|
|
422
|
+
"printf x > .git/modules/sub/hooks/pre-commit",
|
|
423
|
+
"printf x > .git/worktrees/wt/commondir",
|
|
424
|
+
"printf x > .git/worktrees/wt/config.worktree",
|
|
425
|
+
"printf x > .git/worktrees/wt/gitdir",
|
|
426
|
+
"printf x > .git/info-attributes-probe; mkdir -p .git/info; printf x > .git/info/attributes",
|
|
427
|
+
"printf x > .git/modules/sub/objects/ok-object",
|
|
428
|
+
"mkdir -p ../bare/objects ../bare/refs; printf 'ref: refs/heads/main' > ../bare/HEAD; printf x > ../bare/config",
|
|
429
|
+
"mv .git ../moved-git; printf x >> ../moved-git/config",
|
|
430
|
+
"cd ..",
|
|
431
|
+
"printf x > .envrc; printf x > .npmrc; mkdir -p deep; printf x > deep/.npmrc",
|
|
432
|
+
"printf x > .BASHRC; printf x > .envrc",
|
|
433
|
+
"true",
|
|
434
|
+
].join("; "));
|
|
435
|
+
assert.equal(internals.exitCode, 0, `the git-internals probe must run: ${internals.stderr}`);
|
|
436
|
+
assert.equal(text(await fixture.inspect.readFile(at(root, "repo/.git/modules/sub/config"))), "cfg", "submodule config");
|
|
437
|
+
assert.equal(text(await fixture.inspect.readFile(at(root, "repo/.git/worktrees/wt/commondir"))), "../..", "worktree commondir");
|
|
438
|
+
assert.equal(text(await fixture.inspect.readFile(at(root, "repo/.git/modules/sub/objects/ok-object"))), "x", "submodule objects stay writable");
|
|
439
|
+
assert.equal(text(await fixture.inspect.readFile(at(root, "repo/.git/config"))), "cfg", "moving .git away");
|
|
440
|
+
for (const path of [
|
|
441
|
+
"repo/.git/modules/sub/hooks/pre-commit",
|
|
442
|
+
"repo/.git/worktrees/wt/config.worktree",
|
|
443
|
+
"repo/.git/worktrees/wt/gitdir",
|
|
444
|
+
"repo/.git/info-attributes-probe",
|
|
445
|
+
"repo/.git/info/attributes",
|
|
446
|
+
"bare/HEAD",
|
|
447
|
+
"moved-git/config",
|
|
448
|
+
".envrc",
|
|
449
|
+
".npmrc",
|
|
450
|
+
"deep/.npmrc",
|
|
451
|
+
".BASHRC",
|
|
452
|
+
".envrc",
|
|
453
|
+
])
|
|
454
|
+
assert.equal(await fixture.inspect.readFile(at(root, path)), null, `mandatory deny: ${path}`);
|
|
455
|
+
await denied((await native(restricted())).writeFile(at(root, "repo/.git/modules/sub/config"), bytes, signal), "native write of a submodule's config");
|
|
456
|
+
await denied((await native(restricted())).writeFile(at(root, "bare2/HEAD"), bytes, signal), "native write of a bare-repository HEAD");
|
|
457
|
+
// No repository can be forged inside git's own allowlisted subtrees, and hook managers
|
|
458
|
+
// files stay out of reach.
|
|
459
|
+
const forged = await exec(restricted(), [
|
|
460
|
+
"cd repo/.git",
|
|
461
|
+
"mkdir -p objects/zz/.git/objects objects/zz/.git/refs",
|
|
462
|
+
"printf 'ref: refs/heads/main' > objects/zz/.git/HEAD",
|
|
463
|
+
"printf x > objects/zz/.git/config",
|
|
464
|
+
"mkdir -p objects/yy/objects objects/yy/refs; printf 'ref: refs/heads/main' > objects/yy/HEAD",
|
|
465
|
+
"mkdir -p logs/objects; printf ../.. > logs/commondir",
|
|
466
|
+
"mkdir -p refs/remotes/o/objects",
|
|
467
|
+
"cd ../..",
|
|
468
|
+
"mkdir -p .husky .lefthook .githooks .config",
|
|
469
|
+
"printf x > .husky/pre-commit; printf x > .pre-commit-config.yaml; printf x > lefthook.yml",
|
|
470
|
+
"printf x > .lefthook/x; printf x > .githooks/pre-commit; printf x > .config/lefthook.yml",
|
|
471
|
+
"true",
|
|
472
|
+
].join("; "));
|
|
473
|
+
assert.equal(forged.exitCode, 0, `the forged-repository probe must run: ${forged.stderr}`);
|
|
474
|
+
for (const path of [
|
|
475
|
+
"repo/.git/objects/zz/.git/HEAD",
|
|
476
|
+
"repo/.git/objects/zz/.git/config",
|
|
477
|
+
"repo/.git/objects/yy/HEAD",
|
|
478
|
+
"repo/.git/logs/objects",
|
|
479
|
+
"repo/.git/logs/commondir",
|
|
480
|
+
"repo/.git/refs/remotes/o/objects",
|
|
481
|
+
".husky/pre-commit",
|
|
482
|
+
".pre-commit-config.yaml",
|
|
483
|
+
"lefthook.yml",
|
|
484
|
+
".lefthook/x",
|
|
485
|
+
".githooks/pre-commit",
|
|
486
|
+
".config/lefthook.yml",
|
|
487
|
+
])
|
|
488
|
+
assert.equal(await fixture.inspect.mode(at(root, path)), null, `mandatory deny: ${path}`);
|
|
489
|
+
if (support.fullAccess) {
|
|
490
|
+
// ordinary git work in a restricted repository keeps working under these rules
|
|
491
|
+
await exec(full, `cd ${quote(root)} && git init -q work && git -C work -c user.name=t -c user.email=t@t commit -q --allow-empty -m init`);
|
|
492
|
+
const git = await exec(restricted(), "cd work && printf a > f && git add f && git -c user.name=t -c user.email=t@t commit -qm m && " +
|
|
493
|
+
"git checkout -qb topic && git status --short && git log --oneline | wc -l");
|
|
494
|
+
assert.equal(git.exitCode, 0, `ordinary restricted git work: ${git.stderr}`);
|
|
495
|
+
assert.equal(git.stdout.trim(), "2", "the restricted commit landed");
|
|
496
|
+
// stash, pack-refs and gc write git internals of their own (index.stash.<n>,
|
|
497
|
+
// packed-refs.new, MERGE_AUTOSTASH) that the allowlist keeps writable
|
|
498
|
+
const housekeeping = await exec(restricted(), 'cd work && g() { git -c user.name=t -c user.email=t@t -c gc.auto=0 "$@"; } && ' +
|
|
499
|
+
"printf b >> f && g stash -q && g stash pop -q && g commit -qam s && " +
|
|
500
|
+
"g pack-refs --all && g gc -q && git stash list | wc -l");
|
|
501
|
+
assert.equal(housekeeping.exitCode, 0, `restricted stash, pack-refs and gc: ${housekeeping.stderr}`);
|
|
502
|
+
}
|
|
288
503
|
// Negative controls: sibling, symlink escapes and protected paths stay out of reach.
|
|
289
504
|
const reads = await exec(restricted(), `cat ${quote(at(sibling, "secret"))}; cat escape; cat linked/secret; true`);
|
|
290
505
|
assert(!reads.stdout.includes(secret), "restricted reads must not reach the sibling");
|
|
@@ -353,10 +568,15 @@ export async function runSandboxPermissionConformance(fixture) {
|
|
|
353
568
|
await fixture.seed([
|
|
354
569
|
{ path: at(root, "srv-link.sock"), kind: "symlink", target: at(sibling, "srv.sock") },
|
|
355
570
|
]);
|
|
571
|
+
if (fixture.restrictedEnvironment === "refused") {
|
|
572
|
+
// the policy refusal is the result: a typed scope denial before anything runs
|
|
573
|
+
await denied(exec(restricted({ kind: "environment" }), `printf ran > ${quote(at(root, "env-ran"))}`), "a restricted environment-network operation must be refused by policy");
|
|
574
|
+
assert.equal(await fixture.inspect.readFile(at(root, "env-ran")), null);
|
|
575
|
+
}
|
|
356
576
|
for (const network of [
|
|
357
577
|
{ kind: "none" },
|
|
358
578
|
allowlisted,
|
|
359
|
-
{ kind: "environment" },
|
|
579
|
+
...(fixture.restrictedEnvironment === "refused" ? [] : [{ kind: "environment" }]),
|
|
360
580
|
]) {
|
|
361
581
|
const probe = await exec(restricted(network), `python3 -c ${quote(UNIX_CLIENT)} ${quote(at(sibling, "srv.sock"))} srv-link.sock`);
|
|
362
582
|
assert.equal(probe.stdout.trim(), "stream=denied seqpacket=denied dgram=denied raw=denied link=denied pair-dgram=denied pair-raw=denied", `restricted ${network.kind} must not reach a UNIX service outside the roots: ${probe.stderr}`);
|
|
@@ -472,6 +692,30 @@ export async function runSandboxPermissionConformance(fixture) {
|
|
|
472
692
|
assert.notEqual(chmods.stdout.trim(), "ok=0", "in-root chmods must succeed");
|
|
473
693
|
await siblingIntact("a flipped path must not chmod the sibling");
|
|
474
694
|
}
|
|
695
|
+
// The supervisor of a restricted command (its parent) is closed to a same-uid process outside
|
|
696
|
+
// the operation: no ptrace attach, no mem or environ, while the command itself runs normally.
|
|
697
|
+
if (fixture.inspect.outside) {
|
|
698
|
+
const held = exec(restricted(), `echo $PPID > supervisor-pid; printf r > ready-held; ` +
|
|
699
|
+
`until [ -e release-held ]; do sleep 0.01; done; printf ran > held.txt`);
|
|
700
|
+
await waitFor(at(root, "ready-held"), held);
|
|
701
|
+
const supervisor = Number(text(await fixture.inspect.readFile(at(root, "supervisor-pid"))));
|
|
702
|
+
let probed;
|
|
703
|
+
try {
|
|
704
|
+
probed = await fixture.inspect.outside(OUTSIDE_PROBE, [String(supervisor)]);
|
|
705
|
+
}
|
|
706
|
+
finally {
|
|
707
|
+
await exec(restricted(), "touch release-held");
|
|
708
|
+
}
|
|
709
|
+
assert.equal((await held).exitCode, 0, "the supervised command runs normally");
|
|
710
|
+
assert.equal(text(await fixture.inspect.readFile(at(root, "held.txt"))), "ran");
|
|
711
|
+
const { uid, who, control, target } = JSON.parse(probed);
|
|
712
|
+
// Not vacuous: the target is a live process of the outsider's own uid.
|
|
713
|
+
assert.equal(who?.uid, uid, `the supervisor must run as the outsider's uid: ${probed}`);
|
|
714
|
+
assert.notEqual(who?.cmdline ?? "", "", `the supervisor must still be running: ${probed}`);
|
|
715
|
+
assert.equal(control?.mem, "ALLOWED", `the probe must read a same-uid control: ${probed}`);
|
|
716
|
+
assert.equal(control?.environ, "ALLOWED", `the probe must read a same-uid control: ${probed}`);
|
|
717
|
+
assert.deepEqual(target, { mem: "EACCES", environ: "EACCES", attach: "EPERM" }, `a same-uid outsider must not ptrace or read the supervisor ${supervisor}: ${probed}`);
|
|
718
|
+
}
|
|
475
719
|
// Exact cancellation: detached descendants end; a sibling operation keeps running.
|
|
476
720
|
const keepAlive = exec(restricted(), `printf r > ready-keep; until [ -e release-keep ]; do sleep 0.01; done; printf done > kept`);
|
|
477
721
|
await waitFor(at(root, "ready-keep"), keepAlive);
|
|
@@ -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.24",
|
|
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,18 +47,18 @@
|
|
|
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.42"
|
|
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.31"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"vitest": "^5.0.5",
|
|
60
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
61
|
-
"@capybara-hq/plugin-tools": "^0.1.0-rc.
|
|
60
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.31",
|
|
61
|
+
"@capybara-hq/plugin-tools": "^0.1.0-rc.17"
|
|
62
62
|
},
|
|
63
63
|
"peerDependenciesMeta": {
|
|
64
64
|
"@capybara-hq/plugin-tools": {
|