Merge branch 'main' into ring-health-fixes

This commit is contained in:
James Babcock committed 2026-10-25 01:06:38 -07:00
commit 4f8c082b52
368 files changed
+26238 -3401

No files matched your search

+11
View File
@@ -37,3 +37,14 @@ intervals and animation callbacks still fire, and cancelled timers stay cancelle
A short UIKit background task keeps the test process running without glasses.
This covers the ticker's background behavior; sustained execution with BLE and a
locked physical phone still requires device testing.
The native Android EvenHub probe runs on a booted emulator or attached device:
node tests/android-evenhub-native.cjs [adb-serial]
It compiles the production EvenHub WebView classes into an isolated APK (with the
Kotlin compiler and AndroidX artifacts a prior `./build.sh` cached), installs it,
and checks per-package WebView profiles, that the bridge reaches only the app's
own main frame (not its iframes or pages it navigates to), that host scripts and
timer ticks stay out of other sites, and that a renderer crash leaves the process
running.
+22 -1
View File
@@ -117,6 +117,27 @@ test('cancelled tools and late callbacks cannot mutate the next turn or its hist
assert.equal(session.isTurnActive(), false);
});
test('tool names are sanitized, shortened to 64 characters, kept distinct, and mapped back', () => {
const env = sessions();
const pkg = 'com.example.some-long-developer-name.evenhub';
const names = ['glasses.get_state', `app.${pkg}.set_metronome_tempo_and_signature`,
`app.${pkg}.set_metronome_tempo_and_signature_v2`, 'a.b', 'a_b'];
const registry = { listTools: () => names.map(name => ({ name, description: '', inputSchema: { type: 'object' } })) };
const session = new env.AssistantSession(config(), registry);
session.sendUtterance('hi', {}, callbacks());
const turn = env.turns.at(-1);
const apiNames = turn.buildTools().map(tool => tool.name);
assert.equal(apiNames[0], 'glasses_get_state');
assert.ok(apiNames.every(name => /^[a-zA-Z0-9_-]{1,64}$/.test(name)), apiNames.join(', '));
assert.equal(new Set(apiNames).size, names.length);
assert.match(apiNames[1], /^app_com_example_/);
assert.match(apiNames[1], /tempo_and_signature$/);
assert.deepEqual(apiNames.slice(3), ['a_b', 'a_b_2']);
assert.deepEqual(apiNames.map(turn.resolveToolName), names);
// The same canonical name shortens the same way on the next turn.
assert.deepEqual(turn.buildTools().map(tool => tool.name), apiNames);
});
test('synchronous provider errors do not leave a permanently active turn', () => {
const env = sessions(); env.setError();
const session = new env.AssistantSession(config());
@@ -271,7 +292,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
'../../graphics/image': images, '../../native/frame-timings': timings,
'../../util/render-freshness': { beginRenderPass() {}, endRenderPass: () => false },
'../layers': layers, '../window-menu': { WindowMenuLayer: Menu },
'./chrome-layer': { windowIcon: () => () => null }, './geometry': { appViewportSize: () => ({ width: 576, height: 260 }) },
'./chrome-layer': { windowIcon: () => () => null }, './geometry': { appViewportSize: () => ({ width: 576, height: 260 }), setAppImmersive: () => false },
'./shell': { shell },
});
const input = [], menus = [];
+205
View File
@@ -0,0 +1,205 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
const DAY_MS = 24 * 60 * 60 * 1000;
const HOUR_MS = 60 * 60 * 1000;
const START = Date.parse('2026-10-10T12:00:00Z');
/** analytics-store.ts over in-memory files, a settable clock and setting, and a fake server. */
function harness({ level = 'minimal', version = '0.8.3', statuses = [] } = {}) {
const files = new Map();
const sent = [];
const h = {
files, sent, level, version, now: START, statuses: [...statuses],
pendingSend: null,
snapshots: { minimal: { 'device.g2.paired': true }, full: { 'apikey.anthropic': true } },
};
let nextId = 1;
const { AnalyticsStore } = loader({
setTimeout: () => 0,
clearTimeout: () => {},
})('app/analytics/analytics-store.ts');
h.store = new AnalyticsStore({
storage: {
read: name => files.get(name) ?? null,
write: (name, text) => files.set(name, text),
remove: name => files.delete(name),
list: () => [...files.keys()],
removeAll: () => files.clear(),
},
level: () => h.level,
appInfo: () => ({ version: h.version, platform: 'android', build: 'official' }),
now: () => h.now,
randomId: () => `00000000-0000-4000-8000-${String(nextId++).padStart(12, '0')}`,
snapshot: level => ({ ...h.snapshots[level] }),
send: async body => {
sent.push(JSON.parse(body));
if (h.pendingSend) await h.pendingSend;
const status = h.statuses.length ? h.statuses.shift() : 200;
if (status === 'network') throw new Error('offline');
return status;
},
});
h.outbox = () => [...files.keys()].filter(name => name.startsWith('outbox-'));
h.state = () => JSON.parse(files.get('state.json'));
return h;
}
test('Analytics keeps only what the data-collection setting allows', () => {
const h = harness({ level: 'minimal' });
h.store.count('minimal', 'g2.connect');
h.store.count('full', 'app.launch.timer');
h.store.flush();
const pending = JSON.parse(h.files.get('pending.json'));
assert.deepEqual(pending.counters.minimal, { '2026-10-10': { 'g2.connect': 1 } });
assert.deepEqual(pending.counters.full, {});
const off = harness({ level: 'none' });
off.store.count('minimal', 'g2.connect');
off.store.flush();
off.store.applyLevel();
assert.equal(off.files.size, 0);
});
test('Analytics drops bad counter names and flags count once a day', () => {
const h = harness();
h.store.count('minimal', 'Bad Name');
h.store.flag('minimal', 'device.r1.used');
h.store.flag('minimal', 'device.r1.used');
h.store.count('minimal', 'g2.ack-timeout', 3);
h.store.flush();
assert.deepEqual(JSON.parse(h.files.get('pending.json')).counters.minimal['2026-10-10'], {
'device.r1.used': 1, 'g2.ack-timeout': 3,
});
});
test('Analytics seals and uploads a report once a day', async () => {
const h = harness({ level: 'full' });
h.store.count('minimal', 'g2.connect', 2);
h.store.count('full', 'feature.used');
await h.store.uploadIfDue();
assert.equal(h.sent.length, 1);
const [report] = h.sent;
assert.equal(report.schema, 1);
assert.equal(report.level, 'full');
assert.match(report.installId, /^00000000-/);
assert.deepEqual(report.app, { version: '0.8.3', platform: 'android', build: 'official' });
assert.deepEqual(report.counters, { '2026-10-10': { 'g2.connect': 2, 'feature.used': 1 } });
assert.deepEqual(report.snapshot, { 'device.g2.paired': true, 'apikey.anthropic': true });
assert.deepEqual(h.outbox(), []);
h.store.count('minimal', 'g2.connect');
h.now += 3 * HOUR_MS;
await h.store.uploadIfDue();
assert.equal(h.sent.length, 1, 'not due again the same day');
h.now = START + DAY_MS;
await h.store.uploadIfDue();
assert.equal(h.sent.length, 2);
assert.equal(h.sent[1].installId, report.installId);
assert.notEqual(h.sent[1].reportId, report.reportId);
assert.deepEqual(h.sent[1].counters, { '2026-10-10': { 'g2.connect': 1 } });
});
test('Analytics retries a failed upload hourly with the same report id, and drops rejected ones', async () => {
const h = harness({ statuses: ['network', 503] });
h.store.count('minimal', 'g2.connect');
await h.store.uploadIfDue();
assert.equal(h.outbox().length, 1);
h.now += 30 * 60 * 1000;
await h.store.uploadIfDue();
assert.equal(h.sent.length, 1, 'no retry within the hour');
h.now = START + HOUR_MS;
await h.store.uploadIfDue();
assert.equal(h.sent.length, 2);
assert.equal(h.sent[1].reportId, h.sent[0].reportId);
assert.equal(h.outbox().length, 1, 'kept after a 503');
h.now = START + 2 * HOUR_MS;
await h.store.uploadIfDue();
assert.equal(h.sent.length, 3);
assert.deepEqual(h.outbox(), []);
assert.equal(h.state().retryAt, 0);
const rejected = harness({ statuses: [400] });
await rejected.store.uploadIfDue();
assert.deepEqual(rejected.outbox(), [], 'a 400 is not retried');
});
test('Analytics turned off deletes everything, and a new install id is made when it comes back', async () => {
const h = harness();
h.store.count('minimal', 'g2.connect');
await h.store.uploadIfDue();
const firstInstall = h.sent[0].installId;
h.store.count('minimal', 'g2.connect');
h.store.flush();
h.level = 'none';
h.store.applyLevel();
assert.equal(h.files.size, 0);
await h.store.uploadIfDue();
assert.equal(h.sent.length, 1, 'no connection while off');
h.level = 'minimal';
h.now += DAY_MS;
await h.store.uploadIfDue();
assert.equal(h.sent.length, 2);
assert.notEqual(h.sent[1].installId, firstInstall);
assert.deepEqual(h.sent[1].counters, {}, 'counts from before turning off are gone');
});
test('Analytics turned down to minimal drops what was kept for full', async () => {
const h = harness({ level: 'full', statuses: ['network'] });
h.store.count('minimal', 'g2.connect');
h.store.count('full', 'feature.used');
await h.store.uploadIfDue();
h.store.count('full', 'feature.used');
h.store.flush();
h.level = 'minimal';
h.store.applyLevel();
assert.deepEqual(JSON.parse(h.files.get('pending.json')).counters.full, {});
const [outbox] = h.outbox();
assert.deepEqual(JSON.parse(h.files.get(outbox)).snapshot.full, {});
h.now += HOUR_MS;
await h.store.uploadIfDue();
const retried = h.sent[1];
assert.equal(retried.level, 'minimal');
assert.deepEqual(retried.counters, { '2026-10-10': { 'g2.connect': 1 } });
assert.deepEqual(retried.snapshot, { 'device.g2.paired': true });
});
test('Analytics sends counts from before an upgrade under the old version', async () => {
const h = harness({ version: '0.8.3' });
h.store.count('minimal', 'g2.connect');
h.store.flush();
// A new process after the upgrade.
const files = h.files;
const upgraded = harness({ version: '0.8.4' });
for (const [name, text] of files) upgraded.files.set(name, text);
upgraded.store.count('minimal', 'g2.connect', 5);
await upgraded.store.uploadIfDue();
assert.deepEqual(upgraded.sent.map(report => [report.app.version, report.counters['2026-10-10']]), [
['0.8.3', { 'g2.connect': 1 }],
['0.8.4', { 'g2.connect': 5 }],
]);
});
test('Analytics turned off and on during an upload keeps none of the old state', async () => {
const h = harness();
let release;
h.pendingSend = new Promise(resolve => { release = resolve; });
const upload = h.store.uploadIfDue();
await Promise.resolve();
h.level = 'none';
h.store.applyLevel();
h.level = 'minimal';
release();
await upload;
assert.equal(h.files.size, 0, 'the old install id is not written back');
});
+169
View File
@@ -0,0 +1,169 @@
// Run the production Android EvenHub WebView classes in an isolated probe APK on
// an emulator or device, no glasses: node tests/android-evenhub-native.cjs [adb-serial]
// Checks the per-package profiles, the origin-locked bridge and the renderer-crash
// handling against a real WebView. Needs ANDROID_HOME, a JDK, and a prior ./build.sh
// (for the cached Kotlin compiler and AndroidX artifacts).
const http = require('node:http');
const { execFileSync } = require('node:child_process');
const fs = require('node:fs'), path = require('node:path'), os = require('node:os');
const { loader } = require('./helpers/load-typescript.cjs');
const { newestArtifact, kotlinCompiler } = require('./helpers/kotlin-compiler.cjs');
const root = path.resolve(__dirname, '..');
const sdk = process.env.ANDROID_HOME || path.join(os.homedir(), 'Library/Android/sdk');
const newest = dir => fs.readdirSync(dir).filter(name => /^\d/.test(name)).sort((a, b) => a.localeCompare(b, undefined, { numeric: true })).at(-1);
const buildTools = path.join(sdk, 'build-tools', newest(path.join(sdk, 'build-tools')));
const androidJar = path.join(sdk, 'platforms', fs.readdirSync(path.join(sdk, 'platforms')).filter(name => /^android-\d+$/.test(name))
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true })).at(-1), 'android.jar');
const javaBin = process.env.JAVA_HOME ? path.join(process.env.JAVA_HOME, 'bin') : '';
const env = { ...process.env, PATH: [javaBin, process.env.PATH].filter(Boolean).join(path.delimiter) };
const run = (file, args, options = {}) => execFileSync(file, args, { cwd: root, env, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], ...options });
const serial = process.argv[2] || run('adb', ['devices']).split('\n').slice(1).map(line => line.split('\t')).find(([, state]) => state === 'device')?.[0];
if (!serial) throw new Error('No adb device or emulator is attached.');
const adb = (...args) => run('adb', ['-s', serial, ...args]);
const work = fs.mkdtempSync(path.join(os.tmpdir(), 'faceclaw-android-evenhub-probe-'));
// The scripts webview.ts builds, from the production sources.
const session = fs.readFileSync(path.join(root, 'app/apps/evenhub/session.ts'), 'utf8');
const shim = session.match(/export const EVENHUB_BRIDGE_INJECT_SCRIPT = `([\s\S]*?)`;/)[1];
const webview = loader({}, { '@nativescript/core': {}, './session': {}, '../../version': {} })('app/apps/evenhub/webview.ts');
const reports = [];
const server = http.createServer((request, response) => {
const url = new URL(request.url, 'http://probe');
const page = body => { response.setHeader('Content-Type', 'text/html'); response.end(`<!doctype html><html><head></head><body>${body}</body></html>`); };
if (url.pathname === '/report') { reports.push(url.search.slice(1)); response.end(); return; }
if (url.pathname === '/cookie') { reports.push(`cookie:${url.searchParams.get('app')}=${/\bthird=A\b/.test(request.headers.cookie ?? '')}`); page('cookie'); return; }
// A cross-origin iframe inside the app, and a third-party page the app navigates to.
if (url.pathname === '/xframe') { page(`<script>new Image().src = '/report?xframe=' + typeof window.__faceclawEvenHubPort + ',' + typeof window.__faceclawEvenHub</script>`); return; }
if (url.pathname === '/third') {
page(`<script>
var port = window.__faceclawEvenHubPort;
new Image().src = '/report?third=' + typeof port + ',' + typeof window.__faceclawEvenHub + ',' + typeof window.flutter_inappwebview;
if (port) port.postMessage(JSON.stringify(['call', 'probe', '["UNTRUSTED"]', 0]));
document.cookie = 'third=A; max-age=3600';
window.__fcTick = function () { new Image().src = '/report?tick=leak'; return 16; };
</script>`);
return;
}
if (url.pathname === '/remote/') { page(`<script>flutter_inappwebview.callHandler('probe', 'remote')</script>`); return; }
response.writeHead(404); response.end();
});
server.listen(0, '127.0.0.1', async () => {
try {
const port = server.address().port;
adb('reverse', `tcp:${port}`, `tcp:${port}`);
const third = `http://127.0.0.1:${port}`;
const start = { A: 'https://probe.a.evenhub.invalid/index.html', B: 'https://probe.b.evenhub.invalid/index.html',
A2: 'https://probe.a.evenhub.invalid/index.html', R: `http://localhost:${port}/remote/` };
const assets = path.join(work, 'assets'), dist = path.join(assets, 'dist');
fs.mkdirSync(dist, { recursive: true });
const checks = {};
for (const [tag, url] of Object.entries(start)) {
checks[tag] = webview.appOriginCheck(url);
fs.writeFileSync(path.join(assets, `inject-${tag}.js`), webview.guardToAppOrigin(url, webview.ANDROID_EVENHUB_TRANSPORT_SCRIPT + shim));
}
fs.writeFileSync(path.join(assets, 'config.json'), JSON.stringify({ third, start, checks }));
fs.writeFileSync(path.join(dist, 'index.html'), `<!doctype html><html><head><title>probe</title></head><body><script>
var call = function (name) { return flutter_inappwebview.callHandler('probe', name); };
call('early').then(function () { return call('resolved'); });
var same = document.createElement('iframe'); same.src = '/frame.html'; document.body.appendChild(same);
var cross = document.createElement('iframe'); cross.src = '${third}/xframe'; document.body.appendChild(cross);
</script></body></html>`);
// The app's own subframe: it gets the port, but the host ignores subframes.
fs.writeFileSync(path.join(dist, 'frame.html'), `<!doctype html><html><head></head><body><script>
new Image().src = '${third}/report?sameframe=' + typeof window.__faceclawEvenHubPort;
flutter_inappwebview.callHandler('probe', 'FRAME');
</script></body></html>`);
// Link the manifest, assets and androidx.core's resources (generating its R
// class, as Gradle would), compile the production classes with the probe,
// then dex, package and sign.
const compiler = kotlinCompiler();
if (!compiler) throw new Error('Kotlin compiler not in the Gradle cache; run ./build.sh once.');
const aar = (group, artifact) => {
const file = newestArtifact(group, artifact, 'aar');
if (!file) throw new Error(`${group}:${artifact} not in the Gradle cache; run ./build.sh once.`);
const out = path.join(work, artifact);
run('unzip', ['-q', '-o', file, 'classes.jar', 'res/*', '-d', out]);
return out;
};
const webkit = aar('androidx.webkit', 'webkit'), core = aar('androidx.core', 'core');
const libraries = [path.join(webkit, 'classes.jar'), path.join(core, 'classes.jar'),
newestArtifact('androidx.collection', 'collection-jvm'), newestArtifact('androidx.annotation', 'annotation-jvm'),
newestArtifact('org.jspecify', 'jspecify')];
if (libraries.some(file => !file)) throw new Error('AndroidX artifacts missing from the Gradle cache; run ./build.sh once.');
fs.writeFileSync(path.join(work, 'AndroidManifest.xml'), `<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.faceclaw.evenhubprobe">
<uses-permission android:name="android.permission.INTERNET"/>
<application android:label="EvenHubProbe" android:usesCleartextTraffic="true">
<activity android:name=".ProbeActivity" android:exported="true"/>
</application>
</manifest>`);
const aapt2 = path.join(buildTools, 'aapt2'), coreResources = path.join(work, 'core-res.zip'), generated = path.join(work, 'gen');
run(aapt2, ['compile', '--dir', path.join(core, 'res'), '-o', coreResources]);
const unsigned = path.join(work, 'unsigned.apk'), aligned = path.join(work, 'aligned.apk'), signed = path.join(work, 'probe.apk');
run(aapt2, ['link', '-o', unsigned, '-I', androidJar, '--manifest', path.join(work, 'AndroidManifest.xml'), '-A', assets,
'-R', coreResources, '--auto-add-overlay', '--extra-packages', 'androidx.core', '--java', generated,
'--min-sdk-version', '24', '--target-sdk-version', '35']);
const app = 'App_Resources/Android/src/main/java/com/faceclaw/app';
const shared = 'native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app';
fs.writeFileSync(path.join(work, 'Platform.kt'), 'package com.faceclaw.app\n' +
'fun fileExists(path: String): Boolean = java.io.File(path).exists()\n' +
'internal fun readFileData(path: String): ByteArray = java.io.File(path).readBytes()\n');
const classes = path.join(work, 'classes');
run('java', ['-cp', compiler.classpath, 'org.jetbrains.kotlin.cli.jvm.K2JVMCompiler', '-no-stdlib', '-no-reflect', '-nowarn',
'-cp', [androidJar, ...libraries, compiler.stdlib].join(path.delimiter), '-d', classes,
...['WebView', 'WebViewClient', 'WebViewHost', 'JsBridge', 'Profile', 'DocumentStart', 'ChromeClient'].map(name => `${app}/FaceclawEvenHub${name}.kt`),
`${shared}/callbacks/FaceclawEvenHubListener.kt`, `${shared}/evenhub/EvenHubAssetServer.kt`,
path.join(work, 'Platform.kt'), 'tests/native/AndroidEvenHubProbe.kt'], { maxBuffer: 64 << 20 });
const rSources = run('find', [generated, '-name', 'R.java']).trim().split('\n');
run('javac', ['-nowarn', '-cp', androidJar, '-d', classes, ...rSources]);
const dex = path.join(work, 'dex');
fs.mkdirSync(dex);
run('jar', ['cf', path.join(work, 'probe.jar'), '-C', classes, '.']);
run(path.join(buildTools, 'd8'), ['--min-api', '24', '--lib', androidJar, '--output', dex,
path.join(work, 'probe.jar'), compiler.stdlib, ...libraries], { maxBuffer: 64 << 20 });
run('zip', ['-j', unsigned, ...fs.readdirSync(dex).map(name => path.join(dex, name))]);
run(path.join(buildTools, 'zipalign'), ['-p', '-f', '4', unsigned, aligned]);
run(path.join(buildTools, 'apksigner'), ['sign', '--ks', path.join(os.homedir(), '.android/debug.keystore'), '--ks-pass', 'pass:android',
'--key-pass', 'pass:android', '--ks-key-alias', 'androiddebugkey', '--out', signed, aligned]);
try { adb('uninstall', 'com.faceclaw.evenhubprobe'); } catch { /* not installed */ }
adb('install', '-t', signed);
adb('logcat', '-c');
adb('shell', 'am', 'start', '-W', '-n', 'com.faceclaw.evenhubprobe/.ProbeActivity');
let result = null;
const deadline = Date.now() + 40000;
while (!result) {
if (Date.now() > deadline) throw new Error(`Probe timed out (did the process die?); artifacts: ${work}\n${adb('logcat', '-d', '-b', 'crash')}`);
await new Promise(resolve => setTimeout(resolve, 500));
const line = adb('logcat', '-d', '-s', 'EHPROBE:I').split('\n').find(text => text.includes('RESULT '));
if (line) result = JSON.parse(line.slice(line.indexOf('RESULT ') + 7));
}
const seen = new Set(result.seen);
const alive = adb('shell', 'pidof', 'com.faceclaw.evenhubprobe').trim() !== '';
const failures = [];
const expect = (ok, what) => { if (!ok) failures.push(what); };
for (const tag of Object.keys(start)) expect(seen.has(`${tag}:profile=true`), `${tag} has its own profile`);
for (const name of ['A:early', 'A:resolved', 'B:early', 'A2:early', 'R:remote']) expect(seen.has(name), `bridge round trip ${name}`);
expect(![...seen].some(name => name.endsWith(':bridge-error')), 'bridge installs');
expect(!seen.has('A:FRAME'), 'the app\'s subframe is ignored');
expect(!seen.has('A:UNTRUSTED'), 'the third-party page cannot post to the host');
expect(reports.includes('third=undefined,undefined,undefined'), 'the third-party page gets no port, bridge or shim');
expect(reports.length && reports.filter(r => r.startsWith('xframe=')).every(r => r === 'xframe=undefined,undefined'), 'cross-origin iframes get no port or bridge');
expect(!reports.includes('eval=leak'), 'host scripts do not run in the third-party page');
expect(!reports.includes('tick=leak'), 'host ticks do not run in the third-party page');
expect(reports.includes('cookie:B=false'), 'another package cannot see A\'s third-party cookie');
expect(reports.includes('cookie:A2=true'), 'A\'s profile keeps its cookie');
expect(seen.has('R:gone'), 'the crashed renderer is reported');
expect(alive, 'the process survives the renderer crash');
console.log(JSON.stringify({ work, serial, seen: [...seen], reports, alive, failures }));
if (failures.length) process.exitCode = 1;
} catch (error) {
console.error(error.stderr?.toString() || '', error); process.exitCode = 1;
} finally {
try { adb('reverse', '--remove-all'); } catch { /* best effort */ }
server.closeAllConnections(); server.close();
}
});
+461 -112
View File
@@ -11,9 +11,7 @@ const js = (source) => ts.transpileModule(source, {
function geometry() {
const settings = Object.fromEntries(Object.entries({
displayModeSetting: '576x288', verticalPositionSetting: 'middle',
navigateDisplayModeSetting: 'global', navigateVerticalPositionSetting: 'global',
terminalDisplayModeSetting: 'default', terminalVerticalPositionSetting: 'global',
displayLayoutSetting: 'band-middle', navigateDisplayLayoutSetting: 'global', terminalDisplayLayoutSetting: 'default',
appSwitcherPositionSetting: 'left', uiDepthSetting: '0', statusBarPositionSetting: 'top',
statusBarVisibilitySetting: 'always', windowBorderSetting: true,
}).map(([name, value]) => [name, { value, get() { return this.value; } }]));
@@ -27,46 +25,79 @@ function geometry() {
return { ...context.exports, settings, rect };
}
const LAYOUTS = ['band-top', 'band-high', 'band-middle', 'band-low', 'band-bottom', 'tall', 'fullscreen'];
test('defaults preserve normal windows, EvenHub height and tall terminal sessions', () => {
const g = geometry();
assert.deepEqual(g.rect('min', 'navigate'), { x: 64, y: 124, width: 576, height: 260 });
assert.deepEqual(g.rect('min', 'terminal'), g.rect('min'));
assert.deepEqual(g.rect('max', 'terminal'), { x: 64, y: 28, width: 576, height: 452 });
assert.equal(g.windowBandHeight('medium', 'evenhub'), 316);
g.settings.displayModeSetting.value = '640x480';
assert.deepEqual(g.rect('max', 'terminal'), { x: 0, y: 28, width: 640, height: 452 });
// Tall: every window the whole height, beside the strip.
g.settings.displayLayoutSetting.value = 'tall';
assert.deepEqual(g.rect('min'), { x: 64, y: 28, width: 576, height: 452 });
});
test('Navigate can use a small bottom band while other apps fill the panel', () => {
test('Navigate can use a small bottom band while other apps are tall', () => {
const g = geometry();
g.settings.displayModeSetting.value = '640x480';
g.settings.navigateDisplayModeSetting.value = '576x288';
g.settings.navigateVerticalPositionSetting.value = 'bottom';
g.settings.displayLayoutSetting.value = 'tall';
g.settings.navigateDisplayLayoutSetting.value = 'band-bottom';
assert.deepEqual(g.rect('min', 'navigate'), { x: 64, y: 220, width: 576, height: 260 });
assert.equal(g.minWindowTop('navigate'), 192);
assert.equal(g.sidebarStripVisible('window', 'navigate'), true);
assert.equal(g.sidebarStripVisible('window', 'other'), false);
assert.deepEqual(g.rect('min', 'other'), { x: 0, y: 28, width: 640, height: 452 });
assert.deepEqual(g.rect('min', 'other'), { x: 64, y: 28, width: 576, height: 452 });
});
test('Terminal can disable its tall default, inherit position or override both dimensions', () => {
test('Terminal can disable its tall default, follow the global band or choose a mode of its own', () => {
const g = geometry();
g.settings.terminalDisplayModeSetting.value = 'global';
g.settings.terminalDisplayLayoutSetting.value = 'global';
assert.deepEqual(g.rect('max', 'terminal'), g.rect('min'));
g.settings.verticalPositionSetting.value = 'top';
g.settings.displayLayoutSetting.value = 'band-top';
assert.equal(g.windowTop('max', 'terminal'), 0);
g.settings.terminalVerticalPositionSetting.value = 'lower';
g.settings.terminalDisplayLayoutSetting.value = 'band-low';
assert.equal(g.windowTop('max', 'terminal'), 144);
g.settings.terminalDisplayModeSetting.value = '640x480';
assert.deepEqual(g.rect('max', 'terminal'), { x: 0, y: 28, width: 640, height: 452 });
assert.equal(g.sidebarStripVisible('window', 'terminal'), false);
assert.equal(g.sidebarStripVisible('sidebar', 'terminal'), true);
g.settings.terminalDisplayModeSetting.value = '576x480';
g.settings.terminalDisplayLayoutSetting.value = 'tall';
assert.deepEqual(g.rect('min', 'terminal'), { x: 64, y: 28, width: 576, height: 452 });
// The default keeps sessions tall and the sessions list in the global band.
g.settings.terminalDisplayLayoutSetting.value = 'default';
assert.deepEqual(g.rect('max', 'terminal'), { x: 64, y: 28, width: 576, height: 452 });
assert.equal(g.windowTop('min', 'terminal'), 0);
});
test('all explicit size/position combinations stay within the display and align content below the bar', () => {
test('Full Screen widens Tall windows to the panel and drops depth, beside a bottom row or popup only', () => {
const g = geometry();
g.settings.displayLayoutSetting.value = 'fullscreen';
g.settings.uiDepthSetting.value = '48';
// A side strip leaves no width to spare: there it is Tall.
assert.equal(g.displayLayout(), 'tall');
assert.deepEqual(g.rect('min'), { x: 64, y: 28, width: 576, height: 452 });
g.settings.appSwitcherPositionSetting.value = 'bottom';
assert.equal(g.displayLayout(), 'fullscreen');
// Tall's height and the panel's width, the row still reserved under it,
// always shown; no room for a frame, nor for depth.
assert.deepEqual(g.rect('min'), { x: 0, y: 28, width: 640, height: 416 });
assert.deepEqual({ ...g.switcherRect('min') }, { x: 0, y: 444, width: 640, height: 36 });
assert.equal(g.sidebarStripVisible('window'), true);
assert.equal(g.windowFramed(), false);
assert.equal(g.uiDepth(), 0);
// With the status bar in the row, there's no frame top for a header either.
g.settings.statusBarPositionSetting.value = 'bottom';
assert.equal(g.statusInSwitcherRow(), true);
assert.deepEqual(g.rect('min'), { x: 0, y: 0, width: 640, height: 444 });
// A popup's status bar keeps its edge.
g.settings.appSwitcherPositionSetting.value = 'popup';
assert.deepEqual(g.rect('max'), { x: 0, y: 0, width: 640, height: 452 });
assert.equal(g.statusBarTop('max'), 452);
assert.equal(g.windowFramed(), false);
// Per app: depth follows the foreground app's mode.
g.settings.displayLayoutSetting.value = 'band-middle';
g.settings.navigateDisplayLayoutSetting.value = 'fullscreen';
assert.deepEqual([g.uiDepth('navigate'), g.uiDepth('launcher'), g.uiDepth()], [0, 48, 48]);
assert.deepEqual([g.rect('min', 'navigate').width, g.rect('min', 'launcher').width], [640, 576]);
});
test('all display modes and layouts stay within the display and align content below the bar', () => {
const g = geometry();
g.settings.uiDepthSetting.value = '48';
const combos = [['left', 'top'], ['right', 'top'], ['bottom', 'top'], ['bottom', 'bottom'], ['left', 'bottom']];
for (const statusBar of ['top', 'bottom']) {
for (const visibility of ['always', 'switcher']) {
@@ -78,42 +109,43 @@ test('all explicit size/position combinations stay within the display and align
g.settings.statusBarPositionSetting.value = statusBar;
g.settings.statusBarVisibilitySetting.value = visibility;
g.settings.windowBorderSetting.value = border;
for (const globalMode of ['576x288', '576x480', '640x480']) {
g.settings.displayModeSetting.value = globalMode;
const side = switcher === 'left' || switcher === 'right';
for (const globalMode of LAYOUTS) {
g.settings.displayLayoutSetting.value = globalMode;
for (const appId of ['navigate', 'terminal']) {
for (const mode of ['global', '576x288', '576x480', '640x480']) {
g.settings[`${appId}DisplayModeSetting`].value = mode;
for (const position of ['global', 'top', 'upper', 'middle', 'lower', 'bottom']) {
g.settings[`${appId}VerticalPositionSetting`].value = position;
for (const heightMode of ['min', 'medium', 'max']) {
const rect = g.rect(heightMode, appId);
const fullPanel = g.displayMode(appId) === '640x480';
assert.equal(rect.x + rect.width, fullPanel ? 640 : { left: 640, right: 576, bottom: 608, popup: 608 }[switcher]);
const header = g.windowHeaderHeight(appId), footer = g.windowFooterHeight(appId);
assert.equal(g.statusInSwitcherRow(appId), statusBar === 'bottom' && g.switcherRowHeight(appId) > 0);
if (switcher === 'popup') {
// Each edge has the status bar's rows (unless it only
// overlays), else the frame's side, else nothing.
assert.equal(g.windowFramed(appId), border && !fullPanel);
const edge = (side) => visibility === 'always' && statusBar === side ? g.TOP_BAR_HEIGHT : g.windowFramed(appId) ? 1 : 0;
assert.deepEqual([header, footer], [edge('top'), edge('bottom')]);
// The status bar's rows lie within the band, at its edge.
const top = g.windowTop(heightMode, appId), band = g.windowBandHeight(heightMode, appId);
assert.equal(g.statusBarTop(heightMode, appId), statusBar === 'top' ? top : top + band - g.TOP_BAR_HEIGHT);
} else {
assert.deepEqual([header, footer], [g.statusInSwitcherRow(appId) ? 1 : g.TOP_BAR_HEIGHT, 0]);
}
assert.equal(rect.y, g.windowTop(heightMode, appId) + header);
assert.equal(rect.height + header + footer, g.windowBandHeight(heightMode, appId));
assert.ok(rect.y >= header && rect.y + rect.height + footer <= 480 - g.switcherRowHeight(appId));
const row = g.switcherRect(heightMode, appId);
assert.ok(row.y + row.height <= 480);
// A reserved bottom row hangs right under the window, as wide as it.
if (g.switcherRowHeight(appId)) assert.deepEqual([row.x, row.y, row.width], [rect.x, rect.y + rect.height, rect.width]);
// The frame's sides, just outside the window, survive the
// deepest shift (±62 moves each lens 31px).
if (g.windowFramed(appId)) assert.ok(rect.x - 1 - 31 >= 0 && rect.x + rect.width + 31 < 640);
for (const mode of ['default', 'global', ...LAYOUTS]) {
g.settings[`${appId}DisplayLayoutSetting`].value = mode;
const wide = g.displayLayout(appId) === 'fullscreen';
if (wide) assert.equal(side, false, 'Full Screen only beside a bottom row or popup');
assert.equal(g.uiDepth(appId), side || wide ? 0 : 48);
for (const heightMode of ['min', 'medium', 'max']) {
const rect = g.rect(heightMode, appId);
assert.equal(rect.x + rect.width, wide ? 640 : { left: 640, right: 576, bottom: 608, popup: 608 }[switcher]);
const header = g.windowHeaderHeight(appId), footer = g.windowFooterHeight(appId);
assert.equal(g.statusInSwitcherRow(appId), statusBar === 'bottom' && g.switcherRowHeight(appId) > 0);
if (switcher === 'popup') {
// Each edge has the status bar's rows (unless it only
// overlays), else the frame's side, else nothing.
assert.equal(g.windowFramed(appId), border && !wide);
const edge = (side) => visibility === 'always' && statusBar === side ? g.TOP_BAR_HEIGHT : g.windowFramed(appId) ? 1 : 0;
assert.deepEqual([header, footer], [edge('top'), edge('bottom')]);
// The status bar's rows lie within the band, at its edge.
const top = g.windowTop(heightMode, appId), band = g.windowBandHeight(heightMode, appId);
assert.equal(g.statusBarTop(heightMode, appId), statusBar === 'top' ? top : top + band - g.TOP_BAR_HEIGHT);
} else {
assert.equal(g.windowFramed(appId), switcher === 'bottom' && !wide);
assert.deepEqual([header, footer], [!g.statusInSwitcherRow(appId) ? g.TOP_BAR_HEIGHT : g.windowFramed(appId) ? 1 : 0, 0]);
}
assert.equal(rect.y, g.windowTop(heightMode, appId) + header);
assert.equal(rect.height + header + footer, g.windowBandHeight(heightMode, appId));
assert.ok(rect.y >= header && rect.y + rect.height + footer <= 480 - g.switcherRowHeight(appId));
const row = g.switcherRect(heightMode, appId);
assert.ok(row.y + row.height <= 480);
// A reserved bottom row hangs right under the window, as wide as it.
if (g.switcherRowHeight(appId)) assert.deepEqual([row.x, row.y, row.width], [rect.x, rect.y + rect.height, rect.width]);
// The frame's sides, just outside the window, survive the
// deepest shift (±62 moves each lens 31px).
if (g.windowFramed(appId)) assert.ok(rect.x - 1 - 31 >= 0 && rect.x + rect.width + 31 < 640);
}
}
}
@@ -133,8 +165,9 @@ test('the app switcher can sit on the right edge', () => {
// Depth needs the bottom row's side margins.
g.settings.uiDepthSetting.value = '32';
assert.equal(g.uiDepth(), 0);
g.settings.displayModeSetting.value = '640x480';
assert.deepEqual(g.rect('max'), { x: 0, y: 28, width: 640, height: 452 });
// Full Screen needs the width a strip takes: beside one it is Tall.
g.settings.displayLayoutSetting.value = 'fullscreen';
assert.deepEqual(g.rect('min'), { x: 0, y: 28, width: 576, height: 452 });
});
test('a popup app switcher centres 576-wide windows, whose edges the status bar and frame decide', () => {
@@ -167,10 +200,10 @@ test('a popup app switcher centres 576-wide windows, whose edges the status bar
assert.equal(g.windowFramed(), false);
assert.deepEqual(g.rect('max', 'terminal'), { x: 32, y: 0, width: 576, height: 480 });
assert.deepEqual(g.rect('medium'), { x: 32, y: 96, width: 576, height: 288 });
// Full panel: the status bar keeps its edge, but there's no room for a frame.
// Full Screen: the status bar keeps its edge, but there's no room for a frame.
g.settings.windowBorderSetting.value = true;
g.settings.statusBarVisibilitySetting.value = 'always';
g.settings.displayModeSetting.value = '640x480';
g.settings.displayLayoutSetting.value = 'fullscreen';
assert.equal(g.windowFramed(), false);
assert.deepEqual(g.rect('max'), { x: 0, y: 0, width: 640, height: 452 });
assert.equal(g.statusBarTop('max'), 452);
@@ -187,7 +220,7 @@ test('a bottom app switcher centres 576-wide windows and hangs one tall tab unde
assert.deepEqual({ ...g.switcherRect('min') }, { x: 32, y: 366, width: 576, height: 36 });
assert.equal(g.isOnSwitcherEdge(10, 370, 'min'), true);
assert.equal(g.isOnSwitcherEdge(10, 360, 'min'), false);
g.settings.verticalPositionSetting.value = 'bottom';
g.settings.displayLayoutSetting.value = 'band-bottom';
assert.equal(g.switcherRect('min').y, 444);
// The true centre is the viewport's own with the window centred.
assert.equal(g.screenCenterInViewportX(), 288);
@@ -195,15 +228,125 @@ test('a bottom app switcher centres 576-wide windows and hangs one tall tab unde
g.settings.uiDepthSetting.value = '-48';
assert.equal(g.uiDepth(), -48);
assert.equal(g.windowFramed(), true);
// Full panel: windows fill the panel and the row overlays the bottom edge while focused.
g.settings.displayModeSetting.value = '640x480';
assert.deepEqual(g.rect('max'), { x: 0, y: 28, width: 640, height: 452 });
// Full Screen: windows take the panel's width over the row, which stays.
g.settings.displayLayoutSetting.value = 'fullscreen';
assert.deepEqual(g.rect('max'), { x: 0, y: 28, width: 640, height: 416 });
assert.deepEqual({ ...g.switcherRect('max') }, { x: 0, y: 444, width: 640, height: 36 });
assert.equal(g.sidebarStripVisible('window'), false);
assert.equal(g.sidebarStripVisible('sidebar'), true);
assert.equal(g.sidebarStripVisible('window'), true);
assert.equal(g.windowFramed(), false);
});
test('an immersive app fills the panel without chrome rows, frame or depth, in any layout', () => {
const panel = { x: 0, y: 0, width: 640, height: 480 };
for (const position of ['left', 'right', 'bottom', 'popup']) {
const g = geometry();
g.settings.appSwitcherPositionSetting.value = position;
g.settings.statusBarPositionSetting.value = 'bottom';
g.settings.uiDepthSetting.value = '48';
assert.equal(g.setAppImmersive('onboarding', true), true);
assert.equal(g.setAppImmersive('onboarding', true), false);
for (const mode of ['min', 'medium', 'max']) assert.deepEqual(g.rect(mode, 'onboarding'), panel, position);
assert.equal(g.windowFramed('onboarding'), false);
assert.equal(g.statusInSwitcherRow('onboarding'), false);
// The switcher overlays it while focused.
assert.equal(g.sidebarStripVisible('window', 'onboarding'), false);
assert.equal(g.sidebarStripVisible('sidebar', 'onboarding'), true);
assert.equal(g.uiDepth('onboarding'), 0);
// Other apps keep the layout and its depth.
const depth = position === 'bottom' || position === 'popup' ? 48 : 0;
assert.equal(g.uiDepth('launcher'), depth);
assert.equal(g.uiDepth(), depth);
assert.notDeepEqual(g.rect('min', 'launcher'), panel);
assert.equal(g.setAppImmersive('onboarding', false), true);
assert.deepEqual(g.rect('min', 'onboarding'), g.rect('min', 'launcher'));
assert.equal(g.uiDepth('onboarding'), depth);
}
});
test('the phone mirror zooms to the area the shell uses, centred at the panel\'s 4:3', () => {
const g = geometry();
const preview = (mode, appId) => {
const used = { ...g.usedScreenRect(mode, appId) };
return { used, shown: { ...g.phonePreviewRect(used) } };
};
const panel = { x: 0, y: 0, width: 640, height: 480 };
// A side strip and band: the panel's width, so only centring vertically.
assert.deepEqual(preview('min'), { used: { x: 0, y: 96, width: 640, height: 288 }, shown: panel });
g.settings.displayLayoutSetting.value = 'band-top';
assert.deepEqual(preview('min').shown, { x: 0, y: -96, width: 640, height: 480 });
g.settings.appSwitcherPositionSetting.value = 'right';
g.settings.displayLayoutSetting.value = 'band-high';
assert.deepEqual(preview('min'), { used: { x: 0, y: 48, width: 640, height: 288 }, shown: { x: 0, y: -48, width: 640, height: 480 } });
// A bottom row: the band with the frame's sides, and the row under it.
g.settings.appSwitcherPositionSetting.value = 'bottom';
g.settings.displayLayoutSetting.value = 'band-middle';
assert.deepEqual(preview('min'), { used: { x: 31, y: 78, width: 578, height: 324 }, shown: { x: 30, y: 23, width: 580, height: 435 } });
// A tall window (the terminal's default) leaves just the frame's margins.
assert.deepEqual(preview('max', 'terminal'), { used: { x: 31, y: 0, width: 578, height: 480 }, shown: panel });
// A popup shows within the window: just the band.
g.settings.appSwitcherPositionSetting.value = 'popup';
assert.deepEqual(preview('min'), { used: { x: 31, y: 96, width: 578, height: 288 }, shown: { x: 30, y: 23, width: 580, height: 435 } });
// Full Screen and immersive windows use the whole panel.
g.settings.displayLayoutSetting.value = 'fullscreen';
assert.deepEqual(preview('min'), { used: panel, shown: panel });
g.settings.displayLayoutSetting.value = 'band-middle';
g.setAppImmersive('onboarding', true);
assert.deepEqual(preview('min', 'onboarding'), { used: panel, shown: panel });
// Every layout's shown area is exactly 4:3 and contains the used area.
for (const position of ['left', 'right', 'bottom', 'popup']) {
g.settings.appSwitcherPositionSetting.value = position;
for (const layout of LAYOUTS) {
g.settings.displayLayoutSetting.value = layout;
for (const mode of ['min', 'medium', 'max']) {
const { used, shown } = preview(mode);
assert.equal(shown.width * 3, shown.height * 4);
assert.ok(shown.width <= 640 && shown.height <= 480);
assert.ok(shown.x <= used.x && shown.y <= used.y);
assert.ok(shown.x + shown.width >= used.x + used.width && shown.y + shown.height >= used.y + used.height);
}
}
}
});
test('the mirror\'s crop follows Preview scaling, the Glanceboard and the lock, and maps taps back to the panel', () => {
const g = geometry();
const scaling = { value: 'scaled', get() { return this.value; } };
let foreground = { heightMode: 'min', appId: 'launcher' };
const modules = {
'../graphics/image': { G2_LENS_WIDTH: 640, G2_LENS_HEIGHT: 480 },
'../ui/dashboard-settings': { previewScalingSetting: scaling },
'../ui/shell/geometry': g,
'../ui/shell/shell': { shell: { foregroundWindow: () => foreground } },
};
const context = { exports: {}, require: (name) => modules[name] };
vm.runInNewContext(js(read('app/g2/phone-preview-crop.ts')), context);
const { phonePreviewCrop, mirrorToPanelFraction } = context.exports;
const crop = (locked = false, glance = null) => {
const rect = phonePreviewCrop(locked, glance);
return rect && { ...rect };
};
g.settings.appSwitcherPositionSetting.value = 'bottom';
const band = { x: 30, y: 23, width: 580, height: 435 };
assert.deepEqual(crop(), band);
// The whole panel is no crop at all.
foreground = { heightMode: 'max', appId: 'terminal' };
assert.equal(crop(), null);
foreground = null;
assert.deepEqual(crop(), band);
// The Glanceboard while it shows; a locked display's centred box needs the panel.
assert.deepEqual(crop(false, { x: 32, y: 48, width: 576, height: 432 }), { x: 32, y: 48, width: 576, height: 432 });
assert.deepEqual(crop(false, { x: 32, y: 96, width: 576, height: 288 }), { x: 32, y: 24, width: 576, height: 432 });
assert.equal(crop(true), null);
scaling.value = 'raw';
assert.equal(crop(), null);
// Taps: the mirror's corners are the crop's, its margins past the panel's edges.
assert.deepEqual({ ...mirrorToPanelFraction(null, 0.25, 0.75) }, { nx: 0.25, ny: 0.75 });
assert.deepEqual({ ...mirrorToPanelFraction(band, 0, 0) }, { nx: 30 / 640, ny: 23 / 480 });
assert.deepEqual({ ...mirrorToPanelFraction(band, 1, 1) }, { nx: 610 / 640, ny: 458 / 480 });
const above = mirrorToPanelFraction({ x: 0, y: -96, width: 640, height: 480 }, 0.5, 0.1);
assert.ok(above.ny < 0);
});
// The real chrome layer over the given geometry, with platform pieces stubbed:
// a 4px-per-character font that paints each character as a 2x6 block, up to
// `notifications` 24px notification icons (keyed n0, n1, ...), and a phone
@@ -223,7 +366,7 @@ function chromeLayer(g, { notifications = 0, phoneBattery = null, windows = 1, t
'../../graphics/textwrap': require('../.test-build/app/graphics/textwrap.js'),
'../../graphics/battery': require('../.test-build/app/graphics/battery.js'),
'./ambient-cards': { activeAmbientCards: () => [] },
'../../native/notification-icons': { readActiveNotificationIcons: (max) => {
'../../native/notification-icons': { ALL_NOTIFICATIONS: 0x7fffffff, readActiveNotificationIcons: (max) => {
requested.push(max);
const count = Math.min(max, notifications);
return { icons: Array.from({ length: count }, () => new graphics.GrayImage(24, 24, 200)),
@@ -248,8 +391,12 @@ function chromeLayer(g, { notifications = 0, phoneBattery = null, windows = 1, t
selectedIndex: 0, focus: 'window', foregroundHeightMode: 'min',
battery: { headset: null, ring: null, watch: null }, trayIcons,
};
return { chrome: new context.exports.ShellChromeLayer(() => state), state, requested };
let heightChanges = 0;
const chrome = new context.exports.ShellChromeLayer(() => state, () => heightChanges++);
return { chrome, state, requested, planBottomBar: context.exports.planBottomBar, heightChanges: () => heightChanges };
}
const notification = (key) => ({ kind: 'notification', key });
const keysOf = (items) => Array.from(items, (item) => item.key);
test('a bottom app switcher frames the foreground window\'s content in a rounded border', () => {
const g = geometry();
@@ -291,11 +438,30 @@ test('a bottom app switcher frames the foreground window\'s content in a rounded
// The flat paint carries the same frame.
const image = chrome.paint();
assert.deepEqual(frames(image).map((d) => [d.x, d.y]), [[31, 105]]);
// No frame in the full-panel mode.
g.settings.displayModeSetting.value = '640x480';
// No frame in the Full Screen mode.
g.settings.displayLayoutSetting.value = 'fullscreen';
assert.equal(chrome.paintParts().flatMap((p) => frames(p.image)).length, 0);
});
test('over an immersive window the chrome draws only the switcher, and only while it has focus', () => {
for (const position of ['bottom', 'popup', 'left']) {
const g = geometry();
g.settings.appSwitcherPositionSetting.value = position;
g.settings.statusBarPositionSetting.value = position === 'left' ? 'top' : 'bottom';
g.setAppImmersive('onboarding', true);
const { chrome, state } = chromeLayer(g, { windows: 2, notifications: 1 });
state.foregroundAppId = 'onboarding';
assert.equal(chrome.paintParts().length, 0, position);
assert.equal(chrome.paint().pixels.some((value) => value !== 0), false, position);
state.focus = 'sidebar';
const parts = chrome.paintParts();
// No status bar (key 2), not even in a bottom row.
assert.equal(parts.length, 1, position);
assert.notEqual(parts[0].shellKey, 2, position);
if (position === 'bottom') assert.deepEqual([parts[0].x, parts[0].y, parts[0].image.width], [0, 444, 640]);
}
});
test('the launcher\'s tab lines up with the window frame, whose corner squares to meet it', () => {
const g = geometry();
g.settings.appSwitcherPositionSetting.value = 'bottom';
@@ -327,12 +493,13 @@ test('the launcher\'s tab lines up with the window frame, whose corner squares t
({ px, at } = paint(chrome));
assert.deepEqual([px(31, 365), px(32, 365), at(35, 366), at(36, 366)], [0, 0, 1, 40]);
assert.equal(chrome.windowIndexAt(31, 380, 3), 0);
// Scrolled past the launcher, the cells keep the left chevron's margin.
const scrolled = chromeLayer(g, { windows: 20 });
scrolled.state.selectedIndex = 19;
// Scrolled past the launcher (more windows than two rows of 14 hold), the
// cells keep the left chevron's margin.
const scrolled = chromeLayer(g, { windows: 40 });
scrolled.state.selectedIndex = 39;
({ px } = paint(scrolled.chrome));
assert.equal(scrolled.chrome.windowIndexAt(35, 380, 20), null);
assert.notEqual(scrolled.chrome.windowIndexAt(41, 380, 20), null);
assert.equal(scrolled.chrome.windowIndexAt(35, 380, 40), null);
assert.notEqual(scrolled.chrome.windowIndexAt(41, 380, 40), null);
assert.equal(px(31, 365), 0);
});
@@ -350,10 +517,10 @@ test('the status bar can join a bottom app switcher, and windows grow into the t
assert.deepEqual(g.rect('medium'), { x: 32, y: 79, width: 576, height: 288 });
assert.deepEqual(g.rect('max', 'terminal'), { x: 32, y: 1, width: 576, height: 443 });
assert.deepEqual({ ...g.switcherRect('min') }, { x: 32, y: 366, width: 576, height: 36 });
// The full-panel mode keeps the top bar: its row shows only while focused.
g.settings.displayModeSetting.value = '640x480';
assert.equal(g.statusInSwitcherRow(), false);
assert.deepEqual(g.rect('max'), { x: 0, y: 28, width: 640, height: 452 });
// Full Screen keeps the row, and the status bar in it, but has no frame.
g.settings.displayLayoutSetting.value = 'fullscreen';
assert.equal(g.statusInSwitcherRow(), true);
assert.deepEqual(g.rect('max'), { x: 0, y: 0, width: 640, height: 444 });
});
test('the switcher row lays out windows, free space, notifications, widgets, batteries and the clock', () => {
@@ -361,7 +528,7 @@ test('the switcher row lays out windows, free space, notifications, widgets, bat
g.settings.appSwitcherPositionSetting.value = 'bottom';
g.settings.statusBarPositionSetting.value = 'bottom';
const tray = new graphics.GrayImage(30, 20, 180);
const { chrome, requested } = chromeLayer(g, { notifications: 2, phoneBattery: 80, trayIcons: [tray] });
const { chrome, requested } = chromeLayer(g, { notifications: 2, phoneBattery: 80, trayIcons: [{ ownerId: 'w', icon: tray }] });
const parts = chrome.paintParts();
// No top bar: the row, then the status bar on the top bar's surface and depth.
assert.deepEqual(Array.from(parts, (p) => [p.shellKey, p.depth ?? 0]), [[1, 0], [2, -2]]);
@@ -381,35 +548,144 @@ test('the switcher row lays out windows, free space, notifications, widgets, bat
assert.equal(at(row, 40 + 2, 366 + 2), 120, 'first window icon');
assert.equal(chrome.windowIndexAt(45, 380, 1), 0);
assert.equal(chrome.windowIndexAt(iconsLeft + 2, 380, 1), null);
// Notification icons stop short of the one window slot's room (with the
// row's margins and the gap to the status bar).
assert.equal(requested.at(-1), Math.floor((trayLeft - 8 - (32 + 20 + 40 - 8 + 8) + 4) / 28));
// The row asks for every notification icon, to lay itself out round them all.
assert.equal(requested.at(-1), 0x7fffffff);
// No top bar, but the frame is still there, its top one row above the content.
const [frame] = row.image.draws.filter((d) => d.presentation?.displayList);
assert.deepEqual([row.x + frame.x, row.y + frame.y, frame.source.height], [31, 78, 289]);
shellScene.encodeShellScene(parts, g.uiDepth());
});
test('many windows scroll in what the notification icons leave them', () => {
test('past two rows of windows, they scroll, and notification icons give way to a few slots a row', () => {
const g = geometry();
g.settings.appSwitcherPositionSetting.value = 'bottom';
g.settings.statusBarPositionSetting.value = 'bottom';
const { chrome, requested } = chromeLayer(g, { notifications: 40, windows: 12 });
const { chrome, requested, heightChanges } = chromeLayer(g, { notifications: 40, windows: 12 });
const [row, status] = chrome.paintParts();
// Clock only (no batteries or widgets): notifications end 8px before its
// 8px lead-in, and stop where three window slots plus margins remain.
const trayLeft = 608 - 56 - 8, floor = 32 + 20 + 3 * 40 - 8 + 8;
const max = Math.floor((trayLeft - 8 - floor + 4) / 28);
assert.equal(requested.at(-1), max);
const iconsLeft = trayLeft - 8 - max * 28 + 4;
assert.equal(status.x, iconsLeft - 2);
// Three windows fit before the status bar's gap; the rest scroll, with the
// chevron at the end of the windows rather than of the row.
assert.equal(requested.at(-1), 0x7fffffff);
// The last layout: two rows of each, 72px tall, under the unmoved band.
assert.equal(g.switcherRowHeight(), 72);
assert.equal(heightChanges(), 1);
assert.deepEqual([row.y, row.image.height], [366, 72]);
// Notification icons drop from the end until the two status rows leave
// three window slots a row (32 + 20 + 3 * 40 - 8, and the gap): 28 stay,
// 15 in the first row (416px) and 13 with the clock in the second (432px).
assert.equal(chrome.statusItems().length, 28);
assert.deepEqual([status.x, status.y, status.image.height], [608 - 432 - 2, 367, 71]);
const at = (p, x, y) => p.image.withDrawsBaked().pixels[(y - p.y) * p.image.width + x - p.x];
assert.deepEqual([at(status, 608 - 416, 366 + 5 + 2), at(status, 608 - 432, 366 + 36 + 5 + 2)], [200, 200]);
// Three windows a row; the rest scroll, with the chevron after the second
// row's, at the end of the windows rather than of the row.
assert.equal(chrome.windowIndexAt(32 + 10 + 2 * 40 + 4, 380, 12), 2);
assert.equal(chrome.windowIndexAt(32 + 10 + 3 * 40 + 4, 380, 12), null);
const windowsRight = iconsLeft - 8;
const chevron = row.image.pixels.findIndex((v, i) => v === 140);
assert.equal(chevron % row.image.width + row.x, windowsRight - 6);
assert.equal(chrome.windowIndexAt(32 + 10 + 2 * 40 + 4, 420, 12), 5);
const windowsRight = 608 - 432 - 8;
const chevron = row.image.pixels.findIndex((v) => v === 140);
assert.deepEqual([chevron % row.image.width + row.x, Math.floor(chevron / row.image.width) + row.y], [windowsRight - 6, 366 + 36 + 18 - 5]);
});
test('the bottom switcher falls back to denser layouts as what it holds outgrows it', () => {
const { planBottomBar } = chromeLayer(geometry());
const notifications = (count) => Array.from({ length: count }, () => ({ kind: 'notification', width: 24 }));
const clock = { kind: 'clock', width: 56 };
const summary = (plan) => [plan.level, plan.height, plan.windowRows, plan.windowColumns,
Array.from(plan.statusRows, (items) => items.length), plan.statusWidth, plan.statusPitch];
// Three windows (132px with margins) and five icons and the clock fit one row.
assert.deepEqual(summary(planBottomBar(576, 3, [...notifications(5), clock])), [1, 36, 1, 8, [6], 208, 28]);
// Fourteen icons don't (28 * 14 - 4 + 16 + 56 > 576 - 132 - 8), so the
// status bar takes two rows, broken where they come nearest the same
// width: 8 icons (220px) over 6 and the clock (236px), a top bar apart.
const many = [...notifications(14), clock];
assert.deepEqual(summary(planBottomBar(576, 3, many)), [2, 64, 1, 8, [8, 7], 236, 28]);
// Nine windows don't fit the one row of 8 slots that leaves: two rows of
// windows, the status rows level with them.
assert.deepEqual(summary(planBottomBar(576, 9, many)), [3, 72, 2, 8, [8, 7], 236, 36]);
// Seventeen don't fit those 16 slots: the last layout scrolls them.
assert.deepEqual(summary(planBottomBar(576, 17, many)), [4, 72, 2, 8, [8, 7], 236, 36]);
// Without the status bar, the windows alone: 14 a row.
assert.deepEqual(summary(planBottomBar(576, 14, [])), [1, 36, 1, 14, [], 0, 28]);
assert.deepEqual(summary(planBottomBar(576, 15, [])), [3, 72, 2, 14, [], 0, 36]);
assert.deepEqual(summary(planBottomBar(576, 29, [])), [4, 72, 2, 14, [], 0, 36]);
// A full-width (640) row has room for more.
assert.equal(planBottomBar(640, 3, many).level, 1);
});
test('a taller bottom switcher takes its room from the slack under a band, or from full-height windows', () => {
const g = geometry();
g.settings.appSwitcherPositionSetting.value = 'bottom';
g.settings.statusBarPositionSetting.value = 'bottom';
const before = g.rect('min');
assert.equal(g.setSwitcherBarHeight(64), true);
assert.equal(g.setSwitcherBarHeight(64), false);
// The band stays put, the switcher growing down into the slack under it...
assert.deepEqual(g.rect('min'), before);
assert.deepEqual({ ...g.switcherRect('min') }, { x: 32, y: 366, width: 576, height: 64 });
assert.equal(g.isOnSwitcherEdge(10, 420, 'min'), true);
// ...pushing it up only where there's too little.
g.settings.displayLayoutSetting.value = 'band-low';
assert.equal(g.windowTop('min'), 117);
g.settings.displayLayoutSetting.value = 'band-bottom';
assert.equal(g.windowTop('min'), 480 - 64 - 288);
assert.equal(g.switcherRect('min').y + 64, 480);
// Tall windows give up the height.
g.settings.displayLayoutSetting.value = 'tall';
assert.deepEqual(g.rect('max'), { x: 32, y: 1, width: 576, height: 415 });
g.settings.displayLayoutSetting.value = 'band-middle';
assert.deepEqual(g.rect('max', 'terminal'), { x: 32, y: 1, width: 576, height: 415 });
// Over an immersive window the switcher is an overlay of its own height,
// which moves no window.
g.setAppImmersive('onboarding', true);
assert.equal(g.setSwitcherBarHeight(72, 'onboarding'), false);
assert.deepEqual({ ...g.switcherRect('min', 'onboarding') }, { x: 0, y: 408, width: 640, height: 72 });
assert.equal(g.switcherRowHeight(), 64);
// Beside a side strip it takes nothing.
g.settings.appSwitcherPositionSetting.value = 'left';
assert.equal(g.switcherRowHeight(), 0);
});
test('the status bar takes a second row of its own before the windows do', () => {
const g = geometry();
g.settings.appSwitcherPositionSetting.value = 'bottom';
g.settings.statusBarPositionSetting.value = 'bottom';
const { chrome, heightChanges } = chromeLayer(g, { notifications: 14, windows: 3 });
const before = g.rect('min');
const [row, status] = chrome.paintParts();
assert.equal(g.switcherRowHeight(), 64);
assert.equal(heightChanges(), 1);
chrome.paintParts();
assert.equal(heightChanges(), 1, 'reported once');
assert.deepEqual(g.rect('min'), before);
// Both rows right-aligned against the row's end: 8 icons (220px) over 6
// and the clock (236px), a top bar's height apart.
assert.deepEqual([status.x, status.y, status.image.height], [608 - 236 - 2, 367, 63]);
const at = (p, x, y) => p.image.withDrawsBaked().pixels[(y - p.y) * p.image.width + x - p.x];
assert.deepEqual([at(status, 608 - 220, 371 + 2), at(status, 608 - 236, 371 + 28 + 2), at(status, 608 - 56, 371 + 28 + 8 + 2)],
[200, 200, 210]);
assert.deepEqual(keysOf(chrome.statusItems()), Array.from({ length: 14 }, (_, i) => `n${i}`));
// The windows keep one row, against the window.
assert.equal(chrome.windowIndexAt(45, 380, 3), 0);
assert.equal(chrome.windowIndexAt(45, 410, 3), null);
assert.equal(row.image.height, 64);
});
test('windows past one row take a second, where a selected one sits in a box', () => {
const g = geometry();
g.settings.appSwitcherPositionSetting.value = 'bottom';
g.settings.statusBarPositionSetting.value = 'bottom';
const { chrome, state } = chromeLayer(g, { notifications: 14, windows: 9 });
state.selectedIndex = 8;
const [row, status] = chrome.paintParts();
assert.equal(g.switcherRowHeight(), 72);
// Eight slots a row (what the 236px status rows leave); the ninth window
// starts the second row, under the first.
assert.deepEqual([chrome.windowIndexAt(31 + 7 * 40, 380, 9), chrome.windowIndexAt(31, 410, 9), chrome.windowIndexAt(71, 410, 9)], [7, 8, null]);
const at = (p, x, y) => p.image.pixels[(y - p.y) * p.image.width + x - p.x];
// Its selection is a box (as for a sidebar overflow column), and the
// separator runs unbroken over the first row.
assert.deepEqual([at(row, 31, 402 + 18), at(row, 31 + 5, 402 + 7)], [150, 120]);
assert.equal(at(row, 50, 366), 40);
// The status rows line up with the window rows.
assert.equal(status.image.withDrawsBaked().pixels[(366 + 36 + 5 + 2 - status.y) * status.image.width + 608 - 236 - status.x], 200);
});
test('a popup app switcher shows a box of window icons over the dimmed window while focused', () => {
@@ -498,52 +774,98 @@ test('a notification the switcher selects sits in a box, filled with its icon in
g.settings.appSwitcherPositionSetting.value = 'bottom';
g.settings.statusBarPositionSetting.value = 'bottom';
const { chrome, state } = chromeLayer(g, { notifications: 3, windows: 2 });
Object.assign(state, { selectedIndex: -1, selectedNotificationKey: 'n1', focus: 'sidebar' });
Object.assign(state, { selectedIndex: -1, selectedStatusItem: notification('n1'), focus: 'sidebar' });
let [row, status] = chrome.paintParts();
assert.deepEqual(Array.from(chrome.notificationKeys()), ['n0', 'n1', 'n2']);
assert.deepEqual(keysOf(chrome.statusItems()), ['n0', 'n1', 'n2']);
// Clock only: the icons end 8px before its 8px lead-in, 28px apart, each
// 7 rows into the row (the top bar's layout, 5 rows down).
const iconsLeft = 608 - 56 - 8 - 8 - 3 * 28 + 4, iconY = 366 + 7, n1 = iconsLeft + 28;
const at = (p, x, y) => p.image.withDrawsBaked().pixels[(y - p.y) * p.image.width + x - p.x];
// The box: 2px either side of the icon, 1px above and below, white; the
// icon inside it inverted; its neighbours as ever.
// icon inside it inverted (bright, so to black); its neighbours as ever.
assert.deepEqual([at(status, n1 - 2, iconY + 12), at(status, n1 + 25, iconY + 12), at(status, n1 + 12, iconY - 1)], [255, 255, 255]);
assert.equal(at(status, n1 + 12, iconY - 2), 1);
assert.deepEqual([at(status, n1 + 5, iconY + 5), at(status, iconsLeft + 5, iconY + 5)], [55, 200]);
assert.deepEqual([at(status, n1 + 5, iconY + 5), at(status, iconsLeft + 5, iconY + 5)], [1, 200]);
// No window is selected: the separator runs unbroken over the windows.
assert.equal(at(row, 50, 366), 40);
// Mirror touches find the icons by their boxes, which tile the icons' run.
assert.deepEqual([chrome.notificationKeyAt(n1 + 5, 380), chrome.notificationKeyAt(n1 - 3, 380),
chrome.notificationKeyAt(iconsLeft - 3, 380), chrome.notificationKeyAt(n1 + 5, 400)], ['n1', 'n0', null, null]);
const keyAt = (x, y) => chrome.statusItemAt(x, y)?.key ?? null;
assert.deepEqual([keyAt(n1 + 5, 380), keyAt(n1 - 3, 380), keyAt(iconsLeft - 3, 380), keyAt(n1 + 5, 400)], ['n1', 'n0', null, null]);
// With its detail view focused instead, the box is an outline round the plain icon.
state.focus = 'window';
[, status] = chrome.paintParts();
assert.deepEqual([at(status, n1 - 2, iconY + 12), at(status, n1 - 1, iconY + 12), at(status, n1 + 5, iconY + 5)], [150, 1, 200]);
// The first icon's box fits the status bar's surface.
state.selectedNotificationKey = 'n0';
state.selectedStatusItem = notification('n0');
[, status] = chrome.paintParts();
assert.equal(at(status, iconsLeft - 2, iconY + 12), 150);
// In the top bar (the status bar's default place) likewise; barTop=78.
g.settings.statusBarPositionSetting.value = 'top';
const [bar] = chrome.paintParts();
const barIconsLeft = 32 + 10 + 56 + 16;
assert.deepEqual(Array.from(chrome.notificationKeys()), ['n0', 'n1', 'n2']);
assert.deepEqual(keysOf(chrome.statusItems()), ['n0', 'n1', 'n2']);
assert.deepEqual([at(bar, barIconsLeft - 2, 78 + 14), at(bar, barIconsLeft + 5, 78 + 7)], [150, 200]);
assert.equal(chrome.notificationKeyAt(barIconsLeft + 30, 78 + 10), 'n1');
assert.equal(keyAt(barIconsLeft + 30, 78 + 10), 'n1');
});
test('an app widget the switcher selects sits in a box as a notification does, after the notifications', () => {
const g = geometry();
g.settings.appSwitcherPositionSetting.value = 'bottom';
g.settings.statusBarPositionSetting.value = 'bottom';
// A faint 30x20 widget, its bright text a deferred draw, and a 12x16 one.
const wide = new graphics.GrayImage(30, 20, 0);
wide.fillRect(0, 0, 30, 20, 16);
wide.drawImage(new graphics.GrayImage(4, 4, 220), 10, 8);
const small = new graphics.GrayImage(12, 16, 160);
const { chrome, state } = chromeLayer(g, { notifications: 2, windows: 2,
trayIcons: [{ ownerId: 'nightscout', icon: wide }, { ownerId: 'timer', icon: small }] });
Object.assign(state, { selectedIndex: -1, selectedStatusItem: { kind: 'widget', key: 'nightscout' }, focus: 'sidebar' });
let [, status] = chrome.paintParts();
// Notifications first, then the widgets, as they sit left to right.
assert.deepEqual(Array.from(chrome.statusItems(), (item) => `${item.kind}:${item.key}`),
['notification:n0', 'notification:n1', 'widget:nightscout', 'widget:timer']);
// Right to left from the row's end: the clock (56px), its 16px lead-in,
// the small widget, 10px, the wide one. Each centred in the top bar's
// layout, 5 rows into the row.
const smallLeft = 608 - 56 - 16 - 12, wideLeft = smallLeft - 10 - 30, wideTop = 366 + 5 + 4;
const at = (p, x, y) => p.image.withDrawsBaked().pixels[(y - p.y) * p.image.width + x - p.x];
// The box: 2px either side, as tall as a notification's (rows 1..26 of
// the layout) whatever the widget's height; white, with the widget
// inverted inside it, its deferred draw too. The inversion is perceptual:
// the faint fill (level 1) becomes mid-gray level 7, the bright text black.
assert.deepEqual([at(status, wideLeft - 2, 366 + 5 + 14), at(status, wideLeft + 31, 366 + 5 + 14),
at(status, wideLeft + 15, 366 + 5 + 1), at(status, wideLeft + 15, 366 + 5 + 26)], [255, 255, 255, 255]);
assert.equal(at(status, wideLeft + 15, 366 + 5 + 27), 1);
assert.deepEqual([at(status, wideLeft + 2, wideTop + 2), at(status, wideLeft + 11, wideTop + 9)], [112, 1]);
assert.equal(at(status, smallLeft + 2, 366 + 5 + 8), 160);
// Mirror touches find widgets by their boxes too.
assert.deepEqual({ ...chrome.statusItemAt(wideLeft - 1, 380) }, { kind: 'widget', key: 'nightscout' });
assert.deepEqual({ ...chrome.statusItemAt(smallLeft + 13, 380) }, { kind: 'widget', key: 'timer' });
// With its window focused instead, an outline round the plain widget.
state.focus = 'window';
[, status] = chrome.paintParts();
assert.deepEqual([at(status, wideLeft - 2, 366 + 5 + 14), at(status, wideLeft + 2, wideTop + 2)], [150, 16]);
// In the top bar likewise, the notifications still before the widgets
// though drawn after them; barTop=78.
g.settings.statusBarPositionSetting.value = 'top';
const [bar] = chrome.paintParts();
assert.deepEqual(Array.from(chrome.statusItems(), (item) => item.key), ['n0', 'n1', 'nightscout', 'timer']);
const barWideLeft = 608 - 10 - 12 - 10 - 30;
assert.deepEqual([at(bar, barWideLeft - 2, 78 + 14), at(bar, barWideLeft + 2, 78 + 6)], [150, 16]);
});
test('with the selection out on a notification, the windows stay scrolled as they were', () => {
const g = geometry();
g.settings.appSwitcherPositionSetting.value = 'bottom';
const { chrome, state } = chromeLayer(g, { notifications: 2, windows: 20 });
state.selectedIndex = 19;
const { chrome, state } = chromeLayer(g, { notifications: 2, windows: 40 });
state.selectedIndex = 39;
chrome.paintParts();
const last = 32 + 10 + 2 * 40 + 4;
const before = chrome.windowIndexAt(last, 380, 20);
const before = chrome.windowIndexAt(last, 380, 40);
assert.ok(before > 2);
Object.assign(state, { selectedIndex: -1, selectedNotificationKey: 'n0' });
Object.assign(state, { selectedIndex: -1, selectedStatusItem: notification('n0') });
chrome.paintParts();
assert.equal(chrome.windowIndexAt(last, 380, 20), before);
assert.equal(chrome.windowIndexAt(last, 380, 40), before);
});
// Exercise the real worker message handler with platform work stubbed out.
@@ -599,6 +921,33 @@ test('Terminal resize keeps the view identity, negotiates its grid and skips pos
assert.equal(calls.length, 6);
});
test('the games and Roam resize in place, keeping their state, and repaint when in front', () => {
for (const app of ['blocks', 'freecell', 'minesweeper', 'pinball']) {
let paints = 0, menuSize;
const window = { windowId: 'test', viewportWidth: 576, viewportHeight: 443, foreground: true, phase: 'playing',
menu: { resize: (size) => { menuSize = size; } }, lastSubmittedFingerprint: 'old' };
const resize = resizeHandler(`app/apps/${app}/${app}-app.worker.ts`, {
windows: new Map([['test', window]]), renderAndSubmit: () => paints++,
});
resize({ width: 576, height: 415 });
assert.deepEqual([window.viewportWidth, window.viewportHeight, window.phase, window.lastSubmittedFingerprint, paints],
[576, 415, 'playing', '', 1], app);
assert.deepEqual({ ...menuSize }, { width: 576, height: 415 }, app);
window.foreground = false;
resize({ width: 576, height: 443 });
assert.deepEqual([window.viewportHeight, paints], [443, 1], app);
}
let paints = 0, viewSize;
const window = { windowId: 'test', viewportWidth: 576, viewportHeight: 443, menu: null, lastSubmittedFingerprint: 'old',
view: { resize: (...size) => { viewSize = size; } } };
const resize = resizeHandler('app/apps/roam/roam-app.worker.ts', {
window, render: () => paints++, DOC_MARGIN: 6, HEADER_HEIGHT: 30, BOTTOM_MARGIN: 6,
});
resize({ width: 576, height: 415 });
// The document re-wraps for the region under its header.
assert.deepEqual([window.viewportHeight, viewSize, window.lastSubmittedFingerprint, paints], [415, [564, 379], '', 1]);
});
test('resizing a terminal reconnects with the new grid and ignores callbacks from the old socket', () => {
const sockets = [];
const context = {
@@ -612,7 +961,7 @@ test('resizing a terminal reconnects with the new grid and ignores callbacks fro
},
} } },
};
const socketContext = { exports: {}, com: context.com };
const socketContext = { exports: {}, com: context.com, require: () => ({ toJavaBytes: bytes => bytes }) };
vm.runInNewContext(js(read('app/native/socket.ts')), socketContext);
context.require = name => name === './socket' ? socketContext.exports : {};
vm.runInNewContext(js(read('app/native/g2mirror-client.ts')), context);
+25
View File
@@ -193,3 +193,28 @@ test('an unsolicited Soniox session end finalizes visible text and reconnects',
assert.equal(h.sockets.length, 2);
h.client.stop();
});
test('provider selection falls back to on-device without a key and connects the chosen provider with one', () => {
const sockets = [];
const load = loader({
setTimeout() {}, clearTimeout() {}, console: { log() {}, warn() {} },
com: { faceclaw: { app: {
FaceclawWebSocketListener: function(callbacks) { return callbacks; },
FaceclawWebSocket: class { constructor(url, _listener, header, value) { sockets.push({ url, header, value }); } },
} } },
}, { './cloud-stt': { CLOUD_STT_SAMPLE_RATE: 16000, encodeBase64: () => '', toJavaBytes: bytes => bytes } });
const { createCloudSttClient, usesCloudStt } = load('app/native/cloud-stt-provider.ts');
const statuses = [];
const options = { onTranscript() {}, onStatus: status => statuses.push(status), onError() {} };
const selection = { provider: 'onboard', elevenLabsApiKey: '', openAiApiKey: ' ', sonioxApiKey: 'soniox-key' };
assert.equal(usesCloudStt(selection), false);
assert.equal(createCloudSttClient(selection, options, () => false), null);
assert.equal(usesCloudStt({ ...selection, provider: 'whisper' }), false);
assert.equal(createCloudSttClient({ ...selection, provider: 'whisper' }, options, () => false), null);
assert.deepEqual(statuses, ['No OpenAI key set; using on-device voice.']);
assert.equal(usesCloudStt({ ...selection, provider: 'soniox' }), true);
createCloudSttClient({ ...selection, provider: 'soniox' }, options, () => false).start();
createCloudSttClient({ ...selection, provider: 'elevenlabs', elevenLabsApiKey: ' xi ' }, options, () => false).start();
assert.deepEqual(sockets.map(({ url, header, value }) => [new URL(url).host, header, value]),
[['stt-rt.soniox.com', null, null], ['api.elevenlabs.io', 'xi-api-key', 'xi']]);
});
+149
View File
@@ -0,0 +1,149 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
function load(file, modules = {}) {
const source = fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
const context = { exports: {}, require: (name) => modules[name] ?? {}, console, Date };
vm.runInNewContext(ts.transpileModule(source, {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText, context, { filename: file });
return context.exports;
}
const textwrap = load('app/graphics/textwrap.ts');
const graphics = require('../.test-build/app/graphics/image.js');
const plane = load('app/graphics/plane.ts', { './image': graphics });
const gestures = load('app/ui/gestures.ts');
const { BdfFont } = load('app/graphics/bdffont.ts');
const font = (name) => BdfFont.parse(fs.readFileSync(path.join(__dirname, `../app/fonts/terminus/${name}.bdf`), 'utf8'));
const fonts = { getDefaultSmallFont: () => font('ter-u12n'), getDefaultMediumFont: () => font('ter-u16n') };
const layers = load('app/ui/layers.ts', {
'../graphics/image': graphics, '../graphics/plane': plane, './gestures': gestures,
'../native/frame-timings': { spanCurrent: (_name, paint) => paint() },
});
const picker = load('app/ui/date-picker.ts', {
'../graphics/textwrap': textwrap, '../graphics/ui-fonts': fonts, './gestures': gestures,
'./menu': { CONTEXT_MENU_DIM: 0.25 }, './metrics': load('app/ui/metrics.ts'),
});
const day = (year, month, date) => ({ year, month: month - 1, day: date });
// Copied into this realm: the module's objects carry the vm context's prototypes.
const step = (...args) => ({ ...picker.stepCalendarDay(...args) });
function fixture(initial = new Date(2026, 9, 14), size = { width: 576, height: 260 }) {
const picks = [];
let cancels = 0;
const base = { paint: () => new graphics.GrayImage(size.width, size.height, 0), handleInput() {} };
const stack = new layers.LayerStack(base, layers.noopLayerActions, size);
const layer = new picker.DatePickerLayer({
title: 'Go to date', initial, onPick: (date) => picks.push(date), onCancel: () => cancels++,
});
stack.push(layer);
return {
stack, layer, picks, cancels: () => cancels,
input: async (...types) => {
for (const type of types) await stack.handleInput(gestures.makeInputEvent({ type, source: 'ring' }));
},
};
}
test('day steps roll across months and years', () => {
assert.deepEqual(step(day(2026, 10, 31), 'day', 1), day(2026, 11, 1));
assert.deepEqual(step(day(2026, 1, 1), 'day', -1), day(2025, 12, 31));
assert.deepEqual(step(day(2024, 2, 28), 'day', 1), day(2024, 2, 29));
});
test('month and year steps clamp to short months but return to the preferred day', () => {
const feb = step(day(2026, 1, 31), 'month', 1, 31);
assert.deepEqual(feb, day(2026, 2, 28));
assert.deepEqual(step(feb, 'month', 1, 31), day(2026, 3, 31));
assert.deepEqual(step(day(2026, 1, 15), 'month', -1), day(2025, 12, 15));
assert.deepEqual(step(day(2024, 2, 29), 'year', 1, 29), day(2025, 2, 28));
assert.deepEqual(step(day(9999, 12, 31), 'day', 1), day(9999, 12, 31));
assert.deepEqual(step(day(1000, 3, 1), 'year', -1), day(1000, 3, 1));
});
test('relative labels count whole days', () => {
const today = day(2026, 10, 14);
assert.equal(picker.relativeDayLabel(today, today), 'today');
assert.equal(picker.relativeDayLabel(day(2026, 10, 13), today), 'yesterday');
assert.equal(picker.relativeDayLabel(day(2026, 10, 15), today), 'tomorrow');
assert.equal(picker.relativeDayLabel(day(2026, 10, 4), today), '10 days ago');
// Across the US DST change on Nov 1.
assert.equal(picker.relativeDayLabel(day(2026, 11, 20), today), 'in 37 days');
});
test('scroll adjusts the active field; clicks walk the fields and the last one picks', async () => {
const f = fixture();
await f.input('scroll-down', 'scroll-down', 'scroll-down');
assert.deepEqual({ ...f.layer.value }, day(2026, 10, 11));
await f.input('click');
assert.equal(f.layer.activeField, 'month');
await f.input('scroll-up');
assert.deepEqual({ ...f.layer.value }, day(2026, 11, 11));
await f.input('click', 'scroll-down', 'click');
assert.ok(f.stack.isAtBase());
assert.equal(f.picks.length, 1);
assert.equal(f.picks[0].getTime(), new Date(2025, 10, 11).getTime());
assert.equal(f.cancels(), 0);
});
test('double-click steps back a field, then cancels from the first', async () => {
const f = fixture();
await f.input('click', 'click');
assert.equal(f.layer.activeField, 'year');
await f.input('double-click', 'double-click');
assert.equal(f.layer.activeField, 'day');
assert.ok(!f.stack.isAtBase());
await f.input('double-click');
assert.ok(f.stack.isAtBase());
assert.equal(f.cancels(), 1);
assert.equal(f.picks.length, 0);
});
test('a host clearing the stack reports a cancel', () => {
const f = fixture();
f.stack.clearToBase();
assert.equal(f.cancels(), 1);
});
test('watch swipes move between fields without picking or cancelling', async () => {
const f = fixture();
await f.input('swipe-left');
assert.ok(!f.stack.isAtBase());
await f.input('swipe-right', 'swipe-right', 'swipe-right', 'swipe-up');
assert.equal(f.layer.activeField, 'year');
assert.deepEqual({ ...f.layer.value }, day(2027, 10, 14));
assert.ok(!f.stack.isAtBase());
});
test('the dialog is centered over the dimmed window, dropping the calendar when it does not fit', () => {
const widths = [];
for (const size of [{ width: 576, height: 260 }, { width: 576, height: 160 }, { width: 300, height: 260 }]) {
const f = fixture(new Date(2026, 9, 14), size);
const planes = f.stack.paint();
assert.equal(planes.length, 2);
assert.equal(planes.at(-1).dimUnderneath, 0.25);
// The dialog's backdrop is the only value-1 fill.
const image = planes.at(-1).image.withDrawsBaked();
let left = Infinity, right = -1, top = Infinity, bottom = -1;
for (let y = 0; y < image.height; y++) {
for (let x = 0; x < image.width; x++) {
if (image.getPixel(x, y) !== 1) continue;
left = Math.min(left, x); right = Math.max(right, x);
top = Math.min(top, y); bottom = Math.max(bottom, y);
}
}
assert.ok(left > 0 && top > 0 && right < size.width - 1 && bottom < size.height - 1);
assert.ok(Math.abs(left - (size.width - 1 - right)) <= 1);
assert.ok(Math.abs(top - (size.height - 1 - bottom)) <= 1);
widths.push(right - left);
}
// Only the roomy window has the calendar beside the fields.
assert.ok(widths[0] > widths[1] + 100);
assert.equal(widths[1], widths[2]);
});
+66
View File
@@ -0,0 +1,66 @@
const { test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs'), vm = require('node:vm'), ts = require('typescript');
// dashboard-settings.ts over an in-memory settings store (as in brightness-curve.test.cjs).
function settingsFixture(store = new Map()) {
const context = { exports: {}, global: { isIOS: false }, require: id => {
if (id.includes('settings-store')) return {
onSettingsStoreChanged() {}, getStringSetting: (k, d) => store.get(k) ?? d,
setStringSetting: (k, v) => store.set(k, v),
getBooleanSetting: (k, d) => store.get(k) ?? d, setBooleanSetting: (k, v) => store.set(k, v),
};
if (id.includes('brightness-curve')) return require('../.test-build/app/g2/brightness-curve.js');
if (id.includes('animation-speed')) return require('../.test-build/app/ui/animation-speed.js');
return { Layer: class {}, ASSISTANT_MODEL_CHOICES: [] };
}};
vm.runInNewContext(ts.transpileModule(fs.readFileSync('app/ui/dashboard-settings.ts', 'utf8'), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText, context);
return context.exports;
}
test('the display mode starts as the middle band, or carries over the old mode and vertical position', () => {
const layout = (entries) => settingsFixture(new Map(entries)).displayLayoutSetting.get();
assert.equal(layout([]), 'band-middle');
assert.equal(layout([['display.verticalPosition', 'upper']]), 'band-high');
assert.equal(layout([['display.mode', '576x288'], ['display.verticalPosition', 'lower']]), 'band-low');
assert.equal(layout([['display.mode', '576x480'], ['display.verticalPosition', 'top']]), 'tall');
assert.equal(layout([['display.mode', '640x480']]), 'fullscreen');
// Once set, the merged setting is its own.
const store = new Map([['display.mode', '576x480']]);
const api = settingsFixture(store);
api.displayLayoutSetting.set('band-bottom');
assert.equal(store.get('display.layout'), 'band-bottom');
assert.equal(api.displayLayoutSetting.get(), 'band-bottom');
});
test('per-app display modes carry over their old mode and position where the merged values can say it', () => {
const app = (appId, entries) => settingsFixture(new Map(entries))[`${appId}DisplayLayoutSetting`].get();
assert.equal(app('navigate', []), 'global');
assert.equal(app('terminal', []), 'default');
assert.equal(app('navigate', [['navigate.displayMode', '576x288'], ['navigate.verticalPosition', 'bottom']]), 'band-bottom');
// A band at the global position takes the global band.
assert.equal(app('navigate', [['navigate.displayMode', '576x288'], ['display.verticalPosition', 'top']]), 'band-top');
assert.equal(app('navigate', [['navigate.displayMode', '576x288'], ['display.layout', 'band-low']]), 'band-low');
// Following the global band at a position of its own.
assert.equal(app('navigate', [['navigate.verticalPosition', 'top']]), 'band-top');
assert.equal(app('navigate', [['navigate.verticalPosition', 'top'], ['display.mode', '576x480']]), 'global');
assert.equal(app('terminal', [['terminal.displayMode', '640x480']]), 'fullscreen');
assert.equal(app('terminal', [['terminal.displayMode', 'global']]), 'global');
assert.equal(app('terminal', [['terminal.verticalPosition', 'lower']]), 'default');
});
test('Full Screen is offered only with a bottom or popup app switcher', () => {
const store = new Map();
const api = settingsFixture(store);
for (const [position, available] of [['left', false], ['right', false], ['bottom', true], ['popup', true]]) {
api.appSwitcherPositionSetting.set(position);
assert.equal(api.fullScreenAvailable(), available, position);
assert.equal(api.displayLayoutSetting.isDisabled('fullscreen'), !available, position);
assert.equal(api.navigateDisplayLayoutSetting.isDisabled('fullscreen'), !available, position);
assert.equal(api.displayLayoutSetting.isDisabled('tall'), false);
}
assert.deepEqual(Array.from(api.DISPLAY_LAYOUT_VALUES, (value) => api.displayLayoutLabel(value)),
['Band · Top', 'Band · High', 'Band · Middle', 'Band · Low', 'Band · Bottom', 'Tall', 'Full Screen']);
});
+89
View File
@@ -0,0 +1,89 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const vm = require('node:vm');
const { loader } = require('./helpers/load-typescript.cjs');
// Loads webview.ts against recording doubles of the Android/Kotlin classes.
function androidWebView({ remoteUrl = '', bridgeError = null } = {}) {
const calls = [], evaluated = [];
let listener, attachedCheck;
const ignore = new Proxy({}, { get: () => () => {} });
class WebView {
constructor() { calls.push('construct'); }
getSettings() { calls.push('settings'); return ignore; }
setWebViewClient() {} setWebChromeClient() {}
addJavascriptInterface() { calls.push('addJavascriptInterface'); }
evaluateJavascript(js) { evaluated.push(js); }
loadUrl(url) { calls.push(`load ${url}`); }
}
const app = {
FaceclawEvenHubWebView: WebView,
FaceclawEvenHubProfile: { apply: (web, packageId) => { calls.push(`profile ${packageId}`); return web instanceof WebView; } },
FaceclawEvenHubListener: class { constructor(impl) { listener = impl; } },
FaceclawEvenHubJsBridge: {
originRule: url => /^https?:\/\/[^/]+/.exec(url)[0],
install: (_web, rule) => { calls.push(`bridge ${rule}`); return bridgeError; },
},
FaceclawEvenHubWebViewClient: class {}, FaceclawEvenHubChromeClient: class {},
FaceclawEvenHubDocumentStart: { install: (_web, _script, rule) => { calls.push(`document-start ${rule}`); return true; } },
FaceclawEvenHubWebViewHost: { getInstance: () => ({ attach(_activity, _web, check) { attachedCheck = check; }, detach() { calls.push('detach'); } }) },
};
const load = loader({ com: { faceclaw: { app } }, android: { content: { MutableContextWrapper: class {} } }, java: {} }, {
'@nativescript/core': { Application: { android: { foregroundActivity: {} } }, Utils: {} },
'./session': { EVENHUB_BRIDGE_INJECT_SCRIPT: '', buildFaceclawExtensionsScript: () => '' }, '../../version': { FACECLAW_VERSION: 'test' },
});
const failures = [];
const session = { manifest: { packageId: 'com.example.app', entrypoint: 'index.html', name: 'Example' }, distDir: '/dist', remoteUrl,
webViewFailed: (message, fatal) => failures.push([message, fatal]), webViewLoaded() {}, handleBridgeCall() {} };
const api = load('app/apps/evenhub/webview.ts');
const handle = api.createEvenHubWebView(session);
return { api, calls, evaluated, failures, handle, listener: () => listener, attachedCheck: () => attachedCheck };
}
// Runs a host-evaluated script in a document at `href`, as WebView would.
function runIn(href, script, globals = {}) {
const context = vm.createContext({ URL, location: new URL(href), JSON, String, ...globals });
context.window = context;
return { result: vm.runInContext(script, context), context };
}
test('Android EvenHub WebViews join their package profile, then get an origin-locked bridge', () => {
const h = androidWebView();
assert.deepEqual(h.calls, ['construct', 'profile com.example.app', 'settings',
'bridge https://com.example.app.evenhub.invalid', 'load https://com.example.app.evenhub.invalid/index.html']);
const remote = androidWebView({ remoteUrl: 'http://192.168.1.5:5173/app/' });
assert.ok(remote.calls.includes('bridge http://192.168.1.5:5173'));
assert.ok(remote.calls.includes('document-start http://192.168.1.5:5173'));
});
test('Android EvenHub host scripts only run in the app\'s own documents', () => {
const h = androidWebView();
h.handle.evaluateJs('window.ran = true');
assert.equal(runIn('https://com.example.app.evenhub.invalid/index.html?code=1', h.evaluated[0]).context.ran, true);
assert.equal(runIn('https://accounts.example.com/authorize', h.evaluated[0]).context.ran, undefined);
// The ticker's guard is the same check.
assert.equal(runIn('https://com.example.app.evenhub.invalid/', `if (${h.attachedCheck()}) { 5 }`).result, 5);
assert.equal(runIn('http://com.example.app.evenhub.invalid/', `if (${h.attachedCheck()}) { 5 }`).result, undefined);
});
test('Android EvenHub transport wraps the bridge port, and is inert without it', () => {
const posted = [];
const port = { postMessage: message => posted.push(JSON.parse(message)) };
const { api } = androidWebView();
const { context } = runIn('https://com.example.app.evenhub.invalid/', api.ANDROID_EVENHUB_TRANSPORT_SCRIPT, { __faceclawEvenHubPort: port });
context.__faceclawEvenHub.postMessage('evenAppMessage', '["{}"]', 7);
context.__faceclawEvenHub.wakeTimers();
assert.deepEqual(posted, [['call', 'evenAppMessage', '["{}"]', 7], ['wake']]);
assert.equal(runIn('https://elsewhere.example/', api.ANDROID_EVENHUB_TRANSPORT_SCRIPT).context.__faceclawEvenHub, undefined);
});
test('Android EvenHub apps fail visibly without a bridge, and stop using a WebView whose renderer is gone', () => {
const failed = androidWebView({ bridgeError: 'too old' });
assert.deepEqual(failed.failures, [['too old', true]]);
assert.ok(!failed.calls.some(call => call.startsWith('load ')));
const h = androidWebView();
h.listener().onRenderProcessGone(false);
assert.equal(h.failures.length, 1); assert.equal(h.failures[0][1], true);
h.handle.evaluateJs('window.ran = true');
assert.equal(h.evaluated.length, 0);
});
+38
View File
@@ -103,3 +103,41 @@ test("a list without isItemSelectBorderEn has no selection border (protobuf defa
assert.equal(page.containers[0].selectBorder, false);
assert.equal(page.containers[0].itemWidth, 0);
});
test("flags accept booleans (extension layouts) as well as 0/1 (stock)", () => {
const page = parsePage({
listObject: [{ containerID: 1, containerName: "l", isEventCapture: true, preserve: true, itemContainer: { itemName: ["a"], isItemSelectBorderEn: true } }],
textObject: [
{ containerID: 2, containerName: "t", isEventCapture: 1, preserve: 1 },
{ containerID: 3, containerName: "u", isEventCapture: false, preserve: false },
],
});
assert.deepEqual(
page.containers.map((c) => [c.name, c.isEventCapture, c.preserve]),
[["l", true, true], ["t", true, true], ["u", false, false]],
);
assert.equal(page.containers[0].selectBorder, true);
});
test("a layout font is the default for text and list containers, which override it field by field", () => {
const page = parsePage({
font: { family: "Inter", size: 24 },
listObject: [{ containerID: 1, containerName: "l", font: { weight: "bold" } }],
textObject: [{ containerID: 2, containerName: "t" }, { containerID: 3, containerName: "u", font: { family: "Terminus" } }],
imageObject: [{ containerID: 4, containerName: "i" }],
});
assert.deepEqual(
page.containers.map((c) => [c.name, c.font]),
[
["l", { family: "Inter", size: 24, weight: 700 }],
["i", undefined],
["t", { family: "Inter", size: 24 }],
["u", { family: "Terminus", size: 24 }],
],
);
});
test("containers without a font anywhere keep the stock font", () => {
const page = parsePage({ textObject: [{ containerID: 1, containerName: "t", content: "x" }] });
assert.equal(page.containers[0].font, undefined);
});
+45
View File
@@ -0,0 +1,45 @@
// The stock DeviceStatus an EvenHub app sees (getGlassesInfo().status and the
// deviceStatusChanged push), built from Faceclaw's view of the glasses.
const test = require("node:test");
const assert = require("node:assert/strict");
const { buildEvenHubDeviceStatus, sameDeviceStatus, PLACEHOLDER_SERIAL } = require("../.test-build/app/apps/evenhub/device-status.js");
const worn = { serial: "S200LAAJ0123", connected: true, worn: true, battery: 73, charging: false };
test("connected, worn glasses report their real values", () => {
assert.deepEqual(buildEvenHubDeviceStatus(worn), {
sn: "S200LAAJ0123",
connectType: "connected",
isWearing: true,
batteryLevel: 73,
isCharging: false,
isInCase: false,
});
});
test("charging means in the case, since the G2 only charges there", () => {
const status = buildEvenHubDeviceStatus({ ...worn, worn: false, charging: true });
assert.equal(status.isCharging, true);
assert.equal(status.isInCase, true);
assert.equal(status.isWearing, false);
});
test("unknown wear state and battery are omitted, not guessed", () => {
const status = buildEvenHubDeviceStatus({ serial: null, connected: false, worn: null, battery: null, charging: false });
assert.deepEqual(status, { sn: PLACEHOLDER_SERIAL, connectType: "disconnected", isCharging: false, isInCase: false });
assert.equal("isWearing" in status, false);
assert.equal("batteryLevel" in status, false);
});
test("a blank serial falls back to the placeholder", () => {
assert.equal(buildEvenHubDeviceStatus({ ...worn, serial: " " }).sn, PLACEHOLDER_SERIAL);
});
test("sameDeviceStatus compares every field", () => {
const a = buildEvenHubDeviceStatus(worn);
assert.equal(sameDeviceStatus(a, buildEvenHubDeviceStatus(worn)), true);
assert.equal(sameDeviceStatus(a, buildEvenHubDeviceStatus({ ...worn, battery: 72 })), false);
assert.equal(sameDeviceStatus(a, buildEvenHubDeviceStatus({ ...worn, worn: null })), false);
assert.equal(sameDeviceStatus(a, buildEvenHubDeviceStatus({ ...worn, connected: false })), false);
});
+174
View File
@@ -0,0 +1,174 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
// The injected shim (app/apps/evenhub/session.ts) and the published types
// (evenhub-extensions/src/index.ts) describe the same API from two sides.
const source = fs.readFileSync(path.join(__dirname, '../app/apps/evenhub/session.ts'), 'utf8');
const template = source.match(/export function buildFaceclawExtensionsScript[^`]*`([\s\S]*?)`;\n}/)[1];
const shim = template.replace('${JSON.stringify(versionString)}', JSON.stringify('Faceclaw/9.9.9'));
const types = fs.readFileSync(path.join(__dirname, '../evenhub-extensions/src/index.ts'), 'utf8');
function interfaceMembers(name) {
const body = types.match(new RegExp(`export interface ${name} \\{([\\s\\S]*?)\\n\\}`))[1];
const withoutComments = body.replace(/\/\*\*[\s\S]*?\*\//g, '');
return [...withoutComments.matchAll(/^ {2}(?:readonly )?(\w+)[?(:]/gm)].map((m) => m[1]).sort();
}
function page() {
const posted = [];
const win = {
console, JSON, Promise, Array, Object, Error, String,
__faceclawEvenHub: { postMessage(name, argsJson, id) { posted.push({ name, args: JSON.parse(argsJson), id }); } },
};
win.window = win;
vm.createContext(win);
vm.runInContext(shim, win);
const fc = win.getFaceclawExtensions();
return { win, fc, posted };
}
test('the package helper returns the shim, and treats unversioned 0.8.0-0.8.2 hosts as absent', () => {
const { loader } = require('./helpers/load-typescript.cjs');
const helper = (window) => loader(window === undefined ? {} : { window })('evenhub-extensions/src/index.ts').getFaceclawExtensions();
const { win, fc } = page();
assert.equal(helper(win), fc);
assert.equal(helper({ getFaceclawExtensions: () => ({ getVersion: () => 'Faceclaw/0.8.2' }) }), null);
assert.equal(helper({}), null);
assert.equal(helper(undefined), null);
});
test('the shim implements exactly the members the package declares', () => {
const { fc } = page();
assert.deepEqual(Object.keys(fc).sort(), interfaceMembers('FaceclawExtensions'));
});
test('version and api level are available synchronously', () => {
const { fc } = page();
assert.equal(fc.getVersion(), 'Faceclaw/9.9.9');
assert.equal(fc.apiVersion, 1);
});
test('calls resolve with the host value and reject with an Error', async () => {
const { win, fc, posted } = page();
const ok = fc.getConfiguredApiKeys();
const bad = fc.playBuzzer([{ freq: 440, ms: 100 }]);
assert.deepEqual(posted.map((p) => [p.name, p.args[0]]), [['faceclawExt', 'getConfiguredApiKeys'], ['faceclawExt', 'playBuzzer']]);
assert.ok(posted.every((p) => p.id > 0));
win.__fcExtResolve(posted[0].id, true, ['openai']);
win.__fcExtResolve(posted[1].id, false, 'no glasses');
assert.deepEqual(await ok, ['openai']);
await assert.rejects(bad, (error) => error instanceof win.Error && error.message === 'no glasses');
});
test('fire-and-forget calls use id 0', () => {
const { fc, posted } = page();
fc.returnToAppSwitcher();
fc.quit();
assert.deepEqual(posted.map((p) => [p.args[0], p.id]), [['returnToAppSwitcher', 0], ['quit', 0]]);
});
test('a listener that unsubscribes during dispatch does not skip the next one', () => {
const { win, fc } = page();
const seen = [];
const offA = fc.addWindowLifecycleListener((e) => { seen.push(`a:${e.type}`); offA(); });
fc.addWindowLifecycleListener((e) => seen.push(`b:${e.type}`));
win.__fcExtEvent('windowLifecycle', { type: 'hidden' });
win.__fcExtEvent('windowLifecycle', { type: 'visible' });
assert.deepEqual(seen, ['a:hidden', 'b:hidden', 'b:visible']);
});
test('the compass is enabled for the first listener and disabled after the last', () => {
const { win, fc, posted } = page();
const readings = [];
const off1 = fc.addCompassListener((r) => readings.push(r.headingDegrees));
const off2 = fc.addCompassListener(() => {});
win.__fcExtEvent('compass', { headingDegrees: 90 });
off1();
off2();
assert.deepEqual(readings, [90]);
assert.deepEqual(posted.map((p) => p.args), [['setCompass', true], ['setCompass', false]]);
});
test('assistant tools send specs to the host and run handlers on invoke', async () => {
const { win, fc, posted } = page();
fc.setAssistantTools([
{ name: 'double', description: 'Doubles n', handler: ({ n }) => n * 2 },
{ name: 'fail', description: 'Throws', availability: 'open', handler: () => { throw new Error('nope'); } },
]);
assert.deepEqual(posted[0].args, ['setAssistantTools', [
{ name: 'double', description: 'Doubles n', parameters: { type: 'object', properties: {} }, availability: 'foreground' },
{ name: 'fail', description: 'Throws', parameters: { type: 'object', properties: {} }, availability: 'open' },
]]);
win.__fcExtInvokeTool(7, 'double', { n: 21 });
win.__fcExtInvokeTool(8, 'fail', {});
win.__fcExtInvokeTool(9, 'missing', {});
await new Promise((resolve) => setImmediate(resolve));
const results = posted.filter((p) => p.name === 'faceclawExtToolResult').map((p) => p.args).sort((a, b) => a[0] - b[0]);
assert.deepEqual(results, [[7, true, 42], [8, false, 'nope'], [9, false, 'unknown tool missing']]);
});
test('touch-down and text input are requested while someone listens, and unsubscribing twice is harmless', () => {
const { win, fc, posted } = page();
const seen = [];
const offTouch = fc.addTouchDownListener((e) => seen.push(`touch:${e.source}`));
const offText1 = fc.addTextInputListener((e) => seen.push(`text1:${e.text}`));
const offText2 = fc.addTextInputListener((e) => seen.push(`text2:${e.text}`));
win.__fcExtEvent('touchDown', { source: 'watch', timestampMs: 5 });
win.__fcExtEvent('textInput', { text: 'hi' });
offText1();
offText1();
win.__fcExtEvent('textInput', { text: 'again' });
offText2();
offTouch();
assert.deepEqual(seen, ['touch:watch', 'text1:hi', 'text2:hi', 'text2:again']);
assert.deepEqual(posted.map((p) => p.args), [
['setTouchDown', true],
['setTextInput', true],
['setTextInput', false],
['setTouchDown', false],
]);
});
test('window icons are sent as plain arrays, and clearing sends null', async () => {
const { win, fc, posted } = page();
const set = fc.setWindowIcon({ width: 1, height: 2, data: new Uint8ClampedArray([7, 9]) });
const clear = fc.setWindowIcon(null);
assert.deepEqual(posted.map((p) => p.args), [
['setWindowIcon', { width: 1, height: 2, data: [7, 9] }],
['setWindowIcon', null],
]);
win.__fcExtResolve(posted[0].id, true, null);
win.__fcExtResolve(posted[1].id, false, 'setWindowIcon: bad');
await set;
await assert.rejects(clear, /setWindowIcon: bad/);
});
test('window controls are fire-and-forget; startVoiceInput resolves the host answer', async () => {
const { win, fc, posted } = page();
fc.setAttention(1);
fc.setKeepScreenOn(false);
const voice = fc.startVoiceInput();
assert.deepEqual(posted.map((p) => [p.args, p.id === 0]), [
[['setAttention', true], true],
[['setKeepScreenOn', false], true],
[['startVoiceInput'], false],
]);
win.__fcExtResolve(posted[2].id, true, false);
assert.equal(await voice, false);
});
test('font queries are calls; measureText sends null for no font', () => {
const { fc, posted } = page();
void fc.getFonts();
void fc.measureText('hi');
void fc.measureText(42, { family: 'Inter', size: 30 });
assert.deepEqual(posted.map((p) => p.args), [
['getFonts'],
['measureText', 'hi', null],
['measureText', '42', { family: 'Inter', size: 30 }],
]);
assert.ok(posted.every((p) => p.id > 0));
});
+84
View File
@@ -0,0 +1,84 @@
// Font options for EvenHub text and list containers (extension layouts):
// parsing, layout-default inheritance, and choosing a face.
const test = require("node:test");
const assert = require("node:assert/strict");
const {
parseFontSpec,
mergeFontSpecs,
selectFontFace,
describeFontFamilies,
MAX_FONT_SIZE,
} = require("../.test-build/app/apps/evenhub/font-spec.js");
const TERMINUS_SIZES = [12, 14, 16, 18, 20, 22, 24, 28, 32];
const ttf = (family, weight, monospace = false) => ({ family, weight, sizes: null, monospace, key: `ttf:${family}:${weight}` });
const FACES = [
{ family: "EvenHub", weight: 400, sizes: [20], monospace: false, key: "stock" },
{ family: "Terminus", weight: 400, sizes: TERMINUS_SIZES, monospace: true, key: "terminus:400" },
{ family: "Terminus", weight: 700, sizes: TERMINUS_SIZES, monospace: true, key: "terminus:700" },
ttf("Inter 18pt", 300), ttf("Inter 18pt", 400), ttf("Inter 18pt", 700),
ttf("Roboto", 300), ttf("Roboto", 400), ttf("Roboto", 700),
ttf("Roboto Mono", 300, true), ttf("Roboto Mono", 400, true), ttf("Roboto Mono", 700, true),
];
const pick = (spec, faces = FACES) => {
const choice = selectFontFace(spec, faces);
return choice && `${choice.face.key}@${choice.size}`;
};
test("no font object means no spec (the stock font); an empty one means the defaults", () => {
assert.equal(parseFontSpec(undefined), undefined);
assert.equal(parseFontSpec("Roboto"), undefined);
assert.deepEqual(parseFontSpec({}), {});
assert.equal(pick({}), "ttf:Roboto:400@20");
});
test("sizes are rounded and clamped, weights take keywords and numeric strings", () => {
assert.deepEqual(parseFontSpec({ family: " Inter ", size: 17.6, weight: "bold" }), { family: "Inter", size: 18, weight: 700 });
assert.deepEqual(parseFontSpec({ size: 1000, weight: "normal" }), { size: MAX_FONT_SIZE, weight: 400 });
assert.deepEqual(parseFontSpec({ size: 2, weight: "300" }), { size: 6, weight: 300 });
assert.deepEqual(parseFontSpec({ family: "", size: "x", weight: "heavy" }), {});
});
test("a container's font overrides the layout default field by field", () => {
assert.deepEqual(mergeFontSpecs({ family: "Inter", size: 24 }, { size: 30 }), { family: "Inter", size: 30 });
assert.deepEqual(mergeFontSpecs(undefined, { size: 30 }), { size: 30 });
assert.deepEqual(mergeFontSpecs({ family: "Inter" }, undefined), { family: "Inter" });
assert.equal(mergeFontSpecs(undefined, undefined), undefined);
});
test("families match loosely, including without an optical-size suffix", () => {
assert.equal(pick({ family: "inter" }), "ttf:Inter 18pt:400@20");
assert.equal(pick({ family: "Inter 18pt" }), "ttf:Inter 18pt:400@20");
assert.equal(pick({ family: "robotomono", size: 14 }), "ttf:Roboto Mono:400@14");
assert.equal(pick({ family: "ROBOTO" }), "ttf:Roboto:400@20", "Roboto doesn't pick up Roboto Mono");
});
test("an unknown family falls back to Roboto, and with no Roboto there is no choice", () => {
assert.equal(pick({ family: "Comic Sans", weight: 700 }), "ttf:Roboto:700@20");
assert.equal(pick({ family: "Comic Sans" }, FACES.slice(0, 3)), null);
});
test("weights follow CSS matching", () => {
assert.equal(pick({ family: "Inter", weight: 500 }), "ttf:Inter 18pt:400@20", "400-500 look lighter before heavier");
assert.equal(pick({ family: "Inter", weight: 600 }), "ttf:Inter 18pt:700@20", "heavier requests look heavier first");
assert.equal(pick({ family: "Inter", weight: 350 }), "ttf:Inter 18pt:300@20", "lighter requests look lighter first");
assert.equal(pick({ family: "Inter", weight: 100 }), "ttf:Inter 18pt:300@20");
assert.equal(pick({ family: "Inter", weight: 900 }), "ttf:Inter 18pt:700@20");
});
test("bitmap families snap to their nearest size", () => {
assert.equal(pick({ family: "Terminus", size: 25 }), "terminus:400@24");
assert.equal(pick({ family: "Terminus", size: 26, weight: 700 }), "terminus:700@24", "a tie takes the smaller size");
assert.equal(pick({ family: "Terminus", size: 100 }), "terminus:400@32");
assert.equal(pick({ family: "EvenHub", size: 40, weight: 700 }), "stock@20");
});
test("families are listed once each, by their app-facing name", () => {
const families = describeFontFamilies(FACES);
assert.deepEqual(families.map((f) => f.family), ["EvenHub", "Inter", "Roboto", "Roboto Mono", "Terminus"]);
const terminus = families.find((f) => f.family === "Terminus");
assert.deepEqual(terminus, { family: "Terminus", weights: [400, 700], sizes: TERMINUS_SIZES, monospace: true });
const inter = families.find((f) => f.family === "Inter");
assert.deepEqual(inter, { family: "Inter", weights: [300, 400, 700], monospace: false });
});
+56
View File
@@ -0,0 +1,56 @@
// App-supplied switcher icons (extension setWindowIcon): parsing the pixel
// buffer from the bridge, and scaling it to the switcher's icon size.
const test = require("node:test");
const assert = require("node:assert/strict");
const { parseWindowIcon, WindowIconRenderer, MAX_WINDOW_ICON_DIMENSION } = require("../.test-build/app/apps/evenhub/window-icon.js");
test("grayscale data is taken as-is", () => {
const icon = parseWindowIcon({ width: 2, height: 2, data: [0, 64, 128, 255] });
assert.deepEqual([...icon.pixels], [0, 64, 128, 255]);
});
test("RGBA data (an ImageData) becomes luminance times alpha", () => {
const icon = parseWindowIcon({
width: 3,
height: 1,
data: [255, 255, 255, 255, 255, 255, 255, 0, 0, 255, 0, 255],
});
assert.deepEqual([...icon.pixels], [255, 0, 182]);
});
test("a JSON-ified typed array parses like a plain array", () => {
const icon = parseWindowIcon({ width: 2, height: 1, data: { 0: 10, 1: 20 } });
assert.deepEqual([...icon.pixels], [10, 20]);
});
test("malformed icons are refused", () => {
assert.equal(parseWindowIcon(null), null);
assert.equal(parseWindowIcon({ width: 2, height: 2, data: [1, 2, 3] }), null, "wrong length");
assert.equal(parseWindowIcon({ width: 0, height: 2, data: [] }), null, "empty");
assert.equal(parseWindowIcon({ width: 1.5, height: 2, data: [1, 2, 3] }), null, "fractional size");
assert.equal(parseWindowIcon({ width: 1, height: 1, data: ["x"] }), null, "non-numeric data");
const big = MAX_WINDOW_ICON_DIMENSION + 1;
assert.equal(parseWindowIcon({ width: big, height: 1, data: new Array(big).fill(0) }), null, "too wide");
});
test("icons shrink to fit the box, keeping their aspect ratio and averaging pixels", () => {
const data = [];
for (let y = 0; y < 4; y++) for (let x = 0; x < 8; x++) data.push(x < 4 ? 0 : 200);
const renderer = new WindowIconRenderer(parseWindowIcon({ width: 8, height: 4, data }));
const small = renderer.render(4);
assert.equal(small.width, 4);
assert.equal(small.height, 2);
assert.deepEqual([...small.pixels], [0, 0, 200, 200, 0, 0, 200, 200]);
const odd = renderer.render(3);
assert.equal(odd.width, 3);
// The middle column straddles the edge between the halves.
assert.equal(odd.pixels[1], 100);
});
test("renders are cached per size, and a fitting icon is used unscaled", () => {
const source = parseWindowIcon({ width: 4, height: 4, data: new Array(16).fill(9) });
const renderer = new WindowIconRenderer(source);
assert.equal(renderer.render(32), renderer.render(32));
assert.equal(renderer.render(4), source);
});
+11 -1
View File
@@ -1,7 +1,7 @@
const test = require("node:test");
const assert = require("node:assert/strict");
const { chargingDisplayLabel, glassesDisplayLabel } = require("../.test-build/app/g2/glasses-display-state.js");
const { chargingDisplayLabel, glassesDisplayAsleep, glassesDisplayLabel } = require("../.test-build/app/g2/glasses-display-state.js");
const connected = {
phase: "connected",
@@ -9,6 +9,7 @@ const connected = {
screenOn: true,
battery: 72,
foregroundTitle: "Music",
previewMode: false,
};
test("the foreground-title line covers visible, dark, and silent displays", () => {
@@ -18,6 +19,15 @@ test("the foreground-title line covers visible, dark, and silent displays", () =
assert.equal(glassesDisplayLabel({ ...connected, screenOn: false, silentMode: true }), "Silent mode");
});
test("only the Display off state counts as asleep (the watch face's wake hint)", () => {
assert.equal(glassesDisplayAsleep({ ...connected, screenOn: false }), true);
assert.equal(glassesDisplayAsleep({ ...connected, phase: "disconnected", screenOn: false, previewMode: true }), true);
assert.equal(glassesDisplayAsleep(connected), false);
assert.equal(glassesDisplayAsleep({ ...connected, screenOn: false, silentMode: true }), false);
assert.equal(glassesDisplayAsleep({ ...connected, phase: "charging", screenOn: false }), false);
assert.equal(glassesDisplayAsleep({ ...connected, phase: "disconnected", screenOn: false }), false);
});
test("charging takes precedence and includes the last-known G2 battery", () => {
assert.equal(
glassesDisplayLabel({ ...connected, phase: "charging", silentMode: true, screenOn: false }),
+54
View File
@@ -0,0 +1,54 @@
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const cache = path.join(os.homedir(), '.gradle/caches/modules-2/files-2.1');
/** A cached Maven artifact (`.jar` unless `extension` says otherwise), or null. */
function cachedArtifact(group, artifact, version, extension = 'jar') {
const directory = path.join(cache, group, artifact, version);
if (!fs.existsSync(directory)) return null;
for (const hash of fs.readdirSync(directory)) {
const file = path.join(directory, hash, `${artifact}-${version}.${extension}`);
if (fs.existsSync(file)) return file;
}
return null;
}
/** The newest cached version of an artifact, or null. */
function newestArtifact(group, artifact, extension = 'jar') {
const directory = path.join(cache, group, artifact);
if (!fs.existsSync(directory)) return null;
for (const version of fs.readdirSync(directory).sort().reverse()) {
const file = cachedArtifact(group, artifact, version, extension);
if (file) return file;
}
return null;
}
/**
* The Kotlin compiler NativeScript's Android build already cached (the version
* in before-plugins.gradle), or null before the first ./build.sh. Run it as
* `java -cp <classpath> org.jetbrains.kotlin.cli.jvm.K2JVMCompiler -no-stdlib -cp <stdlib> ...`.
*/
function kotlinCompiler() {
const gradle = fs.readFileSync(path.join(__dirname, '../../App_Resources/Android/before-plugins.gradle'), 'utf8')
.match(/kotlinVersion\s*=\s*"([^"]+)"/);
if (!gradle) return null;
const version = gradle[1];
const stdlib = cachedArtifact('org.jetbrains.kotlin', 'kotlin-stdlib', version);
const compiler = [
cachedArtifact('org.jetbrains.kotlin', 'kotlin-compiler-embeddable', version),
stdlib,
cachedArtifact('org.jetbrains.kotlin', 'kotlin-script-runtime', version),
cachedArtifact('org.jetbrains.kotlin', 'kotlin-daemon-embeddable', version),
newestArtifact('org.jetbrains.kotlin', 'kotlin-reflect'),
newestArtifact('org.jetbrains.intellij.deps', 'trove4j'),
newestArtifact('org.jetbrains', 'annotations'),
newestArtifact('org.jetbrains.kotlinx', 'kotlinx-coroutines-core-jvm'),
];
if (compiler.some(file => !file)) return null;
return { classpath: compiler.join(path.delimiter), stdlib };
}
module.exports = { cachedArtifact, newestArtifact, kotlinCompiler };
+131
View File
@@ -0,0 +1,131 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
function hermes() {
const requests = [];
const load = loader({ setTimeout, clearTimeout, JSON, Object, String, Number, Error }, {
'./sse': { openSseRequest: (url, body, headers, listener) => {
const request = { url, body: JSON.parse(body), headers, listener, cancelled: false, cancel() { this.cancelled = true; } };
requests.push(request);
return request;
} },
});
return { ...load('app/native/hermes.ts'), requests };
}
function stream(api, extra = {}) {
const deltas = [], results = [], errors = [];
api.streamHermesChat({
apiKey: 'k', model: 'hermes-agent', system: 'glasses', baseUrl: 'http://hermes-host:8642', sessionId: 'faceclaw-1',
messages: [{ role: 'user', content: 'Remember kiwi.' }, { role: 'assistant', content: 'OK' }, { role: 'user', content: 'Which word?' }],
onTextDelta: (delta) => deltas.push(delta), onDone: (r) => results.push(r), onError: (e) => errors.push(e), ...extra,
});
return { deltas, results, errors, request: api.requests.at(-1) };
}
const chunk = (delta, finish = null) => `data: ${JSON.stringify({ choices: [{ index: 0, delta, finish_reason: finish }] })}`;
test('Hermes gets only the latest user message, the session header and the key', () => {
const api = hermes();
const { request } = stream(api);
assert.equal(request.url, 'http://hermes-host:8642/v1/chat/completions');
assert.equal(request.headers['X-Hermes-Session-Id'], 'faceclaw-1');
assert.equal(request.headers.Authorization, 'Bearer k');
assert.equal(request.body.stream, true);
assert.deepEqual(request.body.messages.map((m) => [m.role, m.content]), [['system', 'glasses'], ['user', 'Which word?']]);
});
test('answer deltas stream, reasoning is not shown, [DONE] finishes the turn', () => {
const api = hermes();
const s = stream(api);
s.request.listener.onLine(chunk({ role: 'assistant' }));
s.request.listener.onLine(chunk({ reasoning_content: 'The word was kiwi.' }));
s.request.listener.onLine(chunk({ content: '\n\n' }));
s.request.listener.onLine(chunk({ content: 'Ki' }));
s.request.listener.onLine(chunk({ content: 'wi' }, 'stop'));
s.request.listener.onLine('data: [DONE]');
assert.deepEqual(s.deltas, ['Ki', 'wi']);
assert.deepEqual(s.results.map((r) => [r.text, r.stopReason]), [['Kiwi', 'end_turn']]);
assert.deepEqual(s.errors, []);
});
test('a rejected key and an empty stream are errors', () => {
const api = hermes();
const rejected = stream(api);
rejected.request.listener.onHttpError(401, '{}');
assert.deepEqual(rejected.errors, ['Hermes: the API server rejected the key']);
const empty = stream(api);
empty.request.listener.onComplete();
assert.deepEqual(empty.errors, ['Hermes stream ended without a reply']);
});
test('failed, interrupted, empty and cut-off runs are errors, not blank answers', () => {
const api = hermes();
const ending = (lines, close = 'done') => {
const s = stream(api);
for (const line of lines) s.request.listener.onLine(line);
if (close === 'done') s.request.listener.onLine('data: [DONE]');
else s.request.listener.onComplete();
assert.deepEqual(s.results, []);
return s.errors;
};
// Hermes's finish chunk: an error object rides along only when there is a message to show.
const finish = (reason, extra = {}) => `data: ${JSON.stringify({ choices: [{ index: 0, delta: {}, finish_reason: reason }], ...extra })}`;
assert.deepEqual(ending([chunk({ content: 'Half' }), finish('error')]), ['Hermes: the agent run failed']);
assert.deepEqual(ending([finish('error', { error: { message: 'admission_conflict', type: 'agent_error' } })]), ['Hermes: admission_conflict']);
assert.deepEqual(ending([chunk({ content: 'Half' }), finish('cancelled')]), ['Hermes: the agent run was interrupted']);
assert.deepEqual(ending([finish('stop')]), ['Hermes ended the turn without a reply']);
assert.deepEqual(ending([chunk({ content: 'Half' })], 'close'), ['Hermes: the reply was cut off']);
const closed = stream(api);
closed.request.listener.onLine(chunk({ content: 'Kiwi' }, 'stop'));
closed.request.listener.onComplete();
assert.deepEqual(closed.results.map((r) => r.text), ['Kiwi'], 'a finished stream may close without [DONE]');
});
test('a restored conversation keeps its Hermes session, and Hermes turns get a long deadline', () => {
const requests = [], delays = [];
const load = loader({ global: { isIOS: false, isAndroid: true }, setTimeout: (_fn, ms) => { delays.push(ms); return 0; }, clearTimeout: () => {} }, {
'./sse': { openSseRequest: (_url, _body, headers, listener) => {
const request = { headers, listener, cancel() {} };
requests.push(request);
return request;
} },
'../native/llama': { streamLocalQwen: () => assert.fail('no local model') },
'./bridge-client': { assistantBridge: {} }, './tool-registry': { toolRegistry: {} },
'../prompts': { ASSISTANT_SYSTEM_PROMPT_BASE: '', buildAssistantSystemPrompt: () => '', describeAssistantContext: () => '' },
});
const { AssistantSession } = load('app/assistant/session.ts');
const config = { kind: 'direct', llm: { selection: 'hermes', provider: 'hermes', model: 'hermes-agent', apiKey: 'k', baseUrl: 'http://hermes-host:8642' } };
const callbacks = { onTextDelta() {}, onToolActivity() {}, onError: (e) => assert.fail(e), onTurnDone() {} };
const turn = (session, text) => {
session.sendUtterance(text, {}, callbacks);
const request = requests.at(-1);
request.listener.onLine(chunk({ content: 'OK' }, 'stop'));
request.listener.onLine('data: [DONE]');
return request.headers['X-Hermes-Session-Id'];
};
const first = new AssistantSession(config, undefined);
const id = turn(first, 'Remember kiwi.');
assert.match(id, /^faceclaw-/);
assert.ok(delays.includes(20 * 60 * 1000), 'Hermes turns are not held to the 2-minute LLM cap');
const restored = new AssistantSession(config, undefined, JSON.parse(JSON.stringify(first.history())));
assert.equal(turn(restored, 'Which word?'), id);
assert.notEqual(turn(new AssistantSession(config, undefined), 'Hello'), id, 'a new conversation gets its own session');
});
test('URL normalization adds /v1 to a bare host and drops the endpoint path', () => {
const { normalizeHermesUrl } = hermes();
assert.equal(normalizeHermesUrl('http://192.0.2.10:8642'), 'http://192.0.2.10:8642/v1');
assert.equal(normalizeHermesUrl('http://h:8642/v1/chat/completions'), 'http://h:8642/v1');
assert.equal(normalizeHermesUrl('h:8642'), '');
});
test('the Hermes model resolves only with a URL, carrying the key and base URL', () => {
const load = loader({ global: { isIOS: true } }, { '../native/llama': { isLocalModelReady: () => false, LOCAL_MODEL: { id: 'q', label: 'Q' } } });
const { resolveAssistantModel } = load('app/assistant/models.ts');
assert.equal(resolveAssistantModel('hermes', { anthropic: '', openai: '' }), null);
const resolved = resolveAssistantModel('hermes', { anthropic: '', openai: '', hermesUrl: ' http://hermes-host:8642 ', hermesKey: ' k ' });
assert.deepEqual({ ...resolved }, { selection: 'hermes', provider: 'hermes', model: 'hermes-agent', apiKey: 'k', baseUrl: 'http://hermes-host:8642' });
assert.equal(resolveAssistantModel('auto', { anthropic: '', openai: '', hermesUrl: 'http://hermes-host:8642' }), null, 'Auto never picks Hermes');
});
+147 -35
View File
@@ -4,6 +4,11 @@ const fs = require('node:fs');
const vm = require('node:vm');
const ts = require('typescript');
const path = require('node:path');
// The provider settings ios-preview-controller hands the voice bridge.
const voiceSettings = { voiceProviderSetting: { get: () => 'onboard' }, elevenLabsApiKeySetting: { get: () => '' },
openAiApiKeySetting: { get: () => '' }, sonioxApiKeySetting: { get: () => '' },
whisperServerUrlSetting: { get: () => '' }, whisperServerModelSetting: { get: () => '' },
whisperServerLanguageSetting: { get: () => '' }, whisperServerApiKeySetting: { get: () => '' } };
function load(file, context) {
const sandbox = { exports: {}, ...context };
const source = fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
@@ -80,9 +85,10 @@ test('iOS settings prompts honor password input and report cancellation', async
test('iOS host forwards hands-free capture mode to the voice bridge', async () => {
const captures = [];
const { IosPreviewController } = load('app/g2/ios-preview-controller.ts', { require: id => id === '../native/ios-voice-input'
? { iosVoiceInput: { startGlassesCapture: (_session, _log, endpointing) => captures.push(endpointing) } } : {} });
? { iosVoiceInput: { startGlassesCapture: (_session, _voice, _log, endpointing) => captures.push(endpointing) } }
: id === '../ui/dashboard-settings' ? voiceSettings : {} });
const host = Object.create(IosPreviewController.prototype);
host.communicator = {}; host.state = { phase: 'connected' };
host.communicator = {}; host.state = { phase: 'connected' }; host.continuousClients = new Map();
await host.startVoiceCapture(true);
await host.startVoiceCapture();
assert.deepEqual(captures, [true, false]);
@@ -182,7 +188,7 @@ test('iOS bandwidth footer toggles live, polls only in foreground and resets its
'./phone-gestures': { PhoneGestureRecognizer: class { cancel() {} } },
'./ble-bandwidth-meter': require('../.test-build/app/phone-ui/ble-bandwidth-meter.js'),
'../native/ble-traffic': { sampleBleTraffic: () => totals },
'../ui/dashboard-settings': { brightnessSetting: { get: () => 'auto' }, displayModeSetting: { get: () => 'full' }, displayModeLabel: () => 'Full', showBleBandwidthSetting: { get: () => enabled },
'../ui/dashboard-settings': { brightnessSetting: { get: () => 'auto' }, displayLayoutSetting: { displayValue: () => 'Tall' }, showBleBandwidthSetting: { get: () => enabled },
onAnySettingChanged: fn => { settingListeners.add(fn); return () => settingListeners.delete(fn); } },
'../g2/device-addresses': { loadDeviceAddresses: () => ({}) },
'../g2/ios-peripheral-identity': { deviceAddressError: () => 'no test devices' },
@@ -253,70 +259,176 @@ test('iOS configures an in-process surface before submitting constructor-trigger
});
test('iOS compositor rejects missing and removed surfaces before crossing into Kotlin', () => {
let nativeSubmissions = 0;
const native = { configureIdXYWidthHeightZOrderTransparent() {}, removeId() {}, submitDrawsIdDataXYWidthHeightDraws() { nativeSubmissions++; } };
let nativeCalls = 0;
const native = { configureIdXYWidthHeightZOrderTransparent() {}, removeId() {}, submitDrawsIdDataXYWidthHeightDraws() { nativeCalls++; },
visibleIdVisible() { nativeCalls++; }, depthIdDepth() { nativeCalls++; } };
const api = load('app/graphics/surface-compositor.ios.ts', {
require: () => ({ toData: data => data }),
FaceclawKitIosSurfaceCompositor: { alloc: () => ({ initWithWidthHeight: () => native }) },
});
const c = new api.SurfaceCompositor(2, 1), pixels = new Uint8Array([1, 2]);
const rect = { x: 0, y: 0, width: 2, height: 1 };
assert.throws(() => c.submitSurfaceFrame('nightscout', pixels, rect), /Unknown surface/);
const rejectsAll = () => {
assert.throws(() => c.submitSurfaceFrame('nightscout', pixels, rect), /Unknown surface/);
assert.throws(() => c.setSurfaceVisible('nightscout', true), /Unknown surface/);
assert.throws(() => c.setSurfaceDepth('nightscout', 1), /Unknown surface/);
};
rejectsAll();
c.configureSurface('nightscout', { ...rect, zOrder: 0, transparency: 'opaque' });
c.submitSurfaceFrame('nightscout', pixels, rect);
c.setSurfaceVisible('nightscout', true);
c.setSurfaceDepth('nightscout', 1);
assert.throws(() => c.setSurfaceDepth('nightscout', 200), /Invalid surface depth/);
c.removeSurface('nightscout');
assert.throws(() => c.submitSurfaceFrame('nightscout', pixels, rect), /Unknown surface/);
assert.equal(nativeSubmissions, 1);
rejectsAll();
assert.equal(nativeCalls, 3);
});
test('iOS welcome sound waits for a new acknowledged frame and is consumed once', async () => {
let pending = true;
const played = [], sounds = load('app/ui/sound-effects.ts', { require: name => { assert.equal(name, '../g2/cfw-message-type'); return load('app/g2/cfw-message-type.ts', {}); } });
const { IosPreviewController } = load('app/g2/ios-preview-controller.ts', {
test('iOS opens the on-glasses onboarding on a new acknowledged frame, once per run while due', () => {
const settings = new Map();
const progress = load('app/apps/onboarding/onboarding-progress.ts', {
require: id => ({
'../phone-ui/onboarding-state': { isWelcomeSoundPending: () => pending, setWelcomeSoundPending: value => { pending = value; } },
'../ui/sound-effects': sounds,
})[id] ?? {},
setTimeout: fn => { fn(); return 1; },
'../../native/settings-store': {
getStringSetting: (key, fallback) => settings.get(key) ?? fallback,
setStringSetting: (key, value) => settings.set(key, value),
},
'../../version': { FACECLAW_VERSION: '9.9.9' },
})[id],
});
const launched = [];
const { IosPreviewController } = load('app/g2/ios-preview-controller.ts', {
require: id => ({ '../apps/onboarding/onboarding-progress': progress })[id] ?? {},
});
const host = Object.create(IosPreviewController.prototype);
host.acknowledgedFrames = 0;
host.actions = { playBuzzerSequence: bytes => played.push([...bytes]) };
host.logBluetooth = assert.fail;
host.maybePlayWelcomeSound({ phase: 'connecting', frames: 0 });
host.maybePlayWelcomeSound({ phase: 'connected', frames: 0 });
assert.equal(pending, true); assert.equal(played.length, 0);
host.maybePlayWelcomeSound({ phase: 'connected', frames: 1 });
assert.equal(pending, false);
await new Promise(resolve => setImmediate(resolve));
assert.ok(played.length > 0);
const count = played.length;
host.maybePlayWelcomeSound({ phase: 'connected', frames: 1 });
host.maybePlayWelcomeSound({ phase: 'connected', frames: 2 });
assert.equal(played.length, count);
host.launchApp = id => { launched.push(id); return Promise.resolve(); };
host.maybeLaunchOnboarding({ phase: 'connecting', frames: 0 });
host.maybeLaunchOnboarding({ phase: 'connected', frames: 0 });
assert.deepEqual(launched, []);
host.maybeLaunchOnboarding({ phase: 'connected', frames: 1 });
assert.deepEqual(launched, ['onboarding']);
// Still unfinished, but a reconnect in the same run doesn't reopen it.
host.maybeLaunchOnboarding({ phase: 'connected', frames: 2 });
assert.deepEqual(launched, ['onboarding']);
assert.equal(progress.isGlassesOnboardingDue(), true);
progress.markGlassesOnboardingFinished();
assert.equal(progress.isGlassesOnboardingDue(), false);
settings.set('onboarding.glassesFinishedVersion', '9.9.8');
assert.equal(progress.isGlassesOnboardingDue(), true, 'an upgrade makes onboarding due again');
});
test('iOS preview voice uses the phone microphone, while connected capture stays on glasses', async () => {
const calls = [];
const bridge = { prepare: async (foreground, phone) => { calls.push(['prepare', foreground, phone]); return true; },
startPhoneCapture: async (_log, endpointing) => calls.push(['phone', endpointing]),
startGlassesCapture: async (_session, _log, endpointing) => calls.push(['glasses', endpointing]) };
const bridge = { prepare: async (foreground, phone, voice) => { calls.push(['prepare', foreground, phone, voice.provider]); return true; },
startPhoneCapture: async (voice, _log, endpointing) => calls.push(['phone', voice.provider, endpointing]),
startGlassesCapture: async (_session, voice, _log, endpointing) => calls.push(['glasses', voice.provider, endpointing]) };
const { IosPreviewController } = load('app/g2/ios-preview-controller.ts', {
require: id => id === '../native/ios-voice-input' ? { iosVoiceInput: bridge } : {},
require: id => id === '../native/ios-voice-input' ? { iosVoiceInput: bridge } : id === '../ui/dashboard-settings' ? voiceSettings : {},
});
const host = Object.create(IosPreviewController.prototype);
host.active = true; host.glassesLocked = false; host.communicator = null; host.state = { phase: 'disconnected' };
host.continuousClients = new Map();
assert.equal(await host.prepareVoiceCapture(), true);
await host.startVoiceCapture(true);
assert.deepEqual(calls, [['prepare', true, true], ['prepare', true, true], ['phone', true]]);
assert.deepEqual(calls, [['prepare', true, true, 'onboard'], ['prepare', true, true, 'onboard'], ['phone', 'onboard', true]]);
calls.length = 0; host.communicator = {}; host.state = { phase: 'connected' };
assert.equal(await host.prepareVoiceCapture(), true); await host.startVoiceCapture(false);
assert.deepEqual(calls, [['prepare', true, false], ['glasses', false]]);
assert.deepEqual(calls, [['prepare', true, false, 'onboard'], ['glasses', 'onboard', false]]);
calls.length = 0; host.active = false; host.communicator = null; host.state = { phase: 'disconnected' };
assert.equal(await host.prepareVoiceCapture(), false); await host.startVoiceCapture();
assert.deepEqual(calls, []);
});
test('iOS continuous capture is shared by windows and restarts after a disconnect, a lock or backgrounding', async () => {
const calls = [], claims = [], providers = [];
// Models the bridge's continuous state: listening on a source, or draining after a stop.
const bridge = { source: null, draining: false, recording: '',
supportsContinuous: voice => voice.provider !== 'onboard',
get continuousSource() { return this.source; },
get continuousActive() { return !!this.source || this.draining; },
prepare: async () => true,
startGlassesCapture: async (_session, voice, _log, _endpointing, continuous) => {
calls.push(['glasses', continuous]); providers.push(`${voice.provider}:${voice.whisperServerLanguage}`); bridge.source = 'glasses'; },
startPhoneCapture: async (_voice, _log, _endpointing, continuous) => { calls.push(['phone', continuous]); bridge.source = 'phone'; },
drain() { if (this.source) { this.source = null; this.draining = true; } },
stopContinuousCapture: async () => { calls.push(['stop']); bridge.drain(); },
handleSessionEnded() { if (bridge.source === 'glasses') bridge.drain(); },
stopPhoneCapture() { if (bridge.source === 'phone') bridge.drain(); },
recordTo: name => { bridge.recording = name; } };
const settings = { ...voiceSettings, voiceProviderSetting: { get: () => 'whisper-server' },
whisperServerUrlSetting: { get: () => 'http://whisper.local:8000' }, whisperServerLanguageSetting: { get: () => 'en' },
saveTranscribeAudioSetting: { get: () => true } };
const { IosPreviewController } = load('app/g2/ios-preview-controller.ts', {
require: id => id === '../native/ios-voice-input' ? { iosVoiceInput: bridge } : id === '../ui/dashboard-settings' ? settings
: id === '../ui/shell/voice-activity' ? { voiceActivity: { setActive: (active, holder) => claims.push([active, holder]) } }
: id === '../native/cloud-stt-provider' ? { transcriptionKey: voice => `${voice.provider}:${voice.whisperServerLanguage}` } : {},
});
const host = Object.create(IosPreviewController.prototype);
Object.assign(host, { active: true, glassesLocked: false, communicator: {}, state: { phase: 'connected' }, sessionConnected: true,
continuousClients: new Map(), continuousPending: false, continuousCaptureToken: 0, displayReady: Promise.resolve(),
glance: { dismiss() {} }, onError: message => calls.push(['error', message]), logBluetooth() {}, fail() {}, requestShellRender() {},
syncRuntime() {}, flushBluetoothLog() {} });
const settle = () => new Promise(resolve => setImmediate(resolve));
// The bridge's end-of-capture callback, once a drain has finished.
const drained = () => { bridge.draining = false; host.syncContinuousCapture(); };
const session = phase => { host.state = { phase }; if (phase !== 'connected') bridge.handleSessionEnded(); host.syncContinuousSession(); };
host.startContinuousVoiceCapture('transcribe', { recordAs: 'transcribe-1' }); await settle();
host.startContinuousVoiceCapture('calculator'); await settle();
assert.deepEqual(calls, [['glasses', true]], 'the second window shares the capture');
assert.equal(bridge.recording, 'transcribe-1');
assert.deepEqual(claims.at(-1), [true, 'continuous-capture']);
host.stopContinuousVoiceCapture('calculator');
assert.deepEqual(calls, [['glasses', true]], 'closing one window keeps the other listening');
// Translate needs a multilingual provider: the shared capture drains and
// restarts on it (Whisper left to detect the language), and moves back to
// the main provider once Translate closes.
calls.length = 0; host.startContinuousVoiceCapture('translate', { multilingualProvider: 'soniox' }); await settle();
assert.deepEqual(calls, [['stop']]);
drained(); await settle();
assert.deepEqual(calls, [['stop'], ['glasses', true]]);
assert.deepEqual(providers.slice(-2), ['whisper-server:en', 'soniox:']);
calls.length = 0; host.stopContinuousVoiceCapture('translate'); drained(); await settle();
assert.deepEqual(calls, [['stop'], ['glasses', true]]);
assert.equal(providers.at(-1), 'whisper-server:en');
// A reconnect drains the capture, waits for the glasses, and resumes on them.
calls.length = 0; session('retrying'); drained(); await settle();
assert.deepEqual(calls, []);
assert.deepEqual(claims.at(-1), [false, 'continuous-capture'], 'other mic users may run meanwhile');
session('connected'); await settle();
assert.deepEqual(calls, [['glasses', true]]);
// Locking drains; unlocking resumes.
calls.length = 0; host.setGlassesLocked(true); drained(); await settle();
assert.deepEqual(calls, []);
host.setGlassesLocked(false); await settle();
assert.deepEqual(calls, [['glasses', true]]);
// A failed capture is not retried in a loop, only on the next session.
calls.length = 0; bridge.source = null; drained(); await settle();
assert.deepEqual(calls, []);
// Without glasses the phone mic stands in while in the foreground, and moves to the glasses when they connect.
host.communicator = null; session('disconnected'); await settle();
assert.deepEqual(calls, [['phone', true]]);
calls.length = 0; host.pause(); drained(); await settle();
assert.deepEqual(calls, [], 'no phone capture in the background');
host.active = true; host.syncContinuousCapture(); await settle();
assert.deepEqual(calls, [['phone', true]]);
calls.length = 0; host.communicator = {}; session('connected'); await settle();
assert.deepEqual(calls, [['stop']]);
drained(); await settle();
assert.deepEqual(calls, [['stop'], ['glasses', true]]);
// The last window closing stops it for good.
calls.length = 0; host.stopContinuousVoiceCapture('transcribe'); drained(); session('retrying'); session('connected'); await settle();
assert.deepEqual(calls, [['stop']]);
assert.equal(bridge.recording, '');
assert.deepEqual(claims.at(-1), [false, 'continuous-capture']);
});
test('iOS keyboard action opens the shared destination session and remains blocked while locked', () => {
let opened = 0;
const { IosPreviewController } = load('app/g2/ios-preview-controller.ts', {
+196
View File
@@ -0,0 +1,196 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
function load(file, modules = {}, globals = {}) {
const sandbox = { exports: {}, console, JSON, Promise, require: id => {
if (!(id in modules)) throw new Error(`Unstubbed import: ${id}`);
return modules[id];
}, ...globals };
vm.runInNewContext(ts.transpileModule(fs.readFileSync(path.join(__dirname, '..', file), 'utf8'), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText, sandbox);
return sandbox.exports;
}
const types = load('app/native/media-types.ts');
/** A FaceclawAppleMusic stand-in: state is plain data the tests mutate. */
function fakeMusic() {
const music = {
permission: 'granted', state: { access: true, hasItem: true, state: 'playing', title: 'Song', artist: 'Band',
album: 'Record', positionMs: 1000, durationMs: 200000, rate: 1, artVersion: 3 },
queue: '[]', volume: 40, art: null, calls: [], permissionRequests: [], browses: [], plays: [],
changeHandler: null,
hasPermission() { return this.permission === 'granted'; },
permissionStatus() { return this.permission; },
requestPermission(done) { this.permissionRequests.push(done); },
start() { this.calls.push('start'); }, stop() { this.calls.push('stop'); },
stateJson() { return JSON.stringify(this.hasPermission() ? this.state : { access: false }); },
playPause() { this.calls.push('playPause'); }, skipNext() { this.calls.push('skipNext'); },
skipPrevious() { this.calls.push('skipPrevious'); }, skipToQueueIndex(i) { this.calls.push(`skipTo:${i}`); },
queueJson() { return this.queue; },
albumArt(size) { this.calls.push(`art:${size}`); return this.art; },
volumePercent() { return this.volume; }, setVolumePercent(v) { this.calls.push(`volume:${v}`); },
browseCompletion(parentId, done) { this.browses.push({ parentId, done }); },
playCompletion(mediaId, done) { this.plays.push({ mediaId, done }); },
};
return music;
}
function controller(music = fakeMusic()) {
const timers = new Map(); let nextTimer = 1;
const dialogs = { confirms: [], alerts: [], confirmResult: true, opened: [] };
const protocolCalls = [];
const api = load('app/native/media-controller.ios.ts', {
'@nativescript/core': {
Dialogs: {
confirm: async options => { dialogs.confirms.push(options); return dialogs.confirmResult; },
alert: async options => { dialogs.alerts.push(options); },
},
Utils: { openUrl: url => dialogs.opened.push(url) },
},
'./image-files': { grayImageFromPacket: bytes => (bytes && bytes.length ? { bytes } : null), PHOTO_TONE: { gamma: 2.2, dither: true } },
'./kotlin-data': { fromData: data => data },
'./media-types': types,
}, {
FaceclawAppleMusic: { shared: () => music },
FaceclawKitIosProtocol: { new: () => ({ grayPacketBgraGammaDither: (packet, gamma, dither) => {
protocolCalls.push({ packet, gamma, dither }); return [1, 0, 1, 0, 200];
} }) },
setInterval: fn => { const id = nextTimer++; timers.set(id, fn); return id; },
clearInterval: id => timers.delete(id),
});
return { api, bridge: api.mediaControllerBridge, music, timers, dialogs, protocolCalls,
tick: () => { for (const fn of timers.values()) fn(); } };
}
test('Apple Music state normalizes the native player, access and missing items', () => {
const { appleMusicState } = controller().api;
const denied = appleMusicState({ access: false });
assert.equal(denied.accessEnabled, false); assert.equal(denied.available, false);
assert.equal(appleMusicState(null).accessEnabled, false);
const playing = appleMusicState({ access: true, hasItem: true, state: 'playing', title: 'A', artist: 'B', album: 'C',
positionMs: 5000, durationMs: 60000, rate: 0, artVersion: 7 });
assert.equal(playing.available, true); assert.equal(playing.appName, 'Apple Music');
assert.equal(playing.packageName, 'com.apple.Music');
assert.equal(playing.playbackSpeed, 1, 'a starting player reports rate 0 but is advancing');
assert.equal(playing.positionMs, 5000); assert.equal(playing.artVersion, 7);
assert.ok(playing.canPlayPause && playing.canSkipNext && playing.canSkipPrevious);
const paused = appleMusicState({ access: true, hasItem: true, state: 'paused', rate: 1, positionMs: 'x', durationMs: null });
assert.equal(paused.playbackSpeed, 0); assert.equal(paused.positionMs, -1); assert.equal(paused.durationMs, -1);
assert.equal(appleMusicState({ access: true, hasItem: true, state: 'odd' }).playbackState, 'unknown');
const empty = appleMusicState({ access: true, hasItem: false, state: 'playing' });
assert.equal(empty.accessEnabled, true); assert.equal(empty.available, false);
assert.equal(empty.playbackState, 'idle'); assert.equal(empty.canPlayPause, false);
});
test('listeners start observation, are told only of real changes, and the poll runs while anyone listens', () => {
const f = controller(); const seen = [];
const off = f.bridge.onStateChange(state => seen.push(state));
assert.deepEqual(f.music.calls, ['start']); assert.equal(seen.length, 1); assert.equal(f.timers.size, 1);
assert.equal(typeof f.music.changeHandler, 'function');
f.music.changeHandler(); // first refresh records the baseline
const baseline = seen.length;
f.music.state.positionMs = 9000; f.tick(); f.music.changeHandler();
assert.equal(seen.length, baseline, 'playback progress alone does not notify');
f.music.state.title = 'Next song'; f.music.state.artVersion = 4; f.tick();
assert.equal(seen.length, baseline + 1); assert.equal(seen.at(-1).title, 'Next song');
f.tick(); assert.equal(seen.length, baseline + 1);
off(); assert.equal(f.timers.size, 0);
f.music.state.title = 'Unheard'; f.music.changeHandler(); assert.equal(seen.length, baseline + 1);
f.bridge.onStateChange(() => {}); assert.equal(f.music.calls.filter(c => c === 'start').length, 1);
});
test('transport, queue, volume and album art go through the native player', async () => {
const f = controller();
await f.bridge.playPause(); await f.bridge.skipNext(); await f.bridge.skipPrevious(); await f.bridge.skipToQueueItem(2.4);
assert.deepEqual(f.music.calls, ['playPause', 'skipNext', 'skipPrevious', 'skipTo:2']);
assert.equal(f.bridge.skipRebuildsQueue, false);
f.music.queue = JSON.stringify([{ id: 0, title: 'One', active: false }, { id: 1, title: 'Two', active: true }, null]);
assert.deepEqual(JSON.parse(JSON.stringify(f.bridge.getQueue())),
[{ id: 0, title: 'One', active: false }, { id: 1, title: 'Two', active: true }, { id: -1, title: '', active: false }]);
f.music.queue = 'not json'; assert.equal(f.bridge.getQueue().length, 0);
assert.equal(f.bridge.getMediaVolumePercent(), 40);
f.music.volume = -1; assert.equal(f.bridge.getMediaVolumePercent(), -1);
f.music.volume = NaN; assert.equal(f.bridge.getMediaVolumePercent(), -1);
f.bridge.setMediaVolumePercent(140); assert.equal(f.music.calls.at(-1), 'volume:100');
assert.equal(f.bridge.getAlbumArt(112), null); assert.equal(f.protocolCalls.length, 0);
f.music.art = 'bgra-packet';
assert.deepEqual(Array.from(f.bridge.getAlbumArt(111.6).bytes), [1, 0, 1, 0, 200]);
assert.equal(f.music.calls.at(-1), 'art:112');
assert.deepEqual(f.protocolCalls[0], { packet: 'bgra-packet', gamma: 2.2, dither: true });
});
test('access requests share one prompt, and denied or restricted access points to Settings', async () => {
const f = controller(); f.music.permission = 'not-determined';
const seen = []; f.bridge.onStateChange(state => seen.push(state.accessEnabled));
assert.equal(f.bridge.hasAccess(), false); assert.equal(f.bridge.snapshot().accessEnabled, false);
const first = f.bridge.requestAccess(), second = f.bridge.requestAccess();
assert.equal(f.music.permissionRequests.length, 1);
f.music.permission = 'granted'; f.music.permissionRequests[0](true);
assert.equal(await first, true); assert.equal(await second, true);
assert.equal(seen.at(-1), true, 'listeners hear about the grant');
assert.equal(await f.bridge.requestAccess(), true); assert.equal(f.music.permissionRequests.length, 1);
f.music.permission = 'denied';
assert.equal(await f.bridge.requestAccess(), false);
assert.equal(f.dialogs.confirms.length, 1); assert.deepEqual(f.dialogs.opened, ['app-settings:']);
f.dialogs.confirmResult = false; await f.bridge.requestAccess(); assert.equal(f.dialogs.opened.length, 1);
f.music.permission = 'restricted';
assert.equal(await f.bridge.requestAccess(), false); assert.equal(f.dialogs.alerts.length, 1);
assert.equal(f.music.permissionRequests.length, 1);
});
function browser(music = fakeMusic()) {
const api = load('app/native/media-browser.ios.ts', { './media-types': types }, {
FaceclawAppleMusic: { shared: () => music },
});
return { bridge: api.mediaBrowserBridge, music };
}
test('the Apple Music library browses only with access and drops answers after disconnect', async () => {
const f = browser();
const [app] = f.bridge.listBrowsableApps();
assert.equal(app.appName, 'Apple Music');
await assert.rejects(f.bridge.connect({ ...app, packageName: 'other' }), /Only Apple Music/);
await assert.rejects(f.bridge.browse('root'), /Not connected/);
assert.equal(await f.bridge.connect(app), 'root');
const listing = f.bridge.browse('root');
assert.equal(f.music.browses[0].parentId, 'root');
f.music.browses[0].done(JSON.stringify([{ mediaId: 'playlists', title: 'Playlists', browsable: true }]), null);
assert.deepEqual(JSON.parse(JSON.stringify(await listing)),
[{ mediaId: 'playlists', title: 'Playlists', subtitle: '', browsable: true, playable: false }]);
const failed = f.bridge.browse('album:1');
f.music.browses[1].done(null, 'Unknown library item');
await assert.rejects(failed, /Unknown library item/);
const garbled = f.bridge.browse('songs');
f.music.browses[2].done('{', null);
await assert.rejects(garbled, /parse failed/);
f.bridge.playFromMediaId('song:5@album:1');
assert.equal(f.music.plays[0].mediaId, 'song:5@album:1');
const stale = f.bridge.browse('playlists');
f.bridge.disconnect();
f.music.browses[3].done('[]', null);
await assert.rejects(stale, /Disconnected/);
f.bridge.playFromMediaId('playlist:2'); assert.equal(f.music.plays.length, 1);
f.music.permission = 'denied';
assert.equal(f.bridge.listBrowsableApps().length, 0);
await assert.rejects(f.bridge.connect(app), /not allowed/);
});
+4 -2
View File
@@ -228,10 +228,12 @@ test('iOS assistant calendar tool awaits events, reports denied access and failu
const f = provider(), registered = new Map();
const { registerSystemTools } = load('app/assistant/system-tools.ts', {
'../native/calendar': f.api, '../native/calendar-permissions': f.permissions,
'../native/media-controller': {}, '../native/notification-icons': {}, '../ui/shell/shell': {}, './tool-registry': {},
'../native/media-controller': { mediaControllerBridge: { start: async () => {} } },
'../native/notification-icons': {}, '../ui/shell/shell': {}, './tool-registry': {},
}, { global: { isIOS: true } });
registerSystemTools({ registerSystemTool: (definition, handler) => registered.set(definition.name, handler) });
assert.deepEqual([...registered.keys()], ['glasses.get_state', 'glasses.show_alert', 'calendar.list_events']);
assert.deepEqual([...registered.keys()], ['glasses.get_state', 'glasses.show_alert', 'calendar.list_events',
'media.now_playing', 'media.play_pause', 'media.next']);
const list = registered.get('calendar.list_events');
const result = list({ within_hours: 2, max_events: 3 });
assert.equal(f.reads[0].max, 3); assert.equal(f.reads[0].window, 7200000);
+129
View File
@@ -0,0 +1,129 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
// FaceclawCommunicatorBridge over a fake Kotlin session that, like the real
// SurfaceCompositor, rejects calls for surfaces it does not hold. Configuring
// an id in `refused` fails the way IosGlassesSession reports it: false.
function harness(refused = new Set()) {
const calls = [];
const surfaces = new Set();
const session = {
setRequiredFirmwareRevisionRevision() {}, setListenerListener() {}, setPreviewAnimationListenerListener() {},
configureSurfaceIdXYWidthHeightZOrderTransparency(id) {
calls.push(['configure', id]);
if (refused.has(id)) return false;
surfaces.add(id);
return true;
},
removeSurfaceId(id) { calls.push(['remove', id]); surfaces.delete(id); },
setSurfaceVisibleIdVisible(id) { calls.push(['visible', id]); if (!surfaces.has(id)) throw new Error(`unknown surface ${id}`); return true; },
setSurfaceDepthIdDepth(id) { calls.push(['depth', id]); if (!surfaces.has(id)) throw new Error(`unknown surface ${id}`); return true; },
submitSurfaceFramePixels8bppSurfaceIdRectXRectYRectWidthRectHeightContentFingerprintPaintMsFrameIdGlyphs(_pixels, id) {
calls.push(['frame', id]);
if (!surfaces.has(id)) throw new Error(`unknown surface ${id}`);
return true;
},
isSurfaceCurrentSurfaceIdFingerprint: (id, fingerprint) => fingerprint === 'same',
};
class NSObject { static new() { return new this(); } }
const timers = [];
const load = loader({
NSObject, NativeClass: () => cls => cls, setTimeout: (fn, delay) => { timers.push({ fn, delay }); return timers.length; }, clearTimeout: id => { timers[id - 1].cleared = true; },
FaceclawKitIosGlassesSession: { alloc: () => ({ initWithRightAddressLeftAddressRingAddress: () => session }) },
FaceclawKitFaceclawBleCommunicatorListener: {}, FaceclawKitIosAncsListener: {}, FaceclawKitIosAudioPacketListener: {},
FaceclawKitFaceclawCompassListener: {}, console: { log() {}, warn() {} },
}, {
'@nativescript/core': { File: {}, knownFolders: {}, path: {} },
'../g2/firmware-compat': { REQUIRED_FACECLAW_FIRMWARE_VERSION: 37 },
'./kotlin-data': { toData: bytes => bytes, fromData: data => data },
'./ios-graphics': { previewPixels() {} },
'./ios-bluetooth': { iosBluetooth: {} },
});
const { FaceclawCommunicatorBridge } = load('app/native/faceclaw-communicator.ios.ts');
const bridge = new FaceclawCommunicatorBridge({ right: 'r', left: 'l' });
// Run queued native calls (each is one setTimeout(0) hop) until none are left.
async function drain() {
for (let i = 0; i < 50; i++) {
await new Promise(resolve => setImmediate(resolve));
const next = timers.find(timer => !timer.ran && !timer.cleared && timer.delay === 0);
if (!next) { await new Promise(resolve => setImmediate(resolve)); if (!timers.some(t => !t.ran && !t.cleared && t.delay === 0)) return; continue; }
next.ran = true; next.fn();
}
}
return { bridge, calls, drain };
}
const rect = { x: 0, y: 0, width: 2, height: 1 };
const options = { x: 0, y: 0, width: 2, height: 1, zOrder: 0, transparency: 'opaque' };
test('a frame queued behind its surface removal is dropped instead of reaching Kotlin', async () => {
const h = harness();
const configured = h.bridge.configureSurface('window:transcribe', options); await h.drain(); await configured;
// Close-window order: the removal is queued first, the in-flight render's frame lands behind it.
const removed = h.bridge.removeSurface('window:transcribe');
const frame = h.bridge.submitSurfaceFrame('window:transcribe', new Uint8Array(2), rect, 'f');
const visible = h.bridge.setSurfaceVisible('window:transcribe', true);
const depth = h.bridge.setSurfaceDepth('window:transcribe', 1);
await h.drain();
await Promise.all([removed, frame, visible, depth]);
assert.deepEqual(h.calls, [['configure', 'window:transcribe'], ['remove', 'window:transcribe']]);
});
test('frames for a live surface still go through, including the idle inline path', async () => {
const h = harness();
const configured = h.bridge.configureSurface('window:calc', options); await h.drain(); await configured;
await h.bridge.submitSurfaceFrame('window:calc', new Uint8Array(2), rect, 'f');
assert.deepEqual(h.calls.at(-1), ['frame', 'window:calc']);
const reconfigured = h.bridge.configureSurface('window:calc', options);
const frame = h.bridge.submitSurfaceFrame('window:calc', new Uint8Array(2), rect, 'g');
await h.drain(); await Promise.all([reconfigured, frame]);
assert.deepEqual(h.calls.slice(-2), [['configure', 'window:calc'], ['frame', 'window:calc']]);
});
test('a surface Kotlin refuses to configure rejects, and its frames never reach Kotlin', async () => {
const h = harness(new Set(['window:bad']));
// Handler attached up front: the rejection lands while drain() runs.
const configured = assert.rejects(h.bridge.configureSurface('window:bad', options), /Could not configure surface window:bad/);
const frame = h.bridge.submitSurfaceFrame('window:bad', new Uint8Array(2), rect, 'f');
await h.drain();
await Promise.all([configured, frame]);
assert.deepEqual(h.calls, [['configure', 'window:bad']]);
});
test('the preview target drops calls for surfaces it does not hold instead of reaching Kotlin', async () => {
// Like IosSurfaceCompositor: these throw undeclared Kotlin exceptions, which abort the process.
const calls = [];
const surfaces = new Set();
const held = (what, id) => { calls.push([what, id]); if (!surfaces.has(id)) throw new Error(`unknown surface ${id}`); };
const native = {
setPreviewAnimationListenerListener() {},
configureIdXYWidthHeightZOrderTransparent(id) { calls.push(['configure', id]); surfaces.add(id); },
removeId(id) { calls.push(['remove', id]); surfaces.delete(id); },
visibleIdVisible: id => held('visible', id),
depthIdDepth: id => held('depth', id),
submitDrawsIdDataXYWidthHeightDraws: id => held('frame', id),
};
const kotlinData = { toData: bytes => bytes, fromData: data => data };
const load = loader({
FaceclawKitIosSurfaceCompositor: { alloc: () => ({ initWithWidthHeight: () => native }) }, console: { log() {} },
}, {
'@nativescript/core': { File: {}, knownFolders: {}, path: {} },
'../graphics/image': { G2_LENS_WIDTH: 576, G2_LENS_HEIGHT: 288 },
'./ios-graphics': { previewPixels() {} },
'./kotlin-data': kotlinData, '../native/kotlin-data': kotlinData,
});
const { PreviewDisplayTarget } = load('app/native/preview-display.ios.ts');
const target = new PreviewDisplayTarget();
// A Glanceboard show() that outlived the session: the preview target replacing it never configured glance.
await target.setSurfaceDepth('glance', 2);
await target.setSurfaceVisible('glance', true);
await target.submitSurfaceFrame('glance', new Uint8Array(2), rect, 'f');
await target.configureSurface('window:calc', options);
await target.submitSurfaceFrame('window:calc', new Uint8Array(2), rect, 'f');
await target.removeSurface('window:calc');
// A worker frame that lands after its window closed.
await target.submitSurfaceFrame('window:calc', new Uint8Array(2), rect, 'g');
await target.setSurfaceVisible('window:calc', false);
assert.deepEqual(calls, [['configure', 'window:calc'], ['frame', 'window:calc'], ['remove', 'window:calc']]);
});
+36 -7
View File
@@ -15,6 +15,11 @@ fs.writeFileSync(path.join(dist, 'index.html'), `<script>flutter_inappwebview.ca
fs.writeFileSync(path.join(dist, 'app.js'), `
import { value } from './module.js';
const call = name => flutter_inappwebview.callHandler(name);
const params = new URLSearchParams(location.search);
if (params.has('code')) await call(['oauth', params.get('code'), params.get('state'), params.get('shim')].join(':'));
const frame = document.createElement('iframe'); frame.src = '/frame.html';
frame.onload = () => { if (frame.contentDocument.getElementById('frame')?.textContent === 'frame') call('iframe'); };
document.documentElement.appendChild(frame);
if (value === 42) await call('module');
const previous = localStorage.getItem('probe'); localStorage.setItem('probe','saved'); await call(previous === 'saved' ? 'restored' : 'stored');
if ((await (await fetch('/data.json')).json()).ok) await call('fetch');
@@ -24,24 +29,48 @@ await WebAssembly.instantiate(new Uint8Array([0,97,115,109,1,0,0,0])); await cal
if (!(await fetch('/%2e%2e/secret.txt')).ok) await call('traversal');
`);
fs.writeFileSync(path.join(dist, 'module.js'), 'export const value = 42;');
const untrusted = "<script>webkit.messageHandlers.faceclaw.postMessage({kind:'call', name:'UNTRUSTED', args:'[]', id:0})</script>";
fs.writeFileSync(path.join(dist, 'frame.html'), `<p id="frame">frame</p>${untrusted}`);
fs.writeFileSync(path.join(dist, 'data.json'), '{"ok":true}');
fs.writeFileSync(path.join(dist, 'pixel.png'), Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aBVkAAAAASUVORK5CYII=', 'base64'));
fs.writeFileSync(path.join(bundle, 'Info.plist'), `<?xml version="1.0"?><plist version="1.0"><dict><key>CFBundleIdentifier</key><string>com.faceclaw.evenhub-probe</string><key>CFBundleExecutable</key><string>EvenHubProbe</string><key>CFBundleName</key><string>EvenHubProbe</string><key>CFBundlePackageType</key><string>APPL</string><key>CFBundleVersion</key><string>1</string><key>CFBundleShortVersionString</key><string>1</string><key>NSAppTransportSecurity</key><dict><key>NSAllowsLocalNetworking</key><true/></dict><key>UILaunchScreen</key><dict/><key>LSRequiresIPhoneOS</key><true/></dict></plist>`);
const sdk = execFileSync('xcrun', ['--sdk', 'iphonesimulator', '--show-sdk-path'], { encoding: 'utf8' }).trim();
execFileSync('xcrun', ['clang', '-fobjc-arc', '-target', `${process.arch === 'arm64' ? 'arm64' : 'x86_64'}-apple-ios15.1-simulator`, '-isysroot', sdk,
'-framework', 'UIKit', '-framework', 'Foundation', '-framework', 'CoreGraphics', '-framework', 'WebKit', '-framework', 'UniformTypeIdentifiers',
'-framework', 'UIKit', '-framework', 'Foundation', '-framework', 'CoreGraphics', '-framework', 'WebKit', '-framework', 'SafariServices', '-framework', 'UniformTypeIdentifiers',
'-I', 'App_Resources/iOS/src', 'tests/native/ios-evenhub-test.m', 'App_Resources/iOS/src/FaceclawEvenHubWebView.m', 'App_Resources/iOS/src/FaceclawCrypto.m', '-o', path.join(bundle, 'EvenHubProbe')], { cwd: root, stdio: 'inherit' });
// Requests that must never arrive: the provider's reply landing outside the app,
// host messages evaluated in a page the app navigated away to, and the cookie the
// first package's sign-in page set reaching the server from another package.
// ownCookie (the first package sending it again later) shows the cookie stuck.
const hits = { callback: 0, awayEval: 0, cookieLeak: 0, ownCookie: 0 };
const server = http.createServer((request, response) => {
if (request.url === '/redirect') { response.writeHead(302, { Location: `http://localhost:${server.address().port}/untrusted` }); response.end(); return; }
if (request.url === '/untrusted') { response.end("<script>webkit.messageHandlers.faceclaw.postMessage({kind:'call', name:'UNTRUSTED', args:'[]', id:0})</script>"); return; }
const file = path.join(dist, request.url === '/' ? 'index.html' : request.url.slice(1));
const url = new URL(request.url, 'http://probe'), port = server.address().port;
if (/\bprobe=1\b/.test(request.headers.cookie ?? '')) {
if (url.pathname === '/away') hits.ownCookie++;
else if (url.pathname !== '/approve') hits.cookieLeak++;
}
// The app's URL redirects to another origin before loading; the app lives there.
if (url.pathname === '/redirect') { response.writeHead(302, { Location: `http://localhost:${port}/` }); response.end(); return; }
// A third-party sign-in page: no bridge or shim, then a server redirect to the app's redirect_uri.
if (url.pathname === '/authorize') { response.end(`${untrusted}<script>document.cookie = 'probe=1; max-age=3600'; location.replace('/approve' + location.search + '&shim=' + typeof window.flutter_inappwebview)</script>`); return; }
if (url.pathname === '/approve') {
const query = url.searchParams;
response.writeHead(302, { Location: `${query.get('redirect_uri')}?code=probe&state=${query.get('state')}&shim=${query.get('shim')}` }); response.end(); return;
}
if (url.pathname.startsWith('/callback')) { hits.callback++; response.end('callback'); return; }
if (url.pathname === '/away') { response.end('<p>away</p>'); return; }
if (url.pathname === '/away-eval') { hits.awayEval++; response.end(); return; }
const file = path.join(dist, url.pathname === '/' ? 'index.html' : url.pathname.slice(1));
if (!file.startsWith(dist + path.sep) || !fs.existsSync(file)) { response.writeHead(404); response.end(); return; }
response.setHeader('Content-Type', file.endsWith('.js') ? 'text/javascript' : file.endsWith('.json') ? 'application/json' : file.endsWith('.png') ? 'image/png' : 'text/html');
response.end(fs.readFileSync(file));
});
server.listen(0, '127.0.0.1', async () => {
try {
fs.writeFileSync(path.join(bundle, 'remote.txt'), `http://127.0.0.1:${server.address().port}/`);
const port = server.address().port;
fs.writeFileSync(path.join(bundle, 'remote.txt'), `http://127.0.0.1:${port}/`);
fs.writeFileSync(path.join(bundle, 'authorize.txt'),
`http://127.0.0.1:${port}/authorize?client_id=probe&redirect_uri=${encodeURIComponent(`http://localhost:${port}/callback/`)}&state=s1`);
const device = process.argv[2] || 'booted';
execFileSync('xcrun', ['simctl', 'install', device, bundle], { stdio: 'inherit' });
const container = execFileSync('xcrun', ['simctl', 'get_app_container', device, 'com.faceclaw.evenhub-probe', 'data'], { encoding: 'utf8' }).trim();
@@ -60,8 +89,8 @@ server.listen(0, '127.0.0.1', async () => {
await new Promise(resolve => setTimeout(resolve, 100));
}
const result = JSON.parse(fs.readFileSync(resultFile, 'utf8'));
console.log(JSON.stringify({ work, ...result }));
if (!result.passed) process.exitCode = 1;
console.log(JSON.stringify({ work, hits, ...result }));
if (!result.passed || hits.callback || hits.awayEval || hits.cookieLeak || !hits.ownCookie) process.exitCode = 1;
} catch (error) {
console.error(error); process.exitCode = 1;
} finally {
+86 -3
View File
@@ -78,8 +78,8 @@ test('local package runtimes unpack independently and clean up after closing or
assert.equal(files.size, 0);
});
function sessionHarness(overrides = {}, playBuzzer = () => {}) {
const settings = new Map(), logs = [], renders = [];
function sessionHarness(overrides = {}, playBuzzer = () => {}, { packageId = 'test.probe', settings = new Map() } = {}) {
const logs = [], renders = [];
const load = loader({ global: { isIOS: true }, setTimeout, clearTimeout, Promise }, {
'@nativescript/core': { ApplicationSettings: { getString: (k, d) => settings.get(k) ?? d, setString: (k, v) => settings.set(k, v) } },
'upng-js': require('upng-js'),
@@ -90,7 +90,7 @@ function sessionHarness(overrides = {}, playBuzzer = () => {}) {
'../../native/location': {}, '../../native/location-tracker': {}, '../../native/location-permissions': {}, ...overrides,
});
const api = load('app/apps/evenhub/session.ts');
const session = new api.EvenHubSession({ name: 'Probe', packageId: 'test.probe', permissions: [] }, '/test/dist', line => logs.push(line), '', playBuzzer);
const session = new api.EvenHubSession({ name: 'Probe', packageId, permissions: [] }, '/test/dist', line => logs.push(line), '', playBuzzer);
session.attachWindow({ requestRender: () => renders.push(1), windowId: 'probe', closeWindow() {} });
const web = vm.createContext({ Promise, Map, Date, console });
web.window = web;
@@ -138,6 +138,52 @@ test('iOS webview adapter defers loading until handles attach and destroys a not
remote.destroy();
});
test('iOS webview adapter passes fatal errors through and logs host notices', () => {
const native = {}, failures = [], logs = [];
const load = loader({ FaceclawEvenHubWebView: { new: () => native }, setTimeout: () => 1, clearTimeout() {},
console: { log: line => logs.push(line), warn() {} } }, {
'./session': { EVENHUB_BRIDGE_INJECT_SCRIPT: '', buildFaceclawExtensionsScript: () => '' }, '../../version': { FACECLAW_VERSION: 'test' },
});
load('app/apps/evenhub/webview.ios.ts').createEvenHubWebView({ manifest: { name: 'Probe' },
webViewFailed: (message, fatal) => failures.push([message, fatal]) });
native.eventHandler(JSON.stringify({ kind: 'error', message: 'offline' }));
native.eventHandler(JSON.stringify({ kind: 'error', message: 'crashed', fatal: true }));
native.eventHandler(JSON.stringify({ kind: 'notice', message: 'Blocked navigation to a mailto: URL.' }));
assert.deepEqual(failures, [['offline', false], ['crashed', true]]);
assert.deepEqual(logs, ['[evenhub:Probe] Blocked navigation to a mailto: URL.']);
});
test('EvenHub load errors replace the window only before the app loads, and a later load clears them', () => {
const drawn = [];
const h = sessionHarness({ '../../graphics/evenhub-font': { EvenHubFont: { get: () => ({
drawText: (_image, _x, _y, text) => drawn.push(text), drawTextWrapped() {}, lineHeight: 20 }) } } });
const heading = () => { drawn.length = 0; h.session.paint({ width: 576, height: 288 }, true); return drawn[0]; };
h.session.webViewFailed('offline');
assert.equal(heading(), 'Could not run Probe...');
h.session.webViewLoaded();
assert.equal(heading(), 'Loading Probe...');
// A failed navigation after the first load leaves the app's page running.
h.session.webViewFailed('A server with the specified hostname could not be found.');
assert.equal(heading(), 'Loading Probe...');
assert.ok(h.logs.includes('evenhub: A server with the specified hostname could not be found.'));
h.session.webViewFailed('The app\'s web process ended.', true);
assert.equal(heading(), 'Could not run Probe...');
h.session.close();
});
test('SDK storage is partitioned by package, even for package IDs containing the key separator', async () => {
const settings = new Map();
const [plain, colon, percent] = ['a', 'a:ls:b', 'a%3Als%3Ab'].map(packageId => sessionHarness({}, undefined, { packageId, settings }));
assert.equal(await colon.call('setLocalStorage', { key: 'c', value: 'secret' }), true);
assert.equal(await colon.call('getLocalStorage', { key: 'c' }), 'secret');
assert.equal(await plain.call('getLocalStorage', { key: 'b:ls:c' }), '');
assert.equal(await percent.call('getLocalStorage', { key: 'c' }), '');
// Ordinary package IDs keep their existing keys.
assert.equal(await plain.call('setLocalStorage', { key: 'k', value: 'v' }), true);
assert.equal(settings.get('evenhub:a:ls:k'), 'v');
for (const h of [plain, colon, percent]) h.session.close();
});
test('EvenHub location uses the platform boundary and closes its subscription', async () => {
let permission = true, callback, starts = 0, stops = 0;
const fix = { latitude: 12, longitude: 34, accuracyMeters: 5, timestampMs: 1234 };
@@ -214,3 +260,40 @@ test('EvenHub buzzer RPC uses the host action on iOS and chunks and paces long s
assert.equal(played.length, 2);
h.session.close();
});
test('EvenHub buzzer RPC rejects the app promise when sending fails', async () => {
const sounds = loader()('app/ui/sound-effects.ts');
const h = sessionHarness({ '../../ui/sound-effects': sounds }, () => Promise.reject(new Error('link lost')));
await assert.rejects(h.session.dispatchExtension('playBuzzer', [[{ freq: 880, ms: 50 }]]), /link lost/);
h.session.close();
});
test('EvenHub assistant tools skip malformed names and schemas with a warning in the app console', () => {
const offered = [];
const h = sessionHarness({ '../../assistant/tool-registry': { toolRegistry: { setAppTools: provider => offered.push(provider), removeAppTools() {} } } });
const warnings = [];
h.web.console = { warn: message => warnings.push(message) };
const object = { type: 'object', properties: { n: { type: 'number' } }, required: ['n'] };
h.session.dispatchExtension('setAssistantTools', [[
{ name: 'ok', description: 'fine', parameters: object },
{ name: 'no_params', description: 'defaults' },
{ name: 'has space', parameters: object },
{ name: 'x'.repeat(65), parameters: object },
{ name: 'untyped', parameters: { properties: {} } },
{ name: 'string', parameters: { type: 'string' } },
{ name: 'union', parameters: { type: 'object', anyOf: [object] } },
{ name: 'bad_props', parameters: { type: 'object', properties: [] } },
{ name: 'bad_required', parameters: { type: 'object', required: 'n' } },
]]);
// Through JSON: the default schema is built in the session's realm.
assert.deepEqual(JSON.parse(JSON.stringify(offered[0].specs.map(spec => [spec.name, spec.inputSchema]))), [
['ok', object],
['no_params', { type: 'object', properties: {} }],
]);
assert.equal(warnings.length, 7);
assert.ok(warnings.every(message => message.startsWith('Faceclaw: setAssistantTools: skipped tool')));
assert.match(warnings[0], /"has space": name must be/);
assert.match(warnings[2], /"untyped": parameters must be a JSON Schema with type "object"/);
assert.match(warnings[4], /"union": parameters can't use oneOf, anyOf or allOf/);
h.session.close();
});
+9 -4
View File
@@ -138,22 +138,27 @@ function fixture() {
"../native/compass.ios": { bindCompassSession() {}, receiveCompassEvent() {} },
'@nativescript/core': { File: { fromPath: () => ({ writeTextSync() {} }) },
knownFolders: { documents: () => ({ path: '/tmp' }) }, path },
'../native/ios-voice-input': { iosVoiceInput: { handleSessionEnded() {}, stopPhoneCapture() {} } },
'../native/ios-voice-input': { iosVoiceInput: { handleSessionEnded() {}, stopPhoneCapture() {}, onSpeechEnd: () => () => {} } },
'../native/cloud-stt-provider': { transcriptionKey: voice => voice.provider },
'../ui/shell/voice-activity': { voiceActivity: { setActive() {}, isActive: () => false, subscribe: () => () => {} } },
'../native/faceclaw-communicator.ios': { FaceclawCommunicatorBridge, resolveIosPeripherals: async addresses => addresses },
'../native/preview-display.ios': { PreviewDisplayTarget },
'./ancs-client': { ANCS_FIRMWARE_VERSION: 16, AncsClient: class { state = 'disconnected'; start() {} stop() {} stopCommand() { return new Uint8Array(); } receive() { return false; } } },
'../native/nightscout-bridge': { nightscoutBridge: { async start() {}, async stop() {} } },
'../native/weather': { weatherBridge: { setSessionActive() {} } },
'./glance-host': { GlanceHost }, './events': events,
// Whole-panel mirror: the pixel assertions below index the full 640x480 preview.
'./phone-preview-crop': { phonePreviewCrop: () => null, mirrorToPanelFraction: (_crop, nx, ny) => ({ nx, ny }) },
'./lock-screen': { LOCK_SCREEN_SURFACE_ID: 'lock-screen', createLockScreenImage: () => new images.GrayImage(640, 480, 123) },
'./glasses-presence': load('app/g2/glasses-presence.ts', {}),
'./device-addresses': { loadDeviceAddresses: () => ({ right: 'AA', left: 'BB', ring: '' }) }, './ios-peripheral-identity': { deviceAddressError: () => null },
'./firmware-compat': load('app/g2/firmware-compat.ts', {}), './reconnect-policy': load('app/g2/reconnect-policy.ts', {}),
'../apps/launcher': { launcherEntries: () => [] },
'../apps/evenhub/installed-apps': {}, '../apps/evenhub/manager': {}, '../apps/evenhub/updates': {}, '../apps/evenhub': {},
'../apps/evenhub/installed-apps': {}, '../apps/evenhub/manager': { onPhoneShownChanged: () => () => {}, phoneUiButton: () => null },
'../apps/evenhub/updates': {}, '../apps/evenhub': {},
'../apps/launcher/launcher-app': { createLauncherWindow: () => window, LAUNCHER_SURFACE_ID: 'launcher' },
'../apps/all-apps': { ALL_APPS: [{ appId: 'glanceboard', glanceboard: provider }] },
'../phone-ui/onboarding-state': { isWelcomeSoundPending: () => false },
'../ui/sound-effects': {},
'../apps/onboarding/onboarding-progress': { claimGlassesOnboardingAutoLaunch: () => false },
'../ui/shell/worker-window': {}, '../ui/shell/in-process-window': {},
'../ui/dashboard-settings': { brightnessSetting: { get: () => 'auto' }, brightnessSettingToLevel: () => null, getBrightnessPreferences: () => ({ auto: true, level: 50, minimum: 2, maximum: 100, curve: '0:0,1000:100', fadeMs: 280 }), lockScreenEnabledSetting: { get: () => settings.lock }, onAnySettingChanged: fn => { settingsChanged = fn; return () => {}; }, previewColorSetting: { get: () => 'white' } },
'../native/phone-battery': { readPhoneBatteryState: () => ({ battery: 80, charging: false }) },
+2 -1
View File
@@ -97,6 +97,7 @@ test('Weather uses the portable location provider and preserves NWS parsing', as
'./location-permissions': { hasLocationPermission: () => permission },
'./settings-store': { getStringSetting: (_key, fallback) => fallback, setStringSetting() {} },
'./location': { getCurrentLocation: async () => fix },
'./reverse-geocode': { reverseGeocode: async () => null },
'../version': { USER_AGENT: 'test' },
'../util/http': { fetchWithUserAgent: async url => { requests.push(url); return { ok: true, json: async () =>
url.includes('/points/') ? { properties: { forecast: 'https://fixture/forecast', relativeLocation: { properties: { city: 'San Francisco', state: 'CA' } } } }
@@ -117,7 +118,7 @@ test('closing Weather during permission prompt cannot restart polling', async ()
'../../native/weather': { weatherBridge: { start() { starts++; }, stop() { stops++; }, onStateChange: () => () => {}, snapshot() {} } },
'./weather': { WeatherLayer: class {} },
'./weather-settings': {},
'../../ui/dashboard-settings': { toggleSettingMenuItem: () => ({}) },
'../../ui/dashboard-settings': { toggleSettingMenuItem: () => ({}), onAnySettingChanged: () => () => {} },
'../../ui/dashboard/settings-panel': { openSettingsSubMenu() {} },
'../../ui/shell/in-process-window': { YieldAtRootLayer: class {}, createInProcessWindow: opts => { options = opts; return { requestRender() {} }; } },
})('app/apps/weather/weather-app.ts');
+51
View File
@@ -0,0 +1,51 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
class FakeImage {
constructor(name) { this.name = name; }
clone() { return new FakeImage(this.name); }
fillRoundedRect() {}
fillRect() {}
}
function setup(notifications, render = name => new FakeImage(name)) {
const icons = loader({}, {
'../graphics/image': { GrayImage: class extends FakeImage { constructor() { super('drawn-bell'); } } },
'../graphics/icons': { renderIcon: (name, size) => { assert.equal(size, 24); return render(name); } },
'../g2/ancs-client': { AncsClient: class {}, ANCS_CONNECT_MESSAGE: '' },
'./notification-sources': { rememberNotificationSources() {} },
})('app/native/notification-icons.ios.ts');
icons.bindIosNotifications({ read: () => notifications });
return icons;
}
const notification = (key, packageName, category) => ({ key, packageName, category });
test('tray icons follow each source\'s first notification category', () => {
const icons = setup([
notification('a', 'com.apple.mobilephone', '2'),
notification('b', 'com.apple.mobilephone', '1'),
notification('c', 'com.apple.mobilemail', '6'),
notification('d', 'com.example.tv', '11'),
]);
const result = icons.readActiveNotificationIcons(10, false);
assert.deepEqual([...result.keys], ['a', 'c', 'd']);
assert.deepEqual([...result.icons].map(icon => icon.name), ['phone-missed', 'mail', 'tv']);
assert.equal(icons.readActiveNotificationIcons(1, false).icons.length, 1);
});
test('unknown categories use the bell; a failed rasterization uses the drawn bell', () => {
const icons = setup([notification('a', 'x', '0'), notification('b', 'y', '12'), notification('c', 'z', '')]);
assert.deepEqual([...icons.readActiveNotificationIcons(10, false).icons].map(icon => icon.name), ['bell', 'bell', 'bell']);
assert.equal(icons.readNotificationIconByKey('missing', false).icon, null);
const failing = setup([notification('a', 'x', '4')], () => null);
assert.equal(failing.readNotificationIconByKey('a', false).icon.name, 'drawn-bell');
});
test('icons are copies, so callers can draw on them', () => {
const shared = new FakeImage('message-circle');
const icons = setup([notification('a', 'x', '4')], () => shared);
assert.notEqual(icons.readNotificationIconByKey('a', false).icon, shared);
});
+57
View File
@@ -0,0 +1,57 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
function harness(width, height) {
const font = { lineHeight: 20, measureText: text => text.length * 10, getGlyph: () => ({ dwidthX: 10 }) };
const load = loader({}, { './onboarding-fonts': { onboardingFont: () => font } });
const { IosPrivacyPage } = load('app/apps/onboarding/ios-privacy-page.ts');
const { IOS_PRIVACY_NOTICE } = load('app/analytics/privacy-disclosure.ts');
const page = new IosPrivacyPage();
let next = 0;
return {
page, notice: IOS_PRIVACY_NOTICE, get next() { return next; },
input(type) { page.handleInput({ type }, { next: () => next++ }); },
paint() {
const rows = [];
page.paint({ width, height, drawText(font, x, y, text) {
assert.ok(x + font.measureText(text) <= width, `horizontal overflow: ${text}`);
assert.ok(y >= 0 && y + font.lineHeight <= height, `vertical overflow: ${text}`);
rows.push({ y, text });
} });
return rows;
},
};
}
for (const [width, height] of [[576, 188], [576, 260], [640, 432]]) {
test(`entire iOS notice is readable before continuing at ${width}x${height}`, () => {
const h = harness(width, height);
const shown = [];
for (let i = 0; !h.next && i < 30; i++) {
const rows = h.paint();
const footer = rows.at(-1);
for (const row of rows.slice(1, -1)) {
assert.ok(row.y + 20 <= footer.y, 'body must not overlap navigation');
shown.push(row.text);
}
h.input('click');
}
assert.equal(h.next, 1);
// Line breaking may also split after punctuation (e.g. device/app).
assert.equal(shown.join('').replace(/\s+/g, ''), h.notice.replace(/\s+/g, ''));
});
}
test('scrolling stays inside the notice; revisiting starts at the beginning', () => {
const h = harness(576, 188);
const first = h.paint().map(row => row.text);
h.input('scroll-up');
assert.deepEqual(h.paint().map(row => row.text), first);
h.input('scroll-down');
assert.notDeepEqual(h.paint().map(row => row.text), first);
for (let i = 0; i < 30; i++) h.input('scroll-down');
assert.equal(h.next, 0, 'scrolling must not accept the notice');
h.page.enter();
assert.deepEqual(h.paint().map(row => row.text), first);
});
+7 -2
View File
@@ -7,8 +7,13 @@ const { join, resolve } = require('node:path');
const root = resolve(__dirname, '..'), dir = mkdtempSync(join(tmpdir(), 'faceclaw-socket-'));
execFileSync('xcrun', ['clang', '-fobjc-arc', '-framework', 'Foundation', '-I', 'App_Resources/iOS/src',
'tests/native/ios-socket-test.m', 'App_Resources/iOS/src/FaceclawSocket.m', '-o', join(dir, 'socket-test')], { cwd: root, stdio: 'inherit' });
const server = new WebSocketServer({ host: '127.0.0.1', port: 0 });
server.on('connection', socket => socket.on('message', data => socket.send(data.toString(), () => socket.close(1000, 'done'))));
// Requires the handshake header; answers binary frames with their hex, echoes text and closes.
const server = new WebSocketServer({ host: '127.0.0.1', port: 0,
verifyClient: (info, done) => done(info.req.headers['x-faceclaw-key'] === 'secret', 401, 'Unauthorized') });
server.on('connection', socket => socket.on('message', data => {
if (Buffer.isBuffer(data)) socket.send(`binary:${data.toString('hex')}`);
else socket.send(data, () => socket.close(1000, 'done'));
}));
server.on('listening', () => {
const child = spawn(join(dir, 'socket-test'), [`ws://127.0.0.1:${server.address().port}`], { stdio: 'inherit' });
child.on('exit', code => { server.close(); rmSync(dir, { recursive: true, force: true }); process.exitCode = code ?? 1; });
+208 -20
View File
@@ -4,15 +4,35 @@ const fs = require('node:fs');
const vm = require('node:vm');
const ts = require('typescript');
function harness() {
const native = { startWithEndpointing(endpointing) { this.endpointing = endpointing; return ''; }, startPhoneWithEndpointing(endpointing) { this.endpointing = endpointing; this.phone = true; return this.error ?? ''; }, cancel() { this.cancels++; }, cancels: 0, finish() { this.finished = true; }, acceptPacket: p => audio.push(p) };
const audio = [], timers = new Map(), commands = [], text = [];
const native = { startWithEndpointing(endpointing) { this.endpointing = endpointing; return ''; }, startPhoneWithEndpointing(endpointing) { this.endpointing = endpointing; this.phone = true; return this.error ?? ''; },
startPcmCaptureWithEndpointingPhone(endpointing, phone) { this.pcmCapture = { endpointing, phone }; return this.error ?? ''; },
cancel() { this.cancels++; }, cancels: 0, finish() { this.finished = true; }, acceptPacket: p => audio.push(p) };
const audio = [], timers = new Map(), commands = [], text = [], clouds = [];
// Stands in for cloud-stt-provider: any provider but "onboard" is a keyed cloud one.
const provider = {
usesCloudStt: voice => voice.provider !== 'onboard',
createCloudSttClient(voice, options, continuous) {
if (voice.provider === 'onboard') return null;
const client = { options, continuous, pcm: [], started: false, finished: 0, stopped: false,
start() { this.started = true; }, acceptPcm(bytes) { this.pcm.push([...bytes]); },
finish() { this.finished++; }, stop() { this.stopped = true; } };
clouds.push(client); return client;
},
};
const recordings = [];
class FakeRecorder {
static open(name) { const r = new FakeRecorder(); r.name = name; r.path = `/Downloads/${name}.wav`; r.pcm = []; r.closed = false; recordings.push(r); return r; }
append(bytes) { this.pcm.push(...bytes); }
close() { this.closed = true; }
}
let authorization = 3, microphoneAuthorization = 3, microphoneRequests = 0, permissionRequests = 0, release;
const sandbox = { exports: {}, FaceclawSpeech: { new: () => native, authorizationStatus: () => authorization,
requestAuthorization: done => { permissionRequests++; done(3); },
microphoneAuthorizationStatus: () => microphoneAuthorization,
requestMicrophoneAuthorization: done => { microphoneRequests++; done(3); } },
setTimeout: fn => { timers.set(fn, fn); return fn; }, clearTimeout: fn => timers.delete(fn),
NSData: { dataWithBytesLength: (b, n) => Buffer.from(b, 0, n) }, interop: { handleof: b => b } };
NSData: { dataWithBytesLength: (b, n) => Buffer.from(b, 0, n) }, interop: { handleof: b => b, bufferFromData: d => d },
require: name => name === './cloud-stt-provider' ? provider : name === './wav-recorder.ios' ? { WavRecorder: FakeRecorder } : {} };
vm.runInNewContext(ts.transpileModule(fs.readFileSync('app/native/voice-control.ios.ts', 'utf8'), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 } }).outputText, sandbox);
const bridge = new sandbox.exports.IosVoiceControlBridge();
@@ -22,20 +42,22 @@ function harness() {
if (enabled) { this.packet = fn; return new Promise(resolve => { release = resolve; }); }
return Promise.resolve();
} };
return { bridge, native, session, audio, commands, text, timers, release: () => release(),
const onboard = { provider: 'onboard', elevenLabsApiKey: '', openAiApiKey: '', sonioxApiKey: '' };
return { bridge, native, session, audio, commands, text, timers, clouds, recordings, release: () => release(),
onboard, cloud: { ...onboard, provider: 'soniox', sonioxApiKey: 'key' },
microphoneAuthorization: value => { microphoneAuthorization = value; }, microphoneRequests: () => microphoneRequests,
authorization: value => { authorization = value; }, permissionRequests: () => permissionRequests,
event: event => native.eventHandler(JSON.stringify(event)) };
}
test('iOS speech permission is requested only in foreground and denial stays actionable', async () => {
const h = harness(); h.authorization(0);
assert.equal(await h.bridge.prepare(false), false); assert.equal(h.permissionRequests(), 0);
assert.equal(await h.bridge.prepare(true), true); assert.equal(h.permissionRequests(), 1);
h.authorization(2); assert.equal(await h.bridge.prepare(true), false);
assert.equal(await h.bridge.prepare(false, false, h.onboard), false); assert.equal(h.permissionRequests(), 0);
assert.equal(await h.bridge.prepare(true, false, h.onboard), true); assert.equal(h.permissionRequests(), 1);
h.authorization(2); assert.equal(await h.bridge.prepare(true, false, h.onboard), false);
assert.match(h.bridge.statusText, /Settings/);
});
test('glasses speech sends PCM-source packets, replaces partials, and drains final text after manual release', async () => {
const h = harness(); const start = h.bridge.startGlassesCapture(h.session, () => {});
const h = harness(); const start = h.bridge.startGlassesCapture(h.session, h.onboard, () => {});
h.session.packet(new Uint8Array([1, 2, 3])); assert.deepEqual([...h.audio[0]], [1, 2, 3]);
h.release(); await start;
h.event({ kind: 'transcript', text: 'hello', final: false });
@@ -51,7 +73,7 @@ test('glasses speech sends PCM-source packets, replaces partials, and drains fin
test('cancel and disconnect during enable cannot resurrect capture or leave its microphone listener active', async () => {
for (const stop of ['stop', 'handleSessionEnded']) {
const h = harness(); let ends = 0; h.bridge.onSpeechEnd(() => ends++);
const start = h.bridge.startGlassesCapture(h.session, () => {});
const start = h.bridge.startGlassesCapture(h.session, h.onboard, () => {});
h.bridge[stop](); h.release(); await start;
h.session.packet(new Uint8Array([9]));
h.event({ kind: 'transcript', text: 'stale', final: true });
@@ -60,7 +82,7 @@ test('cancel and disconnect during enable cannot resurrect capture or leave its
}
});
test('missing microphone data ends the session and disables the mic with an actionable status', async () => {
const h = harness(); const start = h.bridge.startGlassesCapture(h.session, () => {}); h.release(); await start;
const h = harness(); const start = h.bridge.startGlassesCapture(h.session, h.onboard, () => {}); h.release(); await start;
for (const fn of h.timers.values()) fn();
assert.deepEqual(h.commands, [true, false]); assert.match(h.bridge.statusText, /No microphone audio/);
});
@@ -68,7 +90,7 @@ test('missing microphone data ends the session and disables the mic with an acti
test('hands-free endpointing releases the microphone and waits for the final transcript before completing', async () => {
const h = harness(); let ends = 0, completed = false;
h.bridge.onSpeechEnd(() => ends++);
const start = h.bridge.startGlassesCapture(h.session, () => {}, true); h.release(); await start;
const start = h.bridge.startGlassesCapture(h.session, h.onboard, () => {}, true); h.release(); await start;
assert.equal(h.native.endpointing, true);
h.event({ kind: 'transcript', text: 'Set a timer', final: false });
h.event({ kind: 'finishing' });
@@ -80,27 +102,27 @@ test('hands-free endpointing releases the microphone and waits for the final tra
h.event({ kind: 'ended' }); await completion;
assert.equal(completed, true);
assert.equal(h.text.at(-1).text, 'Set a timer for five minutes.');
const manual = h.bridge.startGlassesCapture(h.session, () => {}); h.release(); await manual;
const manual = h.bridge.startGlassesCapture(h.session, h.onboard, () => {}); h.release(); await manual;
assert.equal(h.native.endpointing, false);
const cancelled = h.bridge.stopPushToTalk(); h.bridge.stop(); await cancelled;
});
test('phone microphone permission is requested only for foreground preview capture', async () => {
const h = harness(); h.microphoneAuthorization(0);
assert.equal(await h.bridge.prepare(true), true);
assert.equal(await h.bridge.prepare(true, false, h.onboard), true);
assert.equal(h.microphoneRequests(), 0, 'glasses input does not need phone microphone permission');
assert.equal(await h.bridge.prepare(false, true), false);
assert.equal(await h.bridge.prepare(false, true, h.onboard), false);
assert.equal(h.microphoneRequests(), 0);
assert.equal(await h.bridge.prepare(true, true), true);
assert.equal(await h.bridge.prepare(true, true, h.onboard), true);
assert.equal(h.microphoneRequests(), 1);
h.microphoneAuthorization(2);
assert.equal(await h.bridge.prepare(true, true), false);
assert.equal(await h.bridge.prepare(true, true, h.onboard), false);
assert.match(h.bridge.statusText, /Microphone.*Settings/);
});
test('phone capture forwards endpointing and drains final text without touching Bluetooth', async () => {
const h = harness();
await h.bridge.startPhoneCapture(() => {}, true);
await h.bridge.startPhoneCapture(h.onboard, () => {}, true);
assert.equal(h.native.phone, true); assert.equal(h.native.endpointing, true);
h.bridge.handleSessionEnded();
h.event({ kind: 'transcript', text: 'First line\nSecond line', final: false });
@@ -118,11 +140,11 @@ test('phone capture forwards endpointing and drains final text without touching
test('background cleanup stops phone capture but preserves glasses capture', async () => {
const h = harness(); let ends = 0; h.bridge.onSpeechEnd(() => ends++);
await h.bridge.startPhoneCapture(() => {});
await h.bridge.startPhoneCapture(h.onboard, () => {});
h.bridge.stopPhoneCapture();
assert.equal(ends, 1);
h.event({ kind: 'transcript', text: 'stale', final: true }); assert.equal(h.text.length, 0);
const start = h.bridge.startGlassesCapture(h.session, () => {}); h.release(); await start;
const start = h.bridge.startGlassesCapture(h.session, h.onboard, () => {}); h.release(); await start;
h.bridge.stopPhoneCapture();
h.event({ kind: 'transcript', text: 'on glasses', final: false });
assert.equal(h.text.at(-1).text, 'on glasses');
@@ -132,7 +154,173 @@ test('background cleanup stops phone capture but preserves glasses capture', asy
test('phone microphone startup errors end capture with an actionable status', async () => {
const h = harness(); let ends = 0; h.bridge.onSpeechEnd(() => ends++);
h.native.error = 'No phone microphone is available.';
await h.bridge.startPhoneCapture(() => {});
await h.bridge.startPhoneCapture(h.onboard, () => {});
assert.equal(ends, 1); assert.match(h.bridge.statusText, /No phone microphone/);
await h.bridge.stopPushToTalk();
});
test('a cloud provider needs no Speech Recognition permission, but phone capture still needs the microphone', async () => {
const h = harness(); h.authorization(0); h.microphoneAuthorization(0);
assert.equal(await h.bridge.prepare(false, false, h.cloud), true);
assert.equal(await h.bridge.prepare(false, true, h.cloud), false);
assert.equal(await h.bridge.prepare(true, true, h.cloud), true);
assert.equal(h.permissionRequests(), 0); assert.equal(h.microphoneRequests(), 1);
});
test('glasses cloud capture streams native PCM and completes on the final after the drained audio', async () => {
const h = harness();
const start = h.bridge.startGlassesCapture(h.session, h.cloud, () => {});
assert.deepEqual({ ...h.native.pcmCapture }, { endpointing: false, phone: false });
const client = h.clouds[0]; assert.equal(client.started, true);
client.options.onStatus('Listening (Soniox)...');
h.session.packet(new Uint8Array([1, 2])); assert.equal(h.audio.length, 1, 'LC3 still decodes natively');
h.release(); await start;
h.native.pcmHandler(new Uint8Array([5, 6]).buffer);
h.event({ kind: 'audio', seconds: 1, packets: 20, rms: 0.1, missing: 0, errors: 0 });
assert.equal(h.bridge.statusText, 'Listening (Soniox)...', 'the provider status stays up');
client.options.onTranscript({ text: 'hello', isFinal: false });
let done = false;
const completion = h.bridge.stopPushToTalk().then(() => { done = true; });
assert.deepEqual(h.commands, [true, false]); assert.equal(h.native.finished, true);
h.event({ kind: 'finishing' });
assert.equal(client.finished, 0, 'commit waits for the native audio to drain');
h.native.pcmHandler(new Uint8Array([7]).buffer);
h.event({ kind: 'ended', message: 'Ready to send' });
assert.deepEqual(client.pcm, [[5, 6], [7]]); assert.equal(client.finished, 1);
await Promise.resolve(); assert.equal(done, false);
client.options.onTranscript({ text: 'Hello there.', isFinal: true });
await completion;
assert.equal(client.stopped, true); assert.equal(h.bridge.statusText, 'Ready to send');
assert.deepEqual(h.text, [{ text: 'hello', isFinal: false }, { text: 'Hello there.', isFinal: true }]);
assert.equal(h.timers.size, 0);
});
test('cloud capture times out a missing final, keeps native errors, and ends on provider errors', async () => {
const h = harness();
await h.bridge.startPhoneCapture(h.cloud, () => {}, true);
assert.deepEqual({ ...h.native.pcmCapture }, { endpointing: true, phone: true });
const completion = h.bridge.stopPushToTalk();
h.event({ kind: 'ended', message: 'Phone microphone interrupted.' });
assert.equal(h.clouds[0].finished, 1); assert.equal(h.timers.size, 1);
for (const fn of [...h.timers.values()]) fn();
await completion;
assert.equal(h.clouds[0].stopped, true); assert.equal(h.bridge.statusText, 'Phone microphone interrupted.');
let ends = 0; h.bridge.onSpeechEnd(() => ends++);
await h.bridge.startPhoneCapture(h.cloud, () => {});
h.clouds[1].options.onError('Soniox: Invalid API key');
assert.equal(h.clouds[1].stopped, true); assert.equal(ends, 1);
assert.match(h.bridge.statusText, /Invalid API key/);
h.clouds[1].options.onTranscript({ text: 'stale', isFinal: true });
assert.equal(h.text.length, 0);
h.native.error = 'No phone microphone is available.';
await h.bridge.startPhoneCapture(h.cloud, () => {});
assert.equal(h.clouds[2].started, false, 'no connection without audio');
assert.match(h.bridge.statusText, /No phone microphone/);
});
test('continuous capture needs a cloud provider, shares its mic with push-to-talk, and drains pause segments on stop', async () => {
const h = harness(); let ends = 0; h.bridge.onSpeechEnd(() => ends++);
assert.equal(h.bridge.supportsContinuous(h.onboard), false);
assert.equal(h.bridge.supportsContinuous(h.cloud), true);
const start = h.bridge.startGlassesCapture(h.session, h.cloud, () => {}, false, true); h.release(); await start;
assert.deepEqual(h.native.pcmCapture, { endpointing: false, phone: false });
const [cloud] = h.clouds;
assert.equal(cloud.continuous(), true, 'pauses commit segments while continuous');
// Push-to-talk joins instead of restarting the mic, and releasing it keeps the capture.
await h.bridge.startGlassesCapture(h.session, h.cloud, () => {});
await h.bridge.stopPushToTalk();
assert.equal(h.clouds.length, 1); assert.deepEqual(h.commands, [true]); assert.equal(h.native.finished, undefined);
cloud.options.onTranscript({ text: 'First thought.', isFinal: true, paragraphBreakAfter: true });
const stopped = h.bridge.stopContinuousCapture();
assert.deepEqual(h.commands, [true, false]); assert.equal(h.native.finished, true);
h.event({ kind: 'ended', message: 'Transcription stopped.' });
assert.equal(cloud.finished, 1);
// An earlier pause segment answering late must not end the drain.
cloud.options.onTranscript({ text: 'Second thought.', isFinal: true, paragraphBreakAfter: true });
assert.equal(cloud.stopped, false);
cloud.options.onTranscript({ text: 'The tail.', isFinal: true, paragraphBreakAfter: false });
await stopped;
assert.equal(cloud.stopped, true);
assert.deepEqual(h.text.map(event => event.text), ['First thought.', 'Second thought.', 'The tail.']);
assert.equal(cloud.continuous(), false);
assert.ok(ends >= 1);
});
test('push-to-talk after Transcribe closed starts its own capture instead of joining the finalizing one', async () => {
const h = harness();
const start = h.bridge.startGlassesCapture(h.session, h.cloud, () => {}, false, true); h.release(); await start;
void h.bridge.stopContinuousCapture();
h.event({ kind: 'ended', message: 'Transcription stopped.' });
assert.equal(h.clouds[0].finished, 1, 'the closed window is still finalizing');
const ptt = h.bridge.startGlassesCapture(h.session, h.cloud, () => {}); h.release(); await ptt;
assert.equal(h.clouds.length, 2, 'push-to-talk got a capture of its own');
assert.equal(h.clouds[0].stopped, true);
assert.equal(h.clouds[1].continuous(), false);
});
test('continuous captures record to the requested WAV, created by their first audio and kept across restarts', async () => {
const h = harness();
h.bridge.recordTo('transcribe-2026-10-17-120000');
// A start that fails before any audio leaves no file behind.
h.native.error = 'No phone microphone is available.';
await h.bridge.startPhoneCapture(h.cloud, () => {}, false, true);
delete h.native.error;
const start = h.bridge.startGlassesCapture(h.session, h.cloud, () => {}, false, true); h.release(); await start;
assert.equal(h.recordings.length, 0);
h.native.pcmHandler(new Uint8Array([1, 2, 3, 4]));
h.native.pcmHandler(new Uint8Array([5, 6]));
assert.equal(h.recordings.length, 1);
assert.equal(h.recordings[0].name, 'transcribe-2026-10-17-120000');
assert.deepEqual(h.recordings[0].pcm, [1, 2, 3, 4, 5, 6]);
assert.deepEqual(h.clouds.at(-1).pcm, [[1, 2, 3, 4], [5, 6]], 'transcription still gets the audio');
// A restarted capture (after a disconnect, say) keeps appending to the same file.
h.bridge.stop();
assert.equal(h.recordings[0].closed, false);
const again = h.bridge.startGlassesCapture(h.session, h.cloud, () => {}, false, true); h.release(); await again;
h.native.pcmHandler(new Uint8Array([7]));
assert.equal(h.recordings.length, 1);
assert.deepEqual(h.recordings[0].pcm, [1, 2, 3, 4, 5, 6, 7]);
// Push-to-talk on a capture of its own is not recorded.
h.bridge.stop();
const ptt = h.bridge.startGlassesCapture(h.session, h.cloud, () => {}); h.release(); await ptt;
h.native.pcmHandler(new Uint8Array([8]));
assert.deepEqual(h.recordings[0].pcm, [1, 2, 3, 4, 5, 6, 7]);
h.bridge.recordTo('');
assert.equal(h.recordings[0].closed, true);
});
test('a glasses session ending drains continuous capture instead of discarding what it heard', async () => {
const h = harness(); let ends = 0; h.bridge.onSpeechEnd(() => ends++);
const start = h.bridge.startGlassesCapture(h.session, h.cloud, () => {}, false, true); h.release(); await start;
const [cloud] = h.clouds;
assert.equal(h.bridge.continuousSource, 'glasses');
h.bridge.handleSessionEnded();
assert.deepEqual(h.commands, [true, false]); assert.equal(h.native.finished, true);
assert.equal(cloud.stopped, false, 'the open segment is still transcribed');
assert.equal(h.bridge.continuousSource, null); assert.equal(h.bridge.continuousActive, true);
// The controller reports the session state again while it reconnects.
h.bridge.handleSessionEnded();
h.event({ kind: 'ended', message: 'Ready to send' });
assert.equal(cloud.finished, 1);
assert.equal(ends, 0);
cloud.options.onTranscript({ text: 'Last words.', isFinal: true });
assert.equal(cloud.stopped, true); assert.equal(h.bridge.continuousActive, false);
assert.equal(h.text.at(-1).text, 'Last words.');
assert.match(h.bridge.statusText, /resumes when they reconnect/);
assert.equal(ends, 1, 'the end lets the controller restart the capture');
});
test('backgrounding drains a continuous phone capture', async () => {
const h = harness();
await h.bridge.startPhoneCapture(h.cloud, () => {}, false, true);
assert.equal(h.bridge.continuousSource, 'phone');
h.bridge.stopPhoneCapture();
assert.equal(h.native.finished, true); assert.equal(h.clouds[0].stopped, false);
h.event({ kind: 'ended', message: 'Ready to send' });
h.clouds[0].options.onTranscript({ text: 'Tail.', isFinal: true });
assert.equal(h.bridge.continuousActive, false);
assert.equal(h.text.at(-1).text, 'Tail.');
assert.match(h.bridge.statusText, /background/);
});
+1 -1
View File
@@ -28,7 +28,7 @@ test('every remaining Java source has an explicit Android boundary and every mig
const java = path.join(root, 'App_Resources/Android/src/main/java');
const list = directory => fs.readdirSync(directory, { withFileTypes: true }).flatMap(entry => {
const file = path.join(directory, entry.name);
return entry.isDirectory() ? list(file) : file.endsWith('.java') ? [path.relative(java, file)] : [];
return entry.isDirectory() ? list(file) : file.endsWith('.java') ? [path.relative(java, file).split(path.sep).join('/')] : [];
});
const boundaries = require('../native/kotlin/android-java-boundaries.json');
const retained = boundaries.flatMap(group => { assert.ok(group.reason.length > 20); return group.files; });
@@ -10,9 +10,11 @@ import kotlin.test.*
*/
class PreviewAnimationListenerTest {
// FrameDisplayListTest's menu golden (a 2x2 highlight sliding in to rest at (3, 2)),
// restarted at 0 of its 240 ms so the slide is still in flight at the first pull.
// restarted at 1 of its 240 ms so the slide is still in flight at the first pull. Not 0:
// at exactly 0 the highlight is wholly above this 8x8 screen, so a pull in the same
// millisecond as the submit (a warm JIT) would match the settled frame.
private val menu = "077f0000000300020002000200022a00000096000000010002000200ffffffff0200080000ff24017e30020000000001812c8001812c1611010017328001812c16103001812c3023414031ff24017c30020000000001812c8001812c1611010017328001812c16103001812c30234140310200020001000103100400000000000000001f"
.chunked(2).map { it.toInt(16).toByte() }.toByteArray().also { it.fill(0, 18, 22) }
.chunked(2).map { it.toInt(16).toByte() }.toByteArray().also { it.fill(0, 18, 22); it[18] = 1 }
private fun settledPreview(): ByteArray {
val reader = ArrayByteReader(menu)
@@ -0,0 +1,24 @@
package com.faceclaw.app
import java.io.File
import kotlin.test.Test
import kotlin.test.assertEquals
class WavRecorderRepairTest {
@Test
fun repairsTheHeaderOfARecordingThatWasNeverFinished() {
val file = File.createTempFile("unfinished", ".wav")
try {
// What a process death mid-recording leaves: the empty header from the start, the PCM
// written since, and a torn half-sample at the end.
file.writeBytes(BinaryEncoding.wavHeader(0, 16000, 1) + ByteArray(3201) { 1 })
assertEquals(3200L, FaceclawWavRecorder.repairHeader(file.path, 16000, 1))
val bytes = file.readBytes()
assertEquals(44 + 3200, bytes.size)
assertEquals(BinaryEncoding.wavHeader(3200, 16000, 1).toList(), bytes.copyOf(44).toList())
assertEquals(-1L, FaceclawWavRecorder.repairHeader(file.path + ".missing", 16000, 1))
} finally {
file.delete()
}
}
}
@@ -90,6 +90,7 @@ class CaptionEngineCoreTest {
}
override fun onSpeechStart(startMs: Long) { events.add("start:$startMs"); startLatch.countDown() }
override fun onStatus(status: String?) { events.add("status:$status") }
override fun onStopped(error: String?) { events.add("stopped:$error") }
}
val host = object : CaptionHost {
override val dispatcher = CallbackDispatcher { it() }
@@ -123,5 +124,105 @@ class CaptionEngineCoreTest {
assertEquals("status:Captions listening...", events[1])
assertEquals("start:0", events[2])
assertEquals("utterance:hi:2:0", events[3])
assertEquals("stopped:null", events.last())
}
/** Records listener events; `stopped` opens once the worker reports onStopped. */
private class RecordingListener : FaceclawCaptionEngineListener {
val events = mutableListOf<String>()
val stopped = Latch(1, testPlatform())
var utteranceLatch = Latch(1, testPlatform())
override fun onUtterance(text: String?, embedding: FloatArray?, startMs: Long, endMs: Long, peakRms: Double) {
events.add("utterance:$text")
utteranceLatch.countDown()
}
override fun onSpeechStart(startMs: Long) {}
override fun onStatus(status: String?) {}
override fun onStopped(error: String?) {
events.add("stopped:$error")
stopped.countDown()
}
// Read only after a latch: callbacks run on the worker (the test dispatcher is inline).
fun snapshot(): List<String> = events.toList()
}
private fun captionHost(transcriber: () -> OfflineTranscriber?) = object : CaptionHost {
override val dispatcher = CallbackDispatcher { it() }
override fun loadTranscriber(modelDir: String): OfflineTranscriber? = transcriber()
override fun loadEmbedder(modelPath: String): SpeakerEmbedder? = null
}
private fun speak(session: CaptionSession, loudChunks: Int = 10, quietChunks: Int = 8) {
val loud = AudioSegmentation.pcm16ToLittleEndian(chunk(3000), 0, 800)
val quiet = AudioSegmentation.pcm16ToLittleEndian(chunk(0), 0, 800)
val idle = AudioSegmentation.pcm16ToLittleEndian(chunk(10), 0, 800)
repeat(2) { session.acceptPcm(idle) }
repeat(loudChunks) { session.acceptPcm(loud) }
repeat(quietChunks) { session.acceptPcm(quiet) }
}
@Test
fun captionSessionSurvivesAnUtteranceTheModelRejects() {
var calls = 0
val transcriber = object : OfflineTranscriber {
override fun recognize(samples: FloatArray, count: Int): String {
calls++
if (calls == 1) throw IllegalStateException("bad input")
return "second"
}
override fun release() {}
}
val listener = RecordingListener()
val errors = mutableListOf<String>()
val session = CaptionSession(captionHost { transcriber }, testPlatform(), "caption-reject-test") { m, _ -> errors.add(m) }
session.setListener(listener)
session.setAsrModelDir("models")
session.setSilenceMs(300)
session.start()
speak(session)
assertTrue(listener.utteranceLatch.await(5000))
listener.utteranceLatch = Latch(1, testPlatform())
speak(session)
assertTrue(listener.utteranceLatch.await(5000))
session.stop()
// The rejected utterance still arrives (without text), and the worker kept going.
assertEquals(listOf("utterance:", "utterance:second", "stopped:null"), listener.snapshot())
assertEquals(listOf("caption recognition failed"), errors.toList())
}
@Test
fun requestStopDeliversTheTrailingUtteranceBeforeStopped() {
val transcriber = object : OfflineTranscriber {
override fun recognize(samples: FloatArray, count: Int): String = "last words"
override fun release() {}
}
val listener = RecordingListener()
val session = CaptionSession(captionHost { transcriber }, testPlatform(), "caption-flush-test") { m, e -> error("$m: $e") }
session.setListener(listener)
session.setAsrModelDir("models")
session.start()
// Speech with no closing silence: the utterance is still open when the stop lands.
speak(session, loudChunks = 10, quietChunks = 0)
session.requestStop()
assertTrue(listener.stopped.await(5000))
assertEquals(listOf("utterance:last words", "stopped:null"), listener.snapshot())
}
@Test
fun aModelLoadFailureReportsStoppedWithTheError() {
val listener = RecordingListener()
val session = CaptionSession(
captionHost { throw IllegalStateException("model corrupt") },
testPlatform(),
"caption-load-test",
) { _, _ -> }
session.setListener(listener)
session.setAsrModelDir("models")
session.start()
assertTrue(listener.stopped.await(5000))
assertEquals(listOf("stopped:model corrupt"), listener.snapshot())
// The dead worker left the session stopped, so a later stop is a no-op.
session.stop()
session.requestStop()
}
}
@@ -0,0 +1,33 @@
package com.faceclaw.app
import kotlin.test.Test
import kotlin.test.assertEquals
class ConnectionCountersTest {
@Test
fun drainReturnsTheCountsSinceTheLastDrain() {
ConnectionCounters.drain()
ConnectionCounters.increment("g2.connect-attempt")
ConnectionCounters.increment("g2.connect-attempt")
ConnectionCounters.increment("g2.session-ready")
assertEquals("""{"g2.connect-attempt":2,"g2.session-ready":1}""", ConnectionCounters.drain())
assertEquals("{}", ConnectionCounters.drain())
}
@Test
fun keepsCountingKnownNamesPastTheNameCap() {
ConnectionCounters.drain()
for (index in 0 until 250) ConnectionCounters.increment("name-$index")
ConnectionCounters.increment("name-0")
val drained = Json.parseObject(ConnectionCounters.drain())
assertEquals(200, drained.size)
assertEquals(JsonNumber("2"), drained["name-0"])
}
@Test
fun slugsFailureReasons() {
assertEquals("cfw-recovery-retry-limit", ConnectionCounters.slug("CFW recovery retry limit"))
assertEquals("left-arm-not-found", ConnectionCounters.slug("left arm not found"))
assertEquals("evenhub-resume-prelude-failed", ConnectionCounters.slug("EvenHub resume prelude failed"))
}
}
@@ -453,7 +453,7 @@ class GlassesSessionCoreTest {
s.core.interruptibleSleep.interrupt()
assertTrue(waitUntil(3_000) { s.listener.phases.contains("retrying") }, s.host.logs().takeLast(10).toString())
assertTrue(s.host.hasLog("message timed out: create-layout"))
assertTrue(s.host.hasLog("Transport failure: ack timeout"))
assertTrue(s.host.hasLog("Transport failure: create layout ack timeout"))
assertTrue(s.link.disconnected.containsAll(listOf(RIGHT, LEFT)))
s.core.disconnect()
assertEquals("disconnected", s.listener.phases.last())
@@ -33,6 +33,41 @@ class GraphicsCoresTest {
assertContentEquals(byteArrayOf(0x2c, 1, 2, 0), wide.copyOfRange(0, 4))
}
@Test
fun lightBackgroundsInvertBeforeTheToneCurve() {
val white = 0xffffffff.toInt()
val black = 0xff000000.toInt()
// A white chart with a black stroke and a fully transparent corner.
val chart = IntArray(10 * 10) { white }
chart[55] = black
chart[0] = 0x00ffffff
assertTrue(GrayPacket.hasLightBackground(chart, 10, 10))
val inverted = GrayPacket.fromArgb(chart, 10, 10, 2.2f, false, true)
assertEquals(0, inverted[4 + 1].toInt() and 0xff) // background goes black
assertEquals(255, inverted[4 + 55].toInt() and 0xff) // stroke goes white
assertEquals(0, inverted[4 + 0].toInt() and 0xff) // transparent stays black
// Mid-gray inverts to its sRGB complement, then takes the tone curve.
chart[56] = 0xff404040.toInt()
val curve = GrayPacket.toneCurve(2.2f)
assertEquals(curve[255 - 0x40], GrayPacket.fromArgb(chart, 10, 10, 2.2f, false, true)[4 + 56].toInt() and 0xff)
// Without the flag the conversion is unchanged.
assertContentEquals(GrayPacket.fromArgb(chart, 10, 10, 2.2f, false), GrayPacket.fromArgb(chart, 10, 10, 2.2f, false, false))
}
@Test
fun darkBackgroundsAndPhotosKeepTheirTones() {
// A black chart with a white stroke: already light-on-dark.
val dark = IntArray(10 * 10) { 0xff000000.toInt() }
dark[55] = 0xffffffff.toInt()
assertTrue(!GrayPacket.hasLightBackground(dark, 10, 10))
assertContentEquals(GrayPacket.fromArgb(dark, 10, 10, 1f, false), GrayPacket.fromArgb(dark, 10, 10, 1f, false, true))
// A photo-like spread of tones, even a bright one, has no background to invert.
val ramp = IntArray(16 * 16) { i -> val v = 64 + (i * 191) / 255; 0xff000000.toInt() or (v shl 16) or (v shl 8) or v }
assertTrue(!GrayPacket.hasLightBackground(ramp, 16, 16))
// A mid-gray background is not light enough to be worth inverting.
assertTrue(!GrayPacket.hasLightBackground(IntArray(8 * 8) { 0xff808080.toInt() }, 8, 8))
}
@Test
fun toneCurveDarkensMidtones() {
val identity = GrayPacket.toneCurve(1f)
@@ -0,0 +1,161 @@
package com.faceclaw.app
import kotlin.math.pow
import kotlin.math.roundToInt
import kotlin.test.*
class NotificationIconArtTest {
private val outputSize = 12
private val size = outputSize * NotificationIconArt.ANALYSIS_SCALE
private val clear = 0
private val white = argb(255, 255, 255, 255)
private val black = argb(255, 0, 0, 0)
private val blue = argb(255, 0, 0, 255)
private val green = argb(255, 20, 160, 70)
private fun argb(a: Int, r: Int, g: Int, b: Int): Int = (a shl 24) or (r shl 16) or (g shl 8) or b
private fun icon(pixel: (x: Int, y: Int) -> Int): IntArray = IntArray(size * size) { pixel(it % size, it / size) }
private fun inCircle(x: Int, y: Int, cx: Double, cy: Double, r: Double): Boolean {
val dx = x + 0.5 - cx
val dy = y + 0.5 - cy
return dx * dx + dy * dy <= r * r
}
/** A rounded square inset from the image edge. */
private fun inRoundedSquare(x: Int, y: Int, inset: Int, radius: Int): Boolean {
val lo = inset
val hi = size - 1 - inset
if (x < lo || x > hi || y < lo || y > hi) return false
val cx = x.coerceIn(lo + radius, hi - radius)
val cy = y.coerceIn(lo + radius, hi - radius)
return inCircle(x, y, cx + 0.5, cy + 0.5, radius + 0.5)
}
/** A horizontal bar across the middle, in analysis pixels aligned to output pixels. */
private fun inBar(x: Int, y: Int): Boolean = y in 10..13 && x in 6..17
private fun gray(art: NotificationIconArt.Art, ox: Int, oy: Int): Int = art.gray[oy * outputSize + ox].toInt() and 0xff
@Test fun emptyIconIsEmpty() {
val art = NotificationIconArt.convert(IntArray(size * size), outputSize)
assertEquals(NotificationIconArt.Kind.EMPTY, art.kind)
assertTrue(art.gray.all { it.toInt() == 0 })
}
@Test fun ringWithNoisyColorsIsATemplate() {
// Discord-style: the alpha is a clean shape with a hole, the colors are garbage.
var seed = 12345
val pixels = icon { x, y ->
seed = seed * 1103515245 + 12345
val inRing = inCircle(x, y, 12.0, 12.0, 11.0) && !inCircle(x, y, 12.0, 12.0, 5.0)
if (inRing) argb(255, (seed ushr 8) and 0xff, (seed ushr 16) and 0xff, (seed ushr 4) and 0xff) else clear
}
val art = NotificationIconArt.convert(pixels, outputSize)
assertEquals(NotificationIconArt.Kind.TEMPLATE, art.kind)
assertContentEquals(NotificationIconArt.template(pixels, outputSize).gray, art.gray)
assertEquals(255, gray(art, 1, 6))
assertEquals(0, gray(art, 6, 6))
}
@Test fun darkColoredTemplateStillLightsFully() {
// A plus sign filled pure blue: by brightness it would all but vanish.
val pixels = icon { x, y -> if ((x in 8..15 && y in 2..21) || (y in 8..15 && x in 2..21)) blue else clear }
val art = NotificationIconArt.convert(pixels, outputSize)
assertEquals(NotificationIconArt.Kind.TEMPLATE, art.kind)
assertEquals(255, gray(art, 6, 2))
assertEquals(0, gray(art, 1, 1))
}
@Test fun faintTemplateIsNormalizedToFullBrightness() {
// A theme tint like #8A000000 leaves the whole shape at 54% alpha.
val pixels = icon { x, y -> if (x in 4..19 && y in 4..19 && !(x in 8..15 && y in 8..15)) argb(138, 0, 0, 0) else clear }
val art = NotificationIconArt.convert(pixels, outputSize)
assertEquals(NotificationIconArt.Kind.TEMPLATE, art.kind)
assertEquals(255, gray(art, 2, 2))
}
@Test fun squareWithCutOutIsATemplate() {
val pixels = icon { x, y -> if (inBar(x, y)) clear else white }
assertEquals(NotificationIconArt.Kind.TEMPLATE, NotificationIconArt.convert(pixels, outputSize).kind)
}
@Test fun oneColorDiscIsSolid() {
val pixels = icon { x, y -> if (inCircle(x, y, 12.0, 12.0, 11.0)) blue else clear }
val art = NotificationIconArt.convert(pixels, outputSize)
assertEquals(NotificationIconArt.Kind.SOLID, art.kind)
assertEquals(255, gray(art, 6, 6))
assertEquals(0, gray(art, 0, 0))
}
@Test fun lightGlyphOnColoredTileIsExtracted() {
val pixels = icon { x, y ->
when {
!inRoundedSquare(x, y, 0, 5) -> clear
inBar(x, y) -> white
else -> green
}
}
val art = NotificationIconArt.convert(pixels, outputSize)
assertEquals(NotificationIconArt.Kind.GLYPH, art.kind)
assertEquals(255, gray(art, 6, 5))
assertEquals(0, gray(art, 6, 2))
assertEquals(0, gray(art, 1, 6))
}
@Test fun darkGlyphOnWhiteCircleIsLitNotTheCircle() {
val pixels = icon { x, y ->
when {
!inCircle(x, y, 12.0, 12.0, 11.5) -> clear
inBar(x, y) -> black
else -> white
}
}
val art = NotificationIconArt.convert(pixels, outputSize)
assertEquals(NotificationIconArt.Kind.GLYPH, art.kind)
assertEquals(255, gray(art, 6, 5))
assertEquals(0, gray(art, 6, 2))
}
@Test fun tileWithTransparentMarginIsStillATile() {
val pixels = icon { x, y ->
when {
!inRoundedSquare(x, y, 2, 3) -> clear
inBar(x, y) -> white
else -> green
}
}
assertEquals(NotificationIconArt.Kind.GLYPH, NotificationIconArt.convert(pixels, outputSize).kind)
}
@Test fun gradientTileIsReadAsAPicture() {
val pixels = icon { x, _ -> val v = x * 10; argb(255, v, v, v) }
val art = NotificationIconArt.convert(pixels, outputSize)
assertEquals(NotificationIconArt.Kind.PICTURE, art.kind)
assertTrue(gray(art, 1, 6) < gray(art, 6, 6))
assertTrue(gray(art, 6, 6) < gray(art, 10, 6))
assertEquals(255, gray(art, 11, 6))
}
@Test fun templateConversionIgnoresColors() {
val pixels = icon { x, y -> if (inBar(x, y)) white else green }
val art = NotificationIconArt.template(pixels, outputSize)
assertEquals(NotificationIconArt.Kind.TEMPLATE, art.kind)
assertTrue(art.gray.all { (it.toInt() and 0xff) == 255 })
}
@Test fun downscaleAveragesCoverageThenAppliesTheToneCurve() {
// Alternate opaque and clear columns: every output pixel is half covered.
val pixels = icon { x, _ -> if (x % 2 == 0) white else clear }
val art = NotificationIconArt.convert(pixels, outputSize)
assertEquals(NotificationIconArt.Kind.TEMPLATE, art.kind)
val expected = (255 * 0.5.pow(NotificationIconArt.GAMMA)).roundToInt()
assertTrue(art.gray.all { (it.toInt() and 0xff) == expected })
}
@Test fun rejectsTheWrongPixelCount() {
assertFailsWith<IllegalArgumentException> { NotificationIconArt.convert(IntArray(10), outputSize) }
}
}
@@ -22,6 +22,21 @@ class IosNativeApiTest {
assertContentEquals(auth.byteArray(), result.payload.byteArray())
}
@Test
fun bgraPacketsConvertWithTheSharedGrayTone() {
// 2x1: opaque orange, half-transparent white (B, G, R, A in memory).
val bgra = byteArrayOf(2, 0, 1, 0, 0x20, 0x80.toByte(), 0xff.toByte(), 0xff.toByte(),
0xff.toByte(), 0xff.toByte(), 0xff.toByte(), 0x80.toByte())
val argb = intArrayOf(0xffff8020.toInt(), 0x80ffffff.toInt())
val protocol = IosProtocol()
for (dither in listOf(false, true)) {
assertContentEquals(GrayPacket.fromArgb(argb, 2, 1, 2.2f, dither),
protocol.grayPacket(bgra.data(), 2.2f, dither).byteArray())
}
assertEquals(0UL, protocol.grayPacket(bgra.copyOf(10).data(), 1f, false).length)
assertEquals(0UL, protocol.grayPacket(byteArrayOf(0, 0, 1, 0).data(), 1f, false).length)
}
@Test
fun compassFacadePreservesTheEndOfTheCrcFreePayload() {
val protocol = IosProtocol()
+11 -2
View File
@@ -17,9 +17,9 @@ const font={lineHeight:12,ascent:10,descent:2,measureText:text=>text.length*4,
const menuCore=load('app/ui/menu-core.ts',{
'../graphics/image':graphics,'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'),
});
const {MenuLayer}=load('app/ui/menu.ts',{
const {MenuLayer,TextPageLayer}=load('app/ui/menu.ts',{
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback },
'../graphics/image':graphics,'../graphics/textwrap':{},'../graphics/ui-fonts':{getDefaultSmallFont:()=>font},
'../graphics/image':graphics,'../graphics/textwrap':{wrapText:(_font,text)=>text.split('\n')},'../graphics/ui-fonts':{getDefaultSmallFont:()=>font},
'../util/numeric-util':{clamp:(n,a,b)=>Math.max(a,Math.min(b,n))},'./gestures':{},
'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'),
'./metrics':require('../.test-build/app/ui/metrics.js'),'./menu-core':menuCore,
@@ -64,6 +64,15 @@ test('context menu surface and selected row both use +4 without changing the app
assert.deepEqual(closed.image.pixels,base.pixels);
assert.deepEqual(wire.presentationRecords(prepareFrameDraws(closed.draws)),[]);
});
test('text page paints at the stack size, not the lens size',()=>{
// An app window's stack is its viewport; a lens-sized plane is rejected by
// the compositor as larger than the window surface.
const stack=new LayerStack({paint:()=>new graphics.GrayImage(576,260)},noopLayerActions,{width:576,height:260});
stack.push(new TextPageLayer('Array status','Left: no status yet\nRight: no status yet'));
const painted=stack.paint();
assert.equal(painted.length,1);
assert.equal(painted[0].image.width,576);assert.equal(painted[0].image.height,260);
});
test('system menu bridge shifts its surface and selected row together by +4',()=>{
const image=menu().paint(),bytes=encodeShellScene([{image,x:8,y:0,shellKey:7,depth:4}]);
const view=new DataView(bytes.buffer),w=view.getUint16(8,true),h=view.getUint16(10,true);
+68
View File
@@ -0,0 +1,68 @@
// The caption clock maps the engine's fed-audio clock to wall time, so a
// line's timestamp stays right after audio that never reached the engine
// (beam filter, voice-dialog pause, stall) or arrived late in a burst.
const test = require("node:test");
const assert = require("node:assert/strict");
const { CaptionClock, CAPTION_CLOCK_DRIFT_MS } = require("../.test-build/app/apps/microphones/caption-clock.js");
const RATE = 16000;
// 50 ms of 16 kHz mono S16LE.
const CHUNK_BYTES = 1600;
const CHUNK_MS = 50;
function feed(clock, startWallMs, chunks, intervalMs = CHUNK_MS) {
for (let i = 0; i < chunks; i++) clock.noteFed(CHUNK_BYTES, startWallMs + (i + 1) * intervalMs);
}
test("real-time audio maps straight through", () => {
const clock = new CaptionClock(RATE, 1_000_000);
feed(clock, 1_000_000, 100);
assert.equal(clock.wallMs(0), 1_000_000);
assert.equal(clock.wallMs(2_500), 1_002_500);
});
test("before any audio, times count from the start", () => {
const clock = new CaptionClock(RATE, 5_000);
assert.equal(clock.wallMs(120), 5_120);
});
test("a gap in the audio moves later times past it", () => {
const clock = new CaptionClock(RATE, 0);
feed(clock, 0, 20); // engine 0..1000 ms at wall 0..1000
feed(clock, 61_000, 20); // a minute paused, then 1000 ms more
assert.equal(clock.wallMs(500), 500);
assert.equal(clock.wallMs(1_000), 61_000);
assert.equal(clock.wallMs(1_500), 61_500);
});
test("many small dropped chunks don't accumulate past the drift bound", () => {
const clock = new CaptionClock(RATE, 0);
// Every other 50 ms chunk is dropped (beam filter): fed audio runs at half speed.
for (let i = 0; i < 400; i++) clock.noteFed(CHUNK_BYTES, (i + 1) * 2 * CHUNK_MS);
const engineMs = 399 * CHUNK_MS;
const actualWall = 400 * 2 * CHUNK_MS - CHUNK_MS;
assert.ok(Math.abs(clock.wallMs(engineMs) - actualWall) <= CAPTION_CLOCK_DRIFT_MS + CHUNK_MS);
});
test("jitter within the bound doesn't re-anchor", () => {
const clock = new CaptionClock(RATE, 0);
for (let i = 0; i < 100; i++) {
const jitter = i % 2 === 0 ? 120 : 0;
clock.noteFed(CHUNK_BYTES, (i + 1) * CHUNK_MS + jitter);
}
// Anchored once, by the first chunk (which arrived 120 ms late).
assert.equal(clock.wallMs(1_000), 1_120);
});
test("a late burst re-anchors once the stream is real-time again", () => {
const clock = new CaptionClock(RATE, 0);
feed(clock, 0, 20); // 0..1000 ms on time
// 2 s of audio held up, then delivered all at once at wall 3000.
for (let i = 0; i < 40; i++) clock.noteFed(CHUNK_BYTES, 3_000);
// Then real-time again.
feed(clock, 3_000, 40);
// Engine 3000 ms (fed during real-time after the burst) lands near wall 3000.
assert.ok(Math.abs(clock.wallMs(3_000) - 3_000) <= CAPTION_CLOCK_DRIFT_MS + CHUNK_MS);
assert.ok(Math.abs(clock.wallMs(4_500) - 4_500) <= CAPTION_CLOCK_DRIFT_MS + CHUNK_MS);
});
+18
View File
@@ -172,3 +172,21 @@ test("temple pipeline matches the raw beam with ANC disabled", () => {
assert.equal(viaPipeline.length, direct.length);
for (let i = 0; i < direct.length; i++) assert.equal(viaPipeline[i], direct[i]);
});
test("temple pipeline output is seamless across frame boundaries", () => {
// Streamed frame by frame, the steering delay must reach into the previous
// frame rather than zero-fill, so splitting the signal changes nothing.
const front = makeNoise(800, 3);
const rear = makeNoise(800, 4);
const target = { azimuth: deg(60) };
const whole = new TempleAudioPipeline("left", 16000);
whole.enableANC = false;
const expected = whole.process(front, rear, target);
const framed = new TempleAudioPipeline("left", 16000);
framed.enableANC = false;
const first = framed.process(front.subarray(0, 400), rear.subarray(0, 400), target);
const second = framed.process(front.subarray(400), rear.subarray(400), target);
assert.equal(first.length + second.length, expected.length);
for (let i = 0; i < 400; i++) assert.ok(near(first[i], expected[i], 1e-6));
for (let i = 0; i < 400; i++) assert.ok(near(second[i], expected[400 + i], 1e-6));
});
+6
View File
@@ -22,6 +22,12 @@ test("self-introductions are recognized", () => {
name: "Alice",
kind: "self",
});
// Phone-style self-introductions, including ASR's stray capitalization.
assert.deepEqual(inferIntroducedName("Hey this is Dana calling about the order"), {
name: "Dana",
kind: "self",
});
assert.deepEqual(inferIntroducedName("This is Bob Speaking."), { name: "Bob", kind: "self" });
});
test("third-party introductions are recognized", () => {
+137
View File
@@ -0,0 +1,137 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const detector = require('../.test-build/app/apps/nightscout/missed-bolus-detector.js');
const MIN = 60_000;
const T0 = 1_800_000_000_000;
/**
* 5-minute readings: flat at `base` for `flatMin`, then rising `rate` mg/dL
* per minute for `riseMin`. The rise starts at T0 + flatMin.
*/
function series({ base = 100, flatMin = 60, rate = 2.5, riseMin = 40 } = {}) {
const readings = [];
for (let m = 0; m <= flatMin + riseMin; m += 5) {
readings.push({ timeMs: T0 + m * MIN, mgdl: Math.round(base + Math.max(0, m - flatMin) * rate) });
}
return readings;
}
/** A detector input one minute after the last reading. */
function input(glucose, { boluses = [], carbs = [] } = {}) {
return { nowMs: glucose[glucose.length - 1].timeMs + MIN, glucose, boluses, carbs };
}
const onset = T0 + 60 * MIN;
test('an unannounced meal-shaped rise is a missed bolus', () => {
const result = detector.detectMissedBolus(input(series()));
assert.equal(result.classification, 'missed-bolus', result.reason);
assert.equal(result.rise.onsetMs, onset);
assert.equal(result.rise.nadirMgdl, 100);
assert.equal(result.rise.latestMgdl, 200);
assert.equal(result.rise.riseMgdl, 100);
assert.ok(Math.abs(result.rise.rateMgdlPerMin - 2.5) < 0.01);
});
test('a meal or manual bolus from the pre-bolus window onward accounts for the rise', () => {
for (const [kind, offsetMin] of [['meal', -50], ['meal', 15], ['manual', 30]]) {
const result = detector.detectMissedBolus(input(series(), {
boluses: [{ timeMs: onset + offsetMin * MIN, units: 5, kind }],
}));
assert.equal(result.classification, 'no-alert', `${kind} at ${offsetMin}: ${result.reason}`);
}
// Too long before the rise began, or too small, doesn't count.
for (const bolus of [{ timeMs: onset - 70 * MIN, units: 5, kind: 'meal' }, { timeMs: onset, units: 0.3, kind: 'meal' }]) {
assert.equal(detector.detectMissedBolus(input(series(), { boluses: [bolus] })).classification, 'missed-bolus');
}
});
test('loop boluses do not count; unmarked ones count only above the SMB size threshold', () => {
const smbs = [0, 10, 20, 30].map((m) => ({ timeMs: onset + m * MIN, units: 1.4, kind: 'ambiguous' }));
smbs.push({ timeMs: onset + 5 * MIN, units: 3, kind: 'automatic' });
assert.equal(detector.detectMissedBolus(input(series(), { boluses: smbs })).classification, 'missed-bolus');
const manual = [{ timeMs: onset + 20 * MIN, units: 2, kind: 'ambiguous' }];
assert.equal(detector.detectMissedBolus(input(series(), { boluses: manual })).classification, 'no-alert');
assert.equal(detector.detectMissedBolus(input(series(), { boluses: manual }), { ambiguousBolusMinUnits: 2.5 }).classification, 'missed-bolus');
});
test('a carb entry accounts for the rise unless that option is off', () => {
const carbs = [{ timeMs: onset + 10 * MIN, grams: 40 }];
assert.equal(detector.detectMissedBolus(input(series(), { carbs })).classification, 'no-alert');
assert.equal(detector.detectMissedBolus(input(series(), { carbs }), { carbsCountAsAnnouncement: false }).classification, 'missed-bolus');
});
test('rises that are small, slow, brief, low, or from a hypo do not alert', () => {
const cases = [
series({ rate: 0.9, riseMin: 60 }), // slow: under 1.5 mg/dL/min
series({ rate: 3, riseMin: 15 }), // brief: 15 min
series({ base: 80, rate: 1.6, riseMin: 30 }), // ends at 128, under 140
series({ base: 60, rate: 3, riseMin: 40 }), // recovering from a low
series({ base: 150, rate: 1.5, riseMin: 20 }), // only 30 mg/dL
];
for (const glucose of cases) {
const result = detector.detectMissedBolus(input(glucose));
assert.equal(result.classification, 'no-alert', result.reason);
assert.ok(result.rise);
}
});
test('a rise that has peaked and turned down does not alert', () => {
const glucose = series();
const last = glucose[glucose.length - 1];
for (let m = 5; m <= 20; m += 5) glucose.push({ timeMs: last.timeMs + m * MIN, mgdl: last.mgdl - m });
assert.equal(detector.detectMissedBolus(input(glucose)).classification, 'no-alert');
});
test('stale, missing, or gapped data is insufficient', () => {
const glucose = series();
const stale = { ...input(glucose), nowMs: glucose[glucose.length - 1].timeMs + 20 * MIN };
assert.equal(detector.detectMissedBolus(stale).classification, 'insufficient-data');
assert.equal(detector.detectMissedBolus({ nowMs: T0, glucose: [], boluses: [], carbs: [] }).classification, 'insufficient-data');
// Readings after "now" are ignored rather than used.
const early = { ...input(glucose), nowMs: onset + 11 * MIN };
assert.notEqual(detector.detectMissedBolus(early).classification, 'missed-bolus');
// A CGM dropout splits the window: the rise before it doesn't count.
const gapped = series().filter((r) => r.timeMs < onset + 10 * MIN || r.timeMs > onset + 30 * MIN);
assert.notEqual(detector.detectMissedBolus(input(gapped)).classification, 'missed-bolus');
// Dexcom error codes are dropped; 39 ("LOW") is a real reading.
const withErrors = series().map((r, i) => (i === 3 ? { ...r, mgdl: 5 } : r));
assert.equal(detector.detectMissedBolus(input(withErrors)).classification, 'missed-bolus');
});
test('bolus kinds from each uploader', () => {
const kind = detector.bolusKindFromTreatment;
assert.equal(kind({ eventType: 'Correction Bolus', insulin: 0.5, automatic: true }), 'automatic'); // Loop
assert.equal(kind({ eventType: 'Correction Bolus', insulin: 0.5, automatic: false }), 'manual'); // Loop
assert.equal(kind({ eventType: 'Correction Bolus', insulin: 0.4, isSMB: true }), 'automatic'); // AndroidAPS
assert.equal(kind({ eventType: 'Correction Bolus', insulin: 0.4, type: 'SMB' }), 'automatic'); // Trio
assert.equal(kind({ eventType: 'SMB', insulin: 0.4 }), 'automatic');
assert.equal(kind({ eventType: 'Meal Bolus', insulin: 4 }), 'meal');
assert.equal(kind({ eventType: 'Bolus', insulin: 4, carbs: 30 }), 'meal');
assert.equal(kind({ eventType: 'Correction Bolus', insulin: 4, wizard: { carb_input: 0 } }), 'meal');
// OpenAPS on a Medtronic pump: SMBs and manual corrections look the same.
assert.equal(kind({ eventType: 'Correction Bolus', insulin: 0.3, carbs: null, enteredBy: 'openaps://medtronic/723' }), 'ambiguous');
});
test('normalizing raw Nightscout records', () => {
const { boluses, carbs } = detector.normalizeNightscoutTreatments([
{ eventType: 'Meal Bolus', created_at: '2026-10-11T23:05:32.000Z', insulin: 10.7, carbs: 75, wizard: {} },
{ eventType: 'Correction Bolus', created_at: '2026-10-11T22:05:00.000Z', insulin: 0.3, carbs: null },
{ eventType: 'Temp Basal', created_at: '2026-10-11T22:00:00.000Z', insulin: null, carbs: null, rate: 1.2 },
{ eventType: 'Carb Correction', timestamp: '2026-10-11T21:00:00.000Z', carbs: '15' },
{ eventType: 'Correction Bolus', insulin: 1 }, // no time
]);
assert.deepEqual(boluses, [
{ timeMs: Date.parse('2026-10-11T22:05:00.000Z'), units: 0.3, kind: 'ambiguous' },
{ timeMs: Date.parse('2026-10-11T23:05:32.000Z'), units: 10.7, kind: 'meal' },
]);
assert.deepEqual(carbs, [
{ timeMs: Date.parse('2026-10-11T21:00:00.000Z'), grams: 15 },
{ timeMs: Date.parse('2026-10-11T23:05:32.000Z'), grams: 75 },
]);
assert.deepEqual(
detector.normalizeNightscoutEntries([{ date: 2000, sgv: 120 }, { date: 1000, sgv: 110 }, { date: 3000 }]),
[{ timeMs: 1000, mgdl: 110 }, { timeMs: 2000, mgdl: 120 }],
);
});
+3 -40
View File
@@ -6,6 +6,7 @@ const path = require('node:path');
const vm = require('node:vm');
const { execFileSync } = require('node:child_process');
const ts = require('typescript');
const { kotlinCompiler } = require('./helpers/kotlin-compiler.cjs');
const source = (file) => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
function load(file, requireModule, globals = {}) {
@@ -88,6 +89,8 @@ function bridges() {
'./settings-store': storage,
'../graphics/image': {},
'./image-files': {},
'./notification-access': { isNotificationListenerEnabled: () => true },
'./media-types': load('app/native/media-types.ts', () => { throw new Error('media-types has no imports'); }),
};
const globals = { global: { isAndroid: true }, com: { faceclaw: { app: {
FaceclawMediaBrowser: NativeBrowser,
@@ -189,46 +192,6 @@ test('Music settings keeps toggles and selection when a new app arrives and supp
assert.equal(closes, 1);
});
// FaceclawMediaController is Kotlin compiled by the NativeScript Android build, so
// compile the extracted method with the same Kotlin compiler Gradle already cached.
function kotlinCompiler() {
const gradle = source('App_Resources/Android/before-plugins.gradle').match(/kotlinVersion\s*=\s*"([^"]+)"/);
const cache = path.join(os.homedir(), '.gradle/caches/modules-2/files-2.1');
const jar = (group, artifact, version) => {
const directory = path.join(cache, group, artifact, version);
if (!fs.existsSync(directory)) return null;
for (const hash of fs.readdirSync(directory)) {
const file = path.join(directory, hash, `${artifact}-${version}.jar`);
if (fs.existsSync(file)) return file;
}
return null;
};
const anyVersion = (group, artifact) => {
const directory = path.join(cache, group, artifact);
if (!fs.existsSync(directory)) return null;
for (const version of fs.readdirSync(directory).sort().reverse()) {
const file = jar(group, artifact, version);
if (file) return file;
}
return null;
};
if (!gradle) return null;
const version = gradle[1];
const stdlib = jar('org.jetbrains.kotlin', 'kotlin-stdlib', version);
const compiler = [
jar('org.jetbrains.kotlin', 'kotlin-compiler-embeddable', version),
stdlib,
jar('org.jetbrains.kotlin', 'kotlin-script-runtime', version),
jar('org.jetbrains.kotlin', 'kotlin-daemon-embeddable', version),
anyVersion('org.jetbrains.kotlin', 'kotlin-reflect'),
anyVersion('org.jetbrains.intellij.deps', 'trove4j'),
anyVersion('org.jetbrains', 'annotations'),
anyVersion('org.jetbrains.kotlinx', 'kotlinx-coroutines-core-jvm'),
];
if (compiler.some(file => !file)) return null;
return { classpath: compiler.join(path.delimiter), stdlib };
}
test('native session selection skips ignored playing and idle apps, including the all-ignored case', (t) => {
// Execute the production selection method with lightweight media-session doubles.
const compiler = kotlinCompiler();
+106
View File
@@ -0,0 +1,106 @@
package com.faceclaw.evenhubprobe
import android.app.Activity
import android.content.MutableContextWrapper
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.webkit.WebView
import com.faceclaw.app.FaceclawEvenHubChromeClient
import com.faceclaw.app.FaceclawEvenHubDocumentStart
import com.faceclaw.app.FaceclawEvenHubJsBridge
import com.faceclaw.app.FaceclawEvenHubListener
import com.faceclaw.app.FaceclawEvenHubProfile
import com.faceclaw.app.FaceclawEvenHubWebView
import com.faceclaw.app.FaceclawEvenHubWebViewClient
import com.faceclaw.app.FaceclawEvenHubWebViewHost
import org.json.JSONArray
import org.json.JSONObject
import java.io.File
/**
* Runs the production EvenHub WebView classes (tests/android-evenhub-native.cjs),
* wired the way app/apps/evenhub/webview.ts wires them, and logs what the host saw.
*
* - A: a packaged app. It calls the bridge and gets a reply, embeds a same-origin
* and a cross-origin iframe, then navigates to a third-party page.
* - B: another packaged app (its own profile), which then visits a cookie check.
* - A2: a second WebView for A's package, which visits the same cookie check.
* - R: a remote app, served by the test server, with the document-start shim.
* - Then the shared renderer is crashed; the process must survive it.
*/
class ProbeActivity : Activity() {
private val handler = Handler(Looper.getMainLooper())
private val seen = LinkedHashSet<String>()
private val webViews = HashMap<String, WebView>()
private val checks = HashMap<String, String>()
private lateinit var config: JSONObject
private fun asset(name: String) = assets.open(name).use { it.readBytes().decodeToString() }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
config = JSONObject(asset("config.json"))
val dist = File(filesDir, "dist").apply { mkdirs() }
for (name in assets.list("dist")!!) File(dist, name).writeBytes(assets.open("dist/$name").use { it.readBytes() })
val third = config.getString("third")
handler.post { create("A", "probe.a", dist.path) }
handler.postDelayed({ evaluate("A", "location.href = '$third/third'") }, 4000)
handler.postDelayed({
// A now shows the third-party page: host scripts must not run there.
evaluate("A", "new Image().src = '$third/report?eval=leak'")
create("B", "probe.b", dist.path)
}, 6000)
handler.postDelayed({ create("A2", "probe.a", dist.path); create("R", "probe.remote", null) }, 8000)
handler.postDelayed({
evaluate("B", "location.href = '$third/cookie?app=B'")
evaluate("A2", "location.href = '$third/cookie?app=A2'")
}, 10000)
handler.postDelayed({ webViews["R"]?.loadUrl("chrome://crash") }, 13000)
handler.postDelayed({
Log.i(TAG, "RESULT " + JSONObject().put("seen", JSONArray(seen.toList())))
}, 17000)
}
private fun create(tag: String, packageId: String, distDir: String?) {
val startUrl = config.getJSONObject("start").getString(tag)
checks[tag] = config.getJSONObject("checks").getString(tag)
val web = FaceclawEvenHubWebView(MutableContextWrapper(this))
seen.add("$tag:profile=${FaceclawEvenHubProfile.apply(web, packageId)}")
web.settings.javaScriptEnabled = true
web.settings.domStorageEnabled = true
web.settings.allowFileAccess = false
val listener = object : FaceclawEvenHubListener {
override fun onEvenAppMessage(handlerName: String?, argsJson: String?, callId: Int) {
seen.add("$tag:" + JSONArray(argsJson ?: "[]").optString(0))
evaluate(tag, "window.__fcResolve($callId, true, true)")
}
override fun onPageFinished(url: String?) {}
override fun onRenderProcessGone(crashed: Boolean) {
seen.add("$tag:gone")
webViews.remove(tag)
}
}
val rule = FaceclawEvenHubJsBridge.originRule(startUrl)!!
FaceclawEvenHubJsBridge.install(web, rule, listener)?.let { seen.add("$tag:bridge-error") }
val inject = asset("inject-$tag.js")
val remote = distDir == null
val documentStart = remote && FaceclawEvenHubDocumentStart.install(web, inject, rule)
val host = if (remote) "" else android.net.Uri.parse(startUrl).host
web.webViewClient = FaceclawEvenHubWebViewClient(distDir, host, inject, remote && !documentStart, listener)
web.webChromeClient = FaceclawEvenHubChromeClient()
FaceclawEvenHubWebViewHost.getInstance().attach(this, web, checks[tag]!!)
webViews[tag] = web
web.loadUrl(startUrl)
}
/** As webview.ts's evaluateJs: guarded to the app's origin. */
private fun evaluate(tag: String, js: String) {
webViews[tag]?.evaluateJavascript("if (${checks[tag]}) {\n$js\n}", null)
}
companion object {
private const val TAG = "EHPROBE"
}
}
+35 -7
View File
@@ -12,6 +12,14 @@
@property(nonatomic) BOOL foregroundPassed;
@end
@implementation Probe
- (void)after:(double)seconds run:(void (^)(void))block {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(seconds * NSEC_PER_SEC)), dispatch_get_main_queue(), block);
}
- (UIButton *)button:(NSString *)identifier in:(UIView *)view {
if ([view isKindOfClass:UIButton.class] && [view.accessibilityIdentifier isEqual:identifier]) return (UIButton *)view;
for (UIView *child in view.subviews) { UIButton *found = [self button:identifier in:child]; if (found) return found; }
return nil;
}
- (void)writeResult:(NSDictionary *)result name:(NSString *)name {
NSData *data = [NSJSONSerialization dataWithJSONObject:result options:0 error:nil];
NSString *documents = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
@@ -30,8 +38,10 @@
self.host.eventHandler = ^(NSString *json) {
NSLog(@"EHPROBE %@", json);
NSDictionary *event = [NSJSONSerialization JSONObjectWithData:[json dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
if ([event[@"kind"] isEqual:@"error"] && [event[@"message"] containsString:@"outside the app origin"])
if ([event[@"kind"] isEqual:@"notice"] && [event[@"message"] containsString:@"Blocked navigation to a faceclaw-test:"])
[weakSelf.seen addObject:@"blocked-navigation"];
// Blocked and interrupted navigations are not load errors.
if ([event[@"kind"] isEqual:@"error"]) [weakSelf.seen addObject:[@"ERROR:" stringByAppendingString:event[@"message"]]];
if ([event[@"kind"] isEqual:@"call"]) {
[weakSelf.seen addObject:event[@"name"]];
[weakSelf.seen addObject:[NSString stringWithFormat:@"%ld:%@", (long)weakSelf.phase, event[@"name"]]];
@@ -46,6 +56,24 @@
};
NSString *root = NSBundle.mainBundle.resourcePath;
NSString *script = [NSString stringWithContentsOfFile:[root stringByAppendingPathComponent:@"bridge.js"] encoding:NSUTF8StringEncoding error:nil];
NSString *remote = [NSString stringWithContentsOfFile:[root stringByAppendingPathComponent:@"remote.txt"] encoding:NSUTF8StringEncoding error:nil];
NSString *authorize = [NSString stringWithContentsOfFile:[root stringByAppendingPathComponent:@"authorize.txt"] encoding:NSUTF8StringEncoding error:nil];
// Phase 1: an OAuth sign-in through a third-party page comes back to the packaged app.
[self after:2 run:^{ [self.host evaluate:[NSString stringWithFormat:@"location.href = '%@'", authorize]]; }];
// Phase 2: a non-web scheme is blocked without failing the app; a followed link
// leaves the app, which the Return button restores.
[self after:4.5 run:^{ [self.host evaluate:@"location.href = 'faceclaw-test:blocked'"]; }];
[self after:5 run:^{ [self.host evaluate:[NSString stringWithFormat:@"location.href = '%@away'", remote]]; }];
[self after:6 run:^{
UIButton *button = [self button:@"evenhub-return" in:self.window];
if (button && !button.hidden) [self.seen addObject:@"return-visible"];
[self.host evaluate:@"new Image().src = '/away-eval'"];
[button sendActionsForControlEvents:UIControlEventTouchUpInside];
}];
[self after:7 run:^{
if ([self button:@"evenhub-return" in:self.window].hidden) [self.seen addObject:@"return-hidden"];
[self.host evaluate:@"flutter_inappwebview.callHandler('returned')"];
}];
dispatch_async(dispatch_get_main_queue(), ^{
[self.host start:[root stringByAppendingPathComponent:@"dist"] entrypoint:@"index.html" script:script];
});
@@ -57,15 +85,15 @@
self.host.eventHandler = handler;
self.host.packageIdentifier = phase == 2 ? package : [package stringByAppendingString:@".other"];
if (phase <= 3) [self.host start:[root stringByAppendingPathComponent:@"dist"] entrypoint:@"index.html" script:script];
else {
NSString *url = [NSString stringWithContentsOfFile:[root stringByAppendingPathComponent:@"remote.txt"] encoding:NSUTF8StringEncoding error:nil];
[self.host startURL:phase == 5 ? [url stringByAppendingString:@"redirect"] : url script:script];
}
else [self.host startURL:phase == 5 ? [remote stringByAppendingString:@"redirect"] : remote script:script];
});
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 21 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
NSArray *required = @[@"early", @"module", @"fetch", @"image", @"timer", @"raf", @"wasm", @"traversal", @"1:stored", @"2:restored", @"3:stored", @"4:early", @"4:module", @"4:fetch", @"4:timer", @"blocked-navigation"];
BOOL passed = [[NSSet setWithArray:required] isSubsetOfSet:self.seen] && ![self.seen containsObject:@"UNTRUSTED"];
NSArray *required = @[@"early", @"module", @"fetch", @"image", @"timer", @"raf", @"wasm", @"traversal", @"1:stored", @"2:restored", @"3:stored",
@"1:iframe", @"1:oauth:probe:s1:undefined", @"blocked-navigation", @"return-visible", @"return-hidden", @"2:returned",
@"4:early", @"4:module", @"4:fetch", @"4:timer", @"4:iframe", @"5:early", @"5:module"];
BOOL passed = [[NSSet setWithArray:required] isSubsetOfSet:self.seen] && ![self.seen containsObject:@"UNTRUSTED"] &&
![[self.seen.allObjects componentsJoinedByString:@"\n"] containsString:@"ERROR:"];
NSString *signature = [FaceclawCrypto hmacSha256:@"key" message:@"The quick brown fox jumps over the lazy dog"];
passed &= [signature isEqual:@"97yD9DBThCSxMpjmqm+xQ+9NWaFJRhdZl0edvC0aPNg="];
self.foregroundPassed = passed;
+31 -15
View File
@@ -1,23 +1,39 @@
#import <Foundation/Foundation.h>
#import "FaceclawSocket.h"
/** Drains the socket's events until it closes; handler returns NO to stop early. */
static void pump(FaceclawSocket *socket, BOOL (^handler)(NSDictionary *event)) {
NSDate *deadline = [NSDate dateWithTimeIntervalSinceNow:10];
while (deadline.timeIntervalSinceNow > 0) {
NSArray *events = [NSJSONSerialization JSONObjectWithData:[[socket takeEvents] dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
for (NSDictionary *event in events) if (!handler(event)) return;
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
}
}
int main(int argc, const char **argv) {
@autoreleasepool {
FaceclawSocket *socket = [[FaceclawSocket alloc] initWithURL:[NSString stringWithUTF8String:argv[1]]];
BOOL opened = NO, echoed = NO, closed = NO;
NSDate *deadline = [NSDate dateWithTimeIntervalSinceNow:10];
while (!closed && deadline.timeIntervalSinceNow > 0) {
NSArray *events = [NSJSONSerialization JSONObjectWithData:[[socket takeEvents] dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
for (NSDictionary *event in events) {
NSString *kind = event[@"kind"];
if ([kind isEqual:@"open"]) { opened = YES; [socket sendText:@"Faceclaw echo: π 🔋"]; }
if ([kind isEqual:@"text"]) echoed = [event[@"text"] isEqual:@"Faceclaw echo: π 🔋"];
if ([kind isEqual:@"closed"] || [kind isEqual:@"error"]) closed = YES;
}
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
}
NSString *url = [NSString stringWithUTF8String:argv[1]];
FaceclawSocket *socket = [[FaceclawSocket alloc] initWithURL:url headerName:@"X-Faceclaw-Key" headerValue:@"secret"];
__block BOOL opened = NO, binary = NO, echoed = NO, closed = NO;
pump(socket, ^BOOL(NSDictionary *event) {
NSString *kind = event[@"kind"];
if ([kind isEqual:@"open"]) { opened = YES; const uint8_t bytes[] = {1, 2, 255}; [socket sendData:[NSData dataWithBytes:bytes length:3]]; }
if ([kind isEqual:@"text"] && [event[@"text"] isEqual:@"binary:0102ff"]) { binary = YES; [socket sendText:@"Faceclaw echo: π 🔋"]; }
if ([kind isEqual:@"text"] && [event[@"text"] isEqual:@"Faceclaw echo: π 🔋"]) echoed = YES;
if ([kind isEqual:@"closed"] || [kind isEqual:@"error"]) { closed = YES; return NO; }
return YES;
});
[socket close];
if (!opened || !echoed || !closed) { NSLog(@"FAIL open=%d echo=%d close=%d", opened, echoed, closed); return 1; }
puts("PASS: native WebSocket opens, echoes UTF-8 and reports close");
if (!opened || !binary || !echoed || !closed) { NSLog(@"FAIL open=%d binary=%d echo=%d close=%d", opened, binary, echoed, closed); return 1; }
// Without the header the server refuses the handshake; the error names the status.
FaceclawSocket *refused = [[FaceclawSocket alloc] initWithURL:url];
__block NSString *error = nil;
pump(refused, ^BOOL(NSDictionary *event) {
if ([event[@"kind"] isEqual:@"error"]) { error = event[@"text"]; return NO; }
return YES;
});
[refused close];
if (![error containsString:@"HTTP 401"]) { NSLog(@"FAIL refused handshake error=%@", error); return 1; }
puts("PASS: native WebSocket sends a handshake header, binary and UTF-8 frames, reports close and refused status");
}
return 0;
}
+36 -1
View File
@@ -5,6 +5,7 @@ const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
const alerts = require('../.test-build/app/apps/nightscout/nightscout-alerts.js');
const detector = require('../.test-build/app/apps/nightscout/missed-bolus-detector.js');
const now = 1_800_000_000_000;
const limits = { maxCannulaAgeHours: 72, cartridgeLowUnits: 20, batteryLowVoltage: 1.2, maxLoopAgeMinutes: 15 };
const healthy = { cageTimestampMs: now, reservoirUnits: 100, batteryVoltage: 1.5, loopTimestampMs: now };
@@ -206,6 +207,7 @@ test('bridge exposes numeric measurements and treats absent values as unknown',
let pump = { reservoir: '10.5', battery: { voltage: '1.15' } };
const module = load('app/native/nightscout-bridge.ts', {
'../ui/dashboard-settings': { nightscoutSiteUrlSetting: { get: () => 'https://example.test' }, nightscoutApiTokenSetting: { get: () => 'test' } },
'../apps/nightscout/missed-bolus-detector': detector,
'../util/http': { async fetchTextWithUserAgent(url) {
const body = url.includes('/entries.') ? [{ date: now, sgv: 100 }] : url.includes('/devicestatus.') ? [{ pump, openaps: { suggested: { mills: now - 60_000 } } }] : url.includes('/status.') ? {} : [];
return { ok: true, json: async () => body };
@@ -225,12 +227,44 @@ test('bridge exposes numeric measurements and treats absent values as unknown',
assert.equal(bridge.snapshot().reservoirUnits, 0);
});
test('bridge tags bolus kinds and falls back to the last reading when the window is empty', async () => {
const urls = [];
let recent = [];
const module = load('app/native/nightscout-bridge.ts', {
'../ui/dashboard-settings': { nightscoutSiteUrlSetting: { get: () => 'https://example.test' }, nightscoutApiTokenSetting: { get: () => 'test' } },
'../apps/nightscout/missed-bolus-detector': detector,
'../util/http': { async fetchTextWithUserAgent(url) {
urls.push(url);
const iso = new Date(now - 30 * 60_000).toISOString();
const body = url.includes('/entries.') ? (url.includes('%24gte') ? recent : [{ date: now - 5 * 3_600_000, sgv: 140 }])
: url.includes('/treatments.') && !url.includes('Site%20Change') ? [
{ eventType: 'Meal Bolus', created_at: iso, insulin: 6, carbs: 50 },
{ eventType: 'Correction Bolus', created_at: iso, insulin: 0.3 },
{ eventType: 'Correction Bolus', created_at: iso, insulin: 0.2, automatic: true },
]
: url.includes('/status.') ? {} : [];
return { ok: true, json: async () => body };
} },
}, { Date: class extends Date { static now() { return now; } }, console });
const bridge = new module.NightscoutBridge();
await bridge.refreshNow();
assert.deepEqual(Array.from(bridge.snapshot().boluses, b => b.kind).sort(), ['ambiguous', 'automatic', 'meal']);
assert.equal(bridge.snapshot().latest.sgv, 140, 'a stale last reading still shows');
assert.ok(urls.some(url => url.includes('/entries.json?count=1&')));
recent = [{ date: now - 60_000, sgv: 120 }];
urls.length = 0;
await bridge.refreshNow();
assert.equal(bridge.snapshot().latest.sgv, 120);
assert.ok(!urls.some(url => url.includes('/entries.json?count=1&')), 'no fallback when the window has readings');
});
test('polling starts once and stops even while the initial HTTP request is pending', async () => {
let resolveHttp, calls = 0, nextTimer = 0;
const pending = new Promise(resolve => { resolveHttp = resolve; });
const timers = new Map();
const module = load('app/native/nightscout-bridge.ts', {
'../ui/dashboard-settings': { nightscoutSiteUrlSetting: { get: () => 'https://example.test' }, nightscoutApiTokenSetting: { get: () => 'test' } },
'../apps/nightscout/missed-bolus-detector': detector,
'../util/http': { async fetchTextWithUserAgent() {
calls++;
await pending;
@@ -248,6 +282,7 @@ test('polling starts once and stops even while the initial HTTP request is pendi
assert.equal(timers.size, 0, 'finishing the first refresh must not restart polling');
await bridge.start();
assert.equal(timers.size, 1);
assert.equal(calls, 10);
// Five requests per refresh, plus the last-reading fallback for the empty glucose window.
assert.equal(calls, 12);
await bridge.stop();
});
+48 -8
View File
@@ -187,29 +187,69 @@ test('popup action wraps fully and stays visible with small and large fonts', as
}
});
test('controller filters before waking or opening a popup, and still refreshes the tray', async () => {
test('controller filters before waking or opening a popup, and still refreshes the tray', () => {
const file = ts.createSourceFile('controller.ts', source('app/g2/dashboard-controller.ts'), ts.ScriptTarget.Latest, true);
const controller = file.statements.find((node) => ts.isClassDeclaration(node) && node.name.text === 'DashboardController');
const handler = controller.members.find((node) => node.name?.getText(file) === 'handleAndroidNotificationPosted');
const members = ['handleAndroidNotificationPosted', 'handleAndroidNotificationRemoved', 'popUpAndroidNotification']
.map((name) => controller.members.find((node) => node.name?.getText(file) === name).getText(file));
const { NotificationPopupDelay, notificationPopupDelayMs } = require('../.test-build/app/ui/shell/notification-popup-delay.js');
const prefs = store();
let active = [{ ...mail, key: 'key' }];
let wakes = 0, popups = 0, renders = 0;
const { Harness } = evaluate(`export class Harness { ${handler.getText(file)} }`, null, {
const removed = [];
const { Harness } = evaluate(`export class Harness { ${members.join('\n')} }`, null, {
ALL_NOTIFICATIONS: 0x7fffffff,
readActiveNotifications: () => [{ ...mail, key: 'key' }],
readActiveNotifications: () => active,
shouldShowNotificationOnGlasses: prefs.shouldShowNotificationOnGlasses,
shell: { isScreenOn: () => false, wake: () => { wakes++; return true; }, openNotificationModal: () => popups++ },
notificationPopupDelayMs,
shell: {
isScreenOn: () => false,
wake: () => { wakes++; return true; },
openNotificationModal: () => popups++,
notificationRemoved: (key) => removed.push(key),
},
});
// Popup delays run when the test says so.
let timers = [];
const elapse = () => { const due = timers; timers = []; for (const timer of due) if (!timer.cancelled) timer.run(); };
const instance = new Harness();
instance.notificationPopups = new NotificationPopupDelay((key) => instance.popUpAndroidNotification(key), (run) => {
const timer = { run, cancelled: false };
timers.push(timer);
return () => { timer.cancelled = true; };
});
instance.requestShellRender = () => renders++;
instance.appendLog = () => {};
prefs.setNotificationSourceEnabled(mail, false);
await instance.handleAndroidNotificationPosted('key');
await instance.handleAndroidNotificationPosted('gone');
instance.handleAndroidNotificationPosted('key');
instance.handleAndroidNotificationPosted('gone');
elapse();
assert.equal(wakes, 0);
assert.equal(popups, 0);
assert.equal(renders, 2);
prefs.setNotificationSourceEnabled(mail, true);
await instance.handleAndroidNotificationPosted('key');
instance.handleAndroidNotificationPosted('key');
assert.equal(popups, 0, 'the popup waits out its delay');
elapse();
assert.equal(wakes, 1);
assert.equal(popups, 1);
// Withdrawn by its source during the delay: no wake, no popup, and the shell hears of it.
active = [{ ...mail, key: 'working', foregroundService: true }];
instance.handleAndroidNotificationPosted('working');
active = [];
instance.handleAndroidNotificationRemoved('working');
elapse();
assert.equal(wakes, 1);
assert.equal(popups, 1);
assert.deepEqual(removed, ['working']);
// The filter is checked again once the delay is over.
active = [{ ...mail, key: 'key' }];
instance.handleAndroidNotificationPosted('key');
prefs.setNotificationSourceEnabled(mail, false);
elapse();
assert.equal(popups, 1);
});
+18
View File
@@ -102,3 +102,21 @@ test("the removal reported after a close is ignored, as are stale modals", () =>
assert.deepEqual(host.opened.map((modal) => modal.notificationKey), ["a", "b"]);
assert.deepEqual(queue.queuedKeys(), []);
});
test("a withdrawn notification leaves the queue; the open one is handed back to close", () => {
const host = makeHost();
const queue = new NotificationModalQueue(host);
queue.post("a", true);
queue.post("b", false);
queue.post("c", false);
assert.equal(queue.withdrawn("b"), null);
assert.deepEqual(queue.queuedKeys(), ["c"]);
assert.equal(queue.withdrawn("unknown"), null);
const open = queue.withdrawn("a");
assert.equal(open, host.opened[0]);
// The host closes it, which moves on to the next as a user close would.
queue.closed(open);
assert.deepEqual(host.opened.map((modal) => modal.notificationKey), ["a", "c"]);
queue.closed(queue.withdrawn("c"));
assert.equal(host.sleeps, 1, "the screen the withdrawn notification woke sleeps again");
});
+93
View File
@@ -0,0 +1,93 @@
const test = require("node:test");
const assert = require("node:assert/strict");
const {
FOREGROUND_SERVICE_POPUP_DELAY_MS,
NOTIFICATION_POPUP_DELAY_MS,
NotificationPopupDelay,
notificationPopupDelayMs,
} = require("../.test-build/app/ui/shell/notification-popup-delay.js");
/** A manual clock: schedule() queues timers that advance() fires in due order. */
function makeClock() {
const clock = {
nowMs: 0,
timers: [],
now: () => clock.nowMs,
schedule(run, delayMs) {
const timer = { dueAtMs: clock.nowMs + delayMs, run, cancelled: false };
clock.timers.push(timer);
return () => { timer.cancelled = true; };
},
advance(ms) {
const until = clock.nowMs + ms;
for (;;) {
const due = clock.timers.filter((timer) => !timer.cancelled && timer.dueAtMs <= until)
.sort((a, b) => a.dueAtMs - b.dueAtMs)[0];
if (!due) break;
clock.nowMs = due.dueAtMs;
due.cancelled = true;
due.run();
}
clock.nowMs = until;
},
};
return clock;
}
function makeDelay() {
const clock = makeClock();
const ready = [];
const delay = new NotificationPopupDelay((key) => ready.push(key), clock.schedule, clock.now);
return { clock, ready, delay };
}
test("a notification pops up once its delay passes", () => {
const { clock, ready, delay } = makeDelay();
delay.post("a", 500);
clock.advance(499);
assert.deepEqual(ready, []);
assert.deepEqual(delay.pendingKeys(), ["a"]);
clock.advance(1);
assert.deepEqual(ready, ["a"]);
assert.deepEqual(delay.pendingKeys(), []);
});
test("one withdrawn while waiting never pops up; the replacement still does", () => {
const { clock, ready, delay } = makeDelay();
// Messages: a foreground-service placeholder, the message under another key, then the placeholder goes.
delay.post("working", 5000);
clock.advance(2000);
delay.post("message", 500);
assert.equal(delay.withdraw("working"), true);
clock.advance(10000);
assert.deepEqual(ready, ["message"]);
assert.equal(delay.withdraw("working"), false);
assert.equal(delay.withdraw("message"), false, "already popped up");
});
test("reposts can bring a popup forward but never push it back", () => {
const { clock, ready, delay } = makeDelay();
delay.post("a", 500);
clock.advance(400);
delay.post("a", 500);
clock.advance(100);
assert.deepEqual(ready, ["a"], "an update does not restart the delay");
// Rewritten from a foreground-service placeholder into the real notification, same key.
delay.post("b", 5000);
clock.advance(1000);
delay.post("b", 500);
clock.advance(500);
assert.deepEqual(ready, ["a", "b"]);
clock.advance(10000);
assert.deepEqual(ready, ["a", "b"], "the earlier timer was cancelled");
});
test("foreground-service notifications wait longer, unless urgent", () => {
assert.equal(notificationPopupDelayMs({ category: "msg" }), NOTIFICATION_POPUP_DELAY_MS);
assert.equal(notificationPopupDelayMs({ category: "", foregroundService: true }), FOREGROUND_SERVICE_POPUP_DELAY_MS);
assert.equal(notificationPopupDelayMs({ category: "call", foregroundService: true }), NOTIFICATION_POPUP_DELAY_MS);
assert.equal(notificationPopupDelayMs({ category: "alarm", foregroundService: true }), NOTIFICATION_POPUP_DELAY_MS);
assert.ok(FOREGROUND_SERVICE_POPUP_DELAY_MS > NOTIFICATION_POPUP_DELAY_MS);
});
+263
View File
@@ -0,0 +1,263 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
// Roboto's line heights at the onboarding sizes, and a fixed advance.
const FONTS = { title: 31, body: 24, detail: 19, hero: 52 };
const font = (role) => ({ lineHeight: FONTS[role], measureText: (text) => text.length * 8, getGlyph: () => ({ dwidthX: 8 }) });
function setting(value, values) {
return { value, values, get() { return this.value; }, set(next) { this.value = next; this.writes.push(next); },
writes: [], displayValue: (v) => v[0].toUpperCase() + v.slice(1) };
}
function harness() {
const settings = {
appSwitcherPositionSetting: setting('bottom', ['left', 'right', 'bottom', 'popup']),
statusBarPositionSetting: setting('bottom', ['top', 'bottom']),
uiDepthSetting: setting('48', ['-62', '-48', '-32', '-16', '0', '16', '32', '48', '62']),
};
const load = loader({}, {
'./onboarding-fonts': { onboardingFont: font },
'../../graphics/image': { G2_LENS_WIDTH: 640 },
'../../ui/dashboard-settings': settings,
'../../ui/shell/geometry': { MIN_WINDOW_HEIGHT: 288, SIDEBAR_WIDTH: 64, SWITCHER_ROW_HEIGHT: 36, TOP_BAR_HEIGHT: 28 },
});
return { settings, load };
}
/** An image that records what is drawn, checking it all lands on the image. */
function recorder(width, height) {
const calls = [];
const inside = (kind, x, y, w, h) => {
assert.ok(x >= 0 && y >= 0 && x + w <= width && y + h <= height, `${kind} out of bounds: ${[x, y, w, h]}`);
};
return {
width, height, calls,
fillRect(x, y, w, h, value) { inside('fillRect', x, y, w, h); calls.push({ kind: 'fill', x, y, w, h, value }); },
fillRoundedRect(x, y, w, h, value) { inside('fillRoundedRect', x, y, w, h); calls.push({ kind: 'fill', x, y, w, h, value }); },
drawRoundedRect(x, y, w, h, value) { inside('drawRoundedRect', x, y, w, h); calls.push({ kind: 'outline', x, y, w, h, value }); },
drawText(f, x, y, text, value) {
inside(`text "${text}"`, x, y, f.measureText(text), f.lineHeight);
calls.push({ kind: 'text', x, y, text, value });
},
};
}
test('the layout page fits four 40%-wide diagrams with captions on the immersive panel', () => {
const { load } = harness();
const { LayoutPage } = load('app/apps/onboarding/layout-page.ts');
const page = new LayoutPage();
assert.equal(page.immersive, true);
const image = recorder(640, 480);
page.paint(image, true);
// Each diagram's outline spans the display's width at 40%.
const areas = image.calls.filter((call) => call.kind === 'outline' && call.w === 256);
assert.equal(areas.length, 4);
assert.deepEqual(areas.map((area) => area.h), [130, 130, 130, 130]);
// A 2x2 grid, the layouts with depth on top, captioned under each diagram.
const text = (label) => image.calls.filter((call) => call.kind === 'text' && call.text === label);
const [bottom, popup, left, right] = ['Bottom (Recommended)', 'Popup', 'Left', 'Right'].map((label) => text(label)[0]);
assert.equal(bottom.y, popup.y);
assert.equal(left.y, right.y);
assert.ok(left.y > bottom.y);
assert.ok(popup.x > bottom.x && right.x > left.x);
for (const [caption, area] of [[bottom, areas[0]], [popup, areas[1]], [left, areas[2]], [right, areas[3]]]) {
assert.ok(caption.y >= area.y + area.h, `${caption.text} sits under its diagram`);
assert.ok(caption.x > area.x && caption.x + caption.text.length * 8 < area.x + area.w, `${caption.text} sits under its diagram`);
}
// Customizable Depth under Bottom and Popup only.
const depth = text('Customizable Depth');
assert.equal(depth.length, 2);
for (const [subtitle, title] of [[depth[0], bottom], [depth[1], popup]]) {
assert.equal(subtitle.y, title.y + FONTS.body);
assert.ok(Math.abs(subtitle.x + 'Customizable Depth'.length * 4 - (title.x + title.text.length * 4)) <= 1, 'centred together');
}
// Bottom, recommended, is the selected cell at first, filled while focused.
const box = image.calls.find((call) => call.kind === 'fill' && call.value === 15);
assert.ok(box.x <= areas[0].x && box.y <= areas[0].y && box.y + box.h >= bottom.y);
});
test('the layout page starts on Bottom whatever is set, swipes in reading order, and a tap saves the choice', () => {
const { load, settings } = harness();
const { LayoutPage } = load('app/apps/onboarding/layout-page.ts');
const page = new LayoutPage();
settings.appSwitcherPositionSetting.value = 'right';
page.enter?.();
let next = 0;
const nav = { next: () => next++ };
page.handleInput({ type: 'click' }, nav);
assert.deepEqual(settings.appSwitcherPositionSetting.writes, ['bottom']);
page.handleInput({ type: 'scroll-up' }, nav);
for (let i = 0; i < 2; i++) page.handleInput({ type: 'scroll-down' }, nav);
assert.deepEqual(settings.appSwitcherPositionSetting.writes, ['bottom'], 'scrolling saves nothing');
page.handleInput({ type: 'click' }, nav);
for (let i = 0; i < 5; i++) page.handleInput({ type: 'scroll-down' }, nav);
// Coming back keeps the last choice.
page.enter?.();
page.handleInput({ type: 'click' }, nav);
assert.deepEqual(settings.appSwitcherPositionSetting.writes, ['bottom', 'left', 'right']);
assert.equal(next, 3);
});
test('the text size page offers 12 to 18px, starts on the recommended 16px, and previews plain text', () => {
const menu = { selected: null, items: [], setItems(items, index) { this.items = items; this.selected = index; },
get selectedItem() { return this.items[this.selected] ?? null; }, paint(image, box) { this.box = box; },
async handleInput(event) { this.selected = Math.max(0, Math.min(this.items.length - 1, this.selected + (event.type === 'scroll-down' ? 1 : -1))); } };
let menuOptions;
let selection = { kind: 'ttf', file: 'Roboto-Light.ttf', size: 14 };
const saved = [];
const load = loader({}, {
'./onboarding-fonts': { onboardingFont: font },
'../../graphics/installed-fonts': { installedFontPath: (file) => `/fonts/${file}` },
'../../graphics/ttf-font': { TtfFont: { load: (path, size) => font(size === 12 ? 'title' : 'detail') } },
'../../graphics/ui-fonts': { fontSelectionLabel: () => 'Terminus', getDefaultSmallFont: () => font('detail'),
getUiFontSelection: () => selection, setUiFontSelection: (value) => { selection = value; saved.push(value.size); },
uiFontSizeAllowed: (path, size) => size !== 13 },
'../../ui/font-picker': { FONT_SIZE_CHOICES: [8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 24] },
'../../ui/menu-core': { Menu: class { constructor(options) { menuOptions = options; return menu; } } },
'../../ui/metrics': { LIST_ROW_TEXT_INSET: 4, listRowHeight: (f) => f.lineHeight + 8 },
});
const { TextSizePage } = load('app/apps/onboarding/text-size-page.ts');
const page = new TextSizePage();
page.enter();
assert.deepEqual(Array.from(menu.items), [12, 14, 15, 16, 17, 18]);
assert.equal(menu.selectedItem, 16, 'recommended, not the current 14');
// Only 16 carries the note, beside its size.
const rows = [];
for (const size of menu.items) {
const row = recorder(menu.box?.width ?? 200, 32);
menuOptions.draw({ image: row, item: size, x: 0, y: 0, width: row.width, height: 32, selected: size === 16 });
rows.push(row.calls.map((call) => call.text));
}
assert.deepEqual(rows[3], ['16 px', 'Recommended']);
assert.deepEqual(rows.filter((texts) => texts.length > 1).length, 1);
// The size column holds the note; the preview is paragraphs of text, no menu.
const image = recorder(640, 480);
page.paint(image, true);
assert.ok(menu.box.width >= 10 + '16 px'.length * 8 + 8 + 'Recommended'.length * 8);
const preview = image.calls.filter((call) => call.kind === 'text' && call.x > menu.box.x + menu.box.width);
assert.equal(preview[0].text.startsWith('This is how text will look'), true);
assert.ok(preview.length > 3);
assert.equal(image.calls.some((call) => call.kind === 'text' && call.text === 'Timers'), false);
// A tap saves; coming back keeps the size chosen.
page.handleInput({ type: 'scroll-up' }, { next: () => {} });
page.handleInput({ type: 'click' }, { next: () => {} });
assert.deepEqual(saved, [15]);
page.enter();
assert.equal(menu.selectedItem, 15);
});
test('the depth page follows layouts that have depth, sits in the layout, and applies depth as it scrolls', () => {
const { load, settings } = harness();
const menu = { selected: 0, items: [], select(index) { this.selected = index; },
get selectedItem() { return this.items[this.selected] ?? null; }, paint() {},
async handleInput(event) { this.selected = Math.max(0, Math.min(this.items.length - 1, this.selected + (event.type === 'scroll-down' ? 1 : -1))); } };
const mocks = loader({}, {
'./onboarding-fonts': { onboardingFont: font },
'../../ui/dashboard-settings': settings,
'../../ui/menu-core': { Menu: class { constructor(options) { menu.items = options.items; return menu; } } },
'../../ui/metrics': { LIST_ROW_TEXT_INSET: 4, listRowHeight: (f) => f.lineHeight + 8 },
'./layout-page': { layoutHasDepth: (position) => position === 'bottom' || position === 'popup' },
});
const { DepthPage } = mocks('app/apps/onboarding/depth-page.ts');
const page = new DepthPage();
assert.equal(page.immersive, undefined);
for (const [position, applies] of [['left', false], ['right', false], ['bottom', true], ['popup', true]]) {
settings.appSwitcherPositionSetting.value = position;
assert.equal(page.applies(), applies, position);
}
page.enter();
assert.equal(menu.selectedItem, '48');
let next = 0;
page.handleInput({ type: 'scroll-down' }, { next: () => next++ });
page.handleInput({ type: 'scroll-up' }, { next: () => next++ });
page.handleInput({ type: 'scroll-up' }, { next: () => next++ });
assert.deepEqual(settings.uiDepthSetting.writes, ['62', '48', '32']);
page.handleInput({ type: 'click' }, { next: () => next++ });
assert.equal(next, 1);
});
test('the flow switches immersive mode per page and skips pages that do not apply, both ways', async () => {
const shell = { yields: 0, yieldFocusToSidebar() { this.yields++; } };
const load = loader({}, {
'../../graphics/image': { GrayImage: class {} },
'../../ui/shell/in-process-window': {}, '../../ui/shell/shell': { shell }, '../../ui/sound-effects': {},
'./data-collection-page': {}, './depth-page': {}, './display-mode-page': {}, './ios-privacy-page': {}, './layout-page': {},
'./onboarding-progress': {}, './text-size-page': {}, './welcome-page': {},
});
const { OnboardingLayer } = load('app/apps/onboarding/onboarding-app.ts');
let depthApplies = false;
const entered = [];
const page = (name, extra) => ({ ...extra, enter: () => entered.push(name),
handleInput: (event, nav) => { if (event.type === 'click') nav.next(); } });
const immersive = [];
let finished = 0;
const layer = new OnboardingLayer([
page('welcome', { immersive: true }), page('layout', { immersive: true }),
page('depth', { applies: () => depthApplies }), page('voice', {}),
], (value) => immersive.push(value), () => finished++);
const input = (type) => layer.handleInput({ type });
await input('click');
await input('click');
assert.deepEqual(entered, ['welcome', 'layout', 'voice'], 'depth skipped going forward');
assert.deepEqual(immersive, [true, false]);
await input('double-click');
assert.deepEqual(entered.at(-1), 'layout', 'and going back');
depthApplies = true;
await input('click');
await input('click');
assert.deepEqual(entered.slice(-2), ['depth', 'voice']);
assert.deepEqual(immersive, [true, false, true, false, false]);
await input('click');
assert.equal(finished, 1);
for (let i = 0; i < 4; i++) await input('double-click');
assert.equal(entered.at(-1), 'welcome');
assert.equal(shell.yields, 1, 'double-click on the first page leaves the app');
});
test('the display mode page offers Full Screen only where the layout allows it, and applies the mode as it scrolls', () => {
const values = ['band-top', 'band-high', 'band-middle', 'band-low', 'band-bottom', 'tall', 'fullscreen'];
const settings = {
appSwitcherPositionSetting: setting('bottom', ['left', 'right', 'bottom', 'popup']),
displayLayoutSetting: { ...setting('fullscreen', values), displayValue: (v) => v,
isDisabled: (v) => v === 'fullscreen' && ['left', 'right'].includes(settings.appSwitcherPositionSetting.value) },
};
const menu = { selected: null, items: [], setItems(items, index) { this.items = items; this.selected = index; },
get selectedItem() { return this.items[this.selected] ?? null; }, paint(image, box) { this.box = box; },
async handleInput(event) { this.selected = Math.max(0, Math.min(this.items.length - 1, this.selected + (event.type === 'scroll-down' ? 1 : -1))); } };
const load = loader({}, {
'./onboarding-fonts': { onboardingFont: font },
'../../ui/dashboard-settings': settings,
'../../ui/menu-core': { Menu: class { constructor() { return menu; } } },
'../../ui/metrics': { LIST_ROW_TEXT_INSET: 4, listRowHeight: (f) => f.lineHeight + 8 },
});
const { DisplayModePage } = load('app/apps/onboarding/display-mode-page.ts');
const page = new DisplayModePage();
// An ordinary window, which the mode being applied resizes.
assert.equal(page.immersive, undefined);
page.enter();
assert.deepEqual(Array.from(menu.items), values);
assert.equal(menu.selectedItem, 'fullscreen');
// The selected mode's description sits beside the list, within the window (a band's).
const image = recorder(576, 260);
page.paint(image, true);
const description = image.calls.filter((call) => call.kind === 'text' && call.x >= menu.box.x + menu.box.width);
assert.match(description.map((call) => call.text).join(' '), /Depth is turned off/);
let next = 0;
const nav = { next: () => next++ };
page.handleInput({ type: 'scroll-up' }, nav);
page.handleInput({ type: 'scroll-up' }, nav);
assert.deepEqual(settings.displayLayoutSetting.writes, ['tall', 'band-bottom'], 'applied as it scrolls');
page.handleInput({ type: 'click' }, nav);
assert.equal(next, 1);
assert.deepEqual(settings.displayLayoutSetting.writes, ['tall', 'band-bottom']);
// Beside a side strip, a saved Full Screen shows as Tall, and is saved as such on a tap.
settings.displayLayoutSetting.value = 'fullscreen';
settings.appSwitcherPositionSetting.value = 'left';
page.enter();
assert.deepEqual(Array.from(menu.items), values.slice(0, 6));
assert.equal(menu.selectedItem, 'tall');
page.handleInput({ type: 'click' }, nav);
assert.equal(settings.displayLayoutSetting.value, 'tall');
});
+2 -1
View File
@@ -17,7 +17,7 @@ function harness() {
Application: { android: { get foregroundActivity() { return activityPresent ? activity : null; } } },
android: { content: { Context: { POWER_SERVICE: 'power' } } },
Date: { now: () => now }, CONNECTED_PREVIEW_MIN_UPDATE_MS: 100, RECORDING_MIN_CAPTURE_MS: 200,
previewColorSetting: { get: () => 'green' },
previewColorSetting: { get: () => 'green' }, phonePreviewCrop: () => null,
setTimeout: fn => { const id = timers.size + 1; timers.set(id, fn); return id; },
clearTimeout: id => timers.delete(id),
};
@@ -27,6 +27,7 @@ function harness() {
const instance = new context.exports.Harness();
Object.assign(instance, { lastConnectedPreviewUpdateAtMs: 0, lastRecordCaptureAtMs: 0,
phonePreviewVisible: null, previewTrailingTimer: null, screenRecordingActive: false,
glassesLocked: false, glance: { screenRect: () => null },
display: { getCompositePreview: () => { previews++; return {}; }, recordScreenFrame: () => records++ },
setDisplayPreview() {},
});
+6 -3
View File
@@ -10,8 +10,8 @@ function fixture() {
}
const settings = {
brightnessSetting: { get: () => brightness, set: value => { brightness = value; writes.push(value); } },
displayModeSetting: { get: () => mode, set: value => { mode = value; } },
DISPLAY_MODE_VALUES: ['small', 'large'], displayModeLabel: value => value === 'small' ? 'Small' : 'Large',
displayLayoutSetting: { get: () => mode, set: value => { mode = value; }, values: ['small', 'large', 'huge'],
isDisabled: value => value === 'huge', displayValue(value = mode) { return value[0].toUpperCase() + value.slice(1); } },
};
const { RemoteControlsViewModel } = loader({}, {
'@nativescript/core': { Observable, Dialogs: { action: async () => picked } },
@@ -51,10 +51,13 @@ test('shared brightness controls snap manual levels and restore the manual value
assert.equal(h.brightness(), '2');
});
test('shared screen-size picker preserves cancellation and applies the selected mode', async () => {
test('shared display-mode picker preserves cancellation and applies the selected mode', async () => {
const h = fixture();
h.pick('Cancel'); await h.model.onDisplayModeTap();
assert.equal(h.mode(), 'small');
// Unavailable modes (Full Screen beside a side strip) are not offered.
h.pick('Huge'); await h.model.onDisplayModeTap();
assert.equal(h.mode(), 'small');
h.pick('Large'); await h.model.onDisplayModeTap();
assert.equal(h.mode(), 'large');
assert.equal(h.model.displayModeLabel, 'Large ▾');
+174
View File
@@ -0,0 +1,174 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const launch = require('../.test-build/app/apps/t3code/t3-launch.js');
const EFFORT = {
id: 'effort', label: 'Effort', type: 'select', promptInjectedValues: ['ultrathink'],
options: [{ id: 'low', label: 'Low' }, { id: 'high', label: 'High', isDefault: true }, { id: 'ultrathink', label: 'Ultrathink' }, { id: 'ultracode', label: 'Ultracode' }],
};
const FAST = { id: 'fastMode', label: 'Fast mode', type: 'boolean' };
const providers = [
{ instanceId: 'codex', driver: 'codex', enabled: true, installed: true, auth: { status: 'unauthenticated' }, models: [{ slug: 'gpt-5', isDefault: true }] },
{
instanceId: 'claudeAgent', driver: 'claudeAgent', enabled: true, installed: true, auth: { status: 'authenticated' },
supportedRuntimeModes: ['approval-required', 'full-access'],
models: [
{ slug: 'old', name: 'Old', isLegacy: true, isDefault: true },
{ slug: 'claude-sonnet-5', name: 'Claude Sonnet 5' },
{ slug: 'claude-opus-5', name: 'Claude Opus 5', isDefault: true, capabilities: { optionDescriptors: [EFFORT, FAST] } },
],
},
{ instanceId: 'pi', driver: 'pi', enabled: true, installed: true, auth: { status: 'authenticated' }, models: [{ slug: 'pi-1' }] },
];
const project = { id: 'p1', title: 'faceclaw', workspaceRoot: '/src/faceclaw' };
const refs = {
isRepo: true, hasPrimaryRemote: true, nextCursor: null, totalCount: 4,
refs: [
{ name: 'feature', current: true, isDefault: false, worktreePath: '/src/faceclaw' },
{ name: 'main', current: false, isDefault: true, worktreePath: null },
{ name: 'spike', current: false, isDefault: false, worktreePath: '/src/faceclaw-spike' },
{ name: 'origin/main', isRemote: true, remoteName: 'origin', current: false, isDefault: false, worktreePath: null },
],
};
const context = (overrides = {}) => ({ settings: null, providers, project, scratchWorkspaceRoot: '/home/scratch', projectFile: null, refs, ...overrides });
test('default model selection mirrors mobile', () => {
assert.deepEqual(launch.defaultModelSelection(null, providers, project), { instanceId: 'claudeAgent', model: 'claude-opus-5' });
const settings = { defaultModelSelection: { instanceId: 'codex', model: 'gpt-5' }, projectSettingsOverrides: { p1: { defaultModelSelection: { instanceId: 'claudeAgent', model: 'claude-sonnet-5' } } } };
assert.deepEqual(launch.defaultModelSelection(settings, providers, project), { instanceId: 'claudeAgent', model: 'claude-sonnet-5' });
assert.equal(launch.defaultModelSelection({ defaultModelSelection: { instanceId: 'codex', model: 'gpt-5' } }, providers.slice(0, 1), project), null, 'unauthenticated providers are skipped');
// The project's legacy field acts as an override until the server folds it.
const legacyProject = { ...project, defaultModelSelection: { instanceId: 'pi', model: 'pi-1' } };
assert.deepEqual(launch.defaultModelSelection({ defaultModelSelection: { instanceId: 'claudeAgent', model: 'claude-sonnet-5' } }, providers, legacyProject), { instanceId: 'pi', model: 'pi-1' });
assert.deepEqual(
launch.defaultModelSelection({ projectSettingsFolded: true, defaultModelSelection: { instanceId: 'claudeAgent', model: 'claude-sonnet-5' } }, providers, legacyProject),
{ instanceId: 'claudeAgent', model: 'claude-sonnet-5' },
);
});
test('model choices group usable providers, legacy last', () => {
const groups = launch.modelChoices(providers);
assert.deepEqual(groups.map((group) => group.label), ['Claude', 'Pi']);
assert.deepEqual(groups[0].models.map((model) => model.label), ['Claude Sonnet 5', 'Claude Opus 5', 'Old']);
assert.equal(groups[0].models[2].isLegacy, true);
assert.equal(launch.modelDisplayName(providers, { instanceId: 'claudeAgent', model: 'claude-opus-5' }), 'Claude Opus 5');
});
test('model options: defaults, picks, hidden choices, dispatch normalization', () => {
const opus = { instanceId: 'claudeAgent', model: 'claude-opus-5' };
const [effort, fast] = launch.modelOptionDescriptors(providers, opus);
assert.equal(launch.optionValue(effort, opus), 'high', 'isDefault choice');
assert.equal(launch.optionValueLabel(fast, launch.optionValue(fast, opus)), 'Off');
assert.deepEqual(launch.selectableChoices(effort).map((choice) => choice.id), ['low', 'high'], 'prompt-injected and ultracode are not offered');
const picked = launch.withModelOption(launch.withModelOption(opus, 'effort', 'low'), 'fastMode', true);
assert.equal(launch.optionValue(effort, picked), 'low');
assert.equal(launch.optionValue(fast, picked), true);
assert.deepEqual(launch.withModelOption(picked, 'effort', 'high').options, [{ id: 'fastMode', value: true }, { id: 'effort', value: 'high' }]);
assert.deepEqual(launch.dispatchModelSelection(providers, opus), opus, 'no picks: provider defaults');
const stale = { ...opus, options: [{ id: 'effort', value: 'ultrathink' }, { id: 'gone', value: 'x' }] };
assert.deepEqual(launch.dispatchModelSelection(providers, stale), { ...opus, options: [{ id: 'effort', value: 'high' }] }, 'invalid values fall back; unknown ids drop');
});
test('access modes follow the provider and project defaults', () => {
assert.deepEqual(launch.runtimeModeChoices(providers[1]).map((choice) => choice.mode), ['approval-required', 'full-access']);
assert.equal(launch.runtimeModeChoices(providers[2]).length, 4, 'unspecified: every mode');
const draft = launch.emptyLaunchDraft();
assert.equal(launch.resolveLaunch(draft, context()).runtimeMode, 'full-access');
const settings = { defaultRuntimeMode: 'auto', projectSettingsOverrides: { p1: { defaultRuntimeMode: 'approval-required' } } };
assert.equal(launch.resolveLaunch(draft, context({ settings })).runtimeMode, 'approval-required');
// "auto" isn't one of Claude's here, so it falls back to the first supported mode.
assert.equal(launch.resolveLaunch({ ...draft, runtimeMode: 'auto' }, context()).runtimeMode, 'approval-required');
});
test('workspace: defaults chain, current checkout, existing and new worktrees', () => {
let draft = launch.emptyLaunchDraft();
let resolved = launch.resolveLaunch(draft, context());
assert.equal(resolved.workspaceMode, 'local');
assert.equal(resolved.branch, 'feature');
assert.equal(launch.workspaceLabel(resolved), 'Current checkout');
assert.deepEqual(launch.workspaceStrategy(resolved), { type: 'root', branch: 'feature' });
assert.equal(launch.resolveLaunch(draft, context({ projectFile: { defaultThreadEnvMode: 'worktree' } })).workspaceMode, 'worktree', 't3.json');
assert.equal(
launch.resolveLaunch(draft, context({ settings: { defaultThreadEnvMode: 'local' }, projectFile: { defaultThreadEnvMode: 'worktree' } })).workspaceMode,
'local',
'the environment setting outranks t3.json',
);
assert.equal(
launch.resolveLaunch(draft, context({ project: { ...project, defaultThreadEnvMode: 'worktree' }, settings: { defaultThreadEnvMode: 'local' } })).workspaceMode,
'worktree',
'a project override outranks the environment',
);
// A branch checked out in another worktree runs there.
draft = launch.pickBranch(draft, refs.refs[2], 'local', project);
resolved = launch.resolveLaunch(draft, context());
assert.equal(launch.workspaceLabel(resolved), 'Existing worktree');
assert.deepEqual(launch.workspaceStrategy(resolved), { type: 'existing_worktree', worktreePath: '/src/faceclaw-spike', branch: 'spike' });
assert.equal(launch.needsCheckout(refs.refs[1], 'local'), true);
assert.equal(launch.needsCheckout(refs.refs[2], 'local'), false);
assert.equal(launch.needsCheckout(refs.refs[1], 'worktree'), false);
assert.equal(launch.refBadge(refs.refs[0], project), 'current');
assert.equal(launch.refBadge(refs.refs[2], project), 'worktree');
// New worktree: from the default branch, origin by default.
draft = launch.pickWorkspaceMode(launch.emptyLaunchDraft(), 'worktree');
resolved = launch.resolveLaunch(draft, context());
assert.equal(resolved.branch, 'main');
assert.equal(launch.branchLabel(resolved, true), 'From origin/main');
assert.deepEqual(launch.workspaceStrategy(resolved), { type: 'worktree', baseRef: 'main', startFromOrigin: true });
resolved = launch.resolveLaunch({ ...draft, startFromOrigin: false }, context());
assert.equal(launch.branchLabel(resolved, true), 'From main');
assert.deepEqual(launch.workspaceStrategy(resolved), { type: 'worktree', baseRef: 'main' });
assert.equal(launch.resolveLaunch(draft, context({ settings: { newWorktreesStartFromOrigin: false } })).startFromOrigin, false);
// An explicit base survives switching back and forth; the checkout returns to what's checked out.
draft = launch.pickBranch(draft, refs.refs[0], 'worktree', project);
assert.equal(launch.resolveLaunch(draft, context()).branch, 'feature');
assert.equal(launch.resolveLaunch(launch.pickWorkspaceMode(draft, 'local'), context()).worktreePath, null);
assert.equal(launch.resolveLaunch(launch.pickWorkspaceMode(draft, 'worktree'), context()).branch, 'feature');
// Still loading branches: worktree mode can't start yet.
assert.match(launch.resolveLaunch(launch.pickWorkspaceMode(launch.emptyLaunchDraft(), 'worktree'), context({ refs: null })).blocker, /loading/);
});
test('scratch projects and non-repos run in their folder', () => {
const scratch = { id: 'p2', title: 'Scratch', workspaceRoot: '/home/scratch/' };
let resolved = launch.resolveLaunch({ ...launch.emptyLaunchDraft(), workspaceMode: 'worktree' }, context({ project: scratch, refs: null }));
assert.equal(resolved.canChooseWorkspace, false);
assert.deepEqual(launch.workspaceStrategy(resolved), { type: 'root' });
resolved = launch.resolveLaunch(launch.emptyLaunchDraft(), context({ refs: { refs: [], isRepo: false, hasPrimaryRemote: false } }));
assert.equal(resolved.canChooseWorkspace, false);
});
test('launch payload carries every option', () => {
const draft = { ...launch.pickWorkspaceMode(launch.emptyLaunchDraft(), 'worktree'), model: { instanceId: 'claudeAgent', model: 'claude-opus-5', options: [{ id: 'effort', value: 'low' }] }, runtimeMode: 'approval-required' };
const resolved = launch.resolveLaunch(draft, context());
const payload = launch.launchThreadPayload(project, ' Fix the login test ', resolved, providers);
assert.equal(payload.title, 'Fix the login test');
assert.equal(payload.projectId, 'p1');
assert.deepEqual(payload.modelSelection, { instanceId: 'claudeAgent', model: 'claude-opus-5', options: [{ id: 'effort', value: 'low' }] });
assert.equal(payload.runtimeMode, 'approval-required');
assert.equal(payload.interactionMode, 'default');
assert.deepEqual(payload.workspaceStrategy, { type: 'worktree', baseRef: 'main', startFromOrigin: true });
assert.equal(payload.initialMessage.text, ' Fix the login test ');
assert.throws(() => launch.launchThreadPayload(project, 'x', launch.resolveLaunch(launch.emptyLaunchDraft(), context({ providers: [] })), []), /No usable agent/);
});
test('matching project on another host', () => {
const projects = [
{ id: 'a', title: 'Other', workspaceRoot: '/w/other' },
{ id: 'b', title: 'faceclaw-fork', workspaceRoot: '/w/faceclaw' },
{ id: 'c', title: 'renamed', workspaceRoot: '/w/x', repositoryIdentity: { canonicalKey: 'github.com/jimrandomh/faceclaw' } },
];
assert.equal(launch.matchingProject(projects, { ...project, repositoryIdentity: { canonicalKey: 'github.com/jimrandomh/faceclaw' } }).id, 'c');
assert.equal(launch.matchingProject(projects, project).id, 'b', 'folder name');
assert.equal(launch.matchingProject(projects, { id: 'z', title: 'Other', workspaceRoot: '/elsewhere/q' }).id, 'a', 'title');
assert.equal(launch.matchingProject(projects, { id: 'z', title: 'none', workspaceRoot: '/q/none' }), null);
});
test('t3.json parsing', () => {
assert.deepEqual(launch.parseProjectFile('{"defaultThreadEnvMode":"worktree","scripts":[]}'), { defaultThreadEnvMode: 'worktree' });
assert.deepEqual(launch.parseProjectFile('{"defaultThreadEnvMode":"bogus"}'), {});
assert.equal(launch.parseProjectFile('not json'), null);
});
-16
View File
@@ -198,22 +198,6 @@ test('plainMarkdown cleans up for the glasses', () => {
);
});
test('default model selection mirrors mobile', () => {
const providers = [
{ instanceId: 'codex', enabled: true, installed: true, auth: { status: 'unauthenticated' }, models: [{ slug: 'gpt-5', isDefault: true }] },
{ instanceId: 'claudeAgent', enabled: true, installed: true, auth: { status: 'authenticated' }, models: [{ slug: 'old', isLegacy: true, isDefault: true }, { slug: 'claude-sonnet-5' }, { slug: 'claude-opus-5', isDefault: true }] },
];
const project = { id: 'p1', title: 'faceclaw' };
assert.deepEqual(model.defaultModelSelection(null, providers, project), { instanceId: 'claudeAgent', model: 'claude-opus-5' });
const settings = { defaultModelSelection: { instanceId: 'codex', model: 'gpt-5' }, projectSettingsOverrides: { p1: { defaultModelSelection: { instanceId: 'claudeAgent', model: 'claude-sonnet-5' } } } };
assert.deepEqual(model.defaultModelSelection(settings, providers, project), { instanceId: 'claudeAgent', model: 'claude-sonnet-5' });
assert.equal(model.defaultModelSelection({ defaultModelSelection: { instanceId: 'codex', model: 'gpt-5' } }, providers.slice(0, 1), project), null, 'unauthenticated providers are skipped');
const payload = model.launchThreadPayload(project, ' Fix the login test ', { instanceId: 'claudeAgent', model: 'claude-opus-5' }, null);
assert.equal(payload.title, 'Fix the login test');
assert.equal(payload.runtimeMode, 'full-access');
assert.deepEqual(payload.workspaceStrategy, { type: 'root' });
});
test('formatAge', () => {
assert.equal(model.formatAge(NOW - 20_000, NOW), 'now');
assert.equal(model.formatAge(NOW - 5 * 60_000, NOW), '5m');
+10
View File
@@ -113,6 +113,16 @@ test("timers sort ringing first, then soonest running, then paused", () => {
assert.deepEqual(model.sortTimers([running, paused, rung, sooner], now).map((timer) => timer.id), [4, 2, 1, 3]);
});
test("the tray counts down the running timer that ends soonest", () => {
const now = 1_000_000;
const running = { id: 1, label: "", durationMs: 600_000, endsAtMs: now + 300_000, pausedRemainingMs: null, rungAtMs: null, createdAtMs: 1 };
const sooner = { ...running, id: 2, endsAtMs: now + 60_000 };
const paused = { ...running, id: 3, endsAtMs: null, pausedRemainingMs: 10_000 };
const rung = { ...running, id: 4, endsAtMs: now - 5000, rungAtMs: now - 5000 };
assert.equal(model.soonestRunningTimer([running, paused, rung, sooner], now)?.id, 2);
assert.equal(model.soonestRunningTimer([paused, rung], now), null);
});
test("tool arguments: times of day", () => {
assert.deepEqual(model.parseTimeOfDay("7:30"), { hour: 7, minute: 30 });
assert.deepEqual(model.parseTimeOfDay("7:30 pm"), { hour: 19, minute: 30 });
+166
View File
@@ -0,0 +1,166 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
const { TranslationModel } = loader()('app/apps/translate/translation-model.ts');
const { buildTranslateUserMessage } = loader()('app/prompts.ts');
// One character per pixel, so wrapping is predictable.
const measure = text => text.length;
// Values built inside the loader's sandbox have its prototypes; compare as plain data.
const plain = value => JSON.parse(JSON.stringify(value));
function settingsHarness({ main = 'onboard', setUp = [] } = {}) {
class Setting {
constructor(options) { Object.assign(this, options); this.value = options.defaultValue; }
get() { return this.value; }
set(value) { this.value = value; return value; }
displayValue(value = this.get()) { return this.formatValue ? this.formatValue(value) : String(value); }
}
const labels = { elevenlabs: 'ElevenLabs', whisper: 'OpenAI (Whisper)', soniox: 'Soniox', 'whisper-server': 'Whisper server' };
const available = new Set(setUp);
return loader({}, {
'../../ui/dashboard-settings': {
ConfigSettingEnum: Setting,
ConfigSettingBoolean: Setting,
voiceProviderSetting: {
get: () => main,
isDisabled: provider => !available.has(provider),
displayValue: provider => labels[provider] ?? provider,
},
},
})('app/apps/translate/translate-settings.ts');
}
test('finals become segments; finals arriving mid-translation merge into one pending segment', () => {
const model = new TranslationModel();
model.accept({ text: 'Hola, ¿qué', isFinal: false });
assert.equal(model.live, 'Hola, ¿qué');
model.accept({ text: 'Hola, ¿qué tal?', isFinal: true });
assert.equal(model.live, '');
const first = model.nextJob();
assert.equal(first.segment.source, 'Hola, ¿qué tal?');
assert.deepEqual(plain(first.context), []);
assert.equal(model.nextJob(), null, 'one request at a time');
model.accept({ text: 'Muy bien.', isFinal: true });
model.accept({ text: '', isFinal: true }); // an empty final with no partial adds nothing
model.accept({ text: 'Gracias.', isFinal: true });
assert.equal(model.segments.length, 2);
assert.equal(model.segments[1].source, 'Muy bien. Gracias.');
model.progress(first.segment, 'Hi, how');
assert.equal(first.segment.translation, 'Hi, how');
model.complete(first.segment, 'Hi, how are you?');
const second = model.nextJob();
assert.equal(second.segment.source, 'Muy bien. Gracias.');
assert.deepEqual(plain(second.context), [{ source: 'Hola, ¿qué tal?', translation: 'Hi, how are you?' }]);
model.complete(second.segment, 'Very well. Thanks.');
assert.equal(model.nextJob(), null);
});
test('an empty final keeps the live partial it replaces', () => {
const model = new TranslationModel();
model.accept({ text: 'Bonjour', isFinal: false });
model.accept({ text: '', isFinal: true });
assert.equal(model.segments[0].source, 'Bonjour');
});
test('context skips failed and dropped turns and stays bounded', () => {
const model = new TranslationModel();
const translate = (source, translation) => {
model.accept({ text: source, isFinal: true });
const job = model.nextJob();
if (translation === null) model.fail(job.segment);
else model.complete(job.segment, translation);
};
translate('uno', 'one');
translate('ruido', null);
translate('mmm', '');
for (let i = 0; i < 6; i++) translate(`frase ${i}`, `sentence ${i}`);
model.accept({ text: 'último', isFinal: true });
const { context } = model.nextJob();
assert.equal(context.length, 4);
assert.deepEqual(plain(context.at(-1)), { source: 'frase 5', translation: 'sentence 5' });
assert.ok(context.every(turn => turn.translation));
const long = new TranslationModel();
for (let i = 0; i < 3; i++) {
long.accept({ text: 'x'.repeat(500), isFinal: true });
long.complete(long.nextJob().segment, 'y'.repeat(500));
}
long.accept({ text: 'next', isFinal: true });
assert.equal(long.nextJob().context.length, 1, 'the newest turn is kept even when it alone is over the cap');
});
test('display lines: translations bright, originals dim until translated or when shown, live dimmest', () => {
const model = new TranslationModel();
model.accept({ text: 'Guten Morgen', isFinal: true });
model.complete(model.nextJob().segment, 'Good morning');
model.accept({ text: 'Wie geht es?', isFinal: true });
const asking = model.nextJob().segment;
model.accept({ text: 'Danke', isFinal: false });
assert.deepEqual(plain(model.lines(measure, 100, false)), [
{ text: 'Good morning', gray: 230 },
{ text: 'Wie geht es?', gray: 120 },
{ text: 'Danke', gray: 90 },
]);
model.progress(asking, 'How are');
assert.deepEqual(plain(model.lines(measure, 100, false).map(line => line.text)), ['Good morning', 'How are', 'Danke']);
assert.deepEqual(plain(model.lines(measure, 100, true).map(line => line.gray)), [120, 230, 120, 230, 90]);
assert.deepEqual(plain(model.lines(measure, 7, false).slice(0, 2)), [{ text: 'Good', gray: 230 }, { text: 'morning', gray: 230 }]);
// A failed segment keeps its original on screen.
model.fail(asking);
assert.deepEqual(plain(model.lines(measure, 100, false)[1]), { text: 'Wie geht es?', gray: 120 });
// A finished, empty translation is noise: hidden unless originals are shown.
model.accept({ text: 'mmm', isFinal: true });
model.complete(model.nextJob().segment, '');
assert.equal(model.lines(measure, 100, false).some(line => line.text === 'mmm'), false);
assert.equal(model.lines(measure, 100, true).some(line => line.text === 'mmm'), true);
});
test('saved text pairs each original with its translation', () => {
const model = new TranslationModel();
for (const [source, translation] of [['Ciao', 'Hello'], ['Okay.', 'Okay.'], ['boh', null]]) {
model.accept({ text: source, isFinal: true });
const job = model.nextJob();
if (translation === null) model.fail(job.segment);
else model.complete(job.segment, translation);
}
assert.equal(model.savedText(), 'Ciao\n→ Hello\n\nOkay.\n\nboh\n→ (not translated)');
});
test('the user message carries earlier turns as context, then the speech', () => {
assert.equal(buildTranslateUserMessage('Hola', []), 'Translate this speech into English:\n<speech>Hola</speech>');
const message = buildTranslateUserMessage('¿Y tú?', [{ source: 'Bien', translation: 'Fine' }]);
assert.match(message, /context only/);
assert.match(message, /<speech>Bien<\/speech>\n<english>Fine<\/english>\n\nTranslate this speech/);
assert.ok(message.endsWith('<speech>¿Y tú?</speech>'));
});
test('Auto picks the main provider when it is multilingual, else the first one set up', () => {
let settings = settingsHarness({ main: 'soniox', setUp: ['elevenlabs', 'soniox'] });
assert.equal(settings.resolveTranslateProvider(), 'soniox');
assert.equal(settings.translateProviderSetting.displayValue('auto'), 'Auto (Soniox)');
settings = settingsHarness({ main: 'onboard', setUp: ['soniox', 'whisper'] });
assert.equal(settings.resolveTranslateProvider(), 'whisper');
// The main provider counts only when it is set up.
settings = settingsHarness({ main: 'elevenlabs', setUp: ['soniox'] });
assert.equal(settings.resolveTranslateProvider(), 'soniox');
settings = settingsHarness({ main: 'onboard', setUp: [] });
assert.equal(settings.resolveTranslateProvider(), null);
assert.equal(settings.translateProviderSetting.displayValue('auto'), 'Auto (none set up)');
});
test('an explicit provider is used only while it is set up, and on-device ones are never offered', () => {
const settings = settingsHarness({ main: 'soniox', setUp: ['soniox', 'whisper-server'] });
assert.equal(settings.resolveTranslateProvider('whisper-server'), 'whisper-server');
assert.equal(settings.resolveTranslateProvider('elevenlabs'), null);
assert.equal(settings.translateProviderSetting.isDisabled('elevenlabs'), true);
assert.equal(settings.translateProviderSetting.isDisabled('auto'), false);
assert.deepEqual(plain(settings.translateProviderSetting.values), ['auto', 'elevenlabs', 'whisper', 'soniox', 'whisper-server']);
});
+8 -1
View File
@@ -35,6 +35,7 @@
"../app/g2/glasses-display-state.ts",
"../app/g2/glance-state.ts",
"../app/ui/shell/notification-modal-queue.ts",
"../app/ui/shell/notification-popup-delay.ts",
"../app/apps/glanceboard/layout.ts",
"../app/apps/files/video-layout.ts",
"../app/g2/pairing-candidates.ts",
@@ -44,12 +45,17 @@
"../app/apps/microphones/sentiment.ts",
"../app/apps/microphones/dsp.ts",
"../app/apps/microphones/radar-dots.ts",
"../app/apps/microphones/caption-clock.ts",
"../app/apps/microphones/name-guess.ts",
"../app/apps/evenhub/containers.ts",
"../app/apps/evenhub/list-menu.ts",
"../app/apps/evenhub/device-status.ts",
"../app/apps/evenhub/font-spec.ts",
"../app/apps/evenhub/window-icon.ts",
"../app/apps/timer/timer-model.ts",
"../app/apps/teleprompter/script-tracker.ts",
"../app/apps/nightscout/nightscout-alerts.ts",
"../app/apps/nightscout/missed-bolus-detector.ts",
"../app/health/health-types.ts",
"../app/health/health-derive.ts",
"../app/health/health-store.ts",
@@ -68,6 +74,7 @@
"../app/apps/t3code/t3-auth.ts",
"../app/apps/t3code/t3-client.ts",
"../app/apps/t3code/t3-transcript.ts",
"../app/apps/t3code/t3-glance.ts"
"../app/apps/t3code/t3-glance.ts",
"../app/apps/t3code/t3-launch.ts"
]
}
+36 -13
View File
@@ -157,25 +157,30 @@ test('cloud fallback and a synchronous final still send exactly once', () => {
}
});
test('native completion is capture-specific, follows the final, and does not wait for shared capture', async () => {
let controller;
class Controller {
constructor() { controller = this; }
setListener(listener) { this.listener = listener; }
setCommunicator() {} setUsePhoneMic() {} setSaveRecordings() {} setEndpointing() {}
setNoiseSuppression() {} setBeamFilter() {} clearSpeakerVerification() {} setOnboardModelKind() {}
start(_mode, id) { this.captureId = id; this.active = true; }
stop() { this.active = false; }
isCapturing() { return this.active; }
}
/** The Android voice bridge over a fake native controller (on-device recognition only). */
function androidBridge() {
const controller = {
starts: 0,
setListener(listener) { this.listener = listener; },
setCommunicator() {}, setUsePhoneMic() {}, setSaveRecordings() {}, setEndpointing() {},
setNoiseSuppression() {}, setBeamFilter() {}, clearSpeakerVerification() {}, setOnboardModelKind() {},
start(_mode, id) { this.captureId = id; this.active = true; this.starts++; },
stop() { this.active = false; },
isCapturing() { return this.active; },
};
const { FaceclawVoiceControlBridge } = load('app/native/voice-control.ts', {
'@nativescript/core': { Utils: { android: { getApplicationContext: () => ({}) } } },
'./speech-pause': { SpeechPauseDetector: class { reset() {} } },
'./cloud-stt-provider': { createCloudSttClient: () => null, transcriptionKey: options => options.provider },
}, { global: { isAndroid: true }, com: { faceclaw: { app: {
FaceclawVoiceController: Controller,
FaceclawVoiceController: function () { return controller; },
FaceclawVoiceControllerListener: function (listener) { return listener; },
} } } });
const bridge = new FaceclawVoiceControlBridge();
return { bridge: new FaceclawVoiceControlBridge(), controller };
}
test('native completion is capture-specific, follows the final, and does not wait for shared capture', async () => {
const { bridge, controller } = androidBridge();
const options = { provider: 'onboard-whisper' };
const events = [];
bridge.onTranscript(event => events.push(event.text));
@@ -192,3 +197,21 @@ test('native completion is capture-specific, follows the final, and does not wai
assert.equal(controller.active, true);
bridge.stopContinuousCapture(); controller.listener.onStopped(controller.captureId);
});
test('a shared capture restarts for a holder that needs another provider, and is shared otherwise', () => {
const { bridge, controller } = androidBridge();
bridge.retargetContinuousCapture({ provider: 'soniox' }); // nothing continuous to retarget
assert.equal(controller.starts, 0);
bridge.startPushToTalk({ provider: 'onboard' });
bridge.startContinuousCapture({ provider: 'onboard' });
assert.equal(controller.starts, 1);
bridge.retargetContinuousCapture({ provider: 'soniox' });
assert.equal(controller.starts, 2);
bridge.retargetContinuousCapture({ provider: 'soniox' });
bridge.startPushToTalk({ provider: 'soniox' });
assert.equal(controller.starts, 2);
// Push-to-talk still holds the restarted stream once continuous lets go.
bridge.stopContinuousCapture();
assert.equal(controller.active, true);
assert.equal(bridge.holdsCapture('ptt'), true);
});
+19
View File
@@ -0,0 +1,19 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
test('the WAV header describes 16 kHz mono PCM16 and its data size', () => {
const { wavHeader } = loader({ DataView }, {})('app/native/wav-header.ts');
const header = Buffer.from(wavHeader(32000));
assert.equal(header.length, 44);
assert.equal(header.toString('ascii', 0, 4), 'RIFF');
assert.equal(header.readUInt32LE(4), 36 + 32000);
assert.equal(header.toString('ascii', 8, 16), 'WAVEfmt ');
assert.equal(header.readUInt16LE(20), 1);
assert.equal(header.readUInt16LE(22), 1);
assert.equal(header.readUInt32LE(24), 16000);
assert.equal(header.readUInt32LE(28), 32000);
assert.equal(header.readUInt16LE(34), 16);
assert.equal(header.toString('ascii', 36, 40), 'data');
assert.equal(header.readUInt32LE(40), 32000);
});
+133 -5
View File
@@ -5,22 +5,33 @@ const { loader } = require('./helpers/load-typescript.cjs');
const HOUR_MS = 60 * 60 * 1000;
const fix = { latitude: 37.7, longitude: -122.4, accuracyMeters: 8, timestampMs: 1234 };
/** weather.ts with fake timers, settings store and NWS responses. */
function weatherHarness({ periods, observation = null, store = new Map(), permission = () => true }) {
/**
* weather.ts with fake timers, settings store and NWS responses. Without
* NWS periods, the NWS point lookup 404s and openMeteo answers instead.
* nowMs, if given, fixes the module's clock.
*/
function weatherHarness({
periods, observation = null, openMeteo = null, place = null, store = new Map(), permission = () => true, nowMs,
}) {
const timers = new Map(), requests = [];
let nextTimer = 1;
const api = loader({
setTimeout: (fn, ms) => { const id = nextTimer++; timers.set(id, { fn: () => { timers.delete(id); fn(); }, ms }); return id; },
clearTimeout: id => timers.delete(id),
...(nowMs === undefined ? {} : { Date: class extends Date { static now() { return nowMs; } } }),
}, {
'./location-permissions': { hasLocationPermission: permission },
'./location': { getCurrentLocation: async () => fix },
'./reverse-geocode': { reverseGeocode: async () => place },
'./settings-store': { getStringSetting: (key, fallback) => store.get(key) ?? fallback, setStringSetting: (key, value) => store.set(key, value) },
'../version': { USER_AGENT: 'test' },
'../util/http': { fetchWithUserAgent: async url => {
requests.push(url);
let body;
if (url.includes('/points/')) {
if (url.startsWith('https://api.open-meteo.com/')) {
body = openMeteo;
} else if (url.includes('/points/')) {
if (!periods) return { ok: false, status: 404 };
body = { properties: {
forecast: 'https://fixture/forecast',
observationStations: observation ? 'https://fixture/stations' : undefined,
@@ -46,6 +57,27 @@ function weatherHarness({ periods, observation = null, store = new Map(), permis
const sunny = { name: 'Today', temperature: 70, temperatureUnit: 'F', shortForecast: 'Sunny', isDaytime: true };
/**
* An Open-Meteo answer (Fahrenheit, mph, unix seconds) whose hourly
* forecast starts at local midnight today, with hourly values from
* hour(index) (all fields optional).
*/
function openMeteoResponse({ offsetHours = 0, nowMs = Date.now(), hours = 192, hour = () => ({}), current = {} } = {}) {
const offsetMs = offsetHours * HOUR_MS;
const midnightMs = Math.floor((nowMs + offsetMs) / (24 * HOUR_MS)) * 24 * HOUR_MS - offsetMs;
const hourly = { time: [], temperature_2m: [], precipitation_probability: [], weather_code: [], wind_speed_10m: [], wind_direction_10m: [] };
for (let index = 0; index < hours; index++) {
const values = { temperature_2m: 60, precipitation_probability: 0, weather_code: 0, wind_speed_10m: 5, wind_direction_10m: 180, ...hour(index) };
hourly.time.push((midnightMs + index * HOUR_MS) / 1000);
for (const key of Object.keys(values)) hourly[key].push(values[key]);
}
return {
utc_offset_seconds: offsetHours * 3600,
current: { time: Math.floor(nowMs / 1000), temperature_2m: 64.2, relative_humidity_2m: 94, is_day: 1, weather_code: 2, wind_speed_10m: 2.7, wind_direction_10m: 292, ...current },
hourly,
};
}
test('Weather takes the condition from the NWS icon, falling back to the text', async () => {
const h = weatherHarness({
periods: [
@@ -128,11 +160,97 @@ test('Weather refreshes a stale cache at once and backs off after a failure', as
assert.ok(retry > 9 * 60_000 && retry <= 10 * 60_000, `retry delay ${retry}`);
});
test('Weather outside NWS coverage falls back to Open-Meteo and names the place with the geocoder', async () => {
const h = weatherHarness({
openMeteo: openMeteoResponse({ offsetHours: 10 }),
place: { locality: 'Sydney', region: 'New South Wales', country: 'Australia' },
});
const bridge = new h.api.WeatherBridge();
await bridge.refreshNow();
const state = bridge.snapshot();
assert.equal(state.phase, 'ready', state.status);
assert.equal(state.source, 'open-meteo');
assert.equal(state.locationName, 'Sydney, Australia');
assert.equal(h.requests.length, 2, 'one NWS point lookup, then one Open-Meteo request');
assert.match(h.requests[1], /latitude=37\.7000&longitude=-122\.4000/);
assert.match(h.requests[1], /temperature_unit=fahrenheit/);
assert.deepEqual({ ...state.current, timestampMs: null }, {
temperatureF: 64.2, description: 'Partly Cloudy', humidityPercent: 94, windSpeedMph: 2.7, windDirection: 'W',
timestampMs: null, observed: false, condition: 'partly-cloudy', isDaytime: true,
});
assert.equal(state.forecast.length, 14);
// The source survives a restart; a geocoder with nothing to say leaves the coordinates.
const restarted = new (weatherHarness({ openMeteo: openMeteoResponse(), store: h.store }).api.WeatherBridge)();
assert.equal(restarted.snapshot().source, 'open-meteo');
const unnamed = weatherHarness({ openMeteo: openMeteoResponse() });
const unnamedBridge = new unnamed.api.WeatherBridge();
await unnamedBridge.refreshNow();
assert.equal(unnamedBridge.snapshot().locationName, '37.7000, -122.4000');
});
test('Open-Meteo hours group into NWS-style day and night periods in local time', async () => {
// 3pm local, so the first period is the rest of today.
const offsetHours = -5;
const dayMs = 24 * HOUR_MS;
const nowMs = Math.floor(Date.now() / dayMs) * dayMs + (15 - offsetHours) * HOUR_MS;
const h = weatherHarness({
nowMs,
openMeteo: openMeteoResponse({
offsetHours, nowMs,
hour: index => ({
// Peaks at 80 at 1pm and bottoms out at 20 at 1am; rain tomorrow
// 3pm-5pm, then one stray hour of thunder; a windy 3am tonight.
temperature_2m: 50 + 30 * Math.sin(((index % 24) - 7) / 24 * 2 * Math.PI),
precipitation_probability: index === 24 + 15 ? 80 : 10,
weather_code: { [24 + 15]: 63, [24 + 16]: 63, [24 + 20]: 95 }[index] ?? 1,
wind_speed_10m: index === 24 + 3 ? 30 : 5,
wind_direction_10m: index === 24 + 3 ? 90 : 180,
}),
}),
place: { locality: '', region: 'Ontario', country: 'Canada' },
});
const bridge = new h.api.WeatherBridge();
await bridge.refreshNow();
const { forecast, locationName } = bridge.snapshot();
assert.equal(locationName, 'Ontario, Canada');
const weekday = days => ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][
new Date(nowMs + offsetHours * HOUR_MS + days * dayMs).getUTCDay()];
assert.deepEqual(Array.from(forecast.slice(0, 4), period => period.name), ['Today', 'Tonight', weekday(1), `${weekday(1)} Night`]);
assert.deepEqual(Array.from(forecast, period => period.isDaytime), Array.from({ length: 14 }, (_, index) => index % 2 === 0));
// Today is only 3pm-6pm, past its 1pm peak.
assert.equal(forecast[0].startTimeMs, nowMs);
assert.equal(Math.round(forecast[0].temperatureF), 76);
// Tonight runs to 6am and takes its low and its strongest wind.
assert.equal(Math.round(forecast[1].temperatureF), 20);
assert.equal(forecast[1].windSpeed, '30 mph');
assert.equal(forecast[1].windDirection, 'E');
// Tomorrow takes its most severe lasting code and its highest chance of rain.
assert.equal(Math.round(forecast[2].temperatureF), 80);
assert.equal(forecast[2].shortForecast, 'Rain');
assert.equal(forecast[2].condition, 'rain');
assert.equal(forecast[2].precipitationPercent, 80);
// One hour of thunder doesn't name tomorrow night.
assert.equal(forecast[3].shortForecast, 'Mostly Clear');
assert.equal(forecast[3].condition, 'partly-cloudy');
});
test('Open-Meteo after midnight starts with the rest of last night', async () => {
const dayMs = 24 * HOUR_MS;
const nowMs = Math.floor(Date.now() / dayMs) * dayMs + 2 * HOUR_MS;
const h = weatherHarness({ nowMs, openMeteo: openMeteoResponse({ nowMs }) });
const bridge = new h.api.WeatherBridge();
await bridge.refreshNow();
assert.deepEqual(Array.from(bridge.snapshot().forecast.slice(0, 3), period => period.name), ['Overnight', 'Today', 'Tonight']);
});
/** weather-indicators.ts with a fake shell, settings and bridge. */
function indicatorHarness() {
const settings = new Map(), settingListeners = new Set(), stateListeners = new Set(), trays = [];
const background = [];
let state = { phase: 'ready', current: null, forecast: [], lastUpdatedMs: null };
let systemCardInUse = false;
class GrayImage {
constructor(width, height) { this.width = width; this.height = height; this.draws = []; }
drawImage(_source, x, y) { this.draws.push(['image', x, y]); }
@@ -155,13 +273,16 @@ function indicatorHarness() {
} },
'../../ui/dashboard-settings': {
ConfigSettingBoolean: Setting,
temperatureUnitSetting: new Setting({ storageKey: 'display.temperatureUnit', defaultValue: 'fahrenheit' }),
onAnySettingChanged: listener => { settingListeners.add(listener); return () => settingListeners.delete(listener); },
},
'../../ui/shell/shell': { shell: { setTrayIcon: (id, icon) => trays.push([id, icon]) } },
'../glanceboard/configuration': { isSystemCardWidgetInUse: () => systemCardInUse },
})('app/apps/weather/weather-indicators.ts');
return {
api, trays, background,
setSetting(key, value) { settings.set(key, value); for (const listener of settingListeners) listener(); },
setSystemCardInUse(value) { systemCardInUse = value; for (const listener of settingListeners) listener(); },
setState(next) { state = next; for (const listener of stateListeners) listener(state); },
};
}
@@ -169,12 +290,16 @@ function indicatorHarness() {
test('Weather tray icon follows the status-bar setting and hides a stale reading', () => {
const h = indicatorHarness();
h.api.startWeatherIndicators();
assert.deepEqual(h.background, [false]);
assert.deepEqual(h.background, [false], 'system-card weather is on by default, but no system card is showing');
assert.equal(h.trays.length, 0, 'nothing shown, nothing to clear');
h.setSetting('weather.showOnSystemCard', true);
h.setSystemCardInUse(true);
assert.equal(h.background.at(-1), true, 'the system card alone keeps refreshes running');
assert.equal(h.trays.length, 0);
h.setSetting('weather.showOnSystemCard', false);
assert.equal(h.background.at(-1), false, 'not with its weather turned off');
h.setSetting('weather.showOnSystemCard', true);
assert.equal(h.background.at(-1), true);
h.setSetting('weather.showInStatusBar', true);
const current = { temperatureF: 71.6, condition: 'rain', isDaytime: true };
@@ -184,6 +309,9 @@ test('Weather tray icon follows the status-bar setting and hides a stale reading
assert.equal(icon.height, 24);
assert.deepEqual(icon.draws.map(draw => draw[0]), ['image', 'text']);
assert.equal(icon.draws[1][3], '72°');
h.setSetting('display.temperatureUnit', 'celsius');
assert.equal(h.trays.at(-1)[1].draws[1][3], '22°', 'the temperature unit setting rebuilds the icon');
h.setSetting('display.temperatureUnit', 'fahrenheit');
// An unchanged reading does not rebuild the icon.
const count = h.trays.length;
+228
View File
@@ -0,0 +1,228 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
function load() {
const timers = [];
const modules = loader({
setTimeout(fn, delay) { timers.push({ fn, delay }); return timers.length; },
clearTimeout() {},
DataView, Math, Date, JSON, Object, String, Error, Promise,
}, {});
return { ...modules('app/native/whisper-server-stt.ts'), timers };
}
/** An http stub whose requests resolve only when the test says so. */
function server(models = '{"data":[{"id":"openai/whisper-large-v3"}]}') {
const requests = [];
const http = (request) => new Promise((resolve, reject) => {
if (request.method === 'GET') { requests.push({ ...request, kind: 'models' }); resolve({ status: 200, text: models }); return; }
requests.push({ ...request, kind: 'transcribe', resolve, reject, fields: fields(request.body) });
});
return { http, requests, posts: () => requests.filter(request => request.kind === 'transcribe') };
}
function fields(body) {
const text = Buffer.from(body).toString('latin1');
const out = {};
for (const match of text.matchAll(/name="([^"]+)"\r\n\r\n([^\r]*)\r\n/g)) out[match[1]] = match[2];
return out;
}
function client(config = {}, s = server()) {
const { WhisperServerSttClient, timers } = load();
const events = [], statuses = [], errors = [];
let ready = 0;
const c = new WhisperServerSttClient({
apiKey: config.apiKey ?? '', onTranscript: event => events.push({ ...event }), onStatus: status => statuses.push(status),
onError: error => errors.push(error), onReady: () => ready++, onDisconnected: message => errors.push(`disconnected: ${message}`),
}, { baseUrl: 'http://whisper-host:8004/v1', model: '', language: '', ...config }, s.http);
return { c, s, events, statuses, errors, timers, ready: () => ready };
}
const flush = () => new Promise(resolve => setImmediate(resolve));
function speech(ms, amplitude = 3000) {
const bytes = new Uint8Array(ms * 32);
for (let i = 0; i < bytes.length; i += 2) {
const sample = i % 4 ? amplitude : -amplitude;
bytes[i] = sample & 255; bytes[i + 1] = (sample >> 8) & 255;
}
return bytes;
}
test('URL normalization accepts a bare host, a /v1 root and the full endpoint', () => {
const { normalizeWhisperServerUrl } = load();
assert.equal(normalizeWhisperServerUrl('http://192.0.2.10:8004'), 'http://192.0.2.10:8004/v1');
assert.equal(normalizeWhisperServerUrl(' http://192.0.2.10:8004/v1/ '), 'http://192.0.2.10:8004/v1');
assert.equal(normalizeWhisperServerUrl('https://stt.example/v1/audio/transcriptions'), 'https://stt.example/v1');
assert.equal(normalizeWhisperServerUrl('192.0.2.10:8004'), '');
assert.equal(normalizeWhisperServerUrl(''), '');
});
test('the WAV header describes 16 kHz mono PCM16 and the multipart body carries the fields', () => {
const { wavFile, multipartBody } = load();
const wav = wavFile([new Uint8Array([1, 2, 3, 4]), new Uint8Array([5, 6])], 6);
const view = Buffer.from(wav);
assert.equal(view.toString('ascii', 0, 4), 'RIFF');
assert.equal(view.readUInt32LE(24), 16000);
assert.equal(view.readUInt16LE(22), 1);
assert.equal(view.readUInt32LE(40), 6);
assert.deepEqual([...wav.subarray(44)], [1, 2, 3, 4, 5, 6]);
const body = Buffer.from(multipartBody('B', { model: 'm', language: 'sk' }, wav)).toString('latin1');
assert.match(body, /^--B\r\nContent-Disposition: form-data; name="model"\r\n\r\nm\r\n/);
assert.match(body, /name="file"; filename="audio.wav"\r\nContent-Type: audio\/wav\r\n\r\nRIFF/);
assert.ok(body.endsWith('\r\n--B--\r\n'));
});
test('start lists models, picks the first id, and push-to-talk delivers one final', async () => {
const h = client();
h.c.start(); await flush();
assert.equal(h.ready(), 1);
assert.equal(h.s.requests[0].url, 'http://whisper-host:8004/v1/models');
h.c.acceptPcm(speech(500));
h.c.finish();
const [post] = h.s.posts();
assert.equal(post.url, 'http://whisper-host:8004/v1/audio/transcriptions');
assert.equal(post.fields.model, 'openai/whisper-large-v3');
assert.equal(post.fields.response_format, 'json');
assert.equal('language' in post.fields, false, 'empty language lets Whisper auto-detect');
assert.equal(post.headers.Authorization, undefined);
post.resolve({ status: 200, text: '{"text":" Remind me to call the bank."}' }); await flush();
assert.deepEqual(h.events, [{ text: 'Remind me to call the bank.', isFinal: true, paragraphBreakAfter: false }]);
});
test('a configured model, language and key are sent as given', async () => {
const h = client({ model: 'whisper-1', language: 'SK', apiKey: 'secret' });
h.c.start(); await flush();
h.c.acceptPcm(speech(300)); h.c.finish();
const [post] = h.s.posts();
assert.equal(post.fields.model, 'whisper-1');
assert.equal(post.fields.language, 'sk');
assert.equal(post.headers.Authorization, 'Bearer secret');
});
test('silence is not sent (Whisper would invent text) but push-to-talk still gets an empty final', async () => {
const h = client();
h.c.start(); await flush();
h.c.acceptPcm(speech(2000, 40));
h.c.finish();
assert.equal(h.s.posts().length, 0);
assert.deepEqual(h.events, [{ text: '', isFinal: true, paragraphBreakAfter: false }]);
});
test('interim requests show provisional text and never overwrite the final', async () => {
const h = client();
h.c.start(); await flush();
h.c.acceptPcm(speech(1600));
const [interim] = h.s.posts();
assert.ok(interim, 'an interim request goes out once enough audio arrived');
h.c.acceptPcm(speech(1600));
assert.equal(h.s.posts().length, 1, 'one interim in flight at a time');
interim.resolve({ status: 200, text: '{"text":"hello"}' }); await flush();
assert.deepEqual(h.events.at(-1), { text: 'hello', transcribeText: 'hello', isFinal: false });
h.c.finish();
const final = h.s.posts().at(-1);
final.resolve({ status: 200, text: '{"text":"hello world"}' }); await flush();
assert.deepEqual(h.events.at(-1), { text: 'hello world', isFinal: true, paragraphBreakAfter: false });
});
test('continuous segments finalize in audio order even when answered out of order', async () => {
const h = client();
h.c.start(); await flush();
h.c.acceptPcm(speech(500)); h.c.commitSegment();
h.c.acceptPcm(speech(500)); h.c.commitSegment();
const [first, second] = h.s.posts();
second.resolve({ status: 200, text: '{"text":"second"}' }); await flush();
assert.deepEqual(h.events.map(event => event.isFinal), [false]);
assert.equal(h.events[0].text, 'second');
first.resolve({ status: 200, text: '{"text":"first"}' }); await flush();
assert.deepEqual(h.events.filter(event => event.isFinal).map(event => [event.text, event.paragraphBreakAfter]),
[['first', true], ['second', true]]);
});
/** Seconds of audio in a transcription request's WAV part. */
function postSeconds(post) {
const body = Buffer.from(post.body);
return body.readUInt32LE(body.indexOf('RIFF') + 40) / 32000;
}
test('nonstop speech is cut at its quietest moment into bounded requests that still leave as one final', async () => {
const h = client();
h.c.start(); await flush();
// 25 s of 50 ms chunks with no pause; chunk 440 (22 s in) is the quietest.
for (let i = 0; i < 500; i++) h.c.acceptPcm(speech(50, i === 440 ? 400 : 3000));
const [, head, tailInterim] = h.s.posts();
assert.equal(postSeconds(head), 22.05, 'the cut follows the quietest chunk');
assert.equal(postSeconds(tailInterim), 2.95, 'the audio after it carries over');
h.c.acceptPcm(speech(1000)); h.c.finish();
const tail = h.s.posts().at(-1);
assert.equal(postSeconds(tail), 3.95);
tail.resolve({ status: 200, text: '{"text":"and the rest."}' }); await flush();
assert.deepEqual(h.events.filter(event => event.isFinal), [], 'the tail waits for the head');
head.resolve({ status: 200, text: '{"text":"The long part"}' }); await flush();
assert.deepEqual(h.events.filter(event => event.isFinal),
[{ text: 'The long part and the rest.', isFinal: true, paragraphBreakAfter: false }]);
});
test('a cut with nothing after it yet ends at the next boundary', async () => {
const h = client();
h.c.start(); await flush();
for (let i = 0; i < 500; i++) h.c.acceptPcm(speech(50, i === 499 ? 400 : 3000));
const head = h.s.posts().at(-1);
assert.equal(postSeconds(head), 25);
head.resolve({ status: 200, text: '{"text":"All of it."}' }); await flush();
assert.deepEqual(h.events.filter(event => event.isFinal), []);
h.c.commitSegment();
assert.deepEqual(h.events.filter(event => event.isFinal), [{ text: 'All of it.', isFinal: true, paragraphBreakAfter: true }]);
});
test('a failed final is retried once, then reported without ending the capture', async () => {
const h = client();
h.c.start(); await flush();
h.c.acceptPcm(speech(500)); h.c.commitSegment();
h.s.posts()[0].reject(new Error('timed out')); await flush();
assert.equal(h.timers.at(-1).delay, 750);
h.timers.at(-1).fn();
h.s.posts()[1].resolve({ status: 502, text: 'bad gateway' }); await flush();
assert.match(h.statuses.at(-1), /Whisper server request failed: HTTP 502/);
assert.deepEqual(h.errors, []);
h.c.acceptPcm(speech(500)); h.c.finish();
h.s.posts()[2].resolve({ status: 200, text: '{"text":"still here"}' }); await flush();
assert.equal(h.events.at(-1).text, 'still here');
});
test('an auth rejection is an error, an unreachable server is a disconnect', async () => {
const auth = client();
auth.c.start(); await flush();
auth.c.acceptPcm(speech(500)); auth.c.finish();
auth.s.posts()[0].resolve({ status: 401, text: '' }); await flush();
assert.deepEqual(auth.errors, ['Whisper server rejected the key (401).']);
const down = client({}, { http: () => Promise.reject(new Error('connection refused')) });
down.c.start(); await flush();
assert.equal(down.ready(), 0);
assert.deepEqual(down.errors, ['disconnected: Whisper server unreachable: connection refused']);
});
test('provider selection needs a URL, not a key, and passes the server settings through', () => {
const sockets = [];
const modules = loader({
setTimeout() {}, clearTimeout() {}, console: { log() {}, warn() {} }, DataView,
com: { faceclaw: { app: {
FaceclawWebSocketListener: function(callbacks) { return callbacks; },
FaceclawWebSocket: class { constructor(url) { sockets.push(url); } },
} } },
}, { './cloud-stt': { CLOUD_STT_SAMPLE_RATE: 16000, encodeBase64: () => '', toJavaBytes: bytes => bytes } });
const { createCloudSttClient, usesCloudStt } = modules('app/native/cloud-stt-provider.ts');
const statuses = [];
const options = { onTranscript() {}, onStatus: status => statuses.push(status), onError() {} };
const selection = { provider: 'whisper-server', elevenLabsApiKey: '', openAiApiKey: '', sonioxApiKey: '' };
assert.equal(usesCloudStt(selection), false);
assert.equal(createCloudSttClient(selection, options, () => false), null);
assert.deepEqual(statuses, ['No Whisper server URL set; using on-device voice.']);
const configured = { ...selection, whisperServerUrl: 'http://192.0.2.10:8004' };
assert.equal(usesCloudStt(configured), true);
const client = createCloudSttClient(configured, options, () => false);
assert.ok(client.finalTimeoutMs > 5000, 'batch requests get longer than the 5s realtime default');
assert.equal(sockets.length, 0);
});