Chat info: Session section with native id, resume command and export
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).
This commit is contained in:
@@ -39,6 +39,17 @@ Future<FakeChatGateway> _thread(
|
||||
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();
|
||||
@@ -109,7 +120,7 @@ void main() {
|
||||
|
||||
await _openInfo(tester);
|
||||
|
||||
expect(find.text('Unavailable'), findsNWidgets(4));
|
||||
expect(_metricUnavailable, findsNWidgets(4));
|
||||
expect(find.text('0'), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-info-close')));
|
||||
@@ -128,7 +139,7 @@ void main() {
|
||||
await tester.pump();
|
||||
await _openInfo(tester);
|
||||
|
||||
expect(find.text('Unavailable'), findsNothing);
|
||||
expect(_metricUnavailable, findsNothing);
|
||||
expect(find.text('0 tok/s'), findsOneWidget);
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
expect(find.text('0 / 1,000'), findsOneWidget);
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
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/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/artifacts/actions/artifact_file.dart';
|
||||
import 'package:pipelines_app/features/artifacts/actions/artifact_file_bridge.dart';
|
||||
import 'package:pipelines_app/features/artifacts/actions/artifact_transfer.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_session_handoff.dart';
|
||||
|
||||
import 'chat_thread_fixtures.dart';
|
||||
|
||||
const _id = '0b6f1c2e-1111-4222-8333-444455556666';
|
||||
const _resume = 'cd /work/app && claude --resume $_id';
|
||||
|
||||
JsonMap _row({String backend = 'claude', bool native = true}) => {
|
||||
'id': _id,
|
||||
'title': 'Fix tests',
|
||||
'backend': backend,
|
||||
'directory': '/work/app',
|
||||
'resume_command': _resume,
|
||||
'native_export': native,
|
||||
};
|
||||
|
||||
/// Answers chat_export with a fixed file; everything else as the thread fake.
|
||||
class _ExportGateway extends FakeChatGateway {
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
if (type != 'chat_export') return super.call(type, fields);
|
||||
calls.add((type: type, fields: fields));
|
||||
final format = fields['chat_export']['format'];
|
||||
return {
|
||||
'type': 'chat_export',
|
||||
'chat_export_file': {
|
||||
'session_id': _id,
|
||||
'format': format,
|
||||
'name': format == 'json' ? 'Fix-tests.json' : 'Fix-tests.md',
|
||||
'mime': format == 'json' ? 'application/json' : 'text/markdown',
|
||||
'content': '# Fix tests\n',
|
||||
'messages': 1,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Widget _host(Widget child, bool cupertino) => cupertino
|
||||
? CupertinoApp(
|
||||
theme: const CupertinoThemeData(brightness: Brightness.light),
|
||||
home: CupertinoPageScaffold(child: child),
|
||||
)
|
||||
: MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
|
||||
Future<
|
||||
({_ExportGateway gateway, List<ArtifactFile> shared, List<String> clipboard})
|
||||
>
|
||||
_open(WidgetTester tester, {required bool cupertino, JsonMap? row}) async {
|
||||
tester.view.physicalSize = const Size(800, 2400);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final clipboard = <String>[];
|
||||
final messenger =
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
||||
messenger.setMockMethodCallHandler(SystemChannels.platform, (call) async {
|
||||
if (call.method == 'Clipboard.setData') {
|
||||
clipboard.add('${(call.arguments as Map)['text']}');
|
||||
}
|
||||
return null;
|
||||
});
|
||||
addTearDown(
|
||||
() => messenger.setMockMethodCallHandler(SystemChannels.platform, null),
|
||||
);
|
||||
final gateway = _ExportGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async => chatPage([]);
|
||||
final shared = <ArtifactFile>[];
|
||||
final bridge = ArtifactFileBridge(
|
||||
shareSupported: true,
|
||||
downloadSupported: true,
|
||||
share: (file) async {
|
||||
shared.add(file);
|
||||
return const ArtifactTransferResult(ArtifactTransferState.shared, '');
|
||||
},
|
||||
download: (file) async {
|
||||
shared.add(file);
|
||||
return const ArtifactTransferResult(ArtifactTransferState.saved, '');
|
||||
},
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ChatThreadView(
|
||||
gateway: gateway,
|
||||
sessionId: _id,
|
||||
session: row ?? _row(),
|
||||
onBack: () {},
|
||||
fileBridge: bridge,
|
||||
),
|
||||
cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('chat-info')));
|
||||
await tester.pumpAndSettle();
|
||||
return (gateway: gateway, shared: shared, clipboard: clipboard);
|
||||
}
|
||||
|
||||
Future<void> _tap(WidgetTester tester, Key key) async {
|
||||
await tester.ensureVisible(find.byKey(key));
|
||||
await tester.tap(find.byKey(key));
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'cupertino' : 'material';
|
||||
|
||||
testWidgets('$host: shows the native id, harness and directory', (
|
||||
tester,
|
||||
) async {
|
||||
await _open(tester, cupertino: cupertino);
|
||||
expect(find.text('Session'), findsOneWidget);
|
||||
expect(find.text('Session ID'), findsOneWidget);
|
||||
expect(find.text(_id), findsOneWidget);
|
||||
expect(find.text('Claude'), findsOneWidget);
|
||||
expect(find.text('/work/app'), findsOneWidget);
|
||||
expect(find.text(_resume), findsOneWidget);
|
||||
expect(find.text('Export native session'), findsOneWidget);
|
||||
expect(find.bySemanticsLabel('Copy session ID'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('$host: copies the id and the resume command', (tester) async {
|
||||
final opened = await _open(tester, cupertino: cupertino);
|
||||
await _tap(tester, const Key('chat-session-copy-id'));
|
||||
expect(opened.clipboard, [_id]);
|
||||
expect(find.text('Copied'), findsOneWidget);
|
||||
await _tap(tester, const Key('chat-session-copy-resume'));
|
||||
expect(opened.clipboard, [_id, _resume]);
|
||||
await tester.pump(const Duration(seconds: 3));
|
||||
expect(find.text('Copied'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('$host: export hands the server file to the file action', (
|
||||
tester,
|
||||
) async {
|
||||
final opened = await _open(tester, cupertino: cupertino);
|
||||
await _tap(tester, const Key('chat-session-export-markdown'));
|
||||
await tester.pumpAndSettle();
|
||||
final request = opened.gateway.calls.lastWhere(
|
||||
(call) => call.type == 'chat_export',
|
||||
);
|
||||
expect(request.fields['chat_export'], {
|
||||
'session_id': _id,
|
||||
'format': 'markdown',
|
||||
});
|
||||
expect(opened.shared, hasLength(1));
|
||||
final file = opened.shared.single;
|
||||
expect(file.name, 'Fix-tests.md');
|
||||
expect(file.mimeType, 'text/markdown');
|
||||
expect(utf8.decode(file.bytes), '# Fix tests\n');
|
||||
expect(find.text('Shared Fix-tests.md.'), findsOneWidget);
|
||||
|
||||
await _tap(tester, const Key('chat-session-export-json'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(opened.shared.last.name, 'Fix-tests.json');
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('no native export or resume command when the row has none', (
|
||||
tester,
|
||||
) async {
|
||||
await _open(
|
||||
tester,
|
||||
cupertino: false,
|
||||
row: {'id': _id, 'directory': '/work/app'},
|
||||
);
|
||||
expect(find.text('OpenCode'), findsOneWidget);
|
||||
expect(find.text('Export native session'), findsNothing);
|
||||
expect(find.text('Copy resume command'), findsNothing);
|
||||
expect(find.text('Export conversation'), findsOneWidget);
|
||||
});
|
||||
|
||||
test('a conversation opened by id alone keeps the id', () {
|
||||
final handoff = ChatSessionHandoff.from('ses_abc', null);
|
||||
expect(handoff.id, 'ses_abc');
|
||||
expect(handoff.backend, '');
|
||||
expect(handoff.resumeCommand, '');
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user