From 66d47a5ca80a4ffb7203f0c15165b04196d66c9d Mon Sep 17 00:00:00 2001 From: Cemal YILMAZ <206660090+cemal-yilmaz-bt@users.noreply.github.com> Date: Mon, 1 Jun 2026 17:59:23 +0300 Subject: [PATCH] =?UTF-8?q?refactor(poc):=20address=20Gemini=20review=20?= =?UTF-8?q?=E2=80=94=20simplify=20isPocSessionDeadStop=20+=20reuse=20http.?= =?UTF-8?q?Client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - isPocSessionDeadStop: replace any() closure with type check + contains() - SimulationPanel: shared http.Client for TCP keep-alive across sim steps - runPocSimStep: optional http.Client? param threaded to _runFetch --- poc/flutter-poc/lib/poc_simulation.dart | 12 ++++++------ poc/flutter-poc/lib/widgets/simulation_panel.dart | 10 +++++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/poc/flutter-poc/lib/poc_simulation.dart b/poc/flutter-poc/lib/poc_simulation.dart index a7badc3..e3a9d48 100644 --- a/poc/flutter-poc/lib/poc_simulation.dart +++ b/poc/flutter-poc/lib/poc_simulation.dart @@ -82,9 +82,8 @@ bool isPocSessionDeadStop({ required List sessionDeadAuthIds, }) { if (result.status != 'AUTH') return false; - final isSessionDead = sessionDeadAuthIds.any( - (id) => step is PocSimHostStep && step.auth == id, - ); + final isSessionDead = + step is PocSimHostStep && sessionDeadAuthIds.contains(step.auth); final detail = result.detail ?? ''; return isSessionDead && (detail.contains('invalid_grant') || @@ -199,10 +198,11 @@ PocSimStep? _parseStep(Map m) { Future runPocSimStep( MorphClient morph, PocSimulationConfig cfg, - PocSimStep step, -) async { + PocSimStep step, [ + http.Client? httpClient, +]) async { return switch (step) { - PocSimFetchStep s => _runFetch(s, cfg.mockApiBaseUrl), + PocSimFetchStep s => _runFetch(s, cfg.mockApiBaseUrl, httpClient), PocSimHostStep s => _runHost(morph, s), PocSimLogoutStep s => _runLogout(morph, s), }; diff --git a/poc/flutter-poc/lib/widgets/simulation_panel.dart b/poc/flutter-poc/lib/widgets/simulation_panel.dart index 8efe9d5..448d277 100644 --- a/poc/flutter-poc/lib/widgets/simulation_panel.dart +++ b/poc/flutter-poc/lib/widgets/simulation_panel.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:http/http.dart' as http; import 'package:morph_core/morph_core.dart'; import '../poc_simulation.dart'; @@ -24,6 +25,13 @@ class _SimulationPanelState extends State { bool _probe404Enabled = false; final List _results = []; String _sessionDeadMessage = ''; + final http.Client _httpClient = http.Client(); + + @override + void dispose() { + _httpClient.close(); + super.dispose(); + } List get _autoSteps => widget.cfg.steps .where((s) => @@ -47,7 +55,7 @@ class _SimulationPanelState extends State { for (final step in _autoSteps) { if (!mounted) break; - final result = await runPocSimStep(widget.morph, widget.cfg, step); + final result = await runPocSimStep(widget.morph, widget.cfg, step, _httpClient); if (!mounted) break; setState(() => _results.add(result));