@capybara-hq/testing 0.1.0-rc.47 → 0.1.0-rc.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fixtures.d.ts +2 -1
- package/dist/fixtures.js +2 -0
- package/fixtures/extensions/fake-client-page/.capybara-plugin/plugin.json +7 -0
- package/fixtures/extensions/fake-client-page/package.json +12 -0
- package/fixtures/extensions/fake-client-page/src/client.tsx +36 -0
- package/fixtures/extensions/fake-client-page/src/index.ts +92 -0
- package/package.json +6 -6
package/dist/fixtures.d.ts
CHANGED
|
@@ -22,12 +22,13 @@
|
|
|
22
22
|
* | `fake-context` | `context@1` scripted by its deployment config (`text`, default "fake context"; `mode` `ok` / `null` / `throw` / `hang`); calls recorded on `globalThis.__fakeContext` (`fakeContextProbe`); tool `note` (`sources` web and channel_dm) |
|
|
23
23
|
* | `fake-client` | client extension (`permissions.client`, no extension point): components `hud` (`conversation.properties.section`, server view with `data`), `brand` (`shell.brand`, renders `builtin` in `data-testid="fake-client-brand"`), `empty` (`conversation.empty`), `frame` (`conversation.composer.frame`) and `fx` (`shell.overlay`); `client/styles/fake.css` (outline-color on `button.primary` and the composer's buttons, `--cx-fake-client-run` while `run=running`); an `events` listener storing the last event type; theme `fake`; `suggestedAppearance` = theme `fake` + `shell.brand` -> `brand` |
|
|
24
24
|
* | `fake-watch` | tool `wait` (input `{ key, deadlineMs? }`): a watched input wait whose watcher reads kv `fake-watch:<key>` (`go` settles, `fail` throws, `hang` never answers, else pending), counts its polls in kv `fake-watch:<key>:polls` and writes the identity it got to kv `fake-watch:<key>:ctx`; the resumed call returns `{ outcome, answer, signal }` as JSON; tool `nowatch` asks for a watched wait without a watcher |
|
|
25
|
+
* | `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` |
|
|
25
26
|
* | `fake-client-broken` | client code that throws: component `boom` (render), a `run.started` events listener, and a `conversation.empty` replacement (render) |
|
|
26
27
|
* | `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 |
|
|
27
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` |
|
|
28
29
|
* | `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 |
|
|
29
30
|
*/
|
|
30
|
-
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-watch", "fake-trigger-source"];
|
|
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"];
|
|
31
32
|
/**
|
|
32
33
|
* Fake plugins without an extension (declarative: they live in `fixtures/plugins/<name>`, same
|
|
33
34
|
* pack layout).
|
package/dist/fixtures.js
CHANGED
|
@@ -25,6 +25,7 @@ import { fileURLToPath } from "node:url";
|
|
|
25
25
|
* | `fake-context` | `context@1` scripted by its deployment config (`text`, default "fake context"; `mode` `ok` / `null` / `throw` / `hang`); calls recorded on `globalThis.__fakeContext` (`fakeContextProbe`); tool `note` (`sources` web and channel_dm) |
|
|
26
26
|
* | `fake-client` | client extension (`permissions.client`, no extension point): components `hud` (`conversation.properties.section`, server view with `data`), `brand` (`shell.brand`, renders `builtin` in `data-testid="fake-client-brand"`), `empty` (`conversation.empty`), `frame` (`conversation.composer.frame`) and `fx` (`shell.overlay`); `client/styles/fake.css` (outline-color on `button.primary` and the composer's buttons, `--cx-fake-client-run` while `run=running`); an `events` listener storing the last event type; theme `fake`; `suggestedAppearance` = theme `fake` + `shell.brand` -> `brand` |
|
|
27
27
|
* | `fake-watch` | tool `wait` (input `{ key, deadlineMs? }`): a watched input wait whose watcher reads kv `fake-watch:<key>` (`go` settles, `fail` throws, `hang` never answers, else pending), counts its polls in kv `fake-watch:<key>:polls` and writes the identity it got to kv `fake-watch:<key>:ctx`; the resumed call returns `{ outcome, answer, signal }` as JSON; tool `nowatch` asks for a watched wait without a watcher |
|
|
28
|
+
* | `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` |
|
|
28
29
|
* | `fake-client-broken` | client code that throws: component `boom` (render), a `run.started` events listener, and a `conversation.empty` replacement (render) |
|
|
29
30
|
* | `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 |
|
|
30
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` |
|
|
@@ -50,6 +51,7 @@ export const FAKE_EXTENSIONS = [
|
|
|
50
51
|
"fake-push",
|
|
51
52
|
"fake-client",
|
|
52
53
|
"fake-client-broken",
|
|
54
|
+
"fake-client-page",
|
|
53
55
|
"fake-watch",
|
|
54
56
|
"fake-trigger-source",
|
|
55
57
|
];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capybara-hq/test-plugin-fake-client-page",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Test fake: a full org.page component with named queries and a form-sized action",
|
|
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,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineClientExtension,
|
|
3
|
+
defineComponent,
|
|
4
|
+
ListPage,
|
|
5
|
+
useAction,
|
|
6
|
+
usePluginQuery,
|
|
7
|
+
} from "@capybara-hq/plugin-client";
|
|
8
|
+
|
|
9
|
+
type Items = { items: { id: string; title: string; column: string }[] };
|
|
10
|
+
|
|
11
|
+
// `frame: "page"`: the component draws its page, exactly one forwarded template (spec §2)
|
|
12
|
+
const Board = () => {
|
|
13
|
+
const q = usePluginQuery<Items>("items");
|
|
14
|
+
const act = useAction();
|
|
15
|
+
return (
|
|
16
|
+
<ListPage header={{ title: "Board" }}>
|
|
17
|
+
<section data-testid="fake-client-page-board" data-status={q.status}>
|
|
18
|
+
{(q.data?.items ?? []).map((i) => (
|
|
19
|
+
<button
|
|
20
|
+
key={i.id}
|
|
21
|
+
type="button"
|
|
22
|
+
data-testid={`fake-client-page-item-${i.id}`}
|
|
23
|
+
onClick={() => void act("move", { payload: { id: i.id, column: "done" } })}
|
|
24
|
+
>
|
|
25
|
+
{i.title}
|
|
26
|
+
</button>
|
|
27
|
+
))}
|
|
28
|
+
</section>
|
|
29
|
+
</ListPage>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default defineClientExtension({
|
|
34
|
+
name: "fake-client-page",
|
|
35
|
+
components: { board: defineComponent("org.page", Board) },
|
|
36
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { defineExtension, type JsonValue, UI_LIMITS } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
|
|
3
|
+
const t = (zh: string, en: string) => ({ zh, en });
|
|
4
|
+
|
|
5
|
+
/** What the fake records for tests on `globalThis.__fakeClientPage` (in-process kernels only). */
|
|
6
|
+
export interface FakeClientPageProbe {
|
|
7
|
+
/** How many `slow` queries saw their signal abort. */
|
|
8
|
+
aborted: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** The probe of {@link FakeClientPageProbe}. */
|
|
12
|
+
export function fakeClientPageProbe(): FakeClientPageProbe {
|
|
13
|
+
const g = globalThis as { __fakeClientPage?: FakeClientPageProbe };
|
|
14
|
+
g.__fakeClientPage ??= { aborted: 0 };
|
|
15
|
+
return g.__fakeClientPage;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const items = () => [
|
|
19
|
+
{ id: "a", title: "Alpha", column: "todo" },
|
|
20
|
+
{ id: "b", title: "Beta", column: "doing" },
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Test fake of a full page (plugin full pages spec §3-§4): the `org.page` component `board`
|
|
25
|
+
* (`frame: "page"`, `nav: "primary"`) with the named queries `items` (the items, the params and
|
|
26
|
+
* the identity it was called with), `slow` (answers only by rejecting once its signal aborts),
|
|
27
|
+
* `boom` (throws) and `huge` (a result over `UI_LIMITS.componentQueryBytes`); its action `move`
|
|
28
|
+
* accepts a form-sized payload, calls `ctx.ui.invalidate` for `board` and names `items` to
|
|
29
|
+
* refetch. The `org.page` view `summary` has an action `go` (view block payload limit).
|
|
30
|
+
*/
|
|
31
|
+
export default defineExtension({
|
|
32
|
+
name: "fake-client-page",
|
|
33
|
+
version: "0.1.0",
|
|
34
|
+
sdk: "^0.1.0-rc.0",
|
|
35
|
+
provides: [],
|
|
36
|
+
ui: [
|
|
37
|
+
{
|
|
38
|
+
id: "board",
|
|
39
|
+
title: t("看板", "Board"),
|
|
40
|
+
slot: "org.page",
|
|
41
|
+
kind: "component",
|
|
42
|
+
frame: "page",
|
|
43
|
+
nav: "primary",
|
|
44
|
+
},
|
|
45
|
+
{ id: "summary", title: t("概要", "Summary"), slot: "org.page", kind: "view" },
|
|
46
|
+
],
|
|
47
|
+
permissions: {
|
|
48
|
+
client: true,
|
|
49
|
+
ui: { components: ["board"], views: ["summary"] },
|
|
50
|
+
},
|
|
51
|
+
setup(ctx) {
|
|
52
|
+
ctx.ui.query("board", async (a) => {
|
|
53
|
+
switch (a.query) {
|
|
54
|
+
case "items":
|
|
55
|
+
return {
|
|
56
|
+
items: items(),
|
|
57
|
+
params: a.params,
|
|
58
|
+
caller: {
|
|
59
|
+
orgId: a.orgId,
|
|
60
|
+
accountId: a.accountId,
|
|
61
|
+
role: a.role,
|
|
62
|
+
slot: a.slot,
|
|
63
|
+
locale: a.locale,
|
|
64
|
+
},
|
|
65
|
+
} as JsonValue;
|
|
66
|
+
case "slow":
|
|
67
|
+
return new Promise<JsonValue>((_, reject) => {
|
|
68
|
+
a.signal.addEventListener("abort", () => {
|
|
69
|
+
fakeClientPageProbe().aborted += 1;
|
|
70
|
+
reject(a.signal.reason);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
case "boom":
|
|
74
|
+
throw new Error("fake-client-page: boom");
|
|
75
|
+
case "huge":
|
|
76
|
+
return { blob: "x".repeat(UI_LIMITS.componentQueryBytes) };
|
|
77
|
+
default:
|
|
78
|
+
throw new Error(`fake-client-page: unknown query ${a.query}`);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
ctx.ui.action("board", async (a) => {
|
|
82
|
+
if (a.actionId !== "move") throw new Error(`fake-client-page: unknown action ${a.actionId}`);
|
|
83
|
+
if (a.scope !== "platform") {
|
|
84
|
+
await ctx.ui.invalidate({ orgId: a.orgId, contribution: "board" }).catch(() => {});
|
|
85
|
+
}
|
|
86
|
+
const bytes = Buffer.byteLength(JSON.stringify(a.payload ?? null), "utf8");
|
|
87
|
+
return { toast: t(`已移动 ${bytes}`, `moved ${bytes}`), invalidate: ["items"] };
|
|
88
|
+
});
|
|
89
|
+
ctx.ui.view("summary", async () => ({ blocks: [{ type: "text", markdown: "summary" }] }));
|
|
90
|
+
ctx.ui.action("summary", async () => ({ toast: t("好", "ok") }));
|
|
91
|
+
},
|
|
92
|
+
});
|
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.48",
|
|
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.107"
|
|
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-sdk": "^0.1.0-rc.86",
|
|
56
|
+
"@capybara-hq/plugin-client": "^0.1.0-rc.10"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"vitest": "^5.0.5",
|
|
60
|
-
"@capybara-hq/plugin-
|
|
61
|
-
"@capybara-hq/plugin-
|
|
60
|
+
"@capybara-hq/plugin-tools": "^0.1.0-rc.27",
|
|
61
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.86"
|
|
62
62
|
},
|
|
63
63
|
"peerDependenciesMeta": {
|
|
64
64
|
"@capybara-hq/plugin-tools": {
|