34 lines
1.9 KiB
TypeScript
34 lines
1.9 KiB
TypeScript
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 advertise the configured coordinate convention", () => {
|
|
assert.match(toolsForCoordinates("normalized_1000")[0]?.function.description ?? "", /0\.\.1000/);
|
|
assert.match(toolsForCoordinates("pixels")[0]?.function.description ?? "", /not normalized/);
|
|
});
|
|
|
|
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: [] });
|
|
});
|