Merge commit '42cb6a6f2d0de09a5851b31ef1b866c876a32337' into pipelines/run-20261111-0141-perf-window-moves-do-not-rebuild-content-b294

This commit is contained in:
2026-11-11 02:15:50 +00:00
26 changed files with 468 additions and 801 deletions
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -15,7 +14,7 @@ void main() {
final navigator = GlobalKey<NavigatorState>();
Future<JsonMap>? pending;
Future<void> pump(WidgetTester tester, {bool cupertino = false}) async {
Future<void> pump(WidgetTester tester) async {
machine = FakeMachine();
gateway = ElevatingGateway(
machine,
@@ -35,12 +34,10 @@ void main() {
),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(navigatorKey: navigator, home: home)
: MaterialApp(
navigatorKey: navigator,
home: Scaffold(body: home),
),
MaterialApp(
navigatorKey: navigator,
home: Scaffold(body: home),
),
);
await tester.tap(find.text('Run'));
await tester.pumpAndSettle();
@@ -99,18 +96,6 @@ void main() {
expect(machine.calls, ['chat_shell_run']);
});
testWidgets('a Cupertino host gets the Cupertino dialog', (tester) async {
await pump(tester, cupertino: true);
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
await tester.enterText(
find.byKey(const Key('elevation-password')),
'right',
);
await tester.tap(find.byKey(const Key('elevation-confirm')));
await tester.pumpAndSettle();
expect((await pending!)['type'], 'chat_shell_run_ok');
});
testWidgets('without a mounted navigator the refusal is reported', (
tester,
) async {
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
@@ -34,61 +33,53 @@ class _Gateway extends FakeChatGateway {
}
void main() {
for (final cupertino in [false, true]) {
testWidgets(
'a pushed phone chat stays read and preserves underlying list chrome ($cupertino)',
(tester) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
SharedPreferences.setMockInitialValues({});
final gateway = _Gateway()..history = (_) async => chatPage([]);
addTearDown(gateway.close);
final bar = ShellBarRegistry();
addTearDown(bar.dispose);
final selected = ValueNotifier<String?>('s1');
addTearDown(selected.dispose);
final screen = ShellBarScope(
registry: bar,
destination: AppDestination.chat,
child: ValueListenableBuilder<String?>(
valueListenable: selected,
builder: (_, id, _) => ChatScreen(
gateway: gateway,
initialSessionId: id,
onBack: () => selected.value = null,
),
testWidgets(
'a pushed phone chat stays read and preserves underlying list chrome',
(tester) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
SharedPreferences.setMockInitialValues({});
final gateway = _Gateway()..history = (_) async => chatPage([]);
addTearDown(gateway.close);
final bar = ShellBarRegistry();
addTearDown(bar.dispose);
final selected = ValueNotifier<String?>('s1');
addTearDown(selected.dispose);
final screen = ShellBarScope(
registry: bar,
destination: AppDestination.chat,
child: ValueListenableBuilder<String?>(
valueListenable: selected,
builder: (_, id, _) => ChatScreen(
gateway: gateway,
initialSessionId: id,
onBack: () => selected.value = null,
),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: screen))
: MaterialApp(home: Scaffold(body: screen)),
);
await tester.pumpAndSettle();
final list = tester.widget<ChatSessionsScreen>(
find.byType(ChatSessionsScreen, skipOffstage: false),
);
final controller = list.controller!;
expect(controller.activeSessionId, 's1');
expect(bar.specFor(AppDestination.chat)?.actions, isNotEmpty);
gateway.emitEvent(chatTextFrame('New live answer', session: 's1'));
await tester.pumpAndSettle();
expect(controller.sessions.where(controller.isUnseen), isEmpty);
gateway.emitEvent(chatTextFrame('Different answer', session: 's2'));
await tester.pumpAndSettle();
expect(
controller.sessions
.where(controller.isUnseen)
.map((row) => row['id']),
['s2'],
);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(controller.activeSessionId, isNull);
expect(find.text('Open conversation'), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
},
);
}
),
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: screen)));
await tester.pumpAndSettle();
final list = tester.widget<ChatSessionsScreen>(
find.byType(ChatSessionsScreen, skipOffstage: false),
);
final controller = list.controller!;
expect(controller.activeSessionId, 's1');
expect(bar.specFor(AppDestination.chat)?.actions, isNotEmpty);
gateway.emitEvent(chatTextFrame('New live answer', session: 's1'));
await tester.pumpAndSettle();
expect(controller.sessions.where(controller.isUnseen), isEmpty);
gateway.emitEvent(chatTextFrame('Different answer', session: 's2'));
await tester.pumpAndSettle();
expect(
controller.sessions.where(controller.isUnseen).map((row) => row['id']),
['s2'],
);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(controller.activeSessionId, isNull);
expect(find.text('Open conversation'), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
},
);
}
@@ -192,6 +192,13 @@ void main() {
await tester.pumpAndSettle();
expect(widthOf(tester, 'three'), 950);
expect(find.byType(ChatCenterStageStrip), findsNWidgets(2));
expect(
find.descendant(
of: find.byType(ChatCenterStageStrip).first,
matching: find.byType(InkWell),
),
findsOneWidget,
);
expect(find.text('draft'), findsOneWidget);
stage.value = false;
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/workspace/chat_mobile_panes.dart';
@@ -36,54 +35,48 @@ class _ThreadState extends State<_Thread> {
}
void main() {
for (final cupertino in [false, true]) {
for (final height in [32.0, 48.0]) {
testWidgets(
'peek title and switch fit $height height at 2x ($cupertino)',
(tester) async {
var activated = 0;
Size? bodySize;
final viewport = MediaQuery(
data: const MediaQueryData(textScaler: TextScaler.linear(2)),
child: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: 320,
height: height,
child: ChatMobilePaneViewport(
peek: true,
active: false,
barReveal: const AlwaysStoppedAnimation(0),
onActivate: () => activated++,
label: 'A long working project name',
paneId: 'first',
child: LayoutBuilder(
builder: (context, constraints) {
bodySize = constraints.biggest;
return const SizedBox.expand();
},
),
),
for (final height in [32.0, 48.0]) {
testWidgets('peek title and switch fit $height height at 2x', (
tester,
) async {
var activated = 0;
Size? bodySize;
final viewport = MediaQuery(
data: const MediaQueryData(textScaler: TextScaler.linear(2)),
child: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: 320,
height: height,
child: ChatMobilePaneViewport(
peek: true,
active: false,
barReveal: const AlwaysStoppedAnimation(0),
onActivate: () => activated++,
label: 'A long working project name',
paneId: 'first',
child: LayoutBuilder(
builder: (context, constraints) {
bodySize = constraints.biggest;
return const SizedBox.expand();
},
),
),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: viewport))
: MaterialApp(home: Scaffold(body: viewport)),
);
expect(find.text('A long working project name'), findsOneWidget);
expect(find.text('Switch'), findsOneWidget);
final headerSize = tester.getSize(find.byType(ChatPeekHeader));
expect(headerSize.height, lessThanOrEqualTo(height));
expect(bodySize!.height, closeTo(height - headerSize.height, .01));
await tester.tap(find.text('Switch'));
await tester.pump();
expect(activated, 1);
expect(tester.takeException(), isNull);
},
),
),
);
}
await tester.pumpWidget(MaterialApp(home: Scaffold(body: viewport)));
expect(find.text('A long working project name'), findsOneWidget);
expect(find.text('Switch'), findsOneWidget);
expect(find.byType(TextButton), findsOneWidget);
final headerSize = tester.getSize(find.byType(ChatPeekHeader));
expect(headerSize.height, lessThanOrEqualTo(height));
expect(bodySize!.height, closeTo(height - headerSize.height, .01));
await tester.tap(find.text('Switch'));
await tester.pump();
expect(activated, 1);
expect(tester.takeException(), isNull);
});
}
testWidgets('peek header reserves real body space and keeps reading state', (
tester,
@@ -3,56 +3,47 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace_entrance.dart';
void main() {
for (final cupertino in [false, true]) {
testWidgets('retained entrance moves the same child ($cupertino)', (
tester,
) async {
tester.platformDispatcher.accessibilityFeaturesTestValue =
const FakeAccessibilityFeatures(disableAnimations: false);
addTearDown(
tester.platformDispatcher.clearAccessibilityFeaturesTestValue,
);
final childKey = GlobalKey();
final child = TextField(key: childKey);
Widget host(bool visible, {bool reduced = false}) => MaterialApp(
home: MediaQuery(
data: MediaQueryData(disableAnimations: reduced),
child: SizedBox.expand(
child: ChatWorkspaceEntrance(
visible: visible,
cupertino: cupertino,
child: Material(child: child),
),
testWidgets('retained entrance moves the same child', (tester) async {
tester.platformDispatcher.accessibilityFeaturesTestValue =
const FakeAccessibilityFeatures(disableAnimations: false);
addTearDown(tester.platformDispatcher.clearAccessibilityFeaturesTestValue);
final childKey = GlobalKey();
final child = TextField(key: childKey);
Widget host(bool visible, {bool reduced = false}) => MaterialApp(
home: MediaQuery(
data: MediaQueryData(disableAnimations: reduced),
child: SizedBox.expand(
child: ChatWorkspaceEntrance(
visible: visible,
cupertino: false,
child: Material(child: child),
),
),
);
await tester.pumpWidget(host(false));
final element = childKey.currentContext;
final state = childKey.currentState;
expect(find.byKey(childKey), findsNothing);
await tester.pumpWidget(host(true));
final start = tester.getTopLeft(find.byKey(childKey));
await tester.pump();
await tester.pump(const Duration(milliseconds: 80));
final middle = tester.getTopLeft(find.byKey(childKey));
await tester.pumpAndSettle();
final end = tester.getTopLeft(find.byKey(childKey));
expect(cupertino ? middle.dx : middle.dy, greaterThan(0));
expect(
cupertino ? middle.dx : middle.dy,
lessThan(cupertino ? start.dx : start.dy),
);
expect(end, Offset.zero);
expect(childKey.currentContext, same(element));
expect(childKey.currentState, same(state));
await tester.enterText(find.byType(TextField), 'Retained draft');
await tester.pumpWidget(host(false));
await tester.pumpAndSettle();
await tester.pumpWidget(host(true, reduced: true));
expect(tester.getTopLeft(find.byKey(childKey)), Offset.zero);
expect(find.text('Retained draft'), findsOneWidget);
expect(childKey.currentState, same(state));
expect(tester.takeException(), isNull);
});
}
),
);
await tester.pumpWidget(host(false));
final element = childKey.currentContext;
final state = childKey.currentState;
expect(find.byKey(childKey), findsNothing);
await tester.pumpWidget(host(true));
final start = tester.getTopLeft(find.byKey(childKey));
await tester.pump();
await tester.pump(const Duration(milliseconds: 80));
final middle = tester.getTopLeft(find.byKey(childKey));
await tester.pumpAndSettle();
final end = tester.getTopLeft(find.byKey(childKey));
expect(middle.dy, greaterThan(0));
expect(middle.dy, lessThan(start.dy));
expect(end, Offset.zero);
expect(childKey.currentContext, same(element));
expect(childKey.currentState, same(state));
await tester.enterText(find.byType(TextField), 'Retained draft');
await tester.pumpWidget(host(false));
await tester.pumpAndSettle();
await tester.pumpWidget(host(true, reduced: true));
expect(tester.getTopLeft(find.byKey(childKey)), Offset.zero);
expect(find.text('Retained draft'), findsOneWidget);
expect(childKey.currentState, same(state));
expect(tester.takeException(), isNull);
});
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/servers/machine_access.dart';
@@ -64,96 +63,90 @@ Future<void> addServer(
}
void main() {
for (final cupertino in [false, true]) {
testWidgets('a new machine asks for its own password ($cupertino)', (
tester,
) async {
final connections = ServerConnections(
store: MemoryServerCatalogStore(
catalog: ServerCatalog(
servers: [
SavedServer.validated(
id: 'mac',
name: 'Mac',
endpoints: ['ws://10.0.0.75:8083/connect'],
),
],
selectedId: 'mac',
),
testWidgets('a new machine asks for its own password', (tester) async {
final connections = ServerConnections(
store: MemoryServerCatalogStore(
catalog: ServerCatalog(
servers: [
SavedServer.validated(
id: 'mac',
name: 'Mac',
endpoints: ['ws://10.0.0.75:8083/connect'],
),
],
selectedId: 'mac',
),
onSelected: (_) async {},
);
addTearDown(connections.dispose);
await connections.load();
final auth = FakeAuthenticator()
..verdicts['mac'] = const MachineAccessResult(MachineAccess.connected);
connections.authenticator = auth;
final body = SingleChildScrollView(
child: SavedServersSection(connections: connections),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
home: CupertinoPageScaffold(child: SafeArea(child: body)),
)
: MaterialApp(home: Scaffold(body: body)),
);
expect(find.text('Connected'), findsOneWidget);
// The new machine is unknown to the authenticator until saved; a
// password verdict arrives for whatever id the editor assigned.
auth.verdicts.addAll({
for (final id in ['pending']) id: const MachineAccessResult(
MachineAccess.needsPassword,
),
});
await tester.tap(find.text('Add server'));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('server-profile-name')), 'tank');
await tester.enterText(
find.byKey(const Key('server-profile-addresses')),
'ws://10.0.0.100:8082/connect',
);
// Whatever id the editor chose, that machine wants a password.
connections.addListener(() {
for (final server in connections.catalog.servers) {
auth.verdicts.putIfAbsent(
server.id,
() => const MachineAccessResult(MachineAccess.needsPassword),
);
auth.passwords.putIfAbsent(server.id, () => 'tank-secret');
}
});
await revealSave(tester);
await tester.tap(find.text('Save server'));
await tester.pumpAndSettle();
final tank = connections.catalog.servers.firstWhere((s) => s.name == 'tank');
expect(auth.probes, [tank.id]);
// Saved, and the editor now asks this machine's password; the first
// machine's sign-in is not reused.
expect(find.byKey(const Key('server-profile-password')), findsOneWidget);
expect(find.textContaining('asks for its own password'), findsOneWidget);
await tester.enterText(
find.byKey(const Key('server-profile-password')),
'wrong',
);
await tester.tap(find.byKey(const Key('server-profile-sign-in')));
await tester.pumpAndSettle();
expect(find.text('Wrong password.'), findsOneWidget);
expect(find.byKey(const Key('server-profile-password')), findsOneWidget);
await tester.enterText(
find.byKey(const Key('server-profile-password')),
'tank-secret',
);
await tester.tap(find.byKey(const Key('server-profile-sign-in')));
await tester.pumpAndSettle();
expect(auth.signIns, [(tank.id, 'wrong'), (tank.id, 'tank-secret')]);
// Back on the list: both machines connected, each on its own sign-in.
expect(find.byKey(const Key('server-profile-password')), findsNothing);
expect(find.text('Connected'), findsNWidgets(2));
expect(find.text('Address: ws://10.0.0.100:8082/connect'), findsOneWidget);
expect(connections.catalog.active?.id, 'mac');
),
onSelected: (_) async {},
);
addTearDown(connections.dispose);
await connections.load();
final auth = FakeAuthenticator()
..verdicts['mac'] = const MachineAccessResult(MachineAccess.connected);
connections.authenticator = auth;
final body = SingleChildScrollView(
child: SavedServersSection(connections: connections),
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: body)));
expect(find.text('Connected'), findsOneWidget);
// The new machine is unknown to the authenticator until saved; a
// password verdict arrives for whatever id the editor assigned.
auth.verdicts.addAll({
for (final id in ['pending'])
id: const MachineAccessResult(MachineAccess.needsPassword),
});
}
await tester.tap(find.text('Add server'));
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('server-profile-name')),
'tank',
);
await tester.enterText(
find.byKey(const Key('server-profile-addresses')),
'ws://10.0.0.100:8082/connect',
);
// Whatever id the editor chose, that machine wants a password.
connections.addListener(() {
for (final server in connections.catalog.servers) {
auth.verdicts.putIfAbsent(
server.id,
() => const MachineAccessResult(MachineAccess.needsPassword),
);
auth.passwords.putIfAbsent(server.id, () => 'tank-secret');
}
});
await revealSave(tester);
await tester.tap(find.text('Save server'));
await tester.pumpAndSettle();
final tank = connections.catalog.servers.firstWhere(
(s) => s.name == 'tank',
);
expect(auth.probes, [tank.id]);
// Saved, and the editor now asks this machine's password; the first
// machine's sign-in is not reused.
expect(find.byKey(const Key('server-profile-password')), findsOneWidget);
expect(find.textContaining('asks for its own password'), findsOneWidget);
await tester.enterText(
find.byKey(const Key('server-profile-password')),
'wrong',
);
await tester.tap(find.byKey(const Key('server-profile-sign-in')));
await tester.pumpAndSettle();
expect(find.text('Wrong password.'), findsOneWidget);
expect(find.byKey(const Key('server-profile-password')), findsOneWidget);
await tester.enterText(
find.byKey(const Key('server-profile-password')),
'tank-secret',
);
await tester.tap(find.byKey(const Key('server-profile-sign-in')));
await tester.pumpAndSettle();
expect(auth.signIns, [(tank.id, 'wrong'), (tank.id, 'tank-secret')]);
// Back on the list: both machines connected, each on its own sign-in.
expect(find.byKey(const Key('server-profile-password')), findsNothing);
expect(find.text('Connected'), findsNWidgets(2));
expect(find.text('Address: ws://10.0.0.100:8082/connect'), findsOneWidget);
expect(connections.catalog.active?.id, 'mac');
});
testWidgets('an unreachable machine stays saved with the reason shown', (
tester,
@@ -172,7 +165,8 @@ void main() {
server.id,
() => const MachineAccessResult(
MachineAccess.unreachable,
detail: 'The HTTPS certificate of 100.85.25.33:8443 does not '
detail:
'The HTTPS certificate of 100.85.25.33:8443 does not '
'cover an IP address.',
),
);
@@ -198,7 +192,10 @@ void main() {
await tester.tap(find.byKey(const Key('server-sign-in-later')));
await tester.pumpAndSettle();
expect(connections.catalog.servers.single.name, 'Mac by IP');
expect(find.textContaining('Unreachable: The HTTPS certificate'), findsOneWidget);
expect(
find.textContaining('Unreachable: The HTTPS certificate'),
findsOneWidget,
);
});
testWidgets('a saved machine that wants a password offers Sign in', (
@@ -218,7 +215,9 @@ void main() {
addTearDown(connections.dispose);
await connections.load();
final auth = FakeAuthenticator()
..verdicts['tank'] = const MachineAccessResult(MachineAccess.needsPassword)
..verdicts['tank'] = const MachineAccessResult(
MachineAccess.needsPassword,
)
..passwords['tank'] = 'tank-secret';
connections.authenticator = auth;
await tester.pumpWidget(
@@ -231,7 +230,10 @@ void main() {
await tester.pumpAndSettle();
await tester.tap(find.text('Sign in to tank'));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('machine-password')), 'tank-secret');
await tester.enterText(
find.byKey(const Key('machine-password')),
'tank-secret',
);
await tester.tap(find.byKey(const Key('machine-sign-in')));
await tester.pumpAndSettle();
expect(auth.signIns, [('tank', 'tank-secret')]);
@@ -248,7 +250,9 @@ void main() {
endpoints: ['ws://10.0.0.75:8083/connect'],
);
final auth = FakeAuthenticator()
..verdicts['mac'] = const MachineAccessResult(MachineAccess.needsPassword);
..verdicts['mac'] = const MachineAccessResult(
MachineAccess.needsPassword,
);
SavedServer? saved;
await tester.pumpWidget(
MaterialApp(
@@ -269,7 +273,10 @@ void main() {
);
await tester.tap(find.text('Edit'));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('server-profile-name')), 'Studio');
await tester.enterText(
find.byKey(const Key('server-profile-name')),
'Studio',
);
await revealSave(tester);
await tester.tap(find.text('Save server'));
await tester.pumpAndSettle();
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/settings/storage/storage_screen.dart';
@@ -7,8 +6,7 @@ import '../../../../tool/storage_probe_fixture.dart';
Future<void> _mount(
WidgetTester tester,
StorageProbeGateway gateway,
bool cupertino, {
StorageProbeGateway gateway, {
double width = 900,
double scale = 1,
}) async {
@@ -20,11 +18,7 @@ Future<void> _mount(
data: MediaQuery.of(context).copyWith(textScaler: TextScaler.linear(scale)),
child: child!,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(builder: builder, home: screen)
: MaterialApp(builder: builder, home: screen),
);
await tester.pumpWidget(MaterialApp(builder: builder, home: screen));
await tester.pumpAndSettle();
}
@@ -43,83 +37,72 @@ Finder _field(String label) => find.descendant(
matching: find.byType(EditableText),
);
void main() {
for (final cupertino in [false, true]) {
final style = cupertino ? 'Cupertino' : 'Material';
testWidgets(
'$style usage and partial measurement remain honest at 2x narrow',
(tester) async {
final gateway = StorageProbeGateway();
await _mount(tester, gateway, cupertino, width: 560, scale: 2);
expect(find.text('At least 15.0 GiB used'), findsOneWidget);
expect(
find.text('Measurement is incomplete. See details below.'),
findsOneWidget,
);
expect(find.text('Database'), findsOneWidget);
expect(find.textContaining('6 November 2026'), findsOneWidget);
expect(find.text('Worktrees'), findsOneWidget);
await _tap(tester, 'Preview cleanup');
expect(find.text('Cleanup preview'), findsOneWidget);
expect(
find.text('Protected · worktree active-item · 4.00 GiB'),
findsOneWidget,
);
expect(tester.takeException(), isNull);
},
testWidgets('usage and partial measurement remain honest at 2x narrow', (
tester,
) async {
final gateway = StorageProbeGateway();
await _mount(tester, gateway, width: 560, scale: 2);
expect(find.text('At least 15.0 GiB used'), findsOneWidget);
expect(
find.text('Measurement is incomplete. See details below.'),
findsOneWidget,
);
testWidgets(
'$style cleanup cancellation does not mutate and confirmation uses token',
(tester) async {
final gateway = StorageProbeGateway();
await _mount(tester, gateway, cupertino);
await _tap(tester, 'Preview cleanup');
await _tap(tester, 'Apply cleanup');
expect(find.text('Apply cleanup?'), findsOneWidget);
await _tap(tester, 'Cancel');
expect(
gateway.calls.where((call) => call.type == 'apply_storage_cleanup'),
isEmpty,
);
await _tap(tester, 'Apply cleanup');
await _tap(tester, 'Remove items');
expect(
gateway.calls
.singleWhere((call) => call.type == 'apply_storage_cleanup')
.fields['storage_cleanup_token'],
'fixture-preview-token',
);
expect(find.text('Cleanup result'), findsOneWidget);
expect(
find.text('Worktree became active and was kept.'),
findsOneWidget,
);
expect(tester.takeException(), isNull);
},
expect(find.text('Database'), findsOneWidget);
expect(find.textContaining('6 November 2026'), findsOneWidget);
expect(find.text('Worktrees'), findsOneWidget);
await _tap(tester, 'Preview cleanup');
expect(find.text('Cleanup preview'), findsOneWidget);
expect(
find.text('Protected · worktree active-item · 4.00 GiB'),
findsOneWidget,
);
testWidgets('$style invalid limits do not send a policy', (tester) async {
expect(tester.takeException(), isNull);
});
testWidgets(
'cleanup cancellation does not mutate and confirmation uses token',
(tester) async {
final gateway = StorageProbeGateway();
await _mount(tester, gateway, cupertino);
await tester.ensureVisible(_field('Retain data for days'));
await tester.enterText(_field('Retain data for days'), '-1');
await _tap(tester, 'Save policy');
await _mount(tester, gateway);
await _tap(tester, 'Preview cleanup');
await _tap(tester, 'Apply cleanup');
expect(find.text('Apply cleanup?'), findsOneWidget);
await _tap(tester, 'Cancel');
expect(
find.textContaining('Enter a whole number of days'),
findsOneWidget,
);
expect(
gateway.calls.where((call) => call.type == 'set_storage_policy'),
gateway.calls.where((call) => call.type == 'apply_storage_cleanup'),
isEmpty,
);
});
testWidgets(
'$style unsupported server has an actionable error and no fake usage',
(tester) async {
final gateway = StorageProbeGateway()..unsupported = true;
await _mount(tester, gateway, cupertino);
expect(find.text('Unknown command: get_storage'), findsOneWidget);
expect(find.text('Server storage'), findsNothing);
expect(find.text('Refresh storage'), findsOneWidget);
},
await _tap(tester, 'Apply cleanup');
await _tap(tester, 'Remove items');
expect(
gateway.calls
.singleWhere((call) => call.type == 'apply_storage_cleanup')
.fields['storage_cleanup_token'],
'fixture-preview-token',
);
expect(find.text('Cleanup result'), findsOneWidget);
expect(find.text('Worktree became active and was kept.'), findsOneWidget);
expect(tester.takeException(), isNull);
},
);
testWidgets('invalid limits do not send a policy', (tester) async {
final gateway = StorageProbeGateway();
await _mount(tester, gateway);
await tester.ensureVisible(_field('Retain data for days'));
await tester.enterText(_field('Retain data for days'), '-1');
await _tap(tester, 'Save policy');
expect(find.textContaining('Enter a whole number of days'), findsOneWidget);
expect(
gateway.calls.where((call) => call.type == 'set_storage_policy'),
isEmpty,
);
}
});
testWidgets('unsupported server has an actionable error and no fake usage', (
tester,
) async {
final gateway = StorageProbeGateway()..unsupported = true;
await _mount(tester, gateway);
expect(find.text('Unknown command: get_storage'), findsOneWidget);
expect(find.text('Server storage'), findsNothing);
expect(find.text('Refresh storage'), findsOneWidget);
});
}