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>
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_app.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_route.dart';
|
||||
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
|
||||
import 'package:pipelines_app/shell/detached/detached_window_scope.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||
import '../chat_registration_test.dart' show webServer;
|
||||
import 'detached_fixtures.dart';
|
||||
|
||||
Future<void> _run(WidgetTester tester, ChatServer server, Duration d) async {
|
||||
for (var t = 0; t < d.inMilliseconds; t += 16) {
|
||||
server.answer();
|
||||
await tester.pump(const Duration(milliseconds: 16));
|
||||
}
|
||||
server.answer();
|
||||
}
|
||||
|
||||
void main() {
|
||||
late FakeDetachedPlatform platform;
|
||||
late ChatServer server;
|
||||
|
||||
Future<void> pumpChat(WidgetTester tester) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
tester.view.physicalSize = const Size(720, 860);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
addTearDown(() => TerminalLayout.instance.persist = true);
|
||||
platform = FakeDetachedPlatform();
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
server = ChatServer(channel);
|
||||
await tester.pumpWidget(
|
||||
DetachedWindowApp(
|
||||
route: DetachedRoute.chat('a')!,
|
||||
server: webServer(),
|
||||
client: PipelinesClient(channelFactory: (_) => channel),
|
||||
platform: platform,
|
||||
),
|
||||
);
|
||||
await _run(tester, server, const Duration(milliseconds: 900));
|
||||
}
|
||||
|
||||
testWidgets('a detached chat is the chat pane alone, named after it', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpChat(tester);
|
||||
expect(find.byType(ChatThreadView), findsOneWidget);
|
||||
expect(find.text('Hello from chat'), findsOneWidget);
|
||||
// No shell: no navigation, no chat list, no other chat.
|
||||
expect(find.byType(NavigationRail), findsNothing);
|
||||
expect(find.byType(NavigationBar), findsNothing);
|
||||
expect(find.text('Chat b'), findsNothing);
|
||||
final app = tester.widget<MaterialApp>(find.byType(MaterialApp));
|
||||
expect(app.title, 'Chat a · Pipelines');
|
||||
// Inside a detached window there is nothing to send to another one.
|
||||
final context = tester.element(find.byType(ChatThreadView));
|
||||
expect(DetachedWindowScope.maybeOf(context), isNull);
|
||||
});
|
||||
|
||||
testWidgets('a detached window writes no shared layout', (tester) async {
|
||||
await pumpChat(tester);
|
||||
expect(server.workspaceWrites, isEmpty);
|
||||
expect(
|
||||
server.requests.where((r) => r['type'] == 'chat_open_workspace'),
|
||||
isEmpty,
|
||||
reason: 'the open-chat workspace is the main window\'s',
|
||||
);
|
||||
expect(TerminalLayout.instance.persist, isFalse);
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
expect(prefs.getKeys().where((k) => k.contains('window')), isEmpty);
|
||||
expect(prefs.getString(terminalLayoutKey), isNull);
|
||||
});
|
||||
|
||||
testWidgets('Bring back hands the chat to the main window and closes', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpChat(tester);
|
||||
await tester.tap(find.byTooltip('More actions').hitTestable().first);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Bring back to main window'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(platform.sent.single, {
|
||||
'type': 'bring-back',
|
||||
'kind': 'chat',
|
||||
'id': 'a',
|
||||
});
|
||||
expect(platform.closed, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('with no main window, Bring back opens the full app here', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpChat(tester);
|
||||
platform.mainOpen = false;
|
||||
await tester.tap(find.byTooltip('More actions').hitTestable().first);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Bring back to main window'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(platform.sent, isEmpty);
|
||||
expect(platform.becameMain, '/chat/a');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:pipelines_app/application/detached/detached_platform.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_route.dart';
|
||||
import 'package:pipelines_app/shell/detached/detached_window_scope.dart';
|
||||
|
||||
import '../../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||
|
||||
/// A platform that records what it was asked to open and send.
|
||||
class FakeDetachedPlatform extends DetachedPlatform {
|
||||
DetachedLaunch result = DetachedLaunch.opened;
|
||||
final launches = <({DetachedRoute route, String title, bool tab})>[];
|
||||
final stored = <String, String>{};
|
||||
final sent = <DetachedMessage>[];
|
||||
bool mainOpen = true;
|
||||
bool closed = false;
|
||||
String? becameMain;
|
||||
final incoming = StreamController<DetachedMessage>.broadcast();
|
||||
|
||||
@override
|
||||
bool get supported => true;
|
||||
|
||||
@override
|
||||
Future<DetachedLaunch> launch(
|
||||
DetachedRoute route, {
|
||||
required String title,
|
||||
required Size size,
|
||||
bool tab = false,
|
||||
}) async {
|
||||
launches.add((route: route, title: title, tab: tab));
|
||||
return tab ? DetachedLaunch.opened : result;
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<DetachedMessage> get messages => incoming.stream;
|
||||
|
||||
@override
|
||||
Future<void> put(String token, String json) async => stored[token] = json;
|
||||
|
||||
@override
|
||||
Future<String?> take(String token) async => stored[token];
|
||||
|
||||
@override
|
||||
Future<bool> sendToMain(DetachedMessage message) async {
|
||||
if (!mainOpen) return false;
|
||||
sent.add(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> closeSelf() async => closed = true;
|
||||
|
||||
@override
|
||||
Future<bool> becomeMain(String appPath) async {
|
||||
becameMain = appPath;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// An opener that records the items and opens them at once.
|
||||
class FakeOpener implements DetachedWindowOpener {
|
||||
final chats = <String>[];
|
||||
final terminals = <String>[];
|
||||
final diffs = <List<Map<String, Object?>>>[];
|
||||
bool opens = true;
|
||||
|
||||
@override
|
||||
void openChat(
|
||||
String sessionId, {
|
||||
required String title,
|
||||
void Function()? onOpened,
|
||||
}) {
|
||||
chats.add(sessionId);
|
||||
if (opens) onOpened?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
void openTerminal({
|
||||
String tabKey = '',
|
||||
required String title,
|
||||
void Function()? onOpened,
|
||||
}) {
|
||||
terminals.add(tabKey);
|
||||
if (opens) onOpened?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
void openDiff(
|
||||
List<Map<String, Object?>> files, {
|
||||
int initialIndex = 0,
|
||||
required String title,
|
||||
void Function()? onOpened,
|
||||
}) {
|
||||
diffs.add(files);
|
||||
if (opens) onOpened?.call();
|
||||
}
|
||||
}
|
||||
|
||||
/// Answers a chat app's requests over [channel] like a server with chats
|
||||
/// a, b and c, recording each request (type and body).
|
||||
class ChatServer {
|
||||
ChatServer(this.channel, {List<Object?> openChats = const []})
|
||||
: _entries = openChats;
|
||||
|
||||
final FakeChannel channel;
|
||||
final _answered = <Object?>{};
|
||||
final requests = <Map<String, dynamic>>[];
|
||||
List<Object?> _entries;
|
||||
int _revision = 1;
|
||||
|
||||
/// The open-chat writes the app sent (`chat_open_workspace_request`).
|
||||
List<Map<String, dynamic>> get workspaceWrites => [
|
||||
for (final request in requests)
|
||||
if (request['type'] == 'chat_open_workspace' &&
|
||||
request['chat_open_workspace_request'] != null)
|
||||
request,
|
||||
];
|
||||
|
||||
void answer() {
|
||||
for (final raw in channel.outgoing.toList()) {
|
||||
final m = jsonDecode(raw as String) as Map<String, dynamic>;
|
||||
final id = m['id'];
|
||||
if (id == null || !_answered.add(id)) continue;
|
||||
requests.add(m);
|
||||
channel.incoming.add(jsonEncode(_reply('${m['type']}', id, m)));
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object?> _reply(String type, Object? id, Map<String, dynamic> m) {
|
||||
switch (type) {
|
||||
case 'chat_sessions':
|
||||
return {
|
||||
'id': id,
|
||||
'type': type,
|
||||
'chat_sessions': [
|
||||
for (final s in const ['a', 'b', 'c'])
|
||||
{
|
||||
'id': s,
|
||||
'title': 'Chat $s',
|
||||
'directory': '/workspace/demo',
|
||||
'updated_at': '2026-11-12T10:00:00Z',
|
||||
},
|
||||
],
|
||||
};
|
||||
case 'chat_messages':
|
||||
return {
|
||||
'id': id,
|
||||
'type': 'chat_history',
|
||||
'chat_history': {
|
||||
'messages': [
|
||||
{
|
||||
'id': 'm0',
|
||||
'role': 'user',
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Hello from chat'},
|
||||
],
|
||||
},
|
||||
],
|
||||
'next_cursor': '',
|
||||
'has_more': false,
|
||||
},
|
||||
};
|
||||
case 'chat_open_workspace':
|
||||
final write = m['chat_open_workspace_request'] as Map?;
|
||||
if (write != null) {
|
||||
_revision++;
|
||||
_entries = write['entries'] as List<Object?>;
|
||||
}
|
||||
return {
|
||||
'id': id,
|
||||
'type': type,
|
||||
'chat_open_workspace': {'revision': _revision, 'entries': _entries},
|
||||
};
|
||||
default:
|
||||
return {'id': id, 'type': type};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_route.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_windows.dart';
|
||||
import 'package:pipelines_app/application/pipelines_app.dart';
|
||||
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/shell/detached/detached_window_scope.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||
import '../chat_registration_test.dart' show webServer;
|
||||
import 'detached_fixtures.dart';
|
||||
|
||||
Future<void> _run(WidgetTester tester, ChatServer server, Duration d) async {
|
||||
for (var t = 0; t < d.inMilliseconds; t += 16) {
|
||||
server.answer();
|
||||
await tester.pump(const Duration(milliseconds: 16));
|
||||
}
|
||||
server.answer();
|
||||
}
|
||||
|
||||
void main() {
|
||||
Future<(ChatServer, FakeDetachedPlatform)> pump(
|
||||
WidgetTester tester, {
|
||||
String route = '/chat/a',
|
||||
}) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
tester.view.physicalSize = const Size(1600, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final platform = FakeDetachedPlatform();
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final server = ChatServer(
|
||||
channel,
|
||||
openChats: [
|
||||
{'session_id': 'a'},
|
||||
],
|
||||
);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse(route)),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
await tester.pumpWidget(
|
||||
PipelinesApp(
|
||||
androidSupported: false,
|
||||
server: webServer(),
|
||||
client: PipelinesClient(channelFactory: (_) => channel),
|
||||
routeInformationProvider: provider,
|
||||
detachedPlatform: platform,
|
||||
),
|
||||
);
|
||||
await _run(tester, server, const Duration(milliseconds: 1200));
|
||||
return (server, platform);
|
||||
}
|
||||
|
||||
testWidgets('the main window offers new windows and sends the chat out of '
|
||||
'its workspace', (tester) async {
|
||||
final (server, platform) = await pump(tester);
|
||||
final thread = find.byType(ChatThreadView);
|
||||
expect(thread, findsOneWidget);
|
||||
expect(DetachedWindowScope.maybeOf(tester.element(thread)), isNotNull);
|
||||
await tester.tap(
|
||||
find
|
||||
.descendant(of: thread, matching: find.byTooltip('More actions'))
|
||||
.hitTestable(),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Open in new window (Alt+Shift+Y)'));
|
||||
await _run(tester, server, const Duration(milliseconds: 600));
|
||||
expect(platform.launches.single.route, DetachedRoute.chat('a'));
|
||||
expect(platform.launches.single.title, 'Chat a');
|
||||
expect(find.byType(ChatThreadView), findsNothing);
|
||||
// The main window's own workspace is written without the chat.
|
||||
final write = server.workspaceWrites.last['chat_open_workspace_request'];
|
||||
expect((write as Map)['entries'], isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('a chat brought back opens in the main window', (tester) async {
|
||||
final (server, platform) = await pump(tester, route: '/runs');
|
||||
expect(find.byType(ChatThreadView), findsNothing);
|
||||
platform.incoming.add(
|
||||
const DetachedReturn(DetachedKind.chat, 'b').toMessage(),
|
||||
);
|
||||
await _run(tester, server, const Duration(milliseconds: 900));
|
||||
final thread = tester.widget<ChatThreadView>(find.byType(ChatThreadView));
|
||||
expect(thread.sessionId, 'b');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_platform.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_route.dart';
|
||||
|
||||
void main() {
|
||||
test('each kind round-trips through its path', () {
|
||||
final routes = [
|
||||
DetachedRoute.chat('sess_01-A')!,
|
||||
DetachedRoute.terminal(),
|
||||
DetachedRoute.terminal('mac/term 1'),
|
||||
DetachedRoute.diff('Tok_en-9')!,
|
||||
];
|
||||
for (final route in routes) {
|
||||
expect(DetachedRoute.parse(route.path), route, reason: route.path);
|
||||
}
|
||||
expect(DetachedRoute.chat('a')!.path, '/window/chat/a');
|
||||
expect(DetachedRoute.terminal().path, '/window/terminal');
|
||||
expect(
|
||||
DetachedRoute.terminal('server/t1').path,
|
||||
'/window/terminal?tab=server%2Ft1',
|
||||
);
|
||||
expect(DetachedRoute.diff('abc')!.path, '/window/diff/abc');
|
||||
});
|
||||
|
||||
test('a full URL with an origin and fixture parameters parses', () {
|
||||
final route = DetachedRoute.parse(
|
||||
'https://tank.example.ts.net/window/chat/perf-chat-0?chats=2&theme=dark',
|
||||
);
|
||||
expect(route, DetachedRoute.chat('perf-chat-0'));
|
||||
expect(
|
||||
DetachedRoute.parse('http://x/window/terminal?tab=s%2F7&theme=dark'),
|
||||
DetachedRoute.terminal('s/7'),
|
||||
);
|
||||
});
|
||||
|
||||
test('ordinary app locations and malformed windows are not detached', () {
|
||||
for (final location in [
|
||||
'/',
|
||||
'/chat/a',
|
||||
'/runs/7',
|
||||
'/window',
|
||||
'/window/chat',
|
||||
'/window/chat/a/b',
|
||||
'/window/chat/not%20valid',
|
||||
'/window/diff/has.dot',
|
||||
'/window/diff/${'x' * 65}',
|
||||
'/window/pipelines/3',
|
||||
'/windows/chat/a',
|
||||
'',
|
||||
]) {
|
||||
expect(DetachedRoute.parse(location), isNull, reason: location);
|
||||
}
|
||||
expect(DetachedRoute.chat('no spaces'), isNull);
|
||||
expect(DetachedRoute.diff(''), isNull);
|
||||
expect(DetachedRoute.terminal('k' * 600).id, isEmpty);
|
||||
});
|
||||
|
||||
test('a native launch names its window by argument or environment', () {
|
||||
final chat = DetachedRoute.chat('a');
|
||||
expect(DetachedRoute.fromLaunch(['--detached', '/window/chat/a']), chat);
|
||||
expect(DetachedRoute.fromLaunch(['--detached=/window/chat/a']), chat);
|
||||
expect(
|
||||
DetachedRoute.fromLaunch(const [], {
|
||||
'PIPELINES_DETACHED': '/window/terminal',
|
||||
}),
|
||||
DetachedRoute.terminal(),
|
||||
);
|
||||
expect(DetachedRoute.fromLaunch(const []), isNull);
|
||||
expect(
|
||||
DetachedRoute.fromLaunch(const [], {'PIPELINES_DETACHED': ''}),
|
||||
isNull,
|
||||
);
|
||||
expect(DetachedRoute.fromLaunch(['--detached']), isNull);
|
||||
});
|
||||
|
||||
test('messages carry a marker; anything else is ignored', () {
|
||||
final text = encodeDetachedMessage({'type': 'bring-back', 'id': 'a'});
|
||||
expect(decodeDetachedMessage(text), {'type': 'bring-back', 'id': 'a'});
|
||||
expect(decodeDetachedMessage('{"type":"bring-back"}'), isNull);
|
||||
expect(decodeDetachedMessage('not json'), isNull);
|
||||
expect(decodeDetachedMessage('[1]'), isNull);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_platform.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_route.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_windows.dart';
|
||||
|
||||
import 'detached_fixtures.dart';
|
||||
|
||||
void main() {
|
||||
late FakeDetachedPlatform platform;
|
||||
late List<DetachedReturn> returned;
|
||||
late GlobalKey<ScaffoldMessengerState> messenger;
|
||||
late DetachedWindows windows;
|
||||
|
||||
setUp(() {
|
||||
platform = FakeDetachedPlatform();
|
||||
returned = [];
|
||||
messenger = GlobalKey<ScaffoldMessengerState>();
|
||||
windows = DetachedWindows(
|
||||
platform: platform,
|
||||
onReturn: returned.add,
|
||||
messenger: messenger,
|
||||
)..start();
|
||||
});
|
||||
tearDown(() => windows.dispose());
|
||||
|
||||
Future<void> host(WidgetTester tester) => tester.pumpWidget(
|
||||
MaterialApp(
|
||||
scaffoldMessengerKey: messenger,
|
||||
home: const Scaffold(body: SizedBox()),
|
||||
),
|
||||
);
|
||||
|
||||
testWidgets('an opened window runs onOpened; the item leaves after', (
|
||||
tester,
|
||||
) async {
|
||||
await host(tester);
|
||||
var opened = 0;
|
||||
windows.openChat('a', title: 'Chat a', onOpened: () => opened++);
|
||||
await tester.pump();
|
||||
expect(platform.launches.single.route, DetachedRoute.chat('a'));
|
||||
expect(platform.launches.single.title, 'Chat a');
|
||||
expect(opened, 1);
|
||||
|
||||
windows.openTerminal(tabKey: 's/1', title: 'Terminal: zsh');
|
||||
await tester.pump();
|
||||
expect(platform.launches.last.route, DetachedRoute.terminal('s/1'));
|
||||
});
|
||||
|
||||
testWidgets('a blocked popup says so and offers a tab, which opens it', (
|
||||
tester,
|
||||
) async {
|
||||
await host(tester);
|
||||
platform.result = DetachedLaunch.blocked;
|
||||
var opened = 0;
|
||||
windows.openChat('a', title: 'Chat a', onOpened: () => opened++);
|
||||
await tester.pumpAndSettle();
|
||||
expect(opened, 0, reason: 'nothing leaves the main window yet');
|
||||
expect(find.textContaining('blocked the new window'), findsOneWidget);
|
||||
await tester.tap(find.text('Open in tab'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(platform.launches.last.tab, isTrue);
|
||||
expect(opened, 1);
|
||||
});
|
||||
|
||||
testWidgets('a failure is reported and the item stays', (tester) async {
|
||||
await host(tester);
|
||||
platform.result = DetachedLaunch.failed;
|
||||
var opened = 0;
|
||||
windows.openChat('a', title: 'Chat a', onOpened: () => opened++);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Could not open a new window.'), findsOneWidget);
|
||||
expect(opened, 0);
|
||||
});
|
||||
|
||||
testWidgets('a diff is handed over under its token before it opens', (
|
||||
tester,
|
||||
) async {
|
||||
await host(tester);
|
||||
windows.openDiff(
|
||||
[
|
||||
{'path': 'lib/a.dart', 'kind': 'modified'},
|
||||
],
|
||||
initialIndex: 0,
|
||||
title: 'a.dart',
|
||||
);
|
||||
await tester.pump();
|
||||
final route = platform.launches.single.route;
|
||||
expect(route.kind, DetachedKind.diff);
|
||||
final stored = jsonDecode(platform.stored[route.id]!) as Map;
|
||||
expect((stored['files'] as List).single['path'], 'lib/a.dart');
|
||||
});
|
||||
|
||||
testWidgets('items a detached window gives back reach the main window', (
|
||||
tester,
|
||||
) async {
|
||||
await host(tester);
|
||||
const diff = DetachedReturn(
|
||||
DetachedKind.diff,
|
||||
'tok',
|
||||
files: [
|
||||
{'path': 'a', 'kind': 'added'},
|
||||
],
|
||||
initialIndex: 0,
|
||||
);
|
||||
platform.incoming
|
||||
..add(const DetachedReturn(DetachedKind.chat, 'a').toMessage())
|
||||
..add(diff.toMessage())
|
||||
..add({'type': 'something else'});
|
||||
await tester.pump();
|
||||
expect(returned.map((r) => (r.kind, r.id)), [
|
||||
(DetachedKind.chat, 'a'),
|
||||
(DetachedKind.diff, 'tok'),
|
||||
]);
|
||||
expect(returned.last.files.single['path'], 'a');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/artifacts/actions/artifact_transfer_io.dart'
|
||||
as transfer;
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_html_view_native.dart';
|
||||
|
||||
final _linux = TargetPlatformVariant.only(TargetPlatform.linux);
|
||||
|
||||
/// The Linux app has no web view and no file share sheet: it says so rather
|
||||
/// than failing to create the web view or throwing from Share.
|
||||
void main() {
|
||||
test('only Android, iOS and macOS have the HTML web view', () {
|
||||
for (final platform in TargetPlatform.values) {
|
||||
expect(
|
||||
inertHtmlViewSupported(platform),
|
||||
platform == TargetPlatform.android ||
|
||||
platform == TargetPlatform.iOS ||
|
||||
platform == TargetPlatform.macOS,
|
||||
reason: '$platform',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('an HTML artifact on Linux explains why it is not previewed', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(body: InertHtmlView(html: '<p>report</p>')),
|
||||
),
|
||||
);
|
||||
expect(find.text(inertHtmlUnsupportedMessage), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
// A new document does not reach for a web view either.
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(body: InertHtmlView(html: '<p>next</p>')),
|
||||
),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
}, variant: _linux);
|
||||
|
||||
testWidgets('Linux offers Download but not Share', (tester) async {
|
||||
expect(transfer.artifactDownloadSupported, isTrue);
|
||||
expect(transfer.artifactShareSupported, isFalse);
|
||||
expect(transfer.artifactShareUnsupportedMessage, contains('Download'));
|
||||
}, variant: _linux);
|
||||
|
||||
test('other native platforms keep Share', () {
|
||||
expect(transfer.artifactShareSupported, isTrue);
|
||||
expect(transfer.artifactShareUnsupportedMessage, isEmpty);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_diff.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_route.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_window_body.dart';
|
||||
import 'package:pipelines_app/features/changes/changes.dart';
|
||||
import 'package:pipelines_app/shell/detached/detached_window_scope.dart';
|
||||
|
||||
import '../../application/detached/detached_fixtures.dart';
|
||||
|
||||
FileChange _file(String path) => FileChange(
|
||||
path: path,
|
||||
kind: ChangeKind.modified,
|
||||
patch: '--- a/$path\n+++ b/$path\n@@ -0,0 +1,1 @@\n+line of $path\n',
|
||||
beforeMode: '100644',
|
||||
afterMode: '100755',
|
||||
).withSteps(const ['build']);
|
||||
|
||||
void main() {
|
||||
setUp(() => diffShowsAllFiles.value = false);
|
||||
|
||||
test('a file change survives the hand-over to another window', () {
|
||||
final file = _file('lib/a.dart');
|
||||
final back = FileChange.fromHandover(
|
||||
jsonDecode(jsonEncode(file.toJson())),
|
||||
)!;
|
||||
expect(back.path, file.path);
|
||||
expect(back.kind, file.kind);
|
||||
expect(back.patch, file.patch);
|
||||
expect(back.beforeMode, '100644');
|
||||
expect(back.afterMode, '100755');
|
||||
expect(back.steps, ['build']);
|
||||
expect(back.added, 1);
|
||||
});
|
||||
|
||||
testWidgets('a diff page offers Open in new window and closes once open', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(1000, 700);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final opener = FakeOpener();
|
||||
final files = [_file('lib/a.dart'), _file('lib/b.dart')];
|
||||
await tester.pumpWidget(
|
||||
DetachedWindowScope(
|
||||
opener: opener,
|
||||
child: MaterialApp(
|
||||
home: Builder(
|
||||
builder: (context) => Scaffold(
|
||||
body: TextButton(
|
||||
onPressed: () =>
|
||||
showFileDiffViewer(context, files[1], files: files),
|
||||
child: const Text('open'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('open'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(FileDiffPage), findsOneWidget);
|
||||
await tester.tap(find.byTooltip('Open in new window'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(opener.diffs.single.map((f) => f['path']), [
|
||||
'lib/a.dart',
|
||||
'lib/b.dart',
|
||||
]);
|
||||
expect(find.byType(FileDiffPage), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('without platform windows the diff page has no such button', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(home: FileDiffPage(files: [_file('a')])),
|
||||
);
|
||||
expect(find.byTooltip('Open in new window'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a detached diff shows the handed files and gives them back', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(1000, 820);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final platform = FakeDetachedPlatform();
|
||||
platform.stored['tok'] = jsonEncode({
|
||||
'files': [_file('lib/a.dart').toJson(), _file('lib/b.dart').toJson()],
|
||||
'index': 1,
|
||||
});
|
||||
final titles = <String>[];
|
||||
final back = <(DetachedKind, String, int, int)>[];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: DetachedDiff(
|
||||
token: 'tok',
|
||||
platform: platform,
|
||||
window: DetachedWindowControls(
|
||||
ready: ValueNotifier(true),
|
||||
sync: ValueNotifier(0),
|
||||
setTitle: titles.add,
|
||||
close: () {},
|
||||
bringBackItem: (kind, id, files, index) =>
|
||||
back.add((kind, id, files.length, index)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(FileDiffPage), findsOneWidget);
|
||||
expect(titles.last, '2 files changed');
|
||||
expect(find.text('b.dart'), findsWidgets);
|
||||
// No Back in a window of its own, and no window to open from it.
|
||||
expect(find.byType(BackButton), findsNothing);
|
||||
expect(find.byTooltip('Open in new window'), findsNothing);
|
||||
await tester.tap(find.byTooltip('Bring back to main window'));
|
||||
expect(back, [(DetachedKind.diff, 'tok', 2, 1)]);
|
||||
});
|
||||
|
||||
testWidgets('a diff handed over to nobody says it is gone', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: DetachedDiff(
|
||||
token: 'missing',
|
||||
platform: FakeDetachedPlatform(),
|
||||
window: DetachedWindowControls(
|
||||
ready: ValueNotifier(true),
|
||||
sync: ValueNotifier(0),
|
||||
setTitle: (_) {},
|
||||
close: () {},
|
||||
bringBackItem: (_, _, _, _) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('This diff is no longer available.'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -13,7 +13,7 @@ const _expected = {
|
||||
'budget':
|
||||
'The workspace snapshot ran out of text budget, so no diff text was '
|
||||
'recorded.',
|
||||
'lines': 'The change is over 5,000 lines, so no diff text was recorded.',
|
||||
'lines': 'The change is over 20,000 lines, so no diff text was recorded.',
|
||||
'evidence_size':
|
||||
"This visit's recorded changes reached their size limit, so this patch "
|
||||
'was dropped.',
|
||||
@@ -24,6 +24,15 @@ const _expected = {
|
||||
"The file's content at stage start couldn't be recovered from Git, so no "
|
||||
'diff was recorded.',
|
||||
'binary': 'Binary file; only its metadata was recorded.',
|
||||
'symlink': 'Symbolic link; only the change to its target was recorded.',
|
||||
'protected':
|
||||
'A protected file (secrets, credentials or a database); its content is '
|
||||
'never read, only that it changed.',
|
||||
'generated':
|
||||
'A lockfile, minified or generated file; it is listed without a diff.',
|
||||
'large':
|
||||
'This file is too large to hash, so it was compared by size and '
|
||||
'modification time only.',
|
||||
};
|
||||
|
||||
FileChange _noPatch(Object? reason, {bool binary = false}) =>
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/core/servers/server_scope.dart';
|
||||
import 'package:pipelines_app/features/chat/chat_runtime.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/screen.dart';
|
||||
import 'package:pipelines_app/features/chat/windows/chat_windows.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace_store.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_frame.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_host.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_kind.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_manager.dart';
|
||||
|
||||
import '../../application/detached/detached_fixtures.dart';
|
||||
import 'conversation/chat_thread_fixtures.dart';
|
||||
|
||||
class _Gateway extends FakeChatGateway {
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
if (type == 'chat_sessions') {
|
||||
return Future.value({
|
||||
'chat_sessions': [
|
||||
for (final id in ['a', 'b', 'c'])
|
||||
{'id': id, 'title': 'Chat $id', 'directory': '/home/$id'},
|
||||
],
|
||||
});
|
||||
}
|
||||
if (type == 'chat_shells') return Future.value({'chat_shells': []});
|
||||
return super.call(type, fields);
|
||||
}
|
||||
}
|
||||
|
||||
const _label = 'Open in new window (Alt+Shift+Y)';
|
||||
|
||||
Finder _thread(String id) => find.byWidgetPredicate(
|
||||
(widget) => widget is ChatThreadView && widget.sessionId == id,
|
||||
skipOffstage: false,
|
||||
);
|
||||
|
||||
List<String> _tiled(WidgetTester tester) => [
|
||||
for (final pane
|
||||
in tester
|
||||
.widget<ChatWorkspace>(
|
||||
find.byType(ChatWorkspace, skipOffstage: false),
|
||||
)
|
||||
.controller
|
||||
.panes)
|
||||
pane.sessionId,
|
||||
];
|
||||
|
||||
/// The Chat destination with its floating windows, as the app hosts them,
|
||||
/// with [opener] as the platform's new windows (none when null).
|
||||
class _App {
|
||||
final gateway = _Gateway()..history = (_) async => chatPage([]);
|
||||
final opener = FakeOpener();
|
||||
late final ChatRuntime runtime;
|
||||
late final WindowManager manager;
|
||||
late final ChatWindows windows;
|
||||
|
||||
Future<void> start(WidgetTester tester, {bool detached = true}) async {
|
||||
tester.view.physicalSize = const Size(1800, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final layout = ChatWorkspaceController()
|
||||
..open('a')
|
||||
..splitActive('b', ChatSplitAxis.horizontal);
|
||||
SharedPreferences.setMockInitialValues({
|
||||
scopedServerKey(chatWorkspacePreferenceKey, 'server-a'): layout
|
||||
.snapshot()!
|
||||
.encode(),
|
||||
});
|
||||
bindServerIdentity(gateway, 'server-a');
|
||||
runtime = ChatRuntime(gateway: gateway, serverKey: 'server-a');
|
||||
manager = WindowManager(kinds: WindowKinds(), server: 'server-a');
|
||||
windows = ChatWindows(
|
||||
manager: manager,
|
||||
runtime: runtime,
|
||||
openInChat: (_) {},
|
||||
)..start();
|
||||
if (detached) windows.detached = opener;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
ChatScreen(
|
||||
gateway: gateway,
|
||||
persistWorkspace: true,
|
||||
runtime: runtime,
|
||||
windows: windows,
|
||||
),
|
||||
Positioned.fill(child: WindowHost(manager: manager)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
addTearDown(() async {
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
windows.dispose();
|
||||
runtime.dispose();
|
||||
manager.dispose();
|
||||
gateway.close();
|
||||
});
|
||||
}
|
||||
|
||||
List<String> get floating => [for (final w in windows.windows) w.contentId];
|
||||
}
|
||||
|
||||
Future<void> _paneMenu(WidgetTester tester, String session) async {
|
||||
await tester.tap(
|
||||
find
|
||||
.descendant(
|
||||
of: _thread(session),
|
||||
matching: find.byTooltip('More actions'),
|
||||
)
|
||||
.hitTestable(),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> _rowMenu(WidgetTester tester, String id) async {
|
||||
await tester.tap(find.byTooltip('Chat actions for Chat $id').first);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('the pane menu sends a tiled chat to a new window', (
|
||||
tester,
|
||||
) async {
|
||||
final app = _App();
|
||||
await app.start(tester);
|
||||
expect(_tiled(tester), ['a', 'b']);
|
||||
await _paneMenu(tester, 'b');
|
||||
expect(find.text('Float (Alt+Y)'), findsOneWidget);
|
||||
await tester.tap(find.text(_label));
|
||||
await tester.pumpAndSettle();
|
||||
expect(app.opener.chats, ['b']);
|
||||
// It left the tiling, as Float takes it out, and no floating window.
|
||||
expect(_tiled(tester), ['a']);
|
||||
expect(app.floating, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('a chat whose window did not open stays where it was', (
|
||||
tester,
|
||||
) async {
|
||||
final app = _App();
|
||||
await app.start(tester);
|
||||
app.opener.opens = false;
|
||||
await _paneMenu(tester, 'b');
|
||||
await tester.tap(find.text(_label));
|
||||
await tester.pumpAndSettle();
|
||||
expect(app.opener.chats, ['b']);
|
||||
expect(_tiled(tester), ['a', 'b']);
|
||||
});
|
||||
|
||||
testWidgets('without platform windows the action is not offered', (
|
||||
tester,
|
||||
) async {
|
||||
final app = _App();
|
||||
await app.start(tester, detached: false);
|
||||
await _paneMenu(tester, 'b');
|
||||
expect(find.text('Float (Alt+Y)'), findsOneWidget);
|
||||
expect(find.textContaining('new window'), findsNothing);
|
||||
await tester.tapAt(const Offset(5, 995));
|
||||
await tester.pumpAndSettle();
|
||||
await _rowMenu(tester, 'c');
|
||||
expect(find.textContaining('new window'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('the row menu offers it after Float, for any chat', (
|
||||
tester,
|
||||
) async {
|
||||
final app = _App();
|
||||
await app.start(tester);
|
||||
await _rowMenu(tester, 'c');
|
||||
final float = tester.getTopLeft(find.text('Float (Alt+Y)').last);
|
||||
final open = tester.getTopLeft(find.text(_label).last);
|
||||
expect(open.dy, greaterThan(float.dy));
|
||||
await tester.tap(find.text(_label).last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(app.opener.chats, ['c']);
|
||||
expect(_tiled(tester), ['a', 'b']);
|
||||
});
|
||||
|
||||
testWidgets('a floating chat goes to a new window from its title bar', (
|
||||
tester,
|
||||
) async {
|
||||
final app = _App();
|
||||
await app.start(tester);
|
||||
await _rowMenu(tester, 'c');
|
||||
await tester.tap(find.text('Float (Alt+Y)').last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(app.floating, ['c']);
|
||||
final window = find.ancestor(
|
||||
of: find.text('Chat c'),
|
||||
matching: find.byType(WindowFrame),
|
||||
);
|
||||
await tester.tap(
|
||||
find.descendant(of: window, matching: find.byTooltip(_label)).first,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(app.opener.chats, ['c']);
|
||||
expect(app.floating, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('Alt+Shift+Y sends the active pane; Alt+Y still floats', (
|
||||
tester,
|
||||
) async {
|
||||
final app = _App();
|
||||
await app.start(tester);
|
||||
// The keyboard is in chat b's composer, the active pane.
|
||||
await tester.tap(
|
||||
find
|
||||
.descendant(
|
||||
of: find.byKey(const ValueKey('chat-composer-b')),
|
||||
matching: find.byType(EditableText),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);
|
||||
await tester.pumpAndSettle();
|
||||
expect(app.opener.chats, ['b']);
|
||||
expect(_tiled(tester), ['a']);
|
||||
expect(app.floating, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('a chat brought back from its window joins the tiling', (
|
||||
tester,
|
||||
) async {
|
||||
final app = _App();
|
||||
await app.start(tester);
|
||||
app.windows.bringBack('c');
|
||||
await tester.pumpAndSettle();
|
||||
expect(_tiled(tester), ['a', 'b', 'c']);
|
||||
});
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_composer_bar.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_composer_controller.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_clipboard_paste_native.dart';
|
||||
|
||||
import '../../../core/keyboard/browser_keys.dart';
|
||||
import 'chat_composer_bar_fixtures.dart';
|
||||
@@ -32,6 +33,12 @@ void main() {
|
||||
if (call.method == 'Clipboard.hasStrings') return {'value': true};
|
||||
return null;
|
||||
});
|
||||
// The Linux Runner's clipboard reader: no files, so the text is pasted.
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(
|
||||
chatClipboardFilesChannel,
|
||||
(call) async => {'files': const [], 'errors': const []},
|
||||
);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
@@ -39,6 +46,8 @@ void main() {
|
||||
gateway.close();
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(SystemChannels.platform, null);
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(chatClipboardFilesChannel, null);
|
||||
});
|
||||
|
||||
for (final merged in [false, true]) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import 'package:pipelines_app/features/chat/domain/chat_clipboard_paste_native.d
|
||||
import '../conversation/chat_composer_bar_fixtures.dart';
|
||||
|
||||
final _macOS = TargetPlatformVariant.only(TargetPlatform.macOS);
|
||||
final _linux = TargetPlatformVariant.only(TargetPlatform.linux);
|
||||
|
||||
Finder get _field => find.byKey(const Key('chat-composer-field'));
|
||||
|
||||
@@ -77,10 +78,10 @@ void main() {
|
||||
|
||||
Future<void> done(WidgetTester tester) => tester.pumpWidget(const SizedBox());
|
||||
|
||||
test('only the macOS host reads clipboard files natively', () {
|
||||
test('the macOS and Linux hosts read clipboard files natively', () {
|
||||
expect(chatHostReadsClipboardFiles(TargetPlatform.macOS), isTrue);
|
||||
expect(chatHostReadsClipboardFiles(TargetPlatform.linux), isTrue);
|
||||
for (final platform in [
|
||||
TargetPlatform.linux,
|
||||
TargetPlatform.windows,
|
||||
TargetPlatform.android,
|
||||
TargetPlatform.iOS,
|
||||
@@ -228,4 +229,47 @@ void main() {
|
||||
expect(composer.draft, isEmpty);
|
||||
await done(tester);
|
||||
}, variant: _macOS);
|
||||
|
||||
testWidgets('Ctrl+V attaches a copied screenshot on Linux', (tester) async {
|
||||
pasteboard = {
|
||||
'files': [
|
||||
{
|
||||
'name': '',
|
||||
'mime': 'image/png',
|
||||
'bytes': Uint8List.fromList([3]),
|
||||
},
|
||||
],
|
||||
'errors': const [],
|
||||
};
|
||||
expect(hostChatClipboardPaste.isSupported, isTrue);
|
||||
await mount(tester);
|
||||
await tester.showKeyboard(_field);
|
||||
await tester.pump();
|
||||
await paste(tester, modifier: LogicalKeyboardKey.controlLeft);
|
||||
|
||||
expect(fileReads, 1);
|
||||
expect(find.text('pasted-1.png'), findsOneWidget);
|
||||
expect(textReads, 0);
|
||||
await done(tester);
|
||||
}, variant: _linux);
|
||||
|
||||
testWidgets('Ctrl+V of plain text on Linux pastes it once', (tester) async {
|
||||
await mount(tester);
|
||||
await tester.showKeyboard(_field);
|
||||
await paste(tester, modifier: LogicalKeyboardKey.controlLeft);
|
||||
|
||||
expect(fileReads, 1);
|
||||
expect(composer.draft, 'copied text');
|
||||
await done(tester);
|
||||
}, variant: _linux);
|
||||
|
||||
testWidgets('the Super key is not the Linux paste shortcut', (tester) async {
|
||||
await mount(tester);
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
await tester.pump();
|
||||
await paste(tester);
|
||||
|
||||
expect(fileReads, 0);
|
||||
await done(tester);
|
||||
}, variant: _linux);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:pipelines_app/features/graph/domain/check_stage.dart';
|
||||
import 'package:pipelines_app/features/graph/domain/graph_definition.dart';
|
||||
import 'package:pipelines_app/features/graph/domain/stage_definition.dart';
|
||||
|
||||
Map<String, dynamic> _verify({Map<String, dynamic>? configs}) => {
|
||||
'key': 'verify',
|
||||
'type': 'check',
|
||||
'configs':
|
||||
configs ??
|
||||
{
|
||||
'command_timeout': '15m',
|
||||
'timeout': '1h',
|
||||
'keep_going': 'true',
|
||||
'delivery': 'true',
|
||||
},
|
||||
'edges': {'pass': 'review', 'fail': 'implement', 'error': '#failure'},
|
||||
'blocks': {'commands': 'go vet ./...\n\ngo test ./...\n'},
|
||||
'prompt': '',
|
||||
'output': '',
|
||||
};
|
||||
|
||||
void main() {
|
||||
test('a check stage reads its commands, one per non-blank line', () {
|
||||
expect(isCheckStage(_verify()), isTrue);
|
||||
expect(checkCommands(_verify()), ['go vet ./...', 'go test ./...']);
|
||||
expect(isCheckStage({'type': 'model'}), isFalse);
|
||||
expect(isCheckStage({'key': 'x'}), isFalse);
|
||||
});
|
||||
|
||||
test('the delivery config marks the gate, and only on a check stage', () {
|
||||
expect(isDeliveryGate(_verify()), isTrue);
|
||||
expect(isDeliveryGate(_verify(configs: {'delivery': 'false'})), isFalse);
|
||||
expect(isDeliveryGate(_verify(configs: {})), isFalse);
|
||||
expect(
|
||||
isDeliveryGate({
|
||||
'type': 'model',
|
||||
'configs': {'delivery': 'true'},
|
||||
}),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
test('graph nodes carry the stage type and the gate caption', () {
|
||||
final nodes = graphNodes({
|
||||
'stages': [
|
||||
_verify(),
|
||||
{
|
||||
..._verify(configs: {}),
|
||||
'key': 'lint',
|
||||
},
|
||||
{
|
||||
'key': 'review',
|
||||
'edges': {'success': '#'},
|
||||
},
|
||||
],
|
||||
});
|
||||
final byKey = {for (final node in nodes) node.key: node};
|
||||
expect(byKey['verify']!.kindCaption, 'Delivery gate');
|
||||
expect(byKey['lint']!.kindCaption, 'Check');
|
||||
expect(byKey['review']!.kindCaption, isNull);
|
||||
expect(byKey['#success']!.kindCaption, isNull);
|
||||
});
|
||||
|
||||
test('a check definition lists its commands in place of a prompt', () {
|
||||
final fields = stageDefinitionFields(_verify());
|
||||
final byLabel = {for (final field in fields) field.label: field};
|
||||
expect(byLabel['Type']!.value, 'check (delivery gate)');
|
||||
final commands = byLabel['Commands']!;
|
||||
expect(commands.value, 'go vet ./...\ngo test ./...');
|
||||
expect(commands.monospace, isTrue);
|
||||
expect(byLabel.containsKey('Prompt'), isFalse);
|
||||
expect(byLabel['Command timeout']!.value, '15m');
|
||||
expect(byLabel['Keep going']!.value, 'true');
|
||||
expect(byLabel['Delivery gate']!.value, 'true');
|
||||
expect(byLabel['Outcomes']!.value, contains('pass → review'));
|
||||
expect(byLabel['Outcomes']!.value, contains('fail → implement'));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:pipelines_app/features/graph/domain/graph_definition.dart';
|
||||
import 'package:pipelines_app/features/graph/widgets/graph_stage_node.dart';
|
||||
import 'package:pipelines_app/features/graph/widgets/stage_definition_view.dart';
|
||||
import 'package:pipelines_app/ui/text/monospace.dart';
|
||||
|
||||
Map<String, dynamic> _graph() => {
|
||||
'stages': [
|
||||
{
|
||||
'key': 'verify',
|
||||
'type': 'check',
|
||||
'configs': {'delivery': 'true'},
|
||||
'edges': {'pass': '#', 'fail': 'fix'},
|
||||
'blocks': {'commands': 'go vet ./...\ngo test ./...'},
|
||||
},
|
||||
{
|
||||
'key': 'fix',
|
||||
'type': 'model',
|
||||
'prompt': 'Fix it.',
|
||||
'edges': {'success': 'verify'},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
Widget _host(Widget child) => MaterialApp(
|
||||
home: Scaffold(body: Center(child: child)),
|
||||
);
|
||||
|
||||
void main() {
|
||||
testWidgets('a check node shows its kind under its name', (tester) async {
|
||||
final nodes = {for (final node in graphNodes(_graph())) node.key: node};
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
GraphStageNode(node: nodes['verify']!, onSelected: (_) {}),
|
||||
GraphStageNode(node: nodes['fix']!, onSelected: (_) {}),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.byKey(const ValueKey('graph-node-kind-verify')), findsOne);
|
||||
expect(find.byKey(const ValueKey('graph-node-kind-fix')), findsNothing);
|
||||
expect(find.text('Delivery gate'), findsOne);
|
||||
expect(find.byIcon(Icons.verified_outlined), findsOne);
|
||||
expect(find.bySemanticsLabel('verify\nDelivery gate'), findsOne);
|
||||
expect(find.bySemanticsLabel('fix'), findsOne);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('a check definition lists its commands in monospace', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: StageDefinitionView(
|
||||
graph: _graph(),
|
||||
stageKey: 'verify',
|
||||
pipelineId: 1,
|
||||
pipelineName: 'Demo',
|
||||
version: 3,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final commands = tester.widget<SelectableText>(
|
||||
find.descendant(
|
||||
of: find.byKey(const ValueKey('stage-definition-Commands')),
|
||||
matching: find.byType(SelectableText),
|
||||
),
|
||||
);
|
||||
expect(commands.data, 'go vet ./...\ngo test ./...');
|
||||
expect(commands.style?.fontFamily, appMonospaceFamily);
|
||||
expect(find.text('check (delivery gate)'), findsOne);
|
||||
expect(find.text('Prompt'), findsNothing);
|
||||
});
|
||||
}
|
||||
@@ -29,7 +29,13 @@ void main() {
|
||||
|
||||
await tester.tap(find.byKey(const Key('pipeline-filter')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.ensureVisible(find.text('No schedules'));
|
||||
// The status list (with waiting_quota) pushes scheduling below the
|
||||
// lazily built part of the page: scroll to it.
|
||||
await tester.dragUntilVisible(
|
||||
find.text('No schedules'),
|
||||
find.byType(ListView).last,
|
||||
const Offset(0, -200),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('No schedules'));
|
||||
await tester.pump();
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
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/attention/domain/attention_models.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/cancel_eligibility.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/cancel_wording.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/resume_quota_action.dart';
|
||||
import 'package:pipelines_app/features/runs/domain/run_decisions.dart';
|
||||
import 'package:pipelines_app/features/runs/domain/run_models.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_actions.dart';
|
||||
|
||||
import 'cancel_test_support.dart';
|
||||
|
||||
JsonMap _parked({bool cancelRequested = false}) => {
|
||||
'id': 7,
|
||||
'title': 'Nightly build',
|
||||
'status': 'waiting_quota',
|
||||
'executing': false,
|
||||
'cancel_requested': cancelRequested,
|
||||
'quota_wait': {
|
||||
'resets_at': DateTime(2026, 12, 3, 9).toUtc().toIso8601String(),
|
||||
'resume_at': DateTime(2026, 12, 3, 9, 1).toUtc().toIso8601String(),
|
||||
'sequence': 2,
|
||||
'stage': 'implement',
|
||||
'account': 'work',
|
||||
},
|
||||
};
|
||||
|
||||
Future<List<JsonMap>> _pump(
|
||||
WidgetTester tester,
|
||||
FakeCancelGateway gateway,
|
||||
) async {
|
||||
final changed = <JsonMap>[];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunDetailActions(
|
||||
run: _parked(),
|
||||
gateway: gateway,
|
||||
onRunChanged: changed.add,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return changed;
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('a parked run is cancellable and resumable, never a decision', () {
|
||||
final run = _parked();
|
||||
expect(canCancelRun(run), isTrue);
|
||||
expect(canResumeQuotaRun(run), isTrue);
|
||||
expect(canResumeQuotaRun(_parked(cancelRequested: true)), isFalse);
|
||||
expect(canCancelRun(_parked(cancelRequested: true)), isFalse);
|
||||
expect(canResumeQuotaRun({'id': 7, 'status': 'waiting'}), isFalse);
|
||||
expect(attentionKindForRun(run), isNull);
|
||||
expect(orderAttention([run]), isEmpty);
|
||||
expect(pendingDecision(run), isNull);
|
||||
});
|
||||
|
||||
testWidgets('Resume now sends resume_run and applies the reply', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeCancelGateway(
|
||||
(type, fields) async => {
|
||||
'type': 'run',
|
||||
'run_detail': {'id': 7, 'status': 'running', 'executing': true},
|
||||
},
|
||||
);
|
||||
final changed = await _pump(tester, gateway);
|
||||
expect(find.text('Waiting for usage limit'), findsOneWidget);
|
||||
expect(find.textContaining('account work'), findsOneWidget);
|
||||
expect(find.byKey(cancelActionKey), findsOneWidget);
|
||||
await tester.tap(find.byKey(resumeQuotaActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.calls.single.type, 'resume_run');
|
||||
expect(gateway.calls.single.fields, {'run_id': 7});
|
||||
expect(changed.single['status'], 'running');
|
||||
});
|
||||
|
||||
testWidgets('a refused resume shows the server message', (tester) async {
|
||||
final gateway = FakeCancelGateway(
|
||||
(type, fields) async =>
|
||||
throw Exception('run 7 is not waiting for a usage limit'),
|
||||
);
|
||||
final changed = await _pump(tester, gateway);
|
||||
await tester.tap(find.byKey(resumeQuotaActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(resumeQuotaErrorKey), findsOneWidget);
|
||||
expect(
|
||||
find.textContaining('not waiting for a usage limit'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(changed, isEmpty);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:pipelines_app/features/runs/domain/check_step_output.dart';
|
||||
|
||||
void main() {
|
||||
test('a check output reads each command result', () {
|
||||
final output = checkStepOutput({
|
||||
'markdown': '# outcome\n\nfail\n',
|
||||
'summary': '1 of 2 checks failed: go test ./...',
|
||||
'delivery': true,
|
||||
'checks': [
|
||||
{
|
||||
'command': 'go vet ./...',
|
||||
'status': 'passed',
|
||||
'exit_code': 0,
|
||||
'duration_ms': 2100,
|
||||
'output': '',
|
||||
'truncated': false,
|
||||
},
|
||||
{
|
||||
'command': 'go test ./...',
|
||||
'status': 'failed',
|
||||
'exit_code': 1,
|
||||
'duration_ms': 51000,
|
||||
'output': '--- FAIL',
|
||||
'truncated': true,
|
||||
},
|
||||
{'command': 'make lint', 'status': 'not_run'},
|
||||
'not a map',
|
||||
],
|
||||
})!;
|
||||
expect(output.delivery, isTrue);
|
||||
expect(output.summary, '1 of 2 checks failed: go test ./...');
|
||||
expect(output.markdown, startsWith('# outcome'));
|
||||
expect(output.checks, hasLength(3));
|
||||
final [vet, test, lint] = output.checks;
|
||||
expect(vet.status, CheckCommandStatus.passed);
|
||||
expect(vet.meta, 'exit 0 · 2.1s');
|
||||
expect(test.status, CheckCommandStatus.failed);
|
||||
expect(test.meta, 'exit 1 · 51s');
|
||||
expect(test.truncated, isTrue);
|
||||
expect(lint.status, CheckCommandStatus.notRun);
|
||||
expect(lint.meta, '');
|
||||
expect(checkStatusLabel(lint), 'Not run');
|
||||
});
|
||||
|
||||
test('statuses this client does not know keep their own word', () {
|
||||
final output = checkStepOutput({
|
||||
'checks': [
|
||||
{'command': 'x', 'status': 'skipped_by_policy'},
|
||||
{'command': 'y'},
|
||||
{'command': 'z', 'status': 'timed_out'},
|
||||
],
|
||||
})!;
|
||||
expect(output.checks[0].status, CheckCommandStatus.unknown);
|
||||
expect(checkStatusLabel(output.checks[0]), 'skipped_by_policy');
|
||||
expect(checkStatusLabel(output.checks[1]), 'Unknown status');
|
||||
expect(checkStatusLabel(output.checks[2]), 'Timed out');
|
||||
expect(output.delivery, isFalse);
|
||||
});
|
||||
|
||||
test('outputs without a checks list are not check outputs', () {
|
||||
expect(checkStepOutput(null), isNull);
|
||||
expect(checkStepOutput('text'), isNull);
|
||||
expect(checkStepOutput({'markdown': '# outcome'}), isNull);
|
||||
expect(checkStepOutput({'checks': 'go test'}), isNull);
|
||||
});
|
||||
|
||||
test('durations read compactly', () {
|
||||
expect(formatCheckDuration(850), '850ms');
|
||||
expect(formatCheckDuration(2000), '2s');
|
||||
expect(formatCheckDuration(2100), '2.1s');
|
||||
expect(formatCheckDuration(51000), '51s');
|
||||
expect(formatCheckDuration(185000), '3m 05s');
|
||||
expect(formatCheckDuration(3720000), '1h 02m');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/runs/domain/run_events.dart';
|
||||
|
||||
void main() {
|
||||
const wait = {
|
||||
'resets_at': '2026-12-03T09:00:00Z',
|
||||
'resume_at': '2026-12-03T09:01:00Z',
|
||||
'sequence': 2,
|
||||
'stage': 'implement',
|
||||
'account': 'work',
|
||||
};
|
||||
final running = {
|
||||
'id': 4,
|
||||
'pipeline_id': 1,
|
||||
'name': 'build',
|
||||
'status': 'running',
|
||||
'executing': true,
|
||||
};
|
||||
|
||||
test('a running run parks with its wait and resumes without it', () {
|
||||
final parked = foldRunEvent(
|
||||
[running],
|
||||
{'run_id': 4, 'status': 'waiting_quota', 'quota_wait': wait},
|
||||
).runs.single;
|
||||
expect(parked['status'], 'waiting_quota');
|
||||
expect(parked['executing'], isFalse);
|
||||
expect(parked['quota_wait'], wait);
|
||||
// A frame without a status keeps the wait.
|
||||
final same = foldRunEvent(
|
||||
[parked],
|
||||
{'run_id': 4, 'current_stage': 'implement'},
|
||||
).runs.single;
|
||||
expect(same['quota_wait'], wait);
|
||||
final resumed = foldRunEvent(
|
||||
[parked],
|
||||
{'run_id': 4, 'status': 'running'},
|
||||
).runs.single;
|
||||
expect(resumed['status'], 'running');
|
||||
expect(resumed['executing'], isTrue);
|
||||
expect(resumed.containsKey('quota_wait'), isFalse);
|
||||
});
|
||||
|
||||
test('a deferred run goes back to queued when resumed', () {
|
||||
final deferred = {
|
||||
...running,
|
||||
'status': 'waiting_quota',
|
||||
'executing': false,
|
||||
};
|
||||
final queued = foldRunEvent(
|
||||
[deferred],
|
||||
{'run_id': 4, 'status': 'queued'},
|
||||
).runs.single;
|
||||
expect(queued['status'], 'queued');
|
||||
expect(queued['executing'], isTrue);
|
||||
final parkedAgain = foldRunEvent(
|
||||
[queued],
|
||||
{'run_id': 4, 'status': 'waiting_quota', 'quota_wait': wait},
|
||||
).runs.single;
|
||||
expect(parkedAgain['status'], 'waiting_quota');
|
||||
});
|
||||
|
||||
test('a parked run can be canceled and records the failure class', () {
|
||||
final parked = {...running, 'status': 'waiting_quota', 'quota_wait': wait};
|
||||
final canceled = foldRunEvent(
|
||||
[parked],
|
||||
{'run_id': 4, 'status': 'canceled', 'failure_class': 'canceled'},
|
||||
).runs.single;
|
||||
expect(canceled['status'], 'canceled');
|
||||
expect(canceled['failure_class'], 'canceled');
|
||||
expect(canceled.containsKey('quota_wait'), isFalse);
|
||||
// Terminal stays terminal.
|
||||
final stale = foldRunEvent(
|
||||
[canceled],
|
||||
{'run_id': 4, 'status': 'waiting_quota'},
|
||||
).runs.single;
|
||||
expect(stale['status'], 'canceled');
|
||||
});
|
||||
|
||||
test('the detail folds the same fields and re-reads on parking', () {
|
||||
final detail = foldRunEventDetail(
|
||||
{...running, 'steps': []},
|
||||
{
|
||||
'run_id': 4,
|
||||
'status': 'failed',
|
||||
'failure_class': 'quota',
|
||||
'failure_reason': 'usage limit',
|
||||
},
|
||||
)!;
|
||||
expect(detail['failure_class'], 'quota');
|
||||
expect(
|
||||
runDetailNeedsFullSync({'run_id': 4, 'status': 'waiting_quota'}),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
test('a new row from a parked frame keeps its wait', () {
|
||||
final row = newRunSummaryFromFrame({
|
||||
'run_id': 9,
|
||||
'pipeline_id': 1,
|
||||
'name': 'build',
|
||||
'status': 'waiting_quota',
|
||||
'quota_wait': wait,
|
||||
})!;
|
||||
expect(row['executing'], isFalse);
|
||||
expect(row['quota_wait'], wait);
|
||||
expect(row['failure_class'], '');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/pipelines/pipeline_format.dart'
|
||||
show runStateLabel;
|
||||
import 'package:pipelines_app/features/runs/domain/run_failure_class.dart';
|
||||
import 'package:pipelines_app/features/runs/domain/run_models.dart';
|
||||
import 'package:pipelines_app/features/runs/domain/run_outcome_line.dart';
|
||||
import 'package:pipelines_app/features/runs/domain/run_quota.dart';
|
||||
|
||||
String _local(int hour, int minute) =>
|
||||
DateTime(2026, 12, 3, hour, minute).toUtc().toIso8601String();
|
||||
|
||||
void main() {
|
||||
final now = DateTime(2026, 12, 3, 8);
|
||||
final parked = {
|
||||
'id': 4,
|
||||
'status': 'waiting_quota',
|
||||
'quota_wait': {
|
||||
'resets_at': _local(9, 0),
|
||||
'resume_at': _local(9, 1),
|
||||
'sequence': 3,
|
||||
'stage': 'implement',
|
||||
'account': 'work',
|
||||
},
|
||||
};
|
||||
|
||||
test('quota_wait parses and reads in local time', () {
|
||||
final wait = runQuotaWait(parked)!;
|
||||
expect(wait.sequence, 3);
|
||||
expect(wait.stage, 'implement');
|
||||
expect(wait.account, 'work');
|
||||
expect(quotaResumeText(wait, now: now), 'resumes 09:01');
|
||||
expect(
|
||||
quotaWaitMeta(wait, now: now),
|
||||
'Limit resets 09:00 · run resumes 09:01 · account work · at implement',
|
||||
);
|
||||
expect(runQuotaWait({'status': 'waiting_quota'}), isNull);
|
||||
});
|
||||
|
||||
test('a resume on another day carries its date', () {
|
||||
final later = DateTime(2026, 12, 4, 9, 1);
|
||||
expect(quotaClockText(later, now: now), '4 Dec 09:01');
|
||||
});
|
||||
|
||||
test('waiting_quota is its own state with its own words', () {
|
||||
expect(runStateOf('waiting_quota'), 'waiting_quota');
|
||||
expect(runStates, contains('waiting_quota'));
|
||||
expect(runStateLabel('waiting_quota'), 'Waiting for usage limit');
|
||||
expect(
|
||||
runStatusLabel(parked, now: now),
|
||||
'Waiting for usage limit · resumes 09:01',
|
||||
);
|
||||
expect(
|
||||
runStatusLabel({'status': 'waiting_quota'}),
|
||||
'Waiting for usage limit',
|
||||
);
|
||||
final filtered = filterRuns(
|
||||
[
|
||||
parked,
|
||||
{'id': 5, 'status': 'waiting'},
|
||||
],
|
||||
statuses: {'waiting_quota'},
|
||||
);
|
||||
expect(filtered.map((run) => run['id']), [4]);
|
||||
});
|
||||
|
||||
test('failure classes use the server wording', () {
|
||||
expect(runFailureClassLabel({'failure_class': 'quota'}), 'usage limit');
|
||||
expect(
|
||||
runFailureClassLabel({'failure_class': 'loop_exhausted'}),
|
||||
'loop limit reached',
|
||||
);
|
||||
expect(
|
||||
runFailureClassLabel({'failure_class': 'budget'}),
|
||||
'budget exhausted',
|
||||
);
|
||||
expect(runFailureClassLabel({'failure_class': 'new_kind'}), 'new kind');
|
||||
expect(runFailureClassLabel({}), isNull);
|
||||
expect(runFailureClassLabels.length, 12);
|
||||
});
|
||||
|
||||
test('the outcome line leads with the failure class', () {
|
||||
final line = runOutcomeLine({
|
||||
'status': 'failed',
|
||||
'failure_class': 'quota',
|
||||
'failure_reason': 'Claude usage limit\nreset at 9',
|
||||
})!;
|
||||
expect(line.line, 'Failed · usage limit: Claude usage limit');
|
||||
expect(line.full, 'Failed · usage limit: Claude usage limit\nreset at 9');
|
||||
expect(line.failed, isTrue);
|
||||
expect(
|
||||
runOutcomeLine({'status': 'failed', 'failure_class': 'timeout'})?.line,
|
||||
'Failed · timed out',
|
||||
);
|
||||
// The catch-all class adds nothing to the reason.
|
||||
expect(
|
||||
runOutcomeLine({
|
||||
'status': 'failed',
|
||||
'failure_class': 'other',
|
||||
'failure_reason': 'exit 2',
|
||||
})?.line,
|
||||
'exit 2',
|
||||
);
|
||||
expect(
|
||||
runOutcomeLine({'status': 'failed', 'failure_class': 'other'}),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
|
||||
test('a capped run shows its budget', () {
|
||||
expect(
|
||||
runBudgetText({
|
||||
'budget': {'limit_usd': 5, 'spent_usd': 1.25, 'source': 'run'},
|
||||
}),
|
||||
r'$1.25 of $5.00 budget',
|
||||
);
|
||||
expect(
|
||||
runBudgetText({
|
||||
'budget': {'limit_usd': 2, 'spent_usd': 0, 'source': 'server'},
|
||||
}),
|
||||
r'$0.00 of $2.00 budget (server default)',
|
||||
);
|
||||
expect(
|
||||
runBudgetText({
|
||||
'budget': {'limit_usd': 0},
|
||||
}),
|
||||
isNull,
|
||||
);
|
||||
expect(runBudgetText({}), isNull);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
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/ui/run_check_output_view.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_visit_facts.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_visit_sections.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_visit_session_state.dart';
|
||||
import 'package:pipelines_app/ui/text/monospace.dart';
|
||||
|
||||
import 'run_detail_graph_support.dart';
|
||||
import 'run_detail_visit_support.dart';
|
||||
|
||||
/// verify (a delivery check) -> review, with one failed check visit.
|
||||
JsonMap _checkRun({int repairs = 0}) => <String, dynamic>{
|
||||
'id': 78,
|
||||
'title': 'Check run',
|
||||
'name': 'release',
|
||||
'pipeline_id': 7,
|
||||
'version': 4,
|
||||
'status': 'succeeded',
|
||||
'graph': <String, dynamic>{
|
||||
'stages': <dynamic>[
|
||||
<String, dynamic>{
|
||||
'key': 'verify',
|
||||
'type': 'check',
|
||||
'configs': <String, dynamic>{'delivery': 'true'},
|
||||
'edges': <String, String?>{'pass': '#', 'fail': 'verify'},
|
||||
'blocks': <String, dynamic>{'commands': 'go vet ./...\ngo test ./...'},
|
||||
},
|
||||
],
|
||||
},
|
||||
'steps': <dynamic>[
|
||||
<String, dynamic>{
|
||||
'stage': 'verify',
|
||||
'sequence': 1,
|
||||
'status': 'completed',
|
||||
'outcome': 'fail',
|
||||
'target': 'verify',
|
||||
'started_at': '2026-10-22T00:00:00Z',
|
||||
'finished_at': '2026-10-22T00:01:00Z',
|
||||
if (repairs > 0)
|
||||
'control': <String, dynamic>{'visit': 1, 'outcome_repairs': repairs},
|
||||
'output': <String, dynamic>{
|
||||
'markdown': '# outcome\n\nfail\n\n# handoff\n\nFix the test.',
|
||||
'summary': '1 of 2 checks failed: go test ./...',
|
||||
'delivery': true,
|
||||
'checks': <dynamic>[
|
||||
<String, dynamic>{
|
||||
'command': 'go vet ./...',
|
||||
'status': 'passed',
|
||||
'exit_code': 0,
|
||||
'duration_ms': 2100,
|
||||
'output': 'vet ok',
|
||||
'truncated': false,
|
||||
},
|
||||
<String, dynamic>{
|
||||
'command': 'go test ./...',
|
||||
'status': 'failed',
|
||||
'exit_code': 1,
|
||||
'duration_ms': 51000,
|
||||
'output': '--- FAIL: TestX',
|
||||
'truncated': true,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
void main() {
|
||||
const platform = RunDetailTestPlatform.material;
|
||||
|
||||
testWidgets('a check visit shows one row per command with its output', (
|
||||
tester,
|
||||
) async {
|
||||
await openVisit(tester, platform, run: _checkRun());
|
||||
|
||||
expect(find.byKey(const Key('run-check-output')), findsOneWidget);
|
||||
expect(find.byKey(const Key('run-check-delivery')), findsOneWidget);
|
||||
expect(find.text('1 of 2 checks failed: go test ./...'), findsOneWidget);
|
||||
expect(find.text('go vet ./...'), findsOneWidget);
|
||||
expect(find.text('Passed · exit 0 · 2.1s'), findsOneWidget);
|
||||
expect(find.text('Failed · exit 1 · 51s'), findsOneWidget);
|
||||
// The raw checks list is never shown as a `key=value` field dump.
|
||||
expect(find.text('checks'), findsNothing);
|
||||
|
||||
// Output is collapsed until the row is expanded; then it is selectable
|
||||
// monospace with the truncation note.
|
||||
expect(find.text('--- FAIL: TestX'), findsNothing);
|
||||
final row = find.byKey(const ValueKey('run-check-command-1'));
|
||||
await tester.ensureVisible(row);
|
||||
await tester.tap(find.text('go test ./...'));
|
||||
await tester.pumpAndSettle();
|
||||
final output = tester.widget<SelectableText>(
|
||||
find.widgetWithText(SelectableText, '--- FAIL: TestX'),
|
||||
);
|
||||
expect(output.style?.fontFamily, appMonospaceFamily);
|
||||
expect(find.text(checkOutputTruncated), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('a check visit has no model row and an honest session note', (
|
||||
tester,
|
||||
) async {
|
||||
await openVisit(tester, platform, run: _checkRun());
|
||||
expect(find.text('Provider/model'), findsNothing);
|
||||
expect(find.text('fail'), findsWidgets);
|
||||
await openVisitTab(tester, RunVisitSection.session);
|
||||
expect(find.text(visitSessionCheck), findsOneWidget);
|
||||
expect(find.text(visitSessionNoIdentity), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a repaired outcome is noted on the visit', (tester) async {
|
||||
await openVisit(tester, platform, run: _checkRun(repairs: 1));
|
||||
expect(find.byKey(const Key('run-visit-outcome-repaired')), findsOne);
|
||||
expect(find.text('Outcome repaired by follow-up'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('an unrepaired visit shows no repair note', (tester) async {
|
||||
await openVisit(tester, platform, run: _checkRun());
|
||||
expect(find.byKey(const Key('run-visit-outcome-repaired')), findsNothing);
|
||||
});
|
||||
|
||||
test('outcome repairs read from control, absent meaning none', () {
|
||||
expect(detailVisitOutcomeRepairs({}), 0);
|
||||
expect(detailVisitOutcomeRepairs({'control': 'x'}), 0);
|
||||
expect(
|
||||
detailVisitOutcomeRepairs({
|
||||
'control': {'visit': 2},
|
||||
}),
|
||||
0,
|
||||
);
|
||||
expect(
|
||||
detailVisitOutcomeRepairs({
|
||||
'control': {'outcome_repairs': 2},
|
||||
}),
|
||||
2,
|
||||
);
|
||||
expect(outcomeRepairNote(2), 'Outcome repaired by follow-up (2 times)');
|
||||
});
|
||||
}
|
||||
@@ -120,8 +120,9 @@ void main() {
|
||||
await tester.tap(find.byKey(const ValueKey('runs.filter')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Seven statuses may be combined: those keep their checkboxes.
|
||||
expect(find.byType(CheckboxListTile), findsNWidgets(7));
|
||||
// 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(
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/app_terminals.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_route.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_terminal.dart';
|
||||
import 'package:pipelines_app/application/detached/detached_window_body.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_hub.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_tab_strip.dart';
|
||||
import 'package:pipelines_app/shell/detached/detached_window_scope.dart';
|
||||
|
||||
import '../../application/detached/detached_fixtures.dart';
|
||||
import 'terminal_fixtures.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('the options menu sends the terminal to a new window', (
|
||||
tester,
|
||||
) async {
|
||||
final mac = TerminalGateway()..add('t1', text: 'hello\r\n');
|
||||
addTearDown(mac.close);
|
||||
final hub = TerminalHub(TestMachines([machine('mac', mac)]))..activate();
|
||||
addTearDown(hub.dispose);
|
||||
await tester.runAsync(hub.listed);
|
||||
final layout = TerminalLayout(store: MemoryLayoutStore())..show();
|
||||
final opener = FakeOpener();
|
||||
await tester.pumpWidget(
|
||||
DetachedWindowScope(
|
||||
opener: opener,
|
||||
child: MaterialApp(
|
||||
home: Scaffold(
|
||||
body: TerminalTabStrip(hub: hub, layout: layout),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.byTooltip('Terminal options'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const ValueKey('terminal-new-window')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(opener.terminals, ['mac/t1']);
|
||||
expect(layout.visible, isFalse, reason: 'it leaves the main window');
|
||||
});
|
||||
|
||||
testWidgets('without platform windows the menu has no such choice', (
|
||||
tester,
|
||||
) async {
|
||||
final hub = TerminalHub(TestMachines([]));
|
||||
addTearDown(hub.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: TerminalTabStrip(
|
||||
hub: hub,
|
||||
layout: TerminalLayout(store: MemoryLayoutStore()),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.byTooltip('Terminal options'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('terminal-new-window')), findsNothing);
|
||||
expect(find.text('Floating window'), findsOneWidget);
|
||||
});
|
||||
|
||||
test('a layout that does not persist never saves', () async {
|
||||
final store = MemoryLayoutStore();
|
||||
final layout = TerminalLayout(store: store)..persist = false;
|
||||
layout
|
||||
..setFontSize(18)
|
||||
..show();
|
||||
await layout.save();
|
||||
expect(store.saves, 0);
|
||||
expect(layout.fontSize, 18, reason: 'the window still follows it');
|
||||
});
|
||||
|
||||
testWidgets('a detached terminal opens on its tab, without modes, and '
|
||||
'gives it back', (tester) async {
|
||||
final mac = TerminalGateway()
|
||||
..add('t1', text: 'one\r\n')
|
||||
..add('t2', text: 'two\r\n');
|
||||
addTearDown(mac.close);
|
||||
final connection = ValueNotifier(0);
|
||||
final terminals = AppTerminals(
|
||||
pool: null,
|
||||
connection: connection,
|
||||
connected: () => true,
|
||||
gateway: mac,
|
||||
machineId: 'mac',
|
||||
machineName: () => 'Mac',
|
||||
layout: TerminalLayout(store: MemoryLayoutStore()),
|
||||
);
|
||||
addTearDown(terminals.dispose);
|
||||
final back = <(DetachedKind, String)>[];
|
||||
final titles = <String>[];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: DetachedTerminal(
|
||||
terminals: terminals,
|
||||
tabKey: 'mac/t2',
|
||||
window: DetachedWindowControls(
|
||||
ready: ValueNotifier(true),
|
||||
sync: ValueNotifier(0),
|
||||
setTitle: titles.add,
|
||||
close: () {},
|
||||
bringBackItem: (kind, id, _, _) => back.add((kind, id)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.runAsync(terminals.hub.listed);
|
||||
await tester.pump();
|
||||
expect(terminals.hub.selected?.key, 'mac/t2');
|
||||
expect(titles.last, startsWith('Terminal'));
|
||||
// There is no panel or floating mode to choose in a window of its own.
|
||||
expect(find.byTooltip('Terminal options'), findsNothing);
|
||||
await tester.tap(find.byTooltip('Bring back to main window'));
|
||||
expect(back, [(DetachedKind.terminal, 'mac/t2')]);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_float_shortcut.dart';
|
||||
import 'package:pipelines_app/features/settings/keyboard_shortcuts_registry.dart';
|
||||
import 'package:pipelines_app/shell/detached/detached_window_scope.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Alt+Shift+Y is the new-window chord, never Float', (
|
||||
tester,
|
||||
) async {
|
||||
final seen = <(bool detach, bool float)>[];
|
||||
bool handler(KeyEvent event) {
|
||||
if (event is KeyDownEvent &&
|
||||
event.logicalKey == LogicalKeyboardKey.keyY) {
|
||||
final keyboard = HardwareKeyboard.instance;
|
||||
seen.add((
|
||||
detachedWindowShortcut(event, keyboard),
|
||||
chatFloatShortcut(event, keyboard),
|
||||
));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
HardwareKeyboard.instance.addHandler(handler);
|
||||
addTearDown(() => HardwareKeyboard.instance.removeHandler(handler));
|
||||
|
||||
Future<void> chord(List<LogicalKeyboardKey> modifiers) async {
|
||||
for (final key in modifiers) {
|
||||
await tester.sendKeyDownEvent(key);
|
||||
}
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
|
||||
for (final key in modifiers.reversed) {
|
||||
await tester.sendKeyUpEvent(key);
|
||||
}
|
||||
}
|
||||
|
||||
await chord([LogicalKeyboardKey.altLeft, LogicalKeyboardKey.shiftLeft]);
|
||||
await chord([LogicalKeyboardKey.altLeft]);
|
||||
await chord([LogicalKeyboardKey.shiftLeft]);
|
||||
await chord([
|
||||
LogicalKeyboardKey.controlLeft,
|
||||
LogicalKeyboardKey.altLeft,
|
||||
LogicalKeyboardKey.shiftLeft,
|
||||
]);
|
||||
expect(seen, [
|
||||
(true, false),
|
||||
(false, true),
|
||||
(false, false),
|
||||
(false, false),
|
||||
]);
|
||||
});
|
||||
|
||||
test('the shortcut help lists it where windows exist', () {
|
||||
String? keysOn(TargetPlatform platform, {bool web = false}) =>
|
||||
KeyboardShortcutRegistry(platform: platform, web: web).entries
|
||||
.where((e) => e.action == 'Open the chat in a new window')
|
||||
.map((e) => e.keys)
|
||||
.firstOrNull;
|
||||
expect(keysOn(TargetPlatform.linux), 'Alt+Shift+Y');
|
||||
expect(keysOn(TargetPlatform.macOS), 'Option+Shift+Y');
|
||||
expect(keysOn(TargetPlatform.windows, web: true), 'Alt+Shift+Y');
|
||||
expect(keysOn(TargetPlatform.android), isNull);
|
||||
expect(keysOn(TargetPlatform.iOS), isNull);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user