claude_pane.dart had no widget-test harness, so the T-269 wiring (primary rebind on workspace switch, host tab-reset) shipped uncovered — and the moment any test mounts ClaudePane its 230 lines enter the coverage denominator, which is what sank the gate earlier. Add a real harness: a fake ClaudeSessionOrchestrator (no real `claude` process) plus a connected fake IPC answering files.root, with spawn/respawn driven inside tester.runAsync so the transcript-probe File I/O resolves. Covers spawn-binds-to-repo, in-place rebind, same-repo no-op, send, /clear (in place), /fork, /resume (picker open + cancel), mode cycle, draft round-trip, init-event status, can_use_tool prompt swap, secondary spawn + dispose-close, tap-to-focus, and the disconnected-daemon error path. claude_pane.dart 25% -> 84%; session-host tab-reset covered too. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
95 lines
3.5 KiB
Dart
95 lines
3.5 KiB
Dart
/// Host-level behaviour for the Claude session tabs (T-269): an in-place
|
|
/// workspace switch (Open Project/Folder) must reset to a lone primary tab —
|
|
/// the previous repo's secondaries/forks don't belong in the new workspace.
|
|
///
|
|
/// The embedded [ClaudePane]s take the "daemon not connected" path under the
|
|
/// fake IPC, so no real `claude` process is spawned; this exercises the host's
|
|
/// tab bookkeeping in isolation.
|
|
library;
|
|
|
|
import 'package:clide/builtin/claude/src/claude_session_host.dart';
|
|
import 'package:clide/kernel/kernel.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import '../../helpers/kernel_fixture.dart';
|
|
|
|
Widget _host(KernelFixture f, Key key) => Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: ClideKernel(
|
|
services: f.services,
|
|
child: ClideTheme(
|
|
controller: f.services.theme,
|
|
child: MediaQuery(
|
|
data: const MediaQueryData(),
|
|
child: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: SizedBox(
|
|
// Bounded size so the reorderable tab strip's Draggable has a
|
|
// real width and the Overlay below isn't asked to self-size.
|
|
width: 800,
|
|
height: 600,
|
|
child: Overlay(
|
|
initialEntries: [OverlayEntry(builder: (_) => ClaudeSessionHost(key: key))],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
void main() {
|
|
late KernelFixture f;
|
|
setUp(() async => f = await KernelFixture.create());
|
|
tearDown(() => f.dispose());
|
|
|
|
testWidgets('in-place workspace switch drops secondaries, keeps primary (T-269)', (tester) async {
|
|
final key = GlobalKey<ClaudeSessionHostState>();
|
|
await tester.pumpWidget(_host(f, key));
|
|
await tester.pump();
|
|
final state = key.currentState!;
|
|
|
|
state.addSecondary();
|
|
state.addSecondary();
|
|
await tester.pump();
|
|
expect(state.tabIds, ['primary', 'secondary-1', 'secondary-2']);
|
|
|
|
// Establish the baseline workspace; the first ProjectOpened is the initial
|
|
// open, not a switch, so it must NOT reset anything. (It also resolves each
|
|
// pane's "wait for project" so no spawn timer outlives the widget tree.)
|
|
f.services.events.emit(const ProjectOpened(path: '/repo-a'));
|
|
await tester.pump();
|
|
expect(state.tabIds, ['primary', 'secondary-1', 'secondary-2']);
|
|
|
|
// Switch to a different repo in place → back to just the primary.
|
|
f.services.events.emit(const ProjectOpened(path: '/repo-b'));
|
|
await tester.pump();
|
|
expect(state.tabIds, ['primary']);
|
|
|
|
// The secondary counter resets, so the next secondary is index 1 again.
|
|
// The redundant /repo-b emit resolves the new pane's wait without a reset.
|
|
state.addSecondary();
|
|
f.services.events.emit(const ProjectOpened(path: '/repo-b'));
|
|
await tester.pump();
|
|
expect(state.tabIds, ['primary', 'secondary-1']);
|
|
});
|
|
|
|
testWidgets('re-opening the same workspace is not a switch (no reset) (T-269)', (tester) async {
|
|
final key = GlobalKey<ClaudeSessionHostState>();
|
|
await tester.pumpWidget(_host(f, key));
|
|
await tester.pump();
|
|
final state = key.currentState!;
|
|
|
|
f.services.events.emit(const ProjectOpened(path: '/repo-a'));
|
|
await tester.pump();
|
|
state.addSecondary();
|
|
await tester.pump();
|
|
|
|
// Same path again — a redundant re-open must keep the secondary.
|
|
f.services.events.emit(const ProjectOpened(path: '/repo-a'));
|
|
await tester.pump();
|
|
expect(state.tabIds, ['primary', 'secondary-1']);
|
|
});
|
|
}
|