The first end-to-end test: a Project Think agent, on the real model, writes code that runs in a dynamic worker and drives a mower; the test counts the cells cut, and saves the turn to itest-output/. Installs @cloudflare/think, @cloudflare/codemode, agents, ai, workers-ai-provider, zod. The model-test worker now has a main entry, the Neighbor DO, and a LOADER binding. Red: src/worker.ts doesn't exist yet. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
22 lines
1.1 KiB
TypeScript
22 lines
1.1 KiB
TypeScript
/** @file A vitest reporter that saves annotation bodies (e.g. the code a model
|
|
* wrote) to `itest-output/`, one file per test per run; tests run in workerd,
|
|
* which can't write files. */
|
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
import type { Reporter } from "vitest/reporters";
|
|
|
|
const outDir = new URL("../itest-output/", import.meta.url);
|
|
const extFor: Record<string, string> = { "text/javascript": "js", "application/json": "json", "text/plain": "txt" };
|
|
const slug = (text: string) => text.replace(/[^\w]+/g, "-").replace(/^-|-$/g, "");
|
|
|
|
export default class SaveAnnotations implements Reporter {
|
|
async onTestCaseAnnotate(...[testCase, annotation]: Parameters<NonNullable<Reporter["onTestCaseAnnotate"]>>) {
|
|
const { body, contentType = "text/plain" } = annotation.attachment ?? {};
|
|
if (body === undefined) return;
|
|
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
const file = new URL(`${slug(testCase.name)}-${stamp}.${extFor[contentType] ?? "txt"}`, outDir);
|
|
await mkdir(outDir, { recursive: true });
|
|
await writeFile(file, body);
|
|
console.log(`saved ${annotation.message}: ${file.pathname}`);
|
|
}
|
|
}
|