Handle long presses: push-to-talk, with a tap-like fallback

On a real G2 a touch held slightly too long is reported as a long press
(sysEvent type 9, then type 10 on release; source 1 right temple, 3 left),
not as a tap, and was ignored. A long press now does what a tap does. If it
started a recording and is held at least 700 ms, releasing it sends
(push-to-talk); released sooner, it behaves like a tap and the recording
continues until the next tap or press.

Tests: 219 unit/integration; simulator 7 scenarios (long_press /
long_press_release through the automation API). Not reviewed, not deployed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Dan
2026-11-21 13:11:55 -08:00
co-authored by Claude Fable 5.2
parent b8191a7bd2
commit 9cb34b3125
8 changed files with 148 additions and 7 deletions
+2
View File
@@ -70,6 +70,8 @@ export class FakeDevice implements DevicePort {
}
tap = () => this.emit({ type: 'tap' });
doubleTap = () => this.emit({ type: 'double_tap' });
longPress = () => this.emit({ type: 'long_press' });
longPressRelease = () => this.emit({ type: 'long_press_release' });
swipeDown = () => this.emit({ type: 'swipe_down' });
swipeUp = () => this.emit({ type: 'swipe_up' });
menu = (itemId: number) => this.emit({ type: 'menu', itemId });
+73
View File
@@ -43,6 +43,7 @@ function makeController(dev: FakeDevice): Controller {
submitAttempts: 3,
submitRetryMs: 30,
micStallMs: 300,
holdToTalkMs: 150,
makeClient: (baseUrl, token) =>
new BridgeClient({
baseUrl,
@@ -608,3 +609,75 @@ describe('CODY-009: exactly one conversation is created, whatever the timing', (
expect(h.hermes.executions).toBe(1);
});
});
describe('long press (a real G2 reported a slow tap as a long press)', () => {
it('push-to-talk: hold starts recording, speaking while held, releasing sends', async () => {
await pairedController();
h.stt.next({ text: 'held question' });
device.longPress();
await until('listening with mic open', () => phase() === 'listening' && device.micOpen);
expect(device.frame.status).toContain('● REC');
device.speak(0.5);
await new Promise((r) => setTimeout(r, 200)); // held longer than the push-to-talk threshold
device.longPressRelease();
await until('answer', () => phase() === 'answer');
expect(h.hermes.lastRun()!.input).toBe('held question');
expect(device.micOpen).toBe(false);
expect(h.hermes.executions).toBe(1);
});
it('a press released quickly behaves like a tap: recording continues until the next tap', async () => {
await pairedController();
device.longPress();
await until('listening', () => phase() === 'listening' && device.micOpen);
device.longPressRelease(); // released at once: not push-to-talk
await new Promise((r) => setTimeout(r, 250));
expect(phase()).toBe('listening');
expect(device.micOpen).toBe(true);
expect(h.stt.calls).toBe(0);
device.speak(0.4);
device.tap();
await until('answer', () => phase() === 'answer');
expect(h.hermes.executions).toBe(1);
});
it('a long press while already recording sends, and its release does nothing more', async () => {
await pairedController();
device.tap();
await until('listening', () => phase() === 'listening' && device.micOpen);
device.speak(0.4);
device.longPress();
await until('answer', () => phase() === 'answer');
await new Promise((r) => setTimeout(r, 200));
device.longPressRelease();
await new Promise((r) => setTimeout(r, 100));
expect(phase()).toBe('answer'); // the late release did not start a new recording
expect(device.micOpens).toBe(1);
expect(h.hermes.executions).toBe(1);
});
it('a release with no press, or after a cancel, is ignored', async () => {
await pairedController();
device.longPressRelease();
expect(phase()).toBe('ready');
device.longPress();
await until('listening', () => phase() === 'listening' && device.micOpen);
await new Promise((r) => setTimeout(r, 200));
device.doubleTap(); // cancel while still holding
expect(phase()).toBe('cancelled');
device.longPressRelease();
await new Promise((r) => setTimeout(r, 100));
expect(phase()).toBe('cancelled');
expect(h.stt.calls).toBe(0);
expect(h.hermes.executions).toBe(0);
});
it('a long press on an answer starts a follow-up, like a tap', async () => {
await pairedController();
controller.askText('first');
await until('answer', () => phase() === 'answer');
device.longPress();
await until('listening', () => phase() === 'listening' && device.micOpen);
expect(snapshot.state.conversationId).not.toBeNull();
});
});
+6 -2
View File
@@ -191,13 +191,17 @@ describe('start-up when a callable Even host appears during the wait', () => {
await wait(20);
const afterTap = diagnostics()['Glasses input']!;
expect(afterTap).toContain('1 gesture/lifecycle event(s)');
expect(afterTap).not.toContain('ignored;');
expect(afterTap).toContain('sysEvent(type=none,source=1) -> tap');
// The tap really drove the app: unpaired, so the state stays put, but it was delivered.
push('sysEvent', { eventType: 9, eventSource: 1 }); // long press: outside the contract
push('sysEvent', { eventType: 9, eventSource: 1 }); // long press: recognised
await wait(20);
expect(diagnostics()['Glasses input']).toContain('sysEvent(type=9,source=1) -> long_press');
push('sysEvent', { eventType: 8, imuData: { x: 1, y: 2, z: 3 } }); // IMU: outside the contract
await wait(20);
const afterLongPress = diagnostics()['Glasses input']!;
expect(afterLongPress).toContain('1 ignored');
expect(afterLongPress).toContain('sysEvent(type=9,source=1) -> ignored');
expect(afterLongPress).toContain('sysEvent(type=8) -> ignored');
push('audioEvent', { audioPcm: [1, 2, 3, 4] });
await wait(20);
push('sysEvent', { eventType: 3 });
+20
View File
@@ -304,6 +304,26 @@ describe('Even Hub simulator 0.9.5', () => {
expect(h.hermes.executions).toBe(2);
});
it('hold to talk: a long press starts recording and releasing it sends', async () => {
h.stt.next({ text: 'simulated held question' });
const before = h.hermes.executions;
const mark = consoleLines.length;
await input('long_press');
await waitConsole('-> listening', 10_000, mark);
// Held well past the push-to-talk threshold. (With the unpaced null audio device the capture
// cap may be reached first; either way the recording must end and be answered once.)
await new Promise((r) => setTimeout(r, 1000));
await input('long_press_release');
await waitConsole('-> answer', 20_000, mark);
expect(h.hermes.executions).toBe(before + 1);
expect(h.hermes.lastRun()!.input).toBe('simulated held question');
await new Promise((r) => setTimeout(r, 500));
await screenshot('09-hold-to-talk-answer');
// Leave the app at rest for the checks that follow.
await input('double_click');
await waitConsole('state: answer -> ready', 10_000, mark);
});
it('no uncaught errors or failed fetches were reported by the webview', async () => {
await pumpConsole();
const problems = consoleLines.filter((l) => /\[uncaught\]|\[unhandledrejection\]|\[fetch\]/.test(l));