test / unit + widget + golden + a11y (push) Failing after 31s
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 1m1s
Extends the four existing daemon command suites with the verbs + error paths the originals didn't reach: - editor_commands_test (12 new): unreadable-path FileSystemException catch, editor.active with no buffer, editor.activate requires + validates id, editor.read no-active / unknown-id, editor.set-selection no-active / clamped, editor.set-content with + without selection, editor.save no-active, editor.close requires + validates id. - files_commands_test (8 new): files.read happy + missing-path + empty-path + outside-root + missing-file, files.ls outside-root, files.watch idempotent, FilesService.atCwd resolver. - pane_commands_test (10 new): argv-non-string rejection, unknown kind rejection, env passthrough, close / write / focus / resize missing-id and unknown-id validations, write requires bytes_b64 or text, malformed base64 rejection. - pql_commands_test (14 new): pql.files glob + limit, pql.backlinks happy, pql.outlinks missing, pql.tags, pql.query + pql.search happy paths + missing-arg user_error, pql.decisions.read missing + happy, pql.decisions.show with --with-refs / --with-tickets, pql.decisions.list domain filter, pql.tickets.list multi-filter, pql.tickets.show missing + happy, pql.tickets.status missing + partial-args, pql.tickets.board with team. Coverage: src/daemon/editor_commands.dart 64/100 -> 88/100; files_commands.dart 33/70 -> 64/70 (91%); pane_commands.dart 66/92 -> 78/92 (85%); pql_commands.dart 62/149 -> 105/149 (70% — remaining 44 lines are the per-command PqlException catch branches that only fire when the pql subprocess itself fails mid-call). Total coverage 77.92% -> 79.26%; floor bumped to 79. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
207 lines
7.2 KiB
Dart
207 lines
7.2 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:clide/clide.dart';
|
|
import 'package:clide/src/daemon/editor_commands.dart';
|
|
import 'package:clide/src/editor/registry.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
void main() {
|
|
late Directory sandbox;
|
|
late DaemonDispatcher dispatcher;
|
|
late EditorRegistry reg;
|
|
|
|
setUp(() async {
|
|
sandbox = await Directory.systemTemp.createTemp('clide-ed-cmd-test-');
|
|
await File('${sandbox.path}/doc.md').writeAsString('alpha beta');
|
|
final sink = RecordingEventSink();
|
|
reg = EditorRegistry(events: sink, workspaceRoot: sandbox);
|
|
dispatcher = DaemonDispatcher();
|
|
registerEditorCommands(dispatcher, reg);
|
|
});
|
|
|
|
tearDown(() async {
|
|
await reg.shutdown();
|
|
if (sandbox.existsSync()) sandbox.deleteSync(recursive: true);
|
|
});
|
|
|
|
Future<IpcResponse> call(String cmd, [Map<String, Object?> args = const {}]) {
|
|
return dispatcher.dispatch(IpcRequest(id: '1', cmd: cmd, args: args));
|
|
}
|
|
|
|
test('editor.open requires a path', () async {
|
|
final r = await call('editor.open');
|
|
expect(r.ok, isFalse);
|
|
expect(r.error!.kind, 'user_error');
|
|
});
|
|
|
|
test('editor.open + editor.active round-trip', () async {
|
|
final open = await call('editor.open', {'path': 'doc.md'});
|
|
expect(open.ok, isTrue);
|
|
final id = open.data['id']! as String;
|
|
expect(id, startsWith('b_'));
|
|
|
|
final active = await call('editor.active');
|
|
expect(active.ok, isTrue);
|
|
final act = active.data['active']! as Map;
|
|
expect(act['id'], id);
|
|
expect(act['path'], 'doc.md');
|
|
});
|
|
|
|
test('editor.insert without id targets the active buffer', () async {
|
|
await call('editor.open', {'path': 'doc.md'});
|
|
final r = await call('editor.insert', {'text': 'X '});
|
|
expect(r.ok, isTrue);
|
|
expect(r.data['inserted'], 2);
|
|
|
|
final read = await call('editor.read');
|
|
expect((read.data['content'] as String).startsWith('X '), isTrue);
|
|
});
|
|
|
|
test('editor.replace-selection swaps selected range', () async {
|
|
final open = await call('editor.open', {'path': 'doc.md'});
|
|
final id = open.data['id'] as String?;
|
|
|
|
await call('editor.set-selection', {
|
|
'id': id,
|
|
'selection': {'start': 0, 'end': 5}, // 'alpha'
|
|
});
|
|
final r = await call('editor.replace-selection', {'text': 'gamma'});
|
|
expect(r.ok, isTrue);
|
|
|
|
final read = await call('editor.read');
|
|
expect(read.data['content'], 'gamma beta');
|
|
});
|
|
|
|
test('editor.save persists to disk', () async {
|
|
await call('editor.open', {'path': 'doc.md'});
|
|
await call('editor.insert', {'text': 'Z '});
|
|
final save = await call('editor.save');
|
|
expect(save.ok, isTrue);
|
|
final disk = await File('${sandbox.path}/doc.md').readAsString();
|
|
expect(disk.startsWith('Z '), isTrue);
|
|
});
|
|
|
|
test('editor.close removes the buffer', () async {
|
|
final open = await call('editor.open', {'path': 'doc.md'});
|
|
final id = open.data['id'] as String?;
|
|
final r = await call('editor.close', {'id': id});
|
|
expect(r.ok, isTrue);
|
|
final list = await call('editor.list');
|
|
expect((list.data['buffers'] as List), isEmpty);
|
|
});
|
|
|
|
test('editor.list includes all open buffers', () async {
|
|
await File('${sandbox.path}/a.md').writeAsString('a');
|
|
await File('${sandbox.path}/b.md').writeAsString('b');
|
|
await call('editor.open', {'path': 'a.md'});
|
|
await call('editor.open', {'path': 'b.md'});
|
|
final r = await call('editor.list');
|
|
final names = [
|
|
for (final b in (r.data['buffers'] as List).cast<Map>()) b['path'],
|
|
];
|
|
expect(names, containsAll(['a.md', 'b.md']));
|
|
});
|
|
|
|
test('insert on unknown id returns not-found', () async {
|
|
final r = await call('editor.insert', {'id': 'b_404', 'text': 'x'});
|
|
expect(r.ok, isFalse);
|
|
expect(r.error!.code, IpcExitCode.notFound);
|
|
});
|
|
|
|
test('editor.open returns toolError for an unreadable path', () async {
|
|
// Create a file then chmod 000 so reading fails with a FileSystemException.
|
|
final unreadable = File('${sandbox.path}/locked.md');
|
|
await unreadable.writeAsString('x');
|
|
await Process.run('chmod', ['000', unreadable.path]);
|
|
addTearDown(() async {
|
|
await Process.run('chmod', ['644', unreadable.path]);
|
|
});
|
|
final r = await call('editor.open', {'path': 'locked.md'});
|
|
expect(r.ok, isFalse);
|
|
// Either errno-mapped or toolError — either is acceptable.
|
|
expect(r.error!.code, isNot(IpcExitCode.notFound));
|
|
});
|
|
|
|
test('editor.active returns null when no buffer is open', () async {
|
|
final r = await call('editor.active');
|
|
expect(r.ok, isTrue);
|
|
expect(r.data['active'], isNull);
|
|
});
|
|
|
|
test('editor.activate requires id and validates it', () async {
|
|
final missing = await call('editor.activate');
|
|
expect(missing.ok, isFalse);
|
|
expect(missing.error!.kind, 'user_error');
|
|
final unknown = await call('editor.activate', {'id': 'b_404'});
|
|
expect(unknown.ok, isFalse);
|
|
expect(unknown.error!.kind, 'not_found');
|
|
});
|
|
|
|
test('editor.activate flips the active buffer to the requested one', () async {
|
|
await File('${sandbox.path}/a.md').writeAsString('a');
|
|
await File('${sandbox.path}/b.md').writeAsString('b');
|
|
final a = await call('editor.open', {'path': 'a.md'});
|
|
await call('editor.open', {'path': 'b.md'});
|
|
final r = await call('editor.activate', {'id': a.data['id']});
|
|
expect(r.ok, isTrue);
|
|
expect(r.data['active'], a.data['id']);
|
|
});
|
|
|
|
test('editor.read with no active buffer and no id returns not-found', () async {
|
|
final r = await call('editor.read');
|
|
expect(r.ok, isFalse);
|
|
expect(r.error!.kind, 'not_found');
|
|
});
|
|
|
|
test('editor.read with an unknown id returns not-found', () async {
|
|
final r = await call('editor.read', {'id': 'b_404'});
|
|
expect(r.ok, isFalse);
|
|
expect(r.error!.kind, 'not_found');
|
|
});
|
|
|
|
test('editor.set-selection clamps and applies', () async {
|
|
await call('editor.open', {'path': 'doc.md'});
|
|
final r = await call('editor.set-selection', {
|
|
'selection': {'start': 0, 'end': 3}
|
|
});
|
|
expect(r.ok, isTrue);
|
|
});
|
|
|
|
test('editor.set-selection without an id or active buffer returns not-found', () async {
|
|
final r = await call('editor.set-selection', {
|
|
'selection': {'start': 0, 'end': 1}
|
|
});
|
|
expect(r.ok, isFalse);
|
|
expect(r.error!.kind, 'not_found');
|
|
});
|
|
|
|
test('editor.set-content overwrites the buffer (with and without selection)', () async {
|
|
await call('editor.open', {'path': 'doc.md'});
|
|
final r1 = await call('editor.set-content', {'text': 'replaced'});
|
|
expect(r1.ok, isTrue);
|
|
expect(r1.data['length'], 'replaced'.length);
|
|
final read1 = await call('editor.read');
|
|
expect(read1.data['content'], 'replaced');
|
|
final r2 = await call('editor.set-content', {
|
|
'text': 'short',
|
|
'selection': {'start': 1, 'end': 99}
|
|
});
|
|
expect(r2.ok, isTrue);
|
|
});
|
|
|
|
test('editor.save with no active buffer returns not-found', () async {
|
|
final r = await call('editor.save');
|
|
expect(r.ok, isFalse);
|
|
expect(r.error!.kind, 'not_found');
|
|
});
|
|
|
|
test('editor.close requires id and validates it', () async {
|
|
final missing = await call('editor.close');
|
|
expect(missing.ok, isFalse);
|
|
expect(missing.error!.kind, 'user_error');
|
|
final unknown = await call('editor.close', {'id': 'b_404'});
|
|
expect(unknown.ok, isFalse);
|
|
expect(unknown.error!.kind, 'not_found');
|
|
});
|
|
}
|