test(studio): seven FaiLog cases + visibleForTesting path override
Some checks failed
Security / Security check (push) Failing after 1s

FaiLog used to compute its destination directly from HOME, which
made it impossible to test without scribbling on the operator's
real ~/.fai/logs/. Adds a static testPathOverride seam tagged
@visibleForTesting so the singleton can be redirected at a per-
test temp file.

The new test/fai_log_test.dart covers:

  - append() writes one JSON-shaped line per event
  - context field round-trips when supplied
  - tail() returns oldest-first
  - tail(maxLines:) caps and keeps the newest entries
  - rotation moves the previous log to .log.1 past 256 KiB
  - path getter honours the override
  - writes to an impossible path do not throw — best-effort
    contract that protects the UI from log-write failures

Production behaviour is unchanged: when the override is null
the path getter still computes from HOME/USERPROFILE.

Signed-off-by: flemming-it <stefan.a.flemming@googlemail.com>
This commit is contained in:
flemming-it 2026-06-04 02:43:06 +02:00
parent 805f1b4c1f
commit d9dca60cfb
3 changed files with 113 additions and 1 deletions

View file

@ -23,6 +23,7 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;
class FaiLog {
@ -37,7 +38,15 @@ class FaiLog {
static const int _rotateBytes = 256 * 1024;
/// Test seam. Set this in `setUp` to redirect the singleton at
/// a per-test temp file; reset to `null` in `tearDown`. Production
/// code never touches it the default getter computes from HOME.
@visibleForTesting
static String? testPathOverride;
String get _path {
final override = testPathOverride;
if (override != null) return override;
final home =
Platform.environment['HOME'] ??
Platform.environment['USERPROFILE'] ??