@capybara-hq/testing 0.1.0-rc.45 → 0.1.0-rc.47
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/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/model-conformance.d.ts +13 -1
- package/dist/model-conformance.js +67 -10
- package/fixtures/extensions/fake-bootstrap-a/src/index.ts +0 -1
- package/fixtures/extensions/fake-trigger-source/.capybara-plugin/plugin.json +7 -0
- package/fixtures/extensions/fake-trigger-source/package.json +11 -0
- package/fixtures/extensions/fake-trigger-source/src/index.ts +114 -0
- package/package.json +5 -5
package/dist/fixtures.d.ts
CHANGED
|
@@ -24,9 +24,10 @@
|
|
|
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
25
|
* | `fake-client-broken` | client code that throws: component `boom` (render), a `run.started` events listener, and a `conversation.empty` replacement (render) |
|
|
26
26
|
* | `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
|
+
* | `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` |
|
|
27
28
|
* | `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 |
|
|
28
29
|
*/
|
|
29
|
-
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"];
|
|
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"];
|
|
30
31
|
/**
|
|
31
32
|
* Fake plugins without an extension (declarative: they live in `fixtures/plugins/<name>`, same
|
|
32
33
|
* pack layout).
|
package/dist/fixtures.js
CHANGED
|
@@ -27,6 +27,7 @@ import { fileURLToPath } from "node:url";
|
|
|
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
28
|
* | `fake-client-broken` | client code that throws: component `boom` (render), a `run.started` events listener, and a `conversation.empty` replacement (render) |
|
|
29
29
|
* | `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
|
+
* | `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` |
|
|
30
31
|
* | `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 |
|
|
31
32
|
*/
|
|
32
33
|
export const FAKE_EXTENSIONS = [
|
|
@@ -50,6 +51,7 @@ export const FAKE_EXTENSIONS = [
|
|
|
50
51
|
"fake-client",
|
|
51
52
|
"fake-client-broken",
|
|
52
53
|
"fake-watch",
|
|
54
|
+
"fake-trigger-source",
|
|
53
55
|
];
|
|
54
56
|
/**
|
|
55
57
|
* Fake plugins without an extension (declarative: they live in `fixtures/plugins/<name>`, same
|
package/dist/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export { FAKE_EXTENSIONS, type FakeExtensionName, fakeExtensionDir, fakeExtensio
|
|
|
25
25
|
export { cardRecorded, cookieRequest, createAgent, createConversation, createLocalAccount, createOrg, enableModelProviders, eventsOf, joinOrg, type KernelApp, type KernelRequest, type KernelRequestOptions, type KernelResponse, login, pidOwningLocalPort, postMessage, sleep, startTestKernel, TEST_PASSWORD, type TestKernel, testKernelConfig, truncateTables, waitFor, waitForEvent, waitForTerminal, } from "./kernel-helpers.js";
|
|
26
26
|
export { type LoginSourceSeed, seedLoginSources } from "./login-sources.js";
|
|
27
27
|
export { FAKE_PNG_BASE64, isPngBase64, pdfBase64, pdfSampleWord, redPngBase64, solidPngBase64, } from "./media-samples.js";
|
|
28
|
-
export { type ConformanceTarget, checkDeclaredParameters, checkToolStream, describeModelProviderConformance, MEDIA_SAMPLES, thinkingReplayParams, } from "./model-conformance.js";
|
|
28
|
+
export { type ConformanceTarget, checkCacheDeclaration, checkCacheWriteTiers, checkDeclaredParameters, checkToolStream, describeModelProviderConformance, MEDIA_SAMPLES, thinkingReplayParams, } from "./model-conformance.js";
|
|
29
29
|
export { describePushProviderConformance, type PushConformanceTarget, type PushOutcome, type PushVendorRequest, } from "./push-conformance.js";
|
|
30
30
|
export { type NativeFixtureEntry, runSandboxNativeConformance, type SandboxNativeFixture, } from "./sandbox-native-conformance.js";
|
|
31
31
|
export { runSandboxPermissionConformance, type SandboxPermissionConformancePart, type SandboxPermissionEndpoint, type SandboxPermissionFixture, type SandboxPermissionGrant, type SandboxPermissionOpenNetwork, type SandboxPermissionTarget, } from "./sandbox-permission-conformance.js";
|
package/dist/index.js
CHANGED
|
@@ -25,7 +25,7 @@ export { FAKE_EXTENSIONS, fakeExtensionDir, fakeExtensionEntry, packFixture, } f
|
|
|
25
25
|
export { cardRecorded, cookieRequest, createAgent, createConversation, createLocalAccount, createOrg, enableModelProviders, eventsOf, joinOrg, login, pidOwningLocalPort, postMessage, sleep, startTestKernel, TEST_PASSWORD, testKernelConfig, truncateTables, waitFor, waitForEvent, waitForTerminal, } from "./kernel-helpers.js";
|
|
26
26
|
export { seedLoginSources } from "./login-sources.js";
|
|
27
27
|
export { FAKE_PNG_BASE64, isPngBase64, pdfBase64, pdfSampleWord, redPngBase64, solidPngBase64, } from "./media-samples.js";
|
|
28
|
-
export { checkDeclaredParameters, checkToolStream, describeModelProviderConformance, MEDIA_SAMPLES, thinkingReplayParams, } from "./model-conformance.js";
|
|
28
|
+
export { checkCacheDeclaration, checkCacheWriteTiers, checkDeclaredParameters, checkToolStream, describeModelProviderConformance, MEDIA_SAMPLES, thinkingReplayParams, } from "./model-conformance.js";
|
|
29
29
|
export { describePushProviderConformance, } from "./push-conformance.js";
|
|
30
30
|
export { runSandboxNativeConformance, } from "./sandbox-native-conformance.js";
|
|
31
31
|
export { runSandboxPermissionConformance, } from "./sandbox-permission-conformance.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ModelInfo, type ModelParameter, type ModelProvider, type ModelStreamEvent, type ParamValue } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import { type ModelInfo, type ModelParameter, type ModelProvider, type ModelStreamEvent, type ModelUsage, type ParamValue } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
interface TargetCommon {
|
|
3
3
|
model: string;
|
|
4
4
|
expect: {
|
|
@@ -26,6 +26,18 @@ export type ConformanceTarget = TargetCommon & {
|
|
|
26
26
|
plugin: string;
|
|
27
27
|
provider: ModelProvider;
|
|
28
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* Checks a model's cache declaration with the SDK's `validateModelCache` (null when valid or
|
|
31
|
+
* absent). `info` is undefined when the provider does not list the model. With `expectCaching`
|
|
32
|
+
* (the target's `expect.caching`), a model that declares no cache or `mechanism: "none"` is also
|
|
33
|
+
* a problem.
|
|
34
|
+
*/
|
|
35
|
+
export declare function checkCacheDeclaration(info: ModelInfo | undefined, expectCaching?: boolean): string | null;
|
|
36
|
+
/**
|
|
37
|
+
* Checks the write tiers of a call made with `cacheTtl`: when `usage.cacheWriteByTtl` is present
|
|
38
|
+
* it may hold only that ttl. Returns the problem, or `null` (also when no tiers are reported).
|
|
39
|
+
*/
|
|
40
|
+
export declare function checkCacheWriteTiers(usage: ModelUsage, cacheTtl: number): string | null;
|
|
29
41
|
/**
|
|
30
42
|
* Checks a stream's tool events against its final message: every delta follows its call's start,
|
|
31
43
|
* each call starts once, and the deltas of each started call join to JSON whose parsed value
|
|
@@ -1,7 +1,35 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
1
2
|
import { isDeepStrictEqual } from "node:util";
|
|
2
|
-
import { assertValidDeclarations, EFFORT_VALUES, isModelError, isValidImageGenerationInfo, sanitizeParams, validateEmbedResult, validateImageGenerateResult, validateParams, } from "@capybara-hq/plugin-sdk";
|
|
3
|
+
import { assertValidDeclarations, EFFORT_VALUES, isModelError, isValidImageGenerationInfo, sanitizeParams, validateCacheWriteByTtl, validateEmbedResult, validateImageGenerateResult, validateModelCache, validateParams, } from "@capybara-hq/plugin-sdk";
|
|
3
4
|
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
4
5
|
import { pdfBase64, redPngBase64 } from "./media-samples.js";
|
|
6
|
+
/**
|
|
7
|
+
* Checks a model's cache declaration with the SDK's `validateModelCache` (null when valid or
|
|
8
|
+
* absent). `info` is undefined when the provider does not list the model. With `expectCaching`
|
|
9
|
+
* (the target's `expect.caching`), a model that declares no cache or `mechanism: "none"` is also
|
|
10
|
+
* a problem.
|
|
11
|
+
*/
|
|
12
|
+
export function checkCacheDeclaration(info, expectCaching = false) {
|
|
13
|
+
if (info === undefined)
|
|
14
|
+
return "model is not listed";
|
|
15
|
+
const problem = validateModelCache(info.cache);
|
|
16
|
+
if (problem !== null)
|
|
17
|
+
return problem;
|
|
18
|
+
if (expectCaching && (info.cache === undefined || info.cache.mechanism === "none")) {
|
|
19
|
+
return 'expect.caching is true but the model declares no prompt cache (cache absent or mechanism "none")';
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Checks the write tiers of a call made with `cacheTtl`: when `usage.cacheWriteByTtl` is present
|
|
25
|
+
* it may hold only that ttl. Returns the problem, or `null` (also when no tiers are reported).
|
|
26
|
+
*/
|
|
27
|
+
export function checkCacheWriteTiers(usage, cacheTtl) {
|
|
28
|
+
const other = (usage.cacheWriteByTtl ?? []).find((tier) => tier.ttl !== cacheTtl);
|
|
29
|
+
if (other === undefined)
|
|
30
|
+
return null;
|
|
31
|
+
return `cacheWriteByTtl reports ttl ${other.ttl} for a request with cacheTtl ${cacheTtl}`;
|
|
32
|
+
}
|
|
5
33
|
function streamOf(t, req, signal) {
|
|
6
34
|
const { params, ...rest } = req;
|
|
7
35
|
return t.provider.stream({ ...rest, params: params ?? {} }, { signal });
|
|
@@ -197,7 +225,8 @@ export function describeModelProviderConformance(name, setup) {
|
|
|
197
225
|
it("thinking replay", async (ctx) => {
|
|
198
226
|
if (!t.expect.thinking)
|
|
199
227
|
return ctx.skip();
|
|
200
|
-
//
|
|
228
|
+
// at the top effort tier reasoning tokens count toward the output limit too: 1024 is not
|
|
229
|
+
// enough (gpt-5-nano hits max_tokens on the second turn), so raise it
|
|
201
230
|
const over = { ...(await thinkingOver()), maxOutputTokens: 8192 };
|
|
202
231
|
const first = base({
|
|
203
232
|
...over,
|
|
@@ -215,27 +244,55 @@ export function describeModelProviderConformance(name, setup) {
|
|
|
215
244
|
}));
|
|
216
245
|
expect(second.done.stopReason).toBe("end_turn");
|
|
217
246
|
});
|
|
247
|
+
/**
|
|
248
|
+
* The caching cases' request: a long stable system prefix marked for caching; a `tag` makes
|
|
249
|
+
* the prefix distinct from every other request's.
|
|
250
|
+
*/
|
|
251
|
+
const cachingRequest = (over = {}, tag = "") => base({
|
|
252
|
+
system: [
|
|
253
|
+
{
|
|
254
|
+
text: `Stable prefix${tag}. ${"Reference material. ".repeat(Math.ceil((t.cachePrefixTokens ?? 5000) / 4))}`,
|
|
255
|
+
cache: true,
|
|
256
|
+
},
|
|
257
|
+
],
|
|
258
|
+
...over,
|
|
259
|
+
});
|
|
260
|
+
it("declares a valid cache", async () => {
|
|
261
|
+
const info = (await t.provider.listModels()).find((m) => m.id === t.model);
|
|
262
|
+
expect(checkCacheDeclaration(info, t.expect.caching)).toBeNull();
|
|
263
|
+
});
|
|
218
264
|
it("caching", async (ctx) => {
|
|
219
265
|
if (!t.expect.caching)
|
|
220
266
|
return ctx.skip();
|
|
221
|
-
const req =
|
|
222
|
-
system: [
|
|
223
|
-
{
|
|
224
|
-
text: `Stable prefix. ${"Reference material. ".repeat(Math.ceil((t.cachePrefixTokens ?? 5000) / 4))}`,
|
|
225
|
-
cache: true,
|
|
226
|
-
},
|
|
227
|
-
],
|
|
228
|
-
});
|
|
267
|
+
const req = cachingRequest();
|
|
229
268
|
await collect(t, req);
|
|
230
269
|
const second = await collect(t, req);
|
|
231
270
|
expect(second.done.usage.cacheReadTokens).toBeGreaterThan(0);
|
|
232
271
|
});
|
|
272
|
+
it("cache ttl options", async (ctx) => {
|
|
273
|
+
const info = (await t.provider.listModels()).find((m) => m.id === t.model);
|
|
274
|
+
const options = info?.cache?.ttlOptions ?? [];
|
|
275
|
+
if (options.length === 0)
|
|
276
|
+
return ctx.skip();
|
|
277
|
+
// each option gets its own prefix (the ttl plus a nonce), so each request writes rather
|
|
278
|
+
// than reading an entry an earlier request left; a plugin that drops cacheTtl then reports
|
|
279
|
+
// the wrong tier
|
|
280
|
+
const nonce = randomUUID();
|
|
281
|
+
for (const cacheTtl of options) {
|
|
282
|
+
const req = cachingRequest({ cacheTtl }, ` (ttl ${cacheTtl}, ${nonce})`);
|
|
283
|
+
const { done } = await collect(t, req);
|
|
284
|
+
expect(done.stopReason).toBe("end_turn");
|
|
285
|
+
expect(validateCacheWriteByTtl(done.usage)).toBeNull();
|
|
286
|
+
expect(checkCacheWriteTiers(done.usage, cacheTtl)).toBeNull();
|
|
287
|
+
}
|
|
288
|
+
});
|
|
233
289
|
it("usage", async () => {
|
|
234
290
|
const { done } = await collect(t, base());
|
|
235
291
|
// inputTokens 只是未缓存部分:缓存命中时可能为 0,所以看三类输入之和
|
|
236
292
|
const u = done.usage;
|
|
237
293
|
expect(u.inputTokens + u.cacheReadTokens + u.cacheWriteTokens).toBeGreaterThan(0);
|
|
238
294
|
expect(u.outputTokens).toBeGreaterThan(0);
|
|
295
|
+
expect(validateCacheWriteByTtl(u)).toBeNull();
|
|
239
296
|
});
|
|
240
297
|
it("mid-conversation system", async () => {
|
|
241
298
|
const { done } = await collect(t, base({
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capybara-hq/test-plugin-fake-trigger-source",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Test fake: a trigger source (trigger-source@1) whose tool emits item events through ctx.triggers",
|
|
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,114 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineExtension,
|
|
3
|
+
type ToolSpec,
|
|
4
|
+
TriggerError,
|
|
5
|
+
type TriggerEvent,
|
|
6
|
+
type TriggerEventDeclaration,
|
|
7
|
+
type TriggerSource,
|
|
8
|
+
} from "@capybara-hq/plugin-sdk";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Test fake of a `trigger-source@1` provider (collaboration spec §4.2, §4.3). It declares the
|
|
12
|
+
* event types `item.created`, `item.updated` and `item.assigned` (directed) in
|
|
13
|
+
* `permissions.triggers.emit`, each with the filterable facts `status` (string), `priority`
|
|
14
|
+
* (number), `labels` (string[]) and `projectKey` (string), and the unfilterable fact `internalNote`.
|
|
15
|
+
* - The tool `emit_item_event` emits its input as the event through `ctx.triggers.emit`, with the
|
|
16
|
+
* call's org (unless the input names another `orgId`) and `cause: { call }`; it returns
|
|
17
|
+
* `{ eventId, duplicate }` as JSON, or `{ error: <TriggerError code> }` for a refused emit.
|
|
18
|
+
* - `visible()` admits the accounts listed in `globalThis.__fakeTriggerSource.visible`, or every
|
|
19
|
+
* account when that is unset.
|
|
20
|
+
* - Its setup puts `emit` (the extension's own `ctx.triggers.emit`) on the probe
|
|
21
|
+
* ({@link fakeTriggerSourceProbe}; in-process kernels only), so a test can emit as the extension
|
|
22
|
+
* outside a tool call.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
// capybara:allow-module-state a read-only constant list
|
|
26
|
+
export const FAKE_TRIGGER_TYPES = ["item.created", "item.updated", "item.assigned"] as const;
|
|
27
|
+
|
|
28
|
+
/** The probe tests read and script. */
|
|
29
|
+
export interface FakeTriggerSourceProbe {
|
|
30
|
+
/** The accounts `visible()` admits; undefined admits every account. */
|
|
31
|
+
visible?: string[];
|
|
32
|
+
/** The extension's `ctx.triggers.emit`, set by its setup. */
|
|
33
|
+
emit?: (event: TriggerEvent) => Promise<{ eventId: string; duplicate: boolean }>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function fakeTriggerSourceProbe(): FakeTriggerSourceProbe {
|
|
37
|
+
const g = globalThis as { __fakeTriggerSource?: FakeTriggerSourceProbe };
|
|
38
|
+
g.__fakeTriggerSource ??= {};
|
|
39
|
+
return g.__fakeTriggerSource;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const FACTS: TriggerEventDeclaration["facts"] = {
|
|
43
|
+
status: { type: "string", name: { zh: "状态", en: "Status" }, filterable: true },
|
|
44
|
+
priority: { type: "number", name: { zh: "优先级", en: "Priority" }, filterable: true },
|
|
45
|
+
labels: { type: "string[]", name: { zh: "标签", en: "Labels" }, filterable: true },
|
|
46
|
+
projectKey: { type: "string", name: { zh: "项目", en: "Project" }, filterable: true },
|
|
47
|
+
// declared but not filterable: an automation's filter may not name it
|
|
48
|
+
internalNote: {
|
|
49
|
+
type: "string",
|
|
50
|
+
name: { zh: "内部备注", en: "Internal note" },
|
|
51
|
+
filterable: false,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// capybara:allow-module-state a read-only constant list
|
|
56
|
+
const EVENTS: TriggerEventDeclaration[] = [
|
|
57
|
+
{
|
|
58
|
+
type: "item.created",
|
|
59
|
+
name: { zh: "条目已创建", en: "Item created" },
|
|
60
|
+
directed: false,
|
|
61
|
+
facts: FACTS,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: "item.updated",
|
|
65
|
+
name: { zh: "条目已更新", en: "Item updated" },
|
|
66
|
+
directed: false,
|
|
67
|
+
facts: FACTS,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
type: "item.assigned",
|
|
71
|
+
name: { zh: "条目已指派", en: "Item assigned" },
|
|
72
|
+
directed: true,
|
|
73
|
+
facts: FACTS,
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
const source: TriggerSource = {
|
|
78
|
+
events: () => EVENTS,
|
|
79
|
+
async visible({ accountIds }) {
|
|
80
|
+
const allowed = fakeTriggerSourceProbe().visible;
|
|
81
|
+
return allowed === undefined ? accountIds : accountIds.filter((a) => allowed.includes(a));
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const EMIT: ToolSpec = {
|
|
86
|
+
name: "emit_item_event",
|
|
87
|
+
description:
|
|
88
|
+
"Emit an item event (type, subject, facts, summary, dedupeKey, optional audience) caused by this call. Test fixture only.",
|
|
89
|
+
inputSchema: { type: "object", additionalProperties: true },
|
|
90
|
+
defaultPolicy: "allow",
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export default defineExtension({
|
|
94
|
+
name: "fake-trigger-source",
|
|
95
|
+
version: "0.1.0",
|
|
96
|
+
sdk: "^0.1.0-rc.0",
|
|
97
|
+
provides: ["trigger-source@1"],
|
|
98
|
+
permissions: { tools: ["emit_item_event"], triggers: { emit: [...FAKE_TRIGGER_TYPES] } },
|
|
99
|
+
setup(ctx) {
|
|
100
|
+
ctx.provide("trigger-source@1", source);
|
|
101
|
+
fakeTriggerSourceProbe().emit = (event) => ctx.triggers.emit(event);
|
|
102
|
+
ctx.tools.register(EMIT, async (input, call) => {
|
|
103
|
+
const event = { orgId: call.orgId, ...(input as object), cause: { call } } as TriggerEvent;
|
|
104
|
+
try {
|
|
105
|
+
const r = await ctx.triggers.emit(event);
|
|
106
|
+
return { content: [{ type: "text", text: JSON.stringify(r) }] };
|
|
107
|
+
} catch (err) {
|
|
108
|
+
if (err instanceof TriggerError)
|
|
109
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: err.code }) }] };
|
|
110
|
+
throw err;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
});
|
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.47",
|
|
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.106"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/pg": "^8.23.1",
|
|
54
54
|
"@types/ws": "^8.18.2",
|
|
55
55
|
"@capybara-hq/plugin-client": "^0.1.0-rc.9",
|
|
56
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
56
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.85"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"vitest": "^5.0.5",
|
|
60
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
61
|
-
"@capybara-hq/plugin-tools": "^0.1.0-rc.
|
|
60
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.85",
|
|
61
|
+
"@capybara-hq/plugin-tools": "^0.1.0-rc.26"
|
|
62
62
|
},
|
|
63
63
|
"peerDependenciesMeta": {
|
|
64
64
|
"@capybara-hq/plugin-tools": {
|