T-129: event streaming over the socket — clide tail --events
Sixth slice of T-99. Long-lived event subscription path, the second
half of D-6.
Wire shape:
- Client sends `{cmd:"tail", args:{flags:{events:true, filter:X}}}`.
- Server responds with `{ok:true, data:{streaming:true, filter:X}}`.
- Server pushes `{type:"event", subsystem, kind, ts, data}` lines
until the client closes.
Server (lib/src/ipc/server.dart):
- Takes a DaemonBus, subscribes to DaemonEvent on start.
- Per-subsystem ring buffer (replayDepth=16 per D-6) populated on
every emit.
- `tail --events` connection: send ack, replay matching events from
ring, register the client for future fanout.
- _argv envelope now unwrapped at the server layer so the streaming
check sees the inner `tail` cmd (not just `_argv`).
- Broken subscriber writes drop the subscriber cleanly; the bus
doesn't block on a stalled client.
Client (native/clide-cli/clide.c):
- Sniffs `data.streaming:true` in the ack. If set, loops reading
JSON-line events to stdout (with fflush per line) until EOF.
Tests:
- test/ipc/server_streaming_test.dart — 8 cases covering ack shape,
filter, replay buffer (size + ordering), multi-subscriber fanout,
broken-subscriber cleanup.
- test/cli/clide_cli_e2e_test.dart gets a tail --events test that
spawns the C client, emits two events on the bus, asserts they
print on stdout.
T-99 children remaining: T-130 (MCP), T-131 (wrap-up).
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,8 @@ library;
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:clide/kernel/src/events/bus.dart';
|
||||
import 'package:clide/kernel/src/events/types.dart';
|
||||
import 'package:clide/kernel/src/log.dart';
|
||||
import 'package:clide/src/cli/argv_dispatch.dart';
|
||||
import 'package:clide/src/daemon/dispatcher.dart';
|
||||
@@ -25,6 +27,7 @@ void main() {
|
||||
late final Directory workspaceRoot;
|
||||
late final IpcServer server;
|
||||
late final DaemonDispatcher dispatcher;
|
||||
late final DaemonBus streamingBus;
|
||||
|
||||
setUpAll(() async {
|
||||
final repoRoot = Directory.current.path;
|
||||
@@ -52,10 +55,12 @@ void main() {
|
||||
Directory('${workspaceRoot.path}/.git').createSync();
|
||||
dispatcher = DaemonDispatcher();
|
||||
registerArgvUnwrap(dispatcher);
|
||||
streamingBus = DaemonBus();
|
||||
server = IpcServer(
|
||||
dispatcher: dispatcher,
|
||||
workspaceRoot: workspaceRoot.path,
|
||||
log: Logger(minLevel: LogLevel.error, sinks: const []),
|
||||
events: streamingBus,
|
||||
);
|
||||
await server.start();
|
||||
});
|
||||
@@ -65,6 +70,7 @@ void main() {
|
||||
try {
|
||||
await server.stop();
|
||||
} catch (_) {}
|
||||
await streamingBus.dispose();
|
||||
if (workspaceRoot.existsSync()) {
|
||||
workspaceRoot.deleteSync(recursive: true);
|
||||
}
|
||||
@@ -134,5 +140,36 @@ void main() {
|
||||
expect(r.exitCode, isNot(0));
|
||||
expect(r.stderr.toString(), isNotEmpty);
|
||||
});
|
||||
|
||||
test('tail --events streams bus events to stdout (T-129)', () async {
|
||||
if (!hasCC) {
|
||||
markTestSkipped('cc not available');
|
||||
return;
|
||||
}
|
||||
final proc = await Process.start(binaryPath, ['tail', '--events', '--filter', 'pane'], workingDirectory: workspaceRoot.path);
|
||||
addTearDown(() => proc.kill());
|
||||
final lines = <String>[];
|
||||
final sub = proc.stdout.transform(utf8.decoder).transform(const LineSplitter()).listen(lines.add);
|
||||
addTearDown(sub.cancel);
|
||||
// Wait for the ack so the server has registered us.
|
||||
var attempts = 0;
|
||||
while (lines.isEmpty && attempts < 50) {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 20));
|
||||
attempts++;
|
||||
}
|
||||
expect(lines, isNotEmpty, reason: 'no ack received');
|
||||
// Emit two events.
|
||||
streamingBus.emit(DaemonEvent(subsystem: 'pane', kind: 'spawned', data: const {'id': 'p1'}, ts: DateTime.now().toUtc()));
|
||||
streamingBus.emit(DaemonEvent(subsystem: 'pane', kind: 'closed', data: const {'id': 'p1'}, ts: DateTime.now().toUtc()));
|
||||
attempts = 0;
|
||||
while (lines.length < 3 && attempts < 100) {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 20));
|
||||
attempts++;
|
||||
}
|
||||
expect(lines.length, greaterThanOrEqualTo(3), reason: 'expected ack + 2 events, got: $lines');
|
||||
final concatenated = lines.skip(1).join('\n');
|
||||
expect(concatenated, contains('"kind":"spawned"'));
|
||||
expect(concatenated, contains('"kind":"closed"'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user