feat(log): crash-survivable FileLogSink + dev/prod verbosity toggle (T-432)

First increment of the observability epic (T-425), the productive pivot after
the ConPTY freeze refused to reproduce on CI: if we can't reproduce it, make
the next occurrence leave evidence.

- FileLogSink (lib/kernel/src/file_log_sink.dart): synchronous, crash-survivable
  LogSink. Appends each record as one JSON line to a size-rotated file; fsyncs
  warn/error + risky-source (pty/ffi/conpty/watchdog) records immediately so the
  last breadcrumb is on disk before a hard death, batches the rest on a timer.
  Never throws. Flutter-free → unit-tested under dart test against a temp dir.
- logDirectory() (paths.dart): persistent per-platform log dir (LOCALAPPDATA /
  ~/Library/Logs / $XDG_STATE_HOME) — durable across reboot, unlike the
  ephemeral socketDirectory.
- resolveLogLevel() (log.dart): the requested dev/prod toggle. CLIDE_LOG
  dart-define → CLIDE_LOG env → app.log.level setting → warn(release)/info(debug).
  Lenient parse; an invalid source falls through.
- Boot wiring (facade.boot + main.dart): FileLogSink leads the sink chain (so a
  crash records before the volatile stderr/ring sinks) and the resolved level
  sets Logger.minLevel.

Tests: FileLogSink (JSON shape, error/stack, rotation cap, append-across-restart,
timer-cancel), resolveLogLevel precedence + fall-through, logDirectory per-OS.
Coverage gate 95.11%.

Follow-ups under T-425: live toggle CLI/command/chip (T-433), FFI breadcrumbs
(T-434), watchdog isolate (T-435), CI artifact wiring (T-436).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-15 09:29:41 +02:00
co-authored by Claude Opus 4.8
parent b3acb8a34c
commit 85cc34e09c
12 changed files with 494 additions and 2 deletions
+25
View File
@@ -39,6 +39,31 @@ void main() {
});
});
group('logDirectory (T-425)', () {
test('is a persistent, non-ephemeral location distinct from the socket dir', () {
// The freeze evidence must survive a reboot, so logs must NOT live in
// the ephemeral socket/runtime dir.
expect(logDirectory(), isNot(socketDirectory()));
});
test('Linux: XDG_STATE_HOME/clide/logs when set, else ~/.local/state/...', () {
if (Platform.isMacOS || Platform.isWindows) return;
final state = Platform.environment['XDG_STATE_HOME'];
if (state != null && state.isNotEmpty) {
expect(logDirectory(), '$state/clide/logs');
} else {
final home = Platform.environment['HOME'] ?? '/tmp';
expect(logDirectory(), '$home/.local/state/clide/logs');
}
});
test('macOS: ~/Library/Logs/clide (not Caches)', () {
if (!Platform.isMacOS) return;
final home = Platform.environment['HOME']!;
expect(logDirectory(), '$home/Library/Logs/clide');
});
});
group('fnv1a64Hex (T-126 cross-check)', () {
// Reference values from <http://isthe.com/chongo/tech/comp/fnv/>.
// The C client in native/clide-cli/clide.c MUST produce the same