refactor: rename internal Fai* design system + fai_ helpers to chain
Some checks failed
Security / Security check (push) Failing after 2s
Some checks failed
Security / Security check (push) Failing after 2s
The Studio design system, widgets and helpers carried a Fai* / fai_ prefix (FaiSpace, FaiColors, FaiTheme, FaiLog, 17 fai_*.dart files, the faiBinary* l10n keys). Studio is the Ch∆In product, so rename them to Chain* / chain_ — carefully preserving English fail/failure/failed. Also fix stale references: the 'fai' binary in l10n strings -> 'chain', FAI_* env vars (FAI_BIN/DATA_DIR/MODULES_DIR/TODAY/BOOTSTRAP_TOKEN) -> CHAIN_*, fai_platform -> fai_chain, fai_hub -> chain_hub. Vendor security-hook tooling (FAI_BANNED_TERMS_FILE) + the .fai bundle ext left. flutter analyze + test: clean (20 passed). Signed-off-by: flemming-it <stefan.a.flemming@googlemail.com>
This commit is contained in:
parent
68d23ab7dd
commit
891acd2ba2
52 changed files with 1225 additions and 1225 deletions
|
|
@ -1,103 +0,0 @@
|
|||
// Unit tests for FaiLog — the central error log that
|
||||
// `~/.fai/logs/studio-errors.log` is the operator-visible
|
||||
// surface of. The tests redirect the singleton at a temp file
|
||||
// via `FaiLog.testPathOverride` so the real log under HOME is
|
||||
// never touched.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:chain_studio/data/fai_log.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('FaiLog', () {
|
||||
late Directory tmp;
|
||||
late File logFile;
|
||||
|
||||
setUp(() {
|
||||
tmp = Directory.systemTemp.createTempSync('fai_log_test_');
|
||||
logFile = File('${tmp.path}/studio-errors.log');
|
||||
FaiLog.testPathOverride = logFile.path;
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
FaiLog.testPathOverride = null;
|
||||
try {
|
||||
tmp.deleteSync(recursive: true);
|
||||
} catch (_) {/* best-effort */}
|
||||
});
|
||||
|
||||
test('append writes one JSON-shaped line per event', () async {
|
||||
await FaiLog.instance.error('flows.run', 'boom');
|
||||
final lines = await FaiLog.instance.tail();
|
||||
expect(lines, hasLength(1));
|
||||
final entry = jsonDecode(lines.single) as Map<String, Object?>;
|
||||
expect(entry['source'], 'flows.run');
|
||||
expect(entry['error'], 'boom');
|
||||
expect(entry['level'], 'error');
|
||||
expect(entry['ts'], isA<String>());
|
||||
});
|
||||
|
||||
test('context field is preserved when supplied', () async {
|
||||
await FaiLog.instance.error(
|
||||
'theme.plugin.load',
|
||||
Exception('endpoint unreachable'),
|
||||
context: 'capability=studio.theme.space',
|
||||
);
|
||||
final lines = await FaiLog.instance.tail();
|
||||
final entry = jsonDecode(lines.single) as Map<String, Object?>;
|
||||
expect(entry['context'], 'capability=studio.theme.space');
|
||||
expect(entry['error'], contains('endpoint unreachable'));
|
||||
});
|
||||
|
||||
test('tail returns oldest first', () async {
|
||||
await FaiLog.instance.error('a', '1');
|
||||
await FaiLog.instance.error('b', '2');
|
||||
await FaiLog.instance.error('c', '3');
|
||||
final lines = await FaiLog.instance.tail();
|
||||
expect(lines, hasLength(3));
|
||||
final sources = lines.map((l) => jsonDecode(l)['source']).toList();
|
||||
expect(sources, ['a', 'b', 'c']);
|
||||
});
|
||||
|
||||
test('tail caps output at maxLines and keeps the newest', () async {
|
||||
for (var i = 0; i < 20; i++) {
|
||||
await FaiLog.instance.error('burst', 'event-$i');
|
||||
}
|
||||
final lines = await FaiLog.instance.tail(maxLines: 5);
|
||||
expect(lines, hasLength(5));
|
||||
final last = jsonDecode(lines.last) as Map<String, Object?>;
|
||||
expect(last['error'], 'event-19');
|
||||
});
|
||||
|
||||
test('rotation moves the live log to .log.1 past 256 KiB', () async {
|
||||
// Pre-seed the active log just over the cap. The next
|
||||
// append should rotate, leaving the rotated file at
|
||||
// `.log.1` and a short fresh `.log`.
|
||||
logFile.parent.createSync(recursive: true);
|
||||
logFile.writeAsBytesSync(List.filled(257 * 1024, 0x20));
|
||||
await FaiLog.instance.error('rotation', 'after-cap');
|
||||
expect(File('${logFile.path}.1').existsSync(), isTrue);
|
||||
final newSize = logFile.lengthSync();
|
||||
expect(newSize, lessThan(2 * 1024));
|
||||
final newText = logFile.readAsStringSync();
|
||||
expect(newText, contains('"source":"rotation"'));
|
||||
});
|
||||
|
||||
test('path getter returns the override when set', () {
|
||||
expect(FaiLog.instance.path, logFile.path);
|
||||
});
|
||||
|
||||
test('writes failing silently does not throw', () async {
|
||||
// Redirect to a deliberately impossible path. The error()
|
||||
// call must complete cleanly; the operator UI must never
|
||||
// crash because the disk is full / read-only / missing.
|
||||
FaiLog.testPathOverride = '/this/path/does/not/exist/ever/x.log';
|
||||
await expectLater(
|
||||
FaiLog.instance.error('bad.path', 'boom'),
|
||||
completes,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue