Files
pipelines/app/test/features/runs/ui/runs_sheets_test.dart
T
alan b3c9575fde Runs park on usage limits; failure classes, harness error policy, run budgets
- A stage refused for a Claude usage limit no longer fails its run: the
  runner tries the chats' Claude account auto-switch (per-home setting) and
  reruns the visit, else parks the run in the new waiting_quota status
  (persisted, with reset/resume time in run summaries, details and events)
  and resumes the same visit at reset + 1 min, also after a restart.
  resume_run / `pipelines resume` resumes now; cancel works on parked runs.
  The rerun visit gets a "# Previous attempt" interruption note. Subscription
  limits no longer say "top up the provider account".
- run/retry into an account known to be limited are deferred (quota_policy
  defer/refuse/now; CLI refuses under --json/--yes unless --defer or --now).
- failure_class on runs (quota, loop_exhausted, timeout, permission_denied,
  harness_error, blocked, environment, canceled, interrupted, budget,
  check_failed, other) in RunSummary/RunDetail/events, CLI inspect/runs/wait/
  stats and the app failure line.
- Claude permission denials (permission_denials / refused tool results) fail
  a blocked visit with permission_denied naming the tool use.
- Harness failures are classified transient vs deterministic; deterministic
  ones (and a repeated empty readback) skip error self-loops; transient
  self-loops back off 15 s, 1 min, 4 min.
- Whole-run USD budget: run --budget, server default (run-budget /
  get/set_run_settings); 80% warning notification, stop with class budget.
- App: waiting_quota status/filter with resume time, Resume now and Cancel,
  failure class wording. Docs and skill references updated.

Merges main (check stage, delivery gate, Claude stage restart survival,
schedule changes).

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

185 lines
6.4 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
import 'package:pipelines_app/features/runs/ui/runs_filter_sheet.dart';
import 'package:pipelines_app/features/runs/ui/runs_list.dart';
import 'package:pipelines_app/ui/layout/app_sheet_header.dart';
class _Gateway implements ApiGateway {
final framesController = StreamController<JsonMap>.broadcast();
JsonMap? reply;
@override
Stream<JsonMap> get frames => framesController.stream;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async =>
reply ?? {'runs': []};
}
/// The Runs sheets share one header (title and Done), single-choice groups
/// use check rows, statuses read in sentence case, and the usage page neither
/// repeats its title nor draws a chart of zeros.
void main() {
late _Gateway gateway;
late RunsController controller;
setUp(() {
gateway = _Gateway();
controller = RunsController(RunsRepository(gateway));
});
tearDown(() async {
controller.dispose();
await gateway.framesController.close();
});
Future<void> mount(WidgetTester tester, {String? createdAt}) async {
tester.view.physicalSize = const Size(800, 1400);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final at = createdAt ?? DateTime.now().toIso8601String();
gateway.reply = {
'runs': [
{
'id': 1,
'pipeline_id': 9,
'name': 'Alpha',
'status': 'running',
'created_at': at,
'scheduled': true,
},
],
};
await controller.load();
final list = AnimatedBuilder(
animation: controller,
builder: (context, _) =>
RunsList(controller: controller, onSelected: (_) {}),
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: list)));
await tester.pumpAndSettle();
}
testWidgets('filter sheet has a header whose Done closes it', (tester) async {
await mount(tester);
await tester.tap(find.byKey(const ValueKey('runs.filter')));
await tester.pumpAndSettle();
expect(find.byType(AppSheetHeader), findsOneWidget);
expect(
find.descendant(
of: find.byType(AppSheetHeader),
matching: find.text(runsFilterTitle),
),
findsOneWidget,
);
expect(find.text('Queued'), findsOneWidget);
expect(find.text('queued'), findsNothing);
expect(find.byKey(runsFilterClearKey), findsNothing);
await tester.tap(find.text('Last 7 days'));
await tester.pumpAndSettle();
expect(controller.timeRange, 'last_7_days');
// An active filter offers Clear in the header.
expect(find.byKey(runsFilterClearKey), findsOneWidget);
await tester.tap(find.byKey(runsFilterDoneKey));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('runs.filter.sheet')), findsNothing);
// The applied chip reads in sentence case too.
expect(find.textContaining('Last 7 days'), findsOneWidget);
});
testWidgets('filter uses a dialog wide and a bottom sheet narrow', (
tester,
) async {
await mount(tester);
await tester.tap(find.byKey(const ValueKey('runs.filter')));
await tester.pumpAndSettle();
expect(find.byType(Dialog), findsOneWidget);
await tester.tap(find.byKey(runsFilterDoneKey));
await tester.pumpAndSettle();
tester.view.physicalSize = const Size(500, 1400);
await tester.pump();
await tester.tap(find.byKey(const ValueKey('runs.filter')));
await tester.pumpAndSettle();
expect(find.byType(BottomSheet), findsOneWidget);
});
testWidgets('Material single-choice groups are check rows, not checkboxes', (
tester,
) async {
await mount(tester);
await tester.tap(find.byKey(const ValueKey('runs.filter')));
await tester.pumpAndSettle();
// Eight statuses (with waiting_quota) may be combined: those keep their
// checkboxes.
expect(find.byType(CheckboxListTile), findsNWidgets(8));
final anyTime = find.widgetWithText(ListTile, 'Any time');
expect(anyTime, findsOneWidget);
expect(
find.descendant(of: anyTime, matching: find.byIcon(Icons.check)),
findsOneWidget,
);
expect(
find.descendant(of: anyTime, matching: find.byType(Checkbox)),
findsNothing,
);
final today = find.widgetWithText(ListTile, 'Today');
expect(
find.descendant(of: today, matching: find.byIcon(Icons.check)),
findsNothing,
);
expect(tester.widget<ListTile>(anyTime).selected, isTrue);
});
testWidgets('Material sort opens an anchored choice menu', (tester) async {
await mount(tester);
await tester.tap(find.byKey(const ValueKey('runs.sort')));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('app-choice-menu')), findsOneWidget);
await tester.tap(find.text('Oldest first'));
await tester.pumpAndSettle();
expect(controller.sort, 'oldest_first');
});
testWidgets('the usage page is honest when nothing was reported', (
tester,
) async {
await mount(tester, createdAt: DateTime(2020, 1, 1).toIso8601String());
await tester.tap(find.byKey(const ValueKey('runs.stats')));
await tester.pumpAndSettle();
// The bar says Usage; the body does not repeat it.
expect(find.text('Usage'), findsOneWidget);
expect(find.byKey(const ValueKey('runs.stats.usage.empty')), findsOne);
expect(find.byKey(const ValueKey('runs.stats.days')), findsNothing);
expect(find.byKey(const ValueKey('runs.stats.days.empty')), findsOne);
expect(find.text('Running'), findsOneWidget);
expect(find.text('0'), findsNothing);
});
testWidgets('the 7-day chart shows bars over an axis when runs started', (
tester,
) async {
await mount(tester);
await tester.tap(find.byKey(const ValueKey('runs.stats')));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('runs.stats.days')), findsOneWidget);
expect(find.byKey(const ValueKey('runs.stats.days.empty')), findsNothing);
// Only the day with a run is labelled with its count.
final days = find.byKey(const ValueKey('runs.stats.days'));
expect(find.descendant(of: days, matching: find.text('1')), findsOne);
expect(find.text('0'), findsNothing);
expect(tester.takeException(), isNull);
});
}