191 lines
4.9 KiB
Dart
191 lines
4.9 KiB
Dart
// Web-only fixture entrypoint for rendered search evidence. It is not part of
|
|
// the application's `main.dart`; build it explicitly with:
|
|
// flutter build web -t tool/search_fixture/main.dart
|
|
// `?cupertino=1` renders the same screen inside a CupertinoApp.
|
|
import 'dart:convert';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
import 'package:pipelines_app/features/search/search_screen.dart';
|
|
|
|
void main() {
|
|
final cupertino = Uri.base.queryParameters['cupertino'] == '1';
|
|
runApp(
|
|
cupertino
|
|
? const CupertinoApp(
|
|
title: 'Search fixture',
|
|
home: _FixtureHost(cupertino: true),
|
|
)
|
|
: const MaterialApp(
|
|
title: 'Search fixture',
|
|
home: _FixtureHost(cupertino: false),
|
|
),
|
|
);
|
|
}
|
|
|
|
class _FixtureHost extends StatelessWidget {
|
|
const _FixtureHost({required this.cupertino});
|
|
|
|
final bool cupertino;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => SearchScreen(
|
|
gateway: const _FixtureGateway(),
|
|
cupertino: cupertino,
|
|
onOpen: (hit) {
|
|
final route = cupertino
|
|
? CupertinoPageRoute<void>(
|
|
builder: (_) => _Opened(hit: hit, cupertino: true),
|
|
)
|
|
: MaterialPageRoute<void>(
|
|
builder: (_) => _Opened(hit: hit, cupertino: false),
|
|
);
|
|
Navigator.of(context).push(route);
|
|
},
|
|
);
|
|
}
|
|
|
|
class _Opened extends StatelessWidget {
|
|
const _Opened({required this.hit, required this.cupertino});
|
|
|
|
final JsonMap hit;
|
|
final bool cupertino;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final body = Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(24),
|
|
child: Text(
|
|
'Opened ${hit['kind']} target: ${hit['target']}',
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
);
|
|
if (cupertino) {
|
|
return CupertinoPageScaffold(
|
|
navigationBar: const CupertinoNavigationBar(middle: Text('Opened')),
|
|
child: body,
|
|
);
|
|
}
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Opened')),
|
|
body: body,
|
|
);
|
|
}
|
|
}
|
|
|
|
class _FixtureGateway implements ApiGateway {
|
|
const _FixtureGateway();
|
|
|
|
@override
|
|
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
|
if (type != 'search') throw StateError('unexpected request: $type');
|
|
final request = Map<String, dynamic>.from(fields['search'] as Map);
|
|
final query = '${request['query'] ?? ''}'.trim().toLowerCase();
|
|
final kind = '${request['kind'] ?? ''}';
|
|
await Future<void>.delayed(const Duration(milliseconds: 180));
|
|
var hits = _fixtureHits
|
|
.where((hit) {
|
|
if (kind.isNotEmpty && hit['kind'] != kind) return false;
|
|
if (query.isEmpty) return true;
|
|
return jsonEncode(hit).toLowerCase().contains(query);
|
|
})
|
|
.toList(growable: false);
|
|
return {
|
|
'search_results': {
|
|
'query': request['query'],
|
|
'kind': kind,
|
|
'results': hits,
|
|
'truncated': true,
|
|
'scanned_steps': 2000,
|
|
'scanned_bytes': 1048576,
|
|
'cap': 50,
|
|
'scan_bound_bytes': 1048576,
|
|
},
|
|
};
|
|
}
|
|
|
|
@override
|
|
Stream<JsonMap> get frames => const Stream.empty();
|
|
}
|
|
|
|
const _fixtureHits = <JsonMap>[
|
|
{
|
|
'kind': 'pipeline',
|
|
'target': 'pipeline:24',
|
|
'score': 3,
|
|
'recency': '2026-10-20T09:18:00Z',
|
|
'pipeline': {'id': 24, 'name': 'Plan and land', 'version': 5, 'stages': 4},
|
|
},
|
|
{
|
|
'kind': 'run',
|
|
'target': 'run:457',
|
|
'score': 2,
|
|
'recency': '2026-10-20T08:42:00Z',
|
|
'run': {
|
|
'id': 457,
|
|
'pipeline_name': 'Plan and land',
|
|
'status': 'succeeded',
|
|
'workspace': '/home/user/project',
|
|
'created_at': '2026-10-20T08:12:00Z',
|
|
'finished_at': '2026-10-20T08:42:00Z',
|
|
},
|
|
},
|
|
{
|
|
'kind': 'field',
|
|
'target': 'run:457:3:input',
|
|
'score': 1,
|
|
'matched_field': 'input',
|
|
'recency': '2026-10-20T08:20:00Z',
|
|
'field': {
|
|
'run_id': 457,
|
|
'sequence': 3,
|
|
'field': 'input',
|
|
'snippet': 'Plan the change before implementing it',
|
|
},
|
|
},
|
|
{
|
|
'kind': 'artifact',
|
|
'target': '/artifacts/457/2/plan.md',
|
|
'score': 1,
|
|
'recency': '2026-10-20T08:24:00Z',
|
|
'artifact': {
|
|
'run_id': 457,
|
|
'sequence': 2,
|
|
'name': 'plan.md',
|
|
'content_type': 'text/markdown',
|
|
'size_bytes': 2048,
|
|
'url': '/artifacts/457/2/plan.md',
|
|
},
|
|
},
|
|
{
|
|
'kind': 'version',
|
|
'target': 'pipeline:22:v6',
|
|
'score': 2,
|
|
'recency': '2026-10-18T16:05:00Z',
|
|
'version': {
|
|
'pipeline_id': 22,
|
|
'version': 6,
|
|
'content_hash': '9f2c1ad',
|
|
'created_at': '2026-10-18T16:05:00Z',
|
|
},
|
|
},
|
|
{
|
|
'kind': 'step',
|
|
'target': 'run:457:1',
|
|
'score': 1,
|
|
'recency': '2026-10-20T08:14:00Z',
|
|
'step': {
|
|
'run_id': 457,
|
|
'sequence': 1,
|
|
'stage': 'planner',
|
|
'visit': 1,
|
|
'outcome': 'success',
|
|
'target': '#success',
|
|
'diagnostic': 'plan accepted',
|
|
},
|
|
},
|
|
];
|