Add a home-restricted folder picker to the new-chat dialog

Server: list_directory returns a directory_listing (path, home, parent,
entries with is_dir/is_git_repo/hidden, truncated) confined to the server
user's home subtree after cleaning and resolving symlinks, refusing pseudo
filesystems and capping entries at 2000. Documented in docs/cli.md.

App: "Choose folder…" in the create dialog opens a picker (full-screen page
on phones, large dialog on wide windows, Material and Cupertino) with
breadcrumbs, filter, Show hidden, git badges, dimmed files, recent folders,
inline errors and "Start chat here". The probe app gains a folder fixture
for captures.
This commit is contained in:
2026-11-01 21:51:48 +00:00
parent eadd017bdc
commit eed3806efb
25 changed files with 2333 additions and 9 deletions
@@ -0,0 +1,88 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import '../folder_picker/fake_directory_gateway.dart';
import 'chat_test_harness.dart';
import 'fake_chat_gateway.dart';
/// A chat gateway whose `list_directory` answers come from the fake home tree.
FakeChatGateway _gateway(FakeDirectoryGateway directories) {
final gateway = FakeChatGateway();
gateway.directoriesHandler = () async => {
'chat_directories': [fakeHome, '$fakeHome/projects/app', '/srv/other'],
};
gateway.actionHandler = (type, fields) => directories.call(type, fields);
return gateway;
}
void main() {
final hosts = <String, Future<void> Function(WidgetTester, FakeChatGateway)>{
'material': (tester, gateway) => pumpMaterialChat(tester, gateway),
'cupertino': (tester, gateway) => pumpCupertinoChat(tester, gateway),
'ios material': (tester, gateway) => pumpIosMaterialChat(tester, gateway),
};
for (final MapEntry(key: name, value: pump) in hosts.entries) {
testWidgets('$name: Choose folder fills the directory and creates there', (
tester,
) async {
usePhoneSurface(tester);
final directories = FakeDirectoryGateway();
final gateway = _gateway(directories);
await pump(tester, gateway);
await tester.tap(find.byKey(const Key('chat-new-chat')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-create-choose-folder')));
await tester.pumpAndSettle();
// Opened at home (the dialog's current choice is ~) with the recent
// folder inside home offered first.
expect(directories.requests, [null]);
expect(find.text('Recent folders'), findsOneWidget);
expect(find.text('~/projects/app'), findsOneWidget);
expect(find.text('/srv/other'), findsNothing);
await tester.tap(find.text('projects'));
await tester.pumpAndSettle();
await tester.tap(find.text('web'));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('folder-picker-start')));
await tester.pumpAndSettle();
expect(find.text('Choose folder'), findsNothing);
expect(find.text('Start in $fakeHome/projects/web'), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-create-confirm')));
await tester.pumpAndSettle();
final fields =
gateway.lastFields('chat_create')!['chat_create']! as JsonMap;
expect(fields['directory'], '$fakeHome/projects/web');
expect(fields['title'], 'Web OpenCode');
});
}
testWidgets('the picker reopens at the chosen folder; cancel keeps it', (
tester,
) async {
usePhoneSurface(tester);
final directories = FakeDirectoryGateway();
final gateway = _gateway(directories);
await pumpMaterialChat(tester, gateway);
await tester.tap(find.byKey(const Key('chat-new-chat')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-create-choose-folder')));
await tester.pumpAndSettle();
await tester.tap(find.text('src'));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('folder-picker-start')));
await tester.pumpAndSettle();
expect(find.text('Start in $fakeHome/src'), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-create-choose-folder')));
await tester.pumpAndSettle();
expect(directories.requests.last, '$fakeHome/src');
await tester.tap(find.text('Cancel').last);
await tester.pumpAndSettle();
expect(find.text('Start in $fakeHome/src'), findsOneWidget);
});
}