Fix BigInt serialization in GET /api/device (500 on real hardware) (#14)
CI / build + unit (push) Successful in 18s

This commit was merged in pull request #14.
This commit is contained in:
2026-09-24 23:14:32 +02:00
parent 4beaa377c4
commit ba5e60daf0
4 changed files with 51 additions and 5 deletions
+26
View File
@@ -718,6 +718,32 @@ describe('MeshService device info', () => {
}
});
it('serializes proto uint64 fields as strings (JSON-safe)', async () => {
const bridge = await startBridge();
process.env.MESH_HOST = '127.0.0.1';
process.env.MESH_PORT = String(bridge.port);
const svc = new MeshService();
try {
svc.onModuleInit();
await waitFor(
() => bridge.sockets.length === 1 && svc.status().connected,
);
// powermonEnables is a proto uint64 — protobuf-es decodes it as native bigint
bridge.sockets[0].write(
configSectionFrame('power', { powermonEnables: 123n }),
);
await waitFor(() => svc.deviceInfo().localConfig.power !== undefined);
const info = svc.deviceInfo();
expect(info.localConfig.power?.powermonEnables).toBe('123'); // bigint -> decimal string
expect(() => JSON.stringify(info)).not.toThrow(); // no "Do not know how to serialize a BigInt"
} finally {
svc.onModuleDestroy();
bridge.close();
}
});
it('summarizes NodeInfo snr/hopsAway/viaMqtt when present', async () => {
const bridge = await startBridge();
process.env.MESH_HOST = '127.0.0.1';