@capybara-hq/testing 0.1.0-rc.43 → 0.1.0-rc.44
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/fake-channel.d.ts
CHANGED
|
@@ -157,6 +157,17 @@ export interface FakeChannelServer {
|
|
|
157
157
|
count?: number;
|
|
158
158
|
onlyCards?: boolean;
|
|
159
159
|
}): void;
|
|
160
|
+
/**
|
|
161
|
+
* Hold the response of the next `count` successful `/send` (or `/update`) requests until
|
|
162
|
+
* `release()` (a gate, not a time window): recorded on arrival like {@link delayNext}, answered
|
|
163
|
+
* only once released. `stop()` releases every hold.
|
|
164
|
+
*/
|
|
165
|
+
holdNext(path: "/send" | "/update" | "/send-file", opts?: {
|
|
166
|
+
count?: number;
|
|
167
|
+
onlyCards?: boolean;
|
|
168
|
+
}): {
|
|
169
|
+
release(): void;
|
|
170
|
+
};
|
|
160
171
|
/** 让 /connect 返回该状态码(null 恢复正常)。 */
|
|
161
172
|
failConnect(status: number | null): void;
|
|
162
173
|
/** 该渠道连接当前在线的长连接。 */
|
package/dist/fake-channel.js
CHANGED
|
@@ -32,6 +32,8 @@ export async function startFakeChannelServer(opts = {}) {
|
|
|
32
32
|
const fileByKey = new Map();
|
|
33
33
|
const failures = [];
|
|
34
34
|
const delays = [];
|
|
35
|
+
const holds = [];
|
|
36
|
+
const pause = (d) => d.until ?? new Promise((r) => setTimeout(r, d.delayMs));
|
|
35
37
|
const live = new Map();
|
|
36
38
|
const peaks = new Map();
|
|
37
39
|
let failStatus = null;
|
|
@@ -109,7 +111,7 @@ export async function startFakeChannelServer(opts = {}) {
|
|
|
109
111
|
const fd = delays.find((x) => x.path === path && x.left > 0);
|
|
110
112
|
if (fd) {
|
|
111
113
|
fd.left--;
|
|
112
|
-
await
|
|
114
|
+
await pause(fd);
|
|
113
115
|
}
|
|
114
116
|
json(res, 200, { messageId: fid });
|
|
115
117
|
return;
|
|
@@ -132,7 +134,7 @@ export async function startFakeChannelServer(opts = {}) {
|
|
|
132
134
|
const d = delays.find((x) => x.path === path && x.left > 0 && (!x.onlyCards || hasCards));
|
|
133
135
|
if (d) {
|
|
134
136
|
d.left--;
|
|
135
|
-
await
|
|
137
|
+
await pause(d);
|
|
136
138
|
}
|
|
137
139
|
json(res, 200, { messageId });
|
|
138
140
|
};
|
|
@@ -282,6 +284,21 @@ export async function startFakeChannelServer(opts = {}) {
|
|
|
282
284
|
delayNext(path, delayMs, opts = {}) {
|
|
283
285
|
delays.push({ path, delayMs, left: opts.count ?? 1, onlyCards: opts.onlyCards ?? false });
|
|
284
286
|
},
|
|
287
|
+
holdNext(path, opts = {}) {
|
|
288
|
+
let release;
|
|
289
|
+
const until = new Promise((r) => {
|
|
290
|
+
release = r;
|
|
291
|
+
});
|
|
292
|
+
holds.push(release);
|
|
293
|
+
delays.push({
|
|
294
|
+
path,
|
|
295
|
+
delayMs: 0,
|
|
296
|
+
left: opts.count ?? 1,
|
|
297
|
+
onlyCards: opts.onlyCards ?? false,
|
|
298
|
+
until,
|
|
299
|
+
});
|
|
300
|
+
return { release };
|
|
301
|
+
},
|
|
285
302
|
failConnect(status) {
|
|
286
303
|
failStatus = status;
|
|
287
304
|
},
|
|
@@ -314,6 +331,8 @@ export async function startFakeChannelServer(opts = {}) {
|
|
|
314
331
|
return (updated.filter((x) => x.messageId === s.messageId).at(-1)?.message.text ?? s.message.text);
|
|
315
332
|
},
|
|
316
333
|
async stop() {
|
|
334
|
+
for (const release of holds)
|
|
335
|
+
release();
|
|
317
336
|
for (const res of live.values())
|
|
318
337
|
res.destroy();
|
|
319
338
|
live.clear();
|
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, describeModelProviderConformance, MEDIA_SAMPLES, thinkingReplayParams, } from "./model-conformance.js";
|
|
28
|
+
export { type ConformanceTarget, 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, describeModelProviderConformance, MEDIA_SAMPLES, thinkingReplayParams, } from "./model-conformance.js";
|
|
28
|
+
export { 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 ParamValue } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import { type ModelInfo, type ModelParameter, type ModelProvider, type ModelStreamEvent, type ParamValue } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
interface TargetCommon {
|
|
3
3
|
model: string;
|
|
4
4
|
expect: {
|
|
@@ -26,6 +26,16 @@ export type ConformanceTarget = TargetCommon & {
|
|
|
26
26
|
plugin: string;
|
|
27
27
|
provider: ModelProvider;
|
|
28
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* Checks a stream's tool events against its final message: every delta follows its call's start,
|
|
31
|
+
* each call starts once, and the deltas of each started call join to JSON whose parsed value
|
|
32
|
+
* equals the final call's input (structurally: key order does not matter). A started call with
|
|
33
|
+
* no final call of its id is allowed. Returns the problems (empty when fine); a stream with no
|
|
34
|
+
* tool events passes.
|
|
35
|
+
*/
|
|
36
|
+
export declare function checkToolStream(events: ModelStreamEvent[], done: Extract<ModelStreamEvent, {
|
|
37
|
+
type: "message_complete";
|
|
38
|
+
}>): string[];
|
|
29
39
|
/**
|
|
30
40
|
* `@2` 参数声明检查:每个模型的 `parameters` 须通过 `assertValidDeclarations`,
|
|
31
41
|
* 每个声明的默认值须通过 `validateParams`。返回问题列表(形如 `<模型 id>: <原因>`),无问题为空。
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
1
2
|
import { assertValidDeclarations, EFFORT_VALUES, isModelError, isValidImageGenerationInfo, sanitizeParams, validateEmbedResult, validateImageGenerateResult, validateParams, } from "@capybara-hq/plugin-sdk";
|
|
2
3
|
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
3
4
|
import { pdfBase64, redPngBase64 } from "./media-samples.js";
|
|
@@ -5,6 +6,47 @@ function streamOf(t, req, signal) {
|
|
|
5
6
|
const { params, ...rest } = req;
|
|
6
7
|
return t.provider.stream({ ...rest, params: params ?? {} }, { signal });
|
|
7
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Checks a stream's tool events against its final message: every delta follows its call's start,
|
|
11
|
+
* each call starts once, and the deltas of each started call join to JSON whose parsed value
|
|
12
|
+
* equals the final call's input (structurally: key order does not matter). A started call with
|
|
13
|
+
* no final call of its id is allowed. Returns the problems (empty when fine); a stream with no
|
|
14
|
+
* tool events passes.
|
|
15
|
+
*/
|
|
16
|
+
export function checkToolStream(events, done) {
|
|
17
|
+
const problems = [];
|
|
18
|
+
const streamed = new Map();
|
|
19
|
+
for (const e of events) {
|
|
20
|
+
if (e.type === "tool_call_start") {
|
|
21
|
+
// a repeated start keeps the input streamed so far
|
|
22
|
+
if (streamed.has(e.id))
|
|
23
|
+
problems.push(`repeated tool_call_start for id ${e.id}`);
|
|
24
|
+
else
|
|
25
|
+
streamed.set(e.id, "");
|
|
26
|
+
}
|
|
27
|
+
else if (e.type === "tool_call_delta") {
|
|
28
|
+
const soFar = streamed.get(e.id);
|
|
29
|
+
if (soFar === undefined)
|
|
30
|
+
problems.push(`tool_call_delta for unknown id ${e.id}`);
|
|
31
|
+
else
|
|
32
|
+
streamed.set(e.id, soFar + e.input);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
for (const [id, json] of streamed) {
|
|
36
|
+
const call = done.content.find((b) => b.type === "tool_call" && b.id === id);
|
|
37
|
+
// a started call without a final call of that id is allowed (spec §3)
|
|
38
|
+
if (call?.type !== "tool_call")
|
|
39
|
+
continue;
|
|
40
|
+
let same = false;
|
|
41
|
+
try {
|
|
42
|
+
same = isDeepStrictEqual(JSON.parse(json), call.input);
|
|
43
|
+
}
|
|
44
|
+
catch { }
|
|
45
|
+
if (!same)
|
|
46
|
+
problems.push(`streamed input of ${id} does not parse to the final input`);
|
|
47
|
+
}
|
|
48
|
+
return problems;
|
|
49
|
+
}
|
|
8
50
|
/**
|
|
9
51
|
* `@2` 参数声明检查:每个模型的 `parameters` 须通过 `assertValidDeclarations`,
|
|
10
52
|
* 每个声明的默认值须通过 `validateParams`。返回问题列表(形如 `<模型 id>: <原因>`),无问题为空。
|
|
@@ -120,8 +162,9 @@ export function describeModelProviderConformance(name, setup) {
|
|
|
120
162
|
{ role: "user", content: [{ type: "text", text: "What is the weather in Paris?" }] },
|
|
121
163
|
],
|
|
122
164
|
});
|
|
123
|
-
const { done } = await collect(t, first);
|
|
165
|
+
const { events, done } = await collect(t, first);
|
|
124
166
|
expect(done.stopReason).toBe("tool_use");
|
|
167
|
+
expect(checkToolStream(events, done)).toEqual([]);
|
|
125
168
|
const call = done.content.find((b) => b.type === "tool_call");
|
|
126
169
|
expect(call).toBeDefined();
|
|
127
170
|
if (call?.type !== "tool_call")
|
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.44",
|
|
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.
|
|
50
|
+
"@capybara-hq/kernel": "^0.1.0-rc.98"
|
|
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-client": "^0.1.0-rc.9",
|
|
56
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.81"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"vitest": "^5.0.5",
|
|
60
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
60
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.81",
|
|
61
61
|
"@capybara-hq/plugin-tools": "^0.1.0-rc.25"
|
|
62
62
|
},
|
|
63
63
|
"peerDependenciesMeta": {
|