feat: support normalizing coordinate spaces

This commit is contained in:
Zoe
2026-09-19 18:23:51 -05:00
parent c49f228847
commit 5389d4541c
9 changed files with 85 additions and 15 deletions
+7 -2
View File
@@ -1,9 +1,9 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { complete } from "../src/model.js";
import { desktopArguments, shellArguments } from "../src/tools.js";
import { desktopArguments, shellArguments, toolsForCoordinates } from "../src/tools.js";
const config = { llamaCppOrigin: "http://example.test", modelId: "test", databasePath: ":memory:" };
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";
@@ -19,6 +19,11 @@ test("adapter accepts tool calls and rejects truncated responses", async (t) =>
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 }));
+13
View File
@@ -32,6 +32,19 @@ class ValidationTests(unittest.TestCase):
self.assertIn("--register-session\n", entries[0].read_text())
self.assertIn("OnlyShowIn=XFCE;", entries[0].read_text())
def test_normalized_coordinates(self):
for value, expected in [(0, (0, 0)), (500, (640, 400)), (1000, (1279, 799))]:
self.assertEqual(desktop.click_pixels({"x": value, "y": value}, 1280, 800, "normalized_1000"), expected)
self.assertEqual(desktop.click_pixels({"x": 1000, "y": 1000}, 1, 1, "normalized_1000"), (0, 0))
self.assertEqual(desktop.click_pixels({"x": 480, "y": 425}, 1280, 800, "pixels"), (480, 425))
for value in (-1, 1001, 0.5, True):
with self.assertRaises(ValueError):
desktop.click_pixels({"x": value, "y": 0}, 1280, 800, "normalized_1000")
def test_invalid_coordinate_space(self):
with self.assertRaises(ValueError):
desktop.validate({"actions": [], "coordinateSpace": "guess"}, 1280, 800)
def test_capture(self):
self.assertEqual(desktop.validate({"actions": []}, 100, 100), [])