test(good-fences): the model counts the rs in strawberry (red)

A first integration test of the model call: Workers AI through the AI
binding, behind the same `complete(messages)` interface as the sim's
fake model. Opt-in (`pnpm test:model`) since it needs `wrangler login`
and costs money.

Red: src/model.ts doesn't exist yet.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
dckcandClaude Opus 5.5 committed 2026-10-08 23:36:46 -05:00
1 parent 9b12943be4
commit 47a2337afe
5 files changed
+2256 -1

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
/** @file The model, called for real through the Workers AI binding. */
import { env } from "cloudflare:workers";
import { expect, test } from "vitest";
import { makeWorkersAiModel, MODEL } from "../src/model.ts";
test("the model counts the rs in strawberry", async () => {
const model = makeWorkersAiModel(env.AI, MODEL);
const reply = await model.complete([
{
role: "user",
content: 'How many times does the letter r appear in "strawberry"? Answer with just the number.',
},
]);
expect(reply.trim()).toMatch(/^3\b/);
});
+8 -1
View File
@@ -3,9 +3,16 @@
"private": true, "private": true,
"type": "module", "type": "module",
"scripts": { "scripts": {
"test": "node --test test/*.test.ts" "test": "node --test test/*.test.ts",
"test:model": "vitest run -c vitest.model.config.ts",
"types": "wrangler types -c wrangler.model-tests.jsonc"
}, },
"dependencies": { "dependencies": {
"ses": "^1.14.0" "ses": "^1.14.0"
},
"devDependencies": {
"@cloudflare/vitest-plugin": "1.3.6",
"vitest": "4.1.11",
"wrangler": "^4.148.0"
} }
} }
+2217
View File
File diff suppressed because it is too large. Load diff
+8
View File
@@ -0,0 +1,8 @@
import { defineProject } from "vitest/config";
import { cloudflareTest } from "@cloudflare/vitest-plugin";
/** opt-in (`pnpm test:model`): calls Workers AI, which needs `wrangler login` and costs money */
export default defineProject({
plugins: [cloudflareTest({ wrangler: { configPath: "./wrangler.model-tests.jsonc" } })],
test: { include: ["itest/**/*.test.ts"] },
});
+7
View File
@@ -0,0 +1,7 @@
{
"$schema": "node_modules/wrangler/config-schema.json",
// model integration tests: AI always runs remotely, and costs money
"name": "good-fences-model-tests",
"compatibility_date": "2026-10-01",
"ai": { "binding": "AI", "remote": true }
}