Files
clide/test/pty/env_test.dart
T
jpmschweitzerandClaude Opus 4.7 7b9feba987
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
test sweep: cover src/pty/env + native_pty error paths (T-91)
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>
2026-05-13 07:18:33 +02:00

78 lines
2.5 KiB
Dart

/// Unit tests for `lib/src/pty/env.dart` and
/// `lib/src/pty/errors.dart`.
library;
import 'dart:io';
import 'package:clide/src/pty/env.dart';
import 'package:clide/src/pty/errors.dart';
import 'package:test/test.dart';
void main() {
group('PtyException', () {
test('toString includes the op + message', () {
const e = PtyException('forkpty', 'kaboom');
expect(e.toString(), contains('forkpty'));
expect(e.toString(), contains('kaboom'));
expect(e.toString(), isNot(contains('errno=')));
});
test('toString embeds errno when present', () {
const e = PtyException('execve', 'no such file', errno: 2);
expect(e.toString(), contains('errno=2'));
});
});
group('expandedPath', () {
test('returns a non-empty string on every platform', () {
expect(expandedPath, isNotEmpty);
});
test('on Linux/Windows, equals Platform.environment[PATH]', () {
if (Platform.isMacOS) return; // macOS path-merge tested separately.
expect(expandedPath, Platform.environment['PATH']);
});
test('on macOS, includes the well-known extras', () {
if (!Platform.isMacOS) return;
// Homebrew is the canonical one; at least one of these should appear.
expect(
expandedPath,
anyOf(contains('/opt/homebrew/bin'), contains('/usr/local/bin')),
);
});
});
group('mergePtyEnv', () {
test('clide defaults override the process env where they overlap', () {
final merged = mergePtyEnv(processEnv: {
'TERM': 'dumb',
'CUSTOM': 'preserved',
});
expect(merged['TERM'], 'xterm-256color'); // clide default wins
expect(merged['COLORTERM'], 'truecolor');
expect(merged['CUSTOM'], 'preserved'); // process env retained
});
test('overrides win over both process env and clide defaults', () {
final merged = mergePtyEnv(
processEnv: {'TERM': 'dumb'},
overrides: {'TERM': 'screen-256color'},
);
expect(merged['TERM'], 'screen-256color');
});
test('no overrides argument is equivalent to overrides = null', () {
final a = mergePtyEnv(processEnv: const {'X': '1'});
final b = mergePtyEnv(processEnv: const {'X': '1'}, overrides: null);
expect(a, b);
});
test('clidePtyEnvDefaults set the expected truecolour keys', () {
expect(clidePtyEnvDefaults['TERM'], 'xterm-256color');
expect(clidePtyEnvDefaults['COLORTERM'], 'truecolor');
expect(clidePtyEnvDefaults['CLICOLOR_FORCE'], '1');
});
});
}