add Dart PTY wrapper and test-core harness
PtySession wraps the ptyc helper: socketpair + Process.start + recvmsg with SCM_RIGHTS for master-fd transfer, a background isolate that loops on blocking read() and posts byte chunks, plus write/resize/ kill/close. close() SIGTERMs the child so the PTY's EOF wakes the reader naturally; SIGKILL + fd close + isolate kill cover the edge where the shell ignores SIGTERM — avoids the known Linux quirk where closing an fd doesn't unblock an in-flight read() on it. Env defaults stamp TERM=xterm-256color, COLORTERM=truecolor, CLICOLOR_FORCE=1 so shells + tmux + Claude emit 24-bit sequences that xterm.dart can render. User env (HOME / USER / SHELL) still inherits via mergePtyEnv(). ffi: 2.1.3 added as a runtime dep — the FFI bindings for socketpair, recvmsg, read/write, and ioctl(TIOCSWINSZ) need an allocator we're not writing by hand. Justified in pubspec + listed in licenses.yaml per D-042. make test-core (ci/test_core.sh) runs the Flutter-free core tests under a 120s hard timeout with setsid + process-group kill, wired ahead of the fast app tests in push-check so a hung PTY test can't wedge a pre-push. Current core suite: 24 tests in ~1s. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/// Default environment for PTY-spawned children.
|
||||
///
|
||||
/// `xterm.dart` on the UI side + most shells + tmux + Claude CLI all
|
||||
/// understand the 24-bit-colour triplet `TERM=xterm-256color` +
|
||||
/// `COLORTERM=truecolor`. Without `COLORTERM` most apps fall back to
|
||||
/// the 256-colour palette and the terminal looks washed out even though
|
||||
/// the renderer can do true colour.
|
||||
library;
|
||||
|
||||
/// Base env clide's daemon builds for every PTY child. Callers merge
|
||||
/// with the user's environment before passing to `ptyc` — a child that
|
||||
/// needs user env like `HOME` / `USER` / `SHELL` still gets them; the
|
||||
/// keys here override the ones the child cares about.
|
||||
const Map<String, String> clidePtyEnvDefaults = {
|
||||
'TERM': 'xterm-256color',
|
||||
'COLORTERM': 'truecolor',
|
||||
// Encourages 24-bit emission from tooling that checks this:
|
||||
'CLICOLOR_FORCE': '1',
|
||||
// tmux inherits these when clide spawns tmux; safe to propagate.
|
||||
'LANG': 'en_US.UTF-8',
|
||||
'LC_ALL': 'en_US.UTF-8',
|
||||
};
|
||||
|
||||
/// Merge [base] onto the process environment; clide defaults override
|
||||
/// user env where they overlap. Explicit [overrides] win over both.
|
||||
Map<String, String> mergePtyEnv({
|
||||
required Map<String, String> processEnv,
|
||||
Map<String, String>? overrides,
|
||||
}) {
|
||||
return {
|
||||
...processEnv,
|
||||
...clidePtyEnvDefaults,
|
||||
if (overrides != null) ...overrides,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user