feat(#888): role-based CLI txt-type selection for remote CLI
F3/E3.1. When sending a CLI command to a remote peer, the message type is chosen by the contact's ROLE (owner ruling): a companion (chat) gets the upstream-1.18 command type (3); a repeater or room server keeps the universal CLI_DATA type (1) it has always used. Decided by role, not firmware version: a Contact carries no version, the user types the commands (passthrough), and a non-1.18 companion silently drops the command type (surfaced as no reply, #891). Adds txtTypeCliCommand (3) and cliTxtTypeForContactType(), and parameterizes buildSendCliCommandFrame with the txt type (default CLI_DATA, so the existing repeater path stays byte-identical). A later refinement could pin a peer's version via a `ver` probe on connect. Tests: the role mapping and the frame's type byte + command passthrough. Full suite green (1430); Gemini 2.5-pro review: one naming nit taken. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>epic/870-console-gating
parent
8017ce4baf
commit
0f0c34b054
@ -0,0 +1,65 @@
|
||||
// #888: role-based CLI txt-type selection for remote CLI.
|
||||
//
|
||||
// A companion (chat) gets the 1.18 command type; a repeater/room server gets
|
||||
// the universal CLI_DATA type. The user types the command, so the frame is a
|
||||
// passthrough: the type byte changes, the command does not.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
|
||||
void main() {
|
||||
group('cliTxtTypeForContactType (#888)', () {
|
||||
test('a companion gets the 1.18 command type', () {
|
||||
expect(cliTxtTypeForContactType(advTypeChat), txtTypeCliCommand);
|
||||
expect(txtTypeCliCommand, 3);
|
||||
});
|
||||
|
||||
test('a repeater keeps the universal CLI_DATA type', () {
|
||||
expect(cliTxtTypeForContactType(advTypeRepeater), txtTypeCliData);
|
||||
});
|
||||
|
||||
test('a room server keeps the universal CLI_DATA type', () {
|
||||
expect(cliTxtTypeForContactType(advTypeRoom), txtTypeCliData);
|
||||
});
|
||||
});
|
||||
|
||||
group('buildSendCliCommandFrame carries the chosen type (#888)', () {
|
||||
final pubKey = Uint8List.fromList(List<int>.generate(32, (i) => i));
|
||||
// [cmd][type][attempt][ts x4][pubKey x6][command][0]
|
||||
const int typeOffset = 1;
|
||||
const int commandOffset = 1 + 1 + 1 + 4 + 6;
|
||||
|
||||
test(
|
||||
'defaults to CLI_DATA, so the existing repeater path is unchanged',
|
||||
() {
|
||||
final frame = buildSendCliCommandFrame(pubKey, 'get radio');
|
||||
expect(frame[typeOffset], txtTypeCliData);
|
||||
},
|
||||
);
|
||||
|
||||
test('emits the command type when asked (companion path)', () {
|
||||
final frame = buildSendCliCommandFrame(
|
||||
pubKey,
|
||||
'get radio',
|
||||
txtType: txtTypeCliCommand,
|
||||
);
|
||||
expect(frame[typeOffset], txtTypeCliCommand);
|
||||
});
|
||||
|
||||
test('the command is passed through byte-identical regardless of type', () {
|
||||
const command = '0A|set tx 22';
|
||||
final frame = buildSendCliCommandFrame(
|
||||
pubKey,
|
||||
command,
|
||||
txtType: txtTypeCliCommand,
|
||||
);
|
||||
final written = ascii.decode(
|
||||
frame.sublist(commandOffset, commandOffset + command.length),
|
||||
);
|
||||
expect(written, command);
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Reference in new issue