Merge branch 'main' into worktree-agent-a35ac03e196ffae50
# Conflicts: # app/lib/features/runs/ui/run_detail_content.dart # app/lib/features/runs/ui/run_list_row.dart # app/tool/search_selection_probe_entry.dart
This commit is contained in:
@@ -244,7 +244,7 @@ void main() {
|
||||
expect(find.byType(AlertDialog), findsOneWidget);
|
||||
expect(find.text('Download'), findsOneWidget);
|
||||
expect(find.text('Share'), findsOneWidget);
|
||||
expect(find.text('Open'), findsOneWidget);
|
||||
expect(find.text('Open in browser'), findsOneWidget);
|
||||
expect(find.text('Copy link'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Download'));
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_html_links.dart';
|
||||
|
||||
void main() {
|
||||
const inDocument = ArtifactHtmlLinkAction.inDocument;
|
||||
const external = ArtifactHtmlLinkAction.external;
|
||||
const blocked = ArtifactHtmlLinkAction.blocked;
|
||||
|
||||
final cases = <String, ArtifactHtmlLinkAction>{
|
||||
'#section-2': inDocument,
|
||||
' #top ': inDocument,
|
||||
'about:blank': inDocument,
|
||||
'about:blank#section-2': inDocument,
|
||||
'about:srcdoc#top': inDocument,
|
||||
'https://example.com/report': external,
|
||||
'HTTP://Example.com': external,
|
||||
'http://127.0.0.1:8080/x': external,
|
||||
'mailto:ops@example.com': external,
|
||||
'javascript:alert(1)': blocked,
|
||||
' JavaScript:alert(1)': blocked,
|
||||
'file:///etc/passwd': blocked,
|
||||
'data:text/html,<b>x</b>': blocked,
|
||||
'about:config': blocked,
|
||||
'intent://scan#Intent;end': blocked,
|
||||
'tel:+15551234': blocked,
|
||||
'report.html': blocked,
|
||||
'../7/2/other.html': blocked,
|
||||
'/api/runs': blocked,
|
||||
'//example.com/x': blocked,
|
||||
'http:no-host': blocked,
|
||||
'': blocked,
|
||||
};
|
||||
|
||||
for (final entry in cases.entries) {
|
||||
test(
|
||||
'${entry.key.isEmpty ? '(empty)' : entry.key} -> ${entry.value.name}',
|
||||
() {
|
||||
expect(artifactHtmlLinkAction(entry.key), entry.value);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_record.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_fullscreen.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_body.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_fetch.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_page.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_visit_list.dart';
|
||||
|
||||
import 'artifact_visit_list_fixture.dart';
|
||||
|
||||
const _endpoint = 'ws://127.0.0.1:8081/connect';
|
||||
const _shellBar = Key('shell-tab-bar');
|
||||
|
||||
final ArtifactRecord _report = recordedArtifact(
|
||||
'report.html',
|
||||
url: '/artifacts/1/1/report.html',
|
||||
contentType: 'text/html',
|
||||
);
|
||||
final ArtifactRecord _log = recordedArtifact(
|
||||
'build.log',
|
||||
url: '/artifacts/1/1/build.log',
|
||||
contentType: 'text/plain',
|
||||
);
|
||||
final ArtifactGroup _group = visitGroup(artifacts: [_report, _log]);
|
||||
|
||||
/// Each rendered HTML document, with whether it rendered in full screen.
|
||||
typedef _Rendered = List<(String, bool)>;
|
||||
|
||||
Future<({_Rendered rendered, List<Uri> opened})> _pump(
|
||||
WidgetTester tester, {
|
||||
bool cupertino = false,
|
||||
}) async {
|
||||
final rendered = <(String, bool)>[];
|
||||
final opened = <Uri>[];
|
||||
final page = ArtifactViewerPage(
|
||||
groups: [_group],
|
||||
selectedIdentity: artifactVisitIdentity(_group, _report),
|
||||
configuredEndpoint: _endpoint,
|
||||
fetch: (uri) async => ArtifactFetchResult(
|
||||
status: 200,
|
||||
bytes: utf8.encode(uri.path.endsWith('.html') ? '<h1>Hi</h1>' : 'ok'),
|
||||
),
|
||||
openExternal: (uri) async {
|
||||
opened.add(uri);
|
||||
return true;
|
||||
},
|
||||
htmlBuilder: (context, html) {
|
||||
rendered.add((html, ArtifactFullscreenScope.maybeOf(context) != null));
|
||||
return Text('html:$html');
|
||||
},
|
||||
);
|
||||
// A stand-in for the shell: a nested navigator holding the viewer above a
|
||||
// tab bar the full-screen view must cover.
|
||||
final shell = Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Navigator(
|
||||
onGenerateRoute: (_) => cupertino
|
||||
? CupertinoPageRoute<void>(builder: (_) => page)
|
||||
: MaterialPageRoute<void>(builder: (_) => page),
|
||||
),
|
||||
),
|
||||
const SizedBox(key: _shellBar, height: 56, child: Text('Tabs')),
|
||||
],
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino ? CupertinoApp(home: shell) : MaterialApp(home: shell),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return (rendered: rendered, opened: opened);
|
||||
}
|
||||
|
||||
Future<void> _enter(WidgetTester tester) async {
|
||||
await tester.tap(find.byKey(artifactFullscreenKey));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
/// A bar control by its accessible name: the Material button's tooltip, the
|
||||
/// Cupertino button's semantics label.
|
||||
Finder _named(bool cupertino, String name) =>
|
||||
cupertino ? find.bySemanticsLabel(name) : find.byTooltip(name);
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('$host: the bottom actions offer Full screen', (tester) async {
|
||||
final result = await _pump(tester, cupertino: cupertino);
|
||||
final bar = find.byKey(const Key('artifact-viewer-actions'));
|
||||
expect(
|
||||
find.descendant(of: bar, matching: find.byKey(artifactFullscreenKey)),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(_named(cupertino, 'Full screen'), findsOneWidget);
|
||||
expect(result.rendered.single, ('<h1>Hi</h1>', false));
|
||||
});
|
||||
|
||||
testWidgets('$host: full screen covers the shell, keeps the actions and '
|
||||
'renders the fetched document in the app', (tester) async {
|
||||
final result = await _pump(tester, cupertino: cupertino);
|
||||
await _enter(tester);
|
||||
|
||||
expect(find.byKey(_shellBar), findsNothing);
|
||||
// The same document, fetched once with the app's session, now in the
|
||||
// full-screen scope; nothing was handed to the system browser.
|
||||
expect(result.rendered.last, ('<h1>Hi</h1>', true));
|
||||
expect(result.opened, isEmpty);
|
||||
final bar = find.byKey(const Key('artifact-viewer-actions'));
|
||||
expect(bar, findsOneWidget);
|
||||
for (final key in const [
|
||||
Key('artifact-open'),
|
||||
Key('artifact-copy-link'),
|
||||
artifactPreviousKey,
|
||||
artifactNextKey,
|
||||
]) {
|
||||
expect(find.descendant(of: bar, matching: find.byKey(key)), findsOne);
|
||||
}
|
||||
expect(_named(cupertino, 'Exit full screen'), findsOneWidget);
|
||||
expect(_named(cupertino, 'Open in browser'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('$host: Exit full screen returns to the viewer', (
|
||||
tester,
|
||||
) async {
|
||||
await _pump(tester, cupertino: cupertino);
|
||||
await _enter(tester);
|
||||
await tester.tap(find.byKey(artifactFullscreenKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(_shellBar), findsOneWidget);
|
||||
expect(_named(cupertino, 'Full screen'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('Escape and the system back leave full screen', (tester) async {
|
||||
await _pump(tester);
|
||||
await _enter(tester);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(_shellBar), findsOneWidget);
|
||||
expect(find.text('html:<h1>Hi</h1>'), findsOneWidget);
|
||||
|
||||
await _enter(tester);
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(_shellBar), findsOneWidget);
|
||||
// Back left full screen only, not the viewer as well.
|
||||
expect(find.text('html:<h1>Hi</h1>'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('paging in full screen follows the viewer, any kind', (
|
||||
tester,
|
||||
) async {
|
||||
await _pump(tester);
|
||||
await _enter(tester);
|
||||
await tester.tap(find.byKey(artifactNextKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('build.log'), findsOneWidget);
|
||||
expect(find.byKey(const Key('artifact-text-preview')), findsOneWidget);
|
||||
expect(find.byKey(_shellBar), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(artifactFullscreenKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('build.log'), findsOneWidget);
|
||||
expect(find.byKey(_shellBar), findsOneWidget);
|
||||
});
|
||||
|
||||
test('zoom steps walk the list and hold at both ends', () {
|
||||
expect(artifactHtmlZoomStep(1, 1), 1.1);
|
||||
expect(artifactHtmlZoomStep(1, -1), 0.9);
|
||||
expect(artifactHtmlZoomStep(4, 1), 4);
|
||||
expect(artifactHtmlZoomStep(0.5, -1), 0.5);
|
||||
expect(artifactHtmlZoomStep(1.3, -1), 1.25);
|
||||
});
|
||||
}
|
||||
@@ -188,7 +188,7 @@ void main() {
|
||||
expect(find.byType(ArtifactViewerPage), findsNothing);
|
||||
expect(_dialog(platform, 'session.html'), findsOneWidget);
|
||||
expect(_dialog(platform, 'text/plain · 512\u00a0B'), findsOneWidget);
|
||||
await tester.tap(_dialog(platform, 'Open'));
|
||||
await tester.tap(_dialog(platform, 'Open in browser'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(ArtifactViewerPage), findsNothing);
|
||||
expect(opened, [
|
||||
|
||||
@@ -214,7 +214,7 @@ void main() {
|
||||
);
|
||||
await tester.tap(find.text('result.zip'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(_inDialog(_Platform.material, 'Open'));
|
||||
await tester.tap(_inDialog(_Platform.material, 'Open in browser'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(opened, [
|
||||
@@ -243,7 +243,7 @@ void main() {
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(_inDialog(_Platform.material, 'Open'), findsNothing);
|
||||
expect(_inDialog(_Platform.material, 'Open in browser'), findsNothing);
|
||||
expect(_inDialog(_Platform.material, 'Copy link'), findsNothing);
|
||||
});
|
||||
|
||||
@@ -270,7 +270,7 @@ void main() {
|
||||
_inDialog(_Platform.material, 'No artifact URL recorded.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(_inDialog(_Platform.material, 'Open'), findsNothing);
|
||||
expect(_inDialog(_Platform.material, 'Open in browser'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Copy link copies the resolved url, separate from Open', (
|
||||
@@ -504,7 +504,7 @@ void main() {
|
||||
}
|
||||
|
||||
expect(orderOf('Close'), lessThan(orderOf('Copy link')));
|
||||
expect(orderOf('Copy link'), lessThan(orderOf('Open')));
|
||||
expect(orderOf('Copy link'), lessThan(orderOf('Open in browser')));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/changes/changes.dart';
|
||||
|
||||
import 'widget_hosts.dart';
|
||||
|
||||
const _legacy =
|
||||
"The server truncated this file's patch at its capture limit; no diff "
|
||||
'text was recorded.';
|
||||
|
||||
const _expected = {
|
||||
'file_size': 'This file is over 1 MiB, so no diff text was recorded.',
|
||||
'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.',
|
||||
'evidence_size':
|
||||
"This visit's recorded changes reached their size limit, so this patch "
|
||||
'was dropped.',
|
||||
'git_status':
|
||||
"This change was seen only in Git status, so the file's contents weren't "
|
||||
'compared.',
|
||||
'baseline':
|
||||
"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.',
|
||||
};
|
||||
|
||||
FileChange _noPatch(Object? reason, {bool binary = false}) =>
|
||||
FileChange.fromJson({
|
||||
'path': 'big.txt',
|
||||
'kind': 'modified',
|
||||
'truncated': true,
|
||||
'no_patch': true,
|
||||
'binary': binary,
|
||||
'no_patch_reason': ?reason,
|
||||
});
|
||||
|
||||
void main() {
|
||||
test('each recorded no-patch reason has its own message', () {
|
||||
for (final entry in _expected.entries) {
|
||||
final file = _noPatch(entry.key, binary: entry.key == 'binary');
|
||||
expect(file.noPatchReason, entry.key);
|
||||
expect(patchUnavailableReason(file), entry.value, reason: entry.key);
|
||||
}
|
||||
});
|
||||
|
||||
test('no reason, a blank one or an unknown one keeps the old wording', () {
|
||||
expect(patchUnavailableReason(_noPatch(null)), _legacy);
|
||||
expect(patchUnavailableReason(_noPatch('')), _legacy);
|
||||
expect(patchUnavailableReason(_noPatch('future_reason')), _legacy);
|
||||
expect(patchUnavailableReason(_noPatch(42)), _legacy);
|
||||
});
|
||||
|
||||
test('the reason survives aggregation across stages', () {
|
||||
final file = _noPatch('budget').withSteps(const ['build']);
|
||||
expect(file.noPatchReason, 'budget');
|
||||
});
|
||||
|
||||
testWidgets('the viewer shows the reason, binary included', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
materialHost(
|
||||
Column(
|
||||
children: [
|
||||
Expanded(child: FileDiffViewer(file: _noPatch('lines'))),
|
||||
Expanded(
|
||||
child: FileDiffViewer(file: _noPatch('binary', binary: true)),
|
||||
),
|
||||
Expanded(
|
||||
child: FileDiffViewer(
|
||||
file: FileChange(
|
||||
path: 'logo.bin',
|
||||
kind: ChangeKind.modified,
|
||||
binary: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.text(_expected['lines']!), findsOneWidget);
|
||||
expect(find.text(_expected['binary']!), findsOneWidget);
|
||||
expect(find.text(binaryDiffMessage), findsOneWidget);
|
||||
expect(find.text(_legacy), findsNothing);
|
||||
});
|
||||
}
|
||||
@@ -488,7 +488,9 @@ void main() {
|
||||
});
|
||||
held.complete(const {});
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(chatQuestionAnswered), findsOneWidget);
|
||||
// The answered question leaves the card list (chat_question_group_test).
|
||||
expect(find.text(chatQuestionWaiting), findsNothing);
|
||||
expect(find.text('Colour · Red · +1 more'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a refused question keeps the card open with the server reason', (
|
||||
|
||||
@@ -0,0 +1,301 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
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/chat/conversation/chat_question_card_model.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_question_group.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
|
||||
import 'chat_thread_fixtures.dart';
|
||||
|
||||
JsonMap _turn(String id) => {
|
||||
'kind': 'assistant',
|
||||
'key': id,
|
||||
'messageIds': [id],
|
||||
'parts': const [],
|
||||
};
|
||||
|
||||
JsonMap _card(
|
||||
String id, {
|
||||
String? raisedIn,
|
||||
bool resolved = false,
|
||||
bool cancelled = false,
|
||||
String? error,
|
||||
}) => {
|
||||
'kind': 'question',
|
||||
'key': 'chat-question-$id',
|
||||
'form': {
|
||||
'id': id,
|
||||
'resolved': resolved,
|
||||
'cancelled': cancelled,
|
||||
chatQuestionRaisedIn: ?raisedIn,
|
||||
},
|
||||
'error': error,
|
||||
};
|
||||
|
||||
JsonMap _form({String id = 'form-1'}) => {
|
||||
'id': id,
|
||||
'session_id': 's',
|
||||
'kind': 'question',
|
||||
'title': 'Database',
|
||||
'fields': [
|
||||
{
|
||||
'key': 'q0',
|
||||
'title': 'Which database?',
|
||||
'type': 'string',
|
||||
'required': true,
|
||||
'options': [
|
||||
{'value': 'pg', 'label': 'Postgres'},
|
||||
{'value': 'lite', 'label': 'SQLite'},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const _chip = 'Which database? · Postgres';
|
||||
|
||||
/// A chat whose agent turn `a1` is the one the question arrives during.
|
||||
Future<FakeChatGateway> _open(
|
||||
WidgetTester tester,
|
||||
Size size, {
|
||||
bool cupertino = false,
|
||||
}) async {
|
||||
await tester.binding.setSurfaceSize(size);
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
final gateway = FakeChatGateway()
|
||||
..history = (_) async => chatPage([
|
||||
chatMessage(
|
||||
'u1',
|
||||
'user',
|
||||
parts: [
|
||||
{'type': 'text', 'text': 'Ship the release.'},
|
||||
],
|
||||
),
|
||||
chatMessage(
|
||||
'a1',
|
||||
'assistant',
|
||||
parts: [
|
||||
{'type': 'text', 'text': 'Which database first?'},
|
||||
],
|
||||
),
|
||||
]);
|
||||
addTearDown(gateway.close);
|
||||
final view = ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {});
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: view))
|
||||
: MaterialApp(home: Scaffold(body: view)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
gateway.emitEvent({'session_id': 's', 'kind': 'form', 'form': _form()});
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(chatQuestionWaiting), findsOneWidget);
|
||||
return gateway;
|
||||
}
|
||||
|
||||
Future<void> _answerPostgres(WidgetTester tester) async {
|
||||
await tester.tap(find.text('Postgres'));
|
||||
await tester.pump();
|
||||
await tester.tap(find.text(chatQuestionSubmit));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void _expectCollapsed() {
|
||||
expect(find.text(chatQuestionWaiting), findsNothing);
|
||||
expect(find.text(chatQuestionSubmit), findsNothing);
|
||||
expect(find.text(chatQuestionAnswered), findsNothing);
|
||||
expect(find.text(_chip), findsOneWidget);
|
||||
// The chip sits in its turn's footer, under the turn that asked.
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('chat-message-footer')),
|
||||
matching: find.text(_chip),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('settled questions join the turn they were raised during', () {
|
||||
final rows = groupSettledQuestions([
|
||||
_turn('m1'),
|
||||
_turn('m2'),
|
||||
_card('a', raisedIn: 'm1', resolved: true),
|
||||
_card('b', raisedIn: 'm2', cancelled: true),
|
||||
]);
|
||||
expect(rows.map((r) => r['kind']), ['assistant', 'assistant']);
|
||||
expect(chatRowQuestions(rows[0]).map((f) => f['id']), ['a']);
|
||||
expect(chatRowQuestions(rows[1]).map((f) => f['id']), ['b']);
|
||||
});
|
||||
|
||||
test('questions naming no turn share one row; open ones stay cards', () {
|
||||
final rows = groupSettledQuestions([
|
||||
_turn('m1'),
|
||||
_card('loose-1', resolved: true),
|
||||
_card('pending', raisedIn: 'm1'),
|
||||
_card('refused', raisedIn: 'm1', error: 'no longer awaiting'),
|
||||
_card('loose-2', raisedIn: 'paged-out', resolved: true),
|
||||
]);
|
||||
expect(rows.map((r) => r['kind']), [
|
||||
'assistant',
|
||||
'questions',
|
||||
'question',
|
||||
'question',
|
||||
]);
|
||||
expect(rows[0].containsKey('questions'), isFalse);
|
||||
expect(chatRowQuestions(rows[1]).map((f) => f['id']), [
|
||||
'loose-1',
|
||||
'loose-2',
|
||||
]);
|
||||
});
|
||||
|
||||
test('the summary names the question and its outcome', () {
|
||||
final form = _form();
|
||||
expect(
|
||||
chatQuestionSummary({
|
||||
...form,
|
||||
'resolved': true,
|
||||
'answers': {'q0': 'pg'},
|
||||
}),
|
||||
_chip,
|
||||
);
|
||||
expect(
|
||||
chatQuestionSummary({
|
||||
...form,
|
||||
'resolved': true,
|
||||
'answers': {'q0': 'pg', 'extra': 'x'},
|
||||
}),
|
||||
'$_chip · +1 more',
|
||||
);
|
||||
expect(
|
||||
chatQuestionSummary({...form, 'cancelled': true}),
|
||||
'Which database? · Expired',
|
||||
);
|
||||
expect(
|
||||
chatQuestionSummary({...form, 'resolved': true}),
|
||||
'Which database? · Closed',
|
||||
);
|
||||
});
|
||||
|
||||
for (final (name, size) in [
|
||||
('narrow', const Size(390, 844)),
|
||||
('wide', const Size(1280, 900)),
|
||||
]) {
|
||||
testWidgets('$name: an acknowledged answer collapses into its turn at once '
|
||||
'(Claude Code: the ack is the only signal)', (tester) async {
|
||||
final gateway = await _open(tester, size);
|
||||
final held = Completer<JsonMap>();
|
||||
gateway.answer = (_) => held.future;
|
||||
await tester.tap(find.text('Postgres'));
|
||||
await tester.pump();
|
||||
await tester.tap(find.text(chatQuestionSubmit));
|
||||
await tester.pump();
|
||||
// Still the card while the reply is in flight.
|
||||
expect(find.text(chatQuestionWaiting), findsOneWidget);
|
||||
held.complete(const {'type': 'chat_answer'});
|
||||
await tester.pumpAndSettle();
|
||||
_expectCollapsed();
|
||||
|
||||
// A late replay of the pending frame cannot reopen it.
|
||||
gateway.emitEvent({'session_id': 's', 'kind': 'form', 'form': _form()});
|
||||
await tester.pumpAndSettle();
|
||||
_expectCollapsed();
|
||||
|
||||
await tester.tap(find.text(_chip));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-question-sheet')), findsOneWidget);
|
||||
expect(find.text('Which database?'), findsOneWidget);
|
||||
expect(find.text('Postgres'), findsOneWidget);
|
||||
expect(find.text(chatQuestionAnswered), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('$name: a refused answer keeps the full card with the reason', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = await _open(tester, size);
|
||||
gateway.answer = (_) async =>
|
||||
throw StateError('the question is no longer awaiting an answer');
|
||||
await _answerPostgres(tester);
|
||||
expect(find.textContaining('no longer awaiting'), findsOneWidget);
|
||||
expect(find.text(chatQuestionWaiting), findsOneWidget);
|
||||
expect(find.text(chatQuestionSubmit), findsOneWidget);
|
||||
expect(find.text(_chip), findsNothing);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('OpenCode/Codex: the server resolution collapses a question '
|
||||
'answered elsewhere', (tester) async {
|
||||
final gateway = await _open(tester, const Size(390, 844));
|
||||
gateway.emitEvent({
|
||||
'session_id': 's',
|
||||
'kind': 'form',
|
||||
'form': {'id': 'form-1', 'session_id': 's', 'resolved': true},
|
||||
});
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(chatQuestionWaiting), findsNothing);
|
||||
expect(find.text('Which database? · Closed'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a cancelled question collapses as expired', (tester) async {
|
||||
final gateway = await _open(tester, const Size(390, 844));
|
||||
gateway.emitEvent({
|
||||
'session_id': 's',
|
||||
'kind': 'form',
|
||||
'form': {'id': 'form-1', 'session_id': 's', 'cancelled': true},
|
||||
});
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(chatQuestionWaiting), findsNothing);
|
||||
expect(find.text('Which database? · Expired'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('OpenCode: ack then form.replied leaves one collapsed row', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = await _open(tester, const Size(390, 844));
|
||||
gateway.answer = (_) async {
|
||||
gateway.emitEvent({
|
||||
'session_id': 's',
|
||||
'kind': 'form',
|
||||
'form': {'id': 'form-1', 'session_id': 's', 'resolved': true},
|
||||
});
|
||||
return const {'type': 'chat_answer'};
|
||||
};
|
||||
await _answerPostgres(tester);
|
||||
_expectCollapsed();
|
||||
});
|
||||
|
||||
testWidgets('Cupertino: the answered question collapses to the native chip', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = await _open(tester, const Size(390, 844), cupertino: true);
|
||||
gateway.answer = (_) async => const {'type': 'chat_answer'};
|
||||
await _answerPostgres(tester);
|
||||
_expectCollapsed();
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('after a reload the answered question stays gone', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = await _open(tester, const Size(390, 844));
|
||||
gateway.answer = (_) async => const {'type': 'chat_answer'};
|
||||
await _answerPostgres(tester);
|
||||
_expectCollapsed();
|
||||
// A fresh view over the same server: the subscribe replays only pending
|
||||
// forms, and this one is no longer pending.
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Which database first?'), findsOneWidget);
|
||||
expect(find.text(chatQuestionWaiting), findsNothing);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
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/chat/data/chat_repository.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_list_activity.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_controller.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart';
|
||||
|
||||
import 'chat_test_harness.dart';
|
||||
import 'fake_chat_gateway.dart';
|
||||
|
||||
/// The list shows every chat's live activity from the server: a spinner while
|
||||
/// a turn runs, a quieter badge while only background tasks run, nothing when
|
||||
/// idle. `chat_activity` pushes reach chats this device never opened, and an
|
||||
/// older server (no `activity`) leaves the list as before.
|
||||
JsonMap _row(String id, {JsonMap? activity}) => {
|
||||
'id': id,
|
||||
'title': 'Chat $id',
|
||||
'directory': '/w',
|
||||
'updated_at': 1000,
|
||||
'activity': ?activity,
|
||||
};
|
||||
|
||||
JsonMap _activity({bool turn = false, int tasks = 0, int seq = 1}) => {
|
||||
if (turn) 'turn_running': true,
|
||||
if (tasks > 0) 'background_tasks': tasks,
|
||||
'seq': seq,
|
||||
};
|
||||
|
||||
JsonMap _push(
|
||||
String id, {
|
||||
bool turn = false,
|
||||
int tasks = 0,
|
||||
required int seq,
|
||||
}) => {
|
||||
'type': 'chat_activity',
|
||||
'chat_activity': {
|
||||
'session_id': id,
|
||||
..._activity(turn: turn, tasks: tasks, seq: seq),
|
||||
},
|
||||
};
|
||||
|
||||
/// The row merges its semantics, so the badge's label is part of the row's.
|
||||
Finder _label(int tasks) => find.bySemanticsLabel(
|
||||
RegExp(RegExp.escape('Background tasks running ($tasks)')),
|
||||
);
|
||||
|
||||
Finder _badge(String id) => find.descendant(
|
||||
of: find.byKey(Key('chat-row-$id')),
|
||||
matching: find.byKey(const Key('chat-row-background')),
|
||||
);
|
||||
|
||||
Finder _spinner(String id) => find.descendant(
|
||||
of: find.byKey(Key('chat-row-$id')),
|
||||
matching: find.byKey(const Key('chat-row-working')),
|
||||
);
|
||||
|
||||
Future<void> _pump(
|
||||
WidgetTester tester,
|
||||
FakeChatGateway fake, {
|
||||
bool cupertino = false,
|
||||
}) async {
|
||||
final screen = ChatSessionsScreen(
|
||||
gateway: fake,
|
||||
onOpen: (_) {},
|
||||
localStore: MemoryChatSessionLocalStore(),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(home: screen)
|
||||
: MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: screen,
|
||||
),
|
||||
);
|
||||
// A spinner never settles, so pump a few frames instead.
|
||||
for (var i = 0; i < 5; i++) {
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _frames(WidgetTester tester) async {
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'listed activity draws a spinner, a background badge or nothing',
|
||||
(tester) async {
|
||||
final fake = FakeChatGateway()
|
||||
..sessionsReply = {
|
||||
'chat_sessions': [
|
||||
_row('run', activity: _activity(turn: true, tasks: 1)),
|
||||
_row('bg', activity: _activity(tasks: 2)),
|
||||
_row('idle', activity: _activity()),
|
||||
],
|
||||
};
|
||||
await _pump(tester, fake);
|
||||
|
||||
expect(_spinner('run'), findsOneWidget);
|
||||
expect(_badge('run'), findsNothing, reason: 'the turn spinner wins');
|
||||
expect(_spinner('bg'), findsNothing);
|
||||
expect(_badge('bg'), findsOneWidget);
|
||||
expect(_spinner('idle'), findsNothing);
|
||||
expect(_badge('idle'), findsNothing);
|
||||
expect(_label(2), findsOneWidget);
|
||||
final tooltip = tester.widget<Tooltip>(_badge('bg'));
|
||||
expect(tooltip.message, 'Background tasks running (2)');
|
||||
expect(tooltip.triggerMode, TooltipTriggerMode.manual);
|
||||
expect(
|
||||
find.descendant(of: _badge('bg'), matching: find.byIcon(Icons.pending)),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: _badge('bg'),
|
||||
matching: find.byType(CircularProgressIndicator),
|
||||
),
|
||||
findsNothing,
|
||||
reason: 'the background badge is not a second spinner',
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('pushes move a chat this device never opened', (tester) async {
|
||||
final fake = FakeChatGateway()
|
||||
..sessionsReply = {
|
||||
'chat_sessions': [_row('s1', activity: _activity(seq: 10))],
|
||||
};
|
||||
await _pump(tester, fake);
|
||||
expect(_spinner('s1'), findsNothing);
|
||||
|
||||
fake.pushed.add(_push('s1', turn: true, seq: 11));
|
||||
await _frames(tester);
|
||||
expect(_spinner('s1'), findsOneWidget);
|
||||
|
||||
fake.pushed.add(_push('s1', tasks: 3, seq: 13));
|
||||
await _frames(tester);
|
||||
expect(_spinner('s1'), findsNothing);
|
||||
expect(_label(3), findsOneWidget);
|
||||
|
||||
// A push older than the snapshot already applied is ignored.
|
||||
fake.pushed.add(_push('s1', turn: true, seq: 12));
|
||||
await _frames(tester);
|
||||
expect(_spinner('s1'), findsNothing);
|
||||
expect(_badge('s1'), findsOneWidget);
|
||||
|
||||
fake.pushed.add(_push('s1', seq: 14));
|
||||
await _frames(tester);
|
||||
expect(_badge('s1'), findsNothing);
|
||||
expect(_spinner('s1'), findsNothing);
|
||||
expect(fake.count('chat_sessions'), 1);
|
||||
});
|
||||
|
||||
testWidgets('an older server without activity keeps the old spinner', (
|
||||
tester,
|
||||
) async {
|
||||
final fake = FakeChatGateway()
|
||||
..sessionsReply = {
|
||||
'chat_sessions': [_row('s1')],
|
||||
};
|
||||
await _pump(tester, fake);
|
||||
expect(_badge('s1'), findsNothing);
|
||||
expect(_spinner('s1'), findsNothing);
|
||||
fake.pushed.add({
|
||||
'type': 'chat_event',
|
||||
'chat_event': {
|
||||
'session_id': 's1',
|
||||
'kind': 'step',
|
||||
'step': {'status': 'started'},
|
||||
},
|
||||
});
|
||||
await _frames(tester);
|
||||
expect(_spinner('s1'), findsOneWidget);
|
||||
expect(_badge('s1'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('the Cupertino host draws its own glyph', (tester) async {
|
||||
final fake = FakeChatGateway()
|
||||
..sessionsReply = {
|
||||
'chat_sessions': [_row('bg', activity: _activity(tasks: 1))],
|
||||
};
|
||||
await _pump(tester, fake, cupertino: true);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: _badge('bg'),
|
||||
matching: find.byIcon(CupertinoIcons.ellipsis_circle_fill),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(_label(1), findsOneWidget);
|
||||
});
|
||||
|
||||
group('controller', () {
|
||||
late FakeChatGateway fake;
|
||||
late ChatSessionsController controller;
|
||||
late List<JsonMap> rows;
|
||||
|
||||
setUp(() {
|
||||
fake = FakeChatGateway();
|
||||
fake.sessionsHandler = () async => {'chat_sessions': rows};
|
||||
controller = ChatSessionsController(
|
||||
ChatRepository(fake),
|
||||
localStore: MemoryChatSessionLocalStore(),
|
||||
);
|
||||
});
|
||||
tearDown(() => controller.dispose());
|
||||
|
||||
JsonMap row() => controller.sessions.single;
|
||||
|
||||
test('a list read older than an applied push keeps the push', () async {
|
||||
rows = [_row('s1', activity: _activity(seq: 5))];
|
||||
await controller.refresh();
|
||||
fake.pushed.add(_push('s1', tasks: 2, seq: 7));
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
expect(chatSessionBackgroundTasks(row()), 2);
|
||||
|
||||
rows = [_row('s1', activity: _activity(seq: 6))];
|
||||
await controller.refresh();
|
||||
expect(chatSessionBackgroundTasks(row()), 2);
|
||||
expect(row()['running'], false);
|
||||
});
|
||||
|
||||
test('a newer list read (a reconnect) replaces the pushed state', () async {
|
||||
rows = [_row('s1', activity: _activity(seq: 5))];
|
||||
await controller.refresh();
|
||||
fake.pushed.add(_push('s1', turn: true, tasks: 2, seq: 7));
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
expect(row()['running'], true);
|
||||
|
||||
rows = [_row('s1', activity: _activity(seq: 90))];
|
||||
await controller.refresh();
|
||||
expect(row()['running'], false);
|
||||
expect(chatSessionBackgroundTasks(row()), 0);
|
||||
});
|
||||
});
|
||||
|
||||
test('chatListActivityOf reads rows and pushes and refuses malformed', () {
|
||||
expect(
|
||||
chatListActivityOf({
|
||||
'turn_running': true,
|
||||
'background_tasks': 2,
|
||||
'seq': 9,
|
||||
}, sessionId: 's1'),
|
||||
(sessionId: 's1', turnRunning: true, backgroundTasks: 2, seq: 9),
|
||||
);
|
||||
expect(chatListActivityOf({'session_id': 's2'}), (
|
||||
sessionId: 's2',
|
||||
turnRunning: false,
|
||||
backgroundTasks: 0,
|
||||
seq: 0,
|
||||
));
|
||||
expect(chatListActivityOf({'background_tasks': 1}), isNull);
|
||||
expect(chatListActivityOf('nope', sessionId: 's1'), isNull);
|
||||
expect(
|
||||
chatListActivityOf({
|
||||
'background_tasks': -4,
|
||||
}, sessionId: 's1')?.backgroundTasks,
|
||||
0,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -67,6 +67,25 @@ JsonMap _event(String id, {String kind = 'text', String? delta}) => {
|
||||
},
|
||||
};
|
||||
|
||||
JsonMap _tool(String id, String status) => {
|
||||
'type': 'chat_event',
|
||||
'chat_event': {
|
||||
'session_id': id,
|
||||
'kind': 'tool',
|
||||
'part': {
|
||||
'type': 'tool',
|
||||
'state': {
|
||||
'status': status,
|
||||
if (status == 'completed')
|
||||
'content': [
|
||||
{'type': 'text', 'text': 'command output'},
|
||||
],
|
||||
if (status == 'error') 'error': 'exit status 1',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
void main() {
|
||||
setUp(() => _store = MemoryChatSessionLocalStore());
|
||||
|
||||
@@ -176,46 +195,79 @@ void main() {
|
||||
expect(find.byType(CircularProgressIndicator), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('tool starts are loading; returned tool results are unread', (
|
||||
testWidgets('tool calls and their results are loading, never New', (
|
||||
tester,
|
||||
) async {
|
||||
final fake = gateway();
|
||||
await _pump(tester, fake);
|
||||
fake.pushed.add({
|
||||
'type': 'chat_event',
|
||||
'chat_event': {
|
||||
'session_id': 's1',
|
||||
'kind': 'tool',
|
||||
'part': {
|
||||
'type': 'tool',
|
||||
'state': {'status': 'running'},
|
||||
},
|
||||
},
|
||||
});
|
||||
fake.pushed.add(_tool('s1', 'running'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(find.byKey(const Key('chat-row-unread')), findsNothing);
|
||||
expect(find.byType(CircularProgressIndicator), findsOneWidget);
|
||||
|
||||
fake.pushed.add(_tool('s1', 'completed'));
|
||||
fake.pushed.add(_tool('s1', 'error'));
|
||||
// Harness notices, agent reports, a prompt from another device and
|
||||
// whitespace-only deltas around a tool call are not a reply either.
|
||||
fake.pushed.add({
|
||||
'type': 'chat_event',
|
||||
'chat_event': {
|
||||
'session_id': 's1',
|
||||
'kind': 'tool',
|
||||
'part': {
|
||||
'type': 'tool',
|
||||
'state': {
|
||||
'status': 'completed',
|
||||
'content': [
|
||||
{'type': 'text', 'text': 'command output'},
|
||||
],
|
||||
},
|
||||
},
|
||||
'kind': 'text',
|
||||
'delta': 'Background task finished',
|
||||
'message_kind': 'notice',
|
||||
},
|
||||
});
|
||||
fake.pushed.add({
|
||||
'type': 'chat_event',
|
||||
'chat_event': {
|
||||
'session_id': 's1',
|
||||
'kind': 'text',
|
||||
'delta': 'Subagent report',
|
||||
'message_kind': 'agent_report',
|
||||
},
|
||||
});
|
||||
fake.pushed.add({
|
||||
'type': 'chat_event',
|
||||
'chat_event': {'session_id': 's1', 'kind': 'user', 'delta': 'hi'},
|
||||
});
|
||||
fake.pushed.add(_event('s1', delta: '\n\n'));
|
||||
// The turn is still working, so its spinner never settles.
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(find.byKey(const Key('chat-row-unread')), findsNothing);
|
||||
expect(find.byType(CircularProgressIndicator), findsOneWidget);
|
||||
|
||||
// The assistant's reply after the tool call is what is unread.
|
||||
fake.pushed.add(_event('s1', delta: 'Done: tests pass.'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a tool call and reply in the open chat stay read on leaving', (
|
||||
tester,
|
||||
) async {
|
||||
final fake = gateway();
|
||||
await _pump(tester, fake, active: 's1');
|
||||
fake.pushed.add(_tool('s1', 'running'));
|
||||
fake.pushed.add(_tool('s1', 'completed'));
|
||||
fake.pushed.add(_event('s1', delta: 'Here is the answer.'));
|
||||
fake.pushed.add({
|
||||
'type': 'chat_event',
|
||||
'chat_event': {
|
||||
'session_id': 's1',
|
||||
'kind': 'step',
|
||||
'step': {'status': 'ended'},
|
||||
},
|
||||
});
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
|
||||
expect(find.byType(CircularProgressIndicator), findsNothing);
|
||||
expect(find.byKey(const Key('chat-row-unread')), findsNothing);
|
||||
|
||||
await _pump(tester, fake);
|
||||
expect(find.byKey(const Key('chat-row-unread')), findsNothing);
|
||||
expect(_store.state?.isUnseen('s1') ?? false, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('only unresolved permission requests mark New', (tester) async {
|
||||
|
||||
@@ -37,4 +37,44 @@ void main() {
|
||||
});
|
||||
expect(intermediate!.running, isNull);
|
||||
});
|
||||
|
||||
test('only visible assistant reply text is unread', () {
|
||||
bool attention(Map<String, Object?> event) =>
|
||||
chatSessionFrameEffect({
|
||||
'type': 'chat_event',
|
||||
'chat_event': {'session_id': 's', ...event},
|
||||
})!.attention;
|
||||
for (final status in ['running', 'completed', 'error']) {
|
||||
expect(
|
||||
attention({
|
||||
'kind': 'tool',
|
||||
'part': {
|
||||
'type': 'tool',
|
||||
'state': {
|
||||
'status': status,
|
||||
'content': [
|
||||
{'type': 'text', 'text': 'out'},
|
||||
],
|
||||
'error': status == 'error' ? 'failed' : null,
|
||||
},
|
||||
},
|
||||
}),
|
||||
isFalse,
|
||||
reason: 'tool $status',
|
||||
);
|
||||
}
|
||||
expect(attention({'kind': 'user', 'delta': 'prompt'}), isFalse);
|
||||
expect(attention({'kind': 'text', 'delta': ' \n'}), isFalse);
|
||||
for (final messageKind in ['notice', 'agent_report']) {
|
||||
expect(
|
||||
attention({
|
||||
'kind': 'text',
|
||||
'delta': 'x',
|
||||
'message_kind': messageKind,
|
||||
}),
|
||||
isFalse,
|
||||
);
|
||||
}
|
||||
expect(attention({'kind': 'text', 'delta': 'answer'}), isTrue);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_link_launcher.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_view.dart';
|
||||
|
||||
import 'chat_markdown_test_support.dart';
|
||||
|
||||
// A mouse click on a link opens it even when the pointer moves a few pixels
|
||||
// between press and release: the selection area used to claim that press as a
|
||||
// selection drag after 2 px, so ordinary clicks in the browser opened nothing.
|
||||
void main() {
|
||||
late List<Uri> opened;
|
||||
|
||||
Future<RenderParagraph> pump(WidgetTester tester) async {
|
||||
await phoneViewport(tester);
|
||||
opened = [];
|
||||
await tester.pumpWidget(
|
||||
ChatLinkScope(
|
||||
launcher: (uri) async {
|
||||
opened.add(uri);
|
||||
return true;
|
||||
},
|
||||
child: markdownHost(
|
||||
const ChatMarkdownView(text: 'go [here](https://x.com/c) now'),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return tester.renderObject<RenderParagraph>(find.byType(RichText).first);
|
||||
}
|
||||
|
||||
Offset centreOf(RenderParagraph paragraph, String text) {
|
||||
final start = paragraph.text.toPlainText().indexOf(text);
|
||||
final box = paragraph.getBoxesForSelection(
|
||||
TextSelection(baseOffset: start, extentOffset: start + text.length),
|
||||
);
|
||||
return paragraph.localToGlobal(box.first.toRect().center);
|
||||
}
|
||||
|
||||
Future<void> mouseDrag(WidgetTester tester, Offset from, double dx) async {
|
||||
final mouse = await tester.startGesture(
|
||||
from,
|
||||
kind: PointerDeviceKind.mouse,
|
||||
);
|
||||
await tester.pump();
|
||||
// Three moves, as a hand drifts during a click or drags.
|
||||
for (var i = 1; i <= 3; i++) {
|
||||
await mouse.moveTo(from + Offset(dx * i / 3, 0));
|
||||
await tester.pump();
|
||||
}
|
||||
await mouse.up();
|
||||
await tester.pumpAndSettle();
|
||||
await mouse.removePointer();
|
||||
}
|
||||
|
||||
for (final dx in [0.0, 3.0, 8.0]) {
|
||||
testWidgets(
|
||||
'a mouse click moving ${dx}px opens the link',
|
||||
(tester) async {
|
||||
final paragraph = await pump(tester);
|
||||
await mouseDrag(tester, centreOf(paragraph, 'here'), dx);
|
||||
expect(opened.map((uri) => '$uri'), ['https://x.com/c']);
|
||||
},
|
||||
variant: TargetPlatformVariant.desktop(),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
'dragging off a link opens nothing',
|
||||
(tester) async {
|
||||
final paragraph = await pump(tester);
|
||||
await mouseDrag(tester, centreOf(paragraph, 'here'), 40);
|
||||
expect(opened, isEmpty);
|
||||
},
|
||||
variant: TargetPlatformVariant.only(TargetPlatform.macOS),
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'a mouse drag from plain text still selects across the link',
|
||||
(tester) async {
|
||||
final paragraph = await pump(tester);
|
||||
final from = centreOf(paragraph, 'go');
|
||||
await mouseDrag(tester, from, centreOf(paragraph, 'now').dx - from.dx);
|
||||
expect(opened, isEmpty);
|
||||
String? copied;
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
(call) async {
|
||||
if (call.method == 'Clipboard.setData') {
|
||||
copied = (call.arguments as Map)['text'] as String?;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
null,
|
||||
),
|
||||
);
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.meta);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyC);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.meta);
|
||||
await tester.pump();
|
||||
// The link claims only presses on itself; this drag selects across it.
|
||||
expect(copied, contains('o here n'));
|
||||
},
|
||||
variant: TargetPlatformVariant.only(TargetPlatform.macOS),
|
||||
);
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_view.dart';
|
||||
import 'package:pipelines_app/ui/text/monospace.dart';
|
||||
|
||||
import 'chat_markdown_test_support.dart';
|
||||
|
||||
@@ -126,7 +127,7 @@ void main() {
|
||||
expect(code.style?.backgroundColor, fill, reason: '$cupertino');
|
||||
expect(plain.style?.backgroundColor, isNull, reason: '$cupertino');
|
||||
expect(code.style?.fontSize, isNull, reason: '$cupertino');
|
||||
expect(code.style?.fontFamily, isNull, reason: '$cupertino');
|
||||
expect(code.style?.fontFamily, appMonospaceFamily, reason: '$cupertino');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/runs/domain/run_models.dart';
|
||||
import 'package:pipelines_app/features/runs/domain/run_tokens.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/runs_filter_options.dart';
|
||||
|
||||
JsonMap _run(int id, {Map<String, dynamic>? usage, String? created}) => {
|
||||
'id': id,
|
||||
'created_at': created ?? '2026-10-2${id % 10}T12:00:00Z',
|
||||
'usage': ?usage,
|
||||
};
|
||||
|
||||
Map<String, dynamic> _usage(
|
||||
int total, {
|
||||
int stages = 1,
|
||||
int? tokenStages,
|
||||
bool split = false,
|
||||
int input = 0,
|
||||
int output = 0,
|
||||
int costStages = 0,
|
||||
double? cost,
|
||||
}) => {
|
||||
'stages': stages,
|
||||
'tokens_total': total,
|
||||
'tokens_known_stages': tokenStages ?? stages,
|
||||
'split_known': split,
|
||||
if (input > 0) 'tokens_in': input,
|
||||
if (output > 0) 'tokens_out': output,
|
||||
'cost_known_stages': costStages,
|
||||
'cost_usd': ?cost,
|
||||
};
|
||||
|
||||
void main() {
|
||||
test('token counts are compact decimal multiples', () {
|
||||
expect(formatTokenCount(0), '0');
|
||||
expect(formatTokenCount(950), '950');
|
||||
expect(formatTokenCount(1000), '1K');
|
||||
expect(formatTokenCount(1234), '1.2K');
|
||||
expect(formatTokenCount(340000), '340K');
|
||||
expect(formatTokenCount(999600), '1M');
|
||||
expect(formatTokenCount(22400015), '22.4M');
|
||||
expect(formatTokenCount(1300000000), '1.3B');
|
||||
});
|
||||
|
||||
test('a reported run total is labelled like the size', () {
|
||||
final usage = runTokenUsage(_run(1, usage: _usage(22400015)))!;
|
||||
expect(usage.partial, isFalse);
|
||||
expect(tokenUsageLabel(usage), '22.4M tokens');
|
||||
});
|
||||
|
||||
test('a partial total is a lower bound, never an estimate', () {
|
||||
final usage = runTokenUsage(
|
||||
_run(1, usage: _usage(9, stages: 2, tokenStages: 1)),
|
||||
)!;
|
||||
expect(usage.partial, isTrue);
|
||||
expect(tokenUsageLabel(usage), '≥9 tokens');
|
||||
expect(tokenUsageDetail(usage), '≥9 · 1 of 2 stages reported');
|
||||
});
|
||||
|
||||
test('absent or unreported usage shows nothing', () {
|
||||
expect(runTokenUsage(_run(1)), isNull);
|
||||
expect(runTokenUsage({'id': 1, 'usage': 'bogus'}), isNull);
|
||||
// Only a cost was reported: no token figure is invented.
|
||||
expect(
|
||||
runTokenUsage(_run(1, usage: _usage(0, tokenStages: 0, costStages: 1))),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
|
||||
test('the detail adds the split and the reported cost', () {
|
||||
final usage = runTokenUsage(
|
||||
_run(
|
||||
1,
|
||||
usage: _usage(
|
||||
22400015,
|
||||
stages: 2,
|
||||
split: true,
|
||||
input: 20000010,
|
||||
output: 2400005,
|
||||
costStages: 2,
|
||||
cost: 1.75,
|
||||
),
|
||||
),
|
||||
)!;
|
||||
expect(tokenUsageDetail(usage), '22.4M · 20M in, 2.4M out');
|
||||
expect(tokenUsageCost(usage), '\$1.75');
|
||||
|
||||
final partialCost = runTokenUsage(
|
||||
_run(1, usage: _usage(9, stages: 2, costStages: 1, cost: 0.1)),
|
||||
)!;
|
||||
expect(tokenUsageCost(partialCost), '≥\$0.10');
|
||||
expect(
|
||||
tokenUsageCost(runTokenUsage(_run(1, usage: _usage(9)))!),
|
||||
'Not reported',
|
||||
);
|
||||
expect(
|
||||
tokenUsageCost(
|
||||
runTokenUsage(_run(1, usage: _usage(9, costStages: 1, cost: 0.0042)))!,
|
||||
),
|
||||
'\$0.0042',
|
||||
);
|
||||
});
|
||||
|
||||
test('the detail splits fresh from cached when every stage reported it', () {
|
||||
final usage = runTokenUsage(
|
||||
_run(
|
||||
1,
|
||||
usage: {
|
||||
..._usage(22400000, split: true, input: 900000, output: 150000),
|
||||
'cache_known': true,
|
||||
'cache_read': 21300000,
|
||||
'cache_write': 50000,
|
||||
},
|
||||
),
|
||||
)!;
|
||||
expect(tokenUsageLabel(usage), '22.4M tokens');
|
||||
expect(usage.fresh, 1100000);
|
||||
expect(
|
||||
tokenUsageDetail(usage),
|
||||
'22.4M · 1.1M fresh, 21.3M cached · 900K in, 150K out',
|
||||
);
|
||||
// An older row (or a partial cache split) has no cache figure: just the
|
||||
// total and what else it reported.
|
||||
final old = runTokenUsage(
|
||||
_run(
|
||||
1,
|
||||
usage: _usage(22400000, split: true, input: 900000, output: 150000),
|
||||
),
|
||||
)!;
|
||||
expect(old.fresh, isNull);
|
||||
expect(tokenUsageDetail(old), '22.4M · 900K in, 150K out');
|
||||
});
|
||||
|
||||
test('a zero or missing "known" cost is not reported, never \$0', () {
|
||||
// Subscription models report cost_known with no positive cost_usd.
|
||||
for (final usage in [
|
||||
_usage(9, costStages: 1),
|
||||
_usage(9, costStages: 1, cost: 0),
|
||||
]) {
|
||||
final tokens = runTokenUsage(_run(1, usage: usage))!;
|
||||
expect(tokens.cost, isNull);
|
||||
expect(tokenUsageCost(tokens), 'Not reported');
|
||||
}
|
||||
final stage = stageTokenUsage({
|
||||
'usage': {'tokens_total': 9, 'tokens_known': true, 'cost_known': true},
|
||||
})!;
|
||||
expect(tokenUsageCost(stage), 'Not reported');
|
||||
});
|
||||
|
||||
test('a stage reports its own tokens only when it counted them', () {
|
||||
final stage = stageTokenUsage({
|
||||
'usage': {
|
||||
'tokens_total': 1500,
|
||||
'tokens_known': true,
|
||||
'split_known': true,
|
||||
'tokens_in': 1200,
|
||||
'tokens_out': 300,
|
||||
'cost_known': true,
|
||||
'cost_usd': 0.02,
|
||||
},
|
||||
})!;
|
||||
expect(tokenUsageDetail(stage), '1.5K · 1.2K in, 300 out');
|
||||
expect(tokenUsageCost(stage), '\$0.02');
|
||||
expect(
|
||||
stageTokenUsage({
|
||||
'usage': {'cost_known': true},
|
||||
}),
|
||||
isNull,
|
||||
);
|
||||
expect(stageTokenUsage({}), isNull);
|
||||
});
|
||||
|
||||
test('Most tokens sorts reported totals first, largest first', () {
|
||||
final runs = [
|
||||
_run(1, usage: _usage(5)),
|
||||
_run(2),
|
||||
_run(3, usage: _usage(22400000)),
|
||||
_run(4, usage: _usage(9, stages: 2, tokenStages: 1)),
|
||||
_run(5),
|
||||
];
|
||||
final sorted = sortRuns(runs, sort: 'most_tokens');
|
||||
expect(sorted.map((run) => run['id']), [3, 4, 1, 5, 2]);
|
||||
});
|
||||
|
||||
test('Most tokens is offered beside Largest first and lists flat', () {
|
||||
final keys = runSorts.map((option) => option.$1).toList();
|
||||
expect(keys.indexOf('most_tokens'), keys.indexOf('largest_first') + 1);
|
||||
expect(runSortLabel('most_tokens'), 'Most tokens');
|
||||
expect(flatRunSorts, contains('most_tokens'));
|
||||
});
|
||||
}
|
||||
@@ -24,6 +24,7 @@ JsonMap recordedRunFixture() => <String, dynamic>{
|
||||
'retry_of': 12,
|
||||
'diagnostic': 'Traceback: boom',
|
||||
'completed_steps': 2,
|
||||
'size_bytes': 5 * 1024 * 1024,
|
||||
'input': <String, dynamic>{'prompt': 'ship it'},
|
||||
'output': <String, dynamic>{'result': 'ok'},
|
||||
'steps': <dynamic>[
|
||||
@@ -64,6 +65,9 @@ const recordedLabels = [
|
||||
'Started',
|
||||
'Finished',
|
||||
'Duration',
|
||||
'Size on disk',
|
||||
'Tokens',
|
||||
'Cost',
|
||||
'Retry of',
|
||||
'Diagnostic',
|
||||
];
|
||||
@@ -91,6 +95,12 @@ void main() {
|
||||
formatLocalTimestamp('2026-10-19T09:32:05Z'),
|
||||
);
|
||||
expect(rows.firstWhere((row) => row.label == 'Duration').value, '2m 5s');
|
||||
expect(rows.firstWhere((row) => row.label == 'Size on disk').value, '5 MB');
|
||||
expect(
|
||||
rows.firstWhere((row) => row.label == 'Tokens').value,
|
||||
'123 · 100 in, 23 out',
|
||||
);
|
||||
expect(rows.firstWhere((row) => row.label == 'Cost').value, '\$0.50');
|
||||
expect(rows.firstWhere((row) => row.label == 'Retry of').value, 'run 12');
|
||||
final diagnostic = rows.firstWhere((row) => row.label == 'Diagnostic');
|
||||
expect(diagnostic.value, 'Traceback: boom');
|
||||
|
||||
@@ -86,6 +86,48 @@ void main() {
|
||||
expect(find.text('Pipeline unavailable · 2m 5s · 3 steps'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('shows reported tokens beside the size, and nothing without', (
|
||||
tester,
|
||||
) async {
|
||||
Future<void> pump(JsonMap run) => tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunListRow(run: run, now: DateTime.utc(2026, 10, 22)),
|
||||
),
|
||||
),
|
||||
);
|
||||
final sized = {..._finished, 'size_bytes': 340 * 1024 * 1024};
|
||||
await pump({
|
||||
...sized,
|
||||
'usage': {
|
||||
'stages': 3,
|
||||
'tokens_known_stages': 3,
|
||||
'tokens_total': 22400015,
|
||||
},
|
||||
});
|
||||
expect(
|
||||
find.text('release · 2m 5s · 3 steps · 340 MB · 22.4M tokens'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
await pump({
|
||||
...sized,
|
||||
'usage': {
|
||||
'stages': 3,
|
||||
'tokens_known_stages': 2,
|
||||
'tokens_total': 22400015,
|
||||
},
|
||||
});
|
||||
expect(
|
||||
find.text('release · 2m 5s · 3 steps · 340 MB · ≥22.4M tokens'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
// An older server's list carries no usage: the row is unchanged.
|
||||
await pump(sized);
|
||||
expect(find.text('release · 2m 5s · 3 steps · 340 MB'), findsOneWidget);
|
||||
});
|
||||
|
||||
test('the run action sheet is titled with the run', () {
|
||||
expect(runMoreMenuTitle(_finished), 'Ship the release notes');
|
||||
expect(runMoreMenuTitle({'id': 5, 'name': 'nightly'}), 'nightly');
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_content.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_visit_facts.dart';
|
||||
|
||||
final _reported = <String, dynamic>{
|
||||
'stage': 'build',
|
||||
'sequence': 1,
|
||||
'status': 'completed',
|
||||
'outcome': 'success',
|
||||
'target': 'review',
|
||||
'usage': {
|
||||
'tokens_total': 1500000,
|
||||
'tokens_known': true,
|
||||
'split_known': true,
|
||||
'tokens_in': 1200000,
|
||||
'tokens_out': 300000,
|
||||
'cost_known': true,
|
||||
'cost_usd': 0.42,
|
||||
},
|
||||
};
|
||||
|
||||
final _unreported = <String, dynamic>{
|
||||
'stage': 'gate',
|
||||
'sequence': 2,
|
||||
'status': 'completed',
|
||||
};
|
||||
|
||||
void main() {
|
||||
test('a visit lists its reported tokens and cost as facts', () {
|
||||
final facts = detailVisitFacts(_reported);
|
||||
expect(
|
||||
facts,
|
||||
contains((label: 'Tokens', value: '1.5M · 1.2M in, 300K out')),
|
||||
);
|
||||
expect(facts, contains((label: 'Cost', value: '\$0.42')));
|
||||
final none = detailVisitFacts(_unreported);
|
||||
expect(none.any((fact) => fact.label == 'Tokens'), isFalse);
|
||||
expect(none.any((fact) => fact.label == 'Cost'), isFalse);
|
||||
});
|
||||
|
||||
test('a stage row carries its compact token total', () {
|
||||
final visits = detailTimeline([_reported, _unreported]);
|
||||
expect(visits[0].tokens, '1.5M tokens · \$0.42');
|
||||
expect(visits[1].tokens, isNull);
|
||||
});
|
||||
|
||||
String? rowLabel(Map<String, dynamic> usage) => detailTimeline([
|
||||
{..._unreported, 'usage': usage},
|
||||
])[0].tokens;
|
||||
|
||||
test('a stage row adds its cached share and cost when reported', () {
|
||||
const base = {'tokens_known': true, 'tokens_total': 20100000};
|
||||
expect(
|
||||
rowLabel({
|
||||
...base,
|
||||
'cache_known': true,
|
||||
'cache_read': 19100000,
|
||||
'cost_known': true,
|
||||
'cost_usd': 0.4249,
|
||||
}),
|
||||
'20.1M tokens · 95% cached · \$0.42',
|
||||
);
|
||||
// A known split with no reads is a real 0%, not an absence.
|
||||
expect(
|
||||
rowLabel({...base, 'cache_known': true}),
|
||||
'20.1M tokens · 0% cached',
|
||||
);
|
||||
// An older row without cache_known, or a cache read alone, shows no share.
|
||||
expect(rowLabel({...base, 'cache_read': 19100000}), '20.1M tokens');
|
||||
// Tiny costs stay visible; zero or unknown costs are omitted on the row.
|
||||
expect(
|
||||
rowLabel({...base, 'cost_known': true, 'cost_usd': 0.0042}),
|
||||
'20.1M tokens · <\$0.01',
|
||||
);
|
||||
expect(
|
||||
rowLabel({...base, 'cost_known': true, 'cost_usd': 0.005}),
|
||||
'20.1M tokens · \$0.01',
|
||||
);
|
||||
expect(
|
||||
rowLabel({...base, 'cost_known': true, 'cost_usd': 0}),
|
||||
'20.1M tokens',
|
||||
);
|
||||
expect(rowLabel({...base, 'cost_usd': 1.5}), '20.1M tokens');
|
||||
// The stage detail still says the cost was not reported.
|
||||
final facts = detailVisitFacts({
|
||||
..._unreported,
|
||||
'usage': {...base, 'cost_known': true},
|
||||
});
|
||||
expect(facts, contains((label: 'Cost', value: 'Not reported')));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/settings/settings_font_section.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_font.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_font_controller.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_font_store.dart';
|
||||
|
||||
class _Harness {
|
||||
_Harness({this.hold = false});
|
||||
|
||||
final bool hold;
|
||||
final store = MemoryAppFontStore();
|
||||
final loads = <String>[];
|
||||
final held = <Completer<void>>[];
|
||||
|
||||
late final fonts = AppFontController(
|
||||
store: store,
|
||||
loader: (family, assets) {
|
||||
loads.addAll(assets);
|
||||
if (!hold || assets.length == 1) return Future<void>.value();
|
||||
final done = Completer<void>();
|
||||
held.add(done);
|
||||
return done.future;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _pump(
|
||||
WidgetTester tester,
|
||||
_Harness harness, {
|
||||
bool cupertino = false,
|
||||
}) async {
|
||||
final section = SingleChildScrollView(
|
||||
child: SettingsFontSection(controller: harness.fonts),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: section))
|
||||
: MaterialApp(home: Scaffold(body: section)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
String? _familyOf(WidgetTester tester, AppFont font) => tester
|
||||
.widget<Text>(
|
||||
find.descendant(
|
||||
of: find.byKey(settingsFontKey(font)),
|
||||
matching: find.text(font.label),
|
||||
),
|
||||
)
|
||||
.style
|
||||
?.fontFamily;
|
||||
|
||||
void main() {
|
||||
testWidgets('Material: every option is a radio named in its own face', (
|
||||
tester,
|
||||
) async {
|
||||
final harness = _Harness();
|
||||
await _pump(tester, harness);
|
||||
|
||||
expect(find.text(fontSectionTitle), findsOneWidget);
|
||||
for (final font in AppFont.values) {
|
||||
expect(find.byKey(settingsFontKey(font)), findsOneWidget);
|
||||
expect(_familyOf(tester, font), font.family ?? 'Roboto');
|
||||
}
|
||||
// Showing the picker fetched one regular weight per option, no more.
|
||||
expect(harness.loads, <String?>[
|
||||
for (final font in AppFont.values)
|
||||
if (font.previewAsset != null) font.previewAsset,
|
||||
]);
|
||||
final group = tester.widget<RadioGroup<AppFont>>(
|
||||
find.byType(RadioGroup<AppFont>),
|
||||
);
|
||||
expect(group.groupValue, AppFont.system);
|
||||
});
|
||||
|
||||
testWidgets('Material: choosing a font stores it and shows it loading', (
|
||||
tester,
|
||||
) async {
|
||||
final harness = _Harness(hold: true);
|
||||
await _pump(tester, harness);
|
||||
|
||||
await tester.tap(find.text('Source Sans 3'));
|
||||
await tester.pump();
|
||||
expect(harness.store.font, AppFont.sourceSans3);
|
||||
expect(
|
||||
tester
|
||||
.widget<RadioGroup<AppFont>>(find.byType(RadioGroup<AppFont>))
|
||||
.groupValue,
|
||||
AppFont.sourceSans3,
|
||||
);
|
||||
expect(find.text(fontLoadingText), findsOneWidget);
|
||||
expect(harness.fonts.family, isNull);
|
||||
|
||||
harness.held.single.complete();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(fontLoadingText), findsNothing);
|
||||
expect(harness.fonts.family, 'Source Sans 3');
|
||||
});
|
||||
|
||||
testWidgets('Cupertino: the chosen row carries the checkmark', (
|
||||
tester,
|
||||
) async {
|
||||
final harness = _Harness();
|
||||
await _pump(tester, harness, cupertino: true);
|
||||
|
||||
expect(find.byType(RadioListTile<AppFont>), findsNothing);
|
||||
expect(_familyOf(tester, AppFont.system), 'CupertinoSystemText');
|
||||
Finder check(AppFont font) => find.descendant(
|
||||
of: find.byKey(settingsFontKey(font)),
|
||||
matching: find.byIcon(CupertinoIcons.check_mark),
|
||||
);
|
||||
expect(check(AppFont.system), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Inter'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(check(AppFont.system), findsNothing);
|
||||
expect(check(AppFont.inter), findsOneWidget);
|
||||
expect(harness.store.font, AppFont.inter);
|
||||
expect(harness.fonts.family, 'Inter');
|
||||
});
|
||||
|
||||
testWidgets('a failed save is said under the group', (tester) async {
|
||||
final harness = _Harness();
|
||||
harness.store.failSaves = true;
|
||||
await _pump(tester, harness);
|
||||
|
||||
await tester.tap(find.text('Inter'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(fontSaveFailedText), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../../../tool/memwatch/summary.dart';
|
||||
|
||||
const _root = '/work/app';
|
||||
|
||||
String _event(Map<String, Object?> event) => jsonEncode(event);
|
||||
|
||||
List<String> _run({List<Map<String, Object?>> tests = const [], List<String> extra = const []}) => [
|
||||
_event({'type': 'suite', 'suite': {'id': 0, 'path': '$_root/test/a_test.dart'}}),
|
||||
for (final t in tests) ...[
|
||||
_event({'type': 'testStart', 'test': {'id': t['id'], 'name': t['name'], 'suiteID': 0}}),
|
||||
for (final p in (t['prints'] as List<String>? ?? const []))
|
||||
_event({'type': 'print', 'testID': t['id'], 'message': p}),
|
||||
if (t['error'] != null)
|
||||
_event({'type': 'error', 'testID': t['id'], 'error': t['error'], 'stackTrace': t['stack'] ?? ''}),
|
||||
if (t['done'] != false)
|
||||
_event({
|
||||
'type': 'testDone',
|
||||
'testID': t['id'],
|
||||
'result': t['error'] == null ? 'success' : 'failure',
|
||||
'skipped': t['skipped'] ?? false,
|
||||
'hidden': t['hidden'] ?? false,
|
||||
}),
|
||||
],
|
||||
...extra,
|
||||
];
|
||||
|
||||
String _summary(List<String> events, {int status = 1, List<String> logTail = const []}) => summarize(
|
||||
events,
|
||||
status: status,
|
||||
peakMb: 812,
|
||||
seconds: 9,
|
||||
target: 'test/a',
|
||||
logPath: '/tmp/memwatch/out.x',
|
||||
jsonPath: '/tmp/memwatch/out.x.json',
|
||||
logTail: logTail,
|
||||
appPackage: 'pipelines_app',
|
||||
appRoot: _root,
|
||||
);
|
||||
|
||||
void main() {
|
||||
test('a passing run is the verdict line and the log paths only', () {
|
||||
final summary = _summary(
|
||||
_run(tests: [
|
||||
{'id': 1, 'name': 'loading $_root/test/a_test.dart', 'hidden': true},
|
||||
{'id': 2, 'name': 'ok', 'prints': ['noise']},
|
||||
{'id': 3, 'name': 'skip me', 'skipped': true},
|
||||
]),
|
||||
status: 0,
|
||||
);
|
||||
expect(summary.split('\n'), [
|
||||
'memwatch: PASS: 1 passed, 0 failed, 1 skipped; peak 812 MB; 9s; exit 0 (test/a)',
|
||||
'full output: /tmp/memwatch/out.x',
|
||||
'json results: /tmp/memwatch/out.x.json',
|
||||
]);
|
||||
});
|
||||
|
||||
test('a failure shows its error and app frames, not framework frames', () {
|
||||
final summary = _summary(_run(tests: [
|
||||
{
|
||||
'id': 2,
|
||||
'name': 'group adds',
|
||||
'error': "Expected: <2>\n Actual: <3>",
|
||||
'stack': 'package:matcher expect\n'
|
||||
'package:flutter_test/src/widget_tester.dart 473:18 expect\n'
|
||||
'test/a_test.dart 11:5 main.<fn>\n',
|
||||
},
|
||||
]));
|
||||
expect(summary, contains('memwatch: FAIL: 0 passed, 1 failed, 0 skipped'));
|
||||
expect(summary, contains('FAILED test/a_test.dart: group adds'));
|
||||
expect(summary, contains('Actual: <3>'));
|
||||
expect(summary, contains('test/a_test.dart 11:5'));
|
||||
expect(summary, isNot(contains('package:matcher')));
|
||||
expect(summary, isNot(contains('widget_tester.dart')));
|
||||
});
|
||||
|
||||
test('a flooding failure is bounded and keeps the exception before prints', () {
|
||||
final flood = [for (var i = 0; i < 5000; i++) 'flood $i ${'y' * 500}'];
|
||||
final exception = [
|
||||
'══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞══',
|
||||
'The following TestFailure was thrown running a test:',
|
||||
'Expected: exactly one matching candidate',
|
||||
for (var i = 0; i < 200; i++) '#$i frame (package:flutter/src/widgets/framework.dart:$i:1)',
|
||||
'#201 main.<anonymous closure> (file://$_root/test/a_test.dart:20:5)',
|
||||
].join('\n');
|
||||
final summary = _summary(_run(tests: [
|
||||
for (var id = 2; id < 52; id++)
|
||||
{'id': id, 'name': 'fails $id', 'prints': [...flood, exception], 'error': 'Test failed. See exception logs above.'},
|
||||
]));
|
||||
expect(summary.length, lessThan(maxDetailChars + 4000));
|
||||
expect(summary, contains('Expected: exactly one matching candidate'));
|
||||
expect(summary, contains('(test/a_test.dart:20:5)'));
|
||||
expect(summary, isNot(contains('framework.dart')));
|
||||
expect(summary, contains('printed output (last 8 of 5000 lines):'));
|
||||
expect(summary, contains('... and 20 more failures (see full log)'));
|
||||
expect(summary.indexOf('EXCEPTION CAUGHT'), lessThan(summary.indexOf('printed output')));
|
||||
});
|
||||
|
||||
test('a killed run names the tests still running', () {
|
||||
final summary = _summary(
|
||||
_run(tests: [
|
||||
{'id': 2, 'name': 'finished'},
|
||||
{'id': 3, 'name': 'runaway', 'done': false},
|
||||
]),
|
||||
status: 137,
|
||||
);
|
||||
expect(summary, startsWith('memwatch: KILLED: 1 passed, 0 failed'));
|
||||
expect(summary, contains('RUNNING when killed: test/a_test.dart: runaway'));
|
||||
});
|
||||
|
||||
test('a run without results shows the bounded log tail', () {
|
||||
final summary = _summary(const [], logTail: ['Error: no test files', 'x' * 1000]);
|
||||
expect(summary, contains('no test results were recorded; last log lines:'));
|
||||
expect(summary, contains(' Error: no test files'));
|
||||
expect(summary.length, lessThan(800));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_font.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_font_controller.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_font_store.dart';
|
||||
|
||||
/// Records each load and completes it when the test says so.
|
||||
class _Loads {
|
||||
final calls = <(String, List<String>)>[];
|
||||
final pending = <Completer<void>>[];
|
||||
bool immediate = true;
|
||||
|
||||
Future<void> call(String family, List<String> assets) {
|
||||
calls.add((family, assets));
|
||||
final done = Completer<void>();
|
||||
pending.add(done);
|
||||
if (immediate) done.complete();
|
||||
return done.future;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('starts on the system default with no download', () async {
|
||||
final loads = _Loads();
|
||||
final fonts = AppFontController(
|
||||
store: MemoryAppFontStore(),
|
||||
loader: loads.call,
|
||||
);
|
||||
await fonts.restore();
|
||||
expect(fonts.selected, AppFont.system);
|
||||
expect(fonts.family, isNull);
|
||||
expect(loads.calls, isEmpty);
|
||||
});
|
||||
|
||||
test('restore loads only the stored family, then applies it', () async {
|
||||
final loads = _Loads()..immediate = false;
|
||||
final fonts = AppFontController(
|
||||
store: MemoryAppFontStore(AppFont.inter),
|
||||
loader: loads.call,
|
||||
);
|
||||
final restoring = fonts.restore();
|
||||
await pumpEventQueue();
|
||||
expect(fonts.selected, AppFont.inter);
|
||||
expect(fonts.family, isNull, reason: 'system face until loaded');
|
||||
expect(fonts.loading, isTrue);
|
||||
expect(loads.calls.single.$1, 'Inter');
|
||||
expect(loads.calls.single.$2, AppFont.inter.assets);
|
||||
loads.pending.single.complete();
|
||||
await restoring;
|
||||
expect(fonts.family, 'Inter');
|
||||
expect(fonts.loading, isFalse);
|
||||
});
|
||||
|
||||
test(
|
||||
'restore with a wait returns at the deadline and applies later',
|
||||
() async {
|
||||
final loads = _Loads()..immediate = false;
|
||||
final fonts = AppFontController(
|
||||
store: MemoryAppFontStore(AppFont.sourceSans3),
|
||||
loader: loads.call,
|
||||
);
|
||||
await fonts.restore(wait: const Duration(milliseconds: 10));
|
||||
expect(fonts.family, isNull);
|
||||
loads.pending.single.complete();
|
||||
await pumpEventQueue();
|
||||
expect(fonts.family, 'Source Sans 3');
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'select stores the choice and applies it; system needs no load',
|
||||
() async {
|
||||
final store = MemoryAppFontStore();
|
||||
final loads = _Loads();
|
||||
final fonts = AppFontController(store: store, loader: loads.call);
|
||||
await fonts.select(AppFont.atkinsonHyperlegible);
|
||||
expect(store.font, AppFont.atkinsonHyperlegible);
|
||||
expect(fonts.family, 'Atkinson Hyperlegible Next');
|
||||
await fonts.select(AppFont.system);
|
||||
expect(store.font, AppFont.system);
|
||||
expect(fonts.family, isNull);
|
||||
expect(loads.calls, hasLength(1));
|
||||
},
|
||||
);
|
||||
|
||||
test('a newer choice wins over a slower earlier load', () async {
|
||||
final loads = _Loads()..immediate = false;
|
||||
final fonts = AppFontController(
|
||||
store: MemoryAppFontStore(),
|
||||
loader: loads.call,
|
||||
);
|
||||
final first = fonts.select(AppFont.inter);
|
||||
await pumpEventQueue();
|
||||
final second = fonts.select(AppFont.ibmPlexSans);
|
||||
await pumpEventQueue();
|
||||
loads.pending[1].complete();
|
||||
await second;
|
||||
expect(fonts.family, 'IBM Plex Sans');
|
||||
loads.pending[0].complete();
|
||||
await first;
|
||||
expect(fonts.family, 'IBM Plex Sans');
|
||||
});
|
||||
|
||||
test(
|
||||
'preview loads the regular weight once; choosing loads the rest',
|
||||
() async {
|
||||
final loads = _Loads();
|
||||
final fonts = AppFontController(
|
||||
store: MemoryAppFontStore(),
|
||||
loader: loads.call,
|
||||
);
|
||||
expect(fonts.canPreview(AppFont.inter), isFalse);
|
||||
await fonts.preview(AppFont.inter);
|
||||
await fonts.preview(AppFont.inter);
|
||||
await fonts.preview(AppFont.system);
|
||||
expect(fonts.canPreview(AppFont.inter), isTrue);
|
||||
expect(fonts.canPreview(AppFont.system), isTrue);
|
||||
expect(loads.calls.single.$1, 'Inter');
|
||||
expect(loads.calls.single.$2, <String>['fonts/inter/Inter-Regular.ttf']);
|
||||
await fonts.select(AppFont.inter);
|
||||
expect(loads.calls.last.$2, AppFont.inter.assets.skip(1).toList());
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'a failed load keeps the current face, says so, and can retry',
|
||||
() async {
|
||||
var fail = true;
|
||||
final fonts = AppFontController(
|
||||
store: MemoryAppFontStore(),
|
||||
loader: (family, assets) async {
|
||||
if (fail) throw StateError('offline');
|
||||
},
|
||||
);
|
||||
await fonts.select(AppFont.inter);
|
||||
expect(fonts.family, isNull);
|
||||
expect(fonts.loadFailed, AppFont.inter);
|
||||
expect(fonts.loading, isFalse);
|
||||
fail = false;
|
||||
await fonts.select(AppFont.inter);
|
||||
expect(fonts.loadFailed, isNull);
|
||||
expect(fonts.family, 'Inter');
|
||||
},
|
||||
);
|
||||
|
||||
test('a failed save is reported but the font still applies', () async {
|
||||
final fonts = AppFontController(
|
||||
store: MemoryAppFontStore()..failSaves = true,
|
||||
loader: _Loads().call,
|
||||
);
|
||||
await fonts.select(AppFont.inter);
|
||||
expect(fonts.saveFailed, isTrue);
|
||||
expect(fonts.family, 'Inter');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_font.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_font_store.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
setUp(() => SharedPreferences.setMockInitialValues(<String, Object>{}));
|
||||
|
||||
test('nothing stored is the system default', () async {
|
||||
expect(await const SharedPreferencesAppFontStore().load(), AppFont.system);
|
||||
});
|
||||
|
||||
test(
|
||||
'a choice round-trips under its stable id, on the device only',
|
||||
() async {
|
||||
const store = SharedPreferencesAppFontStore();
|
||||
expect(await store.save(AppFont.ibmPlexSans), isTrue);
|
||||
final preferences = await SharedPreferences.getInstance();
|
||||
expect(preferences.getKeys(), <String>{appFontKey});
|
||||
expect(preferences.getString(appFontKey), 'ibm-plex-sans');
|
||||
expect(await store.load(), AppFont.ibmPlexSans);
|
||||
|
||||
expect(await store.save(AppFont.system), isTrue);
|
||||
expect(await store.load(), AppFont.system);
|
||||
},
|
||||
);
|
||||
|
||||
test('an unknown stored id falls back to the system default', () async {
|
||||
SharedPreferences.setMockInitialValues(<String, Object>{
|
||||
appFontKey: 'comic-sans',
|
||||
});
|
||||
expect(await const SharedPreferencesAppFontStore().load(), AppFont.system);
|
||||
});
|
||||
|
||||
test('every bundled option has its four weights and its licence', () {
|
||||
for (final font in AppFont.values) {
|
||||
if (font == AppFont.system) {
|
||||
expect(font.family, isNull);
|
||||
expect(font.assets, isEmpty);
|
||||
continue;
|
||||
}
|
||||
expect(font.assets, hasLength(4));
|
||||
expect(font.previewAsset, font.assets.first);
|
||||
for (final asset in <String>[...font.assets, font.licenseAsset!]) {
|
||||
expect(File(asset).existsSync(), isTrue, reason: asset);
|
||||
}
|
||||
expect(
|
||||
File(font.licenseAsset!).readAsStringSync(),
|
||||
contains('SIL OPEN FONT LICENSE Version 1.1'),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('the optional fonts are assets, not startup fonts', () {
|
||||
final pubspec = File('pubspec.yaml').readAsStringSync();
|
||||
final fonts = pubspec.substring(pubspec.indexOf('\n fonts:'));
|
||||
for (final font in AppFont.values.where((f) => f.family != null)) {
|
||||
expect(fonts, isNot(contains('family: ${font.family}')));
|
||||
expect(
|
||||
pubspec,
|
||||
contains(' - ${font.licenseAsset!.replaceAll('OFL.txt', '')}\n'),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/app.dart';
|
||||
import 'package:pipelines_app/shell/destination.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_font.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_font_controller.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_font_store.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_theme.dart';
|
||||
|
||||
void main() {
|
||||
test('Material themes take the family and keep sizes and weights', () {
|
||||
for (final build in <ThemeData Function({String? fontFamily})>[
|
||||
appLightTheme,
|
||||
appDarkTheme,
|
||||
]) {
|
||||
final system = build().textTheme;
|
||||
final inter = build(fontFamily: 'Inter').textTheme;
|
||||
expect(build().textTheme.bodyMedium?.fontFamily, isNot('Inter'));
|
||||
for (final (a, b) in <(TextStyle?, TextStyle?)>[
|
||||
(system.bodyMedium, inter.bodyMedium),
|
||||
(system.titleMedium, inter.titleMedium),
|
||||
(system.labelLarge, inter.labelLarge),
|
||||
(system.headlineSmall, inter.headlineSmall),
|
||||
]) {
|
||||
expect(b?.fontFamily, 'Inter');
|
||||
expect(b?.fontSize, a?.fontSize);
|
||||
expect(b?.fontWeight, a?.fontWeight);
|
||||
}
|
||||
expect(
|
||||
build(
|
||||
fontFamily: 'Inter',
|
||||
).cupertinoOverrideTheme?.textTheme?.textStyle.fontFamily,
|
||||
'Inter',
|
||||
);
|
||||
expect(build().cupertinoOverrideTheme, isNull);
|
||||
}
|
||||
});
|
||||
|
||||
test('the Cupertino theme takes the family in every text role', () {
|
||||
expect(appCupertinoThemeWith(), same(appCupertinoTheme));
|
||||
final text = appCupertinoThemeWith(fontFamily: 'Inter').textTheme;
|
||||
const stock = CupertinoTextThemeData();
|
||||
for (final (a, b) in <(TextStyle, TextStyle)>[
|
||||
(stock.textStyle, text.textStyle),
|
||||
(stock.navTitleTextStyle, text.navTitleTextStyle),
|
||||
(stock.navLargeTitleTextStyle, text.navLargeTitleTextStyle),
|
||||
(stock.tabLabelTextStyle, text.tabLabelTextStyle),
|
||||
(stock.actionTextStyle, text.actionTextStyle),
|
||||
(stock.pickerTextStyle, text.pickerTextStyle),
|
||||
]) {
|
||||
expect(b.fontFamily, 'Inter');
|
||||
expect(b.fontSize, a.fontSize);
|
||||
expect(b.fontWeight, a.fontWeight);
|
||||
}
|
||||
expect(
|
||||
appCupertinoThemeWith(fontFamily: 'Inter').scaffoldBackgroundColor,
|
||||
AppColors.background,
|
||||
);
|
||||
});
|
||||
|
||||
for (final cupertino in <bool>[false, true]) {
|
||||
testWidgets('the ${cupertino ? 'Cupertino' : 'Material'} host switches '
|
||||
'font live, without a restart', (tester) async {
|
||||
final fonts = AppFontController(
|
||||
store: MemoryAppFontStore(),
|
||||
loader: (family, assets) async {},
|
||||
);
|
||||
String? family;
|
||||
await tester.pumpWidget(
|
||||
MyApp(
|
||||
cupertino: cupertino,
|
||||
fonts: fonts,
|
||||
destination: AppDestination.settings,
|
||||
destinationBodies: <AppDestination, WidgetBuilder>{
|
||||
AppDestination.settings: (context) => Builder(
|
||||
builder: (context) {
|
||||
family = DefaultTextStyle.of(context).style.fontFamily;
|
||||
return const Text('body');
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
);
|
||||
final before = family;
|
||||
expect(before, isNot('IBM Plex Sans'));
|
||||
await fonts.select(AppFont.ibmPlexSans);
|
||||
await tester.pumpAndSettle();
|
||||
expect(family, 'IBM Plex Sans');
|
||||
await fonts.select(AppFont.system);
|
||||
await tester.pumpAndSettle();
|
||||
expect(family, before);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user