mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 01:21:20 -04:00
uiuiui
This commit is contained in:
@@ -239,6 +239,11 @@ function createRosterLifecycle(deps) {
|
||||
cameraServo: record.meta?.cameraServo,
|
||||
audio: record.meta?.audio,
|
||||
horn: record.meta?.horn,
|
||||
// Generic peripheral metadata is already reduced by roverd to the fields
|
||||
// the browser needs: stable process-local IDs, display names, and ordered
|
||||
// controls. Preserve that order here instead of rebuilding the inventory,
|
||||
// because ESP32 registration order is also the driver's display order.
|
||||
peripherals: Array.isArray(record.meta?.peripherals) ? record.meta.peripherals : [],
|
||||
headlight: record.meta?.headlight
|
||||
? { ...record.meta.headlight, state: record.headlightState }
|
||||
: record.meta?.headlight,
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
// Rover Roster Lifecycle Tests
|
||||
// Purpose: Verifies that boot-discovered accessory metadata reaches the public rover roster unchanged.
|
||||
// Scope: Covers roster projection only; roverd remains responsible for validating and reducing device descriptions.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { createRosterLifecycle } = require('./rosterLifecycle');
|
||||
|
||||
function createRosterManager(meta) {
|
||||
const rovers = new Map([[
|
||||
meta.name,
|
||||
{
|
||||
id: meta.name,
|
||||
meta,
|
||||
batteryState: null,
|
||||
headlightState: null,
|
||||
laserState: null,
|
||||
locked: false,
|
||||
lockReason: null,
|
||||
lastSeen: 123,
|
||||
},
|
||||
]]);
|
||||
|
||||
return createRosterLifecycle({
|
||||
rovers,
|
||||
isPrivateRecord: () => false,
|
||||
isPrivateOpen: () => true,
|
||||
getPrivateSafety: () => ({}),
|
||||
});
|
||||
}
|
||||
|
||||
test('getRoster preserves peripheral and control registration order', () => {
|
||||
const peripherals = [
|
||||
{
|
||||
id: 'firmata-0',
|
||||
name: 'Camera arm',
|
||||
controls: [
|
||||
{ id: 'position', type: 'slider', name: 'Position', min: 0, max: 180 },
|
||||
{ id: 'action', type: 'button', name: 'Action', mode: 'momentary' },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'firmata-1',
|
||||
name: 'Lighting',
|
||||
controls: [
|
||||
{ id: 'brightness', type: 'number', name: 'Brightness', min: 0, max: 255 },
|
||||
],
|
||||
},
|
||||
];
|
||||
const manager = createRosterManager({ name: 'rover-one', peripherals });
|
||||
|
||||
const [entry] = manager.getRoster();
|
||||
|
||||
// Deep equality verifies both the public field set and array order. The
|
||||
// server must not alphabetize controls because their firmware order is a UI
|
||||
// contract rather than incidental transport ordering.
|
||||
assert.deepEqual(entry.peripherals, peripherals);
|
||||
});
|
||||
|
||||
test('getRoster supplies an empty peripheral inventory when none was advertised', () => {
|
||||
const manager = createRosterManager({ name: 'rover-one' });
|
||||
|
||||
const [entry] = manager.getRoster();
|
||||
|
||||
assert.deepEqual(entry.peripherals, []);
|
||||
});
|
||||
Reference in New Issue
Block a user