feat(test): hermetic hub fake + state-matrix sweep across all pages

The widget suites used to talk to whatever listens on the real
endpoint — results depended on the operator's machine (a running
hub fed real data into a11y/responsive runs and its gRPC channel
timers caused the historic flake). Hardening round:

- HubService.instance is now injectable (debugSetInstance);
  FakeHubService (test/support/fake_hub.dart) answers every member
  the pages touch with healthy-empty defaults and scripts per-RPC
  failures (UNIMPLEMENTED / UNAVAILABLE / detached gate) through a
  GrpcError-shaped fake. Unimplemented members are recorded and
  fail the sweep with the exact list.
- state_matrix_test.dart pins the app-wide invariants for every
  sidebar page x hub condition: healthy => no unreachable claims
  and no raw error text; hub gone => honest unreachable states;
  UNIMPLEMENTED => never 'not reachable' while the sidebar shows
  connected; detached gate => plain-language feature-off state.
- a11y + responsive sweeps now inject the fake (hermetic); the
  6-minute idle-timer drain workaround is gone with the cause.

Real bugs the new sweep caught immediately:
- every data page (store, doctor, audit, approvals, federation)
  folded ANY load failure into 'hub not reachable' — the runs-page
  bug class; they now share HubLoadErrorView, which classifies
  into unreachable / needs-newer-hub / load-failed-with-copyable-
  detail (new generic DE+EN strings)
- the approvals page's hidden tab had no future listener: a load
  failure there surfaced as an uncaught async error
- the audit status bar rendered the raw gRPC error wall verbatim;
  it now shows the classified friendly headline (still selectable)

Signed-off-by: flemming-it <stefan.a.flemming@googlemail.com>
This commit is contained in:
flemming-it 2026-07-19 01:02:51 +02:00
parent adc5fc2311
commit 66b26304fd
19 changed files with 733 additions and 97 deletions

View file

@ -217,6 +217,47 @@ FriendlyError? _matchHubPattern(String detail, AppLocalizations l) {
return null;
}
/// How a page-level load failure should be presented. Every page
/// that fetches its content from the hub used to fold ANY failure
/// into "hub not reachable", which contradicted the sidebar's
/// green connected dot whenever the hub answered but the RPC
/// failed (version skew, feature gates, real bugs). The shared
/// classification keeps "not reachable" reserved for genuine
/// connection failures.
enum HubLoadIssue {
/// Socket-level failure or gRPC UNAVAILABLE / DEADLINE_EXCEEDED:
/// the hub itself cannot be reached.
unreachable,
/// gRPC UNIMPLEMENTED: the hub answered, but its version
/// predates the RPC this view needs connected, just too old.
unsupported,
/// Anything else show the friendly error with copyable detail.
other,
}
/// Classify a page-load failure (see [HubLoadIssue]).
HubLoadIssue classifyHubLoadError(Object error) {
switch (grpcCodeOf(error)) {
case 12: // UNIMPLEMENTED
return HubLoadIssue.unsupported;
case 4: // DEADLINE_EXCEEDED
case 14: // UNAVAILABLE
return HubLoadIssue.unreachable;
}
// Non-gRPC failures: only clear socket-level shapes count as
// "unreachable"; everything else keeps its real story.
final s = error.toString().toLowerCase();
if (s.contains('socketexception') ||
s.contains('connection refused') ||
s.contains('connection terminated') ||
s.contains('failed to connect')) {
return HubLoadIssue.unreachable;
}
return HubLoadIssue.other;
}
/// Duck-typed `GrpcError.code` reader public so pages that
/// classify errors themselves (e.g. the runs monitor separating
/// "hub down" from "hub too old") share one accessor instead of

View file

