Files
captoys/good-fences/itest/code-mode.test.ts
T
dckcandClaude Opus 5.5 37faa92649 test(good-fences): lent a mower, the model writes code to mow (red)
Code mode (2c): the harness turns what I say plus `about` into a prompt;
the model replies with `(env) => ...` code. Checked textually for now,
since workerd won't eval it: the code pushes `env.mower` and calls only
methods in `about`. It also prints the code, to see what the model writes.

Red: src/code-mode.ts doesn't exist yet.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-09 00:01:39 -05:00

22 lines
874 B
TypeScript

/** @file The model, asked in code mode, writes code that drives the mower. */
import { env } from "cloudflare:workers";
import { expect, test } from "vitest";
import { codeModeMessages, extractCode } from "../src/code-mode.ts";
import { makeWorkersAiModel, MODEL } from "../src/model.ts";
import { aboutMower } from "../src/mower.ts";
test("lent a mower, the neighbor writes code to mow", async () => {
const model = makeWorkersAiModel(env.AI, MODEL);
const messages = codeModeMessages({
say: "you can use this mower for the weekend",
about: { mower: aboutMower },
});
const code = extractCode(await model.complete(messages));
console.log(code);
const calls = [...code.matchAll(/env\.mower\.(\w+)\(/g)].map(([, method]) => method);
expect(calls).toContain("push");
for (const method of calls) expect(["start", "push", "turn", "stop"]).toContain(method);
});