Files
pipelines/app/tool/template_create_probe.dart
T
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:js_interop';
import 'dart:js_interop_unsafe';
import 'package:flutter/material.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/core/transport/connection_state.dart';
import 'package:pipelines_app/features/templates/data/template_repository.dart';
import 'package:pipelines_app/features/templates/domain/template_entry.dart';
import 'package:pipelines_app/features/templates/ui/template_create_dialog.dart';
/// Browser capture entrypoint for the create-from-template prompt.
///
/// The fixture gateway is in-process and records every request; nothing here
/// opens a socket or contacts a real server. The state published at
/// `globalThis.templateCreateProbe` is read by the probe driver, so it can
/// prove that a validation refusal sent no submit and that an accepted create
/// was reported once.
const _source = ' name: "release"\n stages:\n - key: "añadir" 😀 \n';
class _ProbeGateway implements ApiGateway {
_ProbeGateway(this.publish);
final VoidCallback publish;
int validates = 0;
int submits = 0;
bool failNextValidate = true;
String? lastSource;
JsonMap? lastSubmit;
final List<JsonMap> created = [];
@override
Stream<JsonMap> get frames => const Stream.empty();
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
if (type == 'validate') {
validates++;
lastSource = fields['source'] as String?;
publish();
if (failNextValidate) {
failNextValidate = false;
throw const ProtocolError(
'invalid definition: fixture stage "añadir" has no type',
);
}
return {
'graph': {'stages': []},
};
}
if (type == 'submit') {
submits++;
lastSubmit = Map<String, dynamic>.from(fields);
publish();
return {
'detail': {'id': 71, 'name': 'Probe release'},
};
}
throw StateError('The create probe does not implement $type');
}
}
void main() => runApp(const _ProbeApp());
class _ProbeApp extends StatelessWidget {
const _ProbeApp();
@override
Widget build(BuildContext context) {
final params = Uri.base.queryParameters;
final scale = double.tryParse(params['scale'] ?? '') ?? 1;
Widget scaled(BuildContext context, Widget? app) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(scale)),
child: app!,
);
return MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
builder: scaled,
home: const _ProbeHome(),
);
}
}
class _ProbeHome extends StatefulWidget {
const _ProbeHome();
@override
State<_ProbeHome> createState() => _ProbeHomeState();
}
class _ProbeHomeState extends State<_ProbeHome> {
late final _gateway = _ProbeGateway(_publish);
static const _template = TemplateEntry(
key: 'release',
name: 'Release workflow',
description: 'Fixture template',
source: _source,
scheduled: false,
raw: {},
);
void _publish() {
globalContext.setProperty(
'templateCreateProbe'.toJS,
<String, Object?>{
'validates': _gateway.validates,
'submits': _gateway.submits,
'lastSource': _gateway.lastSource,
'lastSubmit': _gateway.lastSubmit,
'created': _gateway.created,
}.jsify(),
);
}
Future<void> _open() async {
await showTemplateCreateDialog(
context: context,
template: _template,
repository: TemplateRepository(_gateway),
cupertino: false,
onCreated: (detail) {
_gateway.created.add(detail);
_publish();
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Template create probe')),
body: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: FilledButton(
key: const ValueKey<String>('template-probe-open'),
onPressed: _open,
child: const Text(
'Create pipeline from this template',
textAlign: TextAlign.center,
),
),
),
),
);
}
}