Files
clide/test/daemon/log_commands_test.dart
jpmschweitzerandClaude Opus 4.8 432a5f2d5a feat(log): live verbosity toggle — dock Level chip + clide log level (T-433)
The boot-time toggle (CLIDE_LOG / app.log.level) existed; this makes it
adjustable at runtime, from the two surfaces that fit — D-6 parity — and NOT a
Claude-composer slash command (log verbosity isn't a Claude-session concept).

- Output dock Level chip: was a view-only filter; now also drives the kernel
  Logger.minLevel and persists app.log.level, so the choice is real (changes
  what's captured) and survives restart. Initialized from the logger's current
  level so it reflects a CLI change. A null callback keeps it a pure view
  filter (tests / no kernel).
- `clide log level [<level>]` (lib/src/daemon/log_commands.dart): no arg reports
  the level + vocabulary; a valid level sets the live logger and persists;
  unknown → bad_arg (code 64), logger untouched. Wired in buildDispatcher with
  the kernel logger + settings (captured post-boot).

Tested: the command (get/set/case-insensitive/bad-arg, live + persist) and the
controller (initial level, callback fires, same-level no-op, filter-only when
unwired). Coverage gate 95.05%.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-15 12:32:56 +02:00

56 lines
2.1 KiB
Dart

import 'package:clide/kernel/src/log.dart';
import 'package:clide/src/daemon/dispatcher.dart';
import 'package:clide/src/daemon/log_commands.dart';
import 'package:clide/src/ipc/envelope.dart';
import 'package:test/test.dart';
void main() {
group('log.level command (T-433)', () {
test('no arg reports the current level + the vocabulary', () async {
final log = Logger(minLevel: LogLevel.info);
final d = DaemonDispatcher();
registerLogCommands(d, log, (_) async {});
final r = await d.dispatch(IpcRequest(id: '1', cmd: 'log.level', args: const {}));
expect(r.ok, isTrue);
expect(r.data['level'], 'info');
expect(r.data['levels'], containsAll(<String>['trace', 'debug', 'info', 'warn', 'error']));
});
test('a valid level sets the running logger AND persists it', () async {
final log = Logger(minLevel: LogLevel.info);
String? persisted;
final d = DaemonDispatcher();
registerLogCommands(d, log, (name) async => persisted = name);
final r = await d.dispatch(IpcRequest(id: '1', cmd: 'log.level', args: {'level': 'warn'}));
expect(r.ok, isTrue);
expect(r.data['level'], 'warn');
expect(log.minLevel, LogLevel.warn); // live
expect(persisted, 'warn'); // durable
});
test('level name is case-insensitive', () async {
final log = Logger(minLevel: LogLevel.info);
final d = DaemonDispatcher();
registerLogCommands(d, log, (_) async {});
await d.dispatch(IpcRequest(id: '1', cmd: 'log.level', args: {'level': 'ERROR'}));
expect(log.minLevel, LogLevel.error);
});
test('an unknown level errors (code 64), leaves the logger untouched, does not persist', () async {
final log = Logger(minLevel: LogLevel.info);
var persistCalls = 0;
final d = DaemonDispatcher();
registerLogCommands(d, log, (_) async => persistCalls++);
final r = await d.dispatch(IpcRequest(id: '1', cmd: 'log.level', args: {'level': 'loud'}));
expect(r.ok, isFalse);
expect(r.error?.code, 64);
expect(r.error?.hint, contains('warn'));
expect(log.minLevel, LogLevel.info);
expect(persistCalls, 0);
});
});
}