1de74f76bb
The chat information sheet gains a Session section: the harness's native session id (copy), harness, directory, a verified resume command (copy) and Export conversation (Markdown), Export JSON and, for Claude Code, Export native session (the JSONL transcript). Server: chat_sessions rows carry resume_command and native_export; new chat_export command builds Markdown/JSON from the same paged history chat_messages serves (bounded at 8 MiB), refuses non-operator sessions. App: exports go through the artifact file bridge (web download, share sheet on phones).
192 lines
6.0 KiB
Dart
192 lines
6.0 KiB
Dart
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_thread_view.dart';
|
|
|
|
import 'chat_thread_fixtures.dart';
|
|
|
|
Widget _host(Widget child) => MaterialApp(
|
|
theme: ThemeData(platform: TargetPlatform.android),
|
|
home: Scaffold(body: child),
|
|
);
|
|
|
|
Widget _cupertinoHost(Widget child) => CupertinoApp(
|
|
theme: const CupertinoThemeData(brightness: Brightness.dark),
|
|
home: CupertinoPageScaffold(child: child),
|
|
);
|
|
|
|
JsonMap _usageFrame(JsonMap usage) => {
|
|
'session_id': 's',
|
|
'kind': 'usage',
|
|
'usage': usage,
|
|
};
|
|
|
|
Future<FakeChatGateway> _thread(
|
|
WidgetTester tester, {
|
|
bool cupertino = false,
|
|
}) async {
|
|
final gateway = FakeChatGateway();
|
|
addTearDown(gateway.close);
|
|
gateway.history = (_) async => chatPage([]);
|
|
final thread = ChatThreadView(
|
|
gateway: gateway,
|
|
sessionId: 's',
|
|
onBack: () {},
|
|
);
|
|
await tester.pumpWidget(cupertino ? _cupertinoHost(thread) : _host(thread));
|
|
await tester.pumpAndSettle();
|
|
return gateway;
|
|
}
|
|
|
|
/// "Unavailable" inside the usage metric rows only; the Session section says
|
|
/// it too for a conversation opened without its list row.
|
|
final _metricUnavailable = find.descendant(
|
|
of: find.byWidgetPredicate(
|
|
(widget) =>
|
|
widget.key is ValueKey<String> &&
|
|
(widget.key! as ValueKey<String>).value.startsWith('chat-info-metric-'),
|
|
),
|
|
matching: find.text('Unavailable'),
|
|
);
|
|
|
|
Future<void> _openInfo(WidgetTester tester) async {
|
|
await tester.tap(find.byKey(const Key('chat-info')));
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('reports the recorded facts with the web labels', (tester) async {
|
|
final gateway = await _thread(tester);
|
|
gateway.emitEvent(
|
|
_usageFrame({
|
|
'scope': 'session',
|
|
'total_tokens': 132408,
|
|
'context_tokens': 42000,
|
|
'context_window': 200000,
|
|
'cost_usd': 0.1423,
|
|
'output_tokens_per_second': 24.6,
|
|
'rate_basis': 'generation',
|
|
}),
|
|
);
|
|
await tester.pump();
|
|
|
|
await _openInfo(tester);
|
|
|
|
expect(find.text('Chat information'), findsOneWidget);
|
|
expect(find.text('Done'), findsOneWidget);
|
|
expect(find.text('Output rate'), findsOneWidget);
|
|
expect(find.text('24.6 tok/s'), findsOneWidget);
|
|
expect(find.text('Total tokens'), findsOneWidget);
|
|
expect(find.text('132,408'), findsOneWidget);
|
|
expect(find.text('Context'), findsOneWidget);
|
|
expect(find.text('42,000 / 200,000'), findsOneWidget);
|
|
expect(find.text('Reported cost'), findsOneWidget);
|
|
expect(find.text('\$0.1423'), findsOneWidget);
|
|
expect(
|
|
find.text(
|
|
'Last reported by the harness. '
|
|
'Unavailable values are not estimated.',
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
|
|
// A snapshot that arrives while the panel is open replaces the shown one.
|
|
gateway.emitEvent(
|
|
_usageFrame({
|
|
'scope': 'turn',
|
|
'total_tokens': 133000,
|
|
'context_tokens': 3000,
|
|
'context_window': 200000,
|
|
'cost_usd': 0.2,
|
|
'output_tokens_per_second': 10,
|
|
'rate_basis': 'turn',
|
|
}),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('Turn tokens'), findsOneWidget);
|
|
expect(find.text('133,000'), findsOneWidget);
|
|
expect(find.text('Avg output rate'), findsOneWidget);
|
|
expect(find.text('10 tok/s'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('unknown facts say Unavailable while reported zeros stay zero', (
|
|
tester,
|
|
) async {
|
|
final gateway = await _thread(tester);
|
|
gateway.emitEvent(_usageFrame({'scope': 'session'}));
|
|
await tester.pump();
|
|
|
|
await _openInfo(tester);
|
|
|
|
expect(_metricUnavailable, findsNWidgets(4));
|
|
expect(find.text('0'), findsNothing);
|
|
|
|
await tester.tap(find.byKey(const Key('chat-info-close')));
|
|
await tester.pumpAndSettle();
|
|
|
|
gateway.emitEvent(
|
|
_usageFrame({
|
|
'scope': 'session',
|
|
'total_tokens': 0,
|
|
'context_tokens': 0,
|
|
'context_window': 1000,
|
|
'cost_usd': 0,
|
|
'output_tokens_per_second': 0,
|
|
}),
|
|
);
|
|
await tester.pump();
|
|
await _openInfo(tester);
|
|
|
|
expect(_metricUnavailable, findsNothing);
|
|
expect(find.text('0 tok/s'), findsOneWidget);
|
|
expect(find.text('0'), findsOneWidget);
|
|
expect(find.text('0 / 1,000'), findsOneWidget);
|
|
expect(find.text('\$0.0000'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('the native sheet dismisses from Done and the barrier', (
|
|
tester,
|
|
) async {
|
|
final gateway = await _thread(tester);
|
|
gateway.emitEvent(_usageFrame({'scope': 'session', 'total_tokens': 5}));
|
|
await tester.pump();
|
|
|
|
await _openInfo(tester);
|
|
expect(find.byKey(const Key('chat-info-sheet')), findsOneWidget);
|
|
|
|
await tester.tap(find.byKey(const Key('chat-info-close')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('chat-info-sheet')), findsNothing);
|
|
expect(find.byKey(const Key('chat-info')), findsOneWidget);
|
|
|
|
await _openInfo(tester);
|
|
expect(find.byKey(const Key('chat-info-sheet')), findsOneWidget);
|
|
|
|
// The modal barrier above the sheet is the platform's dismiss target.
|
|
await tester.tapAt(const Offset(8, 8));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('chat-info-sheet')), findsNothing);
|
|
expect(find.byKey(const Key('chat-info')), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('the Cupertino host opens and closes the native popup', (
|
|
tester,
|
|
) async {
|
|
final gateway = await _thread(tester, cupertino: true);
|
|
gateway.emitEvent(_usageFrame({'scope': 'session', 'total_tokens': 42}));
|
|
await tester.pump();
|
|
|
|
await _openInfo(tester);
|
|
expect(find.text('Chat information'), findsOneWidget);
|
|
expect(find.text('Done'), findsOneWidget);
|
|
expect(find.text('42'), findsOneWidget);
|
|
|
|
await tester.tap(find.byKey(const Key('chat-info-close')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('chat-info-sheet')), findsNothing);
|
|
expect(find.byKey(const Key('chat-info')), findsOneWidget);
|
|
});
|
|
}
|