Files
pipelines/app/tool/diff_wiring_probe.dart
T

192 lines
5.3 KiB
Dart

// Standalone fixture entry for real-browser run-detail Changes wiring evidence.
//
// Build and probe (from app/):
// flutter build web --target tool/diff_wiring_probe.dart --output build/probe-wire
// node tool/diff_wiring_probe.mjs --root build/probe-wire --out DIR
//
// Server-shaped fixtures only: a fake gateway answers the same get_run envelope
// the app consumes. No server or operator run is touched.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
const _patch =
'--- "a/lib/features/runs/ui/run_changes_action.dart"\n'
'+++ "b/lib/features/runs/ui/run_changes_action.dart"\n'
'@@ -1,3 +1,4 @@\n'
' import package:flutter/material.dart;\n'
'-const label = "Old";\n'
'+const label = "Changes";\n'
'+const recorded = true;\n'
' // end\n';
class _FakeGateway implements ApiGateway {
_FakeGateway(this.detail);
final JsonMap detail;
@override
Stream<JsonMap> get frames => const Stream<JsonMap>.empty();
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type != 'get_run') throw UnsupportedError(type);
return Future.value({'run_detail': detail});
}
}
JsonMap _run({
required bool unavailable,
String status = 'succeeded',
String stepStatus = 'completed',
}) => {
'id': 12,
'title': 'Changes wiring probe',
'name': 'probe',
'status': status,
'steps': [
{
'stage': 'implementer',
'sequence': 1,
'status': stepStatus,
'file_changes': unavailable
? {
'status': 'unavailable',
'skipped': 0,
'omitted': 0,
'diagnostic':
'Workspace snapshot unavailable; changes could not be '
'compared.',
'files': <JsonMap>[],
}
: status == 'running'
? null
: {
'status': 'complete',
'scope': 'Git tracked and nonignored files in the run directory',
'skipped': 0,
'omitted': 0,
'diagnostic': '',
'files': [
{
'path': 'lib/features/runs/ui/run_changes_action.dart',
'kind': 'modified',
'patch': _patch,
},
],
},
},
],
};
void main() {
final params = Uri.base.queryParameters;
final cupertino = params['platform'] == 'cupertino';
final stepsUnavailable = params['capture'] == 'unavailable';
final status = params['run'] == 'failed'
? 'failed'
: params['run'] == 'running'
? 'running'
: 'succeeded';
final stepStatus = status == 'running' ? 'running' : 'completed';
final theme = params['theme'] == 'light' ? Brightness.light : Brightness.dark;
// Browser text scaling is a fixture input like platform and theme: the
// accessibility states are otherwise unreachable from CDP metrics alone.
final textScale = double.tryParse(params['scale'] ?? '') ?? 1;
final body = _ProbeBody(
unavailable: stepsUnavailable,
status: status,
stepStatus: stepStatus,
);
Widget scaled(BuildContext context, Widget? app) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(textScale)),
child: app!,
);
if (cupertino) {
runApp(
CupertinoApp(
title: 'Run changes probe',
theme: CupertinoThemeData(brightness: theme),
builder: (context, app) => Theme(
data: ThemeData(platform: TargetPlatform.iOS),
child: scaled(context, app),
),
home: body,
),
);
} else {
runApp(
MaterialApp(
title: 'Run changes probe',
theme: ThemeData(brightness: theme, platform: TargetPlatform.android),
builder: scaled,
home: body,
),
);
}
}
class _ProbeBody extends StatefulWidget {
const _ProbeBody({
required this.unavailable,
required this.status,
required this.stepStatus,
});
final bool unavailable;
final String status;
final String stepStatus;
@override
State<_ProbeBody> createState() => _ProbeBodyState();
}
class _ProbeBodyState extends State<_ProbeBody> {
late final _FakeGateway _gateway = _FakeGateway(
_run(
unavailable: widget.unavailable,
status: widget.status,
stepStatus: widget.stepStatus,
),
);
late final RunsController _controller = RunsController(
RunsRepository(_gateway),
);
@override
void initState() {
super.initState();
_controller.select(12);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final detail = RunDetailView(
controller: _controller,
gateway: _gateway,
onBack: () {},
);
if (Theme.of(context).platform == TargetPlatform.iOS) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(middle: Text('Runs')),
child: SafeArea(child: detail),
);
}
return Scaffold(
appBar: AppBar(title: const Text('Runs')),
body: detail,
);
}
}