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
+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();
});
});