test sweep: cover src/pty/env + native_pty error paths (T-91)
test / unit + widget + golden + a11y (push) Failing after 34s
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

Two test additions for the pty subsystem:

- test/pty/env_test.dart (9 tests): PtyException.toString with and
  without errno, expandedPath on every platform branch, mergePtyEnv
  override precedence (clide defaults > process env > explicit
  overrides), clidePtyEnvDefaults shape.
- test/pty/session_test.dart extended (4 new tests): bare-command
  PATH resolution, non-existent workingDirectory triggering the
  chdir-failed diagnostic via the child branch, non-existent
  executable triggering the exec-failed diagnostic, resize on a
  live PTY.

Coverage: pty/env.dart 5/19 -> 9/19 (remaining 10 lines are the
macOS-only PATH-merge branch, only reachable when Platform.isMacOS).
pty/errors.dart 0/4 -> 3/4 (remaining 1 is a const-ctor phantom).
The new pty session tests run under `dart test --tags forkpty` so
their branch coverage doesn't surface via lcov, but the code paths
(chdir failure, execve failure, PATH resolution) are now verified.

Total coverage 79.26% -> 79.34%.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-13 07:18:33 +02:00
co-authored by Claude Opus 4.7
parent b1e9abd6aa
commit 7b9feba987
2 changed files with 170 additions and 0 deletions
+93
View File
@@ -95,5 +95,98 @@ void main() {
await done.future.timeout(const Duration(seconds: 3));
expect(s.isClosed, isTrue);
});
test('bare command name resolves via the PATH env var', () async {
// 'sh' is a bare command; without resolution, execve would fail.
final s = NativePty.start(
executable: 'sh',
arguments: ['-c', 'echo path-resolution-ok'],
columns: 80,
rows: 24,
workingDirectory: '/',
environment: {
...Platform.environment,
'TERM': 'xterm-256color',
},
);
addTearDown(s.close);
final buf = StringBuffer();
final done = Completer<void>();
s.output.listen(
(b) => buf.write(utf8.decode(b, allowMalformed: true)),
onDone: () {
if (!done.isCompleted) done.complete();
},
);
await done.future.timeout(const Duration(seconds: 5), onTimeout: () {});
expect(buf.toString(), contains('path-resolution-ok'));
});
test('non-existent workingDirectory produces the chdir-failed diagnostic', () async {
// chdir() fails in the child → writes diagnostic + _exit(1).
final s = NativePty.start(
executable: '/bin/sh',
arguments: ['-c', 'echo should-not-run'],
columns: 80,
rows: 24,
workingDirectory: '/tmp/clide-no-such-dir-${DateTime.now().microsecondsSinceEpoch}',
environment: {
...Platform.environment,
'TERM': 'xterm-256color',
},
);
addTearDown(s.close);
final buf = StringBuffer();
final done = Completer<void>();
s.output.listen(
(b) => buf.write(utf8.decode(b, allowMalformed: true)),
onDone: () {
if (!done.isCompleted) done.complete();
},
);
await done.future.timeout(const Duration(seconds: 5), onTimeout: () {});
expect(buf.toString(), contains('chdir failed'));
});
test('non-existent executable produces the exec-failed diagnostic', () async {
final s = NativePty.start(
executable: '/tmp/clide-no-such-binary-${DateTime.now().microsecondsSinceEpoch}',
arguments: const [],
columns: 80,
rows: 24,
workingDirectory: '/',
environment: {
...Platform.environment,
'TERM': 'xterm-256color',
},
);
addTearDown(s.close);
final buf = StringBuffer();
final done = Completer<void>();
s.output.listen(
(b) => buf.write(utf8.decode(b, allowMalformed: true)),
onDone: () {
if (!done.isCompleted) done.complete();
},
);
await done.future.timeout(const Duration(seconds: 5), onTimeout: () {});
expect(buf.toString(), contains('exec failed'));
});
test('resize on a live PTY does not throw', () async {
final s = NativePty.start(
executable: '/bin/sh',
arguments: ['-c', 'sleep 0.5'],
columns: 80,
rows: 24,
workingDirectory: '/',
environment: {
...Platform.environment,
'TERM': 'xterm-256color',
},
);
addTearDown(s.close);
s.resize(cols: 120, rows: 30);
});
});
}