import { test } from "node:test"; import assert from "node:assert/strict"; import { complete } from "../src/model.js"; import { desktopArguments, shellArguments, toolsForCoordinates } from "../src/tools.js"; const config: import("../src/config.js").Config = { coordinateSpace: "pixels", llamaCppOrigin: "http://example.test", modelId: "test", databasePath: ":memory:" }; test("adapter accepts tool calls and rejects truncated responses", async (t) => { let finish = "tool_calls"; t.mock.method(globalThis, "fetch", async (_url: unknown, options: RequestInit) => { assert.equal(JSON.parse(String(options.body)).model, "test"); return Response.json({ choices: [{ finish_reason: finish, message: { role: "assistant", content: null, tool_calls: [{ id: "one", type: "function", function: { name: "desktop", arguments: '{"actions":[]}' } }], } }] }); }); assert.equal((await complete(config, [], [])).tool_calls?.[0]?.function.name, "desktop"); finish = "length"; await assert.rejects(complete(config, [], []), /incomplete/); }); test("tool descriptions do not inject coordinate normalization or pixel prompting", () => { for (const space of ["pixels", "normalized_1000"] as const) { const description = toolsForCoordinates(space)[0]?.function.description ?? ""; assert.doesNotMatch(description, /normalized/i); assert.doesNotMatch(description, /pixel/i); assert.doesNotMatch(description, /0\.\.1000/); } }); test("tool inputs reject invalid commands, bounds, and action names", () => { assert.throws(() => shellArguments.parse({ command: "", timeoutSeconds: 1 })); assert.throws(() => shellArguments.parse({ command: "true", timeoutSeconds: 999 })); assert.throws(() => desktopArguments.parse({ actions: [{ type: "click", x: -1, y: 0 }] })); assert.throws(() => desktopArguments.parse({ actions: [{ type: "execute" }] })); assert.deepEqual(desktopArguments.parse({ actions: [] }), { actions: [] }); assert.throws(() => desktopArguments.parse({ actions: [{ type: "click_target", target: "1" }] })); assert.equal(desktopArguments.parse({ actions: [{ type: "click_target", target: "1", observationId: "frame" }] }).actions[0]?.type, "click_target"); });