@capybara-hq/testing 0.1.0-rc.13 → 0.1.0-rc.15
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 +4 -2
- package/dist/fixtures.js +5 -1
- 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-im/src/channel.ts +3 -1
- package/fixtures/plugins/fake-theme/themes/{night-city.json → neon-grid.json} +2 -2
- package/package.json +6 -5
package/dist/fixtures.d.ts
CHANGED
|
@@ -18,16 +18,18 @@
|
|
|
18
18
|
* | `fake-dep-provider` / `fake-dep-requirer` | a dependency pair on `counter@1` (the requirer's plugin.json depends on the provider) |
|
|
19
19
|
* | `fake-im` | a whole IM platform for `startFakeChannelServer`: `channel@1` (cards, edits, threads, webhook inbound), `identity-source@1`, `directory@1` (org config `url` of a directory book) and tool `post_announcement` (default policy ask, posts to the platform); deployment config `platformUrl`, `tenant`, `clientId`, secret `clientSecret`. Its `src/index.ts` also exports `makeFakeImChannel`, `fakeImIdentitySource`, `fakeImDirectory` for test extensions that need one part |
|
|
20
20
|
* | `fake-web` / `fake-web-2` | `web-search@1` and `web-fetch@1`, scripted by a prefix of the query or of the fetched URL's path (`error:<kind>`, `throw:`, `hang:`, `redirect:<url>`, `junk:`, `empty:`, `big:<n>`; see `makeFakeWeb`); results name the provider; org config secret `token`, `configured()` iff it is set (throws for `throw:configured`); calls recorded on `globalThis.__fakeWeb` (`fakeWebProbe`) |
|
|
21
|
+
* | `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` |
|
|
22
|
+
* | `fake-client-broken` | client code that throws: component `boom` (render), a `run.started` events listener, and a `conversation.empty` replacement (render) |
|
|
21
23
|
* | `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 |
|
|
22
24
|
*/
|
|
23
|
-
export declare const FAKE_EXTENSIONS: readonly ["fake-connector", "fake-openapi", "fake-object-store", "fake-tools-ui", "fake-storage-user", "fake-embed", "fake-bootstrap-a", "fake-bootstrap-b", "fake-dep-provider", "fake-dep-requirer", "fake-im", "fake-web", "fake-web-2", "fake-config-form"];
|
|
25
|
+
export declare const FAKE_EXTENSIONS: readonly ["fake-connector", "fake-openapi", "fake-object-store", "fake-tools-ui", "fake-storage-user", "fake-embed", "fake-bootstrap-a", "fake-bootstrap-b", "fake-dep-provider", "fake-dep-requirer", "fake-im", "fake-web", "fake-web-2", "fake-config-form", "fake-client", "fake-client-broken"];
|
|
24
26
|
/**
|
|
25
27
|
* Fake plugins without an extension (declarative: they live in `fixtures/plugins/<name>`, same
|
|
26
28
|
* pack layout).
|
|
27
29
|
*
|
|
28
30
|
* | name | provides / covers |
|
|
29
31
|
* |---|---|
|
|
30
|
-
* | `fake-theme` | themes `
|
|
32
|
+
* | `fake-theme` | themes `neon-grid` (dark only, wordmark, font `FakeSans`, logo) and `paper` (light and dark); passes `capybara-plugin check` |
|
|
31
33
|
*/
|
|
32
34
|
export declare const FAKE_PLUGINS: readonly ["fake-theme"];
|
|
33
35
|
/** The name of a fake plugin. */
|
package/dist/fixtures.js
CHANGED
|
@@ -21,6 +21,8 @@ import { fileURLToPath } from "node:url";
|
|
|
21
21
|
* | `fake-dep-provider` / `fake-dep-requirer` | a dependency pair on `counter@1` (the requirer's plugin.json depends on the provider) |
|
|
22
22
|
* | `fake-im` | a whole IM platform for `startFakeChannelServer`: `channel@1` (cards, edits, threads, webhook inbound), `identity-source@1`, `directory@1` (org config `url` of a directory book) and tool `post_announcement` (default policy ask, posts to the platform); deployment config `platformUrl`, `tenant`, `clientId`, secret `clientSecret`. Its `src/index.ts` also exports `makeFakeImChannel`, `fakeImIdentitySource`, `fakeImDirectory` for test extensions that need one part |
|
|
23
23
|
* | `fake-web` / `fake-web-2` | `web-search@1` and `web-fetch@1`, scripted by a prefix of the query or of the fetched URL's path (`error:<kind>`, `throw:`, `hang:`, `redirect:<url>`, `junk:`, `empty:`, `big:<n>`; see `makeFakeWeb`); results name the provider; org config secret `token`, `configured()` iff it is set (throws for `throw:configured`); calls recorded on `globalThis.__fakeWeb` (`fakeWebProbe`) |
|
|
24
|
+
* | `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` |
|
|
25
|
+
* | `fake-client-broken` | client code that throws: component `boom` (render), a `run.started` events listener, and a `conversation.empty` replacement (render) |
|
|
24
26
|
* | `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 |
|
|
25
27
|
*/
|
|
26
28
|
export const FAKE_EXTENSIONS = [
|
|
@@ -38,6 +40,8 @@ export const FAKE_EXTENSIONS = [
|
|
|
38
40
|
"fake-web",
|
|
39
41
|
"fake-web-2",
|
|
40
42
|
"fake-config-form",
|
|
43
|
+
"fake-client",
|
|
44
|
+
"fake-client-broken",
|
|
41
45
|
];
|
|
42
46
|
/**
|
|
43
47
|
* Fake plugins without an extension (declarative: they live in `fixtures/plugins/<name>`, same
|
|
@@ -45,7 +49,7 @@ export const FAKE_EXTENSIONS = [
|
|
|
45
49
|
*
|
|
46
50
|
* | name | provides / covers |
|
|
47
51
|
* |---|---|
|
|
48
|
-
* | `fake-theme` | themes `
|
|
52
|
+
* | `fake-theme` | themes `neon-grid` (dark only, wordmark, font `FakeSans`, logo) and `paper` (light and dark); passes `capybara-plugin check` |
|
|
49
53
|
*/
|
|
50
54
|
export const FAKE_PLUGINS = ["fake-theme"];
|
|
51
55
|
/** `fixtures/extensions/` of this package (same path from `src/` and from `dist/`). */
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineClientExtension, defineComponent } from "@capybara-hq/plugin-client";
|
|
2
|
+
|
|
3
|
+
const Boom = (): never => {
|
|
4
|
+
throw new Error("fake-client-broken: boom");
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const Empty = (): never => {
|
|
8
|
+
throw new Error("fake-client-broken: empty");
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default defineClientExtension({
|
|
12
|
+
name: "fake-client-broken",
|
|
13
|
+
components: {
|
|
14
|
+
boom: defineComponent("conversation.properties.section", Boom),
|
|
15
|
+
empty: defineComponent("conversation.empty", Empty),
|
|
16
|
+
},
|
|
17
|
+
events: {
|
|
18
|
+
"run.started": () => {
|
|
19
|
+
throw new Error("fake-client-broken: run.started");
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineExtension } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
|
|
3
|
+
const t = (zh: string, en: string) => ({ zh, en });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Test fake of a client extension whose browser code is broken, for the host's isolation (error
|
|
7
|
+
* boundaries, the crash budget, safe mode): component `boom` (`conversation.properties.section`)
|
|
8
|
+
* throws on render, the module-level `events` listener throws on `run.started`, and `empty`
|
|
9
|
+
* (`conversation.empty`) throws on render. No server side beyond the declarations.
|
|
10
|
+
*/
|
|
11
|
+
export default defineExtension({
|
|
12
|
+
name: "fake-client-broken",
|
|
13
|
+
version: "0.1.0",
|
|
14
|
+
sdk: "^0.1.0-rc.0",
|
|
15
|
+
provides: [],
|
|
16
|
+
ui: [
|
|
17
|
+
{
|
|
18
|
+
id: "boom",
|
|
19
|
+
title: t("崩溃", "Boom"),
|
|
20
|
+
slot: "conversation.properties.section",
|
|
21
|
+
kind: "component",
|
|
22
|
+
},
|
|
23
|
+
{ id: "empty", title: t("问候", "Greeting"), slot: "conversation.empty", kind: "component" },
|
|
24
|
+
],
|
|
25
|
+
permissions: { client: true, ui: { components: ["boom", "empty"] } },
|
|
26
|
+
setup() {},
|
|
27
|
+
});
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
type ChannelWebhook,
|
|
7
7
|
type InboundEvent,
|
|
8
8
|
secret,
|
|
9
|
+
ui,
|
|
9
10
|
} from "@capybara-hq/plugin-sdk";
|
|
10
11
|
import { z } from "zod";
|
|
11
12
|
|
|
@@ -26,8 +27,9 @@ export const FakeImConnection = z.object({
|
|
|
26
27
|
/**
|
|
27
28
|
* Optional secret (also tests PATCH secret semantics); the webhook signing secret: webhook
|
|
28
29
|
* requests are signed `x-fake-signature: sha256=<hex HMAC-SHA256(webhookToken, raw body)>`.
|
|
30
|
+
* Drawn and required in webhook mode only (`inboundModes`, channel inbound mode fields spec §2).
|
|
29
31
|
*/
|
|
30
|
-
webhookToken: secret(z.string().min(1).optional()),
|
|
32
|
+
webhookToken: ui(secret(z.string().min(1).optional()), { inboundModes: ["webhook"] }),
|
|
31
33
|
/** 被中止后拖这么久才返回(模拟不及时退出的插件)。 */
|
|
32
34
|
lingerMs: z.number().int().nonnegative().default(0),
|
|
33
35
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": { "en": "
|
|
2
|
+
"name": { "en": "Neon Grid", "zh": "霓虹网格" },
|
|
3
3
|
"schemes": {
|
|
4
4
|
"dark": {
|
|
5
5
|
"color": { "bg": "#05070D", "panel": "#0A0E18", "accent": "#FCE300", "on-accent": "#141200" },
|
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
"fonts": [
|
|
10
10
|
{ "family": "FakeSans", "file": "./fonts/FakeSans.woff2", "weight": 400, "role": "prose" }
|
|
11
11
|
],
|
|
12
|
-
"logo": { "mark": "./logo.svg", "wordmark": "
|
|
12
|
+
"logo": { "mark": "./logo.svg", "wordmark": "NEON GRID" }
|
|
13
13
|
}
|
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.15",
|
|
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,17 +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.16"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/pg": "^8.23.1",
|
|
54
54
|
"@types/ws": "^8.18.2",
|
|
55
|
-
"@capybara-hq/plugin-
|
|
55
|
+
"@capybara-hq/plugin-client": "^0.1.0-rc.2",
|
|
56
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.12"
|
|
56
57
|
},
|
|
57
58
|
"peerDependencies": {
|
|
58
59
|
"vitest": "^5.0.5",
|
|
59
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
60
|
-
"@capybara-hq/plugin-tools": "^0.1.0-rc.
|
|
60
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.12",
|
|
61
|
+
"@capybara-hq/plugin-tools": "^0.1.0-rc.13"
|
|
61
62
|
},
|
|
62
63
|
"peerDependenciesMeta": {
|
|
63
64
|
"@capybara-hq/plugin-tools": {
|