feat(app): new chats are named after folder and harness; the first prompt is optional and remembered per harness and folder
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user