From 8457a65fdd0af730c8191807242a6ca21441294b Mon Sep 17 00:00:00 2001 From: dhivadhiva Date: Mon, 16 Nov 2026 13:41:15 +0530 Subject: [PATCH 1/3] Make the bridge screen tests wait for saves, not for time Three widget tests fail on slower runners (Linux arm64, Windows x64). Their settle helper waited a fixed time. Saving a pairing or a host writes a file and runs chmod as a separate process, which needs both real event-loop time and timers on the test's fake clock, so on a slow runner the save had not finished when the test moved on. The helper now waits until no store call is running and no progress indicator is showing. Tracked subclasses of the real stores count the calls still in flight. No assertion changed and nothing is skipped. Each of the three tests passed 20 of 20 runs, and 10 of 10 pinned to one busy core. --- test/ai_bridge_screens_test.dart | 34 +++++++--- test/bridge_one_click_test.dart | 50 +++++++++++--- test/support/settle.dart | 24 +++++++ test/support/tracked_stores.dart | 110 +++++++++++++++++++++++++++++++ 4 files changed, 199 insertions(+), 19 deletions(-) create mode 100644 test/support/tracked_stores.dart diff --git a/test/ai_bridge_screens_test.dart b/test/ai_bridge_screens_test.dart index 4995823..cbee533 100644 --- a/test/ai_bridge_screens_test.dart +++ b/test/ai_bridge_screens_test.dart @@ -26,6 +26,7 @@ import 'package:secure_shell_go/services/settings_store.dart'; import 'support/settle.dart'; import 'support/temp_dir.dart'; +import 'support/tracked_stores.dart'; BridgeConnections _connections() => BridgeConnections( openTransport: (_) => null, @@ -77,8 +78,8 @@ class _FakeBridge extends BridgeService { } /// A log whose Clear always fails. -class _FailingClear extends BridgeAuditLog { - _FailingClear(Directory dir) +class _FailingClear extends TrackedAuditLog { + _FailingClear(super.io, Directory dir) : super(scrub: (s) => s, directory: Directory('${dir.path}/failing')); @override @@ -92,22 +93,26 @@ void main() { late _FakeBridge bridge; late HostStore hostStore; late BridgeAuditLog brokenAudit; + late IoTracker io; String? clipboard; setUp(() async { dir = await Directory.systemTemp.createTemp('ai_bridge_screens_test'); - clients = BridgeClientStore(file: File('${dir.path}/clients.json')); - audit = BridgeAuditLog( + io = IoTracker(); + clients = TrackedClientStore(io, file: File('${dir.path}/clients.json')); + audit = TrackedAuditLog( + io, scrub: (s) => s, directory: Directory('${dir.path}/bridge'), ); bridge = _FakeBridge(dir, clients, audit); // Built here, not in a test body: a store made inside `testWidgets` // queues its first write on the fake clock, which `runAsync` never turns. - hostStore = HostStore(file: File('${dir.path}/hosts.json')); + hostStore = TrackedHostStore(io, file: File('${dir.path}/hosts.json')); // A log whose directory cannot exist: its parent is a file. File('${dir.path}/blocker').writeAsStringSync('x'); - brokenAudit = BridgeAuditLog( + brokenAudit = TrackedAuditLog( + io, scrub: (s) => s, directory: Directory('${dir.path}/blocker/bridge'), ); @@ -139,11 +144,22 @@ void main() { } /// Turns the real event loop, then rebuilds. + /// + /// Waits until no store or log call is still running and no progress + /// indicator is up, rather than for a fixed number of turns, which was + /// too few on slow CI runners. + bool busy() => + io.busy || + find + .byWidgetPredicate((w) => w is ProgressIndicator) + .evaluate() + .isNotEmpty; + Future settle(WidgetTester tester) async { - await settleIo(tester, rounds: 10); + await settleWhile(tester, busy); // Past a route or dialog animation, without waiting on a spinner. await tester.pump(const Duration(milliseconds: 500)); - await settleIo(tester, rounds: 5); + await settleWhile(tester, busy); await tester.pump(const Duration(milliseconds: 500)); } @@ -993,7 +1009,7 @@ void main() { }); testWidgets('says so when Clear fails', (tester) async { - final failing = _FailingClear(dir); + final failing = _FailingClear(io, dir); addTearDown(failing.dispose); await tester.runAsync( () => failing.record( diff --git a/test/bridge_one_click_test.dart b/test/bridge_one_click_test.dart index 6219eaa..fcc592d 100644 --- a/test/bridge_one_click_test.dart +++ b/test/bridge_one_click_test.dart @@ -24,6 +24,7 @@ import 'package:secure_shell_go/services/settings_store.dart'; import 'support/settle.dart'; import 'support/temp_dir.dart'; +import 'support/tracked_stores.dart'; const _claudePath = '/home/user/.local/bin/claude'; const _claudeVersion = '2.1.322 (Claude Code)'; @@ -86,6 +87,20 @@ class _FakeConnector extends ClaudeCliConnector { /// While set, `detect` waits for it. Completer? holdDetect; + + /// How many calls are waiting on [holdDetect] or [hold] right now: the + /// test holds them on purpose, so a screen waiting on one is at rest. + int waiting = 0; + + Future _wait(Future gate) async { + waiting++; + try { + await gate; + } finally { + waiting--; + } + } + final List expectedSources = []; final List<({String path, String token, String launcher})> connectCalls = []; @@ -117,7 +132,7 @@ class _FakeConnector extends ClaudeCliConnector { Future detect() async { detectCalls++; final gate = holdDetect; - if (gate != null) await gate.future; + if (gate != null) await _wait(gate.future); return availability; } @@ -138,7 +153,7 @@ class _FakeConnector extends ClaudeCliConnector { final thrown = throwWith; if (thrown != null) throw StateError('$thrown $token'); final gate = hold; - if (gate != null && holdAt == null) await gate.future; + if (gate != null && holdAt == null) await _wait(gate.future); final at = failAt; final run = [ for (final s in ClaudeConnectStep.values) @@ -147,7 +162,7 @@ class _FakeConnector extends ClaudeCliConnector { ]; for (final s in run) { onStep?.call(s); - if (gate != null && s == holdAt) await gate.future; + if (gate != null && s == holdAt) await _wait(gate.future); } ClaudeConnectStepResult ran(ClaudeConnectStep step, int code, String out) => ClaudeConnectStepResult( @@ -194,17 +209,19 @@ void main() { late _FakeBridge bridge; late HostStore hostStore; late _FakeConnector connector; + late IoTracker io; String? clipboard; setUp(() async { dir = await Directory.systemTemp.createTemp('bridge_one_click_test'); - clients = BridgeClientStore(file: File('${dir.path}/clients.json')); + io = IoTracker(); + clients = TrackedClientStore(io, file: File('${dir.path}/clients.json')); audit = BridgeAuditLog( scrub: (s) => s, directory: Directory('${dir.path}/bridge'), ); bridge = _FakeBridge(dir, clients, audit); - hostStore = HostStore(file: File('${dir.path}/hosts.json')); + hostStore = TrackedHostStore(io, file: File('${dir.path}/hosts.json')); connector = _FakeConnector( const ClaudeCliAvailable( executablePath: _claudePath, @@ -238,10 +255,23 @@ void main() { ); } + /// Waits until the screen's own work is done — no host or pairing store + /// call still running, and no progress indicator except while the fake + /// `claude` is deliberately held — then past any route animation, and + /// once more for work that animation started. A fixed number of event + /// loop turns was too few on slow CI runners. + bool busy() => + io.busy || + (connector.waiting == 0 && + find + .byWidgetPredicate((w) => w is ProgressIndicator) + .evaluate() + .isNotEmpty); + Future settle(WidgetTester tester) async { - await settleIo(tester, rounds: 10); + await settleWhile(tester, busy); await tester.pump(const Duration(milliseconds: 500)); - await settleIo(tester, rounds: 5); + await settleWhile(tester, busy); await tester.pump(const Duration(milliseconds: 500)); } @@ -1085,7 +1115,7 @@ void main() { // Made on the real event loop, as setUp makes the others: its writer // would otherwise wait on the test's fake clock. await tester.runAsync(() async { - hostStore = _FailingHostStore(File('${dir.path}/hosts2.json'), 'c'); + hostStore = _FailingHostStore(io, File('${dir.path}/hosts2.json'), 'c'); }); await addHosts(tester, [_host('a'), _host('b'), _host('c')]); await pumpSection(tester); @@ -1262,8 +1292,8 @@ class _NoConfirmStore extends BridgeClientStore { } /// Saves like the real store but fails to write host [failId]. -class _FailingHostStore extends HostStore { - _FailingHostStore(File file, this.failId) : super(file: file); +class _FailingHostStore extends TrackedHostStore { + _FailingHostStore(super.io, File file, this.failId) : super(file: file); final String failId; diff --git a/test/support/settle.dart b/test/support/settle.dart index 8c8bf52..c8988d7 100644 --- a/test/support/settle.dart +++ b/test/support/settle.dart @@ -71,3 +71,27 @@ Future settleUntil( await settleIo(tester, rounds: 10); } } + +/// Turns both event loops until [busy] has been false on two turns in a +/// row, or [timeout] of real time passes — for "the screen has finished its +/// background work", where the work is tracked (see +/// `tracked_stores.dart`) or shows a progress indicator. Two turns, because +/// one finished step may start the next only after a rebuild. Each turn +/// also moves the fake clock on a little: a store write runs `chmod` as a +/// process, whose plumbing needs timers on the test's clock as well as the +/// real event loop. +Future settleWhile( + WidgetTester tester, + bool Function() busy, { + Duration timeout = const Duration(seconds: 30), +}) async { + final clock = Stopwatch()..start(); + var quiet = 0; + while (quiet < 2 && clock.elapsed < timeout) { + await tester.runAsync( + () => Future.delayed(const Duration(milliseconds: 20)), + ); + await tester.pump(const Duration(milliseconds: 10)); + quiet = busy() ? 0 : quiet + 1; + } +} diff --git a/test/support/tracked_stores.dart b/test/support/tracked_stores.dart new file mode 100644 index 0000000..c133a0d --- /dev/null +++ b/test/support/tracked_stores.dart @@ -0,0 +1,110 @@ +import 'dart:async'; + +import 'package:secure_shell_go/models/host.dart'; +import 'package:secure_shell_go/services/bridge/bridge_audit.dart'; +import 'package:secure_shell_go/services/bridge/bridge_client_store.dart'; +import 'package:secure_shell_go/services/host_store.dart'; + +/// Counts the store calls still running, so a widget test can wait until a +/// screen's file work has really finished instead of for a number of event +/// loop turns (which is too few on a slow CI runner). +class IoTracker { + int _inFlight = 0; + + /// True while any tracked call has not completed. + bool get busy => _inFlight > 0; + + Future track(Future Function() op) async { + _inFlight++; + try { + return await op(); + } finally { + _inFlight--; + } + } +} + +/// A real [HostStore] whose calls are counted by [io]. +class TrackedHostStore extends HostStore { + TrackedHostStore(this.io, {super.file}); + + final IoTracker io; + + @override + Future ensureLoaded() => io.track(super.ensureLoaded); + + @override + Future> all() => io.track(super.all); + + @override + Future get(String id) => io.track(() => super.get(id)); + + @override + Future add(Host host) => io.track(() => super.add(host)); + + @override + Future update(Host host) => io.track(() => super.update(host)); + + @override + Future modify(String id, Host Function(Host current) change) => + io.track(() => super.modify(id, change)); + + @override + Future delete(String id) => io.track(() => super.delete(id)); + + @override + Future replaceAll(Iterable hosts) => + io.track(() => super.replaceAll(hosts)); + + @override + Future> groupNames() => io.track(super.groupNames); + + @override + Future renameGroup(String oldName, String newName) => + io.track(() => super.renameGroup(oldName, newName)); + + @override + Future deleteGroup(String name) => + io.track(() => super.deleteGroup(name)); +} + +/// A real [BridgeClientStore] whose calls are counted by [io]. +class TrackedClientStore extends BridgeClientStore { + TrackedClientStore(this.io, {super.file}); + + final IoTracker io; + + @override + Future> load() => io.track(super.load); + + @override + Future<({BridgeClient client, String token})> create( + String name, { + bool pending = false, + }) => io.track(() => super.create(name, pending: pending)); + + @override + Future confirm(String id) => io.track(() => super.confirm(id)); + + @override + Future verify(String token) => + io.track(() => super.verify(token)); + + @override + Future revoke(String id) => io.track(() => super.revoke(id)); +} + +/// A real [BridgeAuditLog] whose reads and clears are counted by [io]. +/// (Writes are left alone: the screens never write.) +class TrackedAuditLog extends BridgeAuditLog { + TrackedAuditLog(this.io, {required super.scrub, super.directory}); + + final IoTracker io; + + @override + Future> recent({int limit = 200}) => + io.track(() => super.recent(limit: limit)); + + @override + Future clear() => io.track(super.clear); +} From b0013a006b6109573114cfa9f8fd60efb4c63809 Mon Sep 17 00:00:00 2001 From: dhivadhiva Date: Mon, 16 Nov 2026 19:15:41 +0530 Subject: [PATCH 2/3] Let the Flatpak build update its SDK on every runner The Flatpak job updates the GNOME SDK that ships inside the build container. On some hosted runner images that update stops with "Invalid cross-device link" and the builder crashes, because the installation lives in the image and its directories cannot be renamed there. Copy the installation into the container's writable layer before the build, so the update works whichever runner the job lands on. --- .github/workflows/desktop-builds.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/desktop-builds.yml b/.github/workflows/desktop-builds.yml index bbf716b..c35b051 100644 --- a/.github/workflows/desktop-builds.yml +++ b/.github/workflows/desktop-builds.yml @@ -774,6 +774,20 @@ jobs: VERSION="$(grep '^version:' pubspec.yaml | awk '{print $2}' | cut -d+ -f1)" echo "bundle=secureshellgo-$VERSION-$FP_ARCH.flatpak" >> "$GITHUB_OUTPUT" + # The build below updates the SDK that ships inside the container. On + # some hosted runner images that stops with "Invalid cross-device link" + # and the builder crashes: the installation lives in the image, and its + # directories cannot be renamed there. A copy made here lives wholly in + # the container's writable layer, where the update works. + - name: Move the Flatpak installation into the writable layer + run: | + if [ -d /var/lib/flatpak ]; then + cp -a /var/lib/flatpak /var/lib/flatpak.copy + rm -rf /var/lib/flatpak + mv /var/lib/flatpak.copy /var/lib/flatpak + fi + flatpak list --system --columns=application,branch || true + - name: Build the Flatpak uses: flatpak/flatpak-github-actions/flatpak-builder@v6 with: From b194e05c45bc85bd1e35657d8300077e2b336c26 Mon Sep 17 00:00:00 2001 From: dhivadhiva Date: Mon, 16 Nov 2026 19:32:07 +0530 Subject: [PATCH 3/3] Do not let a write to a departed bridge peer escape as an error The outbound stream's failure was swallowed with catchError and a handler that returns nothing. The socket's future carries its own type at run time, so that handler was refused and the failure surfaced as an uncaught ArgumentError whenever a peer left before its reply was written. Handle it with a typed then/onError instead. --- lib/services/bridge/bridge_channel.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/services/bridge/bridge_channel.dart b/lib/services/bridge/bridge_channel.dart index 4e1205a..bafb518 100644 --- a/lib/services/bridge/bridge_channel.dart +++ b/lib/services/bridge/bridge_channel.dart @@ -425,7 +425,10 @@ class _SocketConnection implements BridgeConnection { return chunk; }), ) - .catchError((Object _) {}); + // Not catchError: the socket's future has its own type at run time, + // and a handler that returns nothing is refused for it, which turned + // a peer that left early into an uncaught error. + .then((_) {}, onError: (Object _) {}); } final Socket _socket;