@ -20,7 +20,17 @@ export 'flow_output.dart';
class HubService {
HubService._();
static final HubService instance = HubService._();
static HubService instance = HubService._();
/// Test hook: replace the app-wide instance with a scriptable
/// fake so widget suites are hermetic they must never depend
/// on whether a real hub happens to listen on the operator's
/// machine (the state-matrix suite injects per-RPC behaviours
/// through this). Pass null to restore a real instance.
@visibleForTesting
static void debugSetInstance(HubService? replacement) {
instance = replacement ?? HubService._();
}
HubClient _client = HubClient();

View file

@ -1357,6 +1357,9 @@
"n8nHint": "Aktive n8n-Workflows erscheinen als n8n.<endpoint>.<slug> Fähigkeiten. Einmal konfigurieren, im Store sichtbar.",
"n8nEmpty": "Keine n8n-Endpunkte konfiguriert. + klicken zum Hinzufügen.",
"hubUnreachable": "Hub nicht erreichbar",
"hubViewTooOldTitle": "Diese Ansicht braucht eine neuere Hub-Version",
"hubViewTooOldHint": "Der Hub ist verbunden, aber seine Version kennt diese Ansicht noch nicht. Aktualisieren Sie den Hub (Diagnose → Update), dann erscheint der Inhalt hier.",
"hubViewLoadFailedTitle": "Diese Ansicht konnte nicht geladen werden",
"hubUnreachableHint": "Hub starten mit chain serve.",
"languageEnglish": "English",
"languageGerman": "Deutsch",

View file

@ -1381,6 +1381,9 @@
"n8nHint": "Active n8n workflows surface as n8n.<endpoint>.<slug> capabilities. Configure once, see them in the Store.",
"n8nEmpty": "No n8n endpoints configured. Click + to add one.",
"hubUnreachable": "Hub unreachable",
"hubViewTooOldTitle": "This view needs a newer hub version",
"hubViewTooOldHint": "The hub is connected, but its version does not know this view yet. Update the hub (Doctor → Update) and the content will appear here.",
"hubViewLoadFailedTitle": "This view could not be loaded",
"hubUnreachableHint": "Start the hub with chain serve.",
"languageEnglish": "English",
"languageGerman": "Deutsch",

View file

@ -4076,6 +4076,24 @@ abstract class AppLocalizations {
/// **'Hub unreachable'**
String get hubUnreachable;
/// No description provided for @hubViewTooOldTitle.
///
/// In en, this message translates to:
/// **'This view needs a newer hub version'**
String get hubViewTooOldTitle;
/// No description provided for @hubViewTooOldHint.
///
/// In en, this message translates to:
/// **'The hub is connected, but its version does not know this view yet. Update the hub (Doctor → Update) and the content will appear here.'**
String get hubViewTooOldHint;
/// No description provided for @hubViewLoadFailedTitle.
///
/// In en, this message translates to:
/// **'This view could not be loaded'**
String get hubViewLoadFailedTitle;
/// No description provided for @hubUnreachableHint.
///
/// In en, this message translates to:

View file

@ -2399,6 +2399,18 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get hubUnreachable => 'Hub nicht erreichbar';
@override
String get hubViewTooOldTitle =>
'Diese Ansicht braucht eine neuere Hub-Version';
@override
String get hubViewTooOldHint =>
'Der Hub ist verbunden, aber seine Version kennt diese Ansicht noch nicht. Aktualisieren Sie den Hub (Diagnose → Update), dann erscheint der Inhalt hier.';
@override
String get hubViewLoadFailedTitle =>
'Diese Ansicht konnte nicht geladen werden';
@override
String get hubUnreachableHint => 'Hub starten mit chain serve.';

View file

@ -2400,6 +2400,16 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get hubUnreachable => 'Hub unreachable';
@override
String get hubViewTooOldTitle => 'This view needs a newer hub version';
@override
String get hubViewTooOldHint =>
'The hub is connected, but its version does not know this view yet. Update the hub (Doctor → Update) and the content will appear here.';
@override
String get hubViewLoadFailedTitle => 'This view could not be loaded';
@override
String get hubUnreachableHint => 'Start the hub with chain serve.';

View file

@ -89,6 +89,12 @@ class _ApprovalsPageState extends State<ApprovalsPage>
limit: 200,
project: project,
);
// Only the visible tab has a FutureBuilder listening; give the
// hidden tab's future a silent listener so a load failure there
// never surfaces as an uncaught async error (the FutureBuilder
// that attaches on tab switch still receives the error).
_pendingFuture.then((_) {}, onError: (_) {});
_historyFuture.then((_) {}, onError: (_) {});
});
}
@ -331,7 +337,6 @@ class _PendingList extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final l = AppLocalizations.of(context)!;
return FutureBuilder<List<ApprovalRecord>>(
future: future,
@ -340,16 +345,7 @@ class _PendingList extends StatelessWidget {
return const Center(child: CircularProgressIndicator());
}
if (snapshot.hasError) {
return ChainEmptyState(
icon: Icons.cloud_off_outlined,
iconColor: theme.colorScheme.error,
title: l.hubUnreachable,
hint: l.hubUnreachableHint,
action: FilledButton.tonal(
onPressed: onRetry,
child: Text(l.buttonRetry),
),
);
return HubLoadErrorView(error: snapshot.error!, onRetry: onRetry);
}
final pending = snapshot.data ?? [];
if (pending.isEmpty) {
@ -513,7 +509,6 @@ class _HistoryList extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final l = AppLocalizations.of(context)!;
return FutureBuilder<List<ApprovalRecord>>(
future: future,
@ -522,16 +517,7 @@ class _HistoryList extends StatelessWidget {
return const Center(child: CircularProgressIndicator());
}
if (snapshot.hasError) {
return ChainEmptyState(
icon: Icons.cloud_off_outlined,
iconColor: theme.colorScheme.error,
title: l.hubUnreachable,
hint: l.hubUnreachableHint,
action: FilledButton.tonal(
onPressed: onRetry,
child: Text(l.buttonRetry),
),
);
return HubLoadErrorView(error: snapshot.error!, onRetry: onRetry);
}
final decided = snapshot.data ?? [];
if (decided.isEmpty) {

View file

@ -6,6 +6,7 @@ import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import '../data/error_presentation.dart';
import '../data/friendly_error.dart';
import '../data/hub.dart';
import '../data/workspace.dart';
import '../l10n/app_localizations.dart';
@ -69,7 +70,7 @@ class _AuditPageState extends State<AuditPage> {
String _typeFilter = 'all';
String _search = '';
List<AuditEvent> _events = const [];
String? _error;
Object? _error;
bool _initialLoaded = false;
Timer? _poller;
@ -274,7 +275,7 @@ class _AuditPageState extends State<AuditPage> {
} catch (e) {
if (!mounted) return;
setState(() {
_error = e.toString();
_error = e;
_initialLoaded = true;
});
}
@ -363,7 +364,18 @@ class _AuditPageState extends State<AuditPage> {
),
body: Column(
children: [
_LiveStatusBar(eventCount: filtered.length, error: _error),
// The status bar shows the CLASSIFIED one-liner, never the
// raw thrown object walls of gRPC text belong behind the
// error state's detail expander (state-matrix invariant).
_LiveStatusBar(
eventCount: filtered.length,
error: _error == null
? null
: friendlyError(
_error!,
AppLocalizations.of(context)!,
).headline,
),
Padding(
padding: const EdgeInsets.fromLTRB(
ChainSpace.xl,
@ -388,12 +400,7 @@ class _AuditPageState extends State<AuditPage> {
child: !_initialLoaded
? const Center(child: CircularProgressIndicator())
: _error != null && _events.isEmpty
? ChainEmptyState(
icon: Icons.cloud_off_outlined,
iconColor: theme.colorScheme.error,
title: AppLocalizations.of(context)!.hubUnreachable,
hint: AppLocalizations.of(context)!.hubUnreachableHint,
)
? HubLoadErrorView(error: _error!, onRetry: _refresh)
: filtered.isEmpty
? ChainEmptyState(
icon: Icons.timeline_outlined,

View file

@ -60,17 +60,7 @@ class _DoctorPageState extends State<DoctorPage> {
return const Center(child: CircularProgressIndicator());
}
if (snapshot.hasError) {
final l = AppLocalizations.of(context)!;
return ChainEmptyState(
icon: Icons.cloud_off_outlined,
iconColor: Theme.of(context).colorScheme.error,
title: l.hubUnreachable,
hint: l.hubUnreachableHint,
action: FilledButton.tonal(
onPressed: _refresh,
child: Text(l.buttonRetry),
),
);
return HubLoadErrorView(error: snapshot.error!, onRetry: _refresh);
}
final s = snapshot.data!;
final showUpdate =

View file

@ -126,16 +126,7 @@ class _FederationPageState extends State<FederationPage> {
return const Center(child: CircularProgressIndicator());
}
if (snapshot.hasError) {
return ChainEmptyState(
icon: Icons.cloud_off_outlined,
iconColor: theme.colorScheme.error,
title: l.hubUnreachable,
hint: l.hubUnreachableHint,
action: FilledButton.tonal(
onPressed: _refresh,
child: Text(l.buttonRetry),
),
);
return HubLoadErrorView(error: snapshot.error!, onRetry: _refresh);
}
final sats = snapshot.data ?? [];
if (sats.isEmpty) {

View file

@ -51,30 +51,22 @@ enum RunsLoadIssue {
}
/// Classify a [HubService.listDetachedRuns] failure into the view
/// state the page should render.
/// state the page should render. The runs-specific part is the
/// detached feature gate; everything else delegates to the shared
/// page-load classification.
RunsLoadIssue classifyRunsLoadError(Object error) {
switch (grpcCodeOf(error)) {
case 12: // UNIMPLEMENTED hub predates the RPC
return RunsLoadIssue.unsupported;
case 9: // FAILED_PRECONDITION the hub's detached gate
final msg = (grpcMessageOf(error) ?? '').toLowerCase();
return msg.contains('detached')
? RunsLoadIssue.featureDisabled
: RunsLoadIssue.other;
case 4: // DEADLINE_EXCEEDED
case 14: // UNAVAILABLE
return RunsLoadIssue.unreachable;
if (grpcCodeOf(error) == 9) {
// FAILED_PRECONDITION the hub's detached gate.
final msg = (grpcMessageOf(error) ?? '').toLowerCase();
return msg.contains('detached')
? RunsLoadIssue.featureDisabled
: RunsLoadIssue.other;
}
// Non-gRPC failures: only clear socket-level shapes count as
// "unreachable"; everything else keeps its real story.
final s = error.toString().toLowerCase();
if (s.contains('socketexception') ||
s.contains('connection refused') ||
s.contains('connection terminated') ||
s.contains('failed to connect')) {
return RunsLoadIssue.unreachable;
}
return RunsLoadIssue.other;
return switch (classifyHubLoadError(error)) {
HubLoadIssue.unreachable => RunsLoadIssue.unreachable,
HubLoadIssue.unsupported => RunsLoadIssue.unsupported,
HubLoadIssue.other => RunsLoadIssue.other,
};
}
/// The error rendition of the runs monitor public + callback-driven

View file

@ -288,15 +288,9 @@ class _StorePageState extends State<StorePage> {
return const Center(child: CircularProgressIndicator());
}
if (snap.hasError) {
return ChainEmptyState(
icon: Icons.cloud_off_outlined,
iconColor: theme.colorScheme.error,
title: l.hubUnreachable,
hint: l.hubUnreachableHint,
action: FilledButton.tonal(
onPressed: _runSearch,
child: Text(l.buttonRetry),
),
return HubLoadErrorView(
error: snap.error!,
onRetry: _runSearch,
);
}
final raw = snap.data ?? const <StoreItem>[];

View file

@ -0,0 +1,80 @@
// HubLoadErrorView the one way a page presents "my content
// could not be loaded". Pages used to open-code a "hub not
// reachable" empty state for ANY failure, contradicting the
// sidebar's green connected dot whenever the hub answered but the
// RPC failed (an older hub without the RPC, a feature gate, a real
// bug). This widget routes the failure through the shared
// classification instead:
//
// * unreachable -> the honest "hub not reachable" state
// * unsupported -> "this view needs a newer hub version"
// * other -> "could not load" + the friendly error in a
// copyable detail box (hard rule: errors are
// always copyable)
//
// The state-matrix suite pins the behaviour across every page.
import 'package:flutter/material.dart';
import '../data/friendly_error.dart';
import '../l10n/app_localizations.dart';
import 'chain_empty_state.dart';
import 'chain_error_box.dart';
class HubLoadErrorView extends StatelessWidget {
final Object error;
/// Re-runs the page's load. Rendered on the unreachable and
/// load-failed states when provided.
final VoidCallback? onRetry;
const HubLoadErrorView({super.key, required this.error, this.onRetry});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final l = AppLocalizations.of(context)!;
final retry = onRetry == null
? null
: FilledButton.tonal(
onPressed: onRetry,
child: Text(l.buttonRetry),
);
switch (classifyHubLoadError(error)) {
case HubLoadIssue.unreachable:
return ChainEmptyState(
icon: Icons.cloud_off_outlined,
iconColor: theme.colorScheme.error,
title: l.hubUnreachable,
hint: l.hubUnreachableHint,
action: retry,
);
case HubLoadIssue.unsupported:
return ChainEmptyState(
icon: Icons.system_update_alt_outlined,
title: l.hubViewTooOldTitle,
hint: l.hubViewTooOldHint,
action: retry,
);
case HubLoadIssue.other:
return ChainEmptyState(
icon: Icons.error_outline,
iconColor: theme.colorScheme.error,
title: l.hubViewLoadFailedTitle,
action: Column(
mainAxisSize: MainAxisSize.min,
children: [
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 420),
child: ChainErrorBox(error: error, isError: true),
),
if (retry != null) ...[
const SizedBox(height: 12),
retry,
],
],
),
);
}
}
}

View file

@ -11,6 +11,7 @@ export 'chain_delta_mark.dart';
export 'chain_empty_state.dart';
export 'chain_en_badge.dart';
export 'chain_error_box.dart';
export 'hub_load_error_view.dart';
export 'chain_flow_output.dart';
export 'chain_install_confirm.dart';
export 'chain_log_viewer.dart';