Files
clide/test/builtin/claude/transcript_publisher_test.dart
T
jpmschweitzerandClaude Opus 4.7 0b942db251
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
route Claude transcript content through the MessageBus
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>
2026-05-22 23:03:17 +02:00

84 lines
2.9 KiB
Dart

/// 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');
});
});
}