rebind the Claude pane on an in-place workspace switch (T-269)
Separate clide windows are isolated (own process, per-root IPC socket, per-repo deterministic session id), so parallel repos in separate windows were already fine. But switching the workspace in place (Open Project / Open Folder) only emitted ProjectOpened — nothing rebound the Claude session, so the primary pane kept the PREVIOUS repo's conversation. Two compounding causes, fixed in layers: - ClaudeSessionOrchestrator.spawn() was idempotent on the literal key 'primary' without checking cwd, so it handed the old repo's session to the new repo. It now reuses a cached session only when its cwd matches the spec; a mismatch tears the stale one down and spawns fresh. - The primary ClaudePane is built once behind a GlobalKey and spawns once, so it never re-resolved. It now listens for ProjectOpened and rebinds: close its orchestrator entry, drop the cached session id + repo root, and respawn against the now-active repo. Secondaries don't self-rebind. - ClaudeSessionHost drops the old repo's secondary/fork tabs on a switch, so a switched workspace starts like a fresh launch (lone primary). - The extension closes any remaining sessions whose cwd != the new root, catching team/non-pane sessions no pane owns. Tested at the orchestrator: cwd-aware idempotency (reuse on cwd match, teardown + respawn on mismatch). Pane/host widget coverage is intentionally deferred — claude_pane.dart has no widget-test harness yet and pulling it into coverage piecemeal would drop the gate; tracked separately. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -47,11 +47,11 @@ ClaudeSessionOrchestrator _orch(List<_FakeProc> created) {
|
||||
);
|
||||
}
|
||||
|
||||
SpawnSpec _spec(String id, {bool resume = false, String? transcriptPath}) => SpawnSpec(
|
||||
SpawnSpec _spec(String id, {bool resume = false, String? transcriptPath, String cwd = '/repo'}) => SpawnSpec(
|
||||
id: id,
|
||||
role: id,
|
||||
sessionId: '$id-uuid',
|
||||
cwd: '/repo',
|
||||
cwd: cwd,
|
||||
resume: resume,
|
||||
transcriptPath: transcriptPath,
|
||||
);
|
||||
@@ -140,6 +140,40 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
// ---- in-place workspace switch (T-269) ---------------------------------
|
||||
|
||||
group('spawn — cwd-aware idempotency (T-269)', () {
|
||||
late List<_FakeProc> created;
|
||||
late ClaudeSessionOrchestrator orch;
|
||||
|
||||
setUp(() {
|
||||
created = [];
|
||||
orch = _orch(created);
|
||||
});
|
||||
|
||||
tearDown(() => orch.dispose());
|
||||
|
||||
test('same id + same cwd reuses the session (no second process)', () async {
|
||||
final a = await orch.spawn(_spec('primary', cwd: '/repo-a'));
|
||||
final b = await orch.spawn(_spec('primary', cwd: '/repo-a'));
|
||||
expect(identical(a, b), isTrue);
|
||||
expect(created, hasLength(1));
|
||||
});
|
||||
|
||||
test('same id + different cwd tears down the old session and spawns fresh', () async {
|
||||
// Workspace switched in place: the new repo must NOT inherit the old
|
||||
// repo's 'primary' session.
|
||||
final a = await orch.spawn(_spec('primary', cwd: '/repo-a'));
|
||||
final b = await orch.spawn(_spec('primary', cwd: '/repo-b'));
|
||||
expect(identical(a, b), isFalse);
|
||||
expect(b.cwd, '/repo-b');
|
||||
expect(created, hasLength(2));
|
||||
expect(created.first.killed, isTrue, reason: 'old repo session is killed');
|
||||
expect(orch.sessions, hasLength(1));
|
||||
expect(orch.byId('primary')!.cwd, '/repo-b');
|
||||
});
|
||||
});
|
||||
|
||||
// ---- /resume — bind to an existing session via orchestrator -------------
|
||||
|
||||
group('/resume — resume an existing session via orchestrator', () {
|
||||
|
||||
Reference in New Issue
Block a user