@capybara-hq/testing 0.1.0-rc.2 → 0.1.0-rc.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/dist/containers.d.ts +7 -2
- package/dist/containers.js +7 -3
- package/dist/dual-replica.d.ts +11 -2
- package/dist/dual-replica.js +48 -0
- package/dist/fake-channel.d.ts +31 -2
- package/dist/fake-channel.js +29 -2
- package/dist/fake-e2b.d.ts +34 -0
- package/dist/fake-e2b.js +95 -1
- package/dist/fake-git-server.d.ts +32 -4
- package/dist/fake-git-server.js +87 -19
- package/dist/fake-oauth-server.d.ts +16 -2
- package/dist/fake-oauth-server.js +21 -1
- package/dist/fake-telegram.d.ts +165 -0
- package/dist/fake-telegram.js +569 -0
- package/dist/fixtures.d.ts +21 -4
- package/dist/fixtures.js +30 -4
- package/dist/index.d.ts +8 -5
- package/dist/index.js +6 -3
- package/dist/kernel-helpers.d.ts +48 -16
- package/dist/kernel-helpers.js +73 -13
- package/dist/model-conformance.d.ts +11 -10
- package/dist/model-conformance.js +38 -14
- package/dist/replica-runner.js +16 -8
- package/dist/sandbox-native-conformance.d.ts +31 -0
- package/dist/sandbox-native-conformance.js +153 -0
- package/dist/sandbox-permission-conformance.d.ts +60 -0
- package/dist/sandbox-permission-conformance.js +486 -0
- package/fixtures/extensions/fake-client/.capybara-plugin/plugin.json +11 -0
- package/fixtures/extensions/fake-client/client/styles/fake.css +11 -0
- package/fixtures/extensions/fake-client/package.json +12 -0
- package/fixtures/extensions/fake-client/src/client.tsx +51 -0
- package/fixtures/extensions/fake-client/src/index.ts +43 -0
- package/fixtures/extensions/fake-client/themes/fake.json +11 -0
- package/fixtures/extensions/fake-client-broken/.capybara-plugin/plugin.json +7 -0
- package/fixtures/extensions/fake-client-broken/package.json +12 -0
- package/fixtures/extensions/fake-client-broken/src/client.tsx +22 -0
- package/fixtures/extensions/fake-client-broken/src/index.ts +27 -0
- package/fixtures/extensions/fake-config-form/.capybara-plugin/plugin.json +11 -0
- package/fixtures/extensions/fake-config-form/package.json +12 -0
- package/fixtures/extensions/fake-config-form/src/index.ts +205 -0
- package/fixtures/extensions/fake-context/.capybara-plugin/plugin.json +7 -0
- package/fixtures/extensions/fake-context/package.json +12 -0
- package/fixtures/extensions/fake-context/src/index.ts +81 -0
- package/fixtures/extensions/fake-dep-provider/src/index.ts +1 -1
- package/fixtures/extensions/fake-dep-requirer/src/index.ts +1 -1
- package/fixtures/extensions/fake-embed/src/index.ts +26 -26
- package/fixtures/extensions/fake-im/.capybara-plugin/plugin.json +7 -1
- package/fixtures/extensions/fake-im/guides/fake-im-app.md +32 -0
- package/fixtures/extensions/fake-im/guides/fake-im-app.zh.md +32 -0
- package/fixtures/extensions/fake-im/src/channel.ts +3 -1
- package/fixtures/extensions/fake-im/src/checks.ts +94 -0
- package/fixtures/extensions/fake-im/src/index.ts +36 -1
- package/fixtures/extensions/fake-lifecycle/.capybara-plugin/plugin.json +7 -0
- package/fixtures/extensions/fake-lifecycle/migrations/0001_init.sql +16 -0
- package/fixtures/extensions/fake-lifecycle/package.json +12 -0
- package/fixtures/extensions/fake-lifecycle/src/index.ts +72 -0
- package/fixtures/extensions/fake-storage-user/src/index.ts +1 -1
- package/fixtures/extensions/fake-tools-ui/skills/fake-notes/SKILL.md +1 -1
- package/fixtures/extensions/fake-tools-ui/src/index.ts +62 -3
- package/fixtures/extensions/fake-web/.capybara-plugin/plugin.json +7 -0
- package/fixtures/extensions/fake-web/package.json +12 -0
- package/fixtures/extensions/fake-web/src/index.ts +22 -0
- package/fixtures/extensions/fake-web/src/web.ts +183 -0
- package/fixtures/extensions/fake-web-2/.capybara-plugin/plugin.json +7 -0
- package/fixtures/extensions/fake-web-2/package.json +12 -0
- package/fixtures/extensions/fake-web-2/src/index.ts +16 -0
- package/fixtures/extensions/fake-web-2/src/web.ts +183 -0
- package/fixtures/plugins/fake-theme/.capybara-plugin/plugin.json +7 -0
- package/fixtures/plugins/fake-theme/fonts/FakeSans.woff2 +1 -0
- package/fixtures/plugins/fake-theme/logo.svg +1 -0
- package/fixtures/plugins/fake-theme/package.json +8 -0
- package/fixtures/plugins/fake-theme/themes/neon-grid.json +13 -0
- package/fixtures/plugins/fake-theme/themes/paper.json +12 -0
- package/package.json +6 -5
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { posix } from "node:path";
|
|
4
|
+
import { isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, } from "@capybara-hq/plugin-sdk";
|
|
5
|
+
const text = (data) => (data === null ? null : Buffer.from(data).toString());
|
|
6
|
+
const quote = (value) => `'${value.replaceAll("'", `'"'"'`)}'`;
|
|
7
|
+
/** A Python program in which one thread rewrites a syscall's pointer argument mid-call. */
|
|
8
|
+
const FLIP_PROGRAM = String.raw `
|
|
9
|
+
import ctypes, socket, struct, sys, threading
|
|
10
|
+
libc = ctypes.CDLL(None, use_errno=True)
|
|
11
|
+
mode, rounds = sys.argv[1], int(sys.argv[2])
|
|
12
|
+
stop = threading.Event()
|
|
13
|
+
def flipper(buffer, good, bad):
|
|
14
|
+
while not stop.is_set():
|
|
15
|
+
ctypes.memmove(buffer, bad, len(bad))
|
|
16
|
+
ctypes.memmove(buffer, good, len(good))
|
|
17
|
+
ok = 0
|
|
18
|
+
if mode == "connect":
|
|
19
|
+
def sockaddr(host, port):
|
|
20
|
+
return struct.pack("HH4s8x", socket.AF_INET, socket.htons(port), socket.inet_aton(host))
|
|
21
|
+
good = sockaddr(sys.argv[3], int(sys.argv[4]))
|
|
22
|
+
bad = sockaddr(sys.argv[5], int(sys.argv[6]))
|
|
23
|
+
buffer = ctypes.create_string_buffer(good, len(good))
|
|
24
|
+
thread = threading.Thread(target=flipper, args=(buffer, good, bad))
|
|
25
|
+
thread.start()
|
|
26
|
+
for _ in range(rounds):
|
|
27
|
+
fd = libc.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
|
|
28
|
+
if fd >= 0 and libc.connect(fd, buffer, len(good)) == 0:
|
|
29
|
+
ok += 1
|
|
30
|
+
if fd >= 0:
|
|
31
|
+
libc.close(fd)
|
|
32
|
+
else:
|
|
33
|
+
good, bad = sys.argv[3].encode() + b"\0", sys.argv[4].encode() + b"\0"
|
|
34
|
+
size = max(len(good), len(bad))
|
|
35
|
+
good, bad = good.ljust(size, b"\0"), bad.ljust(size, b"\0")
|
|
36
|
+
buffer = ctypes.create_string_buffer(good, size)
|
|
37
|
+
thread = threading.Thread(target=flipper, args=(buffer, good, bad))
|
|
38
|
+
thread.start()
|
|
39
|
+
for index in range(rounds):
|
|
40
|
+
if libc.chmod(buffer, 0o640 if index % 2 else 0o600) == 0:
|
|
41
|
+
ok += 1
|
|
42
|
+
stop.set()
|
|
43
|
+
thread.join()
|
|
44
|
+
print("ok=%d" % ok)
|
|
45
|
+
`;
|
|
46
|
+
/** Binds and listens on each address; restricted none/allowlist must allow loopback only. */
|
|
47
|
+
const BIND_PROGRAM = `
|
|
48
|
+
import socket
|
|
49
|
+
out = []
|
|
50
|
+
for family, host in ((socket.AF_INET, "127.0.0.1"), (socket.AF_INET6, "::1"),
|
|
51
|
+
(socket.AF_INET, "0.0.0.0"), (socket.AF_INET6, "::")):
|
|
52
|
+
s = socket.socket(family, socket.SOCK_STREAM)
|
|
53
|
+
try:
|
|
54
|
+
s.bind((host, 0))
|
|
55
|
+
s.listen(1)
|
|
56
|
+
out.append(host + "=ok")
|
|
57
|
+
except OSError:
|
|
58
|
+
out.append(host + "=denied")
|
|
59
|
+
s.close()
|
|
60
|
+
# Dissolving an association (connect AF_UNSPEC) must not turn listen() into a bind to any address.
|
|
61
|
+
import ctypes
|
|
62
|
+
libc = ctypes.CDLL(None, use_errno=True)
|
|
63
|
+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
64
|
+
libc.connect(s.fileno(), ctypes.create_string_buffer(16), 16)
|
|
65
|
+
try:
|
|
66
|
+
s.listen(1)
|
|
67
|
+
out.append("unspec=" + s.getsockname()[0])
|
|
68
|
+
except OSError:
|
|
69
|
+
out.append("unspec=denied")
|
|
70
|
+
print(" ".join(out))
|
|
71
|
+
`;
|
|
72
|
+
/** A Full-access UNIX service (stream, seqpacket, datagram) counting every client it sees. */
|
|
73
|
+
const UNIX_SERVER = `
|
|
74
|
+
import os, socket, sys, threading
|
|
75
|
+
path, counter = sys.argv[1], sys.argv[2]
|
|
76
|
+
lock = threading.Lock()
|
|
77
|
+
count = [0]
|
|
78
|
+
def seen():
|
|
79
|
+
with lock:
|
|
80
|
+
count[0] += 1
|
|
81
|
+
with open(counter + ".tmp", "w") as handle:
|
|
82
|
+
handle.write(str(count[0]))
|
|
83
|
+
os.replace(counter + ".tmp", counter)
|
|
84
|
+
def serve(kind, suffix):
|
|
85
|
+
s = socket.socket(socket.AF_UNIX, kind)
|
|
86
|
+
s.bind(path + suffix)
|
|
87
|
+
if kind == socket.SOCK_DGRAM:
|
|
88
|
+
while True:
|
|
89
|
+
s.recv(100)
|
|
90
|
+
seen()
|
|
91
|
+
s.listen(16)
|
|
92
|
+
while True:
|
|
93
|
+
s.accept()[0].close()
|
|
94
|
+
seen()
|
|
95
|
+
threads = [threading.Thread(target=serve, args=a, daemon=True)
|
|
96
|
+
for a in ((socket.SOCK_STREAM, ""), (socket.SOCK_SEQPACKET, ".seq"), (socket.SOCK_DGRAM, ".dgram"))]
|
|
97
|
+
for thread in threads:
|
|
98
|
+
thread.start()
|
|
99
|
+
with open(counter + ".tmp", "w") as handle:
|
|
100
|
+
handle.write("0")
|
|
101
|
+
while not all(os.path.exists(path + suffix) for suffix in ("", ".seq", ".dgram")):
|
|
102
|
+
pass
|
|
103
|
+
os.replace(counter + ".tmp", counter)
|
|
104
|
+
threading.Event().wait()
|
|
105
|
+
`;
|
|
106
|
+
/** Tries every way to reach the outside UNIX service; prints ok/denied per attempt. */
|
|
107
|
+
const UNIX_CLIENT = `
|
|
108
|
+
import socket, sys
|
|
109
|
+
path, link = sys.argv[1], sys.argv[2]
|
|
110
|
+
def attempt(name, action):
|
|
111
|
+
try:
|
|
112
|
+
action()
|
|
113
|
+
return name + "=ok"
|
|
114
|
+
except OSError:
|
|
115
|
+
return name + "=denied"
|
|
116
|
+
def connect(kind, target):
|
|
117
|
+
socket.socket(socket.AF_UNIX, kind).connect(target)
|
|
118
|
+
def send(kind):
|
|
119
|
+
socket.socket(socket.AF_UNIX, kind).sendto(b"x", path + ".dgram")
|
|
120
|
+
def pair(kind):
|
|
121
|
+
# An explicit address on a socketpair datagram socket is honoured by the kernel.
|
|
122
|
+
first, _ = socket.socketpair(socket.AF_UNIX, kind)
|
|
123
|
+
first.sendto(b"x", path + ".dgram")
|
|
124
|
+
print(" ".join([
|
|
125
|
+
attempt("stream", lambda: connect(socket.SOCK_STREAM, path)),
|
|
126
|
+
attempt("seqpacket", lambda: connect(socket.SOCK_SEQPACKET, path + ".seq")),
|
|
127
|
+
attempt("dgram", lambda: send(socket.SOCK_DGRAM)),
|
|
128
|
+
attempt("raw", lambda: send(socket.SOCK_RAW)),
|
|
129
|
+
attempt("link", lambda: connect(socket.SOCK_STREAM, link)),
|
|
130
|
+
attempt("pair-dgram", lambda: pair(socket.SOCK_DGRAM)),
|
|
131
|
+
attempt("pair-raw", lambda: pair(socket.SOCK_RAW)),
|
|
132
|
+
]))
|
|
133
|
+
`;
|
|
134
|
+
/** A UNIX stream server and client inside the root talk to each other. */
|
|
135
|
+
const UNIX_ROUNDTRIP = `
|
|
136
|
+
import socket, sys
|
|
137
|
+
server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
138
|
+
server.bind(sys.argv[1])
|
|
139
|
+
server.listen(1)
|
|
140
|
+
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
141
|
+
client.connect(sys.argv[1])
|
|
142
|
+
peer = server.accept()[0]
|
|
143
|
+
client.sendall(b"ping")
|
|
144
|
+
print("roundtrip=ok" if peer.recv(4) == b"ping" else "roundtrip=bad")
|
|
145
|
+
`;
|
|
146
|
+
/** Atomically exchanges a directory with a symlink to an outside path until a stop file exists. */
|
|
147
|
+
const SWAP_PROGRAM = `
|
|
148
|
+
import ctypes, os, sys
|
|
149
|
+
libc = ctypes.CDLL(None, use_errno=True)
|
|
150
|
+
base, outside, stop = sys.argv[1], sys.argv[2], sys.argv[3]
|
|
151
|
+
os.makedirs(base + "/dir")
|
|
152
|
+
os.symlink(outside, base + "/link")
|
|
153
|
+
open(base + "/swapping", "w").close()
|
|
154
|
+
swaps = 0
|
|
155
|
+
while not os.path.exists(stop):
|
|
156
|
+
if libc.renameat2(-100, (base + "/dir").encode(), -100, (base + "/link").encode(), 2) == 0:
|
|
157
|
+
swaps += 1
|
|
158
|
+
print("swaps=%d" % swaps)
|
|
159
|
+
`;
|
|
160
|
+
/**
|
|
161
|
+
* Proves an actual provider's permission boundary on one shared device: positive controls, sibling,
|
|
162
|
+
* symlink, protected-path and network denials, Full controls without restricted filters, both
|
|
163
|
+
* overlap orders, component/root swaps and mutable syscall pointers during access, exact
|
|
164
|
+
* cancellation and fresh narrowed scopes. Restricted network none/allowlist may bind and listen on
|
|
165
|
+
* loopback (127.0.0.1, ::1) only. Pathname UNIX services outside the roots stay unreachable under
|
|
166
|
+
* every network kind, environment included; metadata reads outside the roots are not covered. A provider that reports restricted unsupported must
|
|
167
|
+
* refuse restricted operations (fail closed); nothing here substitutes a fixture flag for support.
|
|
168
|
+
*/
|
|
169
|
+
export async function runSandboxPermissionConformance(fixture) {
|
|
170
|
+
const { root, sibling } = fixture;
|
|
171
|
+
const at = (base, name) => posix.join(base, name);
|
|
172
|
+
const secret = `sibling-secret-${randomUUID()}`;
|
|
173
|
+
const scoped = (writeRoots) => ({
|
|
174
|
+
kind: "scoped",
|
|
175
|
+
readRoots: [],
|
|
176
|
+
writeRoots,
|
|
177
|
+
});
|
|
178
|
+
const restricted = (network = { kind: "none" }, writeRoots = [root]) => ({
|
|
179
|
+
profile: "approve-for-me",
|
|
180
|
+
filesystem: scoped(writeRoots),
|
|
181
|
+
network,
|
|
182
|
+
});
|
|
183
|
+
const full = {
|
|
184
|
+
profile: "full-access",
|
|
185
|
+
filesystem: { kind: "device" },
|
|
186
|
+
network: { kind: "environment" },
|
|
187
|
+
};
|
|
188
|
+
const { granted, ungranted } = fixture.endpoints;
|
|
189
|
+
const allowlisted = { kind: "allowlist", hosts: [granted.host] };
|
|
190
|
+
const exec = async (grant, command, signal = new AbortController().signal, timeoutMs = 120_000) => (await fixture.operation(grant)).exec({
|
|
191
|
+
command,
|
|
192
|
+
cwd: root,
|
|
193
|
+
timeoutMs,
|
|
194
|
+
maxOutputBytes: 1 << 20,
|
|
195
|
+
signal,
|
|
196
|
+
});
|
|
197
|
+
const native = async (grant) => {
|
|
198
|
+
const operation = await fixture.operation(grant);
|
|
199
|
+
assert(operation.list && operation.scan, "Permission conformance requires list and scan");
|
|
200
|
+
return operation;
|
|
201
|
+
};
|
|
202
|
+
const signal = new AbortController().signal;
|
|
203
|
+
const denied = async (promise, what) => {
|
|
204
|
+
await assert.rejects(promise, (error) => isSandboxScopeDeniedError(error), what);
|
|
205
|
+
};
|
|
206
|
+
const waitFor = async (path) => {
|
|
207
|
+
while ((await fixture.inspect.readFile(path)) === null) {
|
|
208
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
const receipts = async () => Promise.all([granted, ...ungranted].map((endpoint) => endpoint.receipts()));
|
|
212
|
+
const connect = (endpoint) => `python3 -c ${quote(`import socket; socket.create_connection((${JSON.stringify(endpoint.host)}, ${endpoint.port}), 10).close()`)}`;
|
|
213
|
+
try {
|
|
214
|
+
const support = await fixture.support();
|
|
215
|
+
if (support.restricted === null) {
|
|
216
|
+
// Fail closed: no restricted operation may run, and nothing falls back to Full access.
|
|
217
|
+
await assert.rejects((async () => (await fixture.operation(restricted())).exec({
|
|
218
|
+
command: "true",
|
|
219
|
+
cwd: root,
|
|
220
|
+
timeoutMs: 10_000,
|
|
221
|
+
maxOutputBytes: 1024,
|
|
222
|
+
signal,
|
|
223
|
+
}))(), (error) => isSandboxPermissionUnsupportedError(error), "an unsupported runtime must refuse restricted operations");
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
assert.deepEqual(support.restricted, { filesystem: true, network: true, native: true, concurrentScopes: true }, "restricted support requires all four claims together");
|
|
227
|
+
await fixture.seed([
|
|
228
|
+
{ path: at(sibling, "secret"), kind: "file", data: new TextEncoder().encode(secret) },
|
|
229
|
+
{ path: at(root, "inroot.txt"), kind: "file", data: new TextEncoder().encode("inroot") },
|
|
230
|
+
{ path: at(root, "escape"), kind: "symlink", target: at(sibling, "secret") },
|
|
231
|
+
{ path: at(root, "linked"), kind: "symlink", target: sibling },
|
|
232
|
+
]);
|
|
233
|
+
const siblingMode = await fixture.inspect.mode(at(sibling, "secret"));
|
|
234
|
+
const siblingIntact = async (label) => {
|
|
235
|
+
assert.equal(text(await fixture.inspect.readFile(at(sibling, "secret"))), secret, label);
|
|
236
|
+
assert.equal(await fixture.inspect.mode(at(sibling, "secret")), siblingMode, label);
|
|
237
|
+
};
|
|
238
|
+
// Positive controls: ordinary shell, Python, Node and native work inside the root.
|
|
239
|
+
const shell = await exec(restricted(), "cat inroot.txt && printf shell > shell.txt && mkdir -p d/e && printf x > d/e/f && " +
|
|
240
|
+
"chmod 755 d/e/f && touch -d 2001-01-01 d/e/f && ln -s shell.txt alias && cat alias");
|
|
241
|
+
assert.equal(shell.exitCode, 0, `restricted shell work must succeed: ${shell.stderr}`);
|
|
242
|
+
assert.equal(shell.stdout, "inrootshell");
|
|
243
|
+
assert.equal(await fixture.inspect.mode(at(root, "d/e/f")), 0o755, "chmod inside the root");
|
|
244
|
+
const python = await exec(restricted(), `python3 -c ${quote("import pathlib; p = pathlib.Path('py.txt'); p.write_text('py'); print(p.read_text())")}`);
|
|
245
|
+
assert.equal(python.exitCode, 0, `restricted Python work must succeed: ${python.stderr}`);
|
|
246
|
+
assert.equal(python.stdout.trim(), "py");
|
|
247
|
+
const node = await exec(restricted(), `node -e ${quote("const fs = require('fs'); fs.writeFileSync('node.txt', 'node'); console.log(fs.readFileSync('node.txt', 'utf8'))")}`);
|
|
248
|
+
assert.equal(node.exitCode, 0, `restricted Node work must succeed: ${node.stderr}`);
|
|
249
|
+
assert.equal(node.stdout.trim(), "node");
|
|
250
|
+
const bytes = new Uint8Array([0, 1, 2, 255]);
|
|
251
|
+
await (await native(restricted())).writeFile(at(root, "native/n.bin"), bytes, signal);
|
|
252
|
+
assert.deepEqual(await (await native(restricted())).readFile(at(root, "native/n.bin"), {
|
|
253
|
+
maxBytes: 10,
|
|
254
|
+
signal,
|
|
255
|
+
}), { data: bytes, truncated: false });
|
|
256
|
+
assert.deepEqual(await (await native(restricted())).stat(at(root, "native/n.bin"), signal), {
|
|
257
|
+
size: 4,
|
|
258
|
+
isDir: false,
|
|
259
|
+
});
|
|
260
|
+
assert.deepEqual(await (await native(restricted())).list(at(root, "native"), {
|
|
261
|
+
limit: 10,
|
|
262
|
+
signal,
|
|
263
|
+
}), { entries: [{ name: "n.bin", isDir: false }], truncated: false });
|
|
264
|
+
// Negative controls: sibling, symlink escapes and protected paths stay out of reach.
|
|
265
|
+
const reads = await exec(restricted(), `cat ${quote(at(sibling, "secret"))}; cat escape; cat linked/secret; true`);
|
|
266
|
+
assert(!reads.stdout.includes(secret), "restricted reads must not reach the sibling");
|
|
267
|
+
await exec(restricted(), `printf pwn > ${quote(at(sibling, "w1"))}; printf pwn > linked/w2; printf pwn > escape; ` +
|
|
268
|
+
`chmod 777 ${quote(at(sibling, "secret"))}; chmod 777 escape; ` +
|
|
269
|
+
`touch -d 2001-01-01 ${quote(at(sibling, "secret"))}; true`);
|
|
270
|
+
assert.equal(await fixture.inspect.readFile(at(sibling, "w1")), null, "sibling write");
|
|
271
|
+
assert.equal(await fixture.inspect.readFile(at(sibling, "w2")), null, "symlinked dir write");
|
|
272
|
+
await siblingIntact("restricted writes and chmod must not change the sibling");
|
|
273
|
+
for (const path of fixture.protectedPaths) {
|
|
274
|
+
const before = text(await fixture.inspect.readFile(path));
|
|
275
|
+
await exec(restricted(), `printf pwn >> ${quote(path)}; true`);
|
|
276
|
+
assert.equal(text(await fixture.inspect.readFile(path)), before, `protected ${path}`);
|
|
277
|
+
}
|
|
278
|
+
await denied((await native(restricted())).readFile(at(sibling, "secret"), { maxBytes: 100, signal }), "native sibling read");
|
|
279
|
+
await denied((await native(restricted())).readFile(at(root, "escape"), { maxBytes: 100, signal }), "native symlink escape read");
|
|
280
|
+
await denied((await native(restricted())).writeFile(at(sibling, "n1"), bytes, signal), "native sibling write");
|
|
281
|
+
await denied((await native(restricted())).writeFile(at(root, "linked/n2"), bytes, signal), "native write through a directory symlink");
|
|
282
|
+
await denied((await native(restricted())).stat(at(sibling, "secret"), signal), "stat");
|
|
283
|
+
await denied((await native(restricted())).list(sibling, { limit: 5, signal }), "list");
|
|
284
|
+
await siblingIntact("native denials must leave the sibling unchanged");
|
|
285
|
+
// Network: only the granted endpoint, and only while allowlisted.
|
|
286
|
+
const base = await receipts();
|
|
287
|
+
for (const command of [
|
|
288
|
+
connect(granted),
|
|
289
|
+
`curl -fsS -m 10 -o /dev/null http://${granted.host}:${granted.port}/`,
|
|
290
|
+
`node -e ${quote(`require("net").connect(${granted.port}, ${JSON.stringify(granted.host)}).on("connect", function () { this.end() })`)}`,
|
|
291
|
+
]) {
|
|
292
|
+
const result = await exec(restricted(allowlisted), command);
|
|
293
|
+
assert.equal(result.exitCode, 0, `granted endpoint must work: ${command}: ${result.stderr}`);
|
|
294
|
+
}
|
|
295
|
+
for (const endpoint of ungranted) {
|
|
296
|
+
const result = await exec(restricted(allowlisted), connect(endpoint));
|
|
297
|
+
assert.notEqual(result.exitCode, 0, `ungranted ${endpoint.host}:${endpoint.port}`);
|
|
298
|
+
}
|
|
299
|
+
const none = await exec(restricted(), connect(granted));
|
|
300
|
+
assert.notEqual(none.exitCode, 0, "network none must refuse even the granted endpoint");
|
|
301
|
+
const after = await receipts();
|
|
302
|
+
assert.equal(after[0], (base[0] ?? 0) + 3, "granted endpoint receipts");
|
|
303
|
+
assert.deepEqual(after.slice(1), base.slice(1), "ungranted endpoints must see no connection");
|
|
304
|
+
// Restricted network none/allowlist may listen on loopback only.
|
|
305
|
+
for (const network of [{ kind: "none" }, allowlisted]) {
|
|
306
|
+
const binds = await exec(restricted(network), `python3 -c ${quote(BIND_PROGRAM)}`);
|
|
307
|
+
assert.equal(binds.stdout.trim(), "127.0.0.1=ok ::1=ok 0.0.0.0=denied ::=denied unspec=denied", `restricted ${network.kind} binds loopback only: ${binds.stderr}`);
|
|
308
|
+
}
|
|
309
|
+
// Pathname UNIX sockets: a service outside the roots is unreachable under every network kind
|
|
310
|
+
// (including environment, which lifts only the network filter); one inside the root works.
|
|
311
|
+
if (support.fullAccess) {
|
|
312
|
+
const server = new AbortController();
|
|
313
|
+
const outside = exec(full, `python3 -c ${quote(UNIX_SERVER)} ${quote(at(sibling, "srv.sock"))} ${quote(at(sibling, "srv.count"))}`, server.signal);
|
|
314
|
+
await waitFor(at(sibling, "srv.count"));
|
|
315
|
+
await fixture.seed([
|
|
316
|
+
{ path: at(root, "srv-link.sock"), kind: "symlink", target: at(sibling, "srv.sock") },
|
|
317
|
+
]);
|
|
318
|
+
for (const network of [
|
|
319
|
+
{ kind: "none" },
|
|
320
|
+
allowlisted,
|
|
321
|
+
{ kind: "environment" },
|
|
322
|
+
]) {
|
|
323
|
+
const probe = await exec(restricted(network), `python3 -c ${quote(UNIX_CLIENT)} ${quote(at(sibling, "srv.sock"))} srv-link.sock`);
|
|
324
|
+
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}`);
|
|
325
|
+
const inside = await exec(restricted(network), `python3 -c ${quote(UNIX_ROUNDTRIP)} ${quote(at(root, `own-${network.kind}.sock`))}`);
|
|
326
|
+
assert.equal(inside.stdout.trim(), "roundtrip=ok", `in-root UNIX socket: ${inside.stderr}`);
|
|
327
|
+
}
|
|
328
|
+
assert.equal(text(await fixture.inspect.readFile(at(sibling, "srv.count"))), "0", "the outside UNIX service must see no client");
|
|
329
|
+
// The same client under Full access reaches the service seven times: the probe is real.
|
|
330
|
+
const control = await exec(full, `python3 -c ${quote(UNIX_CLIENT)} ${quote(at(sibling, "srv.sock"))} srv-link.sock`);
|
|
331
|
+
assert.equal(control.stdout.trim(), "stream=ok seqpacket=ok dgram=ok raw=ok link=ok pair-dgram=ok pair-raw=ok", `Full UNIX control: ${control.stderr}`);
|
|
332
|
+
while (text(await fixture.inspect.readFile(at(sibling, "srv.count"))) !== "7") {
|
|
333
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
334
|
+
}
|
|
335
|
+
server.abort();
|
|
336
|
+
await outside;
|
|
337
|
+
}
|
|
338
|
+
// Full access controls on the same device: no restricted filters apply.
|
|
339
|
+
if (support.fullAccess) {
|
|
340
|
+
const control = await exec(full, `cat ${quote(at(sibling, "secret"))} && printf full > ${quote(at(sibling, "full"))} && ${connect(ungranted[0] ?? granted)}`);
|
|
341
|
+
assert.equal(control.exitCode, 0, `Full access control must succeed: ${control.stderr}`);
|
|
342
|
+
assert(control.stdout.includes(secret), "Full access reads the sibling");
|
|
343
|
+
assert.equal(text(await fixture.inspect.readFile(at(sibling, "full"))), "full");
|
|
344
|
+
assert.equal((await receipts())[1], (after[1] ?? 0) + 1, "Full reaches an ungranted endpoint");
|
|
345
|
+
}
|
|
346
|
+
// Both overlap orders: a live Full operation never widens a restricted one, and vice versa.
|
|
347
|
+
if (support.fullAccess) {
|
|
348
|
+
const first = exec(restricted(), `printf r > ready-a; until [ -e barrier-a ]; do sleep 0.01; done; ` +
|
|
349
|
+
`printf pwn > ${quote(at(sibling, "overlap-a"))}; cat ${quote(at(sibling, "secret"))}; true`);
|
|
350
|
+
await waitFor(at(root, "ready-a"));
|
|
351
|
+
await exec(full, `printf full > ${quote(at(sibling, "full-a"))} && touch barrier-a`);
|
|
352
|
+
assert(!(await first).stdout.includes(secret), "restricted after a live Full operation");
|
|
353
|
+
assert.equal(await fixture.inspect.readFile(at(sibling, "overlap-a")), null);
|
|
354
|
+
const fullFirst = exec(full, `printf r > ready-b; until [ -e barrier-b ]; do sleep 0.01; done; ` +
|
|
355
|
+
`printf full > ${quote(at(sibling, "full-b"))}`);
|
|
356
|
+
await waitFor(at(root, "ready-b"));
|
|
357
|
+
const second = await exec(restricted(), `printf pwn > ${quote(at(sibling, "overlap-b"))}; cat ${quote(at(sibling, "secret"))}; touch barrier-b`);
|
|
358
|
+
assert(!second.stdout.includes(secret), "restricted while a Full operation is live");
|
|
359
|
+
assert.equal((await fullFirst).exitCode, 0);
|
|
360
|
+
assert.equal(await fixture.inspect.readFile(at(sibling, "overlap-b")), null);
|
|
361
|
+
assert.equal(text(await fixture.inspect.readFile(at(sibling, "full-b"))), "full");
|
|
362
|
+
}
|
|
363
|
+
// Component swaps during native and shell access never escape.
|
|
364
|
+
if (support.fullAccess) {
|
|
365
|
+
const race = at(root, "race");
|
|
366
|
+
const swapper = exec(full, `python3 -c ${quote(SWAP_PROGRAM)} ${quote(race)} ${quote(sibling)} ${quote(at(root, "race-stop"))}`);
|
|
367
|
+
await waitFor(at(race, "swapping"));
|
|
368
|
+
for (let index = 0; index < 30; index++) {
|
|
369
|
+
const op = await native(restricted());
|
|
370
|
+
try {
|
|
371
|
+
await op.writeFile(at(race, `dir/n-${index}`), bytes, signal);
|
|
372
|
+
}
|
|
373
|
+
catch { }
|
|
374
|
+
const read = await (await native(restricted()))
|
|
375
|
+
.readFile(at(race, "dir/secret"), { maxBytes: 200, signal })
|
|
376
|
+
.catch(() => null);
|
|
377
|
+
assert.notEqual(read && text(read.data), secret, "native read escaped during a swap");
|
|
378
|
+
}
|
|
379
|
+
const shellRace = await exec(restricted(), `i=0; while [ $i -lt 400 ]; do printf pwn > race/dir/x-$i; cat race/dir/secret; ` +
|
|
380
|
+
`chmod 777 race/dir/secret; i=$((i+1)); done 2>/dev/null; true`);
|
|
381
|
+
assert(!shellRace.stdout.includes(secret), "shell read escaped during a swap");
|
|
382
|
+
await exec(full, "touch race-stop");
|
|
383
|
+
assert.equal((await swapper).exitCode, 0);
|
|
384
|
+
for (let index = 0; index < 400; index++) {
|
|
385
|
+
assert.equal(await fixture.inspect.readFile(at(sibling, `x-${index}`)), null);
|
|
386
|
+
if (index < 30)
|
|
387
|
+
assert.equal(await fixture.inspect.readFile(at(sibling, `n-${index}`)), null);
|
|
388
|
+
}
|
|
389
|
+
await siblingIntact("component swaps must not reach the sibling");
|
|
390
|
+
// A swap of the root path itself during a live operation, then a fresh operation.
|
|
391
|
+
const moved = `${root}.moved-${randomUUID()}`;
|
|
392
|
+
const live = exec(restricted(), `printf r > ready-root; until [ -e ${quote(at(moved, "barrier-root"))} ]; do sleep 0.01; done; ` +
|
|
393
|
+
`printf pwn > ${quote(at(root, "after-swap"))}; cat ${quote(at(root, "secret"))}; printf ok > in-place; true`);
|
|
394
|
+
await waitFor(at(root, "ready-root"));
|
|
395
|
+
await exec(full, `mv ${quote(root)} ${quote(moved)} && ln -s ${quote(sibling)} ${quote(root)} && touch ${quote(at(moved, "barrier-root"))}`);
|
|
396
|
+
const swapped = await live;
|
|
397
|
+
assert(!swapped.stdout.includes(secret), "a live operation must not follow a root swap");
|
|
398
|
+
assert.equal(text(await fixture.inspect.readFile(at(moved, "in-place"))), "ok");
|
|
399
|
+
await denied((async () => (await native(restricted())).writeFile(at(root, "fresh"), bytes, signal))(), "a fresh native operation must reject a swapped root");
|
|
400
|
+
const fresh = await (await fixture.operation(restricted()))
|
|
401
|
+
.exec({
|
|
402
|
+
command: "printf pwn > fresh-exec",
|
|
403
|
+
cwd: root,
|
|
404
|
+
timeoutMs: 30_000,
|
|
405
|
+
maxOutputBytes: 1024,
|
|
406
|
+
signal,
|
|
407
|
+
})
|
|
408
|
+
.catch((error) => error);
|
|
409
|
+
assert(isSandboxScopeDeniedError(fresh) || fresh.exitCode !== 0, "a fresh exec must not run in a swapped root");
|
|
410
|
+
await exec(full, `rm ${quote(root)} && mv ${quote(moved)} ${quote(root)}`);
|
|
411
|
+
for (const name of ["after-swap", "fresh", "fresh-exec"]) {
|
|
412
|
+
assert.equal(await fixture.inspect.readFile(at(sibling, name)), null, `root swap ${name}`);
|
|
413
|
+
}
|
|
414
|
+
await siblingIntact("root swaps must not reach the sibling");
|
|
415
|
+
}
|
|
416
|
+
// A mutable syscall pointer: another thread rewrites the address/path during the check.
|
|
417
|
+
const target = ungranted[0];
|
|
418
|
+
if (target) {
|
|
419
|
+
const before = await receipts();
|
|
420
|
+
const flip = await exec(restricted(allowlisted), `python3 -c ${quote(FLIP_PROGRAM)} connect 1500 ${granted.host} ${granted.port} ${target.host} ${target.port}`);
|
|
421
|
+
assert.equal(flip.exitCode, 0, `pointer race program must run: ${flip.stderr}`);
|
|
422
|
+
const flipped = await receipts();
|
|
423
|
+
assert.deepEqual(flipped.slice(1), before.slice(1), "a flipped sockaddr must not escape");
|
|
424
|
+
assert((flipped[0] ?? 0) > (before[0] ?? 0), "the race must also reach the granted endpoint");
|
|
425
|
+
const chmods = await exec(restricted(), `python3 -c ${quote(FLIP_PROGRAM)} chmod 3000 ${quote(at(root, "inroot.txt"))} ${quote(at(sibling, "secret"))}`);
|
|
426
|
+
assert.equal(chmods.exitCode, 0, `chmod race program must run: ${chmods.stderr}`);
|
|
427
|
+
assert.notEqual(chmods.stdout.trim(), "ok=0", "in-root chmods must succeed");
|
|
428
|
+
await siblingIntact("a flipped path must not chmod the sibling");
|
|
429
|
+
}
|
|
430
|
+
// Exact cancellation: detached descendants end; a sibling operation keeps running.
|
|
431
|
+
const keepAlive = exec(restricted(), `printf r > ready-keep; until [ -e release-keep ]; do sleep 0.01; done; printf done > kept`);
|
|
432
|
+
await waitFor(at(root, "ready-keep"));
|
|
433
|
+
const abort = new AbortController();
|
|
434
|
+
const cancelled = exec(restricted(), `(sleep 1000 & echo $! > p1); nohup sh -c 'sleep 1001' > /dev/null 2>&1 & echo $! > p2; ` +
|
|
435
|
+
`setsid sleep 1002 > /dev/null 2>&1 & ` +
|
|
436
|
+
`python3 -c ${quote("import os, time\nif os.fork() == 0:\n os.setpgid(0, 0)\n open('p3.tmp', 'w').write(str(os.getpid()))\n os.rename('p3.tmp', 'p3')\n time.sleep(1003)")} & ` +
|
|
437
|
+
`until [ -e p3 ]; do sleep 0.01; done; printf r > ready-cancel; sleep 1004`, abort.signal);
|
|
438
|
+
await waitFor(at(root, "ready-cancel"));
|
|
439
|
+
const pids = await Promise.all(["p1", "p2", "p3"].map(async (name) => Number(text(await fixture.inspect.readFile(at(root, name))))));
|
|
440
|
+
assert.deepEqual(await fixture.inspect.alive(pids), pids, "descendants run before cancel");
|
|
441
|
+
abort.abort();
|
|
442
|
+
const stopped = await cancelled;
|
|
443
|
+
assert.equal(stopped.exitCode, null, "a cancelled operation has no exit code");
|
|
444
|
+
assert.deepEqual(await fixture.inspect.alive(pids), [], "cancellation ends every descendant");
|
|
445
|
+
await exec(restricted(), "touch release-keep");
|
|
446
|
+
assert.equal((await keepAlive).exitCode, 0, "the sibling operation survives the cancel");
|
|
447
|
+
assert.equal(text(await fixture.inspect.readFile(at(root, "kept"))), "done");
|
|
448
|
+
// Timeout ends the whole owned tree as well.
|
|
449
|
+
const timed = await exec(restricted(), `(sleep 1005 & echo $! > p4); sleep 1006`, signal, 1000);
|
|
450
|
+
assert.equal(timed.timedOut, true, "a restricted timeout is reported");
|
|
451
|
+
const p4 = Number(text(await fixture.inspect.readFile(at(root, "p4"))));
|
|
452
|
+
assert.deepEqual(await fixture.inspect.alive([p4]), [], "timeout ends background children");
|
|
453
|
+
// A fresh narrowed scope (after revocation) is enforced on the very next operation, while an
|
|
454
|
+
// operation that started with the broader grant keeps it.
|
|
455
|
+
await fixture.seed([{ path: at(root, "narrow/keep"), kind: "directory" }]);
|
|
456
|
+
const narrowed = restricted({ kind: "none" }, [at(root, "narrow/keep")]);
|
|
457
|
+
const broad = exec(restricted(), `printf r > ready-broad; until [ -e narrow/keep/release-broad ]; do sleep 0.01; done; ` +
|
|
458
|
+
`printf broad > broad.txt`);
|
|
459
|
+
await waitFor(at(root, "ready-broad"));
|
|
460
|
+
const overlapping = await (await fixture.operation(narrowed)).exec({
|
|
461
|
+
command: `printf pwn > ${quote(at(root, "overlapping.txt"))}; touch release-broad; true`,
|
|
462
|
+
cwd: at(root, "narrow/keep"),
|
|
463
|
+
timeoutMs: 30_000,
|
|
464
|
+
maxOutputBytes: 1024,
|
|
465
|
+
signal,
|
|
466
|
+
});
|
|
467
|
+
assert.equal(overlapping.exitCode, 0);
|
|
468
|
+
assert.equal((await broad).exitCode, 0, "the broader live grant is retained");
|
|
469
|
+
assert.equal(text(await fixture.inspect.readFile(at(root, "broad.txt"))), "broad");
|
|
470
|
+
assert.equal(await fixture.inspect.readFile(at(root, "overlapping.txt")), null, "a concurrent narrower scope stays narrow");
|
|
471
|
+
const narrow = await (await fixture.operation(narrowed)).exec({
|
|
472
|
+
command: `printf ok > keep.txt; printf pwn > ${quote(at(root, "revoked.txt"))}; true`,
|
|
473
|
+
cwd: at(root, "narrow/keep"),
|
|
474
|
+
timeoutMs: 30_000,
|
|
475
|
+
maxOutputBytes: 1024,
|
|
476
|
+
signal,
|
|
477
|
+
});
|
|
478
|
+
assert.equal(narrow.exitCode, 0);
|
|
479
|
+
assert.equal(text(await fixture.inspect.readFile(at(root, "narrow/keep/keep.txt"))), "ok");
|
|
480
|
+
assert.equal(await fixture.inspect.readFile(at(root, "revoked.txt")), null, "revoked root");
|
|
481
|
+
await denied((await native(narrowed)).writeFile(at(root, "revoked-native"), bytes, signal), "native write after narrowing");
|
|
482
|
+
}
|
|
483
|
+
finally {
|
|
484
|
+
await fixture.dispose();
|
|
485
|
+
}
|
|
486
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"name": "fake-client",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"publisher": "Capybara",
|
|
6
|
+
"description": "Test fake: client extension components in five slots, CSS decoration, an events listener and a suggested appearance",
|
|
7
|
+
"suggestedAppearance": {
|
|
8
|
+
"theme": "fake",
|
|
9
|
+
"replacements": { "shell.brand": "brand" }
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capybara-hq/test-plugin-fake-client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Test fake: client extension components in five slots, CSS decoration, an events listener and a suggested appearance",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@capybara-hq/plugin-client": "^0.1.0-rc.0",
|
|
10
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.0"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineClientExtension,
|
|
3
|
+
defineComponent,
|
|
4
|
+
useClientStorage,
|
|
5
|
+
useView,
|
|
6
|
+
} from "@capybara-hq/plugin-client";
|
|
7
|
+
|
|
8
|
+
const Hud = () => {
|
|
9
|
+
// useView() is the view state ({ view, status, retry }); the server view's data is on `view`
|
|
10
|
+
const { view } = useView();
|
|
11
|
+
const data = view?.data as { n?: number } | undefined;
|
|
12
|
+
return <span data-testid="fake-client-hud">{`hud ${data?.n ?? "-"}`}</span>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const Brand = ({ builtin }: { builtin: unknown }) => (
|
|
16
|
+
<span data-testid="fake-client-brand">{builtin as never}</span>
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const Empty = ({ greeting }: { greeting: string }) => (
|
|
20
|
+
<p data-testid="fake-client-empty">{greeting}</p>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const Frame = ({ children }: { children?: unknown }) => (
|
|
24
|
+
<div data-testid="fake-client-frame">{children as never}</div>
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const Fx = () => {
|
|
28
|
+
const storage = useClientStorage();
|
|
29
|
+
return <i data-testid="fake-client-fx" data-last={storage.get("last") ?? ""} />;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default defineClientExtension({
|
|
33
|
+
name: "fake-client",
|
|
34
|
+
components: {
|
|
35
|
+
hud: defineComponent("conversation.properties.section", Hud),
|
|
36
|
+
brand: defineComponent("shell.brand", Brand),
|
|
37
|
+
empty: defineComponent("conversation.empty", Empty),
|
|
38
|
+
frame: defineComponent("conversation.composer.frame", Frame),
|
|
39
|
+
fx: defineComponent("shell.overlay", Fx),
|
|
40
|
+
},
|
|
41
|
+
events: {
|
|
42
|
+
"run.started": (e, api) => api.storage.set("last", e.type),
|
|
43
|
+
"run.finished": (e, api) => api.storage.set("last", e.type),
|
|
44
|
+
"run.failed": (e, api) => api.storage.set("last", e.type),
|
|
45
|
+
"message.sent": (e, api) => api.storage.set("last", e.type),
|
|
46
|
+
"message.received": (e, api) => api.storage.set("last", e.type),
|
|
47
|
+
"tool.started": (e, api) => api.storage.set("last", e.type),
|
|
48
|
+
"tool.finished": (e, api) => api.storage.set("last", e.type),
|
|
49
|
+
"approval.requested": (e, api) => api.storage.set("last", e.type),
|
|
50
|
+
},
|
|
51
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { defineExtension, type UiView } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
|
|
3
|
+
const t = (zh: string, en: string) => ({ zh, en });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Test fake of a client extension (client extensions spec §5): one component in each of
|
|
7
|
+
* `conversation.properties.section` (`hud`, server view answering `data: { n: 1 }`), `shell.brand`
|
|
8
|
+
* (`brand`), `conversation.empty` (`empty`), `conversation.composer.frame` (`frame`) and
|
|
9
|
+
* `shell.overlay` (`fx`). The browser side is `src/client.tsx` (components and an `events`
|
|
10
|
+
* listener), `client/styles/fake.css` decorates by part and state, and the theme `fake` is the
|
|
11
|
+
* plugin's `suggestedAppearance` together with `shell.brand` -> `brand`.
|
|
12
|
+
*/
|
|
13
|
+
export default defineExtension({
|
|
14
|
+
name: "fake-client",
|
|
15
|
+
version: "0.1.0",
|
|
16
|
+
sdk: "^0.1.0-rc.0",
|
|
17
|
+
provides: [],
|
|
18
|
+
ui: [
|
|
19
|
+
{
|
|
20
|
+
id: "hud",
|
|
21
|
+
title: t("状态", "Status"),
|
|
22
|
+
slot: "conversation.properties.section",
|
|
23
|
+
kind: "component",
|
|
24
|
+
},
|
|
25
|
+
{ id: "brand", title: t("品牌", "Brand"), slot: "shell.brand", kind: "component" },
|
|
26
|
+
{ id: "empty", title: t("问候", "Greeting"), slot: "conversation.empty", kind: "component" },
|
|
27
|
+
{
|
|
28
|
+
id: "frame",
|
|
29
|
+
title: t("边框", "Frame"),
|
|
30
|
+
slot: "conversation.composer.frame",
|
|
31
|
+
kind: "component",
|
|
32
|
+
},
|
|
33
|
+
{ id: "fx", title: t("特效", "Effects"), slot: "shell.overlay", kind: "component" },
|
|
34
|
+
],
|
|
35
|
+
permissions: {
|
|
36
|
+
client: true,
|
|
37
|
+
ui: { components: ["hud", "brand", "empty", "frame", "fx"] },
|
|
38
|
+
},
|
|
39
|
+
setup(ctx) {
|
|
40
|
+
const withData = (n: number): UiView => ({ blocks: [], data: { n } });
|
|
41
|
+
ctx.ui.view("hud", async () => withData(1));
|
|
42
|
+
},
|
|
43
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capybara-hq/test-plugin-fake-client-broken",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Test fake: client code that throws (a component, an events listener and a conversation.empty replacement)",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@capybara-hq/plugin-client": "^0.1.0-rc.0",
|
|
10
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.0"
|
|
11
|
+
}
|
|
12
|
+
}
|