Files
pipelines/app/tool/chat_sessions_probe_entry.dart
alan 13a5e1dee0 Remove Cupertino branches from probe fixtures
Keep the chat and graph fixtures aligned with the app's Material-only UI by removing alternate Cupertino hosts, imports, and query-controlled rendering paths. Preserve the existing Material scenarios and document the focused probe coverage.
2026-11-11 20:08:06 +00:00

152 lines
4.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/core/transport/connection_state.dart';
import 'package:pipelines_app/features/chat/session_screen.dart';
/// Stateful chat-session fixture for the real-browser probe: every accepted
/// mutation changes the list the next `chat_sessions` read returns, so the
/// screen must refresh from the server rather than guess. A title of
/// `Refused title` is refused with the server's words; the first create returns
/// a reply without `chat_session`; `?unseen=1` reports newer recency after the
/// first read so the `New` marker can be observed.
class _FixtureGateway implements ApiGateway {
_FixtureGateway({this.bumpAfterFirstRead = false});
/// `?unseen=1`: the first list read seeds the device watermark and later
/// reads report newer activity, so the browser can prove the `New` marker.
final bool bumpAfterFirstRead;
int _reads = 0;
int _creates = 0;
final _sessions = <JsonMap>[
{
'id': 'probe-open',
'title': 'Open fixture',
'directory': '/workspace/demo',
'starred': true,
},
{
'id': 'probe-closed',
'title': 'Closed fixture',
'directory': '/workspace/archive',
'closed_at': '2026-01-01',
},
{
'id': 'probe-stream',
'title': 'Streaming fixture',
'directory': '/workspace/demo',
'running': true,
},
];
int _nextId = 1;
@override
Stream<JsonMap> get frames => const Stream.empty();
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
switch (type) {
case 'chat_sessions':
_reads++;
return {
'chat_sessions': [for (final session in _sessions) _row(session)],
};
case 'chat_directories':
return {
'chat_directories': [
'/workspace/demo',
'/workspace/archive',
'/home/user/project',
],
};
case 'chat_backends':
return {
'chat_backends': ['opencode', 'codex'],
};
case 'chat_create':
final body = fields['chat_create']! as JsonMap;
// Exercise the missing-session refusal independently of the fixed
// title the create dialog now submits.
if (_creates++ == 0) return const {};
final session = {
'id': 'probe-new-${_nextId++}',
'title': body['title'],
'directory': body['directory'],
};
_sessions.insert(0, session);
return {'chat_session': Map<String, dynamic>.from(session)};
case 'chat_rename':
final body = fields['chat_rename']! as JsonMap;
if ('${body['title']}' == 'Refused title') {
throw const ProtocolError('a title with usable text is required');
}
_update('${body['session_id']}', 'title', body['title']);
return const {};
case 'chat_star':
final body = fields['chat_query']! as JsonMap;
_update('${body['session_id']}', 'starred', body['starred']);
return const {};
case 'chat_close':
final body = fields['chat_query']! as JsonMap;
_update('${body['session_id']}', 'closed_at', '2026-01-02');
return const {};
case 'chat_reopen':
final body = fields['chat_query']! as JsonMap;
// A refusal long enough to need several lines at 320px with 2x text.
if ('${body['session_id']}' == 'probe-closed') {
throw const ProtocolError(
'the chat is locked by another operator and cannot be reopened '
'from here; refresh the list to see its current state',
);
}
_update('${body['session_id']}', 'closed_at', null);
return const {};
default:
return {'chat_session': {}};
}
}
void _update(String id, String key, Object? value) {
for (final session in _sessions) {
if (session['id'] == id) session[key] = value;
}
}
JsonMap _row(JsonMap session) {
final row = Map<String, dynamic>.from(session);
if (bumpAfterFirstRead &&
(row['id'] == 'probe-open' || row['id'] == 'probe-closed')) {
row['updated_at'] = _reads > 1 ? 2000 : 1000;
}
return row;
}
}
void main() {
final dark = Uri.base.queryParameters['dark'] == '1';
final unseen = Uri.base.queryParameters['unseen'] == '1';
final gateway = _FixtureGateway(bumpAfterFirstRead: unseen);
// `?many=1` adds enough chats to scroll the list behind the bar.
if (Uri.base.queryParameters['many'] == '1') {
gateway._sessions.addAll([
for (var i = 0; i < 24; i++)
{
'id': 'probe-many-$i',
'title': 'Fixture chat ${i + 1}',
'directory': '/workspace/demo',
},
]);
}
final home = ChatSessionsScreen(gateway: gateway, onOpen: (_) {});
runApp(
MaterialApp(
theme: ThemeData(
platform: TargetPlatform.android,
brightness: dark ? Brightness.dark : Brightness.light,
),
home: home,
),
);
}