feat(app): add native omni-search screen over the search gateway
Pure request/parse/row logic in lib/features/search/domain, a gateway-backed repository, and Material plus Cupertino bodies. The header and rows share one scroll view, and the server's truncation, scan and cap facts stay visible even when a bounded scan returns no matches. Tests cover the exact search envelope, token parsing, stale replies, retry, truncation bounds and platform layouts. A Web-only fixture and CDP probe support rendered verification; the screen is not yet registered in the shell.
This commit is contained in:
@@ -0,0 +1,190 @@
|
||||
// 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': '/Users/alan/repos/pipelines',
|
||||
'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',
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,246 @@
|
||||
// Real Chrome evidence for the Flutter search screen. Serves the fixture build
|
||||
// from build/web on an OS-assigned loopback port and drives the page through
|
||||
// Chrome DevTools Protocol, like tool/shell_probe.mjs. Usage:
|
||||
// flutter build web -t tool/search_fixture/main.dart
|
||||
// OPENCODE_ARTIFACT_DIR=<dir> node tool/search_probe.mjs
|
||||
import { createServer } from 'node:http';
|
||||
import { readFile, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { once } from 'node:events';
|
||||
import { setTimeout as delay } from 'node:timers/promises';
|
||||
import { join, extname, resolve, sep } from 'node:path';
|
||||
import { tmpdir } from 'node:os';
|
||||
|
||||
const root = join(process.cwd(), 'build/web');
|
||||
const artifactDir = process.env.OPENCODE_ARTIFACT_DIR;
|
||||
if (!artifactDir) throw new Error('OPENCODE_ARTIFACT_DIR is required for captures');
|
||||
const mime = {
|
||||
'.html': 'text/html',
|
||||
'.js': 'text/javascript',
|
||||
'.json': 'application/json',
|
||||
'.wasm': 'application/wasm',
|
||||
'.png': 'image/png',
|
||||
'.ico': 'image/x-icon',
|
||||
'.ttf': 'font/ttf',
|
||||
'.otf': 'font/otf',
|
||||
};
|
||||
const server = createServer(async (req, res) => {
|
||||
try {
|
||||
const path = resolve(
|
||||
root,
|
||||
'.' + decodeURIComponent(new URL(req.url, 'http://localhost').pathname),
|
||||
);
|
||||
if (path !== root && !path.startsWith(root + sep)) {
|
||||
return res.writeHead(403).end();
|
||||
}
|
||||
const filePath =
|
||||
path === root || path.endsWith('/') ? join(path, 'index.html') : path;
|
||||
const file = await readFile(filePath);
|
||||
res
|
||||
.writeHead(200, {
|
||||
'content-type': mime[extname(filePath)] ?? 'application/octet-stream',
|
||||
})
|
||||
.end(file);
|
||||
} catch {
|
||||
res.writeHead(404).end('not found');
|
||||
}
|
||||
});
|
||||
server.listen(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const port = server.address().port;
|
||||
const profile = await mkdtemp(join(tmpdir(), 'x1-search-chrome-'));
|
||||
const chrome = spawn(
|
||||
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
||||
[
|
||||
'--headless=new',
|
||||
'--no-first-run',
|
||||
'--no-default-browser-check',
|
||||
'--disable-gpu',
|
||||
'--remote-debugging-port=0',
|
||||
`--user-data-dir=${profile}`,
|
||||
'about:blank',
|
||||
],
|
||||
{ stdio: ['ignore', 'ignore', 'pipe'] },
|
||||
);
|
||||
let stderr = '';
|
||||
chrome.stderr.on('data', (data) => {
|
||||
stderr += data;
|
||||
});
|
||||
const waitFor = async (fn) => {
|
||||
for (let i = 0; i < 100; i++) {
|
||||
const value = await fn();
|
||||
if (value) return value;
|
||||
await delay(100);
|
||||
}
|
||||
throw new Error('Timed out waiting for Chrome DevTools');
|
||||
};
|
||||
const result = { captures: [], evidence: {} };
|
||||
let ws;
|
||||
try {
|
||||
const endpoint = await waitFor(() =>
|
||||
stderr.match(/DevTools listening on (ws:\/\/[^\s]+)/)?.[1],
|
||||
);
|
||||
ws = new WebSocket(endpoint);
|
||||
await once(ws, 'open');
|
||||
let id = 0;
|
||||
const pending = new Map();
|
||||
ws.addEventListener('message', (event) => {
|
||||
const msg = JSON.parse(event.data);
|
||||
if (msg.id && pending.has(msg.id)) {
|
||||
pending.get(msg.id)(msg);
|
||||
pending.delete(msg.id);
|
||||
}
|
||||
});
|
||||
const send = (method, params = {}, sessionId) =>
|
||||
new Promise((resolve) => {
|
||||
const callId = ++id;
|
||||
pending.set(callId, resolve);
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
id: callId,
|
||||
method,
|
||||
params,
|
||||
...(sessionId ? { sessionId } : {}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
const created = await send('Target.createTarget', { url: 'about:blank' });
|
||||
if (!created.result) {
|
||||
throw new Error(`Target creation failed: ${JSON.stringify(created)}`);
|
||||
}
|
||||
const target = created.result.targetId;
|
||||
const session = (
|
||||
await send('Target.attachToTarget', { targetId: target, flatten: true })
|
||||
).result.sessionId;
|
||||
await send('Page.enable', {}, session);
|
||||
await send('Runtime.enable', {}, session);
|
||||
const evaluate = async (expression) => {
|
||||
const response = await send(
|
||||
'Runtime.evaluate',
|
||||
{ expression, returnByValue: true, awaitPromise: true },
|
||||
session,
|
||||
);
|
||||
if (response.error) {
|
||||
throw new Error(`Runtime.evaluate failed: ${JSON.stringify(response)}`);
|
||||
}
|
||||
return response.result?.result?.value;
|
||||
};
|
||||
const clickMatching = (needle) =>
|
||||
evaluate(`(() => {
|
||||
const needle = ${JSON.stringify(needle)};
|
||||
const nodes = [...document.querySelectorAll('flt-semantics')];
|
||||
const e = nodes.find(x => x.hasAttribute('flt-tappable') &&
|
||||
(x.getAttribute('aria-label') || x.innerText || '').includes(needle));
|
||||
if (!e) return false;
|
||||
e.click();
|
||||
return true;
|
||||
})()`);
|
||||
const capture = async (name, width, height) => {
|
||||
await send(
|
||||
'Emulation.setDeviceMetricsOverride',
|
||||
{ width, height, deviceScaleFactor: 1, mobile: width < 600 },
|
||||
session,
|
||||
);
|
||||
await delay(350);
|
||||
const data = (
|
||||
await send(
|
||||
'Page.captureScreenshot',
|
||||
{ format: 'png', captureBeyondViewport: false },
|
||||
session,
|
||||
)
|
||||
).result.data;
|
||||
const path = join(artifactDir, `${name}.png`);
|
||||
await writeFile(path, Buffer.from(data, 'base64'));
|
||||
result.captures.push(path);
|
||||
};
|
||||
const load = async (url, width, height) => {
|
||||
await send(
|
||||
'Emulation.setDeviceMetricsOverride',
|
||||
{ width, height, deviceScaleFactor: 1, mobile: width < 600 },
|
||||
session,
|
||||
);
|
||||
const navigation = await send('Page.navigate', { url }, session);
|
||||
if (navigation.error || navigation.result?.errorText) throw new Error(JSON.stringify(navigation));
|
||||
await delay(3500);
|
||||
await evaluate("document.querySelector('flt-semantics-placeholder')?.click()");
|
||||
await delay(900);
|
||||
};
|
||||
const typeText = async (query) => {
|
||||
const focused = await evaluate(`(() => {
|
||||
const input = document.querySelector('input[type="search"]') || document.querySelector('input.flt-text-editing');
|
||||
if (!input) return false; input.focus(); return true; })()`);
|
||||
if (!focused) throw new Error('Search input not found');
|
||||
await delay(400);
|
||||
const inserted = await send('Input.insertText', { text: query }, session);
|
||||
if (inserted.error) throw new Error(JSON.stringify(inserted));
|
||||
await delay(1400);
|
||||
return (await evaluate('document.body.innerText')).trim();
|
||||
};
|
||||
const typeQuery = async (query) => {
|
||||
const trimmed = await typeText(query);
|
||||
if (!trimmed.includes('Plan and land')) {
|
||||
throw new Error(`Results missing after typing: ${JSON.stringify(trimmed)}`);
|
||||
}
|
||||
return {
|
||||
typed: query,
|
||||
resultTitles: ['Plan and land', 'run #457 · Plan and land', 'run #457 · step 3 · input',
|
||||
'plan.md', 'run #457 · planner visit 1'].filter((title) => trimmed.includes(title)),
|
||||
showsServerSnippet: trimmed.includes('Plan the change before implementing it'),
|
||||
showsRecency: /\d{1,2} [A-Z][a-z]{2} \d{2}:\d{2}/.test(trimmed),
|
||||
showsBounds:
|
||||
trimmed.includes('Results truncated') &&
|
||||
trimmed.includes('cap 50') &&
|
||||
trimmed.includes('scanned 2000 steps'),
|
||||
};
|
||||
};
|
||||
const typeTruncatedEmpty = async (query) => {
|
||||
const text = await typeText(query);
|
||||
const emptyCopy = `No matches for "${query}" within the server's scan limit.`;
|
||||
const missing = [
|
||||
emptyCopy, 'Results truncated', '0 results',
|
||||
'scanned 2000 steps', 'scan limit 1.0 MiB',
|
||||
].filter((needle) => !text.includes(needle));
|
||||
if (missing.length) throw new Error(`Truncated empty missing ${JSON.stringify(missing)}`);
|
||||
return { typed: query, emptyCopy, showsTruncationWarning: true, showsBounds: true };
|
||||
};
|
||||
|
||||
const base = `http://127.0.0.1:${port}/`;
|
||||
await load(base, 390, 844);
|
||||
result.evidence.materialPhone = await typeQuery('plan');
|
||||
await capture('x1-search-material-phone', 390, 844);
|
||||
if (!(await clickMatching('Plan and land'))) {
|
||||
throw new Error('Could not open the pipeline row');
|
||||
}
|
||||
await delay(700);
|
||||
const opened = await evaluate('document.body.innerText');
|
||||
if (!opened.includes('pipeline:24')) {
|
||||
throw new Error(`Opened target missing: ${JSON.stringify(opened)}`);
|
||||
}
|
||||
result.evidence.opened = 'pipeline:24';
|
||||
await capture('x1-search-open-target', 390, 844);
|
||||
|
||||
await load(base, 1280, 800);
|
||||
result.evidence.materialDesktop = await typeQuery('plan');
|
||||
await capture('x1-search-material-desktop', 1280, 800);
|
||||
|
||||
await load(`${base}?cupertino=1`, 390, 844);
|
||||
result.evidence.cupertinoPhone = await typeQuery('plan');
|
||||
await capture('x1-search-cupertino-phone', 390, 844);
|
||||
|
||||
await load(base, 390, 844);
|
||||
result.evidence.materialTruncatedEmpty = await typeTruncatedEmpty('needle');
|
||||
await capture('x1-search-truncated-empty', 390, 844);
|
||||
|
||||
await load(`${base}?cupertino=1`, 390, 844);
|
||||
result.evidence.cupertinoTruncatedEmpty =
|
||||
await typeTruncatedEmpty('needle');
|
||||
await capture('x1-search-truncated-empty-cupertino', 390, 844);
|
||||
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
} finally {
|
||||
ws?.close();
|
||||
chrome.kill('SIGTERM');
|
||||
await Promise.race([once(chrome, 'exit'), delay(3000)]);
|
||||
server.close();
|
||||
await rm(profile, { recursive: true, force: true });
|
||||
}
|
||||
Reference in New Issue
Block a user