Files
clide/test/pty/session_test.dart
T
jpmschweitzerandClaude 37108230f2
test / unit + widget + golden + a11y (push) Failing after 37s
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
decouple Pane from PtySession so the web build compiles
Pane is now a pure data class — id, kind, pid, argv, cwd, title,
isClosed. The daemon-side PaneRegistry holds a parallel map of
PtySession keyed on id; registry methods look up both sides when
writing / resizing / closing.

The `clide.dart` barrel no longer re-exports `src/pty/*`,
`src/panes/registry.dart`, or the `*_commands.dart` modules — all
three transitively import `dart:ffi` which isn't available when
compiling to WebAssembly. The daemon entrypoint (bin/clide.dart) +
core tests import them via deep paths now. Pane / PaneKind /
DaemonEventSink / RecordingEventSink stay in the barrel since
they're pure data the Flutter app references over IPC.

Verified: `dart analyze` clean, 53 core tests green, 174 app tests
green, `make ui-smoke` compiles + serves + Playwright smoke passes,
daemon boots + ping round-trips + SIGTERMs cleanly.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-22 10:01:06 +02:00

115 lines
3.5 KiB
Dart

/// `PtySession` smoke tests.
///
/// Exercises the real `ptyc` binary end-to-end: socketpair → spawn →
/// SCM_RIGHTS fd receive → child output through the reader isolate.
/// Linux + macOS only; skipped elsewhere.
library;
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:clide/src/pty/pty.dart';
import 'package:test/test.dart';
void main() {
if (!Platform.isLinux && !Platform.isMacOS) {
return; // POSIX-only wrapper for now.
}
final ptycPath = _resolvePtyc();
group('PtySession', () {
test('spawns /bin/echo and reads its output', () async {
final s = await PtySession.spawn(
argv: const ['/bin/echo', 'hello-pty'],
ptycPath: ptycPath,
);
addTearDown(s.close);
final buf = StringBuffer();
final sub = s.output.listen((bytes) => buf.write(utf8.decode(bytes)));
try {
// echo exits quickly; give the reader up to 2s to see its
// output before we assert.
await Future<void>.delayed(const Duration(milliseconds: 500));
for (var i = 0; i < 20 && !buf.toString().contains('hello-pty'); i++) {
await Future<void>.delayed(const Duration(milliseconds: 100));
}
} finally {
await sub.cancel();
}
expect(buf.toString(), contains('hello-pty'));
expect(s.pid, greaterThan(0));
});
test('write round-trips through /bin/cat', () async {
final s = await PtySession.spawn(
argv: const ['/bin/cat'],
ptycPath: ptycPath,
);
addTearDown(s.close);
final got = Completer<String>();
final buf = StringBuffer();
s.output.listen((bytes) {
buf.write(utf8.decode(bytes));
if (buf.toString().contains('echo-me')) {
if (!got.isCompleted) got.complete(buf.toString());
}
});
// Give the PTY a moment to be ready.
await Future<void>.delayed(const Duration(milliseconds: 100));
s.write(utf8.encode('echo-me\n'));
final out = await got.future.timeout(const Duration(seconds: 3));
expect(out, contains('echo-me'));
});
test('COLORTERM truecolor propagates to the child', () async {
// `/usr/bin/env` prints the child's environment. We should see
// COLORTERM=truecolor because clidePtyEnvDefaults sets it.
final s = await PtySession.spawn(
argv: const ['/usr/bin/env'],
ptycPath: ptycPath,
);
addTearDown(s.close);
final buf = StringBuffer();
final sub = s.output.listen((bytes) => buf.write(utf8.decode(bytes)));
try {
for (var i = 0; i < 20; i++) {
if (buf.toString().contains('COLORTERM=truecolor')) break;
await Future<void>.delayed(const Duration(milliseconds: 100));
}
} finally {
await sub.cancel();
}
expect(buf.toString(), contains('COLORTERM=truecolor'));
expect(buf.toString(), contains('TERM=xterm-256color'));
});
test('close is idempotent and stops the stream', () async {
final s = await PtySession.spawn(
argv: const ['/bin/cat'],
ptycPath: ptycPath,
);
expect(s.isClosed, isFalse);
await s.close();
expect(s.isClosed, isTrue);
await s.close(); // second call should not throw
});
});
}
/// Locate the `ptyc` binary relative to the repo root, falling back to
/// PATH. Lets tests run in fresh clones before anyone's touched PATH.
String _resolvePtyc() {
final devPath = File('ptyc/bin/ptyc');
if (devPath.existsSync()) return devPath.absolute.path;
return 'ptyc';
}