Files
clide/test/daemon/dispatcher_test.dart
T
jpmschweitzerandClaude Opus 4.7 e430a87569 test sweep: kernel commands + widgets coverage, ratchet floor to 93
Add tests for `keybindings.dart` (KeyEvent → Keybinding mapping,
parse-error edges, resolver entries view), `toolchain_paths.dart`
(the Flutter-free `ToolchainView.resolved` static view), and several
`widgets/src/` primitives: tooltip hover/overlay, palette filter +
submit, multitab controller `copyWith` + size getters, and additional
markdown branches (h3–h6 headings, tables, strikethrough, default
block fallback, record-link tap).

Unfreezes the pre-push coverage floor that was held at 90 on
2026-05-14 by mistake and ratchets to 93. Tidies eight test files
that had accumulated unused imports flagged by `unnecessary_import`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-17 20:20:37 +02:00

69 lines
2.3 KiB
Dart

/// Unit tests for the daemon's command dispatcher.
library;
import 'package:clide/clide.dart';
import 'package:test/test.dart';
IpcRequest _req(String cmd, {String id = '1', Map<String, Object?> args = const {}}) {
return IpcRequest(id: id, cmd: cmd, args: args);
}
void main() {
group('DaemonDispatcher', () {
test('ping is registered by default and returns pong + version', () async {
final d = DaemonDispatcher();
final r = await d.dispatch(_req('ping'));
expect(r.ok, isTrue);
expect(r.data['pong'], isTrue);
expect(r.data['version'], isNotNull);
expect(r.data['ts'], isA<String>());
});
test('version returns the bundled version string', () async {
final d = DaemonDispatcher();
final r = await d.dispatch(_req('version'));
expect(r.ok, isTrue);
expect(r.data['version'], clideVersion);
});
test('dispatching an unknown command produces a not-found error', () async {
final d = DaemonDispatcher();
final r = await d.dispatch(_req('nonsense'));
expect(r.ok, isFalse);
expect(r.error?.kind, IpcErrorKind.notFound);
expect(r.error?.message, contains('unknown command'));
});
test('register routes a new handler', () async {
final d = DaemonDispatcher();
d.register('echo', (req) async {
return IpcResponse.ok(id: req.id, data: {'echo': req.args['text']});
});
final r = await d.dispatch(_req('echo', args: {'text': 'hi'}));
expect(r.ok, isTrue);
expect(r.data['echo'], 'hi');
});
test('isEmpty is true for a fresh dispatcher (ping + version only)', () {
final d = DaemonDispatcher();
expect(d.isEmpty, isTrue);
d.register('something', (req) async => IpcResponse.ok(id: req.id, data: const {}));
expect(d.isEmpty, isFalse);
});
test('clear removes user handlers but keeps ping + version', () async {
final d = DaemonDispatcher();
d.register('extra', (req) async => IpcResponse.ok(id: req.id, data: const {}));
expect(d.isEmpty, isFalse);
d.clear();
expect(d.isEmpty, isTrue);
// ping still works
final r = await d.dispatch(_req('ping'));
expect(r.ok, isTrue);
// 'extra' is gone
final r2 = await d.dispatch(_req('extra'));
expect(r2.ok, isFalse);
});
});
}