import { test } from "node:test"; import assert from "node:assert/strict"; import { complete } from "../src/model.js"; import { desktopArguments, shellArguments } from "../src/tools.js"; const config = { 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 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: [] }); });