add panel.resize CLI verb (T-119)
test / unit + widget + golden + a11y (push) Failing after 36s
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 28s
test / unit + widget + golden + a11y (push) Failing after 36s
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 28s
The keyboard half of panel resizing landed in T-111 (arrow-key splitters); this completes D-6 user/Claude parity with a CLI verb now that T-99's IPC dispatch path exists. `clide panel resize <slot> --to N` sets an absolute pixel size, `--by N` nudges relative to current, and the reserved `editor` slot drives the editor/bottom-panel split ratio. The handler lives in panel_commands.dart and stays Flutter-free (so test/daemon/ keeps running under `dart test`) by talking to an abstract PanelResizer; the kernel bridge in panel_resizer_kernel.dart wraps LayoutArrangement and reuses T-111's bumpedSlotSize so the CLI's relative deltas honour the same right-edge sign-flip as the drag/arrow handlers. Arguments are lifted from both the direct call shape and the argv-translator's positional/flags shape pending the typed schema in T-120. The daemonClientFactory now receives the LayoutArrangement so the dispatcher can reach it. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
/// Tests for the `panel.*` command handlers (T-119).
|
||||
///
|
||||
/// Uses an in-memory [PanelResizer] fake so the dispatch surface can
|
||||
/// be exercised under `dart test` without pulling Flutter into the
|
||||
/// build (the live kernel resizer wraps `LayoutArrangement`, which is
|
||||
/// Flutter-bound; tests for that live in
|
||||
/// `test/kernel/src/panels/arrangement_test.dart`).
|
||||
library;
|
||||
|
||||
import 'package:clide/clide.dart';
|
||||
import 'package:clide/src/daemon/panel_commands.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('panel.resize dispatch', () {
|
||||
late DaemonDispatcher dispatcher;
|
||||
late _FakeResizer resizer;
|
||||
|
||||
setUp(() {
|
||||
resizer = _FakeResizer(
|
||||
slots: {'sidebar': 200, 'context': 240, 'workspace': 800},
|
||||
editorRatio: 0.35,
|
||||
);
|
||||
dispatcher = DaemonDispatcher();
|
||||
registerPanelCommands(dispatcher, resizer);
|
||||
});
|
||||
|
||||
Future<IpcResponse> call(Map<String, Object?> args) {
|
||||
return dispatcher.dispatch(IpcRequest(id: '1', cmd: 'panel.resize', args: args));
|
||||
}
|
||||
|
||||
test('rejects a request with no slot', () async {
|
||||
final r = await call(const {'to': 220});
|
||||
expect(r.ok, isFalse);
|
||||
expect(r.error!.kind, 'user_error');
|
||||
expect(r.error!.message, contains('slot'));
|
||||
});
|
||||
|
||||
test('rejects a request with neither `to` nor `by`', () async {
|
||||
final r = await call(const {'slot': 'sidebar'});
|
||||
expect(r.ok, isFalse);
|
||||
expect(r.error!.kind, 'user_error');
|
||||
expect(r.error!.message, contains('to'));
|
||||
expect(r.error!.message, contains('by'));
|
||||
});
|
||||
|
||||
test('rejects a request with both `to` and `by`', () async {
|
||||
final r = await call(const {'slot': 'sidebar', 'to': 200, 'by': 10});
|
||||
expect(r.ok, isFalse);
|
||||
expect(r.error!.kind, 'user_error');
|
||||
expect(r.error!.message, contains('only one'));
|
||||
});
|
||||
|
||||
test('rejects a non-numeric `to`', () async {
|
||||
final r = await call(const {'slot': 'sidebar', 'to': 'lots'});
|
||||
expect(r.ok, isFalse);
|
||||
expect(r.error!.kind, 'user_error');
|
||||
expect(r.error!.message, contains('numeric'));
|
||||
});
|
||||
|
||||
test('rejects an unknown slot with not-found', () async {
|
||||
final r = await call(const {'slot': 'nonsense', 'to': 100});
|
||||
expect(r.ok, isFalse);
|
||||
expect(r.error!.kind, 'not_found');
|
||||
expect(r.error!.message, contains('nonsense'));
|
||||
});
|
||||
|
||||
test('absolute `to` sets the slot size and echoes the result', () async {
|
||||
final r = await call(const {'slot': 'sidebar', 'to': 320});
|
||||
expect(r.ok, isTrue, reason: r.error?.message);
|
||||
expect(r.data['slot'], 'sidebar');
|
||||
expect(r.data['size'], 320);
|
||||
expect(resizer.slots['sidebar'], 320);
|
||||
});
|
||||
|
||||
test('relative `by` bumps the slot through PanelResizer.bumpSlotSize', () async {
|
||||
final r = await call(const {'slot': 'sidebar', 'by': 25});
|
||||
expect(r.ok, isTrue, reason: r.error?.message);
|
||||
expect(resizer.slots['sidebar'], 200 + 25);
|
||||
expect(resizer.lastBumpSlot, 'sidebar');
|
||||
expect(resizer.lastBumpDelta, 25);
|
||||
});
|
||||
|
||||
test('editor slot routes to setEditorRatio', () async {
|
||||
final r = await call(const {'slot': 'editor', 'to': 0.55});
|
||||
expect(r.ok, isTrue, reason: r.error?.message);
|
||||
expect(r.data['ratio'], 0.55);
|
||||
expect(resizer.editorRatio, 0.55);
|
||||
});
|
||||
|
||||
test('editor slot with `by` routes to bumpEditorRatio', () async {
|
||||
final r = await call(const {'slot': 'editor', 'by': 0.1});
|
||||
expect(r.ok, isTrue, reason: r.error?.message);
|
||||
expect(resizer.editorRatio, closeTo(0.45, 1e-9));
|
||||
});
|
||||
|
||||
group('argv-translator shape', () {
|
||||
test('positional[0] supplies the slot and flags carry to/by as strings', () async {
|
||||
final r = await call(const {
|
||||
'positional': ['sidebar'],
|
||||
'flags': {'to': '275'},
|
||||
});
|
||||
expect(r.ok, isTrue, reason: r.error?.message);
|
||||
expect(resizer.slots['sidebar'], 275);
|
||||
});
|
||||
|
||||
test('argv shape `by` parses to a delta', () async {
|
||||
final r = await call(const {
|
||||
'positional': ['context'],
|
||||
'flags': {'by': '-30'},
|
||||
});
|
||||
expect(r.ok, isTrue, reason: r.error?.message);
|
||||
expect(resizer.lastBumpSlot, 'context');
|
||||
expect(resizer.lastBumpDelta, -30);
|
||||
});
|
||||
|
||||
test('argv shape with neither flag still surfaces a user error', () async {
|
||||
final r = await call(const {
|
||||
'positional': ['sidebar'],
|
||||
'flags': <String, Object?>{},
|
||||
});
|
||||
expect(r.ok, isFalse);
|
||||
expect(r.error!.kind, 'user_error');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class _FakeResizer implements PanelResizer {
|
||||
_FakeResizer({required this.slots, required this.editorRatio});
|
||||
|
||||
final Map<String, double> slots;
|
||||
double editorRatio;
|
||||
|
||||
String? lastBumpSlot;
|
||||
double? lastBumpDelta;
|
||||
|
||||
@override
|
||||
bool setSlotSize(String slot, double size) {
|
||||
if (!slots.containsKey(slot)) return false;
|
||||
slots[slot] = size;
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
bool bumpSlotSize(String slot, double rawDelta) {
|
||||
if (!slots.containsKey(slot)) return false;
|
||||
lastBumpSlot = slot;
|
||||
lastBumpDelta = rawDelta;
|
||||
slots[slot] = slots[slot]! + rawDelta;
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
void setEditorRatio(double ratio) {
|
||||
editorRatio = ratio;
|
||||
}
|
||||
|
||||
@override
|
||||
void bumpEditorRatio(double delta) {
|
||||
editorRatio += delta;
|
||||
}
|
||||
|
||||
@override
|
||||
double? currentSlotSize(String slot) => slots[slot];
|
||||
|
||||
@override
|
||||
double get currentEditorRatio => editorRatio;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ class KernelFixture {
|
||||
preloadNamespaces: catalogs.keys.toList(),
|
||||
defaultLocale: defaultLocale,
|
||||
initialLocale: initialLocale,
|
||||
daemonClientFactory: (log, events) {
|
||||
daemonClientFactory: (log, events, _) {
|
||||
fake = FakeDaemonClient(log: log, events: events);
|
||||
return fake!;
|
||||
},
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/// Tests the kernel-side bridge that connects the Flutter-free
|
||||
/// `panel.resize` handler (T-119) to the live [LayoutArrangement].
|
||||
/// The handler-side tests live in
|
||||
/// `test/daemon/panel_commands_test.dart` against an in-memory fake.
|
||||
library;
|
||||
|
||||
import 'package:clide/kernel/kernel.dart';
|
||||
import 'package:clide/src/daemon/panel_resizer_kernel.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('ArrangementPanelResizer', () {
|
||||
late LayoutArrangement arrangement;
|
||||
late ArrangementPanelResizer r;
|
||||
|
||||
setUp(() {
|
||||
arrangement = LayoutArrangement()..applyPreset(classicPreset());
|
||||
r = ArrangementPanelResizer(arrangement);
|
||||
});
|
||||
|
||||
test('setSlotSize forwards to LayoutArrangement.setSize and clamps', () {
|
||||
final ok = r.setSlotSize('sidebar', 10000);
|
||||
expect(ok, isTrue);
|
||||
expect(arrangement.sizeOf(Slots.sidebar), arrangement.maxSizeOf(Slots.sidebar));
|
||||
expect(r.currentSlotSize('sidebar'), arrangement.sizeOf(Slots.sidebar));
|
||||
});
|
||||
|
||||
test('setSlotSize returns false for an unknown slot', () {
|
||||
expect(r.setSlotSize('does-not-exist', 250), isFalse);
|
||||
});
|
||||
|
||||
test('bumpSlotSize applies the T-111 sign-flip on context panel', () {
|
||||
final start = arrangement.sizeOf(Slots.contextPanel)!;
|
||||
final ok = r.bumpSlotSize('context', 40);
|
||||
expect(ok, isTrue);
|
||||
// Context sits on the right edge — positive delta shrinks it.
|
||||
expect(arrangement.sizeOf(Slots.contextPanel), lessThan(start));
|
||||
});
|
||||
|
||||
test('bumpSlotSize returns false for an unknown slot', () {
|
||||
expect(r.bumpSlotSize('nope', 5), isFalse);
|
||||
});
|
||||
|
||||
test('setEditorRatio + currentEditorRatio round-trip through arrangement', () {
|
||||
r.setEditorRatio(0.5);
|
||||
expect(arrangement.editorRatio, 0.5);
|
||||
expect(r.currentEditorRatio, 0.5);
|
||||
});
|
||||
|
||||
test('bumpEditorRatio adds to current ratio (kernel re-clamps)', () {
|
||||
r.setEditorRatio(0.4);
|
||||
r.bumpEditorRatio(0.2);
|
||||
expect(arrangement.editorRatio, closeTo(0.60, 1e-9));
|
||||
r.bumpEditorRatio(1.0); // out-of-range; kernel clamps to 0.70
|
||||
expect(arrangement.editorRatio, 0.70);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user