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); +});