diff --git a/app/lib/features/chat/conversation/chat_composer_bar.dart b/app/lib/features/chat/conversation/chat_composer_bar.dart index ebbde1a2..771fdd88 100644 --- a/app/lib/features/chat/conversation/chat_composer_bar.dart +++ b/app/lib/features/chat/conversation/chat_composer_bar.dart @@ -3,6 +3,7 @@ import 'dart:math' as math; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'chat_stop_icon.dart'; import 'package:flutter/services.dart'; import '../../../core/api_gateway.dart'; @@ -937,10 +938,11 @@ class _ChatComposerBarState extends State { sizeStyle: CupertinoButtonSize.small, color: stop ? CupertinoColors.systemRed.resolveFrom(context) : null, onPressed: enabled ? press : null, - child: Icon( - stop ? CupertinoIcons.stop_fill : CupertinoIcons.arrow_up, - size: 18, - ), + child: stop + ? const ChatStopIcon( + child: Icon(CupertinoIcons.stop_fill, size: 18), + ) + : const Icon(CupertinoIcons.arrow_up, size: 18), ), ); } @@ -955,7 +957,9 @@ class _ChatComposerBarState extends State { ) : null, onPressed: enabled ? press : null, - icon: Icon(stop ? Icons.stop : Icons.send), + icon: stop + ? const ChatStopIcon(child: Icon(Icons.stop)) + : const Icon(Icons.send), ); } diff --git a/app/lib/features/chat/conversation/chat_stop_icon.dart b/app/lib/features/chat/conversation/chat_stop_icon.dart new file mode 100644 index 00000000..1b17adf8 --- /dev/null +++ b/app/lib/features/chat/conversation/chat_stop_icon.dart @@ -0,0 +1,48 @@ +import 'package:flutter/widgets.dart'; + +/// Slow, continuous progress motion confined to the Stop glyph. The native +/// button, hit target and semantics never rotate. TickerMode pauses hidden UI. +class ChatStopIcon extends StatefulWidget { + const ChatStopIcon({super.key, required this.child}); + + final Widget child; + static const period = Duration(seconds: 8); + + @override + State createState() => _ChatStopIconState(); +} + +class _ChatStopIconState extends State + with SingleTickerProviderStateMixin { + late final _rotation = AnimationController( + vsync: this, + duration: ChatStopIcon.period, + ); + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + if (MediaQuery.maybeDisableAnimationsOf(context) ?? false) { + _rotation.stop(); + _rotation.value = 0; + } else if (!_rotation.isAnimating) { + _rotation.repeat(); + } + } + + @override + void dispose() { + _rotation.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) => RepaintBoundary( + key: const Key('chat-stop-paint-boundary'), + child: RotationTransition( + key: const Key('chat-stop-rotation'), + turns: _rotation, + child: widget.child, + ), + ); +} diff --git a/app/notes/slow-stop-rotation.md b/app/notes/slow-stop-rotation.md new file mode 100644 index 00000000..6b70d00a --- /dev/null +++ b/app/notes/slow-stop-rotation.md @@ -0,0 +1,28 @@ +# Slow continuous Stop rotation + +User requested the Stop button rotate slowly and continuously in chat. + +- The glyph makes one linear turn every **8 seconds**, repeating for as long as + the processing turn keeps Stop visible. Native button geometry, semantics, + tooltip, hit target and interrupt action stay stationary/unchanged; Send remains + available. No transcript or transport state is driven by animation. +- A local RepaintBoundary confines painting to the icon. TickerMode silences + hidden routes; controller disposal stops animation when Stop disappears. +- System reduced motion makes the icon static and resets its angle; re-enabling + motion resumes rotation. +- Tests cover 8-second cadence/repetition, reduced-motion toggling, hidden mode, + disposal, no ancestor repaint and both native button styles/actions/geometry. +- Functional chat tests use a scoped reduced-motion test configuration so their + asynchronous pumpAndSettle remains meaningful with an intentionally infinite + animation. Dedicated animation tests explicitly enable motion and pump time. +- This exposed an existing zero-duration AnimatedSize layout mutation under + reduced motion; 701449b4 skips that size animator entirely, with two regression + cases for asynchronously arriving rows. Default-motion behavior is unchanged. +- Full gate: clean analysis and **1,860 tests pass**. +- Normal-app browser probe CHECK_STOP_ROTATION=1 passes 20 checks/14 captures per + host in `build/stop-rotation-{material,cupertino}/`. Pixel comparisons prove + motion, identical hit-target geometry and static reduced-motion output. + Both Material motion frames visually inspected. +- No backend changes, service restarts or device operations. The prior stock-Back + APK 29880696 finished and is preserved in `build/candidates/stock-chat-back-29880696/`; + final combined web/APK deployment is pending. Actual device behavior unverified. diff --git a/app/test/features/chat/conversation/chat_stop_icon_test.dart b/app/test/features/chat/conversation/chat_stop_icon_test.dart new file mode 100644 index 00000000..e89e50ae --- /dev/null +++ b/app/test/features/chat/conversation/chat_stop_icon_test.dart @@ -0,0 +1,178 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/chat/conversation/chat_stop_icon.dart'; +import 'package:pipelines_app/features/chat/conversation/chat_composer_bar.dart'; +import 'package:pipelines_app/features/chat/conversation/chat_composer_controller.dart'; +import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart'; + +import 'chat_composer_bar_fixtures.dart'; + +class _CountPaint extends CustomPainter { + _CountPaint(this.onPaint); + final VoidCallback onPaint; + @override + void paint(Canvas canvas, Size size) => onPaint(); + @override + bool shouldRepaint(_CountPaint oldDelegate) => false; +} + +void main() { + setUp(() { + TestWidgetsFlutterBinding.ensureInitialized() + .platformDispatcher + .accessibilityFeaturesTestValue = const FakeAccessibilityFeatures( + disableAnimations: false, + ); + }); + tearDown(() { + TestWidgetsFlutterBinding.ensureInitialized() + .platformDispatcher + .accessibilityFeaturesTestValue = const FakeAccessibilityFeatures( + disableAnimations: true, + ); + }); + + testWidgets('rotation repaints only the icon, not the surrounding chat', ( + tester, + ) async { + var paints = 0; + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: CustomPaint( + painter: _CountPaint(() => paints++), + child: const ChatStopIcon(child: Icon(Icons.stop)), + ), + ), + ), + ); + final before = paints; + await tester.pump(const Duration(seconds: 1)); + await tester.pump(const Duration(seconds: 1)); + expect(paints, before); + await tester.pumpWidget(const SizedBox.shrink()); + }); + + testWidgets( + 'Stop rotates linearly and continuously once every eight seconds', + (tester) async { + await tester.pumpWidget( + const MaterialApp( + home: Scaffold(body: ChatStopIcon(child: Icon(Icons.stop))), + ), + ); + RotationTransition rotation() => + tester.widget(find.byKey(const Key('chat-stop-rotation'))); + await tester.pump(const Duration(seconds: 2)); + expect(rotation().turns.value, closeTo(0.25, 0.001)); + await tester.pump(const Duration(seconds: 2)); + expect(rotation().turns.value, closeTo(0.5, 0.001)); + await tester.pump(const Duration(seconds: 8)); + expect(rotation().turns.value, closeTo(0.5, 0.001)); + await tester.pumpWidget(const SizedBox.shrink()); + expect(tester.binding.transientCallbackCount, 0); + }, + ); + + testWidgets('reduced motion stops/reset rotation and resumes when enabled', ( + tester, + ) async { + final reduce = ValueNotifier(true); + addTearDown(reduce.dispose); + await tester.pumpWidget( + MaterialApp( + home: ValueListenableBuilder( + valueListenable: reduce, + builder: (context, value, _) => MediaQuery( + data: MediaQuery.of(context).copyWith(disableAnimations: value), + child: const ChatStopIcon(child: Icon(Icons.stop)), + ), + ), + ), + ); + RotationTransition rotation() => + tester.widget(find.byKey(const Key('chat-stop-rotation'))); + await tester.pumpAndSettle(); + expect(rotation().turns.value, 0); + expect(tester.binding.transientCallbackCount, 0); + reduce.value = false; + await tester.pump(); + await tester.pump(const Duration(seconds: 1)); + expect(rotation().turns.value, closeTo(0.125, 0.001)); + reduce.value = true; + await tester.pumpAndSettle(); + expect(rotation().turns.value, 0); + expect(tester.binding.transientCallbackCount, 0); + }); + + testWidgets('TickerMode silences hidden Stop animation', (tester) async { + await tester.pumpWidget( + const MaterialApp( + home: TickerMode( + enabled: false, + child: ChatStopIcon(child: Icon(Icons.stop)), + ), + ), + ); + await tester.pumpAndSettle(); + expect(tester.binding.transientCallbackCount, 0); + await tester.pumpWidget(const SizedBox.shrink()); + }); + + for (final cupertino in [false, true]) { + testWidgets( + 'rotating Stop keeps its target and interrupt action; Send stays available ($cupertino)', + (tester) async { + final gateway = ComposerBarGateway(); + addTearDown(gateway.close); + final composer = ChatComposerController( + gateway, + 's', + drafts: MemoryChatDraftStore(), + ); + addTearDown(composer.dispose); + final running = ValueNotifier(true); + addTearDown(running.dispose); + final bar = ValueListenableBuilder( + valueListenable: running, + builder: (_, value, _) => + ChatComposerBar(composer: composer, running: value), + ); + await tester.pumpWidget( + cupertino + ? CupertinoApp( + home: CupertinoPageScaffold(child: Center(child: bar)), + ) + : MaterialApp( + home: Scaffold(body: Center(child: bar)), + ), + ); + final stop = find.byKey(const Key('chat-composer-stop')); + final target = tester.getRect(stop); + await tester.pump(const Duration(seconds: 3)); + expect(tester.getRect(stop), target); + expect(find.byKey(const Key('chat-composer-primary')), findsOneWidget); + expect( + tester + .widget( + find.byKey(const Key('chat-stop-rotation')), + ) + .turns + .value, + greaterThan(0), + ); + await tester.tap(stop); + await tester.pump(); + await tester.pump(); + expect(gateway.interruptBodies, [ + {'session_id': 's'}, + ]); + running.value = false; + await tester.pumpAndSettle(); + expect(find.byType(ChatStopIcon), findsNothing); + expect(tester.binding.transientCallbackCount, 0); + }, + ); + } +} diff --git a/app/test/features/chat/flutter_test_config.dart b/app/test/features/chat/flutter_test_config.dart new file mode 100644 index 00000000..2e3f4e32 --- /dev/null +++ b/app/test/features/chat/flutter_test_config.dart @@ -0,0 +1,13 @@ +import 'dart:async'; +import 'package:flutter_test/flutter_test.dart'; + +/// Functional chat tests settle asynchronous state with reduced motion. Tests +/// covering animation explicitly opt back in and pump known frame durations. +Future testExecutable(FutureOr Function() testMain) async { + TestWidgetsFlutterBinding.ensureInitialized() + .platformDispatcher + .accessibilityFeaturesTestValue = const FakeAccessibilityFeatures( + disableAnimations: true, + ); + await testMain(); +} diff --git a/app/tool/chat_stage_debug_probe.mjs b/app/tool/chat_stage_debug_probe.mjs index a38550b1..77432ccb 100644 --- a/app/tool/chat_stage_debug_probe.mjs +++ b/app/tool/chat_stage_debug_probe.mjs @@ -46,6 +46,9 @@ try { const port = await waitForPort(join(profile, 'DevToolsActivePort')); connection = await connect((await waitForPage(port)).webSocketDebuggerUrl); await connection.send('Page.enable'); + if (process.env.CHECK_STOP_ROTATION === '1') { + await connection.send('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-reduced-motion', value: 'no-preference' }] }); + } if (process.env.PROBE_PLATFORM === 'material') { await connection.send('Emulation.setUserAgentOverride', { userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36', @@ -109,6 +112,32 @@ try { log.checks.push('per-message reasoning is immediately left of tools count'); await assertPainted('Checking the recorded evidence.', 'reasoning visible while text streams', 'chat-live-reasoning'); await assertPainted('The answer is arriving.', 'streamed answer visible', 'chat-live-answer'); + if (process.env.CHECK_STOP_ROTATION === '1') { + const stop = (await axNodes(connection)).find(node => node.name?.value === 'Stop' && node.role?.value === 'button' && node.backendDOMNodeId); + assert.ok(stop, 'Stop target available'); + const box = (await connection.send('DOM.getBoxModel', { backendNodeId: stop.backendDOMNodeId })).model.content; + const crop = [box[0], box[1], box[4], box[5]].map(Math.round); + const differs = async (a, b) => { + const code = 'import sys; from PIL import Image,ImageChops; box=tuple(map(int,sys.argv[3:])); a=Image.open(sys.argv[1]).convert("RGB").crop(box); b=Image.open(sys.argv[2]).convert("RGB").crop(box); print(int(ImageChops.difference(a,b).getbbox() is not None))'; + const { stdout } = await promisify(execFile)('python3', ['-c', code, a, b, ...crop.map(String)]); + return stdout.trim() === '1'; + }; + await capture(connection, output, log, 'stop-rotation-a'); const normalA = log.captures.at(-1); + await sleep(1000); + await capture(connection, output, log, 'stop-rotation-b'); const normalB = log.captures.at(-1); + assert.ok(await differs(normalA, normalB), 'Stop glyph rotates continuously'); + const after = (await connection.send('DOM.getBoxModel', { backendNodeId: stop.backendDOMNodeId })).model.content; + assert.deepEqual(after, box, 'Stop hit target stays fixed'); + log.checks.push('Stop rotates while processing with an unchanged hit target'); + await connection.send('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-reduced-motion', value: 'reduce' }] }); + await sleep(500); + await capture(connection, output, log, 'stop-reduced-motion-a'); const reducedA = log.captures.at(-1); + await sleep(1000); + await capture(connection, output, log, 'stop-reduced-motion-b'); const reducedB = log.captures.at(-1); + assert.ok(!await differs(reducedA, reducedB), 'Reduced motion keeps Stop static'); + log.checks.push('system reduced motion stops the rotation'); + await connection.send('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-reduced-motion', value: 'no-preference' }] }); + } const field = (await axNodes(connection)).find(node => node.role?.value === 'textbox'); assert.ok(field, 'composer text field'); const { model } = await connection.send('DOM.getBoxModel', { backendNodeId: field.backendDOMNodeId });