replace ptyc with forkpty() via Dart FFI
test / unit + widget + golden + a11y (push) Failing after 3m13s
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 / unit + widget + golden + a11y (push) Failing after 3m13s
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
NativePty calls forkpty() directly — no helper binary, no socketpair, no SCM_RIGHTS. The master fd stays in-process. Reader isolate uses poll() for clean shutdown. Based on the pty-spike proof-of-concept. Platform-aware: macOS uses libSystem (DynamicLibrary.process), Linux needs libutil.so.1. TIOCSWINSZ platform-detected. PaneRegistry updated to use NativePty. registerPaneCommands no longer needs a Toolchain parameter. All ptyc references removed from the daemon layer. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
cf2ae48201
commit
5aa0eb46e4
@@ -28,7 +28,7 @@ void main() {
|
||||
final sink = RecordingEventSink();
|
||||
registry = PaneRegistry(events: sink);
|
||||
dispatcher = DaemonDispatcher();
|
||||
registerPaneCommands(dispatcher, registry, toolchain: toolchain);
|
||||
registerPaneCommands(dispatcher, registry);
|
||||
});
|
||||
|
||||
tearDown(() => registry.shutdown());
|
||||
|
||||
@@ -35,7 +35,6 @@ void main() {
|
||||
final pane = await registry.spawn(
|
||||
kind: PaneKind.terminal,
|
||||
argv: const ['/bin/echo', 'hi'],
|
||||
ptycPath: ptycPath,
|
||||
);
|
||||
|
||||
expect(pane.id, startsWith('p_'));
|
||||
@@ -50,7 +49,6 @@ void main() {
|
||||
await registry.spawn(
|
||||
kind: PaneKind.terminal,
|
||||
argv: const ['/bin/echo', 'hello-panes'],
|
||||
ptycPath: ptycPath,
|
||||
);
|
||||
|
||||
// /bin/echo closes its pty quickly. Wait briefly for output +
|
||||
@@ -73,7 +71,6 @@ void main() {
|
||||
final pane = await registry.spawn(
|
||||
kind: PaneKind.terminal,
|
||||
argv: const ['/bin/cat'],
|
||||
ptycPath: ptycPath,
|
||||
);
|
||||
|
||||
final writeCount = registry.write(pane.id, utf8.encode('abc'));
|
||||
@@ -90,7 +87,6 @@ void main() {
|
||||
final pane = await registry.spawn(
|
||||
kind: PaneKind.terminal,
|
||||
argv: const ['/bin/cat'],
|
||||
ptycPath: ptycPath,
|
||||
);
|
||||
|
||||
await registry.close(pane.id);
|
||||
@@ -109,7 +105,6 @@ void main() {
|
||||
final pane = await registry.spawn(
|
||||
kind: PaneKind.claude,
|
||||
argv: const ['/bin/sh', '-c', 'exit 0'],
|
||||
ptycPath: ptycPath,
|
||||
);
|
||||
expect(pane.kind, PaneKind.claude);
|
||||
expect(pane.toJson()['kind'], 'claude');
|
||||
|
||||
+61
-81
@@ -1,114 +1,94 @@
|
||||
/// `PtySession` smoke tests.
|
||||
/// NativePty 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.
|
||||
/// Exercises forkpty() end-to-end: spawn → 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:clide/src/pty/native_pty.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
if (!Platform.isLinux && !Platform.isMacOS) {
|
||||
return; // POSIX-only wrapper for now.
|
||||
}
|
||||
if (!Platform.isLinux && !Platform.isMacOS) return;
|
||||
|
||||
final ptycPath = _resolvePtyc();
|
||||
final shell = Platform.environment['SHELL'] ?? '/bin/zsh';
|
||||
|
||||
group('PtySession', () {
|
||||
test('spawns /bin/echo and reads its output', () async {
|
||||
final s = await PtySession.spawn(
|
||||
argv: const ['/bin/echo', 'hello-pty'],
|
||||
ptycPath: ptycPath,
|
||||
group('NativePty', () {
|
||||
test('spawns shell -c echo and reads output', () async {
|
||||
final s = NativePty.start(
|
||||
executable: shell,
|
||||
arguments: ['-l', '-c', 'echo hello-pty'],
|
||||
columns: 80,
|
||||
rows: 24,
|
||||
workingDirectory: Platform.environment['HOME'] ?? '/',
|
||||
environment: {
|
||||
...Platform.environment,
|
||||
'TERM': 'xterm-256color',
|
||||
},
|
||||
);
|
||||
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();
|
||||
}
|
||||
s.output.listen((bytes) => buf.write(utf8.decode(bytes, allowMalformed: true)));
|
||||
|
||||
// Shell exits quickly; give reader up to 3s.
|
||||
for (var i = 0; i < 30 && !buf.toString().contains('hello-pty'); i++) {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
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,
|
||||
test('write sends keystrokes to child', () async {
|
||||
final s = NativePty.start(
|
||||
executable: shell,
|
||||
arguments: ['-l'],
|
||||
columns: 80,
|
||||
rows: 24,
|
||||
workingDirectory: Platform.environment['HOME'] ?? '/',
|
||||
environment: {
|
||||
...Platform.environment,
|
||||
'TERM': 'xterm-256color',
|
||||
},
|
||||
);
|
||||
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();
|
||||
s.output.listen((bytes) => buf.write(utf8.decode(bytes, allowMalformed: true)));
|
||||
|
||||
// Wait for prompt.
|
||||
await Future<void>.delayed(const Duration(seconds: 1));
|
||||
|
||||
// Type a command.
|
||||
s.write(utf8.encode('echo write-test-ok\n'));
|
||||
|
||||
for (var i = 0; i < 30 && !buf.toString().contains('write-test-ok'); i++) {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
|
||||
expect(buf.toString(), contains('COLORTERM=truecolor'));
|
||||
expect(buf.toString(), contains('TERM=xterm-256color'));
|
||||
expect(buf.toString(), contains('write-test-ok'));
|
||||
});
|
||||
|
||||
test('close is idempotent and stops the stream', () async {
|
||||
final s = await PtySession.spawn(
|
||||
argv: const ['/bin/cat'],
|
||||
ptycPath: ptycPath,
|
||||
test('close kills child and closes output', () async {
|
||||
final s = NativePty.start(
|
||||
executable: shell,
|
||||
arguments: ['-l'],
|
||||
columns: 80,
|
||||
rows: 24,
|
||||
workingDirectory: Platform.environment['HOME'] ?? '/',
|
||||
environment: {
|
||||
...Platform.environment,
|
||||
'TERM': 'xterm-256color',
|
||||
},
|
||||
);
|
||||
expect(s.isClosed, isFalse);
|
||||
|
||||
final done = Completer<void>();
|
||||
s.output.listen((_) {}, onDone: () => done.complete());
|
||||
|
||||
await s.close();
|
||||
await done.future.timeout(const Duration(seconds: 3));
|
||||
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';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user