Files
pipelines/app/test/ui/status/error_notice_test.dart
T
alan e72bee3faa First run: empty states with a next step, harness setup instead of errors
- One shared EmptyState (icon on a tonal disc, title, one line, primary
  action) that follows the design tokens; used by Runs (Start your first
  run), Pipelines (Browse templates), Schedules and the chat list (Start a
  chat).
- Chat on a server without an agent harness showed "Bad state: No saved
  machine is connected.": the federated list now keeps the server's own
  refusal, treats an omitted empty list as no chats, and the list shows a
  "Set up an agent" state with the harness setup command and Refresh. New
  chat shows the same step instead of a form that can only be refused.
- A run that fails because no harness CLI exists names the setup command
  beside the raw reason; error advice gains a noHarness kind.
- Templates opened before the app connected stayed on "Not connected";
  it now reads again when the connection arrives. The Pipelines empty state
  links to Templates, which had no entry point in the UI.
- The first-launch walkthrough waits briefly for the connection, so a
  connected web app is no longer told to connect; the empty-server check
  treats omitted lists and no chat harness as empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 23:29:23 +00:00

98 lines
3.1 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/error_advice.dart';
import 'package:pipelines_app/core/transport/connection_state.dart';
import 'package:pipelines_app/ui/status/error_notice.dart';
import 'package:pipelines_app/ui/text/plural.dart';
/// Common failures read as what to do, with the raw detail kept behind
/// Details; any other failure reads exactly as reported.
void main() {
test('common failures map to their kind', () {
expect(
errorAdviceKind(const NotConnectedError()),
ErrorAdviceKind.notConnected,
);
expect(
errorAdviceKind(StateError('Connection closed')),
ErrorAdviceKind.notConnected,
);
expect(
errorAdviceKind(const ProtocolError('unknown command: list_schedules')),
ErrorAdviceKind.serverTooOld,
);
expect(
errorAdviceKind(const ProtocolError('x', code: 'elevation_required')),
ErrorAdviceKind.permission,
);
expect(
errorAdviceKind('permission denied: /srv'),
ErrorAdviceKind.permission,
);
expect(
errorAdviceKind(TimeoutException('request timed out after 30000ms')),
ErrorAdviceKind.timeout,
);
expect(
errorAdviceKind(
const ProtocolError('chat is not configured on this server'),
),
ErrorAdviceKind.noHarness,
);
expect(
errorAdviceKind(
'HARNESS TRANSPORT: harness unreachable: cannot run the selected '
'OpenCode CLI',
),
ErrorAdviceKind.noHarness,
);
expect(
errorAdviceSentence(ErrorAdviceKind.noHarness),
contains('pipelines harness setup'),
);
expect(errorAdviceKind('pipeline 4 has no stage review'), isNull);
final advice = errorAdvice(StateError('Connection closed'));
expect(advice?.detail, 'Connection closed');
expect(advice?.sentence, contains('Settings'));
});
testWidgets('a common failure says what to do and keeps its detail', (
tester,
) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: ErrorNotice(error: 'unknown command: list_schedules'),
),
),
);
expect(
find.text(errorAdviceSentence(ErrorAdviceKind.serverTooOld)),
findsOneWidget,
);
expect(find.text('unknown command: list_schedules'), findsNothing);
await tester.tap(find.byKey(errorNoticeDetailsKey));
await tester.pump();
expect(find.text('unknown command: list_schedules'), findsOneWidget);
expect(find.byKey(errorNoticeCopyKey), findsOneWidget);
});
testWidgets('any other failure reads as reported', (tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(body: ErrorNotice(error: 'Bad state: pipeline gone')),
),
);
expect(find.text('Bad state: pipeline gone'), findsOneWidget);
expect(find.byKey(errorNoticeDetailsKey), findsNothing);
});
test('counts are pluralised', () {
expect(countLabel(1, 'stage'), '1 stage');
expect(countLabel(3, 'stage'), '3 stages');
expect(countLabel(0, 'file'), '0 files');
});
}