test(#717): pin the frame budget per platform, so this cannot regress silently
One getter decides the composer's byte budget on every platform, and it had collapsed that budget to zero on three of them before anyone noticed: Windows (#686), Linux (#717) and Web (#718). Each surfaced as a user reporting "the keyboard doesn't respond", two months and three platforms apart. Nothing exercised the getter, so nothing went red. Extracts the decision into `MeshCoreConnector.resolveFrameBudget`, a pure function of (transport, isWeb, mtuNow). The getter is now a one-line delegate and behaves identically. This is what makes the web branch testable at all: `kIsWeb` is a compile-time constant, so a VM test could never enter it and CI runs the suite on the VM only. 19 new cases, covering what we now know rather than what we guessed: - wired transports are never floored, and ignore a bogus MTU - web is exempt from the floor, and both composers stay usable at MTU 23 - native BLE keeps the #395 write-safety floor: unknown MTU yields 20, never the full frame, because defaulting an unknown link to the largest size would authorize an oversized write - the MTUs actually measured on hardware (Android 247, Windows 176) leave a usable channel composer - the original failure stays reproducible: an unreported MTU still gives a 0-byte channel budget and 4 bytes for a DM, the two numbers users reported Also adds widget tests for the #684 notice, including the disconnect case the pre-PR review caught, and the severity split between a zero and a small budget. analyze clean, 981 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>fix/717-linux-web-mtu
parent
91f3cdfa3b
commit
2aea299f65
@ -0,0 +1,133 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
|
||||
/// Regression lock for the frame budget, per platform.
|
||||
///
|
||||
/// This one getter decides the composer's byte budget everywhere, and it had
|
||||
/// collapsed that budget to zero on three of the five platforms before anyone
|
||||
/// noticed, each time surfacing as a user reporting "the keyboard doesn't
|
||||
/// respond":
|
||||
///
|
||||
/// Windows (#686) - the WinRT plugin never created a GattSession, so no MTU
|
||||
/// was ever reported and mtuNow stayed on its 23 default.
|
||||
/// Linux (#717) - the plugin's onMtuChanged returned Stream.empty().
|
||||
/// Web (#718) - Web Bluetooth exposes no MTU at all, so the BLE floor
|
||||
/// applied forever.
|
||||
///
|
||||
/// None of those were caught by a test, because nothing exercised this
|
||||
/// function. They were caught by users, two months and three platforms apart.
|
||||
/// These cases exist so a regression is a red build instead of a bug report.
|
||||
int _budget({
|
||||
MeshCoreTransportType transport = MeshCoreTransportType.bluetooth,
|
||||
bool isWeb = false,
|
||||
int mtuNow = 0,
|
||||
}) => MeshCoreConnector.resolveFrameBudget(
|
||||
transport: transport,
|
||||
isWeb: isWeb,
|
||||
mtuNow: mtuNow,
|
||||
);
|
||||
|
||||
void main() {
|
||||
group('non-BLE transports are never floored', () {
|
||||
test('usb gets the full frame', () {
|
||||
expect(_budget(transport: MeshCoreTransportType.usb), maxFrameSize);
|
||||
});
|
||||
|
||||
test('tcp gets the full frame', () {
|
||||
expect(_budget(transport: MeshCoreTransportType.tcp), maxFrameSize);
|
||||
});
|
||||
|
||||
test('a wired transport ignores a bogus MTU entirely', () {
|
||||
expect(
|
||||
_budget(transport: MeshCoreTransportType.usb, mtuNow: 23),
|
||||
maxFrameSize,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('web BLE is exempt from the floor (#718)', () {
|
||||
// The branch that cannot be reached any other way: kIsWeb is a
|
||||
// compile-time constant, so without the pure function this is untestable.
|
||||
test('web gets the full frame even with no MTU reported', () {
|
||||
expect(_budget(isWeb: true, mtuNow: 0), maxFrameSize);
|
||||
});
|
||||
|
||||
test('web gets the full frame even at the 23-byte ATT default', () {
|
||||
expect(_budget(isWeb: true, mtuNow: 23), maxFrameSize);
|
||||
});
|
||||
|
||||
test('a web budget leaves BOTH composers usable', () {
|
||||
// The actual regression: this is what was 0 before #718.
|
||||
final budget = _budget(isWeb: true, mtuNow: 23);
|
||||
expect(
|
||||
isComposerBudgetUsable(
|
||||
maxChannelMessageBytes('KB9QDI-JOE', maxFrameBytes: budget),
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
isComposerBudgetUsable(maxContactMessageBytes(maxFrameBytes: budget)),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('native BLE keeps the write-safety floor (#395)', () {
|
||||
test('no device reported yields the floor, never the full frame', () {
|
||||
// Must NOT be maxFrameSize: defaulting an unknown link to the largest
|
||||
// size would authorize an oversized write, which is what the floor is
|
||||
// for. The floor is correct here even though it is what made the
|
||||
// composer unusable; the fix was reporting the MTU, not removing this.
|
||||
expect(_budget(mtuNow: 0), 20);
|
||||
});
|
||||
|
||||
test('the 23-byte ATT minimum yields the floor', () {
|
||||
expect(_budget(mtuNow: 23), 20);
|
||||
});
|
||||
|
||||
test('a negotiated MTU is honoured minus the 3-byte ATT header', () {
|
||||
expect(_budget(mtuNow: 100), 97);
|
||||
});
|
||||
|
||||
test('a large MTU is capped at the frame size', () {
|
||||
expect(_budget(mtuNow: 517), maxFrameSize);
|
||||
});
|
||||
|
||||
test('never returns below the floor for an absurdly small MTU', () {
|
||||
expect(_budget(mtuNow: 5), 20);
|
||||
});
|
||||
});
|
||||
|
||||
group('the MTUs actually measured on hardware leave the composer usable', () {
|
||||
// Pinning the real numbers, so a regression that silently reintroduces the
|
||||
// floor on a healthy link fails here rather than in someone's chat window.
|
||||
for (final probe in <({String platform, int mtu})>[
|
||||
(platform: 'Android', mtu: 247),
|
||||
(platform: 'Windows after #686', mtu: 176),
|
||||
]) {
|
||||
test('${probe.platform} (MTU ${probe.mtu})', () {
|
||||
final budget = _budget(mtuNow: probe.mtu);
|
||||
expect(budget, maxFrameSize);
|
||||
expect(
|
||||
isComposerBudgetUsable(
|
||||
maxChannelMessageBytes('KB9QDI-JOE', maxFrameBytes: budget),
|
||||
),
|
||||
isTrue,
|
||||
reason: 'a healthy link must leave a usable channel composer',
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
group('the exact failure users reported is still reproducible', () {
|
||||
test('an unreported MTU collapses the channel composer to zero', () {
|
||||
// Not a fix to preserve, a fact to keep visible: when the MTU is
|
||||
// genuinely unknown the budget IS unusable, which is why #684's guard
|
||||
// has to exist and why reporting the MTU was the real fix.
|
||||
final budget = _budget(mtuNow: 0);
|
||||
expect(maxChannelMessageBytes('KB9QDI-JOE', maxFrameBytes: budget), 0);
|
||||
expect(maxContactMessageBytes(maxFrameBytes: budget), 4);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,115 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/widgets/composer_budget_notice.dart';
|
||||
|
||||
/// #684: a composer whose byte budget has collapsed must say so, instead of
|
||||
/// presenting a field that silently rejects every keystroke (#592 was reported
|
||||
/// three times as "the keyboard doesn't respond"). Equally it must stay
|
||||
/// invisible the rest of the time, or it becomes noise that teaches people to
|
||||
/// ignore it.
|
||||
Widget _wrap(Widget child) => MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
|
||||
void main() {
|
||||
group('stays invisible when it should (#684)', () {
|
||||
testWidgets('healthy budget renders nothing', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
_wrap(
|
||||
const ComposerBudgetNotice(
|
||||
maxBytes: 148, // a channel composer on a 172-byte frame budget
|
||||
transport: MeshCoreTransportType.bluetooth,
|
||||
isConnected: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.error_outline), findsNothing);
|
||||
expect(find.byIcon(Icons.info_outline), findsNothing);
|
||||
expect(find.byType(Text), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('collapsed budget while DISCONNECTED renders nothing', (
|
||||
tester,
|
||||
) async {
|
||||
// The regression the pre-PR review caught. While disconnected the
|
||||
// transport still reads bluetooth and there is no device, so the budget
|
||||
// collapses to the same floor an unreported MTU produces. Without the
|
||||
// gate this banner appeared on every disconnect and blamed the link for
|
||||
// a small packet size when there was no link at all.
|
||||
await tester.pumpWidget(
|
||||
_wrap(
|
||||
const ComposerBudgetNotice(
|
||||
maxBytes: 0,
|
||||
transport: MeshCoreTransportType.bluetooth,
|
||||
isConnected: false,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.error_outline), findsNothing);
|
||||
expect(find.byType(Text), findsNothing);
|
||||
});
|
||||
});
|
||||
|
||||
group('explains itself when the budget has collapsed (#684)', () {
|
||||
testWidgets('zero budget reads as a failure, not a hint', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
_wrap(
|
||||
const ComposerBudgetNotice(
|
||||
maxBytes: 0,
|
||||
transport: MeshCoreTransportType.bluetooth,
|
||||
isConnected: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.error_outline), findsOneWidget);
|
||||
expect(find.byIcon(Icons.info_outline), findsNothing);
|
||||
// Names the cause in plain words rather than exposing byte arithmetic.
|
||||
expect(find.textContaining('Bluetooth'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a small but nonzero budget is stated, not alarmed about', (
|
||||
tester,
|
||||
) async {
|
||||
// 4 bytes is the measured DM budget at the unknown-MTU floor. The link
|
||||
// works, it is just tiny, so this must not render as an error.
|
||||
await tester.pumpWidget(
|
||||
_wrap(
|
||||
const ComposerBudgetNotice(
|
||||
maxBytes: 4,
|
||||
transport: MeshCoreTransportType.bluetooth,
|
||||
isConnected: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.info_outline), findsOneWidget);
|
||||
expect(find.byIcon(Icons.error_outline), findsNothing);
|
||||
// The actual number is surfaced so the user knows what they have.
|
||||
expect(find.textContaining('4'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a non-bluetooth transport does not blame Bluetooth', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
_wrap(
|
||||
const ComposerBudgetNotice(
|
||||
maxBytes: 0,
|
||||
transport: MeshCoreTransportType.usb,
|
||||
isConnected: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.error_outline), findsOneWidget);
|
||||
expect(find.textContaining('Bluetooth'), findsNothing);
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Reference in new issue