check / check (push) Canceled after 0s
The box within reach of the couch: a Raspberry Pi 3B with the AIY Voice HAT, from the first household's configuration, made generic. - box/body: the button service, in Python: press and talk, turns by voice, a press interrupts; the look signal - box/*.js: the ir and look capabilities, behind gates, for the brain; the ask client, the box's side of a conversation - box/module.nix: the services, each confined to the devices and addresses it needs; the private network as an option (a tailnet by default); the Pico found by its USB IDs, as /dev/pdtv26-ir - box/voicehat.nix: the Voice HAT's device tree overlay and ALSA setup - lib.mkBox: a box's whole system from its name, the home server's, the Wi-Fi network's, and who looks after it - checks: box-js, box-py (doctests and pyflakes), and box-system (an example box's system evaluates) Generated-by: Claude Opus 5.5
44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
// Tests for the look capability, with a fake camera and a fake button service.
|
|
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { Look } from './look.js';
|
|
|
|
const fakes = ({ signalFails = false, grabFails = false } = {}) => {
|
|
const log = [];
|
|
const signal = async () => {
|
|
if (signalFails) throw new Error('the button service is not listening');
|
|
log.push('flash');
|
|
return () => log.push('stop');
|
|
};
|
|
const grab = async () => {
|
|
log.push('grab');
|
|
if (grabFails) throw new Error('camera: 401');
|
|
return new Uint8Array([0xff, 0xd8, 0xff]);
|
|
};
|
|
return { log, look: new Look(signal, grab) };
|
|
};
|
|
|
|
test('a look is shown before the frame is taken, and stops after', async () => {
|
|
const { log, look } = fakes();
|
|
assert.equal(await look.look(), '/9j/');
|
|
assert.deepEqual(log, ['flash', 'grab', 'stop']);
|
|
});
|
|
|
|
test('no indication, no look', async () => {
|
|
const { log, look } = fakes({ signalFails: true });
|
|
await assert.rejects(look.look(), /not listening/);
|
|
assert.deepEqual(log, []);
|
|
});
|
|
|
|
test('the indication stops even when the camera fails', async () => {
|
|
const { log, look } = fakes({ grabFails: true });
|
|
await assert.rejects(look.look(), /401/);
|
|
assert.deepEqual(log, ['flash', 'grab', 'stop']);
|
|
});
|
|
|
|
test('one look at a time', async () => {
|
|
const { log, look } = fakes();
|
|
await Promise.all([look.look(), look.look()]);
|
|
assert.deepEqual(log, ['flash', 'grab', 'stop', 'flash', 'grab', 'stop']);
|
|
});
|