fix: test fix to normalized coordinate space.

This commit is contained in:
Zoe
2026-09-20 23:35:24 -05:00
parent f4aef8f5f3
commit 5ea5c9aeb1
5 changed files with 19 additions and 38 deletions
+1 -7
View File
@@ -1,7 +1,7 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { complete } from "../src/model.js";
import { desktopArguments, scaleImage, shellArguments, toolsForCoordinates } from "../src/tools.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:" };
@@ -37,9 +37,3 @@ test("tool inputs reject invalid commands, bounds, and action names", () => {
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");
});
test("scaleImage resizes PNG to requested dimensions", async () => {
const buffer = await scaleImage("artifacts/first.png", 1000, 1000);
assert.ok(Buffer.isBuffer(buffer));
assert.ok(buffer.length > 0);
});
+12 -4
View File
@@ -38,7 +38,7 @@ class ValidationTests(unittest.TestCase):
desktop.main()
if actions:
self.assertEqual(events, ["capture", "action", 0.5, "capture"])
command.assert_called_once_with("xdotool", "mousemove", "--sync", "640", "400", "click", "1")
command.assert_called_once_with("xdotool", "mousemove", "--sync", "640", "500", "click", "1")
else:
self.assertEqual(events, ["capture", "capture"])
@@ -64,9 +64,17 @@ class ValidationTests(unittest.TestCase):
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))
# 1280x800: width > 1000 (normalized 0..1000), height <= 1000 (pixels 0..799)
self.assertEqual(desktop.click_pixels({"x": 0, "y": 0}, 1280, 800, "normalized_1000"), (0, 0))
self.assertEqual(desktop.click_pixels({"x": 500, "y": 400}, 1280, 800, "normalized_1000"), (640, 400))
self.assertEqual(desktop.click_pixels({"x": 1000, "y": 799}, 1280, 800, "normalized_1000"), (1279, 799))
# 1920x1080: both > 1000 (both normalized 0..1000)
self.assertEqual(desktop.click_pixels({"x": 500, "y": 500}, 1920, 1080, "normalized_1000"), (960, 540))
# 800x600: both <= 1000 (both pixels)
self.assertEqual(desktop.click_pixels({"x": 400, "y": 300}, 800, 600, "normalized_1000"), (400, 300))
# 1x1: both <= 1000
self.assertEqual(desktop.click_pixels({"x": 0, "y": 0}, 1, 1, "normalized_1000"), (0, 0))
# pixels mode
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):