spawn terminal panes in the open workspace root (T-381)

The shell spawned with Directory.current — $HOME for desktop-entry
launches, and stale after a project switch since the process CWD
never moves. Use the kernel project root, falling back to the
process CWD only when no project is open.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-12 01:06:45 +02:00
co-authored by Claude Fable 5
parent 5f9c054420
commit 5d9443d9f7
5 changed files with 45 additions and 1 deletions
@@ -6,6 +6,8 @@
/// was never sent and the backend PTY + daemon pane leaked.
library;
import 'dart:io';
import 'package:clide/builtin/terminal/src/terminal_pane.dart';
import 'package:clide/clide.dart';
import 'package:flutter/widgets.dart';
@@ -49,6 +51,30 @@ void main() {
expect(closed, ['pane-7']);
});
testWidgets('spawns the shell in the open workspace, not Directory.current (T-381)', (tester) async {
String? spawnedCwd;
fixture.ipc.setConnected(true);
fixture.ipc.stub('pane.spawn', (args) async {
spawnedCwd = args['cwd'] as String?;
return IpcResponse.ok(id: 'r1', data: {'id': 'pane-9', 'pid': 1});
});
// Open a project so the kernel has a workspace root.
final repo = await tester.runAsync(() async {
final dir = fixture.tempDir.createTempSync('repo-');
Directory('${dir.path}/.git').createSync();
return dir;
});
final opened = await tester.runAsync(() => fixture.services.project.open(repo!.path));
expect(opened, isTrue);
await tester.pumpWidget(harness(fixture, const TerminalPane()));
await pumpAsync(tester);
expect(spawnedCwd, repo!.path);
expect(spawnedCwd, isNot(Directory.current.path));
});
testWidgets('disposing before spawn completes sends no close', (tester) async {
final closed = <String>[];
fixture.ipc.setConnected(false); // spawn bails out: no pane id