Fix chat session unread attention state

This commit is contained in:
2026-10-28 16:32:33 +00:00
parent 48fdeaff97
commit 985cc35516
10 changed files with 395 additions and 40 deletions
@@ -39,9 +39,7 @@ void main() {
);
});
testWidgets('New appears only for a recency newer than this device read', (
tester,
) async {
testWidgets('updated recency alone does not create New', (tester) async {
final gateway = FakeChatGateway();
var updatedAt = 1000;
gateway.sessionsHandler = () async => {
@@ -60,7 +58,7 @@ void main() {
updatedAt = 2000;
await tester.tap(find.byKey(const Key('chat-refresh')));
await tester.pumpAndSettle();
expect(find.text('New'), findsOneWidget);
expect(find.text('New'), findsNothing);
await tester.tap(find.byKey(const Key('chat-row-s1')));
await tester.pumpAndSettle();
@@ -129,8 +129,8 @@ void main() {
expect(chatSessionRowStatus({}, unseen: false), isNull);
expect(chatSessionRowStatus({}, unseen: true), 'New');
// The web suppresses the streaming word; the row's activity icon carries it.
expect(chatSessionRowStatus({'running': true}, unseen: true), isNull);
// Running never hides an unread message; the native spinner is separate.
expect(chatSessionRowStatus({'running': true}, unseen: true), 'New');
expect(chatSessionRowStatus({'running': true}, unseen: false), isNull);
expect(
chatSessionRowStatus({'closed_at': '2026-01-01'}, unseen: true),
@@ -1,7 +1,12 @@
import 'dart:async';
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';
import 'package:pipelines_app/features/chat/ui/sessions/chat_session_local.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart';
import 'chat_test_harness.dart';
import 'fake_chat_gateway.dart';
@@ -25,11 +30,42 @@ Future<void> _pump(
await tester.pumpAndSettle();
}
Future<void> _pumpCupertino(
WidgetTester tester,
FakeChatGateway gateway,
) async {
await tester.pumpWidget(
CupertinoApp(
home: ChatSessionsScreen(
gateway: gateway,
onOpen: (_) {},
localStore: _store,
),
),
);
await tester.pumpAndSettle();
}
late MemoryChatSessionLocalStore _store;
JsonMap _event(String id, {String kind = 'text'}) => {
class _DeferredStore implements ChatSessionLocalStore {
final loaded = Completer<ChatSessionLocal>();
ChatSessionLocal? saved;
@override
Future<ChatSessionLocal> load() => loaded.future;
@override
Future<void> save(ChatSessionLocal state) async => saved = state;
}
JsonMap _event(String id, {String kind = 'text', String? delta}) => {
'type': 'chat_event',
'chat_event': {'session_id': id, 'kind': kind},
'chat_event': {
'session_id': id,
'kind': kind,
if (kind == 'text') 'delta': delta ?? 'hello',
},
};
void main() {
@@ -84,4 +120,204 @@ void main() {
await tester.pumpAndSettle();
expect(find.text('New'), findsOneWidget);
});
testWidgets('step and reasoning churn show loading, not New', (tester) async {
final fake = gateway();
await _pump(tester, fake);
fake.pushed.add({
'type': 'chat_event',
'chat_event': {
'session_id': 's1',
'kind': 'step',
'step': {'status': 'started'},
},
});
await tester.pump();
await tester.pump();
expect(find.text('New'), findsNothing);
expect(
tester
.widget<ChatSessionRowContent>(find.byType(ChatSessionRowContent))
.loading,
isTrue,
);
expect(find.byType(CircularProgressIndicator), findsOneWidget);
fake.pushed.add(_event('s1', kind: 'reasoning', delta: 'thinking'));
await tester.pump();
await tester.pump();
expect(find.text('New'), findsNothing);
expect(fake.count('chat_sessions'), 1);
fake.pushed.add({
'type': 'chat_event',
'chat_event': {
'session_id': 's1',
'kind': 'step',
'step': {'status': 'ended'},
},
});
await tester.pump();
await tester.pump();
expect(find.byType(CircularProgressIndicator), findsNothing);
expect(find.text('New'), findsNothing);
});
testWidgets('an unread visible answer remains New while running', (
tester,
) async {
final fake = gateway();
await _pump(tester, fake);
fake.pushed.add({
'type': 'chat_event',
'chat_event': {
'session_id': 's1',
'kind': 'step',
'step': {'status': 'started'},
},
});
fake.pushed.add(_event('s1'));
await tester.pumpAndSettle();
expect(find.text('New'), findsOneWidget);
expect(find.byType(CircularProgressIndicator), findsNothing);
});
testWidgets('tool starts are loading; returned tool results are unread', (
tester,
) async {
final fake = gateway();
await _pump(tester, fake);
fake.pushed.add({
'type': 'chat_event',
'chat_event': {
'session_id': 's1',
'kind': 'tool',
'part': {
'type': 'tool',
'state': {'status': 'running'},
},
},
});
await tester.pump();
await tester.pump();
expect(find.text('New'), findsNothing);
expect(find.byType(CircularProgressIndicator), findsOneWidget);
fake.pushed.add({
'type': 'chat_event',
'chat_event': {
'session_id': 's1',
'kind': 'tool',
'part': {
'type': 'tool',
'state': {
'status': 'completed',
'content': [
{'type': 'text', 'text': 'command output'},
],
},
},
},
});
await tester.pumpAndSettle();
expect(find.text('New'), findsOneWidget);
expect(find.byType(CircularProgressIndicator), findsNothing);
});
testWidgets('only unresolved permission requests mark New', (tester) async {
final fake = gateway();
await _pump(tester, fake);
fake.pushed.add({
'type': 'chat_permission',
'chat_permission': {
'session_id': 's1',
'request_id': 'p1',
'resolved': true,
'decision': 'once',
},
});
await tester.pumpAndSettle();
expect(find.text('New'), findsNothing);
fake.pushed.add({
'type': 'chat_permission',
'chat_permission': {'session_id': 's1', 'request_id': 'p2'},
});
await tester.pumpAndSettle();
expect(find.text('New'), findsOneWidget);
});
testWidgets('updated_at alone never manufactures unread state', (
tester,
) async {
final fake = gateway();
await _pump(tester, fake);
fake.sessionsReply = {
'chat_sessions': [
{'id': 's1', 'title': 'First', 'directory': '/w', 'updated_at': 2000},
],
};
// A server refresh may report newer recency without telling us what arrived.
await tester.tap(find.byKey(const Key('chat-refresh')));
await tester.pumpAndSettle();
fake.pushed.add(_event('unknown'));
await tester.pumpAndSettle();
expect(find.text('New'), findsNothing);
await tester.pumpWidget(const SizedBox.shrink());
fake.pushed.add(_event('s1'));
await tester.pump();
});
testWidgets('opening wins over an event waiting for local-store load', (
tester,
) async {
final fake = gateway();
final delayed = _DeferredStore();
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: ChatSessionsScreen(
gateway: fake,
onOpen: (_) {},
localStore: delayed,
),
),
);
await tester.pump();
await tester.pump();
fake.pushed.add(_event('s1'));
await tester.pump();
await tester.tap(find.byKey(const Key('chat-row-s1')));
delayed.loaded.complete(const ChatSessionLocal());
await tester.pump();
await tester.pump();
expect(find.text('New'), findsNothing);
expect(delayed.saved?.isUnseen('s1'), isFalse);
});
testWidgets('Cupertino rows load, mark a real answer New, then read it', (
tester,
) async {
final fake = gateway();
await _pumpCupertino(tester, fake);
fake.pushed.add({
'type': 'chat_event',
'chat_event': {
'session_id': 's1',
'kind': 'step',
'step': {'status': 'started'},
},
});
await tester.pump();
await tester.pump();
expect(find.byType(CupertinoActivityIndicator), findsOneWidget);
expect(find.text('New'), findsNothing);
fake.pushed.add(_event('s1'));
await tester.pumpAndSettle();
expect(find.text('New'), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-row-s1')));
await tester.pump();
await tester.pump();
expect(find.text('New'), findsNothing);
});
}
@@ -23,7 +23,6 @@ void main() {
'title': 'Harness chat',
'backend': backend,
'starred': starred,
'running': true,
},
],
),