CODY-011 deploy/install.sh performs the ownership-sensitive sequence: the
release is copied to app.new, that one directory is given to the
hermeven user, npm ci runs unprivileged, and the finished tree is
handed back to root:root with group/other write removed. Secrets,
state and model directories are never touched. The guide now gives
exact commands, including the C/C++ toolchain a clean host needs
(found by running it on one).
CODY-012 install.sh builds the phone page with the bridge address preset
and installs it root-owned into /opt/hermeven/www for Caddy. The
guide explains the web build versus the .ehpk package and when
each is needed.
CODY-013 README states which commit was deployed, what was checked, and
what remains unverified.
Also corrects a wrong diagnosis recorded in the previous commit: the phone
page that showed "Browser preview" had been opened in Chrome, not in the
Even app. Host detection keeps a short precautionary wait (2.5 s) and its
comments no longer claim an observed Even-app delay.
tests/deploy/runbook-proof.sh proves the guide on a disposable Ubuntu 24.04
host with systemd.
Not reviewed.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
95 lines
3.7 KiB
TypeScript
95 lines
3.7 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { HOST_WAIT_MS, PLATFORM_READY_EVENT, waitForEvenHost, watchForLateHost, type HostWindow } from '../../apps/even-client/src/device/hostDetect.ts';
|
|
|
|
/**
|
|
* Host detection waits briefly for the Even app's connection instead of deciding on the first
|
|
* instant. This is a precaution: no real phone has yet been observed providing it late.
|
|
*/
|
|
function fakeWindow() {
|
|
const listeners = new Map<string, Set<() => void>>();
|
|
const win: HostWindow & { fire(type: string): void; listenerCount(): number } = {
|
|
addEventListener: (type, l) => void (listeners.get(type) ?? listeners.set(type, new Set()).get(type)!).add(l),
|
|
removeEventListener: (type, l) => void listeners.get(type)?.delete(l),
|
|
fire: (type) => listeners.get(type)?.forEach((l) => l()),
|
|
listenerCount: () => [...listeners.values()].reduce((n, s) => n + s.size, 0),
|
|
};
|
|
return win;
|
|
}
|
|
const host = { callHandler: () => undefined };
|
|
|
|
beforeEach(() => vi.useFakeTimers());
|
|
afterEach(() => vi.useRealTimers());
|
|
|
|
describe('detecting the Even app host', () => {
|
|
it('present from the start (the simulator): found at once', async () => {
|
|
const win = fakeWindow();
|
|
win.flutter_inappwebview = host;
|
|
expect(await waitForEvenHost(win)).toEqual({ found: true, waitedMs: 0 });
|
|
expect(win.listenerCount()).toBe(0);
|
|
});
|
|
|
|
it('appears shortly after the page starts: found, not mistaken for a browser', async () => {
|
|
const win = fakeWindow();
|
|
const detecting = waitForEvenHost(win);
|
|
await vi.advanceTimersByTimeAsync(800);
|
|
win.flutter_inappwebview = host;
|
|
await vi.advanceTimersByTimeAsync(60);
|
|
const result = await detecting;
|
|
expect(result.found).toBe(true);
|
|
expect(result.waitedMs).toBeGreaterThanOrEqual(800);
|
|
expect(result.waitedMs).toBeLessThan(1000);
|
|
});
|
|
|
|
it("the WebView's platform-ready event triggers an immediate check", async () => {
|
|
const win = fakeWindow();
|
|
const detecting = waitForEvenHost(win, { pollMs: 100_000 });
|
|
await vi.advanceTimersByTimeAsync(300);
|
|
win.flutter_inappwebview = host;
|
|
win.fire(PLATFORM_READY_EVENT);
|
|
expect((await detecting).found).toBe(true);
|
|
});
|
|
|
|
it('the event alone, with no host object, proves nothing', async () => {
|
|
const win = fakeWindow();
|
|
const detecting = waitForEvenHost(win);
|
|
win.fire(PLATFORM_READY_EVENT);
|
|
await vi.advanceTimersByTimeAsync(HOST_WAIT_MS + 10);
|
|
expect((await detecting).found).toBe(false);
|
|
});
|
|
|
|
it('an object without a callable callHandler is not a host', async () => {
|
|
const win = fakeWindow();
|
|
win.flutter_inappwebview = {};
|
|
const detecting = waitForEvenHost(win);
|
|
await vi.advanceTimersByTimeAsync(HOST_WAIT_MS + 10);
|
|
expect((await detecting).found).toBe(false);
|
|
});
|
|
|
|
it('a plain browser: gives up after the wait and cleans up', async () => {
|
|
const win = fakeWindow();
|
|
const detecting = waitForEvenHost(win);
|
|
await vi.advanceTimersByTimeAsync(HOST_WAIT_MS - 10);
|
|
let settled = false;
|
|
void detecting.then(() => (settled = true));
|
|
await Promise.resolve();
|
|
expect(settled).toBe(false);
|
|
await vi.advanceTimersByTimeAsync(20);
|
|
expect(await detecting).toEqual({ found: false, waitedMs: HOST_WAIT_MS });
|
|
expect(win.listenerCount()).toBe(0);
|
|
});
|
|
|
|
it('a host that turns up after preview mode was chosen triggers exactly one late callback', async () => {
|
|
const win = fakeWindow();
|
|
let late = 0;
|
|
watchForLateHost(win, () => (late += 1));
|
|
await vi.advanceTimersByTimeAsync(3000);
|
|
expect(late).toBe(0);
|
|
win.flutter_inappwebview = host;
|
|
await vi.advanceTimersByTimeAsync(600);
|
|
win.fire(PLATFORM_READY_EVENT);
|
|
await vi.advanceTimersByTimeAsync(5000);
|
|
expect(late).toBe(1);
|
|
expect(win.listenerCount()).toBe(0);
|
|
});
|
|
});
|