merge(app): land browser-verified adaptive shell
This commit is contained in:
+28
-110
@@ -1,122 +1,40 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
import 'shell/adaptive_shell.dart';
|
||||
import 'shell/destination.dart';
|
||||
|
||||
export 'shell/adaptive_shell.dart';
|
||||
export 'shell/destination.dart';
|
||||
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
const MyApp({super.key, this.destinationBodies = const {}, this.cupertino});
|
||||
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
theme: ThemeData(
|
||||
// This is the theme of your application.
|
||||
//
|
||||
// TRY THIS: Try running your application with "flutter run". You'll see
|
||||
// the application has a purple toolbar. Then, without quitting the app,
|
||||
// try changing the seedColor in the colorScheme below to Colors.green
|
||||
// and then invoke "hot reload" (save your changes or press the "hot
|
||||
// reload" button in a Flutter-supported IDE, or press "r" if you used
|
||||
// the command line to start the app).
|
||||
//
|
||||
// Notice that the counter didn't reset back to zero; the application
|
||||
// state is not lost during the reload. To reset the state, use hot
|
||||
// restart instead.
|
||||
//
|
||||
// This works for code too, not just values: Most code changes can be
|
||||
// tested with just a hot reload.
|
||||
colorScheme: .fromSeed(seedColor: Colors.deepPurple),
|
||||
),
|
||||
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key, required this.title});
|
||||
|
||||
// This widget is the home page of your application. It is stateful, meaning
|
||||
// that it has a State object (defined below) that contains fields that affect
|
||||
// how it looks.
|
||||
|
||||
// This class is the configuration for the state. It holds the values (in this
|
||||
// case the title) provided by the parent (in this case the App widget) and
|
||||
// used by the build method of the State. Fields in a Widget subclass are
|
||||
// always marked "final".
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int _counter = 0;
|
||||
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
// This call to setState tells the Flutter framework that something has
|
||||
// changed in this State, which causes it to rerun the build method below
|
||||
// so that the display can reflect the updated values. If we changed
|
||||
// _counter without calling setState(), then the build method would not be
|
||||
// called again, and so nothing would appear to happen.
|
||||
_counter++;
|
||||
});
|
||||
}
|
||||
final Map<AppDestination, WidgetBuilder> destinationBodies;
|
||||
final bool? cupertino;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// This method is rerun every time setState is called, for instance as done
|
||||
// by the _incrementCounter method above.
|
||||
//
|
||||
// The Flutter framework has been optimized to make rerunning build methods
|
||||
// fast, so that you can just rebuild anything that needs updating rather
|
||||
// than having to individually change instances of widgets.
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
// TRY THIS: Try changing the color here to a specific color (to
|
||||
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
|
||||
// change color while the other colors stay the same.
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
// Here we take the value from the MyHomePage object that was created by
|
||||
// the App.build method, and use it to set our appbar title.
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: Center(
|
||||
// Center is a layout widget. It takes a single child and positions it
|
||||
// in the middle of the parent.
|
||||
child: Column(
|
||||
// Column is also a layout widget. It takes a list of children and
|
||||
// arranges them vertically. By default, it sizes itself to fit its
|
||||
// children horizontally, and tries to be as tall as its parent.
|
||||
//
|
||||
// Column has various properties to control how it sizes itself and
|
||||
// how it positions its children. Here we use mainAxisAlignment to
|
||||
// center the children vertically; the main axis here is the vertical
|
||||
// axis because Columns are vertical (the cross axis would be
|
||||
// horizontal).
|
||||
//
|
||||
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
|
||||
// action in the IDE, or press "p" in the console), to see the
|
||||
// wireframe for each widget.
|
||||
mainAxisAlignment: .center,
|
||||
children: [
|
||||
const Text('You have pushed the button this many times:'),
|
||||
Text(
|
||||
'$_counter',
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
),
|
||||
],
|
||||
final platform = defaultTargetPlatform;
|
||||
if (cupertino ??
|
||||
(platform == TargetPlatform.iOS || platform == TargetPlatform.macOS)) {
|
||||
return CupertinoApp(
|
||||
title: 'Pipelines',
|
||||
home: AdaptiveShell(
|
||||
destinationBodies: destinationBodies,
|
||||
cupertino: true,
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
tooltip: 'Increment',
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
);
|
||||
}
|
||||
return MaterialApp(
|
||||
title: 'Pipelines',
|
||||
theme: ThemeData(),
|
||||
darkTheme: ThemeData(brightness: Brightness.dark),
|
||||
themeMode: ThemeMode.system,
|
||||
home: AdaptiveShell(destinationBodies: destinationBodies),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'destination.dart';
|
||||
|
||||
class AdaptiveShell extends StatefulWidget {
|
||||
const AdaptiveShell({
|
||||
super.key,
|
||||
this.destinationBodies = const {},
|
||||
this.cupertino = false,
|
||||
});
|
||||
|
||||
final Map<AppDestination, WidgetBuilder> destinationBodies;
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
State<AdaptiveShell> createState() => _AdaptiveShellState();
|
||||
}
|
||||
|
||||
class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
AppDestination _selected = AppDestination.pipelines;
|
||||
|
||||
void _select(AppDestination destination) =>
|
||||
setState(() => _selected = destination);
|
||||
|
||||
List<T> _items<T>(T Function(AppDestination) build) =>
|
||||
AppDestination.values.map(build).toList();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final index = AppDestination.values.indexOf(_selected);
|
||||
final details = destinationDetails(_selected);
|
||||
final contents = AppDestination.values.map((destination) {
|
||||
final item = destinationDetails(destination);
|
||||
return KeyedSubtree(
|
||||
key: ValueKey(destination),
|
||||
child:
|
||||
widget.destinationBodies[destination]?.call(context) ??
|
||||
Center(child: Text('${item.label} — Not implemented')),
|
||||
);
|
||||
}).toList();
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final wide = constraints.maxWidth >= 600;
|
||||
if (widget.cupertino) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(middle: Text(details.label)),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(child: _destinationStack(contents, index)),
|
||||
CupertinoTabBar(
|
||||
currentIndex: index,
|
||||
onTap: (value) => _select(AppDestination.values[value]),
|
||||
items: _items((destination) {
|
||||
final item = destinationDetails(destination);
|
||||
return BottomNavigationBarItem(
|
||||
icon: Icon(item.cupertinoIcon),
|
||||
label: item.label,
|
||||
);
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(details.label)),
|
||||
body: Row(
|
||||
children: [
|
||||
if (wide)
|
||||
NavigationRail(
|
||||
selectedIndex: index,
|
||||
onDestinationSelected: (value) =>
|
||||
_select(AppDestination.values[value]),
|
||||
labelType: NavigationRailLabelType.all,
|
||||
destinations: _items((destination) {
|
||||
final item = destinationDetails(destination);
|
||||
return NavigationRailDestination(
|
||||
icon: Icon(item.icon),
|
||||
label: Text(item.label),
|
||||
);
|
||||
}),
|
||||
),
|
||||
Expanded(child: _destinationStack(contents, index)),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: wide
|
||||
? null
|
||||
: NavigationBar(
|
||||
selectedIndex: index,
|
||||
onDestinationSelected: (value) =>
|
||||
_select(AppDestination.values[value]),
|
||||
destinations: _items((destination) {
|
||||
final item = destinationDetails(destination);
|
||||
return NavigationDestination(
|
||||
icon: Icon(item.icon),
|
||||
label: item.label,
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _destinationStack(List<Widget> contents, int index) =>
|
||||
IndexedStack(index: index, children: contents);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
enum AppDestination { pipelines, runs, chat, settings }
|
||||
|
||||
({String label, IconData icon, IconData cupertinoIcon}) destinationDetails(
|
||||
AppDestination value,
|
||||
) => switch (value) {
|
||||
AppDestination.pipelines => (
|
||||
label: 'Pipelines',
|
||||
icon: Icons.account_tree_outlined,
|
||||
cupertinoIcon: CupertinoIcons.arrow_branch,
|
||||
),
|
||||
AppDestination.runs => (
|
||||
label: 'Runs',
|
||||
icon: Icons.play_circle_outline,
|
||||
cupertinoIcon: CupertinoIcons.play_circle,
|
||||
),
|
||||
AppDestination.chat => (
|
||||
label: 'Chat',
|
||||
icon: Icons.chat_bubble_outline,
|
||||
cupertinoIcon: CupertinoIcons.chat_bubble_2,
|
||||
),
|
||||
AppDestination.settings => (
|
||||
label: 'Settings',
|
||||
icon: Icons.settings_outlined,
|
||||
cupertinoIcon: CupertinoIcons.gear,
|
||||
),
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
# F2 — Adaptive shell
|
||||
|
||||
## Manager browser acceptance
|
||||
The initial capture attempt failed because the fixture served its index with
|
||||
binary MIME. Corrected the fixture MIME and navigation assertions; the real
|
||||
Chrome run now passes actual Pipelines → Runs → Chat → Settings → Pipelines
|
||||
navigation, checking the selected destination body (not only navigation labels).
|
||||
Captured and inspected at 390×844 and 1280×800:
|
||||
`/private/var/folders/jp/q0qvjyg54fl_c5vhhk1ylz2m0000gn/T/opencode/f2-shell-{phone,phone-runs,phone-settings,desktop}.png`.
|
||||
These show the native Cupertino shell on a macOS browser with explicitly labelled
|
||||
unimplemented feature bodies. They do not prove feature parity or mobile behavior.
|
||||
Reproduce from app/ using `OPENCODE_ARTIFACT_DIR=<directory> node tool/shell_probe.mjs`
|
||||
after `flutter build web`. Earlier missing-capture statements below are historical.
|
||||
|
||||
Implemented standard adaptive navigation for Pipelines, Runs, Chat and Settings.
|
||||
Material uses a bottom `NavigationBar` below 600 logical pixels and a labeled
|
||||
`NavigationRail` at wider widths. Cupertino uses the native navigation bar and
|
||||
tab bar. `MyApp` chooses Cupertino on iOS/macOS, leaves Material system light/dark
|
||||
themes active elsewhere, and accepts injectable `WidgetBuilder` bodies through
|
||||
`AdaptiveShell`; unregistered destinations are explicitly marked Not implemented.
|
||||
|
||||
## Verification
|
||||
|
||||
- `flutter test test/widget_test.dart`: passed (narrow/wide, 2x text scale,
|
||||
Cupertino controls and injected destination body).
|
||||
- `flutter analyze`: passed, no issues.
|
||||
- Follow-up verification: widget tests now cover state retention across tab
|
||||
switches and Cupertino safe-area insets. `flutter build web` succeeds.
|
||||
- Browser interaction/capture remains unverified: the local Chrome DevTools
|
||||
probe did not complete, so no rendered evidence is claimed. Mobile targets
|
||||
are unverified.
|
||||
|
||||
No API capabilities are asserted or mocked. No dependencies were added.
|
||||
+89
-18
@@ -1,30 +1,101 @@
|
||||
// This is a basic Flutter widget test.
|
||||
//
|
||||
// To perform an interaction with a widget in your test, use the WidgetTester
|
||||
// utility in the flutter_test package. For example, you can send tap and scroll
|
||||
// gestures. You can also use WidgetTester to find child widgets in the widget
|
||||
// tree, read text, and verify that the values of widget properties are correct.
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:pipelines_app/main.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||
// Build our app and trigger a frame.
|
||||
await tester.pumpWidget(const MyApp());
|
||||
for (final width in [390.0, 1000.0]) {
|
||||
testWidgets(
|
||||
'Material shell adapts at width $width and supports large text',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = Size(width, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: MediaQuery(
|
||||
data: MediaQueryData(textScaler: TextScaler.linear(2)),
|
||||
child: AdaptiveShell(),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.text('Pipelines'), findsWidgets);
|
||||
expect(find.text('Pipelines — Not implemented'), findsOneWidget);
|
||||
expect(
|
||||
find.byType(NavigationBar),
|
||||
width < 600 ? findsOneWidget : findsNothing,
|
||||
);
|
||||
expect(
|
||||
find.byType(NavigationRail),
|
||||
width >= 600 ? findsOneWidget : findsNothing,
|
||||
);
|
||||
await tester.tap(find.text('Runs').last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Runs — Not implemented'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Verify that our counter starts at 0.
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
expect(find.text('1'), findsNothing);
|
||||
testWidgets('Cupertino shell uses native navigation controls', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(const MyApp(cupertino: true));
|
||||
expect(find.byType(CupertinoNavigationBar), findsOneWidget);
|
||||
expect(find.byType(CupertinoTabBar), findsOneWidget);
|
||||
expect(find.text('Pipelines — Not implemented'), findsOneWidget);
|
||||
});
|
||||
|
||||
// Tap the '+' icon and trigger a frame.
|
||||
await tester.tap(find.byIcon(Icons.add));
|
||||
testWidgets('Cupertino content stays inside safe area', (tester) async {
|
||||
tester.view.padding = const FakeViewPadding(top: 36, bottom: 28);
|
||||
addTearDown(tester.view.resetPadding);
|
||||
await tester.pumpWidget(const MyApp(cupertino: true));
|
||||
final tabBar = tester.getRect(find.byType(CupertinoTabBar));
|
||||
expect(tabBar.bottom, lessThanOrEqualTo(900 - 28));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('destination state survives switching tabs', (tester) async {
|
||||
var builds = 0;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: AdaptiveShell(
|
||||
destinationBodies: {
|
||||
AppDestination.pipelines: (_) => StatefulBuilder(
|
||||
builder: (context, setState) => TextButton(
|
||||
onPressed: () => setState(() => builds++),
|
||||
child: Text('Builds: $builds'),
|
||||
),
|
||||
),
|
||||
AppDestination.runs: (_) => const Text('Runs screen'),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Builds: 0'));
|
||||
await tester.pump();
|
||||
await tester.tap(find.text('Runs').last);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Pipelines').last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Builds: 1'), findsOneWidget);
|
||||
});
|
||||
|
||||
// Verify that our counter has incremented.
|
||||
expect(find.text('0'), findsNothing);
|
||||
expect(find.text('1'), findsOneWidget);
|
||||
testWidgets('destination content can be supplied by integration', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: AdaptiveShell(
|
||||
destinationBodies: {
|
||||
AppDestination.pipelines: (_) =>
|
||||
const Text('Injected pipelines screen'),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.text('Injected pipelines screen'), findsOneWidget);
|
||||
expect(find.text('Pipelines — Not implemented'), findsNothing);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
import { createServer } from 'node:http';
|
||||
import { readFile } 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';
|
||||
import { mkdtemp, rm } from 'node:fs/promises';
|
||||
|
||||
const root = join(process.cwd(), 'build/web');
|
||||
const mime = { '.html': 'text/html', '.js': 'text/javascript', '.json': 'application/json', '.wasm': 'application/wasm', '.png': 'image/png', '.ico': 'image/x-icon' };
|
||||
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.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(), 'f2-shell-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');
|
||||
};
|
||||
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.method?.includes('detached') || msg.method?.includes('crashed')) console.error('CDP event', JSON.stringify(msg));
|
||||
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 navigation = await send('Page.navigate', { url: `http://127.0.0.1:${port}/` }, session);
|
||||
if (navigation.error || navigation.result?.errorText) throw new Error(JSON.stringify(navigation));
|
||||
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;
|
||||
};
|
||||
await delay(3500);
|
||||
const loaded = await evaluate("({url:location.href, ready:document.readyState, body:document.body.innerText, html:document.body.innerHTML.slice(0,500)})");
|
||||
if (!loaded?.url.includes(`127.0.0.1:${port}`)) throw new Error(`Fixture did not load: ${JSON.stringify(loaded)}`);
|
||||
await evaluate("document.querySelector('flt-semantics-placeholder')?.click()");
|
||||
await delay(900);
|
||||
const clickLabel = async label => evaluate(`(() => { const e=[...document.querySelectorAll('flt-semantics')].find(x => (x.getAttribute('aria-label') || x.innerText || '') === ${JSON.stringify(label)}); if (!e) return false; e.click(); return true; })()`);
|
||||
const labels = await evaluate("[...document.querySelectorAll('flt-semantics')].map(x=>x.getAttribute('aria-label')||x.innerText).filter(Boolean)");
|
||||
if (!labels?.some(x => x.includes('Pipelines'))) throw new Error(`Flutter semantics unavailable: ${JSON.stringify(labels)}`);
|
||||
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;
|
||||
await (await import('node:fs/promises')).writeFile(`${process.env.OPENCODE_ARTIFACT_DIR}/${name}.png`, Buffer.from(data, 'base64'));
|
||||
};
|
||||
await capture('f2-shell-phone', 390, 844);
|
||||
for (const label of ['Runs', 'Chat', 'Settings', 'Pipelines']) {
|
||||
if (!await clickLabel(label)) throw new Error(`Could not interact with ${label} navigation`);
|
||||
await delay(250);
|
||||
const current = await evaluate("[...document.querySelectorAll('flt-semantics')].map(x=>x.getAttribute('aria-label')||x.innerText).filter(Boolean)");
|
||||
if (!current?.some(x => x.includes(label + ' — Not implemented'))) throw new Error(`${label} body missing after navigation: ${JSON.stringify(current)}`);
|
||||
if (label === 'Runs' || label === 'Settings') await capture(`f2-shell-phone-${label.toLowerCase()}`, 390, 844);
|
||||
}
|
||||
await capture('f2-shell-desktop', 1280, 800);
|
||||
console.log(JSON.stringify({ labels, captures: ['f2-shell-phone.png', 'f2-shell-phone-runs.png', 'f2-shell-phone-settings.png', 'f2-shell-desktop.png'], navigated: ['Runs', 'Chat', 'Settings', 'Pipelines'] }, 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