CODY-016, 017, 018: launch source cannot be missed; a failed idle exit is retried

CODY-016. The SDK pushes the launch source once, early. The Even adapter now
subscribes in its constructor, remembers the value and replays it to a
listener that subscribes later. appMenu still does not arm idle exit.

CODY-018. exitNow() returns whether the host confirmed. The adapter keeps at
most one shutdown call in flight (through the same queue as every other host
call), lets a repeat request wait on that call, and never calls the host
again after a confirmed exit, including one confirmed late. The controller
marks itself as gone only on confirmation or on a system_exit/abnormal_exit
event; otherwise it retries after 3 s, at most 4 attempts in a row, under the
same resting-screen and phone-grace guards, and starts again after activity.

CODY-017. README: one owner-reported locked-phone success; pocketed,
five-minute and ten-cycle runs unverified.

Tests: production-adapter tests with a stand-in host, including the default
30 s under a fake clock; a simulator scenario that performs the real exit
(development-only ?idleExit=fast). Not reviewed. 0.1.1 is not uploaded.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Dan
2026-11-21 14:38:29 -08:00
co-authored by Claude Fable 5.2
parent 1ae105ed18
commit bbde3c86a8
12 changed files with 679 additions and 42 deletions
+64 -18
View File
@@ -31,6 +31,7 @@ let automation = '';
let lastConsoleId = 0;
const consoleLines: string[] = [];
let audioEchoLines = 0;
let simulatorExitOutcome = 'not run';
async function freePort(): Promise<number> {
return new Promise((resolvePort) => {
@@ -145,29 +146,16 @@ function litInBand(shot: { rows: Buffer[]; width: number }, fromY: number, toY:
return lit;
}
beforeAll(async () => {
mkdirSync(artifacts, { recursive: true });
const vitePort = await freePort();
vite = await createServer({
root: resolve(here, '../../apps/even-client'),
configFile: resolve(here, '../../apps/even-client/vite.config.ts'),
server: { host: '127.0.0.1', port: vitePort, strictPort: true },
logLevel: 'error',
});
await vite.listen();
const pageOrigin = `http://127.0.0.1:${vitePort}`;
h = await createHarness({
env: { HERMEVEN_ALLOWED_ORIGINS: pageOrigin, HERMEVEN_CAPTURE_MAX_SECONDS: '120' },
timing: { agentDeadlineMs: 20_000, transcribeDeadlineMs: 10_000 },
});
const { code } = h.bridge.devices.createPairingCode();
let pageOriginForRelaunch = '';
/** Start a simulator on the page. `idleExit` is the development-only switch read by main.ts. */
async function launchSimulator(idleExit: 'off' | 'fast', code: string): Promise<void> {
const pageOrigin = pageOriginForRelaunch;
const automationPort = await freePort();
automation = `http://127.0.0.1:${automationPort}`;
const bin = require.resolve('@evenrealities/sim-linux-x64/bin/evenhub-simulator');
// idleExit=off: this suite drives the app for longer than the idle timeout between steps.
const url = `${pageOrigin}/?idleExit=off&bridge=${encodeURIComponent(h.url)}&pair=${encodeURIComponent(code)}`;
const url = `${pageOrigin}/?idleExit=${idleExit}&bridge=${encodeURIComponent(h.url)}&pair=${encodeURIComponent(code)}`;
// alsa:null yields silence: the simulator never opens a real microphone in this test.
sim = spawn(bin, [url, '--automation-port', String(automationPort), '--no-glow', '--aid', 'alsa:null'], {
stdio: ['ignore', 'pipe', 'pipe'],
@@ -186,6 +174,28 @@ beforeAll(async () => {
if (Date.now() > deadline) throw new Error(`simulator automation API did not start.\n${simOutput.slice(-2000)}`);
await new Promise((r) => setTimeout(r, 250));
}
}
beforeAll(async () => {
mkdirSync(artifacts, { recursive: true });
const vitePort = await freePort();
vite = await createServer({
root: resolve(here, '../../apps/even-client'),
configFile: resolve(here, '../../apps/even-client/vite.config.ts'),
server: { host: '127.0.0.1', port: vitePort, strictPort: true },
logLevel: 'error',
});
await vite.listen();
const pageOrigin = `http://127.0.0.1:${vitePort}`;
h = await createHarness({
env: { HERMEVEN_ALLOWED_ORIGINS: pageOrigin, HERMEVEN_CAPTURE_MAX_SECONDS: '120' },
timing: { agentDeadlineMs: 20_000, transcribeDeadlineMs: 10_000 },
});
const { code } = h.bridge.devices.createPairingCode();
pageOriginForRelaunch = pageOrigin;
await launchSimulator('off', code);
});
afterAll(async () => {
@@ -330,4 +340,40 @@ describe('Even Hub simulator 0.9.5', () => {
const problems = consoleLines.filter((l) => /\[uncaught\]|\[unhandledrejection\]|\[fetch\]/.test(l));
expect(problems).toEqual([]);
});
it('idle exit for real: with short waits, the app calls the simulator\'s shutDownPageContainer(0) and records the answer', async () => {
// A second simulator, this time WITHOUT idle exit disabled (development-only short waits:
// 5 s at Ready). Everything above ran with it off because the steps take longer than that.
sim.kill('SIGTERM');
await new Promise((r) => setTimeout(r, 500));
if (sim.exitCode === null) sim.kill('SIGKILL');
await pumpConsole().catch(() => undefined);
const from = consoleLines.length;
lastConsoleId = 0;
await launchSimulator('fast', h.bridge.devices.createPairingCode().code);
await waitConsole('hud: HUD page created', 30_000, from);
await waitConsole('-> ready', 20_000, from);
await new Promise((r) => setTimeout(r, 6_500));
await pumpConsole();
// Opened by URL, no gesture yet: not armed, so it must still be there.
expect(consoleLines.slice(from).some((l) => l.includes('leaving the glasses'))).toBe(false);
await input('down'); // a glasses gesture arms it
await waitConsole('leaving the glasses: idle on ready', 15_000, from);
await new Promise((r) => setTimeout(r, 1_500));
await pumpConsole();
const after = consoleLines.slice(from);
const confirmed = after.some((l) => l.includes('lifecycle: left the glasses'));
const refused = after.some((l) => l.includes('did not confirm leaving'));
simulatorExitOutcome = confirmed ? 'confirmed' : refused ? 'not confirmed' : 'no answer recorded';
console.log(`[simulator] shutDownPageContainer(0): ${simulatorExitOutcome}`);
const shot = await screenshot('08-after-idle-exit');
// Observed on simulator 0.9.5: the call is confirmed and the display is cleared.
expect(simulatorExitOutcome).toBe('confirmed');
expect(shot.lit).toBeLessThan(50);
// What the simulator does with the call is recorded, not assumed; either way the app must
// have asked, and must not have thrown.
expect(confirmed || refused).toBe(true);
const problems = after.filter((l) => /\[uncaught\]|\[unhandledrejection\]/.test(l));
expect(problems).toEqual([]);
}, 120_000);
});