@capybara-hq/testing 0.1.0-rc.24 → 0.1.0-rc.26

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
@@ -21,7 +21,7 @@ export { type FakeSlackAck, type FakeSlackCall, type FakeSlackFailure, type Fake
21
21
  export { type FakeTelegramBot, type FakeTelegramCall, type FakeTelegramFailure, type FakeTelegramMessage, type FakeTelegramOptions, type FakeTelegramServer, findTelegramButton, startFakeTelegram, type TgChat, type TgUser, telegramCallback, telegramGroupMessage, telegramPrivateMessage, telegramWebhookHeaders, } from "./fake-telegram.js";
22
22
  export { FAKE_EXTENSIONS, type FakeExtensionName, fakeExtensionDir, fakeExtensionEntry, type PackedFixture, packFixture, } from "./fixtures.js";
23
23
  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";
24
- export { isPngBase64, pdfBase64, pdfSampleWord, redPngBase64, solidPngBase64, } from "./media-samples.js";
24
+ export { FAKE_PNG_BASE64, isPngBase64, pdfBase64, pdfSampleWord, redPngBase64, solidPngBase64, } from "./media-samples.js";
25
25
  export { type ConformanceTarget, checkDeclaredParameters, describeModelProviderConformance, MEDIA_SAMPLES, thinkingReplayParams, } from "./model-conformance.js";
26
26
  export { type NativeFixtureEntry, runSandboxNativeConformance, type SandboxNativeFixture, } from "./sandbox-native-conformance.js";
27
27
  export { runSandboxPermissionConformance, type SandboxPermissionEndpoint, type SandboxPermissionFixture, type SandboxPermissionGrant, } from "./sandbox-permission-conformance.js";
package/dist/index.js CHANGED
@@ -21,7 +21,7 @@ export { findSlackButton, signSlackWebhook, slackBlockAction, slackDmEvent, slac
21
21
  export { findTelegramButton, startFakeTelegram, telegramCallback, telegramGroupMessage, telegramPrivateMessage, telegramWebhookHeaders, } from "./fake-telegram.js";
22
22
  export { FAKE_EXTENSIONS, fakeExtensionDir, fakeExtensionEntry, packFixture, } from "./fixtures.js";
23
23
  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";
24
- export { isPngBase64, pdfBase64, pdfSampleWord, redPngBase64, solidPngBase64, } from "./media-samples.js";
24
+ export { FAKE_PNG_BASE64, isPngBase64, pdfBase64, pdfSampleWord, redPngBase64, solidPngBase64, } from "./media-samples.js";
25
25
  export { checkDeclaredParameters, describeModelProviderConformance, MEDIA_SAMPLES, thinkingReplayParams, } from "./model-conformance.js";
26
26
  export { runSandboxNativeConformance, } from "./sandbox-native-conformance.js";
27
27
  export { runSandboxPermissionConformance, } from "./sandbox-permission-conformance.js";
@@ -8,3 +8,5 @@ export declare function pdfBase64(word: string): string;
8
8
  export declare function isPngBase64(data: unknown): boolean;
9
9
  /** 夹具用:从 {@link pdfBase64} 生成的 PDF 里读出印的词;不是这样的 PDF 时返回 null。 */
10
10
  export declare function pdfSampleWord(data: unknown): string | null;
11
+ /** A valid 1x1 PNG, base64; model-fake keeps an identical copy (a test checks they are equal). */
12
+ export declare const FAKE_PNG_BASE64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC";
@@ -74,3 +74,5 @@ export function pdfSampleWord(data) {
74
74
  return null;
75
75
  return /\(([A-Z0-9]+)\) Tj/.exec(pdf)?.[1] ?? null;
76
76
  }
77
+ /** A valid 1x1 PNG, base64; model-fake keeps an identical copy (a test checks they are equal). */
78
+ export const FAKE_PNG_BASE64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC";
@@ -9,6 +9,10 @@ interface TargetCommon {
9
9
  model: string;
10
10
  dimensions: number;
11
11
  };
12
+ /** Set when the provider lists an image generation model: runs the image cases. */
13
+ imageGeneration?: {
14
+ model: string;
15
+ };
12
16
  };
13
17
  /** caching 用例的稳定前缀大小(约 token 数),默认 5000。 */
14
18
  cachePrefixTokens?: number;
@@ -1,4 +1,4 @@
1
- import { assertValidDeclarations, EFFORT_VALUES, isModelError, sanitizeParams, validateEmbedResult, validateParams, } from "@capybara-hq/plugin-sdk";
1
+ import { assertValidDeclarations, EFFORT_VALUES, isModelError, isValidImageGenerationInfo, sanitizeParams, validateEmbedResult, validateImageGenerateResult, validateParams, } from "@capybara-hq/plugin-sdk";
2
2
  import { afterAll, beforeAll, describe, expect, it } from "vitest";
3
3
  import { pdfBase64, redPngBase64 } from "./media-samples.js";
4
4
  function streamOf(t, req, signal) {
@@ -284,6 +284,55 @@ export function describeModelProviderConformance(name, setup) {
284
284
  expect(validateEmbedResult(req, info, res)).toBeNull();
285
285
  });
286
286
  });
