merge(app): land chat sections and create-chat naming and prompts
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
/// Whether a new chat starts with a prompt, and which, for one harness and
|
||||
/// directory: the last choice made there.
|
||||
typedef ChatCreatePrompt = ({bool send, String text});
|
||||
|
||||
abstract interface class ChatCreatePromptStore {
|
||||
Future<ChatCreatePrompt?> read(String backend, String directory);
|
||||
|
||||
Future<void> write(String backend, String directory, ChatCreatePrompt value);
|
||||
}
|
||||
|
||||
class SharedPreferencesChatCreatePromptStore implements ChatCreatePromptStore {
|
||||
const SharedPreferencesChatCreatePromptStore();
|
||||
|
||||
static String _key(String backend, String directory) =>
|
||||
'pipelines.chat.createPrompt.v1.$backend|$directory';
|
||||
|
||||
@override
|
||||
Future<ChatCreatePrompt?> read(String backend, String directory) async {
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final raw = prefs.getString(_key(backend, directory));
|
||||
if (raw == null) return null;
|
||||
final data = jsonDecode(raw);
|
||||
if (data is! Map || data['send'] is! bool || data['text'] is! String) {
|
||||
return null;
|
||||
}
|
||||
return (send: data['send'] as bool, text: data['text'] as String);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> write(
|
||||
String backend,
|
||||
String directory,
|
||||
ChatCreatePrompt value,
|
||||
) async {
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(
|
||||
_key(backend, directory),
|
||||
jsonEncode({'send': value.send, 'text': value.text}),
|
||||
);
|
||||
} catch (_) {
|
||||
// Remembering is a convenience; the chat is still created.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The default chat name: the directory's last folder and the harness, as in
|
||||
/// "Pipelines Codex".
|
||||
String defaultChatName(String directory, String harnessLabel) {
|
||||
final parts = directory
|
||||
.split('/')
|
||||
.where((part) => part.isNotEmpty && part != '~')
|
||||
.toList();
|
||||
final leaf = parts.isEmpty ? 'Home' : parts.last;
|
||||
final folder = leaf.isEmpty
|
||||
? 'Home'
|
||||
: '${leaf[0].toUpperCase()}${leaf.substring(1)}';
|
||||
return '$folder $harnessLabel';
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../../data/chat_create_prompt_store.dart';
|
||||
import '../../data/chat_repository.dart';
|
||||
import '../../domain/chat_commands.dart';
|
||||
import 'chat_adaptive.dart';
|
||||
@@ -39,11 +42,14 @@ Future<JsonMap?> showChatCreateDialog(
|
||||
required String operationId,
|
||||
required Future<JsonMap> Function(ChatDraft draft, String operationId)
|
||||
onSubmit,
|
||||
ChatCreatePromptStore prompts =
|
||||
const SharedPreferencesChatCreatePromptStore(),
|
||||
}) {
|
||||
final dialog = CreateChatDialog(
|
||||
repository: repository,
|
||||
operationId: operationId,
|
||||
onSubmit: onSubmit,
|
||||
prompts: prompts,
|
||||
);
|
||||
return chatControlsStyleOf(context) == ChatControlsStyle.cupertino
|
||||
? showCupertinoDialog<JsonMap>(context: context, builder: (_) => dialog)
|
||||
@@ -56,8 +62,12 @@ class CreateChatDialog extends StatefulWidget {
|
||||
required this.repository,
|
||||
required this.operationId,
|
||||
required this.onSubmit,
|
||||
this.prompts = const SharedPreferencesChatCreatePromptStore(),
|
||||
});
|
||||
|
||||
/// The last first-prompt choice per harness and directory.
|
||||
final ChatCreatePromptStore prompts;
|
||||
|
||||
final ChatRepository repository;
|
||||
final String operationId;
|
||||
final Future<JsonMap> Function(ChatDraft draft, String operationId) onSubmit;
|
||||
@@ -70,6 +80,17 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
|
||||
final _instructions = TextEditingController(
|
||||
text: chatDefaultSessionInstructions,
|
||||
);
|
||||
final _name = TextEditingController();
|
||||
|
||||
/// The name follows the folder and harness until the operator edits it.
|
||||
bool _nameEdited = false;
|
||||
|
||||
/// Whether the new chat starts with the prompt below.
|
||||
bool _sendPrompt = true;
|
||||
|
||||
/// The remembered prompt fills in only until the operator types one.
|
||||
bool _promptEdited = false;
|
||||
int _recall = 0;
|
||||
List<String> _directories = const [];
|
||||
List<String> _backends = const [];
|
||||
String? _directory;
|
||||
@@ -90,6 +111,7 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
|
||||
void dispose() {
|
||||
_attempt++;
|
||||
_instructions.dispose();
|
||||
_name.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -118,6 +140,7 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
|
||||
: _backends.first;
|
||||
_loading = false;
|
||||
});
|
||||
_choiceChanged();
|
||||
} catch (error) {
|
||||
if (!mounted || attempt != _attempt) return;
|
||||
setState(() {
|
||||
@@ -129,23 +152,52 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
|
||||
|
||||
bool get _catalogReady => !_loading && _catalogError == null;
|
||||
|
||||
/// A folder or harness pick: the default name follows it, and the prompt
|
||||
/// choice last made there comes back.
|
||||
Future<void> _choiceChanged() async {
|
||||
final backend = _backend ?? '';
|
||||
final directory = _directory ?? chatHomeDirectory;
|
||||
if (!_nameEdited) {
|
||||
_name.text = defaultChatName(directory, chatBackendLabel(backend));
|
||||
}
|
||||
final recall = ++_recall;
|
||||
final saved = await widget.prompts.read(backend, directory);
|
||||
if (!mounted || recall != _recall) return;
|
||||
if (_promptEdited) return;
|
||||
setState(() {
|
||||
_sendPrompt = saved?.send ?? true;
|
||||
_instructions.text = saved?.text ?? chatDefaultSessionInstructions;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _submit() async {
|
||||
if (!_catalogReady || _submitting) return;
|
||||
final directory = _directory ?? chatHomeDirectory;
|
||||
final backend = _backend ?? '';
|
||||
setState(() {
|
||||
_submitting = true;
|
||||
_formError = null;
|
||||
});
|
||||
try {
|
||||
final name = _name.text.trim();
|
||||
final session = await widget.onSubmit(
|
||||
ChatDraft(
|
||||
title: chatNewSessionTitle,
|
||||
title: name.isEmpty
|
||||
? defaultChatName(directory, chatBackendLabel(backend))
|
||||
: name,
|
||||
directory: directory,
|
||||
backend: _backend ?? '',
|
||||
instructions: _instructions.text,
|
||||
backend: backend,
|
||||
instructions: _sendPrompt ? _instructions.text : '',
|
||||
),
|
||||
widget.operationId,
|
||||
);
|
||||
// Next time in this folder with this harness, the same choice.
|
||||
unawaited(
|
||||
widget.prompts.write(backend, directory, (
|
||||
send: _sendPrompt,
|
||||
text: _instructions.text,
|
||||
)),
|
||||
);
|
||||
if (!mounted) return;
|
||||
Navigator.pop(context, session);
|
||||
} catch (error) {
|
||||
@@ -173,29 +225,70 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
|
||||
backends: _backends,
|
||||
directory: _directory,
|
||||
backend: _backend,
|
||||
onDirectory: (value) => setState(() => _directory = value),
|
||||
onBackend: (value) => setState(() => _backend = value),
|
||||
onDirectory: (value) {
|
||||
setState(() => _directory = value);
|
||||
_choiceChanged();
|
||||
},
|
||||
onBackend: (value) {
|
||||
setState(() => _backend = value);
|
||||
_choiceChanged();
|
||||
},
|
||||
onRetry: _loadCatalog,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Text('How should it act?'),
|
||||
const Text('Name'),
|
||||
const SizedBox(height: 4),
|
||||
if (cupertino)
|
||||
CupertinoTextField(
|
||||
key: const Key('chat-create-instructions'),
|
||||
controller: _instructions,
|
||||
minLines: 2,
|
||||
maxLines: 4,
|
||||
key: const Key('chat-create-name'),
|
||||
controller: _name,
|
||||
onChanged: (_) => _nameEdited = true,
|
||||
)
|
||||
else
|
||||
TextField(
|
||||
key: const Key('chat-create-instructions'),
|
||||
controller: _instructions,
|
||||
minLines: 2,
|
||||
maxLines: 4,
|
||||
key: const Key('chat-create-name'),
|
||||
controller: _name,
|
||||
onChanged: (_) => _nameEdited = true,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
const Text(chatCreateInstructionsHelper),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
const Expanded(child: Text('Start with a prompt')),
|
||||
if (cupertino)
|
||||
CupertinoSwitch(
|
||||
key: const Key('chat-create-send-prompt'),
|
||||
value: _sendPrompt,
|
||||
onChanged: (value) => setState(() => _sendPrompt = value),
|
||||
)
|
||||
else
|
||||
Switch(
|
||||
key: const Key('chat-create-send-prompt'),
|
||||
value: _sendPrompt,
|
||||
onChanged: (value) => setState(() => _sendPrompt = value),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (_sendPrompt) ...[
|
||||
const SizedBox(height: 4),
|
||||
if (cupertino)
|
||||
CupertinoTextField(
|
||||
key: const Key('chat-create-instructions'),
|
||||
controller: _instructions,
|
||||
minLines: 2,
|
||||
maxLines: 4,
|
||||
onChanged: (_) => _promptEdited = true,
|
||||
)
|
||||
else
|
||||
TextField(
|
||||
key: const Key('chat-create-instructions'),
|
||||
controller: _instructions,
|
||||
minLines: 2,
|
||||
maxLines: 4,
|
||||
onChanged: (_) => _promptEdited = true,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
const Text(chatCreateInstructionsHelper),
|
||||
],
|
||||
if (_catalogReady) ...[
|
||||
const SizedBox(height: 8),
|
||||
const Text(chatCreateModelNote),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import '../../../../ui/layout/collapsible_list_section.dart';
|
||||
import '../../../../ui/theme/app_theme.dart';
|
||||
import '../../../../ui/layout/section_heading.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
import '../../../../core/api_gateway.dart';
|
||||
@@ -58,23 +58,32 @@ class CupertinoSessionList extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
List<CupertinoListSection> _section(ChatSessionSection section) {
|
||||
List<Widget> _section(ChatSessionSection section) {
|
||||
final groups = groupChatSessions(section.sessions);
|
||||
// Closed chats start folded away; the live ones start open.
|
||||
return [
|
||||
for (final group in groups)
|
||||
CupertinoListSection.insetGrouped(
|
||||
backgroundColor: AppColors.groupedBackground,
|
||||
// Styled as a section divider, not as another chat row.
|
||||
header: Builder(
|
||||
builder: (context) => Text(
|
||||
groups.length > 1
|
||||
? '${section.title} · ${group.directory.isEmpty ? 'No directory' : group.directory}'
|
||||
: section.title,
|
||||
style: SectionHeadingStyle.of(context).title,
|
||||
CollapsibleListSection(
|
||||
key: ValueKey('chat-section-${section.title}'),
|
||||
title: section.title,
|
||||
count: section.sessions.length,
|
||||
initiallyOpen: section.title != 'Closed',
|
||||
children: [
|
||||
for (final group in groups)
|
||||
CupertinoListSection.insetGrouped(
|
||||
backgroundColor: AppColors.groupedBackground,
|
||||
header: groups.length > 1
|
||||
? Text(
|
||||
group.directory.isEmpty
|
||||
? 'No directory'
|
||||
: group.directory,
|
||||
)
|
||||
: null,
|
||||
children: [
|
||||
for (final session in group.sessions) ..._row(session),
|
||||
],
|
||||
),
|
||||
),
|
||||
children: [for (final session in group.sessions) ..._row(session)],
|
||||
),
|
||||
],
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import '../../../../ui/layout/collapsible_list_section.dart';
|
||||
import '../../../../ui/layout/section_heading.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@@ -63,14 +64,12 @@ class MaterialSessionList extends StatelessWidget {
|
||||
Widget _section(BuildContext context, ChatSessionSection section) {
|
||||
final groups = groupChatSessions(section.sessions);
|
||||
final heading = SectionHeadingStyle.of(context);
|
||||
return ExpansionTile(
|
||||
// Styled as a section divider, not as another chat row.
|
||||
title: Text(section.title, style: heading.title),
|
||||
backgroundColor: heading.background.withValues(alpha: 0.35),
|
||||
collapsedBackgroundColor: heading.background,
|
||||
shape: Border(left: BorderSide(color: heading.accent, width: 3)),
|
||||
collapsedShape: Border(left: BorderSide(color: heading.accent, width: 3)),
|
||||
initiallyExpanded: true,
|
||||
// Closed chats start folded away; the live ones start open.
|
||||
return CollapsibleListSection(
|
||||
key: ValueKey('chat-section-${section.title}'),
|
||||
title: section.title,
|
||||
count: section.sessions.length,
|
||||
initiallyOpen: section.title != 'Closed',
|
||||
children: [
|
||||
for (final group in groups) ...[
|
||||
if (groups.length > 1)
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../adaptive/host.dart';
|
||||
import '../motion/motion.dart';
|
||||
import 'section_heading.dart';
|
||||
|
||||
/// A titled group in a list: a [SectionHeading] strip (bold title, count,
|
||||
/// chevron) that reads as a divider, and opens or closes its rows on a tap.
|
||||
class CollapsibleListSection extends StatefulWidget {
|
||||
const CollapsibleListSection({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.children,
|
||||
this.count,
|
||||
this.initiallyOpen = true,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final int? count;
|
||||
final bool initiallyOpen;
|
||||
final List<Widget> children;
|
||||
|
||||
@override
|
||||
State<CollapsibleListSection> createState() => _CollapsibleListSectionState();
|
||||
}
|
||||
|
||||
class _CollapsibleListSectionState extends State<CollapsibleListSection> {
|
||||
late bool _open = widget.initiallyOpen;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
final muted = cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final heading = Semantics(
|
||||
container: true,
|
||||
header: true,
|
||||
button: true,
|
||||
expanded: _open,
|
||||
label: widget.title,
|
||||
excludeSemantics: true,
|
||||
onTap: _toggle,
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: _toggle,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: SectionHeading(
|
||||
title: widget.title,
|
||||
minHeight: 44,
|
||||
trailing: [
|
||||
if (widget.count != null)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.only(end: 6),
|
||||
child: Text(
|
||||
'${widget.count}',
|
||||
style: TextStyle(color: muted),
|
||||
),
|
||||
),
|
||||
AnimatedRotation(
|
||||
turns: _open ? 0.5 : 0,
|
||||
duration: Motion.of(context, Motion.standard),
|
||||
curve: Motion.curve,
|
||||
child: Icon(
|
||||
cupertino ? CupertinoIcons.chevron_down : Icons.expand_more,
|
||||
color: muted,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(padding: const EdgeInsets.only(top: 8), child: heading),
|
||||
ClipRect(
|
||||
child: AnimatedSize(
|
||||
duration: Motion.of(context, Motion.standard),
|
||||
curve: Motion.curve,
|
||||
alignment: Alignment.topCenter,
|
||||
child: _open
|
||||
? Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: widget.children,
|
||||
)
|
||||
: const SizedBox(width: double.infinity),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _toggle() => setState(() => _open = !_open);
|
||||
}
|
||||
@@ -134,9 +134,7 @@ void main() {
|
||||
|
||||
expect(gateway.sent('chat_rename'), isEmpty);
|
||||
expect(
|
||||
find.text(
|
||||
'Usage: /rename <title> — renames this session.',
|
||||
),
|
||||
find.text('Usage: /rename <title> — renames this session.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -44,28 +44,32 @@ void main() {
|
||||
expect(chatFormAnswerError(fields, {'note': 'ok', 'count': 5}), '');
|
||||
});
|
||||
|
||||
test('integer input becomes an int, including decimal and exponent forms', () {
|
||||
final field = <String, dynamic>{'key': 'count', 'type': 'integer'};
|
||||
expect(chatFormFieldValue(field, '1.0'), isA<int>());
|
||||
expect(chatFormFieldValue(field, '1.0'), 1);
|
||||
expect(chatFormFieldValue(field, '1e3'), 1000);
|
||||
expect(chatFormFieldValue(field, '1.5'), 1.5);
|
||||
expect((chatFormFieldValue(field, 'nope')! as num).isNaN, isTrue);
|
||||
expect(chatFormFieldValue({'type': 'number'}, '1e3'), 1000.0);
|
||||
test(
|
||||
'integer input becomes an int, including decimal and exponent forms',
|
||||
() {
|
||||
final field = <String, dynamic>{'key': 'count', 'type': 'integer'};
|
||||
expect(chatFormFieldValue(field, '1.0'), isA<int>());
|
||||
expect(chatFormFieldValue(field, '1.0'), 1);
|
||||
expect(chatFormFieldValue(field, '1e3'), 1000);
|
||||
expect(chatFormFieldValue(field, '1.5'), 1.5);
|
||||
expect((chatFormFieldValue(field, 'nope')! as num).isNaN, isTrue);
|
||||
expect(chatFormFieldValue({'type': 'number'}, '1e3'), 1000.0);
|
||||
|
||||
final fields = [field];
|
||||
expect(
|
||||
chatVisibleFormAnswers(
|
||||
fields,
|
||||
{'count': chatFormFieldValue(field, '1.0')},
|
||||
),
|
||||
{'count': 1},
|
||||
);
|
||||
expect(
|
||||
chatFormAnswerError(fields, {'count': chatFormFieldValue(field, '1.0')}),
|
||||
'',
|
||||
);
|
||||
});
|
||||
final fields = [field];
|
||||
expect(
|
||||
chatVisibleFormAnswers(fields, {
|
||||
'count': chatFormFieldValue(field, '1.0'),
|
||||
}),
|
||||
{'count': 1},
|
||||
);
|
||||
expect(
|
||||
chatFormAnswerError(fields, {
|
||||
'count': chatFormFieldValue(field, '1.0'),
|
||||
}),
|
||||
'',
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('a malformed pattern is reported with the documented wording', () {
|
||||
final fields = [
|
||||
@@ -84,9 +88,12 @@ void main() {
|
||||
// An unparseable server pattern constrains nothing, like a browser ignoring
|
||||
// an invalid `pattern` attribute.
|
||||
expect(
|
||||
chatFormAnswerError([
|
||||
{'key': 'code', 'type': 'string', 'pattern': '('},
|
||||
], {'code': 'anything'}),
|
||||
chatFormAnswerError(
|
||||
[
|
||||
{'key': 'code', 'type': 'string', 'pattern': '('},
|
||||
],
|
||||
{'code': 'anything'},
|
||||
),
|
||||
'',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -253,9 +253,7 @@ void main() {
|
||||
) async {
|
||||
final semantics = tester.ensureSemantics();
|
||||
await tester.pumpWidget(
|
||||
scrollHost(
|
||||
ChatQuestionCard(form: question(), onSubmit: (_, _) async {}),
|
||||
),
|
||||
scrollHost(ChatQuestionCard(form: question(), onSubmit: (_, _) async {})),
|
||||
);
|
||||
final node = tester.getSemantics(
|
||||
find.byKey(const ValueKey<String>('chat-question-input-note')),
|
||||
@@ -296,65 +294,67 @@ void main() {
|
||||
expect(sent!['count'], isA<int>());
|
||||
});
|
||||
|
||||
testWidgets('decline and cancel send their recorded actions with no answers', (
|
||||
tester,
|
||||
) async {
|
||||
final actions = <String>[];
|
||||
final answers = <Map<String, dynamic>>[];
|
||||
await tester.pumpWidget(
|
||||
scrollHost(
|
||||
ChatQuestionCard(
|
||||
form: question(),
|
||||
onSubmit: (sent, action) async {
|
||||
actions.add(action);
|
||||
answers.add(sent);
|
||||
},
|
||||
testWidgets(
|
||||
'decline and cancel send their recorded actions with no answers',
|
||||
(tester) async {
|
||||
final actions = <String>[];
|
||||
final answers = <Map<String, dynamic>>[];
|
||||
await tester.pumpWidget(
|
||||
scrollHost(
|
||||
ChatQuestionCard(
|
||||
form: question(),
|
||||
onSubmit: (sent, action) async {
|
||||
actions.add(action);
|
||||
answers.add(sent);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Decline'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Cancel question'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(actions, ['decline', 'cancel']);
|
||||
expect(answers, [<String, dynamic>{}, <String, dynamic>{}]);
|
||||
});
|
||||
);
|
||||
await tester.tap(find.text('Decline'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Cancel question'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(actions, ['decline', 'cancel']);
|
||||
expect(answers, [<String, dynamic>{}, <String, dynamic>{}]);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('an all-external form confirms completion without field answers', (
|
||||
tester,
|
||||
) async {
|
||||
Map<String, dynamic>? sent;
|
||||
String? action;
|
||||
await tester.pumpWidget(
|
||||
scrollHost(
|
||||
ChatQuestionCard(
|
||||
form: {
|
||||
'id': 'form-external',
|
||||
'title': 'Open the form',
|
||||
'actions': ['accept'],
|
||||
'fields': [
|
||||
{
|
||||
'key': 'form',
|
||||
'title': 'External form',
|
||||
'type': 'external',
|
||||
'url': 'https://example.com/complete',
|
||||
},
|
||||
],
|
||||
},
|
||||
onSubmit: (answers, next) async {
|
||||
sent = answers;
|
||||
action = next;
|
||||
},
|
||||
testWidgets(
|
||||
'an all-external form confirms completion without field answers',
|
||||
(tester) async {
|
||||
Map<String, dynamic>? sent;
|
||||
String? action;
|
||||
await tester.pumpWidget(
|
||||
scrollHost(
|
||||
ChatQuestionCard(
|
||||
form: {
|
||||
'id': 'form-external',
|
||||
'title': 'Open the form',
|
||||
'actions': ['accept'],
|
||||
'fields': [
|
||||
{
|
||||
'key': 'form',
|
||||
'title': 'External form',
|
||||
'type': 'external',
|
||||
'url': 'https://example.com/complete',
|
||||
},
|
||||
],
|
||||
},
|
||||
onSubmit: (answers, next) async {
|
||||
sent = answers;
|
||||
action = next;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.text('Confirm completion'), findsOneWidget);
|
||||
expect(find.text('https://example.com/complete'), findsOneWidget);
|
||||
await tester.tap(find.text('Confirm completion'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(sent, isEmpty);
|
||||
expect(action, 'accept');
|
||||
});
|
||||
);
|
||||
expect(find.text('Confirm completion'), findsOneWidget);
|
||||
expect(find.text('https://example.com/complete'), findsOneWidget);
|
||||
await tester.tap(find.text('Confirm completion'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(sent, isEmpty);
|
||||
expect(action, 'accept');
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('an unsupported external URL shows the web alert wording', (
|
||||
tester,
|
||||
@@ -405,7 +405,12 @@ void main() {
|
||||
'resolved': true,
|
||||
'answers': {'enabled': true, 'extra': 'kept'},
|
||||
'fields': [
|
||||
{'key': 'enabled', 'title': '', 'description': '', 'type': 'boolean'},
|
||||
{
|
||||
'key': 'enabled',
|
||||
'title': '',
|
||||
'description': '',
|
||||
'type': 'boolean',
|
||||
},
|
||||
],
|
||||
},
|
||||
onSubmit: (_, _) async {},
|
||||
|
||||
@@ -71,10 +71,7 @@ void main() {
|
||||
|
||||
group('arrival count', () {
|
||||
test('counts only messages after the release point', () {
|
||||
expect(
|
||||
chatNewMessageCount(['m1', 'm2', 'm3'], 'm2'),
|
||||
1,
|
||||
);
|
||||
expect(chatNewMessageCount(['m1', 'm2', 'm3'], 'm2'), 1);
|
||||
expect(
|
||||
chatNewMessageCount(['older', 'm1', 'm2', 'live', 'newer'], 'm2'),
|
||||
2,
|
||||
@@ -98,22 +95,13 @@ void main() {
|
||||
|
||||
group('restore', () {
|
||||
test('no saved position lands on the newest end', () {
|
||||
expect(
|
||||
chatRestoreOffset(savedOffset: null, maxScrollExtent: 640),
|
||||
640,
|
||||
);
|
||||
expect(chatRestoreOffset(savedOffset: null, maxScrollExtent: 640), 640);
|
||||
});
|
||||
|
||||
test('a saved position is kept within the current extent', () {
|
||||
expect(
|
||||
chatRestoreOffset(savedOffset: 120, maxScrollExtent: 640),
|
||||
120,
|
||||
);
|
||||
expect(chatRestoreOffset(savedOffset: 120, maxScrollExtent: 640), 120);
|
||||
expect(chatRestoreOffset(savedOffset: 0, maxScrollExtent: 640), 0);
|
||||
expect(
|
||||
chatRestoreOffset(savedOffset: 900, maxScrollExtent: 640),
|
||||
640,
|
||||
);
|
||||
expect(chatRestoreOffset(savedOffset: 900, maxScrollExtent: 640), 640);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -44,15 +44,12 @@ void main() {
|
||||
});
|
||||
await pumpEventQueue();
|
||||
|
||||
expect(controller.permissionFrames, hasLength(ChatThreadCards.settledLimit + 1));
|
||||
expect(
|
||||
controller.permissionFrames.first['request_id'],
|
||||
'req-5',
|
||||
);
|
||||
expect(
|
||||
controller.permissionFrames.last['request_id'],
|
||||
'req-pending',
|
||||
controller.permissionFrames,
|
||||
hasLength(ChatThreadCards.settledLimit + 1),
|
||||
);
|
||||
expect(controller.permissionFrames.first['request_id'], 'req-5');
|
||||
expect(controller.permissionFrames.last['request_id'], 'req-pending');
|
||||
});
|
||||
|
||||
test('settled forms are bounded while the pending one is kept', () async {
|
||||
@@ -75,7 +72,10 @@ void main() {
|
||||
});
|
||||
await pumpEventQueue();
|
||||
|
||||
expect(controller.questionForms, hasLength(ChatThreadCards.settledLimit + 1));
|
||||
expect(
|
||||
controller.questionForms,
|
||||
hasLength(ChatThreadCards.settledLimit + 1),
|
||||
);
|
||||
expect(controller.questionForms.first['id'], 'form-5');
|
||||
expect(controller.questionForms.last['id'], 'form-pending');
|
||||
});
|
||||
|
||||
@@ -35,9 +35,7 @@ JsonMap tallPage() => chatPage([
|
||||
]);
|
||||
|
||||
ScrollController transcriptScroll(WidgetTester tester) =>
|
||||
tester
|
||||
.widget<ListView>(find.byKey(const Key('chat-thread-s')))
|
||||
.controller!;
|
||||
tester.widget<ListView>(find.byKey(const Key('chat-thread-s'))).controller!;
|
||||
|
||||
void main() {
|
||||
testWidgets('a streaming transcript stays pinned to its newest end', (
|
||||
@@ -62,7 +60,9 @@ void main() {
|
||||
|
||||
// A new message and further deltas grow the turn; every frame keeps the
|
||||
// newest end visible without an animation the operator has to chase.
|
||||
gateway.emitEvent(chatTextFrame('One streamed paragraph. ', messageId: 'live'));
|
||||
gateway.emitEvent(
|
||||
chatTextFrame('One streamed paragraph. ', messageId: 'live'),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
gateway.emitEvent(chatTextFrame('And another delta. ', messageId: 'live'));
|
||||
@@ -115,19 +115,15 @@ void main() {
|
||||
// The operator's position is not moved by an arrival; only the
|
||||
// control's count changes.
|
||||
expect(scroll.position.pixels, closeTo(releasedAt, 0.5));
|
||||
expect(
|
||||
find.text('Jump to latest · 1 new message'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Jump to latest · 1 new message'), findsOneWidget);
|
||||
|
||||
gateway.emitEvent(chatTextFrame('A second answer. ', messageId: 'live-2'));
|
||||
gateway.emitEvent(
|
||||
chatTextFrame('A second answer. ', messageId: 'live-2'),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(scroll.position.pixels, closeTo(releasedAt, 0.5));
|
||||
expect(
|
||||
find.text('Jump to latest · 2 new messages'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Jump to latest · 2 new messages'), findsOneWidget);
|
||||
|
||||
if (cupertino) {
|
||||
// The affordance is a standard Cupertino control; no Material
|
||||
|
||||
@@ -184,7 +184,9 @@ void main() {
|
||||
]) {
|
||||
expect(find.text(body), findsOneWidget, reason: body);
|
||||
}
|
||||
Navigator.of(tester.element(find.text('NEWEST folded reasoning body.'))).pop();
|
||||
Navigator.of(
|
||||
tester.element(find.text('NEWEST folded reasoning body.')),
|
||||
).pop();
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.text('Load older'),
|
||||
|
||||
@@ -41,11 +41,7 @@ void main() {
|
||||
expect(draft.add(files!.single.attachment), isNull);
|
||||
expect(
|
||||
draft.attachments.single,
|
||||
const ChatAttachment(
|
||||
name: 'notes.txt',
|
||||
mime: 'text/plain',
|
||||
sizeBytes: 3,
|
||||
),
|
||||
const ChatAttachment(name: 'notes.txt', mime: 'text/plain', sizeBytes: 3),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -66,7 +66,8 @@ void main() {
|
||||
|
||||
final fields =
|
||||
gateway.lastFields('chat_create')!['chat_create']! as JsonMap;
|
||||
expect(fields['title'], 'New chat');
|
||||
// Named after the folder and harness by default.
|
||||
expect(fields['title'], 'Home OpenCode');
|
||||
expect(fields['directory'], '~');
|
||||
expect(fields.containsKey('backend'), isFalse);
|
||||
expect(fields['instructions'], 'Keep me');
|
||||
@@ -169,7 +170,7 @@ void main() {
|
||||
|
||||
final fields =
|
||||
gateway.lastFields('chat_create')!['chat_create']! as JsonMap;
|
||||
expect(fields['title'], 'New chat');
|
||||
expect(fields['title'], 'Archive Codex');
|
||||
expect(fields['directory'], '/archive');
|
||||
expect(fields['backend'], 'codex');
|
||||
expect(fields['instructions'], 'Be careful');
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/data/chat_create_prompt_store.dart';
|
||||
import 'package:pipelines_app/features/chat/data/chat_repository.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/create_chat_dialog.dart';
|
||||
|
||||
import 'fake_chat_gateway.dart';
|
||||
|
||||
class _MemoryPrompts implements ChatCreatePromptStore {
|
||||
final Map<String, ChatCreatePrompt> saved = {};
|
||||
|
||||
@override
|
||||
Future<ChatCreatePrompt?> read(String backend, String directory) async =>
|
||||
saved['$backend|$directory'];
|
||||
|
||||
@override
|
||||
Future<void> write(
|
||||
String backend,
|
||||
String directory,
|
||||
ChatCreatePrompt value,
|
||||
) async => saved['$backend|$directory'] = value;
|
||||
}
|
||||
|
||||
Future<ChatDraft?> _create(
|
||||
WidgetTester tester,
|
||||
_MemoryPrompts prompts, {
|
||||
bool turnOff = false,
|
||||
String? prompt,
|
||||
}) async {
|
||||
ChatDraft? sent;
|
||||
final gateway = FakeChatGateway()
|
||||
..directoriesHandler = () async => {
|
||||
'chat_directories': ['/work/pipelines'],
|
||||
};
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: CreateChatDialog(
|
||||
repository: ChatRepository(gateway),
|
||||
operationId: 'op',
|
||||
prompts: prompts,
|
||||
onSubmit: (draft, _) async {
|
||||
sent = draft;
|
||||
return {'id': 'new'};
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
if (prompt != null) {
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-create-instructions')),
|
||||
prompt,
|
||||
);
|
||||
}
|
||||
if (turnOff) {
|
||||
await tester.tap(find.byKey(const Key('chat-create-send-prompt')));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
await tester.ensureVisible(find.byKey(const Key('chat-create-confirm')));
|
||||
await tester.tap(find.byKey(const Key('chat-create-confirm')));
|
||||
await tester.pumpAndSettle();
|
||||
return sent;
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('the default name is the folder and the harness', () {
|
||||
expect(
|
||||
defaultChatName('/Users/me/repos/pipelines', 'Codex'),
|
||||
'Pipelines Codex',
|
||||
);
|
||||
expect(defaultChatName('~', 'OpenCode'), 'Home OpenCode');
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'a custom prompt is sent and comes back for that harness and folder',
|
||||
(tester) async {
|
||||
final prompts = _MemoryPrompts();
|
||||
final first = await _create(tester, prompts, prompt: 'Review only.');
|
||||
expect(first!.instructions, 'Review only.');
|
||||
expect(prompts.saved.values.single, (send: true, text: 'Review only.'));
|
||||
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
final second = await _create(tester, prompts);
|
||||
expect(second!.instructions, 'Review only.');
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('a chat can start without a prompt, and that is remembered', (
|
||||
tester,
|
||||
) async {
|
||||
final prompts = _MemoryPrompts();
|
||||
final draft = await _create(tester, prompts, turnOff: true);
|
||||
expect(draft!.instructions, isEmpty);
|
||||
expect(prompts.saved.values.single.send, isFalse);
|
||||
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
await _create(tester, prompts);
|
||||
expect(prompts.saved.values.single.send, isFalse);
|
||||
});
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import 'package:pipelines_app/core/api_gateway.dart';
|
||||
|
||||
import 'chat_test_harness.dart';
|
||||
import 'fake_chat_gateway.dart';
|
||||
import 'expand_closed.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('material row star, rename, close confirm and reopen', (
|
||||
@@ -53,6 +54,7 @@ void main() {
|
||||
'chat_query': {'session_id': 's2'},
|
||||
});
|
||||
|
||||
await expandClosedChats(tester);
|
||||
await tester.ensureVisible(find.byKey(const Key('chat-actions-s4')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('chat-actions-s4')));
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dar
|
||||
|
||||
import 'chat_test_harness.dart';
|
||||
import 'fake_chat_gateway.dart';
|
||||
import 'expand_closed.dart';
|
||||
|
||||
/// Long enough that a single ellipsised line would visibly lose the reason.
|
||||
const _refusal =
|
||||
@@ -93,6 +94,7 @@ void main() {
|
||||
closed = true;
|
||||
await tester.tap(find.byKey(const Key('chat-refresh')));
|
||||
await tester.pumpAndSettle();
|
||||
await expandClosedChats(tester);
|
||||
|
||||
expect(find.text('New'), findsNothing);
|
||||
expect(
|
||||
@@ -134,6 +136,7 @@ void main() {
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await expandClosedChats(tester);
|
||||
|
||||
await tester.ensureVisible(find.byKey(const Key('chat-actions-s4')));
|
||||
await tester.tap(find.byKey(const Key('chat-actions-s4')));
|
||||
@@ -185,6 +188,7 @@ void main() {
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await expandClosedChats(tester);
|
||||
|
||||
await tester.ensureVisible(find.byKey(const Key('chat-actions-s4')));
|
||||
await tester.tap(find.byKey(const Key('chat-actions-s4')));
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/session_list_material.dart';
|
||||
import 'expand_closed.dart';
|
||||
|
||||
/// The Android host: a Material grouped list with its native separators.
|
||||
Future<void> _pumpRows(
|
||||
@@ -116,6 +117,7 @@ void main() {
|
||||
'closed_at': '2026-01-01',
|
||||
},
|
||||
], section: 'Closed');
|
||||
await expandClosedChats(tester);
|
||||
|
||||
// The section header also says Closed; the row's trailing word is its own.
|
||||
expect(
|
||||
|
||||
@@ -46,7 +46,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(bodies, hasLength(2));
|
||||
expect(bodies[1]['operation_id'], bodies[0]['operation_id']);
|
||||
expect(bodies[1]['title'], 'New chat');
|
||||
expect(bodies[1]['title'], 'Home OpenCode');
|
||||
expect(find.byKey(const Key('chat-create-instructions')), findsNothing);
|
||||
expect(opened?['id'], 'created');
|
||||
expect(gateway.count('chat_sessions'), greaterThanOrEqualTo(2));
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'chat_test_harness.dart';
|
||||
import 'fake_chat_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart';
|
||||
import 'expand_closed.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('deep-linked active chat is marked read when its row loads', (
|
||||
@@ -64,17 +65,13 @@ void main() {
|
||||
final gateway = FakeChatGateway()
|
||||
..sessionsReply = {'chat_sessions': sampleSessions()};
|
||||
await pumpMaterialChat(tester, gateway);
|
||||
await expandClosedChats(tester);
|
||||
|
||||
expect(find.text('Starred'), findsOneWidget);
|
||||
expect(find.text('Chats'), findsNWidgets(2));
|
||||
// The Closed section header, and each closed row's trailing word.
|
||||
expect(
|
||||
find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is ExpansionTile &&
|
||||
widget.title is Text &&
|
||||
(widget.title as Text).data == 'Closed',
|
||||
),
|
||||
find.byKey(const ValueKey('chat-section-Closed')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
@@ -112,8 +109,10 @@ void main() {
|
||||
// The list has no search field; New chat and Refresh are the actions.
|
||||
expect(find.byType(CupertinoSearchTextField), findsNothing);
|
||||
expect(find.byType(Scaffold), findsNothing);
|
||||
expect(find.text('Chats · /work'), findsOneWidget);
|
||||
expect(find.text('Chats · /else'), findsOneWidget);
|
||||
// Directory groups sit under their section's heading.
|
||||
expect(find.byKey(const ValueKey('chat-section-Chats')), findsOneWidget);
|
||||
expect(find.text('/work'), findsWidgets);
|
||||
expect(find.text('/else'), findsWidgets);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-star-s2')));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -138,6 +137,8 @@ void main() {
|
||||
'chat_rename': {'session_id': 's2', 'title': 'Renamed on Cupertino'},
|
||||
});
|
||||
|
||||
await expandClosedChats(tester);
|
||||
await tester.ensureVisible(find.byKey(const Key('chat-actions-s4')));
|
||||
await tester.tap(find.byKey(const Key('chat-actions-s4')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Reopen'));
|
||||
@@ -198,4 +199,17 @@ void main() {
|
||||
);
|
||||
semantics.dispose();
|
||||
});
|
||||
|
||||
testWidgets('closed chats start folded away behind their heading', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeChatGateway()
|
||||
..sessionsReply = {'chat_sessions': sampleSessions()};
|
||||
await pumpMaterialChat(tester, gateway);
|
||||
expect(find.byKey(const ValueKey('chat-section-Closed')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-row-s4')), findsNothing);
|
||||
expect(find.text('Open chat'), findsOneWidget);
|
||||
await expandClosedChats(tester);
|
||||
expect(find.byKey(const Key('chat-row-s4')), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
/// Closed chats start folded away; opens that section when it is shown.
|
||||
Future<void> expandClosedChats(WidgetTester tester) async {
|
||||
final section = find.byKey(const ValueKey('chat-section-Closed'));
|
||||
if (section.evaluate().isEmpty) return;
|
||||
final heading = find.descendant(of: section, matching: find.text('Closed'));
|
||||
await tester.ensureVisible(heading.first);
|
||||
await tester.tap(heading.first);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
Reference in New Issue
Block a user