Chat list: tool calls and notices never mark a chat New

Only visible assistant reply text, a pending form or an unresolved
permission request is unread. Tool results, user prompts, harness
notices/agent reports and blank deltas only drive the working state.
This commit is contained in:
2026-11-03 18:34:29 +00:00
parent fa6c0864db
commit c320dac131
4 changed files with 145 additions and 35 deletions
@@ -67,6 +67,25 @@ JsonMap _event(String id, {String kind = 'text', String? delta}) => {
},
};
JsonMap _tool(String id, String status) => {
'type': 'chat_event',
'chat_event': {
'session_id': id,
'kind': 'tool',
'part': {
'type': 'tool',
'state': {
'status': status,
if (status == 'completed')
'content': [
{'type': 'text', 'text': 'command output'},
],
if (status == 'error') 'error': 'exit status 1',
},
},
},
};
void main() {
setUp(() => _store = MemoryChatSessionLocalStore());
@@ -176,46 +195,79 @@ void main() {
expect(find.byType(CircularProgressIndicator), findsNothing);
});
testWidgets('tool starts are loading; returned tool results are unread', (
testWidgets('tool calls and their results are loading, never New', (
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'},
},
},
});
fake.pushed.add(_tool('s1', 'running'));
await tester.pump();
await tester.pump();
expect(find.byKey(const Key('chat-row-unread')), findsNothing);
expect(find.byType(CircularProgressIndicator), findsOneWidget);
fake.pushed.add(_tool('s1', 'completed'));
fake.pushed.add(_tool('s1', 'error'));
// Harness notices, agent reports, a prompt from another device and
// whitespace-only deltas around a tool call are not a reply either.
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'},
],
},
},
'kind': 'text',
'delta': 'Background task finished',
'message_kind': 'notice',
},
});
fake.pushed.add({
'type': 'chat_event',
'chat_event': {
'session_id': 's1',
'kind': 'text',
'delta': 'Subagent report',
'message_kind': 'agent_report',
},
});
fake.pushed.add({
'type': 'chat_event',
'chat_event': {'session_id': 's1', 'kind': 'user', 'delta': 'hi'},
});
fake.pushed.add(_event('s1', delta: '\n\n'));
// The turn is still working, so its spinner never settles.
await tester.pump();
await tester.pump();
expect(find.byKey(const Key('chat-row-unread')), findsNothing);
expect(find.byType(CircularProgressIndicator), findsOneWidget);
// The assistant's reply after the tool call is what is unread.
fake.pushed.add(_event('s1', delta: 'Done: tests pass.'));
await tester.pump();
await tester.pump();
expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
});
testWidgets('a tool call and reply in the open chat stay read on leaving', (
tester,
) async {
final fake = gateway();
await _pump(tester, fake, active: 's1');
fake.pushed.add(_tool('s1', 'running'));
fake.pushed.add(_tool('s1', 'completed'));
fake.pushed.add(_event('s1', delta: 'Here is the answer.'));
fake.pushed.add({
'type': 'chat_event',
'chat_event': {
'session_id': 's1',
'kind': 'step',
'step': {'status': 'ended'},
},
});
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
expect(find.byType(CircularProgressIndicator), findsNothing);
expect(find.byKey(const Key('chat-row-unread')), findsNothing);
await _pump(tester, fake);
expect(find.byKey(const Key('chat-row-unread')), findsNothing);
expect(_store.state?.isUnseen('s1') ?? false, isFalse);
});
testWidgets('only unresolved permission requests mark New', (tester) async {
@@ -37,4 +37,44 @@ void main() {
});
expect(intermediate!.running, isNull);
});
test('only visible assistant reply text is unread', () {
bool attention(Map<String, Object?> event) =>
chatSessionFrameEffect({
'type': 'chat_event',
'chat_event': {'session_id': 's', ...event},
})!.attention;
for (final status in ['running', 'completed', 'error']) {
expect(
attention({
'kind': 'tool',
'part': {
'type': 'tool',
'state': {
'status': status,
'content': [
{'type': 'text', 'text': 'out'},
],
'error': status == 'error' ? 'failed' : null,
},
},
}),
isFalse,
reason: 'tool $status',
);
}
expect(attention({'kind': 'user', 'delta': 'prompt'}), isFalse);
expect(attention({'kind': 'text', 'delta': ' \n'}), isFalse);
for (final messageKind in ['notice', 'agent_report']) {
expect(
attention({
'kind': 'text',
'delta': 'x',
'message_kind': messageKind,
}),
isFalse,
);
}
expect(attention({'kind': 'text', 'delta': 'answer'}), isTrue);
});
}