route Claude transcript content through the MessageBus
test / unit + widget + golden + a11y (push) Failing after 26s
test / integration_test (xvfb) (push) Has been skipped
test / bundle smoke (xvfb 5s) (push) Has been skipped
test / daemon subprocess + web WASM smoke (push) Has been skipped
test / dart doc (lib API) (push) Failing after 23s
test / unit + widget + golden + a11y (push) Failing after 26s
test / integration_test (xvfb) (push) Has been skipped
test / bundle smoke (xvfb 5s) (push) Has been skipped
test / daemon subprocess + web WASM smoke (push) Has been skipped
test / dart doc (lib API) (push) Failing after 23s
The Claude pane owned a TranscriptReader directly via the controller. Insert a TranscriptPublisher that tails the transcript and republishes each ConversationItem onto the kernel MessageBus; the view's controller subscribes through ConversationController.fromBus. The subscription is attached before the reader's first poll, so the initial tail isn't missed on the broadcast bus. This decouples reading from rendering: the team work (T-139/T-140) can run one observer that publishes per-agent channels while the lead tile and each teammate tile subscribe independently. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,9 @@ import 'dart:async';
|
||||
|
||||
import 'package:clide/builtin/claude/src/conversation_controller.dart';
|
||||
import 'package:clide/builtin/claude/src/conversation_view.dart';
|
||||
import 'package:clide/builtin/claude/src/transcript_publisher.dart';
|
||||
import 'package:clide/builtin/claude/src/transcript_reader.dart';
|
||||
import 'package:clide/kernel/src/events/message_bus.dart';
|
||||
import 'package:clide/widgets/widgets.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -78,6 +80,35 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group('ConversationController.fromBus', () {
|
||||
test('consumes items published on its publisher/channel', () async {
|
||||
final bus = MessageBus();
|
||||
addTearDown(bus.dispose);
|
||||
final c = ConversationController.fromBus(messages: bus);
|
||||
addTearDown(c.dispose);
|
||||
|
||||
bus.publish(ClaudeConversation.publisher, ClaudeConversation.leadChannel, {ClaudeConversation.itemKey: _user('hi')});
|
||||
bus.publish(ClaudeConversation.publisher, ClaudeConversation.leadChannel, {ClaudeConversation.itemKey: _asst('hello')});
|
||||
await Future<void>.delayed(const Duration(milliseconds: 20));
|
||||
|
||||
expect(c.items, hasLength(2));
|
||||
expect(c.items.first, isA<UserMessage>());
|
||||
});
|
||||
|
||||
test('ignores other publishers and channels', () async {
|
||||
final bus = MessageBus();
|
||||
addTearDown(bus.dispose);
|
||||
final c = ConversationController.fromBus(messages: bus);
|
||||
addTearDown(c.dispose);
|
||||
|
||||
bus.publish('someone.else', ClaudeConversation.leadChannel, {ClaudeConversation.itemKey: _user('nope')});
|
||||
bus.publish(ClaudeConversation.publisher, 'conversation/other', {ClaudeConversation.itemKey: _user('nope')});
|
||||
await Future<void>.delayed(const Duration(milliseconds: 20));
|
||||
|
||||
expect(c.items, isEmpty);
|
||||
});
|
||||
});
|
||||
|
||||
group('ConversationView', () {
|
||||
late KernelFixture f;
|
||||
setUp(() async => f = await KernelFixture.create());
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/// Tests for TranscriptPublisher — bridges a TranscriptReader onto the
|
||||
/// kernel MessageBus (T-137/D-75). Pure Dart: MessageBus + reader have no
|
||||
/// Flutter dependency, so this runs under `package:test`.
|
||||
library;
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:clide/builtin/claude/src/transcript_publisher.dart';
|
||||
import 'package:clide/builtin/claude/src/transcript_reader.dart';
|
||||
import 'package:clide/kernel/src/events/message_bus.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
Map<String, dynamic> _userLine(String uuid, String text) => {
|
||||
'type': 'user',
|
||||
'uuid': uuid,
|
||||
'parentUuid': '',
|
||||
'isSidechain': false,
|
||||
'version': '2.1.143',
|
||||
'timestamp': '2026-05-16T08:53:06.708Z',
|
||||
'message': {'role': 'user', 'content': text},
|
||||
};
|
||||
|
||||
Map<String, dynamic> _asstLine(String uuid, String text) => {
|
||||
'type': 'assistant',
|
||||
'uuid': uuid,
|
||||
'parentUuid': '',
|
||||
'isSidechain': false,
|
||||
'version': '2.1.143',
|
||||
'timestamp': '2026-05-16T08:53:07.708Z',
|
||||
'message': {
|
||||
'role': 'assistant',
|
||||
'content': [
|
||||
{'type': 'text', 'text': text}
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
void main() {
|
||||
group('TranscriptPublisher', () {
|
||||
late Directory base;
|
||||
const workspace = '/pub/ws';
|
||||
|
||||
setUp(() async => base = await Directory.systemTemp.createTemp('transcript_publisher_test_'));
|
||||
tearDown(() async => base.delete(recursive: true));
|
||||
|
||||
test('republishes reader items onto the bus (lead channel + item key)', () async {
|
||||
final dir = Directory('${base.path}/${workspace.replaceAll('/', '-')}');
|
||||
await dir.create(recursive: true);
|
||||
File('${dir.path}/session-abc.jsonl').writeAsStringSync(
|
||||
'${[_userLine('u1', 'hello'), _asstLine('a1', 'hi there')].map(jsonEncode).join('\n')}\n',
|
||||
);
|
||||
|
||||
final bus = MessageBus();
|
||||
addTearDown(bus.dispose);
|
||||
final received = <Message>[];
|
||||
// Subscribe before the publisher starts the reader's first poll.
|
||||
final sub = bus.subscribe(publisher: ClaudeConversation.publisher, channel: ClaudeConversation.leadChannel).listen(received.add);
|
||||
|
||||
final reader = TranscriptReader(
|
||||
workspace,
|
||||
projectsBase: base.path,
|
||||
pollInterval: const Duration(milliseconds: 20),
|
||||
);
|
||||
final pub = TranscriptPublisher(messages: bus, reader: reader);
|
||||
|
||||
await Future<void>.delayed(const Duration(milliseconds: 200));
|
||||
await sub.cancel();
|
||||
await pub.dispose();
|
||||
|
||||
expect(received, hasLength(2));
|
||||
expect(received.every((m) => m.data[ClaudeConversation.itemKey] is ConversationItem), isTrue);
|
||||
final items = received.map((m) => m.data[ClaudeConversation.itemKey]).toList();
|
||||
expect(items.first, isA<UserMessage>());
|
||||
expect((items.first as UserMessage).text, 'hello');
|
||||
expect(items[1], isA<AssistantTextMessage>());
|
||||
});
|
||||
|
||||
test('teammateChannel namespaces by agentId', () {
|
||||
expect(ClaudeConversation.teammateChannel('coder@team-x'), 'conversation/coder@team-x');
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user