@capybara-hq/testing 0.1.0-rc.48 → 0.1.0-rc.49
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 +3 -2
- package/dist/fixtures.js +3 -1
- package/fixtures/extensions/fake-run-lifecycle/.capybara-plugin/plugin.json +7 -0
- package/fixtures/extensions/fake-run-lifecycle/package.json +11 -0
- package/fixtures/extensions/fake-run-lifecycle/src/index.ts +42 -0
- package/fixtures/extensions/fake-trigger-source/src/index.ts +55 -3
- package/package.json +6 -6
package/dist/fixtures.d.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
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`) |
|
|
15
15
|
* | `fake-lifecycle` | observes `org.member_removed`, `agent.deleted` and `org.deleted`; a migration with tables `calls` (every call) and `deliveries` (every call that succeeded), each row the mount and the payload; deployment config `failTimes` (default 0): the first `failTimes` calls of each (mount, payload) throw, and `label` (optional, at most 10 characters, overridable per org: an invalid org copy) |
|
|
16
|
+
* | `fake-run-lifecycle` | observes `run.lifecycle`; every payload is recorded in order on `globalThis.__fakeRunLifecycle.calls` (`fakeRunLifecycleProbe`); probe `failTimes`: the first N calls throw after being recorded |
|
|
16
17
|
* | `fake-embed` | embeds `panel` (page) and `panel-conv` (conversation), static `/ui/panel.js`, token-checked routes, SSE over `ctx.bus` |
|
|
17
18
|
* | `fake-bootstrap-a` | `model-provider@2` with a required secret `apiKey` (pending configuration until set) |
|
|
18
19
|
* | `fake-bootstrap-b` | `object-store@1` kept in its own PG table; `bucket` + secret `secretKey` |
|
|
@@ -25,10 +26,10 @@
|
|
|
25
26
|
* | `fake-client-page` | a full page (plugin full pages spec §3-§4): `org.page` component `board` (`frame: "page"`, `nav: "primary"`, client entry using `usePluginQuery("items")`) with queries `items` (items, params and caller), `slow` (rejects only when its signal aborts; counted in `fakeClientPageProbe().aborted`), `boom` (throws) and `huge` (over `UI_LIMITS.componentQueryBytes`); action `move` (any payload, calls `ctx.ui.invalidate` for `board`, answers `invalidate: ["items"]`); `org.page` view `summary` with action `go` |
|
|
26
27
|
* | `fake-client-broken` | client code that throws: component `boom` (render), a `run.started` events listener, and a `conversation.empty` replacement (render) |
|
|
27
28
|
* | `fake-push` | `push-provider@1` scripted by the token prefix (`dead:`, `auth:`, `rate:`, `flaky:<n>:`, `throw:`, `net:`, `hang:`; else delivered); deployment config `apps` (default `["com.example.app"]`), optional secret `key`; every send is a row of `plugin_fake_push.sends` and an entry of `fakePushProbe().sends`; `makeFakePush()` is the same provider without a kernel |
|
|
28
|
-
* | `fake-trigger-source` | `trigger-source@1`: declares `item.created`, `item.updated`, `item.assigned` (directed) in `permissions.triggers.emit`, facts `status` / `priority` / `labels` / `projectKey` (all filterable); tool `emit_item_event` emits its input through `ctx.triggers.emit` with `cause: { call }` and returns `{ eventId, duplicate }` (or `{ error: <code> }`); `visible()` admits `globalThis.__fakeTriggerSource.visible` (every account when unset); the probe (`fakeTriggerSourceProbe`) also carries the extension's `ctx.triggers.emit` |
|
|
29
|
+
* | `fake-trigger-source` | `trigger-source@1`: declares `item.created`, `item.updated`, `item.assigned` (directed) in `permissions.triggers.emit`, facts `status` / `priority` / `labels` / `projectKey` (all filterable); tool `emit_item_event` emits its input through `ctx.triggers.emit` with `cause: { call }` and returns `{ eventId, duplicate }` (or `{ error: <code> }`); `visible()` admits `globalThis.__fakeTriggerSource.visible` (every account when unset); the probe (`fakeTriggerSourceProbe`) also carries the extension's `ctx.triggers.emit` and `ctx.inbox` (`permissions.inbox`); `org.page` view `requests` whose UI action records `{ actionId, accountId, role, payload }` on the probe's `actions` (action `fail` throws); observes `run.lifecycle` into the probe's `lifecycle` |
|
|
29
30
|
* | `fake-config-form` | display name 表单样例 / Form sample; no extension point: an openai-compatible-shaped deployment config (endpoints with a preset menu, an API key per endpoint in the secret record `apiKeys`, model rows, advanced fields, localized custom issues) carrying the config form hints of the extension config forms spec §6, for the web form e2e |
|
|
30
31
|
*/
|
|
31
|
-
export declare const FAKE_EXTENSIONS: readonly ["fake-connector", "fake-openapi", "fake-object-store", "fake-tools-ui", "fake-storage-user", "fake-lifecycle", "fake-embed", "fake-bootstrap-a", "fake-bootstrap-b", "fake-dep-provider", "fake-dep-requirer", "fake-im", "fake-web", "fake-web-2", "fake-context", "fake-config-form", "fake-push", "fake-client", "fake-client-broken", "fake-client-page", "fake-watch", "fake-trigger-source"];
|
|
32
|
+
export declare const FAKE_EXTENSIONS: readonly ["fake-connector", "fake-openapi", "fake-object-store", "fake-tools-ui", "fake-storage-user", "fake-lifecycle", "fake-run-lifecycle", "fake-embed", "fake-bootstrap-a", "fake-bootstrap-b", "fake-dep-provider", "fake-dep-requirer", "fake-im", "fake-web", "fake-web-2", "fake-context", "fake-config-form", "fake-push", "fake-client", "fake-client-broken", "fake-client-page", "fake-watch", "fake-trigger-source"];
|
|
32
33
|
/**
|
|
33
34
|
* Fake plugins without an extension (declarative: they live in `fixtures/plugins/<name>`, same
|
|
34
35
|
* pack layout).
|
package/dist/fixtures.js
CHANGED
|
@@ -16,6 +16,7 @@ import { fileURLToPath } from "node:url";
|
|
|
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`) |
|
|
18
18
|
* | `fake-lifecycle` | observes `org.member_removed`, `agent.deleted` and `org.deleted`; a migration with tables `calls` (every call) and `deliveries` (every call that succeeded), each row the mount and the payload; deployment config `failTimes` (default 0): the first `failTimes` calls of each (mount, payload) throw, and `label` (optional, at most 10 characters, overridable per org: an invalid org copy) |
|
|
19
|
+
* | `fake-run-lifecycle` | observes `run.lifecycle`; every payload is recorded in order on `globalThis.__fakeRunLifecycle.calls` (`fakeRunLifecycleProbe`); probe `failTimes`: the first N calls throw after being recorded |
|
|
19
20
|
* | `fake-embed` | embeds `panel` (page) and `panel-conv` (conversation), static `/ui/panel.js`, token-checked routes, SSE over `ctx.bus` |
|
|
20
21
|
* | `fake-bootstrap-a` | `model-provider@2` with a required secret `apiKey` (pending configuration until set) |
|
|
21
22
|
* | `fake-bootstrap-b` | `object-store@1` kept in its own PG table; `bucket` + secret `secretKey` |
|
|
@@ -28,7 +29,7 @@ import { fileURLToPath } from "node:url";
|
|
|
28
29
|
* | `fake-client-page` | a full page (plugin full pages spec §3-§4): `org.page` component `board` (`frame: "page"`, `nav: "primary"`, client entry using `usePluginQuery("items")`) with queries `items` (items, params and caller), `slow` (rejects only when its signal aborts; counted in `fakeClientPageProbe().aborted`), `boom` (throws) and `huge` (over `UI_LIMITS.componentQueryBytes`); action `move` (any payload, calls `ctx.ui.invalidate` for `board`, answers `invalidate: ["items"]`); `org.page` view `summary` with action `go` |
|
|
29
30
|
* | `fake-client-broken` | client code that throws: component `boom` (render), a `run.started` events listener, and a `conversation.empty` replacement (render) |
|
|
30
31
|
* | `fake-push` | `push-provider@1` scripted by the token prefix (`dead:`, `auth:`, `rate:`, `flaky:<n>:`, `throw:`, `net:`, `hang:`; else delivered); deployment config `apps` (default `["com.example.app"]`), optional secret `key`; every send is a row of `plugin_fake_push.sends` and an entry of `fakePushProbe().sends`; `makeFakePush()` is the same provider without a kernel |
|
|
31
|
-
* | `fake-trigger-source` | `trigger-source@1`: declares `item.created`, `item.updated`, `item.assigned` (directed) in `permissions.triggers.emit`, facts `status` / `priority` / `labels` / `projectKey` (all filterable); tool `emit_item_event` emits its input through `ctx.triggers.emit` with `cause: { call }` and returns `{ eventId, duplicate }` (or `{ error: <code> }`); `visible()` admits `globalThis.__fakeTriggerSource.visible` (every account when unset); the probe (`fakeTriggerSourceProbe`) also carries the extension's `ctx.triggers.emit` |
|
|
32
|
+
* | `fake-trigger-source` | `trigger-source@1`: declares `item.created`, `item.updated`, `item.assigned` (directed) in `permissions.triggers.emit`, facts `status` / `priority` / `labels` / `projectKey` (all filterable); tool `emit_item_event` emits its input through `ctx.triggers.emit` with `cause: { call }` and returns `{ eventId, duplicate }` (or `{ error: <code> }`); `visible()` admits `globalThis.__fakeTriggerSource.visible` (every account when unset); the probe (`fakeTriggerSourceProbe`) also carries the extension's `ctx.triggers.emit` and `ctx.inbox` (`permissions.inbox`); `org.page` view `requests` whose UI action records `{ actionId, accountId, role, payload }` on the probe's `actions` (action `fail` throws); observes `run.lifecycle` into the probe's `lifecycle` |
|
|
32
33
|
* | `fake-config-form` | display name 表单样例 / Form sample; no extension point: an openai-compatible-shaped deployment config (endpoints with a preset menu, an API key per endpoint in the secret record `apiKeys`, model rows, advanced fields, localized custom issues) carrying the config form hints of the extension config forms spec §6, for the web form e2e |
|
|
33
34
|
*/
|
|
34
35
|
export const FAKE_EXTENSIONS = [
|
|
@@ -38,6 +39,7 @@ export const FAKE_EXTENSIONS = [
|
|
|
38
39
|
"fake-tools-ui",
|
|
39
40
|
"fake-storage-user",
|
|
40
41
|
"fake-lifecycle",
|
|
42
|
+
"fake-run-lifecycle",
|
|
41
43
|
"fake-embed",
|
|
42
44
|
"fake-bootstrap-a",
|
|
43
45
|
"fake-bootstrap-b",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capybara-hq/test-plugin-fake-run-lifecycle",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Test fake: observes the run.lifecycle hook and records every payload on globalThis",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.0"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { defineExtension, type RunLifecyclePayload } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Test fake of a plugin that shows run state on its subjects: it observes `run.lifecycle` and
|
|
5
|
+
* records every payload, in order, on `globalThis.__fakeRunLifecycle.calls` (in-process kernels
|
|
6
|
+
* only; {@link fakeRunLifecycleProbe}). `failTimes` on the probe makes the first N calls throw
|
|
7
|
+
* (a handler failure never affects the run; the kernel retries the delivery).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** The probe tests read and script. */
|
|
11
|
+
export interface FakeRunLifecycleProbe {
|
|
12
|
+
/** Every payload a handler call received, in order (a retried delivery appears again). */
|
|
13
|
+
calls: RunLifecyclePayload[];
|
|
14
|
+
/** The first this many calls throw after being recorded. */
|
|
15
|
+
failTimes?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function fakeRunLifecycleProbe(): FakeRunLifecycleProbe {
|
|
19
|
+
const g = globalThis as { __fakeRunLifecycle?: FakeRunLifecycleProbe };
|
|
20
|
+
g.__fakeRunLifecycle ??= { calls: [] };
|
|
21
|
+
return g.__fakeRunLifecycle;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default defineExtension({
|
|
25
|
+
name: "fake-run-lifecycle",
|
|
26
|
+
version: "0.1.0",
|
|
27
|
+
sdk: "^0.1.0-rc.0",
|
|
28
|
+
provides: [],
|
|
29
|
+
permissions: { hooks: ["run.lifecycle"] },
|
|
30
|
+
setup(ctx) {
|
|
31
|
+
ctx.hooks.on(
|
|
32
|
+
"run.lifecycle",
|
|
33
|
+
(p) => {
|
|
34
|
+
const probe = fakeRunLifecycleProbe();
|
|
35
|
+
probe.calls.push({ ...p });
|
|
36
|
+
if (probe.failTimes !== undefined && probe.calls.length <= probe.failTimes)
|
|
37
|
+
throw new Error("fake-run-lifecycle: scripted failure");
|
|
38
|
+
},
|
|
39
|
+
{ mode: "observe" },
|
|
40
|
+
);
|
|
41
|
+
},
|
|
42
|
+
});
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
defineExtension,
|
|
3
|
+
type InboxCtx,
|
|
4
|
+
type RunLifecyclePayload,
|
|
5
|
+
type ToolCallContext,
|
|
3
6
|
type ToolSpec,
|
|
4
7
|
TriggerError,
|
|
5
8
|
type TriggerEvent,
|
|
@@ -19,7 +22,13 @@ import {
|
|
|
19
22
|
* account when that is unset.
|
|
20
23
|
* - Its setup puts `emit` (the extension's own `ctx.triggers.emit`) on the probe
|
|
21
24
|
* ({@link fakeTriggerSourceProbe}; in-process kernels only), so a test can emit as the extension
|
|
22
|
-
* outside a tool call.
|
|
25
|
+
* outside a tool call; likewise `causeOf` (its `ctx.triggers.causeOf`) and `inbox` (its
|
|
26
|
+
* `ctx.inbox`, `permissions.inbox`).
|
|
27
|
+
* - It observes `run.lifecycle` (`permissions.hooks`) and records every payload on the probe's
|
|
28
|
+
* `lifecycle`.
|
|
29
|
+
* - The `org.page` view `requests` has a UI action that records every call on the probe's
|
|
30
|
+
* `actions` (`{ actionId, accountId, role, payload }`) and answers a toast; an action id `fail`
|
|
31
|
+
* throws instead (nothing recorded).
|
|
23
32
|
*/
|
|
24
33
|
|
|
25
34
|
// capybara:allow-module-state a read-only constant list
|
|
@@ -31,6 +40,14 @@ export interface FakeTriggerSourceProbe {
|
|
|
31
40
|
visible?: string[];
|
|
32
41
|
/** The extension's `ctx.triggers.emit`, set by its setup. */
|
|
33
42
|
emit?: (event: TriggerEvent) => Promise<{ eventId: string; duplicate: boolean }>;
|
|
43
|
+
/** The extension's `ctx.triggers.causeOf`, set by its setup. */
|
|
44
|
+
causeOf?: (call: ToolCallContext) => Promise<string>;
|
|
45
|
+
/** The extension's `ctx.inbox`, set by its setup. */
|
|
46
|
+
inbox?: InboxCtx;
|
|
47
|
+
/** Every `run.lifecycle` payload the extension received (it subscribes), in order. */
|
|
48
|
+
lifecycle?: RunLifecyclePayload[];
|
|
49
|
+
/** The calls of the `requests` view's UI action, in order. */
|
|
50
|
+
actions?: { actionId: string; accountId: string; role: string; payload: unknown }[];
|
|
34
51
|
}
|
|
35
52
|
|
|
36
53
|
export function fakeTriggerSourceProbe(): FakeTriggerSourceProbe {
|
|
@@ -95,10 +112,45 @@ export default defineExtension({
|
|
|
95
112
|
version: "0.1.0",
|
|
96
113
|
sdk: "^0.1.0-rc.0",
|
|
97
114
|
provides: ["trigger-source@1"],
|
|
98
|
-
|
|
115
|
+
ui: [{ id: "requests", title: { zh: "请求", en: "Requests" }, slot: "org.page", kind: "view" }],
|
|
116
|
+
permissions: {
|
|
117
|
+
tools: ["emit_item_event"],
|
|
118
|
+
hooks: ["run.lifecycle"],
|
|
119
|
+
triggers: { emit: [...FAKE_TRIGGER_TYPES] },
|
|
120
|
+
inbox: true,
|
|
121
|
+
ui: { views: ["requests"] },
|
|
122
|
+
},
|
|
99
123
|
setup(ctx) {
|
|
100
124
|
ctx.provide("trigger-source@1", source);
|
|
101
|
-
|
|
125
|
+
const probe = fakeTriggerSourceProbe();
|
|
126
|
+
probe.emit = (event) => ctx.triggers.emit(event);
|
|
127
|
+
probe.causeOf = (call) => ctx.triggers.causeOf(call);
|
|
128
|
+
probe.inbox = ctx.inbox;
|
|
129
|
+
ctx.hooks.on(
|
|
130
|
+
"run.lifecycle",
|
|
131
|
+
(p) => {
|
|
132
|
+
const pr = fakeTriggerSourceProbe();
|
|
133
|
+
pr.lifecycle ??= [];
|
|
134
|
+
pr.lifecycle.push({ ...p });
|
|
135
|
+
},
|
|
136
|
+
{ mode: "observe" },
|
|
137
|
+
);
|
|
138
|
+
ctx.ui.view("requests", async () => ({
|
|
139
|
+
blocks: [{ type: "actions", buttons: [{ actionId: "accept", label: "Accept" }] }],
|
|
140
|
+
}));
|
|
141
|
+
ctx.ui.action("requests", async (args) => {
|
|
142
|
+
if (args.actionId === "fail") throw new Error("the fake action failed");
|
|
143
|
+
const accountId = "accountId" in args ? args.accountId : "";
|
|
144
|
+
const role = "role" in args ? String(args.role) : "";
|
|
145
|
+
fakeTriggerSourceProbe().actions ??= [];
|
|
146
|
+
fakeTriggerSourceProbe().actions?.push({
|
|
147
|
+
actionId: args.actionId,
|
|
148
|
+
accountId,
|
|
149
|
+
role,
|
|
150
|
+
payload: args.payload,
|
|
151
|
+
});
|
|
152
|
+
return { toast: { zh: "已接受", en: "Accepted" } };
|
|
153
|
+
});
|
|
102
154
|
ctx.tools.register(EMIT, async (input, call) => {
|
|
103
155
|
const event = { orgId: call.orgId, ...(input as object), cause: { call } } as TriggerEvent;
|
|
104
156
|
try {
|
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.49",
|
|
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.109"
|
|
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.10",
|
|
56
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.87"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"vitest": "^5.0.5",
|
|
60
|
-
"@capybara-hq/plugin-
|
|
61
|
-
"@capybara-hq/plugin-
|
|
60
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.87",
|
|
61
|
+
"@capybara-hq/plugin-tools": "^0.1.0-rc.28"
|
|
62
62
|
},
|
|
63
63
|
"peerDependenciesMeta": {
|
|
64
64
|
"@capybara-hq/plugin-tools": {
|