// Guards for the streamed `chain update apply` path. // // Applying an update downloads and swaps a binary and takes minutes. // The bug class: a caller that passes a line callback and silently // gets nothing back, or a streaming path that stops honouring the // test override and starts spawning real processes in the suite. import 'package:chain_studio/data/system_actions.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { tearDown(() => SystemActions.debugRunFaiOverride = null); test('the test override still wins over the streaming path', () async { // Hermetic by construction: with an override installed, no process // may be started even when a line callback is supplied. var seenArgs = []; SystemActions.debugRunFaiOverride = (args) async { seenArgs = args; return (ok: true, stdout: 'done', stderr: ''); }; var lines = []; final r = await SystemActions.chainUpdateApply( 'stable', onLine: lines.add, ); expect(r.ok, isTrue); expect(r.stdout, 'done'); expect(seenArgs, ['update', 'apply', '--channel', 'stable']); expect(lines, isEmpty, reason: 'the override produces no live lines'); }); test('the channel reaches the CLI unchanged', () async { var seenArgs = []; SystemActions.debugRunFaiOverride = (args) async { seenArgs = args; return (ok: true, stdout: '', stderr: ''); }; await SystemActions.chainUpdateApply('beta', onLine: (_) {}); expect(seenArgs, contains('beta')); }); test('callers without a line callback keep the buffered behaviour', () async { SystemActions.debugRunFaiOverride = (args) async => (ok: false, stdout: '', stderr: 'boom'); final r = await SystemActions.chainUpdateApply('stable'); expect(r.ok, isFalse); expect(r.stderr, 'boom'); }); }