diff --git a/app/lib/features/templates/data/template_repository.dart b/app/lib/features/templates/data/template_repository.dart index da56f5ea..d1464ae4 100644 --- a/app/lib/features/templates/data/template_repository.dart +++ b/app/lib/features/templates/data/template_repository.dart @@ -79,6 +79,12 @@ class TemplateRepository { 'The server returned no pipeline detail.', ); } + final id = detail['id']; + if (id is! num || !id.isFinite || id <= 0 || id != id.truncateToDouble()) { + throw const TemplateRepositoryException( + 'The server did not confirm a created pipeline.', + ); + } return Map.from(detail); } } diff --git a/app/lib/features/templates/ui/template_create_controls.dart b/app/lib/features/templates/ui/template_create_controls.dart new file mode 100644 index 00000000..a236cac1 --- /dev/null +++ b/app/lib/features/templates/ui/template_create_controls.dart @@ -0,0 +1,71 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import 'template_create_wording.dart'; + +/// Full wrapping native label, not a clipped placeholder/floating field label. +class TemplateCreateNameField extends StatelessWidget { + const TemplateCreateNameField({ + super.key, + required this.cupertino, + required this.controller, + required this.enabled, + required this.onSubmit, + }); + + final bool cupertino; + final TextEditingController controller; + final bool enabled; + final VoidCallback onSubmit; + + @override + Widget build(BuildContext context) => MergeSemantics( + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + const Text(templateCreateNameLabel), + const SizedBox(height: 8), + if (cupertino) + CupertinoTextField( + key: templateCreateNameKey, + controller: controller, + enabled: enabled, + autofocus: true, + textInputAction: TextInputAction.done, + onSubmitted: (_) => onSubmit(), + ) + else + TextField( + key: templateCreateNameKey, + controller: controller, + enabled: enabled, + autofocus: true, + textInputAction: TextInputAction.done, + onSubmitted: (_) => onSubmit(), + ), + ], + ), + ); +} + +Widget templateCreateDialogAction({ + required Key key, + required bool cupertino, + required VoidCallback? onPressed, + required Widget child, + bool primary = false, +}) { + if (cupertino) { + return CupertinoDialogAction( + key: key, + isDefaultAction: primary, + onPressed: onPressed, + child: child, + ); + } + if (primary) { + return FilledButton(key: key, onPressed: onPressed, child: child); + } + return TextButton(key: key, onPressed: onPressed, child: child); +} diff --git a/app/lib/features/templates/ui/template_create_dialog.dart b/app/lib/features/templates/ui/template_create_dialog.dart index 584b128d..f2297ed4 100644 --- a/app/lib/features/templates/ui/template_create_dialog.dart +++ b/app/lib/features/templates/ui/template_create_dialog.dart @@ -6,6 +6,7 @@ import '../../../core/api_gateway.dart'; import '../data/template_repository.dart'; import '../domain/template_entry.dart'; import 'template_create_wording.dart'; +import 'template_create_controls.dart'; /// Opens the native create prompt; resolves when it closes. Opening, typing and /// Cancel send nothing; Create validates the source first and only a passing @@ -156,7 +157,12 @@ class _TemplateCreateDialogState extends State<_TemplateCreateDialog> { mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - _field(), + TemplateCreateNameField( + cupertino: widget.cupertino, + controller: _name, + enabled: _fieldEnabled, + onSubmit: _create, + ), // Feedback stays next to the field it belongs to. The note below can // be pushed out of the dialog's scroll viewport on a short, large-text // screen; a refusal or success line must not be. @@ -189,7 +195,8 @@ class _TemplateCreateDialogState extends State<_TemplateCreateDialog> { ], ); final actions = [ - _dialogAction( + templateCreateDialogAction( + cupertino: widget.cupertino, key: templateCreateCancelKey, onPressed: _sending ? null : _cancel, child: Text( @@ -198,7 +205,8 @@ class _TemplateCreateDialogState extends State<_TemplateCreateDialog> { : templateCreateCloseLabel, ), ), - _dialogAction( + templateCreateDialogAction( + cupertino: widget.cupertino, key: templateCreateConfirmKey, primary: true, onPressed: _canSubmit ? _create : null, @@ -228,60 +236,4 @@ class _TemplateCreateDialogState extends State<_TemplateCreateDialog> { ), ); } - - Widget _field() { - // A wrapping label above the field, like the browser's label span: the - // Material floating label is ellipsized to `New pipeline name (requ…` at 2x - // text, and a Cupertino placeholder is not exposed as the field's name. - // Merging the visible label into the field gives both hosts one node with - // the exact wording and the field's value. - final field = widget.cupertino - ? CupertinoTextField( - key: templateCreateNameKey, - controller: _name, - enabled: _fieldEnabled, - autofocus: true, - textInputAction: TextInputAction.done, - onSubmitted: (_) => _create(), - ) - : TextField( - key: templateCreateNameKey, - controller: _name, - enabled: _fieldEnabled, - autofocus: true, - textInputAction: TextInputAction.done, - onSubmitted: (_) => _create(), - ); - return MergeSemantics( - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - const Text(templateCreateNameLabel), - const SizedBox(height: 8), - field, - ], - ), - ); - } - - Widget _dialogAction({ - required Key key, - required VoidCallback? onPressed, - required Widget child, - bool primary = false, - }) { - if (widget.cupertino) { - return CupertinoDialogAction( - key: key, - isDefaultAction: primary, - onPressed: onPressed, - child: child, - ); - } - if (primary) { - return FilledButton(key: key, onPressed: onPressed, child: child); - } - return TextButton(key: key, onPressed: onPressed, child: child); - } } diff --git a/app/notes/T1-create.md b/app/notes/T1-create.md index 80fbf106..67668cbc 100644 --- a/app/notes/T1-create.md +++ b/app/notes/T1-create.md @@ -1,5 +1,13 @@ # T1 — native create-from-template prompt +Manager integration: retained both sides' compatible run-test gateway/scroll +repairs when merging. Split native field/action controls from dialog state so +production files remain under250lines. Added a fail-closed repository guard: +an empty/malformed created detail without a positive integral pipeline identity +cannot be reported as successful creation. The new regression failed before the +guard; all24 template tests pass after. Source/native capture recheck precedes +actual gallery/Settings delivery; no production definition was created. + ## Result A native Material/Cupertino prompt implements the browser's P5 create flow diff --git a/app/test/features/templates/data/template_confirmation_test.dart b/app/test/features/templates/data/template_confirmation_test.dart new file mode 100644 index 00000000..bbd1329c --- /dev/null +++ b/app/test/features/templates/data/template_confirmation_test.dart @@ -0,0 +1,25 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/templates/data/template_repository.dart'; + +import 'template_test_support.dart'; + +void main() { + test( + 'a malformed created detail never becomes a claimed successful create', + () async { + for (final id in [null, 0, -1, 'unknown', 1.5]) { + final gateway = RecordingGateway([ + { + 'type': 'submitted', + 'detail': {'id': id, 'name': 'Unconfirmed'}, + }, + ]); + await expectLater( + TemplateRepository(gateway).submit('Topic', source), + throwsA(isA()), + ); + expect(gateway.calls.single.fields['create_only'], isTrue); + } + }, + ); +}