Desktop/dock-launched clide inherits a sparse PATH (no ~/.local/bin, brew, nvm, …), so pql/git/claude and PTY tools went missing. T-347 fixed only the toolchain/pql path on Linux; env.dart's expander was still macOS-only and claude/PTY/git used the raw PATH — the breakage recurred per spawn site because there were three divergent expanders. Consolidate into one resolver (lib/src/env/shell_env.dart): - primeLoginShellPath(): probe the user's real login shell once at startup (`$SHELL -l -c`, sentinel-framed, bounded timeout, graceful fallback to the process PATH). Captures the user's actual PATH, not a hardcoded guess. - expandToolPath(): the canonical merge (moved from toolchain_paths, which re-exports it for its tests) — unions the well-known user/local bin dirs. - resolvedToolPath(): currentSearchPath() + expandToolPath, the single call every spawn site uses. Routed through it: PTY children (registry.dart now overrides PATH), git (env.dart → operations.dart), the toolchain probe (toolchain_paths), and hosted claude (agent_bootstrap). Primed in main.dart's !kIsWeb boot. Deleted the macOS-only env.dart copy and the cli_install copy. Tests: new shell_env_test (probe + every fallback + merge); env_test and cli_install_test updated to the consolidated surface. analyze clean, web wasm build still green, make test green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
65 lines
2.2 KiB
Dart
65 lines
2.2 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('posix_spawn', 'kaboom');
|
|
expect(e.toString(), contains('posix_spawn'));
|
|
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 (delegates to the shared resolver, T-439)', () {
|
|
test('non-empty on every platform', () {
|
|
expect(expandedPath, isNotEmpty);
|
|
});
|
|
|
|
test('is a superset of the process PATH (never drops entries)', () {
|
|
final got = expandedPath.split(':').toSet();
|
|
for (final dir in (Platform.environment['PATH'] ?? '').split(':').where((e) => e.isNotEmpty)) {
|
|
expect(got, contains(dir));
|
|
}
|
|
});
|
|
});
|
|
|
|
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');
|
|
});
|
|
});
|
|
}
|