Files
pipelines/app/tool/schedule_editor_probe_app.dart
alan b60ad6d98f Remove alternate hosts from tooling probes
Keep the probe suite on the Material composition so browser fixtures and capture drivers no longer render or select Cupertino hosts. Record the final residual legacy arguments and implementation checks for the delivery gate.
2026-11-11 21:38:30 +00:00

151 lines
4.1 KiB
Dart

import 'dart:convert';
import 'dart:js_interop';
import 'dart:js_interop_unsafe';
import 'package:flutter/material.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/schedules/domain/editor/schedule_draft.dart';
import 'package:pipelines_app/features/schedules/ui/editor/schedule_editor_form.dart';
/// Isolated browser fixture for the native saved-schedule form.
///
/// flutter build web -t tool/schedule_editor_probe_app.dart
///
/// Query: `brightness=dark`, `scale=2`. The injected callback
/// refuses the first valid submit and accepts the retry; it never opens a
/// socket or touches a real schedule. Its counters/record are published at
/// `globalThis.scheduleEditorProbe` for the Chrome probe.
void main() => runApp(const _ProbeApp());
class _ProbeApp extends StatelessWidget {
const _ProbeApp();
@override
Widget build(BuildContext context) {
final parameters = Uri.base.queryParameters;
final dark = parameters['brightness'] == 'dark';
final scale = double.tryParse(parameters['scale'] ?? '') ?? 1.0;
Widget media(BuildContext context, Widget? app) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(scale)),
child: app!,
);
const home = _ProbeHome();
return MaterialApp(
theme: ThemeData(
brightness: dark ? Brightness.dark : Brightness.light,
platform: TargetPlatform.android,
),
builder: media,
home: Scaffold(
appBar: AppBar(title: const Text('Schedule editor probe')),
body: SafeArea(child: home),
),
);
}
}
class _Refusal implements Exception {
const _Refusal();
@override
String toString() => 'conflict: revision 13 is stale';
}
class _ProbeHome extends StatefulWidget {
const _ProbeHome();
@override
State<_ProbeHome> createState() => _ProbeHomeState();
}
class _ProbeHomeState extends State<_ProbeHome> {
final _draft = ScheduleDraft.create(
pipelineId: 4,
version: '2',
workspace: '/srv/research',
timezone: 'Europe/London',
);
int _submits = 0;
int _records = 0;
bool _pending = false;
bool _refuseNext = true;
String? _lastError;
JsonMap? _lastRecord;
@override
void initState() {
super.initState();
_publish();
}
void _publish() {
globalContext.setProperty(
'scheduleEditorProbe'.toJS,
<String, Object?>{
'submits': _submits,
'records': _records,
'pending': _pending,
'lastError': _lastError,
'lastRecord': _lastRecord,
}.jsify(),
);
}
Future<void> _submit(JsonMap record) async {
_submits++;
_pending = true;
_publish();
if (mounted) setState(() {});
await Future<void>.delayed(const Duration(milliseconds: 900));
if (_refuseNext) {
_refuseNext = false;
_pending = false;
_lastError = 'conflict: revision 13 is stale';
_publish();
if (mounted) setState(() {});
throw const _Refusal();
}
_pending = false;
_records++;
_lastRecord = record;
_publish();
if (mounted) setState(() {});
}
@override
Widget build(BuildContext context) {
final record = _lastRecord;
return SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 640),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ScheduleEditorForm(
draft: _draft,
onSubmit: _submit,
onCancel: () {},
),
if (record != null) ...[
const SizedBox(height: 24),
Text(
'Submitted record',
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 8),
SelectableText(
const JsonEncoder.withIndent(' ').convert(record),
),
],
],
),
),
),
);
}
}