import 'dart:io'; import 'package:flutter_test/flutter_test.dart'; import 'package:ads_manager/data/daily_log.dart'; import 'package:ads_manager/ui/manager_model.dart'; void main() { test('memory and persisted logs redact connection credentials', () async { final dir = await Directory.systemTemp.createTemp('ads-redact'); final model = ManagerModel(logWriter: DailyLog(dir)); try { final secret = 'c' * 64; model.repository.token = secret; model.log('connection error $secret'); await model.diskLog.flush(); expect(model.logs.single, contains('[REDACTED]')); final file = (await dir.list().toList()).whereType().single; final value = await file.readAsString(); expect(value, isNot(contains(secret))); } finally { model.dispose(); await dir.delete(recursive: true); } }); test('daily files, bounded size rotation and retention', () async { final folder = await Directory.systemTemp.createTemp('ads-log-test'); try { var now = DateTime(2026, 11, 13, 23, 59); await File('${folder.path}/ads-2026-10-01.log').writeAsString('expired'); await File('${folder.path}/other.txt').writeAsString('keep'); final log = DailyLog( folder, maxBytes: 1, maxParts: 2, keepDays: 14, clock: () => now, ); log.add('first'); log.add('second'); log.add('third'); await log.flush(); expect( await File('${folder.path}/ads-2026-11-13.log').readAsString(), contains('third'), ); expect( await File('${folder.path}/ads-2026-11-13.1.log').readAsString(), contains('second'), ); expect(await File('${folder.path}/ads-2026-11-13.2.log').exists(), false); expect(await File('${folder.path}/ads-2026-10-01.log').exists(), false); expect(await File('${folder.path}/other.txt').exists(), true); now = DateTime(2026, 11, 14); log.add('new day'); await log.flush(); expect( await File('${folder.path}/ads-2026-11-14.log').readAsString(), contains('new day'), ); expect(log.error, isNull); } finally { await folder.delete(recursive: true); } }); }