First vertical slice: Even client, bridge, contract v1, tests, docs
Client (apps/even-client): pure interaction reducer with generation-based stale-result rejection, HUD renderer, measured pagination, Even Hub SDK 0.0.16 adapter, bridge HTTP client, phone pairing/status/diagnostics page. Bridge (services/bridge): device pairing and revocable expiring credentials, turn engine with idempotent submit, cancel, deadlines and restart recovery, Hermes Runs API adapter, OpenAI-compatible STT adapter, operator CLI. Contract (packages/contracts): versioned schemas, types and error codes. Tests: 122 unit/integration (fakes), 6 simulator scenarios (Even Hub simulator 0.9.5), 9 scenarios against a real Hermes v0.23.1 gateway with a stub model. No real STT, real model or physical device has been exercised; see docs/test-evidence.md and docs/device-test-plan.md. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import { evenHubEventFromJson, OsEventTypeList } from '@evenrealities/even_hub_sdk';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { normalizeEvent, OS_EVENT, type RawEvenHubEvent } from '../src/device/events.ts';
|
||||
|
||||
/**
|
||||
* These run the published SDK's own parser (`evenHubEventFromJson`) over host
|
||||
* payload shapes, then our normaliser. They verify our mapping against the SDK
|
||||
* as shipped, not against a pair of glasses.
|
||||
*/
|
||||
const parse = (payload: unknown) => normalizeEvent(evenHubEventFromJson(payload) as RawEvenHubEvent);
|
||||
|
||||
describe('event constants', () => {
|
||||
it('match the SDK enum', () => {
|
||||
expect(OS_EVENT).toEqual({
|
||||
CLICK: OsEventTypeList.CLICK_EVENT,
|
||||
SCROLL_TOP: OsEventTypeList.SCROLL_TOP_EVENT,
|
||||
SCROLL_BOTTOM: OsEventTypeList.SCROLL_BOTTOM_EVENT,
|
||||
DOUBLE_CLICK: OsEventTypeList.DOUBLE_CLICK_EVENT,
|
||||
FOREGROUND_ENTER: OsEventTypeList.FOREGROUND_ENTER_EVENT,
|
||||
FOREGROUND_EXIT: OsEventTypeList.FOREGROUND_EXIT_EVENT,
|
||||
ABNORMAL_EXIT: OsEventTypeList.ABNORMAL_EXIT_EVENT,
|
||||
SYSTEM_EXIT: OsEventTypeList.SYSTEM_EXIT_EVENT,
|
||||
IMU_DATA_REPORT: OsEventTypeList.IMU_DATA_REPORT,
|
||||
LONG_PRESS: OsEventTypeList.LONG_PRESS_EVENT,
|
||||
LONG_PRESS_RELEASE: OsEventTypeList.LONG_PRESS_RELEASE_EVENT,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('gestures through the SDK parser', () => {
|
||||
it('a tap arrives with no eventType (protobuf omits zero) on either envelope', () => {
|
||||
expect(parse({ type: 'sysEvent', jsonData: { eventSource: 1 } })).toEqual([{ type: 'tap' }]);
|
||||
expect(parse({ type: 'textEvent', jsonData: { containerID: 1, containerName: 'body' } })).toEqual([{ type: 'tap' }]);
|
||||
expect(parse({ type: 'sysEvent', jsonData: { eventType: 0 } })).toEqual([{ type: 'tap' }]);
|
||||
});
|
||||
|
||||
it('double tap, swipes and lifecycle map from sysEvent and textEvent', () => {
|
||||
expect(parse({ type: 'sysEvent', jsonData: { eventType: 3 } })).toEqual([{ type: 'double_tap' }]);
|
||||
expect(parse({ type: 'textEvent', jsonData: { eventType: 3 } })).toEqual([{ type: 'double_tap' }]);
|
||||
expect(parse({ type: 'textEvent', jsonData: { eventType: 1 } })).toEqual([{ type: 'swipe_up' }]);
|
||||
expect(parse({ type: 'textEvent', jsonData: { eventType: 2 } })).toEqual([{ type: 'swipe_down' }]);
|
||||
expect(parse({ type: 'sysEvent', jsonData: { eventType: 'SCROLL_BOTTOM_EVENT' } })).toEqual([{ type: 'swipe_down' }]);
|
||||
expect(parse({ type: 'sysEvent', jsonData: { eventType: 4 } })).toEqual([{ type: 'foreground_enter' }]);
|
||||
expect(parse({ type: 'sysEvent', jsonData: { eventType: 5 } })).toEqual([{ type: 'foreground_exit' }]);
|
||||
expect(parse({ type: 'sysEvent', jsonData: { eventType: 6 } })).toEqual([{ type: 'abnormal_exit' }]);
|
||||
expect(parse({ type: 'sysEvent', jsonData: { eventType: 7 } })).toEqual([{ type: 'system_exit' }]);
|
||||
});
|
||||
|
||||
it('ring and left-temple sources produce the same semantic gestures', () => {
|
||||
for (const eventSource of [1, 2, 3]) {
|
||||
expect(parse({ type: 'sysEvent', jsonData: { eventSource } })).toEqual([{ type: 'tap' }]);
|
||||
expect(parse({ type: 'sysEvent', jsonData: { eventSource, eventType: 3 } })).toEqual([{ type: 'double_tap' }]);
|
||||
}
|
||||
});
|
||||
|
||||
it('audio frames are never mistaken for taps', () => {
|
||||
const out = parse({ type: 'audioEvent', jsonData: { audioPcm: [1, 2, 3, 4] } });
|
||||
expect(out).toHaveLength(1);
|
||||
expect(out[0]!.type).toBe('audio');
|
||||
expect(Array.from((out[0] as { pcm: Uint8Array }).pcm)).toEqual([1, 2, 3, 4]);
|
||||
});
|
||||
|
||||
it('menu selections carry their item id and are not taps', () => {
|
||||
expect(parse({ type: 'menuItemClickEvent', jsonData: { itemID: 2 } })).toEqual([{ type: 'menu', itemId: 2 }]);
|
||||
});
|
||||
|
||||
it('IMU reports and long presses are outside the interaction contract', () => {
|
||||
expect(parse({ type: 'sysEvent', jsonData: { eventType: 8, imuData: { x: 1, y: 2, z: 3 } } })).toEqual([]);
|
||||
expect(parse({ type: 'sysEvent', jsonData: { eventType: 9 } })).toEqual([]);
|
||||
expect(parse({ type: 'sysEvent', jsonData: { eventType: 10 } })).toEqual([]);
|
||||
});
|
||||
|
||||
it('an empty or unknown event produces nothing', () => {
|
||||
expect(normalizeEvent({})).toEqual([]);
|
||||
expect(parse({ type: 'somethingNew', jsonData: {} })).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user