Files
gnome-jarvis/test/observer.test.js
T
snxraven 5b7c2b3b6d
Rolling release / release (push) Successful in 9m40s
Fix libei
2026-09-12 11:07:40 -04:00

37 lines
2.1 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { DesktopObserver } from '../computer-use/observer.js';
test('Phase 6 observer returns stable refs and ranked semantic matches', async () => {
const observer = new DesktopObserver({
screenshot: { capture: async () => '/tmp/frame.png' },
normalizer: { normalize: async () => ({ path: '/tmp/frame.webp' }) },
shell: { windows: async () => ({ available: true, windows: [{ id: 1 }] }), focused: async () => ({ id: 1 }) },
atspi: { tree: async () => [{ role: 'switch', name: 'Night Light', rect: [10, 20, 30, 30] }, { role: 'button', name: 'Cancel', rect: [1, 2, 3, 4] }] },
});
const bundle = await observer.observe({ includeOcr: false });
assert.equal(bundle.screenshot_path, '/tmp/frame.webp'); assert.equal(bundle.tree[0].ref, 'r1');
assert.equal((await observer.find({ query: 'night light' }))[0].ref, 'r1');
const zoom = await observer.zoom({ ref: 'r1' }); assert.deepEqual(zoom.rect, [10, 20, 30, 30]);
});
test('observer returns after a hung screenshot instead of staying on THINKING', async () => {
const observer = new DesktopObserver({
screenshot: { capture: () => new Promise(() => {}) },
shell: { windows: async () => ({ available: true, windows: [] }), focused: async () => null },
atspi: { tree: async () => [] },
timeouts: { screenshot: 40 },
});
const started = Date.now();
const bundle = await observer.observe({ includeTree: false, includeOcr: false });
assert.ok(Date.now() - started < 1000);
assert.equal(bundle.screenshot_path, null);
assert.match(bundle.unavailable.join(' '), /screenshot/);
});
test('Phase 6 observer reports portal failure instead of inventing a frame', async () => {
const observer = new DesktopObserver({ screenshot: { capture: async () => { throw new Error('no session bus'); } }, shell: { windows: async () => ({ available: false, windows: [] }), focused: async () => null }, atspi: { tree: async () => [] } });
const bundle = await observer.observe({ includeTree: false, includeOcr: false });
assert.equal(bundle.screenshot_path, null); assert.match(bundle.unavailable[0], /screenshot/);
});