Files
clide/test/panes/registry_test.dart
T
jpmschweitzerandClaude Opus 4.7 72a3dce4a3
test / unit + widget + golden + a11y (push) Failing after 32s
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 1m2s
test sweep: foundational systems — files / ipc errno / panes (T-91)
Three small foundational test additions:

- test/files/watcher_test.dart (new, 8 tests): FileChangeKind
  fromEvent across every FileSystemEvent.type + wire getter,
  FileChange.toJson, FileWatcher end-to-end (created event,
  ignored-path filtering, idempotent start, stop teardown).
- ignore_test: trailing /**, bare **, ? glob-pattern branches in
  the regex compiler.
- path_safety_test: PathOutsideRoot.toString embeds the three
  fields.
- ipc/errno_mapping_test: ENOTDIR / ENOMEM / EAGAIN branches in
  errnoToIpcError that weren't previously hit.
- panes/registry_test: RecordingEventSink.ofSubsystem filter.

Coverage: src/files/watcher.dart 10/36 -> ~ all; ignore.dart +
path_safety.dart residuals closed; ipc/errno_mapping.dart 3 added
branches; panes/event_sink.dart 100%.

Total coverage 90.53% -> 90.99%.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 10:19:07 +02:00

120 lines
3.9 KiB
Dart

/// Unit tests for [PaneRegistry].
///
/// Exercises spawn / list / write / resize / close against the real
/// NativePty (forkpty via FFI). Events are captured via
/// [RecordingEventSink].
library;
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:clide/clide.dart';
import 'package:clide/src/panes/registry.dart';
import 'package:test/test.dart';
void main() {
if (!Platform.isLinux && !Platform.isMacOS) return;
group('PaneRegistry', () {
late RecordingEventSink sink;
late PaneRegistry registry;
setUp(() {
sink = RecordingEventSink();
registry = PaneRegistry(events: sink);
});
tearDown(() => registry.shutdown());
test('spawn → emits pane.spawned and lists the pane', () async {
final pane = await registry.spawn(
kind: PaneKind.terminal,
argv: const ['/bin/echo', 'hi'],
);
expect(pane.id, startsWith('p_'));
expect(pane.kind, PaneKind.terminal);
expect(registry.panes, contains(pane));
expect(sink.ofKind('pane.spawned'), hasLength(1));
final evt = sink.ofKind('pane.spawned').first;
expect(evt.data['id'], pane.id);
});
test('output events base64-encode the child bytes', tags: ['forkpty'], () async {
await registry.spawn(
kind: PaneKind.terminal,
argv: const ['/bin/echo', 'hello-panes'],
);
// /bin/echo closes its pty quickly. Wait briefly for output +
// the resulting pane.exit event to settle.
for (var i = 0; i < 30; i++) {
if (sink.ofKind('pane.output').isNotEmpty && sink.ofKind('pane.exit').isNotEmpty) break;
await Future<void>.delayed(const Duration(milliseconds: 100));
}
final out = sink.ofKind('pane.output').toList();
expect(out, isNotEmpty);
final decoded = out.map((e) => utf8.decode(base64Decode(e.data['bytes_b64']! as String))).join();
expect(decoded, contains('hello-panes'));
});
test('write + resize emit no spurious events, update state', () async {
final pane = await registry.spawn(
kind: PaneKind.terminal,
argv: const ['/bin/cat'],
);
final writeCount = registry.write(pane.id, utf8.encode('abc'));
expect(writeCount, greaterThan(0));
registry.resize(pane.id, cols: 120, rows: 40);
final resized = sink.ofKind('pane.resized').toList();
expect(resized, hasLength(1));
expect(resized.single.data['cols'], 120);
expect(resized.single.data['rows'], 40);
});
test('close is idempotent + emits pane.closed once', () async {
final pane = await registry.spawn(
kind: PaneKind.terminal,
argv: const ['/bin/cat'],
);
await registry.close(pane.id);
await registry.close(pane.id); // second call: no-op
expect(registry.get(pane.id), isNull);
expect(sink.ofKind('pane.closed'), hasLength(1));
});
test('close on unknown id does nothing', () async {
await registry.close('p_nonexistent');
expect(sink.ofKind('pane.closed'), isEmpty);
});
test('claude kind round-trips on the wire', () async {
final pane = await registry.spawn(
kind: PaneKind.claude,
argv: const ['/bin/sh', '-c', 'exit 0'],
);
expect(pane.kind, PaneKind.claude);
expect(pane.toJson()['kind'], 'claude');
});
});
group('RecordingEventSink filters', () {
test('ofSubsystem narrows events to a single subsystem', () {
final s = RecordingEventSink();
final ts = DateTime.now().toUtc();
s.emit(IpcEvent(subsystem: 'pane', kind: 'spawned', timestamp: ts, data: const {}));
s.emit(IpcEvent(subsystem: 'git', kind: 'changed', timestamp: ts, data: const {}));
s.emit(IpcEvent(subsystem: 'pane', kind: 'closed', timestamp: ts, data: const {}));
expect(s.ofSubsystem('pane'), hasLength(2));
expect(s.ofSubsystem('git'), hasLength(1));
expect(s.ofSubsystem('files'), isEmpty);
});
});
}