@capybara-hq/testing 0.1.0-rc.45 → 0.1.0-rc.46
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/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({
|
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.46",
|
|
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.105"
|
|
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.84"
|
|
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.84",
|
|
61
61
|
"@capybara-hq/plugin-tools": "^0.1.0-rc.25"
|
|
62
62
|
},
|
|
63
63
|
"peerDependenciesMeta": {
|