@capybara-hq/testing 0.1.0-rc.6 → 0.1.0-rc.7

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.
@@ -4,6 +4,11 @@ interface TargetCommon {
4
4
  expect: {
5
5
  thinking: boolean;
6
6
  caching: boolean;
7
+ /** Set when the provider lists an embedding model: runs the embedding cases. */
8
+ embedding?: {
9
+ model: string;
10
+ dimensions: number;
11
+ };
7
12
  };
8
13
  /** caching 用例的稳定前缀大小(约 token 数),默认 5000。 */
9
14
  cachePrefixTokens?: number;
@@ -1,4 +1,4 @@
1
- import { assertValidDeclarations, EFFORT_VALUES, isModelError, sanitizeParams, validateParams, } from "@capybara-hq/plugin-sdk";
1
+ import { assertValidDeclarations, EFFORT_VALUES, isModelError, sanitizeParams, validateEmbedResult, 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) {
@@ -260,6 +260,38 @@ export function describeModelProviderConformance(name, setup) {
260
260
  expect(done.stopReason).toBe("end_turn");
261
261
  expect(textOf(done.content).toUpperCase()).toContain(s.word);
262
262
  });
263
+ describe("embedding", () => {
264
+ const inputs = ["alpha", "bravo", "charlie"];
265
+ const run = async () => {
266
+ const emb = t.expect.embedding;
267
+ const provider = t.provider;
268
+ if (!emb || !provider.embed)
269
+ throw new Error("the target declares embedding but has no embed");
270
+ const req = { model: emb.model, input: inputs, dimensions: emb.dimensions };
271
+ const res = await provider.embed(req, { signal: new AbortController().signal });
272
+ const models = await provider.listModels();
273
+ const info = models.find((m) => m.id === emb.model)?.embedding;
274
+ return { req, res, info };
275
+ };
276
+ it("embeds a batch in order", async (ctx) => {
277
+ if (!t.expect.embedding)
278
+ return ctx.skip();
279
+ const { res } = await run();
280
+ expect(res.vectors).toHaveLength(inputs.length);
281
+ for (const v of res.vectors)
282
+ expect(v).toHaveLength(t.expect.embedding.dimensions);
283
+ expect(res.usage.inputTokens).toBeGreaterThanOrEqual(0);
284
+ });
285
+ it("embed result passes validateEmbedResult", async (ctx) => {
286
+ if (!t.expect.embedding)
287
+ return ctx.skip();
288
+ const { req, res, info } = await run();
289
+ expect(info).toBeDefined();
290
+ if (!info)
291
+ return;
292
+ expect(validateEmbedResult(req, info, res)).toBeNull();
293
+ });
294
+ });
263
295
  it("abort", async () => {
264
296
  const ac = new AbortController();
265
297
  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.6",
3
+ "version": "0.1.0-rc.7",
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.5"
50
+ "@capybara-hq/kernel": "^0.1.0-rc.6"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/pg": "^8.23.1",
54
54
  "@types/ws": "^8.18.2",
55
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.3"
55
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.4"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "vitest": "^5.0.5",
59
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.3",
60
- "@capybara-hq/plugin-tools": "^0.1.0-rc.5"
59
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.4",
60
+ "@capybara-hq/plugin-tools": "^0.1.0-rc.6"
61
61
  },
62
62
  "peerDependenciesMeta": {
63
63
  "@capybara-hq/plugin-tools": {