@capybara-hq/testing 0.1.0-rc.14 → 0.1.0-rc.16
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/dual-replica.d.ts +7 -1
- package/dist/dual-replica.js +48 -0
- package/dist/fixtures.d.ts +1 -1
- package/dist/fixtures.js +1 -1
- package/dist/kernel-helpers.d.ts +3 -1
- package/dist/kernel-helpers.js +3 -1
- 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 -6
package/dist/dual-replica.d.ts
CHANGED
|
@@ -108,7 +108,13 @@ export interface Harness {
|
|
|
108
108
|
* 另一个副本照常工作。已退出时是空操作。
|
|
109
109
|
*/
|
|
110
110
|
kill(index: number): Promise<void>;
|
|
111
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* 停两个副本(15s 后 SIGKILL)、删临时库、关自有容器;幂等。Before the replicas stop it asserts
|
|
113
|
+
* that they left no queued run without its job (neither in the outbox nor in BullMQ: the "queue
|
|
114
|
+
* lost jobs" canary of the kernel's run-orphan-check, transactional outbox spec §11); after the
|
|
115
|
+
* cleanup it rejects naming such runs, or with the check's own error. A database or Redis it
|
|
116
|
+
* cannot reach skips the check.
|
|
117
|
+
*/
|
|
112
118
|
stop(): Promise<void>;
|
|
113
119
|
}
|
|
114
120
|
/**
|
package/dist/dual-replica.js
CHANGED
|
@@ -3,6 +3,7 @@ import { randomBytes } from "node:crypto";
|
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { extname, resolve } from "node:path";
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
+
import { Redis } from "ioredis";
|
|
6
7
|
import { createFreshDatabase, sharedPgAdminUrl, startPostgresContainer, startTestRedis, } from "./containers.js";
|
|
7
8
|
/** 副本在响应头里标明自己的序号(runner 把 `http.replicaId` 设为 `"0"` / `"1"`)。 */
|
|
8
9
|
export const REPLICA_HEADER = "x-capybara-replica";
|
|
@@ -20,6 +21,41 @@ const ALL_ROLES = ["api", "worker", "gateway"];
|
|
|
20
21
|
const STOP_TIMEOUT_MS = 15_000;
|
|
21
22
|
const START_TIMEOUT_MS = 60_000;
|
|
22
23
|
const STDERR_TAIL = 4000;
|
|
24
|
+
/**
|
|
25
|
+
* The queued runs of the harness's database whose job is neither in the outbox nor in BullMQ (the
|
|
26
|
+
* kernel's `queuedRunsWithoutJob`; a BullMQ job is the hash `bull:<queue>:<jobId>`). Null only when
|
|
27
|
+
* the database or Redis cannot be reached (a test that stopped them: the check is skipped); any
|
|
28
|
+
* other error is thrown.
|
|
29
|
+
*/
|
|
30
|
+
async function queuedOrphansOf(dbUrl, redisUrl) {
|
|
31
|
+
// loaded here, not at the top: a process that only spawns replicas (or is killed) never needs
|
|
32
|
+
// the kernel in its own module graph
|
|
33
|
+
const { createDb, kernelDb, queuedRunsWithoutJob } = await import("@capybara-hq/kernel");
|
|
34
|
+
const { sql } = await import("kysely");
|
|
35
|
+
const raw = createDb(dbUrl, 1, () => { }, { connectTimeoutMs: 5000 });
|
|
36
|
+
const redis = new Redis(redisUrl, {
|
|
37
|
+
lazyConnect: true,
|
|
38
|
+
connectTimeout: 5000,
|
|
39
|
+
maxRetriesPerRequest: 1,
|
|
40
|
+
retryStrategy: () => null,
|
|
41
|
+
});
|
|
42
|
+
redis.on("error", () => { });
|
|
43
|
+
try {
|
|
44
|
+
try {
|
|
45
|
+
await redis.connect();
|
|
46
|
+
await sql `SELECT 1`.execute(raw);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const found = await queuedRunsWithoutJob(kernelDb(raw), async (queue, jobId) => (await redis.exists(`bull:${queue}:${jobId}`)) === 1, { minAgeMs: 0 });
|
|
52
|
+
return found.map((c) => `${c.runId} (conversation ${c.conversationId}, job ${c.jobId})`);
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
redis.disconnect();
|
|
56
|
+
await raw.destroy().catch(() => { });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
23
59
|
/** runner 与本文件同目录;源码下是 .ts,编译后是 .js。 */
|
|
24
60
|
const runnerPath = fileURLToPath(new URL(`./replica-runner${extname(fileURLToPath(import.meta.url))}`, import.meta.url));
|
|
25
61
|
/**
|
|
@@ -120,6 +156,8 @@ export async function createDualReplicaHarness(opts) {
|
|
|
120
156
|
const runners = [];
|
|
121
157
|
let dropDb;
|
|
122
158
|
let stopPromise;
|
|
159
|
+
/** Set once both replicas started: `stop()` then checks for queued runs without a job. */
|
|
160
|
+
let checkOrphans;
|
|
123
161
|
const stopRunner = async (r) => {
|
|
124
162
|
if (r.child.exitCode !== null || r.child.signalCode !== null)
|
|
125
163
|
return;
|
|
@@ -138,9 +176,18 @@ export async function createDualReplicaHarness(opts) {
|
|
|
138
176
|
};
|
|
139
177
|
const stop = () => {
|
|
140
178
|
stopPromise ??= (async () => {
|
|
179
|
+
const checked = await checkOrphans?.().then((orphans) => ({ orphans }), (error) => ({ error }));
|
|
141
180
|
await Promise.allSettled(runners.map(stopRunner));
|
|
142
181
|
await Promise.allSettled([dropDb?.()]);
|
|
143
182
|
await Promise.allSettled(owned.map((c) => c.stop()));
|
|
183
|
+
if (checked && "error" in checked)
|
|
184
|
+
throw checked.error;
|
|
185
|
+
const orphans = checked?.orphans ?? null;
|
|
186
|
+
if (orphans !== null && orphans.length > 0) {
|
|
187
|
+
throw new Error(`the replicas left ${orphans.length} queued run(s) without a job (neither owed by the ` +
|
|
188
|
+
`outbox nor in BullMQ; the run-orphan-check would report "the queue lost jobs"): ` +
|
|
189
|
+
orphans.join(", "));
|
|
190
|
+
}
|
|
144
191
|
})();
|
|
145
192
|
return stopPromise;
|
|
146
193
|
};
|
|
@@ -216,6 +263,7 @@ export async function createDualReplicaHarness(opts) {
|
|
|
216
263
|
};
|
|
217
264
|
let calls = 0;
|
|
218
265
|
let extraChain = Promise.resolve();
|
|
266
|
+
checkOrphans = () => queuedOrphansOf(db.url, redisUrl);
|
|
219
267
|
const kill = async (index) => {
|
|
220
268
|
const { runner: r } = runnerAt(index);
|
|
221
269
|
if (r.child.exitCode === null && r.child.signalCode === null)
|
package/dist/fixtures.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export declare const FAKE_EXTENSIONS: readonly ["fake-connector", "fake-openapi"
|
|
|
29
29
|
*
|
|
30
30
|
* | name | provides / covers |
|
|
31
31
|
* |---|---|
|
|
32
|
-
* | `fake-theme` | themes `
|
|
32
|
+
* | `fake-theme` | themes `neon-grid` (dark only, wordmark, font `FakeSans`, logo) and `paper` (light and dark); passes `capybara-plugin check` |
|
|
33
33
|
*/
|
|
34
34
|
export declare const FAKE_PLUGINS: readonly ["fake-theme"];
|
|
35
35
|
/** The name of a fake plugin. */
|
package/dist/fixtures.js
CHANGED
|
@@ -49,7 +49,7 @@ export const FAKE_EXTENSIONS = [
|
|
|
49
49
|
*
|
|
50
50
|
* | name | provides / covers |
|
|
51
51
|
* |---|---|
|
|
52
|
-
* | `fake-theme` | themes `
|
|
52
|
+
* | `fake-theme` | themes `neon-grid` (dark only, wordmark, font `FakeSans`, logo) and `paper` (light and dark); passes `capybara-plugin check` |
|
|
53
53
|
*/
|
|
54
54
|
export const FAKE_PLUGINS = ["fake-theme"];
|
|
55
55
|
/** `fixtures/extensions/` of this package (same path from `src/` and from `dist/`). */
|
package/dist/kernel-helpers.d.ts
CHANGED
|
@@ -97,7 +97,8 @@ export declare function joinOrg(k: Pick<TestKernel, "http">, owner: KernelReques
|
|
|
97
97
|
}>;
|
|
98
98
|
/**
|
|
99
99
|
* Creates an org-visible agent; returns its id. An agent has every tool the org offers unless
|
|
100
|
-
* `disabledTools` turns it off (tools default-on spec)
|
|
100
|
+
* `disabledTools` turns it off (tools default-on spec), and every skill on in the org unless
|
|
101
|
+
* `disabledSkills` turns it off (skills default-on spec); with several tools model-fake answers
|
|
101
102
|
* ordinary messages instead of calling one.
|
|
102
103
|
*/
|
|
103
104
|
export declare function createAgent(req: KernelRequest, orgId: string, opts?: {
|
|
@@ -106,6 +107,7 @@ export declare function createAgent(req: KernelRequest, orgId: string, opts?: {
|
|
|
106
107
|
model: string;
|
|
107
108
|
};
|
|
108
109
|
disabledTools?: unknown[];
|
|
110
|
+
disabledSkills?: unknown[];
|
|
109
111
|
}): Promise<string>;
|
|
110
112
|
/** Creates a conversation with the agent; returns its id. */
|
|
111
113
|
export declare function createConversation(req: KernelRequest, orgId: string, agentId: string): Promise<string>;
|
package/dist/kernel-helpers.js
CHANGED
|
@@ -179,7 +179,8 @@ export async function joinOrg(k, owner, orgId, name, role = "member") {
|
|
|
179
179
|
}
|
|
180
180
|
/**
|
|
181
181
|
* Creates an org-visible agent; returns its id. An agent has every tool the org offers unless
|
|
182
|
-
* `disabledTools` turns it off (tools default-on spec)
|
|
182
|
+
* `disabledTools` turns it off (tools default-on spec), and every skill on in the org unless
|
|
183
|
+
* `disabledSkills` turns it off (skills default-on spec); with several tools model-fake answers
|
|
183
184
|
* ordinary messages instead of calling one.
|
|
184
185
|
*/
|
|
185
186
|
export async function createAgent(req, orgId, opts = {}) {
|
|
@@ -192,6 +193,7 @@ export async function createAgent(req, orgId, opts = {}) {
|
|
|
192
193
|
instructions: "Be helpful.",
|
|
193
194
|
model: opts.model ?? { provider: "model-fake", model: "fake-1" },
|
|
194
195
|
disabledTools: opts.disabledTools ?? [],
|
|
196
|
+
...(opts.disabledSkills !== undefined && { disabledSkills: opts.disabledSkills }),
|
|
195
197
|
},
|
|
196
198
|
visibility: "org",
|
|
197
199
|
},
|
|
@@ -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.16",
|
|
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.24"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/pg": "^8.23.1",
|
|
54
54
|
"@types/ws": "^8.18.2",
|
|
55
|
-
"@capybara-hq/plugin-client": "^0.1.0-rc.
|
|
56
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
55
|
+
"@capybara-hq/plugin-client": "^0.1.0-rc.4",
|
|
56
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.18"
|
|
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.18",
|
|
61
|
+
"@capybara-hq/plugin-tools": "^0.1.0-rc.13"
|
|
62
62
|
},
|
|
63
63
|
"peerDependenciesMeta": {
|
|
64
64
|
"@capybara-hq/plugin-tools": {
|