@capybara-hq/testing 0.1.0-rc.10 → 0.1.0-rc.12

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.
@@ -21,10 +21,21 @@
21
21
  * | `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
22
  */
23
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"];
24
+ /**
25
+ * Fake plugins without an extension (declarative: they live in `fixtures/plugins/<name>`, same
26
+ * pack layout).
27
+ *
28
+ * | name | provides / covers |
29
+ * |---|---|
30
+ * | `fake-theme` | themes `night-city` (dark only, wordmark, font `FakeSans`, logo) and `paper` (light and dark); passes `capybara-plugin check` |
31
+ */
32
+ export declare const FAKE_PLUGINS: readonly ["fake-theme"];
33
+ /** The name of a fake plugin. */
34
+ export type FakePluginName = (typeof FAKE_PLUGINS)[number];
24
35
  /** The name of a fake extension (also its plugin and extension name). */
25
36
  export type FakeExtensionName = (typeof FAKE_EXTENSIONS)[number];
26
37
  /** The plugin directory of a fake (pack layout), for `packFixture` or a packer of your own. */
27
- export declare function fakeExtensionDir(name: FakeExtensionName): string;
38
+ export declare function fakeExtensionDir(name: FakeExtensionName | FakePluginName): string;
28
39
  /**
29
40
  * The extension entry `src/index.ts` of a fake, for kernel configs that load extensions by path
30
41
  * (`extensions: [fakeExtensionEntry("fake-connector")]`). `createDualReplicaHarness` loads it in
@@ -48,4 +59,4 @@ export interface PackedFixture {
48
59
  * skills and templates), writes it to `outDir` and returns its path, bytes and sha256. Packing
49
60
  * leaves no files in the fixture directory.
50
61
  */
51
- export declare function packFixture(name: FakeExtensionName, outDir: string): Promise<PackedFixture>;
62
+ export declare function packFixture(name: FakeExtensionName | FakePluginName, outDir: string): Promise<PackedFixture>;
package/dist/fixtures.js CHANGED
@@ -39,11 +39,22 @@ export const FAKE_EXTENSIONS = [
39
39
  "fake-web-2",
40
40
  "fake-config-form",
41
41
  ];
42
+ /**
43
+ * Fake plugins without an extension (declarative: they live in `fixtures/plugins/<name>`, same
44
+ * pack layout).
45
+ *
46
+ * | name | provides / covers |
47
+ * |---|---|
48
+ * | `fake-theme` | themes `night-city` (dark only, wordmark, font `FakeSans`, logo) and `paper` (light and dark); passes `capybara-plugin check` |
49
+ */
50
+ export const FAKE_PLUGINS = ["fake-theme"];
42
51
  /** `fixtures/extensions/` of this package (same path from `src/` and from `dist/`). */
43
52
  const FIXTURES_DIR = fileURLToPath(new URL("../fixtures/extensions/", import.meta.url));
53
+ /** `fixtures/plugins/` of this package. */
54
+ const PLUGINS_DIR = fileURLToPath(new URL("../fixtures/plugins/", import.meta.url));
44
55
  /** The plugin directory of a fake (pack layout), for `packFixture` or a packer of your own. */
45
56
  export function fakeExtensionDir(name) {
46
- return join(FIXTURES_DIR, name);
57
+ return join(FAKE_PLUGINS.includes(name) ? PLUGINS_DIR : FIXTURES_DIR, name);
47
58
  }
48
59
  /**
49
60
  * The extension entry `src/index.ts` of a fake, for kernel configs that load extensions by path
@@ -89,8 +100,10 @@ async function packer() {
89
100
  * leaves no files in the fixture directory.
90
101
  */
91
102
  export async function packFixture(name, outDir) {
92
- if (!FAKE_EXTENSIONS.includes(name))
93
- throw new Error(`unknown fake extension ${String(name)}`);
103
+ const known = FAKE_EXTENSIONS.includes(name) ||
104
+ FAKE_PLUGINS.includes(name);
105
+ if (!known)
106
+ throw new Error(`unknown fake extension or plugin ${String(name)}`);
94
107
  const pack = await packer();
95
108
  const r = await pack(fakeExtensionDir(name), outDir);
96
109
  return { file: r.file, bytes: new Uint8Array(await readFile(r.file)), sha256: r.sha256 };
@@ -1,4 +1,4 @@
1
- import { defineExtension, EMBED_PROTOCOL, type EmbedClaims } from "@capybara-hq/plugin-sdk";
1
+ import { defineExtension, EMBED_PROTOCOL, type OrgEmbedClaims } from "@capybara-hq/plugin-sdk";
2
2
  import { z } from "zod";
3
3
 
4
4
  /**
@@ -96,14 +96,14 @@ export default defineExtension({
96
96
  {
97
97
  id: "panel",
98
98
  title: { zh: "面板", en: "Panel" },
99
- place: "page",
99
+ slot: "org.page",
100
100
  kind: "embed",
101
101
  path: "/ui/panel",
102
102
  },
103
103
  {
104
104
  id: "panel-conv",
105
105
  title: { zh: "面板", en: "Panel" },
106
- place: "conversation",
106
+ slot: "conversation.panel",
107
107
  kind: "embed",
108
108
  path: "/ui/panel-conv",
109
109
  },
@@ -120,9 +120,11 @@ export default defineExtension({
120
120
  ui: { embeds: ["panel", "panel-conv"] },
121
121
  },
122
122
  setup(ctx) {
123
- const auth = async (req: Request): Promise<EmbedClaims | null> => {
123
+ /** An org-scope token's claims (every contribution here is in an org slot), or null. */
124
+ const auth = async (req: Request): Promise<OrgEmbedClaims | null> => {
124
125
  const m = BEARER_RE.exec(req.headers.get("authorization") ?? "");
125
- return m?.[1] === undefined ? null : ctx.ui.verifyEmbedToken(m[1]);
126
+ const claims = m?.[1] === undefined ? null : await ctx.ui.verifyEmbedToken(m[1]);
127
+ return claims?.scope === "org" ? claims : null;
126
128
  };
127
129
  const page = async () =>
128
130
  new Response(PAGE, { headers: { "content-type": "text/html; charset=utf-8" } });
@@ -104,8 +104,31 @@ export default defineExtension({
104
104
  sdk: "^0.1.0-rc.0",
105
105
  provides: [],
106
106
  migrations: "../migrations",
107
- ui: [{ id: "tasks", title: { zh: "条目", en: "Items" }, place: "conversation", kind: "view" }],
108
- permissions: { tools: ["write"], ui: { views: ["tasks"] } },
107
+ ui: [
108
+ { id: "tasks", title: { zh: "条目", en: "Items" }, slot: "conversation.panel", kind: "view" },
109
+ {
110
+ id: "agent-notes",
111
+ title: { zh: "智能体备注", en: "Agent notes" },
112
+ slot: "agent.detail.section",
113
+ kind: "view",
114
+ },
115
+ {
116
+ id: "org-admin",
117
+ title: { zh: "组织设置扩展", en: "Org admin" },
118
+ slot: "org.settings.section",
119
+ kind: "view",
120
+ },
121
+ {
122
+ id: "platform-home",
123
+ title: { zh: "平台首页", en: "Platform home" },
124
+ slot: "platform.page",
125
+ kind: "view",
126
+ },
127
+ ],
128
+ permissions: {
129
+ tools: ["write"],
130
+ ui: { views: ["tasks", "agent-notes", "org-admin", "platform-home"] },
131
+ },
109
132
  setup(ctx) {
110
133
  ctx.tools.register(WRITE, async (input, tctx) => {
111
134
  const parsed = WriteInput.safeParse(input);
@@ -136,5 +159,21 @@ export default defineExtension({
136
159
  ctx.ui.view("tasks", async ({ conversationId }) =>
137
160
  tasksView(conversationId === undefined ? [] : await readItems(ctx.db, conversationId)),
138
161
  );
162
+ const ping: UiView["blocks"] = [
163
+ { type: "actions", buttons: [{ actionId: "ping", label: "Ping" }] },
164
+ ];
165
+ const done = async () => ({ toast: { zh: "已完成", en: "Done" } });
166
+ ctx.ui.view("agent-notes", async (args) => ({
167
+ blocks: [{ type: "heading", text: `Agent ${args.agentId ?? ""}`.trim() }, ...ping],
168
+ }));
169
+ ctx.ui.action("agent-notes", done);
170
+ ctx.ui.view("org-admin", async () => ({
171
+ blocks: [{ type: "heading", text: "Org settings" }, ...ping],
172
+ }));
173
+ ctx.ui.action("org-admin", done);
174
+ ctx.ui.view("platform-home", async () => ({
175
+ blocks: [{ type: "heading", text: "Platform home" }, ...ping],
176
+ }));
177
+ ctx.ui.action("platform-home", done);
139
178
  },
140
179
  });
@@ -0,0 +1,7 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "name": "fake-theme",
4
+ "version": "0.1.0",
5
+ "publisher": "Capybara",
6
+ "description": "Fixture: a declarative plugin with two themes and no extension"
7
+ }
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><title>Fake theme</title><path d="M0 0h10v10z" fill="#FCE300"/></svg>
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@capybara-hq/plugin-fake-theme",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "description": "Fixture: a declarative plugin with two themes and no extension",
6
+ "license": "Apache-2.0",
7
+ "type": "module"
8
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": { "en": "Night City", "zh": "夜之城" },
3
+ "schemes": {
4
+ "dark": {
5
+ "color": { "bg": "#05070D", "panel": "#0A0E18", "accent": "#FCE300", "on-accent": "#141200" },
6
+ "radius": { "sm": 0, "md": 2 }
7
+ }
8
+ },
9
+ "fonts": [
10
+ { "family": "FakeSans", "file": "./fonts/FakeSans.woff2", "weight": 400, "role": "prose" }
11
+ ],
12
+ "logo": { "mark": "./logo.svg", "wordmark": "NIGHT CITY" }
13
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": { "en": "Paper", "zh": "纸张" },
3
+ "schemes": {
4
+ "light": {
5
+ "color": { "accent": "#8A3B12", "on-accent": "#FFFFFF" },
6
+ "radius": { "md": 6 }
7
+ },
8
+ "dark": {
9
+ "color": { "accent": "#E0A070", "on-accent": "#1B1915" }
10
+ }
11
+ }
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/testing",
3
- "version": "0.1.0-rc.10",
3
+ "version": "0.1.0-rc.12",
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,17 @@
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.10"
50
+ "@capybara-hq/kernel": "^0.1.0-rc.13"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/pg": "^8.23.1",
54
54
  "@types/ws": "^8.18.2",
55
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.7"
55
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.9"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "vitest": "^5.0.5",
59
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.7",
60
- "@capybara-hq/plugin-tools": "^0.1.0-rc.8"
59
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.9",
60
+ "@capybara-hq/plugin-tools": "^0.1.0-rc.10"
61
61
  },
62
62
  "peerDependenciesMeta": {
63
63
  "@capybara-hq/plugin-tools": {