// Fixture replies for the new-chat folder picker in the capture probe app // (`search_selection_probe_entry.dart`). They answer `chat_sessions`, // `chat_directories`, `chat_backends` and `list_directory` with server-shaped // bodies over an invented home tree, so `/chat` → New chat → Choose folder can // be rendered and captured without any server. import 'package:pipelines_app/core/api_gateway.dart'; const probeHome = '/home/operator'; JsonMap _entry( String parent, String name, { bool dir = true, bool git = false, }) => { 'name': name, 'path': '$parent/$name', 'is_dir': dir, 'is_git_repo': git, 'hidden': name.startsWith('.'), }; final Map> _tree = { probeHome: [ for (final name in ['.cache', '.config', '.ssh']) _entry(probeHome, name), _entry(probeHome, 'Desktop'), _entry(probeHome, 'Documents'), _entry(probeHome, 'Downloads'), _entry(probeHome, 'notes', git: true), _entry(probeHome, 'Private'), _entry(probeHome, 'repos'), _entry(probeHome, '.zshrc', dir: false), _entry(probeHome, 'todo.md', dir: false), ], '$probeHome/repos': [ _entry('$probeHome/repos', 'dotfiles', git: true), _entry('$probeHome/repos', 'pipelines', git: true), _entry('$probeHome/repos', 'scratch'), _entry('$probeHome/repos', 'website', git: true), _entry('$probeHome/repos', 'README.txt', dir: false), ], '$probeHome/repos/pipelines': [ for (final name in ['.git', '.github']) _entry('$probeHome/repos/pipelines', name), for (final name in ['app', 'cmd', 'docs', 'internal', 'web']) _entry('$probeHome/repos/pipelines', name), for (final name in ['AGENTS.md', 'go.mod', 'README.md']) _entry('$probeHome/repos/pipelines', name, dir: false), ], }; /// The reply for a folder-picker request, or null when [request] is not one. JsonMap? probeFolderReply(JsonMap request) { final id = request['id']; switch ('${request['type']}') { case 'chat_sessions': return {'id': id, 'type': 'chat_sessions', 'chat_sessions': const []}; case 'chat_directories': return { 'id': id, 'type': 'chat_directories', 'chat_directories': [probeHome, '$probeHome/repos/pipelines'], }; case 'chat_backends': return { 'id': id, 'type': 'chat_backends', 'chat_backends': ['opencode', 'claude', 'codex'], }; case 'list_directory': final body = request['list_directory']; final requested = body is Map ? body['path'] as String? : null; final path = requested == null || requested == '~' ? probeHome : requested; final entries = _tree[path]; if (path == '$probeHome/Private') { return {'id': id, 'type': 'error', 'error': 'permission denied: $path'}; } if (path != probeHome && !path.startsWith('$probeHome/')) { return { 'id': id, 'type': 'error', 'error': 'path $path is outside the home directory $probeHome; only ' 'folders inside home can be listed', }; } return { 'id': id, 'type': 'directory_listing', 'directory_listing': { 'path': path, 'home': probeHome, 'parent': path == probeHome ? null : path.substring(0, path.lastIndexOf('/')), 'entries': entries ?? const [], }, }; } return null; }