287
+ describe("image generation", () => {
288
+ const run = async (n) => {
289
+ const img = t.expect.imageGeneration;
290
+ const provider = t.provider;
291
+ if (!img || !provider.generateImage) {
292
+ throw new Error("the target declares imageGeneration but has no generateImage");
293
+ }
294
+ const models = await provider.listModels();
295
+ const info = models.find((m) => m.id === img.model)?.imageGeneration;
296
+ if (!info)
297
+ throw new Error(`model ${img.model} lists no imageGeneration`);
298
+ const req = {
299
+ model: img.model,
300
+ prompt: "a small red square",
301
+ size: info.defaultSize,
302
+ n,
303
+ params: {},
304
+ };
305
+ const res = await provider.generateImage(req, { signal: new AbortController().signal });
306
+ return { req, res, info };
307
+ };
308
+ it("lists valid imageGeneration info", async (ctx) => {
309
+ const img = t.expect.imageGeneration;
310
+ if (!img)
311
+ return ctx.skip();
312
+ const models = await t.provider.listModels();
313
+ const info = models.find((m) => m.id === img.model)?.imageGeneration;
314
+ expect(isValidImageGenerationInfo(info)).toBe(true);
315
+ });
316
+ it("generates one image that passes validateImageGenerateResult", async (ctx) => {
317
+ if (!t.expect.imageGeneration)
318
+ return ctx.skip();
319
+ const { req, res, info } = await run(1);
320
+ expect(validateImageGenerateResult(req, info, res)).toBeNull();
321
+ });
322
+ // A model that returns one image per call declares maxImages 1; the kernel never asks it
323
+ // for more, so the suite does not either.
324
+ it("generates two images when the model allows it", async (ctx) => {
325
+ const img = t.expect.imageGeneration;
326
+ if (!img)
327
+ return ctx.skip();
328
+ const listed = (await t.provider.listModels()).find((m) => m.id === img.model);
329
+ if ((listed?.imageGeneration?.maxImages ?? 0) < 2)
330
+ return ctx.skip();
331
+ const { req, res, info } = await run(2);
332
+ expect(res.images).toHaveLength(2);
333
+ expect(validateImageGenerateResult(req, info, res)).toBeNull();
334
+ });
335
+ });
287
336
  it("abort", async () => {
288
337
  const ac = new AbortController();
289
338
  const it = streamOf(t, base(), ac.signal)[Symbol.asyncIterator]();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/testing",
3
- "version": "0.1.0-rc.24",
3
+ "version": "0.1.0-rc.26",
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.42"
50
+ "@capybara-hq/kernel": "^0.1.0-rc.44"
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.5",
56
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.31"
56
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.32"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "vitest": "^5.0.5",
60
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.31",
61
- "@capybara-hq/plugin-tools": "^0.1.0-rc.17"
60
+ "@capybara-hq/plugin-tools": "^0.1.0-rc.17",
61
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.32"
62
62
  },
63
63
  "peerDependenciesMeta": {
64
64
  "@capybara-hq/plugin-tools": {