@capybara-hq/testing 0.1.0-rc.4 → 0.1.0-rc.40
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/device-service-conformance.d.ts +38 -0
- package/dist/device-service-conformance.js +141 -0
- package/dist/dual-replica.d.ts +23 -1
- package/dist/dual-replica.js +53 -0
- package/dist/fake-channel.d.ts +44 -5
- package/dist/fake-channel.js +63 -2
- package/dist/fake-dial-in-machine.d.ts +150 -0
- package/dist/fake-dial-in-machine.js +367 -0
- 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-lark.d.ts +12 -1
- package/dist/fake-lark.js +63 -10
- package/dist/fake-oauth-server.d.ts +62 -2
- package/dist/fake-oauth-server.js +86 -5
- package/dist/fake-slack.d.ts +17 -1
- package/dist/fake-slack.js +98 -0
- package/dist/fake-telegram.d.ts +173 -0
- package/dist/fake-telegram.js +632 -0
- package/dist/fixtures.d.ts +24 -8
- package/dist/fixtures.js +31 -8
- package/dist/index.d.ts +15 -9
- package/dist/index.js +10 -4
- package/dist/kernel-helpers.d.ts +16 -4
- package/dist/kernel-helpers.js +39 -4
- package/dist/media-samples.d.ts +2 -0
- package/dist/media-samples.js +2 -0
- package/dist/model-conformance.d.ts +15 -10
- package/dist/model-conformance.js +87 -14
- package/dist/push-conformance.d.ts +31 -0
- package/dist/push-conformance.js +160 -0
- package/dist/replica-runner.js +2 -0
- package/dist/sandbox-native-conformance.d.ts +31 -0
- package/dist/sandbox-native-conformance.js +153 -0
- package/dist/sandbox-permission-conformance.d.ts +310 -0
- package/dist/sandbox-permission-conformance.js +1491 -0
- package/fixtures/extensions/fake-bootstrap-a/src/index.ts +8 -4
- package/fixtures/extensions/fake-bootstrap-b/src/index.ts +8 -4
- 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/src/index.ts +52 -46
- package/fixtures/extensions/fake-connector/src/index.ts +64 -34
- 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 +78 -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 +22 -1
- package/fixtures/extensions/fake-im/src/checks.ts +94 -0
- package/fixtures/extensions/fake-im/src/directory.ts +44 -20
- package/fixtures/extensions/fake-im/src/index.ts +59 -11
- 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-object-store/src/index.ts +12 -8
- package/fixtures/extensions/fake-openapi/src/index.ts +46 -34
- package/fixtures/extensions/fake-push/.capybara-plugin/plugin.json +13 -0
- package/fixtures/extensions/fake-push/guides/fake-push-key.md +6 -0
- package/fixtures/extensions/fake-push/guides/fake-push-key.zh.md +6 -0
- package/fixtures/extensions/fake-push/migrations/0001_sends.sql +9 -0
- package/fixtures/extensions/fake-push/package.json +12 -0
- package/fixtures/extensions/fake-push/src/check.ts +40 -0
- package/fixtures/extensions/fake-push/src/index.ts +56 -0
- package/fixtures/extensions/fake-push/src/push.ts +103 -0
- package/fixtures/extensions/fake-tools-ui/src/index.ts +61 -2
- package/fixtures/extensions/fake-web/src/index.ts +5 -4
- package/fixtures/extensions/fake-web/src/web.ts +11 -7
- package/fixtures/extensions/fake-web-2/src/index.ts +2 -2
- package/fixtures/extensions/fake-web-2/src/web.ts +11 -7
- package/fixtures/plugins/fake-theme/.capybara-plugin/plugin.json +7 -0
- package/fixtures/plugins/fake-theme/brand/app-512.png +0 -0
- package/fixtures/plugins/fake-theme/brand/app-mask-512.png +0 -0
- package/fixtures/plugins/fake-theme/brand/avatars/bot.svg +1 -0
- package/fixtures/plugins/fake-theme/brand/avatars/cat.png +0 -0
- package/fixtures/plugins/fake-theme/brand/illustration.svg +1 -0
- package/fixtures/plugins/fake-theme/brand/unnamed.svg +1 -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/brand-kit.json +24 -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,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineExtension,
|
|
3
|
+
type ExtensionContext,
|
|
4
|
+
type HookCall,
|
|
5
|
+
platformOnly,
|
|
6
|
+
} from "@capybara-hq/plugin-sdk";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Test fake of an extension that cleans up after removals: it observes the three lifecycle hooks
|
|
11
|
+
* (`org.member_removed`, `agent.deleted`, `org.deleted`) and records every call in its own schema
|
|
12
|
+
* (`plugin_fake_lifecycle`): table `calls` gets one row per call, `deliveries` one row per call
|
|
13
|
+
* that succeeded, each with the mount and the payload. Deployment config `failTimes` (default 0):
|
|
14
|
+
* the first `failTimes` calls of each (mount, payload) throw, so tests can drive the kernel's
|
|
15
|
+
* retries; the count lives in PG, so it holds across replicas (platform-only). Deployment config `label` (optional,
|
|
16
|
+
* at most 10 characters) is overridable per org, so a test can store an org copy that does not
|
|
17
|
+
* validate (an org whose effective config is invalid).
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const DeploymentConfig = z.object({
|
|
21
|
+
/** How many calls of each (mount, payload) throw before one succeeds. */
|
|
22
|
+
failTimes: platformOnly(z.number().int().min(0).default(0)),
|
|
23
|
+
/** Overridable per org; an org copy with a longer label makes that org's config invalid. */
|
|
24
|
+
label: z.string().max(10).optional(),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
type Db = ExtensionContext["db"];
|
|
28
|
+
|
|
29
|
+
/** Records the call, throws while it is one of the first `failTimes`, else records the delivery. */
|
|
30
|
+
async function handle(
|
|
31
|
+
db: Db,
|
|
32
|
+
mount: string,
|
|
33
|
+
payload: object,
|
|
34
|
+
call: HookCall | undefined,
|
|
35
|
+
): Promise<void> {
|
|
36
|
+
const json = JSON.stringify(payload);
|
|
37
|
+
await db.insertInto("calls").values({ mount, payload: json }).execute();
|
|
38
|
+
const { failTimes } = DeploymentConfig.parse(call?.config ?? {});
|
|
39
|
+
if (failTimes > 0) {
|
|
40
|
+
const row = await db
|
|
41
|
+
.selectFrom("calls")
|
|
42
|
+
.select((eb) => eb.fn.countAll<string>().as("n"))
|
|
43
|
+
.where("mount", "=", mount)
|
|
44
|
+
.where("payload", "=", json)
|
|
45
|
+
.executeTakeFirstOrThrow();
|
|
46
|
+
if (Number(row.n) <= failTimes) throw new Error(`fake-lifecycle: call ${row.n} fails`);
|
|
47
|
+
}
|
|
48
|
+
await db.insertInto("deliveries").values({ mount, payload: json }).execute();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default defineExtension({
|
|
52
|
+
name: "fake-lifecycle",
|
|
53
|
+
version: "0.1.0",
|
|
54
|
+
sdk: "^0.1.0-rc.0",
|
|
55
|
+
provides: [],
|
|
56
|
+
migrations: "../migrations",
|
|
57
|
+
config: { deployment: DeploymentConfig },
|
|
58
|
+
permissions: { hooks: ["org.member_removed", "agent.deleted", "org.deleted"] },
|
|
59
|
+
setup(ctx) {
|
|
60
|
+
ctx.hooks.on(
|
|
61
|
+
"org.member_removed",
|
|
62
|
+
(p, _signal, call) => handle(ctx.db, "org.member_removed", p, call),
|
|
63
|
+
{ mode: "observe" },
|
|
64
|
+
);
|
|
65
|
+
ctx.hooks.on("agent.deleted", (p, _signal, call) => handle(ctx.db, "agent.deleted", p, call), {
|
|
66
|
+
mode: "observe",
|
|
67
|
+
});
|
|
68
|
+
ctx.hooks.on("org.deleted", (p, _signal, call) => handle(ctx.db, "org.deleted", p, call), {
|
|
69
|
+
mode: "observe",
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
});
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
OBJECT_STORE_EXTENSION_POINT,
|
|
15
15
|
type ObjectHead,
|
|
16
16
|
type ObjectStore,
|
|
17
|
+
platformOnly,
|
|
17
18
|
secret,
|
|
18
19
|
} from "@capybara-hq/plugin-sdk";
|
|
19
20
|
import { z } from "zod";
|
|
@@ -28,14 +29,17 @@ import { z } from "zod";
|
|
|
28
29
|
* refused, `presignGet` sets the disposition and response type.
|
|
29
30
|
*/
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
/** Platform-only (object-store@1 is infrastructure, unified config spec §5.3). */
|
|
33
|
+
const DeploymentConfig = platformOnly(
|
|
34
|
+
z.object({
|
|
35
|
+
endpoint: z.string().url().optional(),
|
|
36
|
+
region: z.string().min(1),
|
|
37
|
+
bucket: z.string().min(1),
|
|
38
|
+
accessKeyId: secret(z.string().min(1)),
|
|
39
|
+
secretAccessKey: secret(z.string().min(1)),
|
|
40
|
+
forcePathStyle: z.boolean().default(true),
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
39
43
|
|
|
40
44
|
/** The deployment config of the fake (as `startTestS3()` gives it). */
|
|
41
45
|
export type FakeObjectStoreConfig = z.input<typeof DeploymentConfig>;
|
|
@@ -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
|
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"name": "fake-push",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"publisher": "Capybara",
|
|
6
|
+
"description": "Test fake: a scripted push provider (push-provider@1) driven by the token prefix",
|
|
7
|
+
"setupGuides": [
|
|
8
|
+
{
|
|
9
|
+
"id": "fake-push-key",
|
|
10
|
+
"place": "extension-deployment"
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- Runs with search_path "plugin_fake_push, public": table names carry no schema prefix.
|
|
2
|
+
-- Every send attempt (one row per registration per call), so dual-replica tests count across processes.
|
|
3
|
+
CREATE TABLE IF NOT EXISTS sends (
|
|
4
|
+
id bigserial PRIMARY KEY,
|
|
5
|
+
registration_id text NOT NULL,
|
|
6
|
+
job_marker text NOT NULL DEFAULT '',
|
|
7
|
+
message jsonb NOT NULL,
|
|
8
|
+
at timestamptz NOT NULL DEFAULT now()
|
|
9
|
+
);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capybara-hq/test-plugin-fake-push",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Test fake: a scripted push provider (push-provider@1) driven by the token prefix",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.0",
|
|
10
|
+
"zod": "^4.6.7"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { SetupCheckDefinition } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The platform setup check of `fake-push` (place `extension-deployment`), registered in
|
|
5
|
+
* `index.ts` as `fake-push-key`: it reads the deployment config's `key` from its target (the
|
|
6
|
+
* extension's own deployment config) and answers without a third-party call:
|
|
7
|
+
*
|
|
8
|
+
* - no key: `failing` (set one);
|
|
9
|
+
* - a key starting with `bad`: `failing`, with a reason and a fix that echo the key (the kernel
|
|
10
|
+
* must redact it; a key of 8 characters or more is redacted);
|
|
11
|
+
* - any other key: `ok`, with a reason naming the plugin and the org the check got (`none` for the
|
|
12
|
+
* platform), so a test sees what the kernel passed.
|
|
13
|
+
*/
|
|
14
|
+
export const keyCheck: SetupCheckDefinition = {
|
|
15
|
+
place: "extension-deployment",
|
|
16
|
+
async run(args) {
|
|
17
|
+
if (args.target.kind !== "extension-deployment") throw new Error("not a deployment target");
|
|
18
|
+
const key = (args.target.config as { key?: unknown } | null)?.key;
|
|
19
|
+
if (typeof key !== "string" || key === "") {
|
|
20
|
+
return {
|
|
21
|
+
status: "failing",
|
|
22
|
+
reason: { en: "No key is set in the deployment config." },
|
|
23
|
+
fix: { en: "Save a key in the deployment config field key." },
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (key.startsWith("bad")) {
|
|
27
|
+
return {
|
|
28
|
+
status: "failing",
|
|
29
|
+
reason: { en: `The fake push service refused the key ${key}.` },
|
|
30
|
+
fix: { en: `Replace ${key} with a key from the fake push console.` },
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
status: "ok",
|
|
35
|
+
reason: {
|
|
36
|
+
en: `The fake push service accepted the key of ${args.target.plugin} (org: ${args.orgId ?? "none"}).`,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineExtension,
|
|
3
|
+
PUSH_PROVIDER_EXTENSION_POINT,
|
|
4
|
+
platformOnly,
|
|
5
|
+
secret,
|
|
6
|
+
} from "@capybara-hq/plugin-sdk";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import { keyCheck } from "./check.js";
|
|
9
|
+
import { fakePushProbe, makeFakePush } from "./push.js";
|
|
10
|
+
|
|
11
|
+
export { type FakePushSend, fakePushProbe, makeFakePush } from "./push.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Test fake of a push provider (`push-provider@1`), scripted by the token prefix (see
|
|
15
|
+
* `makeFakePush`). Deployment config: `apps` (the app ids it covers, default
|
|
16
|
+
* `["com.example.app"]`) and an optional secret `key`. Every send attempt is recorded in
|
|
17
|
+
* `plugin_fake_push.sends` (counted across replicas) and on `fakePushProbe().sends` (in process).
|
|
18
|
+
* Its platform setup guide (`guides/fake-push-key.md`, place `extension-deployment`) has one check,
|
|
19
|
+
* `fake-push-key` (`check.ts`), which reads `key`. Platform-only: push delivery is the kernel's,
|
|
20
|
+
* never an org-bound call (spec §5.3).
|
|
21
|
+
*/
|
|
22
|
+
const DeploymentConfig = platformOnly(
|
|
23
|
+
z.object({
|
|
24
|
+
apps: z.array(z.string().min(1)).default(["com.example.app"]),
|
|
25
|
+
key: secret(z.string()).optional(),
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export default defineExtension({
|
|
30
|
+
name: "fake-push",
|
|
31
|
+
version: "0.1.0",
|
|
32
|
+
sdk: "^0.1.0-rc.0",
|
|
33
|
+
provides: [PUSH_PROVIDER_EXTENSION_POINT],
|
|
34
|
+
permissions: { setupChecks: ["fake-push-key"] },
|
|
35
|
+
migrations: "../migrations",
|
|
36
|
+
config: { deployment: DeploymentConfig },
|
|
37
|
+
setup(ctx) {
|
|
38
|
+
const cfg = DeploymentConfig.parse(ctx.config);
|
|
39
|
+
const { provider } = makeFakePush({
|
|
40
|
+
apps: cfg.apps,
|
|
41
|
+
probe: fakePushProbe(),
|
|
42
|
+
async onSend(s) {
|
|
43
|
+
await ctx.db
|
|
44
|
+
.insertInto("sends")
|
|
45
|
+
.values({
|
|
46
|
+
registration_id: s.registrationId,
|
|
47
|
+
job_marker: "",
|
|
48
|
+
message: JSON.stringify(s.message),
|
|
49
|
+
})
|
|
50
|
+
.execute();
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
ctx.provide(PUSH_PROVIDER_EXTENSION_POINT, provider);
|
|
54
|
+
ctx.setup.check("fake-push-key", keyCheck);
|
|
55
|
+
},
|
|
56
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PushError,
|
|
3
|
+
type PushMessage,
|
|
4
|
+
type PushProvider,
|
|
5
|
+
type PushResult,
|
|
6
|
+
type PushTarget,
|
|
7
|
+
} from "@capybara-hq/plugin-sdk";
|
|
8
|
+
|
|
9
|
+
/** One send attempt as the probe records it. */
|
|
10
|
+
export interface FakePushSend {
|
|
11
|
+
registrationId: string;
|
|
12
|
+
token: string;
|
|
13
|
+
message: PushMessage;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The probe tests read: every send attempt of this process (extension instances share it). */
|
|
17
|
+
export function fakePushProbe(): { sends: FakePushSend[] } {
|
|
18
|
+
const g = globalThis as { __fakePush?: { sends: FakePushSend[] } };
|
|
19
|
+
g.__fakePush ??= { sends: [] };
|
|
20
|
+
return g.__fakePush;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Rejects with the signal's reason once it aborts. */
|
|
24
|
+
function hang(signal: AbortSignal): Promise<never> {
|
|
25
|
+
return new Promise((_, reject) => {
|
|
26
|
+
if (signal.aborted) reject(signal.reason);
|
|
27
|
+
else signal.addEventListener("abort", () => reject(signal.reason), { once: true });
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const failed = (
|
|
32
|
+
registrationId: string,
|
|
33
|
+
kind: "auth" | "rate_limited" | "transient",
|
|
34
|
+
message: string,
|
|
35
|
+
retryAfterMs?: number,
|
|
36
|
+
): PushResult => ({
|
|
37
|
+
registrationId,
|
|
38
|
+
status: "failed",
|
|
39
|
+
kind,
|
|
40
|
+
message,
|
|
41
|
+
...(retryAfterMs !== undefined && { retryAfterMs }),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export interface FakePushOptions {
|
|
45
|
+
/** The app ids `apps()` lists (default `["com.example.app"]`). */
|
|
46
|
+
apps?: readonly string[];
|
|
47
|
+
/** Called once per registration per `send` (the extension writes `plugin_fake_push.sends`). */
|
|
48
|
+
onSend?: (send: FakePushSend) => Promise<void> | void;
|
|
49
|
+
/** The probe to record on (default: the process probe). */
|
|
50
|
+
probe?: { sends: FakePushSend[] };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The scripted provider, by token prefix: `dead:` unregistered; `auth:` failed auth; `rate:`
|
|
55
|
+
* failed rate_limited (`retryAfterMs` 1000); `flaky:<n>:` transient for the first n calls of that
|
|
56
|
+
* token, then delivered; `throw:` a plain Error; `net:` a thrown transient PushError; `hang:`
|
|
57
|
+
* waits for the signal; anything else delivered. Result messages never contain the token. Usable
|
|
58
|
+
* without a kernel.
|
|
59
|
+
*/
|
|
60
|
+
export function makeFakePush(opts: FakePushOptions = {}): {
|
|
61
|
+
provider: PushProvider;
|
|
62
|
+
sends: FakePushSend[];
|
|
63
|
+
} {
|
|
64
|
+
const apps = Object.freeze([...(opts.apps ?? ["com.example.app"])]);
|
|
65
|
+
const probe = opts.probe ?? { sends: [] };
|
|
66
|
+
const flakyCalls = new Map<string, number>();
|
|
67
|
+
|
|
68
|
+
async function one(
|
|
69
|
+
r: PushTarget,
|
|
70
|
+
message: PushMessage,
|
|
71
|
+
signal: AbortSignal,
|
|
72
|
+
): Promise<PushResult> {
|
|
73
|
+
const send: FakePushSend = { registrationId: r.id, token: r.token, message };
|
|
74
|
+
probe.sends.push(send);
|
|
75
|
+
await opts.onSend?.(send);
|
|
76
|
+
const t = r.token;
|
|
77
|
+
if (t.startsWith("dead:")) return { registrationId: r.id, status: "unregistered" };
|
|
78
|
+
if (t.startsWith("auth:")) return failed(r.id, "auth", "fake-push: credentials rejected");
|
|
79
|
+
if (t.startsWith("rate:")) {
|
|
80
|
+
return failed(r.id, "rate_limited", "fake-push: rate limited", 1000);
|
|
81
|
+
}
|
|
82
|
+
const flaky = /^flaky:(\d+):/.exec(t);
|
|
83
|
+
if (flaky) {
|
|
84
|
+
const n = Number(flaky[1]);
|
|
85
|
+
const seen = flakyCalls.get(t) ?? 0;
|
|
86
|
+
flakyCalls.set(t, seen + 1);
|
|
87
|
+
if (seen < n) return failed(r.id, "transient", "fake-push: temporary failure");
|
|
88
|
+
}
|
|
89
|
+
if (t.startsWith("throw:")) throw new Error("fake-push: scripted failure");
|
|
90
|
+
if (t.startsWith("net:")) {
|
|
91
|
+
throw new PushError("fake-push: network error", { kind: "transient" });
|
|
92
|
+
}
|
|
93
|
+
if (t.startsWith("hang:")) await hang(signal);
|
|
94
|
+
return { registrationId: r.id, status: "delivered" };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const provider: PushProvider = {
|
|
98
|
+
apps: () => apps,
|
|
99
|
+
send: ({ registrations, message, signal }) =>
|
|
100
|
+
Promise.all(registrations.map((r) => one(r, message, signal))),
|
|
101
|
+
};
|
|
102
|
+
return { provider, sends: probe.sends };
|
|
103
|
+
}
|
|
@@ -13,6 +13,8 @@ import { z } from "zod";
|
|
|
13
13
|
* it needs no object store (storage is `fake-storage-user`'s).
|
|
14
14
|
* - tool `write` (model-visible `plugin__fake-tools-ui__write`, default policy allow): replaces the
|
|
15
15
|
* conversation's item list in the extension's own table, then invalidates the view `tasks`;
|
|
16
|
+
* - tool `web-only` (default policy allow, `sources: ["web", "channel_dm"]`): returns, as JSON
|
|
17
|
+
* text, the call's `source`, `ownerAccountId`, `accountId` and `role`;
|
|
16
18
|
* - view `tasks` (conversation tab): badge `<done>/<total>` and a checklist;
|
|
17
19
|
* - the plugin also ships the skill `fake-notes` and the connector template `fake-notes`
|
|
18
20
|
* (for the `fake-connector` extension).
|
|
@@ -62,6 +64,16 @@ const WRITE: ToolSpec = {
|
|
|
62
64
|
defaultPolicy: "allow",
|
|
63
65
|
};
|
|
64
66
|
|
|
67
|
+
const WEB_ONLY: ToolSpec = {
|
|
68
|
+
name: "web-only",
|
|
69
|
+
description:
|
|
70
|
+
"Report who and where this call runs: the conversation source, its owner, the caller and the " +
|
|
71
|
+
"caller's role. Offered only in web and direct-message conversations. Test fixture only.",
|
|
72
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
|
73
|
+
defaultPolicy: "allow",
|
|
74
|
+
sources: ["web", "channel_dm"],
|
|
75
|
+
};
|
|
76
|
+
|
|
65
77
|
const render = (items: FakeItem[]): string =>
|
|
66
78
|
items.length === 0
|
|
67
79
|
? "The list is now empty."
|
|
@@ -104,8 +116,31 @@ export default defineExtension({
|
|
|
104
116
|
sdk: "^0.1.0-rc.0",
|
|
105
117
|
provides: [],
|
|
106
118
|
migrations: "../migrations",
|
|
107
|
-
ui: [
|
|
108
|
-
|
|
119
|
+
ui: [
|
|
120
|
+
{ id: "tasks", title: { zh: "条目", en: "Items" }, slot: "conversation.panel", kind: "view" },
|
|
121
|
+
{
|
|
122
|
+
id: "agent-notes",
|
|
123
|
+
title: { zh: "智能体备注", en: "Agent notes" },
|
|
124
|
+
slot: "agent.detail.section",
|
|
125
|
+
kind: "view",
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
id: "org-admin",
|
|
129
|
+
title: { zh: "组织设置扩展", en: "Org admin" },
|
|
130
|
+
slot: "org.settings.section",
|
|
131
|
+
kind: "view",
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
id: "platform-home",
|
|
135
|
+
title: { zh: "平台首页", en: "Platform home" },
|
|
136
|
+
slot: "platform.page",
|
|
137
|
+
kind: "view",
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
permissions: {
|
|
141
|
+
tools: ["write", "web-only"],
|
|
142
|
+
ui: { views: ["tasks", "agent-notes", "org-admin", "platform-home"] },
|
|
143
|
+
},
|
|
109
144
|
setup(ctx) {
|
|
110
145
|
ctx.tools.register(WRITE, async (input, tctx) => {
|
|
111
146
|
const parsed = WriteInput.safeParse(input);
|
|
@@ -133,8 +168,32 @@ export default defineExtension({
|
|
|
133
168
|
},
|
|
134
169
|
};
|
|
135
170
|
});
|
|
171
|
+
ctx.tools.register(WEB_ONLY, async (_input, tctx) => {
|
|
172
|
+
const { source, ownerAccountId, accountId, role } = tctx;
|
|
173
|
+
return {
|
|
174
|
+
content: [
|
|
175
|
+
{ type: "text", text: JSON.stringify({ source, ownerAccountId, accountId, role }) },
|
|
176
|
+
],
|
|
177
|
+
};
|
|
178
|
+
});
|
|
136
179
|
ctx.ui.view("tasks", async ({ conversationId }) =>
|
|
137
180
|
tasksView(conversationId === undefined ? [] : await readItems(ctx.db, conversationId)),
|
|
138
181
|
);
|
|
182
|
+
const ping: UiView["blocks"] = [
|
|
183
|
+
{ type: "actions", buttons: [{ actionId: "ping", label: "Ping" }] },
|
|
184
|
+
];
|
|
185
|
+
const done = async () => ({ toast: { zh: "已完成", en: "Done" } });
|
|
186
|
+
ctx.ui.view("agent-notes", async (args) => ({
|
|
187
|
+
blocks: [{ type: "heading", text: `Agent ${args.agentId ?? ""}`.trim() }, ...ping],
|
|
188
|
+
}));
|
|
189
|
+
ctx.ui.action("agent-notes", done);
|
|
190
|
+
ctx.ui.view("org-admin", async () => ({
|
|
191
|
+
blocks: [{ type: "heading", text: "Org settings" }, ...ping],
|
|
192
|
+
}));
|
|
193
|
+
ctx.ui.action("org-admin", done);
|
|
194
|
+
ctx.ui.view("platform-home", async () => ({
|
|
195
|
+
blocks: [{ type: "heading", text: "Platform home" }, ...ping],
|
|
196
|
+
}));
|
|
197
|
+
ctx.ui.action("platform-home", done);
|
|
139
198
|
},
|
|
140
199
|
});
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { defineExtension } from "@capybara-hq/plugin-sdk";
|
|
2
|
-
import {
|
|
2
|
+
import { FakeWebConfig, makeFakeWeb } from "./web.js";
|
|
3
3
|
|
|
4
|
-
export { type FakeWebCall,
|
|
4
|
+
export { type FakeWebCall, FakeWebConfig, fakeWebProbe, makeFakeWeb } from "./web.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Test fake: a scripted web provider (`web-search@1` and `web-fetch@1`; see `makeFakeWeb` for the
|
|
8
|
-
* scripts).
|
|
8
|
+
* scripts). Deployment config `{ token }` (a required, org-overridable secret the platform may
|
|
9
|
+
* leave empty); `configured()` is true iff the token is set and not `unconfigured`.
|
|
9
10
|
* `fake-web-2` is the same with its own name, for the org default provider.
|
|
10
11
|
*/
|
|
11
12
|
export default defineExtension({
|
|
@@ -13,7 +14,7 @@ export default defineExtension({
|
|
|
13
14
|
version: "0.1.0",
|
|
14
15
|
sdk: "^0.1.0-rc.0",
|
|
15
16
|
provides: ["web-search@1", "web-fetch@1"],
|
|
16
|
-
config: {
|
|
17
|
+
config: { deployment: FakeWebConfig },
|
|
17
18
|
setup(ctx) {
|
|
18
19
|
const { search, fetch } = makeFakeWeb("fake-web");
|
|
19
20
|
ctx.provide("web-search@1", search);
|
|
@@ -13,10 +13,11 @@ import { z } from "zod";
|
|
|
13
13
|
// own directory); test/fixtures.test.ts of @capybara-hq/testing keeps them equal.
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* Deployment config of the fake web providers: a required, org-overridable secret `token`. The
|
|
17
|
+
* platform may leave it empty (orgs then need their own copy); `configured()` is false for the
|
|
18
|
+
* token `unconfigured` and throws for the token `throw:configured`.
|
|
18
19
|
*/
|
|
19
|
-
export const
|
|
20
|
+
export const FakeWebConfig = z.object({ token: secret(z.string().min(1)) });
|
|
20
21
|
|
|
21
22
|
/** One provider call, recorded on `globalThis.__fakeWeb` (in-process kernels only). */
|
|
22
23
|
export interface FakeWebCall {
|
|
@@ -43,11 +44,14 @@ const KINDS: readonly WebProviderErrorKind[] = [
|
|
|
43
44
|
"invalid",
|
|
44
45
|
];
|
|
45
46
|
|
|
46
|
-
/**
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
/**
|
|
48
|
+
* True iff the effective config's token is set and is not `unconfigured`; the token
|
|
49
|
+
* `throw:configured` makes it throw.
|
|
50
|
+
*/
|
|
51
|
+
const configured = (config: unknown): boolean => {
|
|
52
|
+
const token = (config as { token?: unknown } | null)?.token;
|
|
49
53
|
if (token === "throw:configured") throw new Error("fake web: configured() failed");
|
|
50
|
-
return typeof token === "string" && token.length > 0;
|
|
54
|
+
return typeof token === "string" && token.length > 0 && token !== "unconfigured";
|
|
51
55
|
};
|
|
52
56
|
|
|
53
57
|
/** The script of a fetch: the decoded URL path (and query) after the first `/`. */
|