feat: pin sends to testowy channel (index 2), never primary (v0.1.3) (#5)
CI / build + unit (push) Successful in 36s

feat: pin sends to testowy channel (index 2), never primary (v0.1.3)
This commit was merged in pull request #5.
This commit is contained in:
2026-09-23 22:06:01 +02:00
parent 266aadf635
commit 3062f40899
7 changed files with 72 additions and 6 deletions
+54 -2
View File
@@ -1,9 +1,9 @@
import { create, toBinary } from '@bufbuild/protobuf';
import { create, fromBinary, toBinary } from '@bufbuild/protobuf';
import * as P from '@meshtastic/protobufs';
import * as net from 'node:net';
import type { AddressInfo } from 'node:net';
import { describe, expect, it } from 'vitest';
import { frame } from './codec.js';
import { extractFrames, frame } from './codec.js';
import { MeshService } from './mesh.service.js';
function startBridge(): Promise<{
@@ -116,3 +116,55 @@ describe('MeshService channel pipeline', () => {
}
});
});
describe('MeshService send', () => {
it('sends on the test channel (index 2) by default, never primary', async () => {
const bridge = await startBridge();
process.env.MESH_HOST = '127.0.0.1';
process.env.MESH_PORT = String(bridge.port);
delete process.env.MESH_SEND_CHANNEL; // default path: "testowy" (index 2)
const svc = new MeshService();
try {
svc.onModuleInit();
await waitFor(
() => bridge.sockets.length === 1 && svc.status().connected,
);
const out: Uint8Array[] = [];
bridge.sockets[0].on('data', (c) => out.push(c));
const id = await svc.sendText(42, 'hello testowy');
expect(id).toBeGreaterThan(0);
const readOutbound = (): P.Mesh.MeshPacket | undefined => {
const merged = new Uint8Array(out.reduce((n, c) => n + c.length, 0));
let off = 0;
for (const c of out) {
merged.set(c, off);
off += c.length;
}
const { packets } = extractFrames(merged);
if (!packets.length) return undefined;
const tr = fromBinary(P.Mesh.ToRadioSchema, packets[0]);
return tr.payloadVariant?.case === 'packet'
? tr.payloadVariant.value
: undefined;
};
await waitFor(() => readOutbound() !== undefined);
const pkt = readOutbound()!;
expect(pkt.channel).toBe(2); // "testowy" — never the primary channel (0)
expect(pkt.to).toBe(42);
const decoded =
pkt.payloadVariant?.case === 'decoded'
? pkt.payloadVariant.value
: undefined;
expect(
new TextDecoder().decode(decoded?.payload ?? new Uint8Array()),
).toBe('hello testowy');
} finally {
delete process.env.MESH_SEND_CHANNEL;
svc.onModuleDestroy();
bridge.close();
}
});
});