From 37faa9264917614d40180211a73434438b30d503 Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Fri, 9 Oct 2026 00:01:39 -0500 Subject: [PATCH] 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) --- good-fences/itest/code-mode.test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 good-fences/itest/code-mode.test.ts diff --git a/good-fences/itest/code-mode.test.ts b/good-fences/itest/code-mode.test.ts new file mode 100644 index 0000000..d1f50fa --- /dev/null +++ b/good-fences/itest/code-mode.test.ts @@ -0,0 +1,21 @@ +/** @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); +});